| 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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 // again clamping at EOF. | 115 // again clamping at EOF. |
| 116 srcData->offset = std::min(checkedNbBytes, srcData->src_size); | 116 srcData->offset = std::min(checkedNbBytes, srcData->src_size); |
| 117 } | 117 } |
| 118 return OPJ_TRUE; | 118 return OPJ_TRUE; |
| 119 } | 119 } |
| 120 opj_stream_t* fx_opj_stream_create_memory_stream(DecodeData* data, | 120 opj_stream_t* fx_opj_stream_create_memory_stream(DecodeData* data, |
| 121 OPJ_SIZE_T p_size, | 121 OPJ_SIZE_T p_size, |
| 122 OPJ_BOOL p_is_read_stream) { | 122 OPJ_BOOL p_is_read_stream) { |
| 123 opj_stream_t* l_stream = 00; | 123 opj_stream_t* l_stream = 00; |
| 124 if (!data || !data->src_data || data->src_size <= 0) { | 124 if (!data || !data->src_data || data->src_size <= 0) { |
| 125 return NULL; | 125 return nullptr; |
| 126 } | 126 } |
| 127 l_stream = opj_stream_create(p_size, p_is_read_stream); | 127 l_stream = opj_stream_create(p_size, p_is_read_stream); |
| 128 if (!l_stream) { | 128 if (!l_stream) { |
| 129 return NULL; | 129 return nullptr; |
| 130 } | 130 } |
| 131 opj_stream_set_user_data(l_stream, data, NULL); | 131 opj_stream_set_user_data(l_stream, data, nullptr); |
| 132 opj_stream_set_user_data_length(l_stream, data->src_size); | 132 opj_stream_set_user_data_length(l_stream, data->src_size); |
| 133 opj_stream_set_read_function(l_stream, opj_read_from_memory); | 133 opj_stream_set_read_function(l_stream, opj_read_from_memory); |
| 134 opj_stream_set_write_function(l_stream, opj_write_from_memory); | 134 opj_stream_set_write_function(l_stream, opj_write_from_memory); |
| 135 opj_stream_set_skip_function(l_stream, opj_skip_from_memory); | 135 opj_stream_set_skip_function(l_stream, opj_skip_from_memory); |
| 136 opj_stream_set_seek_function(l_stream, opj_seek_from_memory); | 136 opj_stream_set_seek_function(l_stream, opj_seek_from_memory); |
| 137 return l_stream; | 137 return l_stream; |
| 138 } | 138 } |
| 139 static void sycc_to_rgb(int offset, | 139 static void sycc_to_rgb(int offset, |
| 140 int upb, | 140 int upb, |
| 141 int y, | 141 int y, |
| (...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 604 if (enumcs == 14) { | 604 if (enumcs == 14) { |
| 605 int *L, *a, *b, *red, *green, *blue, *src0, *src1, *src2; | 605 int *L, *a, *b, *red, *green, *blue, *src0, *src1, *src2; |
| 606 double rl, ol, ra, oa, rb, ob, prec0, prec1, prec2; | 606 double rl, ol, ra, oa, rb, ob, prec0, prec1, prec2; |
| 607 double minL, maxL, mina, maxa, minb, maxb; | 607 double minL, maxL, mina, maxa, minb, maxb; |
| 608 unsigned int default_type; | 608 unsigned int default_type; |
| 609 unsigned int i, max; | 609 unsigned int i, max; |
| 610 cmsHPROFILE in, out; | 610 cmsHPROFILE in, out; |
| 611 cmsHTRANSFORM transform; | 611 cmsHTRANSFORM transform; |
| 612 cmsUInt16Number RGB[3]; | 612 cmsUInt16Number RGB[3]; |
| 613 cmsCIELab Lab; | 613 cmsCIELab Lab; |
| 614 in = cmsCreateLab4Profile(NULL); | 614 in = cmsCreateLab4Profile(nullptr); |
| 615 out = cmsCreate_sRGBProfile(); | 615 out = cmsCreate_sRGBProfile(); |
| 616 transform = cmsCreateTransform(in, TYPE_Lab_DBL, out, TYPE_RGB_16, | 616 transform = cmsCreateTransform(in, TYPE_Lab_DBL, out, TYPE_RGB_16, |
| 617 INTENT_PERCEPTUAL, 0); | 617 INTENT_PERCEPTUAL, 0); |
| 618 cmsCloseProfile(in); | 618 cmsCloseProfile(in); |
| 619 cmsCloseProfile(out); | 619 cmsCloseProfile(out); |
| 620 if (!transform) { | 620 if (!transform) { |
| 621 return; | 621 return; |
| 622 } | 622 } |
| 623 prec0 = (double)image->comps[0].prec; | 623 prec0 = (double)image->comps[0].prec; |
| 624 prec1 = (double)image->comps[1].prec; | 624 prec1 = (double)image->comps[1].prec; |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 711 opj_image_destroy(image); | 711 opj_image_destroy(image); |
| 712 } | 712 } |
| 713 } | 713 } |
| 714 | 714 |
| 715 FX_BOOL CJPX_Decoder::Init(const unsigned char* src_data, uint32_t src_size) { | 715 FX_BOOL CJPX_Decoder::Init(const unsigned char* src_data, uint32_t src_size) { |
| 716 static const unsigned char szJP2Header[] = { | 716 static const unsigned char szJP2Header[] = { |
| 717 0x00, 0x00, 0x00, 0x0c, 0x6a, 0x50, 0x20, 0x20, 0x0d, 0x0a, 0x87, 0x0a}; | 717 0x00, 0x00, 0x00, 0x0c, 0x6a, 0x50, 0x20, 0x20, 0x0d, 0x0a, 0x87, 0x0a}; |
| 718 if (!src_data || src_size < sizeof(szJP2Header)) | 718 if (!src_data || src_size < sizeof(szJP2Header)) |
| 719 return FALSE; | 719 return FALSE; |
| 720 | 720 |
| 721 image = NULL; | 721 image = nullptr; |
| 722 m_SrcData = src_data; | 722 m_SrcData = src_data; |
| 723 m_SrcSize = src_size; | 723 m_SrcSize = src_size; |
| 724 DecodeData srcData(const_cast<unsigned char*>(src_data), src_size); | 724 DecodeData srcData(const_cast<unsigned char*>(src_data), src_size); |
| 725 l_stream = fx_opj_stream_create_memory_stream(&srcData, | 725 l_stream = fx_opj_stream_create_memory_stream(&srcData, |
| 726 OPJ_J2K_STREAM_CHUNK_SIZE, 1); | 726 OPJ_J2K_STREAM_CHUNK_SIZE, 1); |
| 727 if (!l_stream) { | 727 if (!l_stream) { |
| 728 return FALSE; | 728 return FALSE; |
| 729 } | 729 } |
| 730 opj_dparameters_t parameters; | 730 opj_dparameters_t parameters; |
| 731 opj_set_default_decoder_parameters(¶meters); | 731 opj_set_default_decoder_parameters(¶meters); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 742 } | 742 } |
| 743 if (m_ColorSpace && m_ColorSpace->GetFamily() == PDFCS_INDEXED) | 743 if (m_ColorSpace && m_ColorSpace->GetFamily() == PDFCS_INDEXED) |
| 744 parameters.flags |= OPJ_DPARAMETERS_IGNORE_PCLR_CMAP_CDEF_FLAG; | 744 parameters.flags |= OPJ_DPARAMETERS_IGNORE_PCLR_CMAP_CDEF_FLAG; |
| 745 opj_set_info_handler(l_codec, fx_info_callback, 00); | 745 opj_set_info_handler(l_codec, fx_info_callback, 00); |
| 746 opj_set_warning_handler(l_codec, fx_warning_callback, 00); | 746 opj_set_warning_handler(l_codec, fx_warning_callback, 00); |
| 747 opj_set_error_handler(l_codec, fx_error_callback, 00); | 747 opj_set_error_handler(l_codec, fx_error_callback, 00); |
| 748 if (!opj_setup_decoder(l_codec, ¶meters)) { | 748 if (!opj_setup_decoder(l_codec, ¶meters)) { |
| 749 return FALSE; | 749 return FALSE; |
| 750 } | 750 } |
| 751 if (!opj_read_header(l_stream, l_codec, &image)) { | 751 if (!opj_read_header(l_stream, l_codec, &image)) { |
| 752 image = NULL; | 752 image = nullptr; |
| 753 return FALSE; | 753 return FALSE; |
| 754 } | 754 } |
| 755 image->pdfium_use_colorspace = !!m_ColorSpace; | 755 image->pdfium_use_colorspace = !!m_ColorSpace; |
| 756 | 756 |
| 757 if (!parameters.nb_tile_to_decode) { | 757 if (!parameters.nb_tile_to_decode) { |
| 758 if (!opj_set_decode_area(l_codec, image, parameters.DA_x0, parameters.DA_y0, | 758 if (!opj_set_decode_area(l_codec, image, parameters.DA_x0, parameters.DA_y0, |
| 759 parameters.DA_x1, parameters.DA_y1)) { | 759 parameters.DA_x1, parameters.DA_y1)) { |
| 760 opj_image_destroy(image); | 760 opj_image_destroy(image); |
| 761 image = NULL; | 761 image = nullptr; |
| 762 return FALSE; | 762 return FALSE; |
| 763 } | 763 } |
| 764 if (!(opj_decode(l_codec, l_stream, image) && | 764 if (!(opj_decode(l_codec, l_stream, image) && |
| 765 opj_end_decompress(l_codec, l_stream))) { | 765 opj_end_decompress(l_codec, l_stream))) { |
| 766 opj_image_destroy(image); | 766 opj_image_destroy(image); |
| 767 image = NULL; | 767 image = nullptr; |
| 768 return FALSE; | 768 return FALSE; |
| 769 } | 769 } |
| 770 } else { | 770 } else { |
| 771 if (!opj_get_decoded_tile(l_codec, l_stream, image, | 771 if (!opj_get_decoded_tile(l_codec, l_stream, image, |
| 772 parameters.tile_index)) { | 772 parameters.tile_index)) { |
| 773 return FALSE; | 773 return FALSE; |
| 774 } | 774 } |
| 775 } | 775 } |
| 776 opj_stream_destroy(l_stream); | 776 opj_stream_destroy(l_stream); |
| 777 l_stream = NULL; | 777 l_stream = nullptr; |
| 778 if (image->color_space != OPJ_CLRSPC_SYCC && image->numcomps == 3 && | 778 if (image->color_space != OPJ_CLRSPC_SYCC && image->numcomps == 3 && |
| 779 image->comps[0].dx == image->comps[0].dy && image->comps[1].dx != 1) { | 779 image->comps[0].dx == image->comps[0].dy && image->comps[1].dx != 1) { |
| 780 image->color_space = OPJ_CLRSPC_SYCC; | 780 image->color_space = OPJ_CLRSPC_SYCC; |
| 781 } else if (image->numcomps <= 2) { | 781 } else if (image->numcomps <= 2) { |
| 782 image->color_space = OPJ_CLRSPC_GRAY; | 782 image->color_space = OPJ_CLRSPC_GRAY; |
| 783 } | 783 } |
| 784 if (image->color_space == OPJ_CLRSPC_SYCC) { | 784 if (image->color_space == OPJ_CLRSPC_SYCC) { |
| 785 color_sycc_to_rgb(image); | 785 color_sycc_to_rgb(image); |
| 786 } | 786 } |
| 787 if (image->icc_profile_buf) { | 787 if (image->icc_profile_buf) { |
| 788 FX_Free(image->icc_profile_buf); | 788 FX_Free(image->icc_profile_buf); |
| 789 image->icc_profile_buf = NULL; | 789 image->icc_profile_buf = nullptr; |
| 790 image->icc_profile_len = 0; | 790 image->icc_profile_len = 0; |
| 791 } | 791 } |
| 792 if (!image) { | 792 if (!image) { |
| 793 return FALSE; | 793 return FALSE; |
| 794 } | 794 } |
| 795 return TRUE; | 795 return TRUE; |
| 796 } | 796 } |
| 797 | 797 |
| 798 void CJPX_Decoder::GetInfo(uint32_t* width, | 798 void CJPX_Decoder::GetInfo(uint32_t* width, |
| 799 uint32_t* height, | 799 uint32_t* height, |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 897 bool CCodec_JpxModule::Decode(CJPX_Decoder* pDecoder, | 897 bool CCodec_JpxModule::Decode(CJPX_Decoder* pDecoder, |
| 898 uint8_t* dest_data, | 898 uint8_t* dest_data, |
| 899 int pitch, | 899 int pitch, |
| 900 const std::vector<uint8_t>& offsets) { | 900 const std::vector<uint8_t>& offsets) { |
| 901 return pDecoder->Decode(dest_data, pitch, offsets); | 901 return pDecoder->Decode(dest_data, pitch, offsets); |
| 902 } | 902 } |
| 903 | 903 |
| 904 void CCodec_JpxModule::DestroyDecoder(CJPX_Decoder* pDecoder) { | 904 void CCodec_JpxModule::DestroyDecoder(CJPX_Decoder* pDecoder) { |
| 905 delete pDecoder; | 905 delete pDecoder; |
| 906 } | 906 } |
| OLD | NEW |