| 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 598 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 609 image->comps[0].prec = 16; | 609 image->comps[0].prec = 16; |
| 610 image->comps[1].prec = 16; | 610 image->comps[1].prec = 16; |
| 611 image->comps[2].prec = 16; | 611 image->comps[2].prec = 16; |
| 612 return; | 612 return; |
| 613 } | 613 } |
| 614 } | 614 } |
| 615 class CJPX_Decoder { | 615 class CJPX_Decoder { |
| 616 public: | 616 public: |
| 617 explicit CJPX_Decoder(bool use_colorspace); | 617 explicit CJPX_Decoder(bool use_colorspace); |
| 618 ~CJPX_Decoder(); | 618 ~CJPX_Decoder(); |
| 619 FX_BOOL Init(const unsigned char* src_data, int src_size); | 619 FX_BOOL Init(const unsigned char* src_data, FX_DWORD src_size); |
| 620 void GetInfo(FX_DWORD* width, FX_DWORD* height, FX_DWORD* components); | 620 void GetInfo(FX_DWORD* width, FX_DWORD* height, FX_DWORD* components); |
| 621 bool Decode(uint8_t* dest_buf, | 621 bool Decode(uint8_t* dest_buf, |
| 622 int pitch, | 622 int pitch, |
| 623 const std::vector<uint8_t>& offsets); | 623 const std::vector<uint8_t>& offsets); |
| 624 | 624 |
| 625 private: | 625 private: |
| 626 const uint8_t* m_SrcData; | 626 const uint8_t* m_SrcData; |
| 627 int m_SrcSize; | 627 FX_DWORD m_SrcSize; |
| 628 opj_image_t* image; | 628 opj_image_t* image; |
| 629 opj_codec_t* l_codec; | 629 opj_codec_t* l_codec; |
| 630 opj_stream_t* l_stream; | 630 opj_stream_t* l_stream; |
| 631 const bool m_UseColorSpace; | 631 const bool m_UseColorSpace; |
| 632 }; | 632 }; |
| 633 | 633 |
| 634 CJPX_Decoder::CJPX_Decoder(bool use_colorspace) | 634 CJPX_Decoder::CJPX_Decoder(bool use_colorspace) |
| 635 : image(nullptr), | 635 : image(nullptr), |
| 636 l_codec(nullptr), | 636 l_codec(nullptr), |
| 637 l_stream(nullptr), | 637 l_stream(nullptr), |
| 638 m_UseColorSpace(use_colorspace) { | 638 m_UseColorSpace(use_colorspace) { |
| 639 } | 639 } |
| 640 | 640 |
| 641 CJPX_Decoder::~CJPX_Decoder() { | 641 CJPX_Decoder::~CJPX_Decoder() { |
| 642 if (l_codec) { | 642 if (l_codec) { |
| 643 opj_destroy_codec(l_codec); | 643 opj_destroy_codec(l_codec); |
| 644 } | 644 } |
| 645 if (l_stream) { | 645 if (l_stream) { |
| 646 opj_stream_destroy(l_stream); | 646 opj_stream_destroy(l_stream); |
| 647 } | 647 } |
| 648 if (image) { | 648 if (image) { |
| 649 opj_image_destroy(image); | 649 opj_image_destroy(image); |
| 650 } | 650 } |
| 651 } | 651 } |
| 652 | 652 |
| 653 FX_BOOL CJPX_Decoder::Init(const unsigned char* src_data, int src_size) { | 653 FX_BOOL CJPX_Decoder::Init(const unsigned char* src_data, FX_DWORD src_size) { |
| 654 static const unsigned char szJP2Header[] = { | 654 static const unsigned char szJP2Header[] = { |
| 655 0x00, 0x00, 0x00, 0x0c, 0x6a, 0x50, 0x20, 0x20, 0x0d, 0x0a, 0x87, 0x0a}; | 655 0x00, 0x00, 0x00, 0x0c, 0x6a, 0x50, 0x20, 0x20, 0x0d, 0x0a, 0x87, 0x0a}; |
| 656 if (!src_data || src_size < sizeof(szJP2Header)) { | 656 if (!src_data || src_size < sizeof(szJP2Header)) |
| 657 return FALSE; | 657 return FALSE; |
| 658 } | 658 |
| 659 image = NULL; | 659 image = NULL; |
| 660 m_SrcData = src_data; | 660 m_SrcData = src_data; |
| 661 m_SrcSize = src_size; | 661 m_SrcSize = src_size; |
| 662 DecodeData srcData(const_cast<unsigned char*>(src_data), src_size); | 662 DecodeData srcData(const_cast<unsigned char*>(src_data), src_size); |
| 663 l_stream = fx_opj_stream_create_memory_stream(&srcData, | 663 l_stream = fx_opj_stream_create_memory_stream(&srcData, |
| 664 OPJ_J2K_STREAM_CHUNK_SIZE, 1); | 664 OPJ_J2K_STREAM_CHUNK_SIZE, 1); |
| 665 if (l_stream == NULL) { | 665 if (l_stream == NULL) { |
| 666 return FALSE; | 666 return FALSE; |
| 667 } | 667 } |
| 668 opj_dparameters_t parameters; | 668 opj_dparameters_t parameters; |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 834 bool CCodec_JpxModule::Decode(CJPX_Decoder* pDecoder, | 834 bool CCodec_JpxModule::Decode(CJPX_Decoder* pDecoder, |
| 835 uint8_t* dest_data, | 835 uint8_t* dest_data, |
| 836 int pitch, | 836 int pitch, |
| 837 const std::vector<uint8_t>& offsets) { | 837 const std::vector<uint8_t>& offsets) { |
| 838 return pDecoder->Decode(dest_data, pitch, offsets); | 838 return pDecoder->Decode(dest_data, pitch, offsets); |
| 839 } | 839 } |
| 840 | 840 |
| 841 void CCodec_JpxModule::DestroyDecoder(CJPX_Decoder* pDecoder) { | 841 void CCodec_JpxModule::DestroyDecoder(CJPX_Decoder* pDecoder) { |
| 842 delete pDecoder; | 842 delete pDecoder; |
| 843 } | 843 } |
| OLD | NEW |