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 22 matching lines...) Expand all Loading... | |
33 } | 33 } |
34 OPJ_SIZE_T bufferLength = srcData->src_size - srcData->offset; | 34 OPJ_SIZE_T bufferLength = srcData->src_size - srcData->offset; |
35 OPJ_SIZE_T readlength = p_nb_bytes < bufferLength ? p_nb_bytes : bufferLengt h; | 35 OPJ_SIZE_T readlength = p_nb_bytes < bufferLength ? p_nb_bytes : bufferLengt h; |
36 memcpy(p_buffer, &srcData->src_data[srcData->offset], readlength); | 36 memcpy(p_buffer, &srcData->src_data[srcData->offset], readlength); |
37 srcData->offset += readlength; | 37 srcData->offset += readlength; |
38 return readlength; | 38 return readlength; |
39 } | 39 } |
40 static OPJ_SIZE_T opj_write_from_memory (void * p_buffer, OPJ_SIZE_T p_nb_bytes, void* p_user_data) | 40 static OPJ_SIZE_T opj_write_from_memory (void * p_buffer, OPJ_SIZE_T p_nb_bytes, void* p_user_data) |
41 { | 41 { |
42 DecodeData* srcData = static_cast<DecodeData*>(p_user_data); | 42 DecodeData* srcData = static_cast<DecodeData*>(p_user_data); |
43 if (srcData == NULL || srcData->src_size == 0 || srcData->src_data == NULL | | srcData->offset >= srcData->src_size) { | 43 if (srcData == NULL || srcData->src_size == 0 || srcData->src_data == NULL | | srcData->offset >= srcData->src_size) { |
Tom Sepez
2015/03/11 18:29:12
Also, per the spec, a fseek() beyond EOF followed
jun_fang
2015/03/11 21:14:41
I think that the checking |srcData->offset >= srcD
| |
44 return -1; | 44 return -1; |
45 } | 45 } |
46 OPJ_SIZE_T bufferLength = srcData->src_size - srcData->offset; | 46 OPJ_SIZE_T bufferLength = srcData->src_size - srcData->offset; |
47 OPJ_SIZE_T writeLength = p_nb_bytes < bufferLength ? p_nb_bytes : bufferLeng th; | 47 OPJ_SIZE_T writeLength = p_nb_bytes < bufferLength ? p_nb_bytes : bufferLeng th; |
48 memcpy(&srcData->src_data[srcData->offset], p_buffer, writeLength); | 48 memcpy(&srcData->src_data[srcData->offset], p_buffer, writeLength); |
49 srcData->offset += writeLength; | 49 srcData->offset += writeLength; |
50 return writeLength; | 50 return writeLength; |
51 } | 51 } |
52 static OPJ_OFF_T opj_skip_from_memory (OPJ_OFF_T p_nb_bytes, void* p_user_data) | 52 static OPJ_OFF_T opj_skip_from_memory (OPJ_OFF_T p_nb_bytes, void* p_user_data) |
53 { | 53 { |
54 DecodeData* srcData = static_cast<DecodeData*>(p_user_data); | 54 DecodeData* srcData = static_cast<DecodeData*>(p_user_data); |
55 if (srcData == NULL || srcData->src_size == 0 || srcData->src_data == NULL | | srcData->offset >= srcData->src_size) { | 55 if (srcData == NULL || srcData->src_size == 0 || srcData->src_data == NULL) { |
56 return -1; | 56 return -1; |
57 } | 57 } |
58 if (srcData->offset >= srcData->src_size) { | |
59 return p_nb_bytes; | |
Tom Sepez
2015/03/11 18:25:41
I think we have to adjust the offset here, for exa
jun_fang
2015/03/11 21:14:41
Acknowledged.
| |
60 } | |
58 OPJ_SIZE_T bufferLength = srcData->src_size - srcData->offset; | 61 OPJ_SIZE_T bufferLength = srcData->src_size - srcData->offset; |
59 OPJ_SIZE_T skipLength = p_nb_bytes < bufferLength ? p_nb_bytes : bufferLengt h; | 62 OPJ_SIZE_T skipLength = p_nb_bytes < bufferLength ? p_nb_bytes : bufferLengt h; |
60 srcData->offset += skipLength; | 63 srcData->offset += skipLength; |
61 return skipLength; | 64 return skipLength; |
62 } | 65 } |
63 static OPJ_BOOL opj_seek_from_memory (OPJ_OFF_T p_nb_bytes, void* p_user_data) | 66 static OPJ_BOOL opj_seek_from_memory (OPJ_OFF_T p_nb_bytes, void* p_user_data) |
64 { | 67 { |
65 DecodeData* srcData = static_cast<DecodeData*>(p_user_data); | 68 DecodeData* srcData = static_cast<DecodeData*>(p_user_data); |
66 if (srcData == NULL || srcData->src_size == 0 || srcData->src_data == NULL | | srcData->offset >= srcData->src_size) { | 69 if (srcData == NULL || srcData->src_size == 0 || srcData->src_data == NULL) { |
67 return OPJ_FALSE; | 70 return OPJ_FALSE; |
68 } | 71 } |
72 if (srcData->offset >= srcData->src_size) { | |
73 return OPJ_TRUE; | |
74 } | |
69 if (p_nb_bytes >= srcData->src_size) { | 75 if (p_nb_bytes >= srcData->src_size) { |
70 return OPJ_FALSE; | 76 return OPJ_FALSE; |
71 } | 77 } |
72 srcData->offset = p_nb_bytes; | 78 srcData->offset = p_nb_bytes; |
73 return OPJ_TRUE; | 79 return OPJ_TRUE; |
74 } | 80 } |
75 opj_stream_t* fx_opj_stream_create_memory_stream (DecodeData* data, OPJ_SIZE _T p_size, OPJ_BOOL p_is_read_stream) | 81 opj_stream_t* fx_opj_stream_create_memory_stream (DecodeData* data, OPJ_SIZE _T p_size, OPJ_BOOL p_is_read_stream) |
76 { | 82 { |
77 opj_stream_t* l_stream = 00; | 83 opj_stream_t* l_stream = 00; |
78 if (!data || ! data->src_data || data->src_size <= 0 ) { | 84 if (!data || ! data->src_data || data->src_size <= 0 ) { |
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
622 image->useColorSpace = 0; | 628 image->useColorSpace = 0; |
623 } | 629 } |
624 */ | 630 */ |
625 if (!parameters.nb_tile_to_decode) { | 631 if (!parameters.nb_tile_to_decode) { |
626 if (!opj_set_decode_area(l_codec, image, parameters.DA_x0, | 632 if (!opj_set_decode_area(l_codec, image, parameters.DA_x0, |
627 parameters.DA_y0, parameters.DA_x1, paramete rs.DA_y1)) { | 633 parameters.DA_y0, parameters.DA_x1, paramete rs.DA_y1)) { |
628 opj_image_destroy(image); | 634 opj_image_destroy(image); |
629 image = NULL; | 635 image = NULL; |
630 return FALSE; | 636 return FALSE; |
631 } | 637 } |
632 if (!(opj_decode(l_codec, l_stream, image) && opj_end_decompress(l_codec ,» l_stream))) { | 638 if (!(opj_decode(l_codec, l_stream, image) && opj_end_decompress(l_codec , l_stream))) { |
633 opj_image_destroy(image); | 639 opj_image_destroy(image); |
634 image = NULL; | 640 image = NULL; |
635 return FALSE; | 641 return FALSE; |
636 } | 642 } |
637 } else { | 643 } else { |
638 if (!opj_get_decoded_tile(l_codec, l_stream, image, parameters.tile_inde x)) { | 644 if (!opj_get_decoded_tile(l_codec, l_stream, image, parameters.tile_inde x)) { |
639 return FALSE; | 645 return FALSE; |
640 } | 646 } |
641 } | 647 } |
642 opj_stream_destroy(l_stream); | 648 opj_stream_destroy(l_stream); |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
785 FX_BOOL CCodec_JpxModule::Decode(void* ctx, FX_LPBYTE dest_data, int pitch, FX_B OOL bTranslateColor, FX_LPBYTE offsets) | 791 FX_BOOL CCodec_JpxModule::Decode(void* ctx, FX_LPBYTE dest_data, int pitch, FX_B OOL bTranslateColor, FX_LPBYTE offsets) |
786 { | 792 { |
787 CJPX_Decoder* pDecoder = (CJPX_Decoder*)ctx; | 793 CJPX_Decoder* pDecoder = (CJPX_Decoder*)ctx; |
788 return pDecoder->Decode(dest_data, pitch, bTranslateColor, offsets); | 794 return pDecoder->Decode(dest_data, pitch, bTranslateColor, offsets); |
789 } | 795 } |
790 void CCodec_JpxModule::DestroyDecoder(void* ctx) | 796 void CCodec_JpxModule::DestroyDecoder(void* ctx) |
791 { | 797 { |
792 CJPX_Decoder* pDecoder = (CJPX_Decoder*)ctx; | 798 CJPX_Decoder* pDecoder = (CJPX_Decoder*)ctx; |
793 delete pDecoder; | 799 delete pDecoder; |
794 } | 800 } |
OLD | NEW |