| 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 | 9 |
| 10 #include "../../../../third_party/lcms2-2.6/include/lcms2.h" | 10 #include "../../../../third_party/lcms2-2.6/include/lcms2.h" |
| (...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 606 FX_Free(src2); | 606 FX_Free(src2); |
| 607 image->color_space = OPJ_CLRSPC_SRGB; | 607 image->color_space = OPJ_CLRSPC_SRGB; |
| 608 image->comps[0].prec = 16; | 608 image->comps[0].prec = 16; |
| 609 image->comps[1].prec = 16; | 609 image->comps[1].prec = 16; |
| 610 image->comps[2].prec = 16; | 610 image->comps[2].prec = 16; |
| 611 return; | 611 return; |
| 612 } | 612 } |
| 613 } | 613 } |
| 614 class CJPX_Decoder { | 614 class CJPX_Decoder { |
| 615 public: | 615 public: |
| 616 CJPX_Decoder(); | 616 explicit CJPX_Decoder(bool use_colorspace); |
| 617 ~CJPX_Decoder(); | 617 ~CJPX_Decoder(); |
| 618 FX_BOOL Init(const unsigned char* src_data, int src_size); | 618 FX_BOOL Init(const unsigned char* src_data, int src_size); |
| 619 void GetInfo(FX_DWORD& width, | 619 void GetInfo(FX_DWORD* width, FX_DWORD* height, FX_DWORD* components); |
| 620 FX_DWORD& height, | |
| 621 FX_DWORD& codestream_nComps, | |
| 622 FX_DWORD& output_nComps); | |
| 623 FX_BOOL Decode(uint8_t* dest_buf, | 620 FX_BOOL Decode(uint8_t* dest_buf, |
| 624 int pitch, | 621 int pitch, |
| 625 FX_BOOL bTranslateColor, | |
| 626 uint8_t* offsets); | 622 uint8_t* offsets); |
| 623 |
| 624 private: |
| 627 const uint8_t* m_SrcData; | 625 const uint8_t* m_SrcData; |
| 628 int m_SrcSize; | 626 int m_SrcSize; |
| 629 opj_image_t* image; | 627 opj_image_t* image; |
| 630 opj_codec_t* l_codec; | 628 opj_codec_t* l_codec; |
| 631 opj_stream_t* l_stream; | 629 opj_stream_t* l_stream; |
| 632 FX_BOOL m_useColorSpace; | 630 bool m_UseColorSpace; |
| 633 }; | 631 }; |
| 634 CJPX_Decoder::CJPX_Decoder() | 632 |
| 635 : image(NULL), l_codec(NULL), l_stream(NULL), m_useColorSpace(FALSE) {} | 633 CJPX_Decoder::CJPX_Decoder(bool use_colorspace) |
| 634 : image(nullptr), |
| 635 l_codec(nullptr), |
| 636 l_stream(nullptr), |
| 637 m_UseColorSpace(use_colorspace) { |
| 638 } |
| 639 |
| 636 CJPX_Decoder::~CJPX_Decoder() { | 640 CJPX_Decoder::~CJPX_Decoder() { |
| 637 if (l_codec) { | 641 if (l_codec) { |
| 638 opj_destroy_codec(l_codec); | 642 opj_destroy_codec(l_codec); |
| 639 } | 643 } |
| 640 if (l_stream) { | 644 if (l_stream) { |
| 641 opj_stream_destroy(l_stream); | 645 opj_stream_destroy(l_stream); |
| 642 } | 646 } |
| 643 if (image) { | 647 if (image) { |
| 644 opj_image_destroy(image); | 648 opj_image_destroy(image); |
| 645 } | 649 } |
| 646 } | 650 } |
| 651 |
| 647 FX_BOOL CJPX_Decoder::Init(const unsigned char* src_data, int src_size) { | 652 FX_BOOL CJPX_Decoder::Init(const unsigned char* src_data, int src_size) { |
| 648 static const unsigned char szJP2Header[] = { | 653 static const unsigned char szJP2Header[] = { |
| 649 0x00, 0x00, 0x00, 0x0c, 0x6a, 0x50, 0x20, 0x20, 0x0d, 0x0a, 0x87, 0x0a}; | 654 0x00, 0x00, 0x00, 0x0c, 0x6a, 0x50, 0x20, 0x20, 0x0d, 0x0a, 0x87, 0x0a}; |
| 650 if (!src_data || src_size < sizeof(szJP2Header)) { | 655 if (!src_data || src_size < sizeof(szJP2Header)) { |
| 651 return FALSE; | 656 return FALSE; |
| 652 } | 657 } |
| 653 image = NULL; | 658 image = NULL; |
| 654 m_SrcData = src_data; | 659 m_SrcData = src_data; |
| 655 m_SrcSize = src_size; | 660 m_SrcSize = src_size; |
| 656 DecodeData srcData(const_cast<unsigned char*>(src_data), src_size); | 661 DecodeData srcData(const_cast<unsigned char*>(src_data), src_size); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 715 if (image->icc_profile_buf) { | 720 if (image->icc_profile_buf) { |
| 716 FX_Free(image->icc_profile_buf); | 721 FX_Free(image->icc_profile_buf); |
| 717 image->icc_profile_buf = NULL; | 722 image->icc_profile_buf = NULL; |
| 718 image->icc_profile_len = 0; | 723 image->icc_profile_len = 0; |
| 719 } | 724 } |
| 720 if (!image) { | 725 if (!image) { |
| 721 return FALSE; | 726 return FALSE; |
| 722 } | 727 } |
| 723 return TRUE; | 728 return TRUE; |
| 724 } | 729 } |
| 725 void CJPX_Decoder::GetInfo(FX_DWORD& width, | 730 |
| 726 FX_DWORD& height, | 731 void CJPX_Decoder::GetInfo(FX_DWORD* width, |
| 727 FX_DWORD& codestream_nComps, | 732 FX_DWORD* height, |
| 728 FX_DWORD& output_nComps) { | 733 FX_DWORD* components) { |
| 729 width = (FX_DWORD)image->x1; | 734 *width = (FX_DWORD)image->x1; |
| 730 height = (FX_DWORD)image->y1; | 735 *height = (FX_DWORD)image->y1; |
| 731 output_nComps = codestream_nComps = (FX_DWORD)image->numcomps; | 736 *components = (FX_DWORD)image->numcomps; |
| 732 } | 737 } |
| 738 |
| 733 FX_BOOL CJPX_Decoder::Decode(uint8_t* dest_buf, | 739 FX_BOOL CJPX_Decoder::Decode(uint8_t* dest_buf, |
| 734 int pitch, | 740 int pitch, |
| 735 FX_BOOL bTranslateColor, | |
| 736 uint8_t* offsets) { | 741 uint8_t* offsets) { |
| 737 int i, wid, hei, row, col, channel, src; | 742 int i, wid, hei, row, col, channel, src; |
| 738 uint8_t* pChannel; | 743 uint8_t* pChannel; |
| 739 uint8_t* pScanline; | 744 uint8_t* pScanline; |
| 740 uint8_t* pPixel; | 745 uint8_t* pPixel; |
| 741 | 746 |
| 742 if (image->comps[0].w != image->x1 || image->comps[0].h != image->y1) { | 747 if (image->comps[0].w != image->x1 || image->comps[0].h != image->y1) { |
| 743 return FALSE; | 748 return FALSE; |
| 744 } | 749 } |
| 745 if (pitch<(int)(image->comps[0].w * 8 * image->numcomps + 31)>> 5 << 2) { | 750 if (pitch<(int)(image->comps[0].w * 8 * image->numcomps + 31)>> 5 << 2) { |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 808 } | 813 } |
| 809 } | 814 } |
| 810 } | 815 } |
| 811 result = TRUE; | 816 result = TRUE; |
| 812 | 817 |
| 813 done: | 818 done: |
| 814 FX_Free(channel_bufs); | 819 FX_Free(channel_bufs); |
| 815 FX_Free(adjust_comps); | 820 FX_Free(adjust_comps); |
| 816 return result; | 821 return result; |
| 817 } | 822 } |
| 818 void initialize_transition_table(); | 823 |
| 819 void initialize_significance_luts(); | |
| 820 void initialize_sign_lut(); | |
| 821 CCodec_JpxModule::CCodec_JpxModule() {} | 824 CCodec_JpxModule::CCodec_JpxModule() {} |
| 822 void* CCodec_JpxModule::CreateDecoder(const uint8_t* src_buf, | 825 CCodec_JpxModule::~CCodec_JpxModule() { |
| 823 FX_DWORD src_size, | |
| 824 FX_BOOL useColorSpace) { | |
| 825 CJPX_Decoder* pDecoder = new CJPX_Decoder; | |
| 826 pDecoder->m_useColorSpace = useColorSpace; | |
| 827 if (!pDecoder->Init(src_buf, src_size)) { | |
| 828 delete pDecoder; | |
| 829 return NULL; | |
| 830 } | |
| 831 return pDecoder; | |
| 832 } | 826 } |
| 833 void CCodec_JpxModule::GetImageInfo(void* ctx, | 827 |
| 834 FX_DWORD& width, | 828 CJPX_Decoder* CCodec_JpxModule::CreateDecoder(const uint8_t* src_buf, |
| 835 FX_DWORD& height, | 829 FX_DWORD src_size, |
| 836 FX_DWORD& codestream_nComps, | 830 bool use_colorspace) { |
| 837 FX_DWORD& output_nComps) { | 831 nonstd::unique_ptr<CJPX_Decoder> decoder(new CJPX_Decoder(use_colorspace)); |
| 838 CJPX_Decoder* pDecoder = (CJPX_Decoder*)ctx; | 832 return decoder->Init(src_buf, src_size) ? decoder.release() : nullptr; |
| 839 pDecoder->GetInfo(width, height, codestream_nComps, output_nComps); | |
| 840 } | 833 } |
| 841 FX_BOOL CCodec_JpxModule::Decode(void* ctx, | 834 |
| 835 void CCodec_JpxModule::GetImageInfo(CJPX_Decoder* pDecoder, |
| 836 FX_DWORD* width, |
| 837 FX_DWORD* height, |
| 838 FX_DWORD* components) { |
| 839 pDecoder->GetInfo(width, height, components); |
| 840 } |
| 841 |
| 842 FX_BOOL CCodec_JpxModule::Decode(CJPX_Decoder* pDecoder, |
| 842 uint8_t* dest_data, | 843 uint8_t* dest_data, |
| 843 int pitch, | 844 int pitch, |
| 844 FX_BOOL bTranslateColor, | |
| 845 uint8_t* offsets) { | 845 uint8_t* offsets) { |
| 846 CJPX_Decoder* pDecoder = (CJPX_Decoder*)ctx; | 846 return pDecoder->Decode(dest_data, pitch, offsets); |
| 847 return pDecoder->Decode(dest_data, pitch, bTranslateColor, offsets); | |
| 848 } | 847 } |
| 849 void CCodec_JpxModule::DestroyDecoder(void* ctx) { | 848 |
| 850 CJPX_Decoder* pDecoder = (CJPX_Decoder*)ctx; | 849 void CCodec_JpxModule::DestroyDecoder(CJPX_Decoder* pDecoder) { |
| 851 delete pDecoder; | 850 delete pDecoder; |
| 852 } | 851 } |
| OLD | NEW |