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 598 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 CJPX_Decoder(); |
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, |
620 FX_DWORD& height, | 620 FX_DWORD* height, |
621 FX_DWORD& codestream_nComps, | 621 FX_DWORD* codestream_nComps, |
622 FX_DWORD& output_nComps); | 622 FX_DWORD* output_nComps); |
623 FX_BOOL Decode(uint8_t* dest_buf, | 623 FX_BOOL Decode(uint8_t* dest_buf, |
624 int pitch, | 624 int pitch, |
625 FX_BOOL bTranslateColor, | |
626 uint8_t* offsets); | 625 uint8_t* offsets); |
627 const uint8_t* m_SrcData; | 626 const uint8_t* m_SrcData; |
628 int m_SrcSize; | 627 int m_SrcSize; |
629 opj_image_t* image; | 628 opj_image_t* image; |
630 opj_codec_t* l_codec; | 629 opj_codec_t* l_codec; |
631 opj_stream_t* l_stream; | 630 opj_stream_t* l_stream; |
632 FX_BOOL m_useColorSpace; | 631 FX_BOOL m_useColorSpace; |
633 }; | 632 }; |
634 CJPX_Decoder::CJPX_Decoder() | 633 CJPX_Decoder::CJPX_Decoder() |
635 : image(NULL), l_codec(NULL), l_stream(NULL), m_useColorSpace(FALSE) {} | 634 : image(NULL), l_codec(NULL), l_stream(NULL), m_useColorSpace(FALSE) {} |
635 | |
636 CJPX_Decoder::~CJPX_Decoder() { | 636 CJPX_Decoder::~CJPX_Decoder() { |
637 if (l_codec) { | 637 if (l_codec) { |
638 opj_destroy_codec(l_codec); | 638 opj_destroy_codec(l_codec); |
639 } | 639 } |
640 if (l_stream) { | 640 if (l_stream) { |
641 opj_stream_destroy(l_stream); | 641 opj_stream_destroy(l_stream); |
642 } | 642 } |
643 if (image) { | 643 if (image) { |
644 opj_image_destroy(image); | 644 opj_image_destroy(image); |
645 } | 645 } |
646 } | 646 } |
647 | |
647 FX_BOOL CJPX_Decoder::Init(const unsigned char* src_data, int src_size) { | 648 FX_BOOL CJPX_Decoder::Init(const unsigned char* src_data, int src_size) { |
648 static const unsigned char szJP2Header[] = { | 649 static const unsigned char szJP2Header[] = { |
649 0x00, 0x00, 0x00, 0x0c, 0x6a, 0x50, 0x20, 0x20, 0x0d, 0x0a, 0x87, 0x0a}; | 650 0x00, 0x00, 0x00, 0x0c, 0x6a, 0x50, 0x20, 0x20, 0x0d, 0x0a, 0x87, 0x0a}; |
650 if (!src_data || src_size < sizeof(szJP2Header)) { | 651 if (!src_data || src_size < sizeof(szJP2Header)) { |
651 return FALSE; | 652 return FALSE; |
652 } | 653 } |
653 image = NULL; | 654 image = NULL; |
654 m_SrcData = src_data; | 655 m_SrcData = src_data; |
655 m_SrcSize = src_size; | 656 m_SrcSize = src_size; |
656 DecodeData srcData(const_cast<unsigned char*>(src_data), src_size); | 657 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) { | 716 if (image->icc_profile_buf) { |
716 FX_Free(image->icc_profile_buf); | 717 FX_Free(image->icc_profile_buf); |
717 image->icc_profile_buf = NULL; | 718 image->icc_profile_buf = NULL; |
718 image->icc_profile_len = 0; | 719 image->icc_profile_len = 0; |
719 } | 720 } |
720 if (!image) { | 721 if (!image) { |
721 return FALSE; | 722 return FALSE; |
722 } | 723 } |
723 return TRUE; | 724 return TRUE; |
724 } | 725 } |
725 void CJPX_Decoder::GetInfo(FX_DWORD& width, | 726 |
726 FX_DWORD& height, | 727 void CJPX_Decoder::GetInfo(FX_DWORD* width, |
727 FX_DWORD& codestream_nComps, | 728 FX_DWORD* height, |
728 FX_DWORD& output_nComps) { | 729 FX_DWORD* codestream_nComps, |
729 width = (FX_DWORD)image->x1; | 730 FX_DWORD* output_nComps) { |
730 height = (FX_DWORD)image->y1; | 731 *width = (FX_DWORD)image->x1; |
731 output_nComps = codestream_nComps = (FX_DWORD)image->numcomps; | 732 *height = (FX_DWORD)image->y1; |
733 *output_nComps = *codestream_nComps = (FX_DWORD)image->numcomps; | |
Tom Sepez
2015/09/01 21:38:48
nit: one per line.
| |
732 } | 734 } |
735 | |
733 FX_BOOL CJPX_Decoder::Decode(uint8_t* dest_buf, | 736 FX_BOOL CJPX_Decoder::Decode(uint8_t* dest_buf, |
734 int pitch, | 737 int pitch, |
735 FX_BOOL bTranslateColor, | |
736 uint8_t* offsets) { | 738 uint8_t* offsets) { |
737 int i, wid, hei, row, col, channel, src; | 739 int i, wid, hei, row, col, channel, src; |
738 uint8_t* pChannel; | 740 uint8_t* pChannel; |
739 uint8_t* pScanline; | 741 uint8_t* pScanline; |
740 uint8_t* pPixel; | 742 uint8_t* pPixel; |
741 | 743 |
742 if (image->comps[0].w != image->x1 || image->comps[0].h != image->y1) { | 744 if (image->comps[0].w != image->x1 || image->comps[0].h != image->y1) { |
743 return FALSE; | 745 return FALSE; |
744 } | 746 } |
745 if (pitch<(int)(image->comps[0].w * 8 * image->numcomps + 31)>> 5 << 2) { | 747 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 } | 810 } |
809 } | 811 } |
810 } | 812 } |
811 result = TRUE; | 813 result = TRUE; |
812 | 814 |
813 done: | 815 done: |
814 FX_Free(channel_bufs); | 816 FX_Free(channel_bufs); |
815 FX_Free(adjust_comps); | 817 FX_Free(adjust_comps); |
816 return result; | 818 return result; |
817 } | 819 } |
820 | |
818 void initialize_transition_table(); | 821 void initialize_transition_table(); |
Tom Sepez
2015/09/01 21:38:48
nit: for another day, which header do these belong
Lei Zhang
2015/09/01 22:06:26
It's dead code. Will remove in patch set 4.
| |
819 void initialize_significance_luts(); | 822 void initialize_significance_luts(); |
820 void initialize_sign_lut(); | 823 void initialize_sign_lut(); |
824 | |
821 CCodec_JpxModule::CCodec_JpxModule() {} | 825 CCodec_JpxModule::CCodec_JpxModule() {} |
826 CCodec_JpxModule::~CCodec_JpxModule() { | |
Lei Zhang
2015/09/01 21:31:50
git cl format has changed and is now being inconsi
Tom Sepez
2015/09/01 21:38:48
Sigh.
| |
827 } | |
828 | |
822 void* CCodec_JpxModule::CreateDecoder(const uint8_t* src_buf, | 829 void* CCodec_JpxModule::CreateDecoder(const uint8_t* src_buf, |
823 FX_DWORD src_size, | 830 FX_DWORD src_size, |
824 FX_BOOL useColorSpace) { | 831 FX_BOOL useColorSpace) { |
825 CJPX_Decoder* pDecoder = new CJPX_Decoder; | 832 nonstd::unique_ptr<CJPX_Decoder> decoder(new CJPX_Decoder); |
826 pDecoder->m_useColorSpace = useColorSpace; | 833 decoder->m_useColorSpace = useColorSpace; |
Tom Sepez
2015/09/01 21:38:48
nit: shoule useColorSpace be an argument to the CT
Lei Zhang
2015/09/01 22:06:27
It's going away in patch set 3.
| |
827 if (!pDecoder->Init(src_buf, src_size)) { | 834 return decoder->Init(src_buf, src_size) ? decoder.release() : nullptr; |
828 delete pDecoder; | |
829 return NULL; | |
830 } | |
831 return pDecoder; | |
832 } | 835 } |
836 | |
833 void CCodec_JpxModule::GetImageInfo(void* ctx, | 837 void CCodec_JpxModule::GetImageInfo(void* ctx, |
834 FX_DWORD& width, | 838 FX_DWORD* width, |
835 FX_DWORD& height, | 839 FX_DWORD* height, |
836 FX_DWORD& codestream_nComps, | 840 FX_DWORD* codestream_nComps, |
837 FX_DWORD& output_nComps) { | 841 FX_DWORD* output_nComps) { |
838 CJPX_Decoder* pDecoder = (CJPX_Decoder*)ctx; | 842 CJPX_Decoder* pDecoder = (CJPX_Decoder*)ctx; |
839 pDecoder->GetInfo(width, height, codestream_nComps, output_nComps); | 843 pDecoder->GetInfo(width, height, codestream_nComps, output_nComps); |
840 } | 844 } |
845 | |
841 FX_BOOL CCodec_JpxModule::Decode(void* ctx, | 846 FX_BOOL CCodec_JpxModule::Decode(void* ctx, |
842 uint8_t* dest_data, | 847 uint8_t* dest_data, |
843 int pitch, | 848 int pitch, |
844 FX_BOOL bTranslateColor, | |
845 uint8_t* offsets) { | 849 uint8_t* offsets) { |
846 CJPX_Decoder* pDecoder = (CJPX_Decoder*)ctx; | 850 CJPX_Decoder* pDecoder = (CJPX_Decoder*)ctx; |
847 return pDecoder->Decode(dest_data, pitch, bTranslateColor, offsets); | 851 return pDecoder->Decode(dest_data, pitch, offsets); |
848 } | 852 } |
853 | |
849 void CCodec_JpxModule::DestroyDecoder(void* ctx) { | 854 void CCodec_JpxModule::DestroyDecoder(void* ctx) { |
850 CJPX_Decoder* pDecoder = (CJPX_Decoder*)ctx; | 855 CJPX_Decoder* pDecoder = (CJPX_Decoder*)ctx; |
851 delete pDecoder; | 856 delete pDecoder; |
852 } | 857 } |
OLD | NEW |