| 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 "../../../include/fxcodec/fx_codec.h" | 7 #include "../../../include/fxcodec/fx_codec.h" |
| 8 #include "codec_int.h" | 8 #include "codec_int.h" |
| 9 #include "../fx_libopenjpeg/libopenjpeg20/openjpeg.h" | 9 #include "../fx_libopenjpeg/libopenjpeg20/openjpeg.h" |
| 10 #include "../lcms2/include/fx_lcms2.h" | 10 #include "../lcms2/include/fx_lcms2.h" |
| (...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 574 } | 574 } |
| 575 if(l_stream) { | 575 if(l_stream) { |
| 576 opj_stream_destroy(l_stream); | 576 opj_stream_destroy(l_stream); |
| 577 } | 577 } |
| 578 if(image) { | 578 if(image) { |
| 579 opj_image_destroy(image); | 579 opj_image_destroy(image); |
| 580 } | 580 } |
| 581 } | 581 } |
| 582 FX_BOOL CJPX_Decoder::Init(const unsigned char* src_data, int src_size) | 582 FX_BOOL CJPX_Decoder::Init(const unsigned char* src_data, int src_size) |
| 583 { | 583 { |
| 584 opj_dparameters_t parameters; | 584 static const unsigned char szJP2Header[] = { 0x00, 0x00, 0x00, 0x0c, 0x6a, 0
x50, 0x20, 0x20, 0x0d, 0x0a, 0x87, 0x0a }; |
| 585 if (!src_data || src_size < sizeof(szJP2Header)) { |
| 586 return FALSE; |
| 587 } |
| 585 image = NULL; | 588 image = NULL; |
| 586 m_SrcData = src_data; | 589 m_SrcData = src_data; |
| 587 m_SrcSize = src_size; | 590 m_SrcSize = src_size; |
| 588 decodeData srcData; | 591 decodeData srcData; |
| 589 srcData.offset = 0; | 592 srcData.offset = 0; |
| 590 srcData.src_size = src_size; | 593 srcData.src_size = src_size; |
| 591 srcData.src_data = src_data; | 594 srcData.src_data = src_data; |
| 592 l_stream = fx_opj_stream_create_memory_stream(&srcData, OPJ_J2K_STREAM_CHUNK
_SIZE, 1); | 595 l_stream = fx_opj_stream_create_memory_stream(&srcData, OPJ_J2K_STREAM_CHUNK
_SIZE, 1); |
| 593 if (l_stream == NULL) { | 596 if (l_stream == NULL) { |
| 594 return FALSE; | 597 return FALSE; |
| 595 } | 598 } |
| 599 opj_dparameters_t parameters; |
| 596 opj_set_default_decoder_parameters(¶meters); | 600 opj_set_default_decoder_parameters(¶meters); |
| 597 parameters.decod_format = 0; | 601 parameters.decod_format = 0; |
| 598 parameters.cod_format = 3; | 602 parameters.cod_format = 3; |
| 599 if(FXSYS_memcmp32(m_SrcData, "\x00\x00\x00\x0c\x6a\x50\x20\x20\x0d\x0a\x87\x
0a", 12) == 0) { | 603 if(FXSYS_memcmp32(m_SrcData, szJP2Header, sizeof(szJP2Header)) == 0) { |
| 600 l_codec = opj_create_decompress(OPJ_CODEC_JP2); | 604 l_codec = opj_create_decompress(OPJ_CODEC_JP2); |
| 601 parameters.decod_format = 1; | 605 parameters.decod_format = 1; |
| 602 } else { | 606 } else { |
| 603 l_codec = opj_create_decompress(OPJ_CODEC_J2K); | 607 l_codec = opj_create_decompress(OPJ_CODEC_J2K); |
| 604 } | 608 } |
| 605 if(!l_codec) { | 609 if(!l_codec) { |
| 606 return FALSE; | 610 return FALSE; |
| 607 } | 611 } |
| 608 opj_set_info_handler(l_codec, fx_info_callback, 00); | 612 opj_set_info_handler(l_codec, fx_info_callback, 00); |
| 609 opj_set_warning_handler(l_codec, fx_warning_callback, 00); | 613 opj_set_warning_handler(l_codec, fx_warning_callback, 00); |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 782 FX_BOOL CCodec_JpxModule::Decode(void* ctx, FX_LPBYTE dest_data, int pitch, FX_B
OOL bTranslateColor, FX_LPBYTE offsets) | 786 FX_BOOL CCodec_JpxModule::Decode(void* ctx, FX_LPBYTE dest_data, int pitch, FX_B
OOL bTranslateColor, FX_LPBYTE offsets) |
| 783 { | 787 { |
| 784 CJPX_Decoder* pDecoder = (CJPX_Decoder*)ctx; | 788 CJPX_Decoder* pDecoder = (CJPX_Decoder*)ctx; |
| 785 return pDecoder->Decode(dest_data, pitch, bTranslateColor, offsets); | 789 return pDecoder->Decode(dest_data, pitch, bTranslateColor, offsets); |
| 786 } | 790 } |
| 787 void CCodec_JpxModule::DestroyDecoder(void* ctx) | 791 void CCodec_JpxModule::DestroyDecoder(void* ctx) |
| 788 { | 792 { |
| 789 CJPX_Decoder* pDecoder = (CJPX_Decoder*)ctx; | 793 CJPX_Decoder* pDecoder = (CJPX_Decoder*)ctx; |
| 790 delete pDecoder; | 794 delete pDecoder; |
| 791 } | 795 } |
| OLD | NEW |