1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
7 #include "../../../include/fxcodec/fx_codec.h"
9 #include "../fx_libopenjpeg/libopenjpeg20/openjpeg.h"
10 #include "../lcms2/include/fx_lcms2.h"
11 static void fx_error_callback(const char *msg, void *client_data)
15 static void fx_warning_callback(const char *msg, void *client_data)
19 static void fx_info_callback(const char *msg, void *client_data)
24 const unsigned char* src_data;
28 static OPJ_SIZE_T opj_read_from_memory (void * p_buffer, OPJ_SIZE_T p_nb_bytes, decodeData* srcData)
30 if(srcData == NULL || srcData->src_size == 0 || srcData->src_data == NULL || srcData->offset >= srcData->src_size) {
33 OPJ_SIZE_T readlength = p_nb_bytes;
34 OPJ_SIZE_T bufferLength = (OPJ_SIZE_T)(srcData->src_size - srcData->offset);
35 if(bufferLength <= 0) {
38 if(bufferLength <= p_nb_bytes) {
39 readlength = bufferLength;
41 memcpy(p_buffer, &(srcData->src_data[srcData->offset]), readlength);
42 srcData->offset += (int)readlength;
45 static OPJ_SIZE_T opj_write_from_memory (void * p_buffer, OPJ_SIZE_T p_nb_bytes, decodeData* srcData)
47 if(srcData == NULL || srcData->src_size == 0 || srcData->src_data == NULL || srcData->offset >= srcData->src_size) {
50 OPJ_SIZE_T writeLength = p_nb_bytes;
51 OPJ_SIZE_T bufferLength = (OPJ_SIZE_T)(srcData->src_size - srcData->offset);
52 if(bufferLength <= p_nb_bytes) {
53 writeLength = bufferLength;
55 memcpy((void*&)(srcData->src_data[srcData->offset]), p_buffer, writeLength);
56 srcData->offset += (int)writeLength;
59 static OPJ_OFF_T opj_skip_from_memory (OPJ_OFF_T p_nb_bytes, decodeData* srcData)
61 if(srcData == NULL || srcData->src_size == 0 || srcData->src_data == NULL || srcData->offset >= srcData->src_size) {
64 OPJ_OFF_T postion = srcData->offset + p_nb_bytes;
67 } else if (postion > srcData->src_size) {
69 srcData->offset = (int)postion;
72 static OPJ_BOOL opj_seek_from_memory (OPJ_OFF_T p_nb_bytes, decodeData * srcData)
74 if(srcData == NULL || srcData->src_size == 0 || srcData->src_data == NULL || srcData->offset >= srcData->src_size) {
77 srcData->offset = (int)p_nb_bytes;
78 if(srcData->offset < 0) {
80 } else if(srcData->offset > srcData->src_size) {
81 srcData->offset = srcData->src_size;
85 opj_stream_t* fx_opj_stream_create_memory_stream (decodeData* data, OPJ_SIZE_T p_size, OPJ_BOOL p_is_read_stream)
87 opj_stream_t* l_stream = 00;
88 if (!data || ! data->src_data || data->src_size <= 0 ) {
91 l_stream = opj_stream_create(p_size, p_is_read_stream);
95 opj_stream_set_user_data_v3(l_stream, data, NULL);
96 opj_stream_set_user_data_length(l_stream, data->src_size);
97 opj_stream_set_read_function(l_stream, (opj_stream_read_fn) opj_read_from_memory);
98 opj_stream_set_write_function(l_stream, (opj_stream_write_fn) opj_write_from_memory);
99 opj_stream_set_skip_function(l_stream, (opj_stream_skip_fn) opj_skip_from_memory);
100 opj_stream_set_seek_function(l_stream, (opj_stream_seek_fn) opj_seek_from_memory);
103 static void sycc_to_rgb(int offset, int upb, int y, int cb, int cr,
104 int *out_r, int *out_g, int *out_b)
109 r = y + (int)(1.402 * (float)cr);
115 g = y - (int)(0.344 * (float)cb + 0.714 * (float)cr);
121 b = y + (int)(1.772 * (float)cb);
128 static void sycc444_to_rgb(opj_image_t *img)
130 int *d0, *d1, *d2, *r, *g, *b;
131 const int *y, *cb, *cr;
132 int maxw, maxh, max, i, offset, upb;
133 i = (int)img->comps[0].prec;
134 offset = 1 << (i - 1);
136 maxw = (int)img->comps[0].w;
137 maxh = (int)img->comps[0].h;
139 y = img->comps[0].data;
140 cb = img->comps[1].data;
141 cr = img->comps[2].data;
142 d0 = r = FX_Alloc(int, (size_t)max);
143 d1 = g = FX_Alloc(int, (size_t)max);
144 d2 = b = FX_Alloc(int, (size_t)max);
145 for(i = 0; i < max; ++i) {
146 sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b);
154 FX_Free(img->comps[0].data);
155 img->comps[0].data = d0;
156 FX_Free(img->comps[1].data);
157 img->comps[1].data = d1;
158 FX_Free(img->comps[2].data);
159 img->comps[2].data = d2;
161 static void sycc422_to_rgb(opj_image_t *img)
163 int *d0, *d1, *d2, *r, *g, *b;
164 const int *y, *cb, *cr;
165 int maxw, maxh, max, offset, upb;
167 i = (int)img->comps[0].prec;
168 offset = 1 << (i - 1);
170 maxw = (int)img->comps[0].w;
171 maxh = (int)img->comps[0].h;
173 y = img->comps[0].data;
174 cb = img->comps[1].data;
175 cr = img->comps[2].data;
176 d0 = r = FX_Alloc(int, (size_t)max);
177 d1 = g = FX_Alloc(int, (size_t)max);
178 d2 = b = FX_Alloc(int, (size_t)max);
179 for(i = 0; i < maxh; ++i) {
180 for(j = 0; j < maxw; j += 2) {
181 sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b);
186 sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b);
195 FX_Free(img->comps[0].data);
196 img->comps[0].data = d0;
197 FX_Free(img->comps[1].data);
198 img->comps[1].data = d1;
199 FX_Free(img->comps[2].data);
200 img->comps[2].data = d2;
201 img->comps[1].w = maxw;
202 img->comps[1].h = maxh;
203 img->comps[2].w = maxw;
204 img->comps[2].h = maxh;
205 img->comps[1].w = (OPJ_UINT32)maxw;
206 img->comps[1].h = (OPJ_UINT32)maxh;
207 img->comps[2].w = (OPJ_UINT32)maxw;
208 img->comps[2].h = (OPJ_UINT32)maxh;
209 img->comps[1].dx = img->comps[0].dx;
210 img->comps[2].dx = img->comps[0].dx;
211 img->comps[1].dy = img->comps[0].dy;
212 img->comps[2].dy = img->comps[0].dy;
214 static void sycc420_to_rgb(opj_image_t *img)
216 int *d0, *d1, *d2, *r, *g, *b, *nr, *ng, *nb;
217 const int *y, *cb, *cr, *ny;
218 int maxw, maxh, max, offset, upb;
220 i = (int)img->comps[0].prec;
221 offset = 1 << (i - 1);
223 maxw = (int)img->comps[0].w;
224 maxh = (int)img->comps[0].h;
226 y = img->comps[0].data;
227 cb = img->comps[1].data;
228 cr = img->comps[2].data;
229 d0 = r = FX_Alloc(int, (size_t)max);
230 d1 = g = FX_Alloc(int, (size_t)max);
231 d2 = b = FX_Alloc(int, (size_t)max);
232 for(i = 0; i < maxh; i += 2) {
237 for(j = 0; j < maxw; j += 2) {
238 sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b);
243 sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b);
248 sycc_to_rgb(offset, upb, *ny, *cb, *cr, nr, ng, nb);
253 sycc_to_rgb(offset, upb, *ny, *cb, *cr, nr, ng, nb);
266 FX_Free(img->comps[0].data);
267 img->comps[0].data = d0;
268 FX_Free(img->comps[1].data);
269 img->comps[1].data = d1;
270 FX_Free(img->comps[2].data);
271 img->comps[2].data = d2;
272 img->comps[1].w = maxw;
273 img->comps[1].h = maxh;
274 img->comps[2].w = maxw;
275 img->comps[2].h = maxh;
276 img->comps[1].w = (OPJ_UINT32)maxw;
277 img->comps[1].h = (OPJ_UINT32)maxh;
278 img->comps[2].w = (OPJ_UINT32)maxw;
279 img->comps[2].h = (OPJ_UINT32)maxh;
280 img->comps[1].dx = img->comps[0].dx;
281 img->comps[2].dx = img->comps[0].dx;
282 img->comps[1].dy = img->comps[0].dy;
283 img->comps[2].dy = img->comps[0].dy;
285 void color_sycc_to_rgb(opj_image_t *img)
287 if(img->numcomps < 3) {
288 img->color_space = OPJ_CLRSPC_GRAY;
291 if((img->comps[0].dx == 1)
292 && (img->comps[1].dx == 2)
293 && (img->comps[2].dx == 2)
294 && (img->comps[0].dy == 1)
295 && (img->comps[1].dy == 2)
296 && (img->comps[2].dy == 2)) {
298 } else if((img->comps[0].dx == 1)
299 && (img->comps[1].dx == 2)
300 && (img->comps[2].dx == 2)
301 && (img->comps[0].dy == 1)
302 && (img->comps[1].dy == 1)
303 && (img->comps[2].dy == 1)) {
305 } else if((img->comps[0].dx == 1)
306 && (img->comps[1].dx == 1)
307 && (img->comps[2].dx == 1)
308 && (img->comps[0].dy == 1)
309 && (img->comps[1].dy == 1)
310 && (img->comps[2].dy == 1)) {
315 img->color_space = OPJ_CLRSPC_SRGB;
317 void color_apply_icc_profile(opj_image_t *image)
319 cmsHPROFILE in_prof, out_prof;
320 cmsHTRANSFORM transform;
321 cmsColorSpaceSignature in_space, out_space;
322 cmsUInt32Number intent, in_type, out_type, nr_samples;
324 int prec, i, max, max_w, max_h;
325 OPJ_COLOR_SPACE oldspace;
327 cmsOpenProfileFromMem(image->icc_profile_buf, image->icc_profile_len);
328 if(in_prof == NULL) {
331 in_space = cmsGetPCS(in_prof);
332 out_space = cmsGetColorSpace(in_prof);
333 intent = cmsGetHeaderRenderingIntent(in_prof);
334 max_w = (int)image->comps[0].w;
335 max_h = (int)image->comps[0].h;
336 prec = (int)image->comps[0].prec;
337 oldspace = image->color_space;
338 if(out_space == cmsSigRgbData) {
340 in_type = TYPE_RGB_8;
341 out_type = TYPE_RGB_8;
343 in_type = TYPE_RGB_16;
344 out_type = TYPE_RGB_16;
346 out_prof = cmsCreate_sRGBProfile();
347 image->color_space = OPJ_CLRSPC_SRGB;
348 } else if(out_space == cmsSigGrayData) {
350 in_type = TYPE_GRAY_8;
351 out_type = TYPE_RGB_8;
353 in_type = TYPE_GRAY_16;
354 out_type = TYPE_RGB_16;
356 out_prof = cmsCreate_sRGBProfile();
357 image->color_space = OPJ_CLRSPC_SRGB;
358 } else if(out_space == cmsSigYCbCrData) {
359 in_type = TYPE_YCbCr_16;
360 out_type = TYPE_RGB_16;
361 out_prof = cmsCreate_sRGBProfile();
362 image->color_space = OPJ_CLRSPC_SRGB;
366 transform = cmsCreateTransform(in_prof, in_type,
367 out_prof, out_type, intent, 0);
368 cmsCloseProfile(in_prof);
369 cmsCloseProfile(out_prof);
370 if(transform == NULL) {
371 image->color_space = oldspace;
374 if(image->numcomps > 2) {
376 unsigned char *inbuf, *outbuf, *in, *out;
378 nr_samples = (cmsUInt32Number)max * 3 * (cmsUInt32Number)sizeof(unsigned char);
379 in = inbuf = FX_Alloc(unsigned char, nr_samples);
380 out = outbuf = FX_Alloc(unsigned char, nr_samples);
381 r = image->comps[0].data;
382 g = image->comps[1].data;
383 b = image->comps[2].data;
384 for(i = 0; i < max; ++i) {
385 *in++ = (unsigned char) * r++;
386 *in++ = (unsigned char) * g++;
387 *in++ = (unsigned char) * b++;
389 cmsDoTransform(transform, inbuf, outbuf, (cmsUInt32Number)max);
390 r = image->comps[0].data;
391 g = image->comps[1].data;
392 b = image->comps[2].data;
393 for(i = 0; i < max; ++i) {
394 *r++ = (int) * out++;
395 *g++ = (int) * out++;
396 *b++ = (int) * out++;
401 unsigned short *inbuf, *outbuf, *in, *out;
403 nr_samples = (cmsUInt32Number)max * 3 * (cmsUInt32Number)sizeof(unsigned short);
404 in = inbuf = FX_Alloc(unsigned short, nr_samples);
405 out = outbuf = FX_Alloc(unsigned short, nr_samples);
406 r = image->comps[0].data;
407 g = image->comps[1].data;
408 b = image->comps[2].data;
409 for(i = 0; i < max; ++i) {
410 *in++ = (unsigned short) * r++;
411 *in++ = (unsigned short) * g++;
412 *in++ = (unsigned short) * b++;
414 cmsDoTransform(transform, inbuf, outbuf, (cmsUInt32Number)max);
415 r = image->comps[0].data;
416 g = image->comps[1].data;
417 b = image->comps[2].data;
418 for(i = 0; i < max; ++i) {
419 *r++ = (int) * out++;
420 *g++ = (int) * out++;
421 *b++ = (int) * out++;
427 unsigned char *in, *inbuf, *out, *outbuf;
429 nr_samples = (cmsUInt32Number)max * 3 * sizeof(unsigned char);
430 in = inbuf = FX_Alloc(unsigned char, nr_samples);
431 out = outbuf = FX_Alloc(unsigned char, nr_samples);
432 image->comps = (opj_image_comp_t*)
433 realloc(image->comps, (image->numcomps + 2) * sizeof(opj_image_comp_t));
434 if(image->numcomps == 2) {
435 image->comps[3] = image->comps[1];
437 image->comps[1] = image->comps[0];
438 image->comps[2] = image->comps[0];
439 image->comps[1].data = FX_Alloc(int, (size_t)max);
440 FXSYS_memset8(image->comps[1].data, 0, sizeof(int) * (size_t)max);
441 image->comps[2].data = FX_Alloc(int, (size_t)max);
442 FXSYS_memset8(image->comps[2].data, 0, sizeof(int) * (size_t)max);
443 image->numcomps += 2;
444 r = image->comps[0].data;
445 for(i = 0; i < max; ++i) {
446 *in++ = (unsigned char) * r++;
448 cmsDoTransform(transform, inbuf, outbuf, (cmsUInt32Number)max);
449 r = image->comps[0].data;
450 g = image->comps[1].data;
451 b = image->comps[2].data;
452 for(i = 0; i < max; ++i) {
453 *r++ = (int) * out++;
454 *g++ = (int) * out++;
455 *b++ = (int) * out++;
460 cmsDeleteTransform(transform);
462 void color_apply_conversion(opj_image_t *image)
465 int enumcs, numcomps;
466 numcomps = image->numcomps;
470 row = (int*)image->icc_profile_buf;
473 int *L, *a, *b, *red, *green, *blue, *src0, *src1, *src2;
474 double rl, ol, ra, oa, rb, ob, prec0, prec1, prec2;
475 double minL, maxL, mina, maxa, minb, maxb;
476 unsigned int default_type, il;
477 unsigned int i, max, illu;
479 cmsHTRANSFORM transform;
480 cmsUInt16Number RGB[3];
484 in = cmsCreateLab4Profile(NULL);
485 out = cmsCreate_sRGBProfile();
487 cmsCreateTransform(in, TYPE_Lab_DBL, out, TYPE_RGB_16,
488 INTENT_PERCEPTUAL, 0);
490 cmsCloseProfile(out);
491 if(transform == NULL) {
494 prec0 = (double)image->comps[0].prec;
495 prec1 = (double)image->comps[1].prec;
496 prec2 = (double)image->comps[2].prec;
497 default_type = row[1];
498 if(default_type == 0x44454600) {
503 oa = pow(2, prec1 - 1);
504 ob = pow(2, prec2 - 2) + pow(2, prec2 - 3);
513 L = src0 = image->comps[0].data;
514 a = src1 = image->comps[1].data;
515 b = src2 = image->comps[2].data;
516 max = image->comps[0].w * image->comps[0].h;
517 red = FX_Alloc(int, max);
518 image->comps[0].data = red;
519 green = FX_Alloc(int, max);
520 image->comps[1].data = green;
521 blue = FX_Alloc(int, max);
522 image->comps[2].data = blue;
523 minL = -(rl * ol) / (pow(2, prec0) - 1);
525 mina = -(ra * oa) / (pow(2, prec1) - 1);
527 minb = -(rb * ob) / (pow(2, prec2) - 1);
529 for(i = 0; i < max; ++i) {
530 Lab.L = minL + (double)(*L) * (maxL - minL) / (pow(2, prec0) - 1);
532 Lab.a = mina + (double)(*a) * (maxa - mina) / (pow(2, prec1) - 1);
534 Lab.b = minb + (double)(*b) * (maxb - minb) / (pow(2, prec2) - 1);
536 cmsDoTransform(transform, &Lab, RGB, 1);
541 cmsDeleteTransform(transform);
545 image->color_space = OPJ_CLRSPC_SRGB;
546 image->comps[0].prec = 16;
547 image->comps[1].prec = 16;
548 image->comps[2].prec = 16;
552 class CJPX_Decoder : public CFX_Object
557 FX_BOOL Init(const unsigned char* src_data, int src_size);
558 void GetInfo(FX_DWORD& width, FX_DWORD& height, FX_DWORD& codestream_nComps, FX_DWORD& output_nComps);
559 FX_BOOL Decode(FX_LPBYTE dest_buf, int pitch, FX_BOOL bTranslateColor, FX_LPBYTE offsets);
560 FX_LPCBYTE m_SrcData;
563 opj_codec_t* l_codec;
564 opj_stream_t *l_stream;
565 FX_BOOL m_useColorSpace;
567 CJPX_Decoder::CJPX_Decoder(): image(NULL), l_codec(NULL), l_stream(NULL), m_useColorSpace(FALSE)
570 CJPX_Decoder::~CJPX_Decoder()
573 opj_destroy_codec(l_codec);
576 opj_stream_destroy(l_stream);
579 opj_image_destroy(image);
582 FX_BOOL CJPX_Decoder::Init(const unsigned char* src_data, int src_size)
584 opj_dparameters_t parameters;
586 m_SrcData = src_data;
587 m_SrcSize = src_size;
590 srcData.src_size = src_size;
591 srcData.src_data = src_data;
592 l_stream = fx_opj_stream_create_memory_stream(&srcData, OPJ_J2K_STREAM_CHUNK_SIZE, 1);
593 if (l_stream == NULL) {
596 opj_set_default_decoder_parameters(¶meters);
597 parameters.decod_format = 0;
598 parameters.cod_format = 3;
599 if(FXSYS_memcmp32(m_SrcData, "\x00\x00\x00\x0c\x6a\x50\x20\x20\x0d\x0a\x87\x0a", 12) == 0) {
600 l_codec = opj_create_decompress(OPJ_CODEC_JP2);
601 parameters.decod_format = 1;
603 l_codec = opj_create_decompress(OPJ_CODEC_J2K);
608 opj_set_info_handler(l_codec, fx_info_callback, 00);
609 opj_set_warning_handler(l_codec, fx_warning_callback, 00);
610 opj_set_error_handler(l_codec, fx_error_callback, 00);
611 if ( !opj_setup_decoder(l_codec, ¶meters) ) {
614 if(! opj_read_header(l_stream, l_codec, &image)) {
618 if(this->m_useColorSpace) {
619 image->useColorSpace = 1;
621 image->useColorSpace = 0;
623 if (!parameters.nb_tile_to_decode) {
624 if (!opj_set_decode_area(l_codec, image, parameters.DA_x0,
625 parameters.DA_y0, parameters.DA_x1, parameters.DA_y1)) {
626 opj_image_destroy(image);
630 if (!(opj_decode(l_codec, l_stream, image) && opj_end_decompress(l_codec, l_stream))) {
631 opj_image_destroy(image);
636 if (!opj_get_decoded_tile(l_codec, l_stream, image, parameters.tile_index)) {
640 opj_stream_destroy(l_stream);
642 if( image->color_space != OPJ_CLRSPC_SYCC
643 && image->numcomps == 3 && image->comps[0].dx == image->comps[0].dy
644 && image->comps[1].dx != 1 ) {
645 image->color_space = OPJ_CLRSPC_SYCC;
646 } else if (image->numcomps <= 2) {
647 image->color_space = OPJ_CLRSPC_GRAY;
649 if(image->color_space == OPJ_CLRSPC_SYCC) {
650 color_sycc_to_rgb(image);
652 if(image->icc_profile_buf && !image->useColorSpace) {
653 FX_Free(image->icc_profile_buf);
654 image->icc_profile_buf = NULL;
655 image->icc_profile_len = 0;
662 void CJPX_Decoder::GetInfo(FX_DWORD& width, FX_DWORD& height, FX_DWORD& codestream_nComps, FX_DWORD& output_nComps)
664 width = (FX_DWORD)image->x1;
665 height = (FX_DWORD)image->y1;
666 output_nComps = codestream_nComps = (FX_DWORD)image->numcomps;
668 FX_BOOL CJPX_Decoder::Decode(FX_LPBYTE dest_buf, int pitch, FX_BOOL bTranslateColor, FX_LPBYTE offsets)
670 FX_BYTE** channel_bufs;
672 int i, wid, hei, row, col, channel, src;
674 FX_LPBYTE pChannel, pScanline, pPixel;
676 if(image->comps[0].w != image->x1 || image->comps[0].h != image->y1) {
679 if(pitch < (int)(image->comps[0].w * 8 * image->numcomps + 31) >> 5 << 2) {
682 FXSYS_memset8(dest_buf, 0xff, image->y1 * pitch);
683 channel_bufs = FX_Alloc(FX_BYTE*, image->numcomps);
684 if (channel_bufs == NULL) {
687 adjust_comps = FX_Alloc(int, image->numcomps);
688 if (adjust_comps == NULL) {
689 FX_Free(channel_bufs);
693 for (i = 0; i < (int)image->numcomps; i ++) {
694 channel_bufs[i] = dest_buf + offsets[i];
695 adjust_comps[i] = image->comps[i].prec - 8;
697 if(image->comps[i].dx != image->comps[i - 1].dx
698 || image->comps[i].dy != image->comps[i - 1].dy
699 || image->comps[i].prec != image->comps[i - 1].prec) {
705 wid = image->comps[0].w;
706 hei = image->comps[0].h;
707 for (channel = 0; channel < (int)image->numcomps; channel++) {
708 pChannel = channel_bufs[channel];
709 if(adjust_comps[channel] < 0) {
710 for(row = 0; row < hei; row++) {
711 pScanline = pChannel + row * pitch;
712 for (col = 0; col < wid; col++) {
713 pPixel = pScanline + col * image->numcomps;
714 src = image->comps[channel].data[row * wid + col];
715 src += image->comps[channel].sgnd ? 1 << (image->comps[channel].prec - 1) : 0;
716 if (adjust_comps[channel] > 0) {
719 *pPixel = (FX_BYTE)(src << -adjust_comps[channel]);
724 for(row = 0; row < hei; row++) {
725 pScanline = pChannel + row * pitch;
726 for (col = 0; col < wid; col++) {
727 pPixel = pScanline + col * image->numcomps;
728 if (!image->comps[channel].data) {
731 src = image->comps[channel].data[row * wid + col];
732 src += image->comps[channel].sgnd ? 1 << (image->comps[channel].prec - 1) : 0;
733 if (adjust_comps[channel] - 1 < 0) {
734 *pPixel = (FX_BYTE)((src >> adjust_comps[channel]));
736 int tmpPixel = (src >> adjust_comps[channel]) + ((src >> (adjust_comps[channel] - 1)) % 2);
737 if (tmpPixel > 255) {
739 } else if (tmpPixel < 0) {
742 *pPixel = (FX_BYTE)tmpPixel;
749 FX_Free(channel_bufs);
750 FX_Free(adjust_comps);
753 FX_Free(channel_bufs);
754 FX_Free(adjust_comps);
757 void initialize_transition_table();
758 void initialize_significance_luts();
759 void initialize_sign_lut();
760 CCodec_JpxModule::CCodec_JpxModule()
763 void* CCodec_JpxModule::CreateDecoder(FX_LPCBYTE src_buf, FX_DWORD src_size , FX_BOOL useColorSpace)
765 CJPX_Decoder* pDecoder = FX_NEW CJPX_Decoder;
766 if (pDecoder == NULL) {
769 pDecoder->m_useColorSpace = useColorSpace;
770 if (!pDecoder->Init(src_buf, src_size)) {
776 void CCodec_JpxModule::GetImageInfo(FX_LPVOID ctx, FX_DWORD& width, FX_DWORD& height,
777 FX_DWORD& codestream_nComps, FX_DWORD& output_nComps)
779 CJPX_Decoder* pDecoder = (CJPX_Decoder*)ctx;
780 pDecoder->GetInfo(width, height, codestream_nComps, output_nComps);
782 FX_BOOL CCodec_JpxModule::Decode(void* ctx, FX_LPBYTE dest_data, int pitch, FX_BOOL bTranslateColor, FX_LPBYTE offsets)
784 CJPX_Decoder* pDecoder = (CJPX_Decoder*)ctx;
785 return pDecoder->Decode(dest_data, pitch, bTranslateColor, offsets);
787 void CCodec_JpxModule::DestroyDecoder(void* ctx)
789 CJPX_Decoder* pDecoder = (CJPX_Decoder*)ctx;