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 <memory> | 9 #include <memory> |
10 #include <vector> | 10 #include <vector> |
(...skipping 26 matching lines...) Expand all Loading... |
37 if (srcData->offset >= srcData->src_size) { | 37 if (srcData->offset >= srcData->src_size) { |
38 return static_cast<OPJ_SIZE_T>(-1); | 38 return static_cast<OPJ_SIZE_T>(-1); |
39 } | 39 } |
40 OPJ_SIZE_T bufferLength = srcData->src_size - srcData->offset; | 40 OPJ_SIZE_T bufferLength = srcData->src_size - srcData->offset; |
41 OPJ_SIZE_T readlength = nb_bytes < bufferLength ? nb_bytes : bufferLength; | 41 OPJ_SIZE_T readlength = nb_bytes < bufferLength ? nb_bytes : bufferLength; |
42 memcpy(p_buffer, &srcData->src_data[srcData->offset], readlength); | 42 memcpy(p_buffer, &srcData->src_data[srcData->offset], readlength); |
43 srcData->offset += readlength; | 43 srcData->offset += readlength; |
44 return readlength; | 44 return readlength; |
45 } | 45 } |
46 | 46 |
47 OPJ_SIZE_T opj_write_from_memory(void* p_buffer, | |
48 OPJ_SIZE_T nb_bytes, | |
49 void* p_user_data) { | |
50 DecodeData* srcData = static_cast<DecodeData*>(p_user_data); | |
51 if (!srcData || !srcData->src_data || srcData->src_size == 0) { | |
52 return static_cast<OPJ_SIZE_T>(-1); | |
53 } | |
54 // Writes at EOF return an error code. | |
55 if (srcData->offset >= srcData->src_size) { | |
56 return static_cast<OPJ_SIZE_T>(-1); | |
57 } | |
58 OPJ_SIZE_T bufferLength = srcData->src_size - srcData->offset; | |
59 OPJ_SIZE_T writeLength = nb_bytes < bufferLength ? nb_bytes : bufferLength; | |
60 memcpy(&srcData->src_data[srcData->offset], p_buffer, writeLength); | |
61 srcData->offset += writeLength; | |
62 return writeLength; | |
63 } | |
64 | |
65 OPJ_OFF_T opj_skip_from_memory(OPJ_OFF_T nb_bytes, void* p_user_data) { | 47 OPJ_OFF_T opj_skip_from_memory(OPJ_OFF_T nb_bytes, void* p_user_data) { |
66 DecodeData* srcData = static_cast<DecodeData*>(p_user_data); | 48 DecodeData* srcData = static_cast<DecodeData*>(p_user_data); |
67 if (!srcData || !srcData->src_data || srcData->src_size == 0) { | 49 if (!srcData || !srcData->src_data || srcData->src_size == 0) { |
68 return static_cast<OPJ_OFF_T>(-1); | 50 return static_cast<OPJ_OFF_T>(-1); |
69 } | 51 } |
70 // Offsets are signed and may indicate a negative skip. Do not support this | 52 // Offsets are signed and may indicate a negative skip. Do not support this |
71 // because of the strange return convention where either bytes skipped or | 53 // because of the strange return convention where either bytes skipped or |
72 // -1 is returned. Following that convention, a successful relative seek of | 54 // -1 is returned. Following that convention, a successful relative seek of |
73 // -1 bytes would be required to to give the same result as the error case. | 55 // -1 bytes would be required to to give the same result as the error case. |
74 if (nb_bytes < 0) { | 56 if (nb_bytes < 0) { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 if (!data || !data->src_data || data->src_size <= 0) { | 107 if (!data || !data->src_data || data->src_size <= 0) { |
126 return nullptr; | 108 return nullptr; |
127 } | 109 } |
128 l_stream = opj_stream_create(p_size, p_is_read_stream); | 110 l_stream = opj_stream_create(p_size, p_is_read_stream); |
129 if (!l_stream) { | 111 if (!l_stream) { |
130 return nullptr; | 112 return nullptr; |
131 } | 113 } |
132 opj_stream_set_user_data(l_stream, data, nullptr); | 114 opj_stream_set_user_data(l_stream, data, nullptr); |
133 opj_stream_set_user_data_length(l_stream, data->src_size); | 115 opj_stream_set_user_data_length(l_stream, data->src_size); |
134 opj_stream_set_read_function(l_stream, opj_read_from_memory); | 116 opj_stream_set_read_function(l_stream, opj_read_from_memory); |
135 opj_stream_set_write_function(l_stream, opj_write_from_memory); | |
136 opj_stream_set_skip_function(l_stream, opj_skip_from_memory); | 117 opj_stream_set_skip_function(l_stream, opj_skip_from_memory); |
137 opj_stream_set_seek_function(l_stream, opj_seek_from_memory); | 118 opj_stream_set_seek_function(l_stream, opj_seek_from_memory); |
138 return l_stream; | 119 return l_stream; |
139 } | 120 } |
140 static void sycc_to_rgb(int offset, | 121 static void sycc_to_rgb(int offset, |
141 int upb, | 122 int upb, |
142 int y, | 123 int y, |
143 int cb, | 124 int cb, |
144 int cr, | 125 int cr, |
145 int* out_r, | 126 int* out_r, |
(...skipping 764 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
910 bool CCodec_JpxModule::Decode(CJPX_Decoder* pDecoder, | 891 bool CCodec_JpxModule::Decode(CJPX_Decoder* pDecoder, |
911 uint8_t* dest_data, | 892 uint8_t* dest_data, |
912 int pitch, | 893 int pitch, |
913 const std::vector<uint8_t>& offsets) { | 894 const std::vector<uint8_t>& offsets) { |
914 return pDecoder->Decode(dest_data, pitch, offsets); | 895 return pDecoder->Decode(dest_data, pitch, offsets); |
915 } | 896 } |
916 | 897 |
917 void CCodec_JpxModule::DestroyDecoder(CJPX_Decoder* pDecoder) { | 898 void CCodec_JpxModule::DestroyDecoder(CJPX_Decoder* pDecoder) { |
918 delete pDecoder; | 899 delete pDecoder; |
919 } | 900 } |
OLD | NEW |