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 597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 explicit CJPX_Decoder(bool use_colorspace); | 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, FX_DWORD src_size); |
619 void GetInfo(FX_DWORD* width, FX_DWORD* height, FX_DWORD* components); | 619 void GetInfo(FX_DWORD* width, FX_DWORD* height, FX_DWORD* components); |
620 FX_BOOL Decode(uint8_t* dest_buf, | 620 FX_BOOL Decode(uint8_t* dest_buf, |
621 int pitch, | 621 int pitch, |
622 uint8_t* offsets); | 622 uint8_t* offsets); |
623 | 623 |
624 private: | 624 private: |
625 const uint8_t* m_SrcData; | 625 const uint8_t* m_SrcData; |
626 int m_SrcSize; | 626 FX_DWORD m_SrcSize; |
627 opj_image_t* image; | 627 opj_image_t* image; |
628 opj_codec_t* l_codec; | 628 opj_codec_t* l_codec; |
629 opj_stream_t* l_stream; | 629 opj_stream_t* l_stream; |
630 const bool m_UseColorSpace; | 630 const bool m_UseColorSpace; |
631 }; | 631 }; |
632 | 632 |
633 CJPX_Decoder::CJPX_Decoder(bool use_colorspace) | 633 CJPX_Decoder::CJPX_Decoder(bool use_colorspace) |
634 : image(nullptr), | 634 : image(nullptr), |
635 l_codec(nullptr), | 635 l_codec(nullptr), |
636 l_stream(nullptr), | 636 l_stream(nullptr), |
637 m_UseColorSpace(use_colorspace) { | 637 m_UseColorSpace(use_colorspace) { |
638 } | 638 } |
639 | 639 |
640 CJPX_Decoder::~CJPX_Decoder() { | 640 CJPX_Decoder::~CJPX_Decoder() { |
641 if (l_codec) { | 641 if (l_codec) { |
642 opj_destroy_codec(l_codec); | 642 opj_destroy_codec(l_codec); |
643 } | 643 } |
644 if (l_stream) { | 644 if (l_stream) { |
645 opj_stream_destroy(l_stream); | 645 opj_stream_destroy(l_stream); |
646 } | 646 } |
647 if (image) { | 647 if (image) { |
648 opj_image_destroy(image); | 648 opj_image_destroy(image); |
649 } | 649 } |
650 } | 650 } |
651 | 651 |
652 FX_BOOL CJPX_Decoder::Init(const unsigned char* src_data, int src_size) { | 652 FX_BOOL CJPX_Decoder::Init(const unsigned char* src_data, FX_DWORD src_size) { |
653 static const unsigned char szJP2Header[] = { | 653 static const unsigned char szJP2Header[] = { |
654 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}; |
655 if (!src_data || src_size < sizeof(szJP2Header)) { | 655 if (!src_data || src_size < sizeof(szJP2Header)) |
656 return FALSE; | 656 return FALSE; |
657 } | 657 |
658 image = NULL; | 658 image = NULL; |
659 m_SrcData = src_data; | 659 m_SrcData = src_data; |
660 m_SrcSize = src_size; | 660 m_SrcSize = src_size; |
661 DecodeData srcData(const_cast<unsigned char*>(src_data), src_size); | 661 DecodeData srcData(const_cast<unsigned char*>(src_data), src_size); |
662 l_stream = fx_opj_stream_create_memory_stream(&srcData, | 662 l_stream = fx_opj_stream_create_memory_stream(&srcData, |
663 OPJ_J2K_STREAM_CHUNK_SIZE, 1); | 663 OPJ_J2K_STREAM_CHUNK_SIZE, 1); |
664 if (l_stream == NULL) { | 664 if (l_stream == NULL) { |
665 return FALSE; | 665 return FALSE; |
666 } | 666 } |
667 opj_dparameters_t parameters; | 667 opj_dparameters_t parameters; |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
844 FX_BOOL CCodec_JpxModule::Decode(CJPX_Decoder* pDecoder, | 844 FX_BOOL CCodec_JpxModule::Decode(CJPX_Decoder* pDecoder, |
845 uint8_t* dest_data, | 845 uint8_t* dest_data, |
846 int pitch, | 846 int pitch, |
847 uint8_t* offsets) { | 847 uint8_t* offsets) { |
848 return pDecoder->Decode(dest_data, pitch, offsets); | 848 return pDecoder->Decode(dest_data, pitch, offsets); |
849 } | 849 } |
850 | 850 |
851 void CCodec_JpxModule::DestroyDecoder(CJPX_Decoder* pDecoder) { | 851 void CCodec_JpxModule::DestroyDecoder(CJPX_Decoder* pDecoder) { |
852 delete pDecoder; | 852 delete pDecoder; |
853 } | 853 } |
OLD | NEW |