OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 void color_apply_icc_profile(opj_image_t* image) { | 427 void color_apply_icc_profile(opj_image_t* image) { |
428 cmsHPROFILE out_prof; | 428 cmsHPROFILE out_prof; |
429 cmsUInt32Number in_type; | 429 cmsUInt32Number in_type; |
430 cmsUInt32Number out_type; | 430 cmsUInt32Number out_type; |
431 int* r; | 431 int* r; |
432 int* g; | 432 int* g; |
433 int* b; | 433 int* b; |
434 int max; | 434 int max; |
435 cmsHPROFILE in_prof = | 435 cmsHPROFILE in_prof = |
436 cmsOpenProfileFromMem(image->icc_profile_buf, image->icc_profile_len); | 436 cmsOpenProfileFromMem(image->icc_profile_buf, image->icc_profile_len); |
437 if (in_prof == NULL) { | 437 if (!in_prof) { |
438 return; | 438 return; |
439 } | 439 } |
440 cmsColorSpaceSignature out_space = cmsGetColorSpace(in_prof); | 440 cmsColorSpaceSignature out_space = cmsGetColorSpace(in_prof); |
441 cmsUInt32Number intent = cmsGetHeaderRenderingIntent(in_prof); | 441 cmsUInt32Number intent = cmsGetHeaderRenderingIntent(in_prof); |
442 int max_w = (int)image->comps[0].w; | 442 int max_w = (int)image->comps[0].w; |
443 int max_h = (int)image->comps[0].h; | 443 int max_h = (int)image->comps[0].h; |
444 int prec = (int)image->comps[0].prec; | 444 int prec = (int)image->comps[0].prec; |
445 OPJ_COLOR_SPACE oldspace = image->color_space; | 445 OPJ_COLOR_SPACE oldspace = image->color_space; |
446 if (out_space == cmsSigRgbData) { | 446 if (out_space == cmsSigRgbData) { |
447 if (prec <= 8) { | 447 if (prec <= 8) { |
(...skipping 20 matching lines...) Expand all Loading... |
468 out_type = TYPE_RGB_16; | 468 out_type = TYPE_RGB_16; |
469 out_prof = cmsCreate_sRGBProfile(); | 469 out_prof = cmsCreate_sRGBProfile(); |
470 image->color_space = OPJ_CLRSPC_SRGB; | 470 image->color_space = OPJ_CLRSPC_SRGB; |
471 } else { | 471 } else { |
472 return; | 472 return; |
473 } | 473 } |
474 cmsHTRANSFORM transform = | 474 cmsHTRANSFORM transform = |
475 cmsCreateTransform(in_prof, in_type, out_prof, out_type, intent, 0); | 475 cmsCreateTransform(in_prof, in_type, out_prof, out_type, intent, 0); |
476 cmsCloseProfile(in_prof); | 476 cmsCloseProfile(in_prof); |
477 cmsCloseProfile(out_prof); | 477 cmsCloseProfile(out_prof); |
478 if (transform == NULL) { | 478 if (!transform) { |
479 image->color_space = oldspace; | 479 image->color_space = oldspace; |
480 return; | 480 return; |
481 } | 481 } |
482 if (image->numcomps > 2) { | 482 if (image->numcomps > 2) { |
483 if (prec <= 8) { | 483 if (prec <= 8) { |
484 unsigned char *inbuf, *outbuf, *in, *out; | 484 unsigned char *inbuf, *outbuf, *in, *out; |
485 max = max_w * max_h; | 485 max = max_w * max_h; |
486 cmsUInt32Number nr_samples = max * 3 * sizeof(unsigned char); | 486 cmsUInt32Number nr_samples = max * 3 * sizeof(unsigned char); |
487 in = inbuf = FX_Alloc(unsigned char, nr_samples); | 487 in = inbuf = FX_Alloc(unsigned char, nr_samples); |
488 out = outbuf = FX_Alloc(unsigned char, nr_samples); | 488 out = outbuf = FX_Alloc(unsigned char, nr_samples); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
586 cmsHPROFILE in, out; | 586 cmsHPROFILE in, out; |
587 cmsHTRANSFORM transform; | 587 cmsHTRANSFORM transform; |
588 cmsUInt16Number RGB[3]; | 588 cmsUInt16Number RGB[3]; |
589 cmsCIELab Lab; | 589 cmsCIELab Lab; |
590 in = cmsCreateLab4Profile(NULL); | 590 in = cmsCreateLab4Profile(NULL); |
591 out = cmsCreate_sRGBProfile(); | 591 out = cmsCreate_sRGBProfile(); |
592 transform = cmsCreateTransform(in, TYPE_Lab_DBL, out, TYPE_RGB_16, | 592 transform = cmsCreateTransform(in, TYPE_Lab_DBL, out, TYPE_RGB_16, |
593 INTENT_PERCEPTUAL, 0); | 593 INTENT_PERCEPTUAL, 0); |
594 cmsCloseProfile(in); | 594 cmsCloseProfile(in); |
595 cmsCloseProfile(out); | 595 cmsCloseProfile(out); |
596 if (transform == NULL) { | 596 if (!transform) { |
597 return; | 597 return; |
598 } | 598 } |
599 prec0 = (double)image->comps[0].prec; | 599 prec0 = (double)image->comps[0].prec; |
600 prec1 = (double)image->comps[1].prec; | 600 prec1 = (double)image->comps[1].prec; |
601 prec2 = (double)image->comps[2].prec; | 601 prec2 = (double)image->comps[2].prec; |
602 default_type = row[1]; | 602 default_type = row[1]; |
603 if (default_type == 0x44454600) { | 603 if (default_type == 0x44454600) { |
604 rl = 100; | 604 rl = 100; |
605 ra = 170; | 605 ra = 170; |
606 rb = 200; | 606 rb = 200; |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
697 0x00, 0x00, 0x00, 0x0c, 0x6a, 0x50, 0x20, 0x20, 0x0d, 0x0a, 0x87, 0x0a}; | 697 0x00, 0x00, 0x00, 0x0c, 0x6a, 0x50, 0x20, 0x20, 0x0d, 0x0a, 0x87, 0x0a}; |
698 if (!src_data || src_size < sizeof(szJP2Header)) | 698 if (!src_data || src_size < sizeof(szJP2Header)) |
699 return FALSE; | 699 return FALSE; |
700 | 700 |
701 image = NULL; | 701 image = NULL; |
702 m_SrcData = src_data; | 702 m_SrcData = src_data; |
703 m_SrcSize = src_size; | 703 m_SrcSize = src_size; |
704 DecodeData srcData(const_cast<unsigned char*>(src_data), src_size); | 704 DecodeData srcData(const_cast<unsigned char*>(src_data), src_size); |
705 l_stream = fx_opj_stream_create_memory_stream(&srcData, | 705 l_stream = fx_opj_stream_create_memory_stream(&srcData, |
706 OPJ_J2K_STREAM_CHUNK_SIZE, 1); | 706 OPJ_J2K_STREAM_CHUNK_SIZE, 1); |
707 if (l_stream == NULL) { | 707 if (!l_stream) { |
708 return FALSE; | 708 return FALSE; |
709 } | 709 } |
710 opj_dparameters_t parameters; | 710 opj_dparameters_t parameters; |
711 opj_set_default_decoder_parameters(¶meters); | 711 opj_set_default_decoder_parameters(¶meters); |
712 parameters.decod_format = 0; | 712 parameters.decod_format = 0; |
713 parameters.cod_format = 3; | 713 parameters.cod_format = 3; |
714 if (FXSYS_memcmp(m_SrcData, szJP2Header, sizeof(szJP2Header)) == 0) { | 714 if (FXSYS_memcmp(m_SrcData, szJP2Header, sizeof(szJP2Header)) == 0) { |
715 l_codec = opj_create_decompress(OPJ_CODEC_JP2); | 715 l_codec = opj_create_decompress(OPJ_CODEC_JP2); |
716 parameters.decod_format = 1; | 716 parameters.decod_format = 1; |
717 } else { | 717 } else { |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
876 bool CCodec_JpxModule::Decode(CJPX_Decoder* pDecoder, | 876 bool CCodec_JpxModule::Decode(CJPX_Decoder* pDecoder, |
877 uint8_t* dest_data, | 877 uint8_t* dest_data, |
878 int pitch, | 878 int pitch, |
879 const std::vector<uint8_t>& offsets) { | 879 const std::vector<uint8_t>& offsets) { |
880 return pDecoder->Decode(dest_data, pitch, offsets); | 880 return pDecoder->Decode(dest_data, pitch, offsets); |
881 } | 881 } |
882 | 882 |
883 void CCodec_JpxModule::DestroyDecoder(CJPX_Decoder* pDecoder) { | 883 void CCodec_JpxModule::DestroyDecoder(CJPX_Decoder* pDecoder) { |
884 delete pDecoder; | 884 delete pDecoder; |
885 } | 885 } |
OLD | NEW |