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 <setjmp.h> | 7 #include <setjmp.h> |
8 | 8 |
9 #include "../../../include/fxcodec/fx_codec.h" | 9 #include "../../../include/fxcodec/fx_codec.h" |
10 #include "../../../include/fxcrt/fx_safe_types.h" | 10 #include "../../../include/fxcrt/fx_safe_types.h" |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 static void _error_do_nothing1(j_common_ptr cinfo, int) {} | 70 static void _error_do_nothing1(j_common_ptr cinfo, int) {} |
71 }; | 71 }; |
72 extern "C" { | 72 extern "C" { |
73 static void _error_do_nothing2(j_common_ptr cinfo, char*) {} | 73 static void _error_do_nothing2(j_common_ptr cinfo, char*) {} |
74 }; | 74 }; |
75 #define JPEG_MARKER_EXIF (JPEG_APP0 + 1) | 75 #define JPEG_MARKER_EXIF (JPEG_APP0 + 1) |
76 #define JPEG_MARKER_ICC (JPEG_APP0 + 2) | 76 #define JPEG_MARKER_ICC (JPEG_APP0 + 2) |
77 #define JPEG_MARKER_AUTHORTIME (JPEG_APP0 + 3) | 77 #define JPEG_MARKER_AUTHORTIME (JPEG_APP0 + 3) |
78 #define JPEG_MARKER_MAXSIZE 0xFFFF | 78 #define JPEG_MARKER_MAXSIZE 0xFFFF |
79 #define JPEG_OVERHEAD_LEN 14 | 79 #define JPEG_OVERHEAD_LEN 14 |
80 static» FX_BOOL _JpegEmbedIccProfile(j_compress_ptr cinfo, FX_LPCBYTE icc_buf_pt
r, FX_DWORD icc_length) | 80 static» FX_BOOL _JpegEmbedIccProfile(j_compress_ptr cinfo, const uint8_t* icc_bu
f_ptr, FX_DWORD icc_length) |
81 { | 81 { |
82 if(icc_buf_ptr == NULL || icc_length == 0) { | 82 if(icc_buf_ptr == NULL || icc_length == 0) { |
83 return FALSE; | 83 return FALSE; |
84 } | 84 } |
85 FX_DWORD icc_segment_size = (JPEG_MARKER_MAXSIZE - 2 - JPEG_OVERHEAD_LEN); | 85 FX_DWORD icc_segment_size = (JPEG_MARKER_MAXSIZE - 2 - JPEG_OVERHEAD_LEN); |
86 FX_DWORD icc_segment_num = (icc_length / icc_segment_size) + 1; | 86 FX_DWORD icc_segment_num = (icc_length / icc_segment_size) + 1; |
87 if (icc_segment_num > 255) { | 87 if (icc_segment_num > 255) { |
88 return FALSE; | 88 return FALSE; |
89 } | 89 } |
90 FX_DWORD icc_data_length = JPEG_OVERHEAD_LEN + (icc_segment_num > 1 ? icc_se
gment_size : icc_length); | 90 FX_DWORD icc_data_length = JPEG_OVERHEAD_LEN + (icc_segment_num > 1 ? icc_se
gment_size : icc_length); |
91 FX_LPBYTE icc_data = FX_Alloc(uint8_t, icc_data_length); | 91 uint8_t* icc_data = FX_Alloc(uint8_t, icc_data_length); |
92 FXSYS_memcpy32(icc_data, "\x49\x43\x43\x5f\x50\x52\x4f\x46\x49\x4c\x45\x00",
12); | 92 FXSYS_memcpy32(icc_data, "\x49\x43\x43\x5f\x50\x52\x4f\x46\x49\x4c\x45\x00",
12); |
93 icc_data[13] = (uint8_t)icc_segment_num; | 93 icc_data[13] = (uint8_t)icc_segment_num; |
94 for (uint8_t i = 0; i < (icc_segment_num - 1); i++) { | 94 for (uint8_t i = 0; i < (icc_segment_num - 1); i++) { |
95 icc_data[12] = i + 1; | 95 icc_data[12] = i + 1; |
96 FXSYS_memcpy32(icc_data + JPEG_OVERHEAD_LEN, icc_buf_ptr + i * icc_segme
nt_size, icc_segment_size); | 96 FXSYS_memcpy32(icc_data + JPEG_OVERHEAD_LEN, icc_buf_ptr + i * icc_segme
nt_size, icc_segment_size); |
97 jpeg_write_marker(cinfo, JPEG_MARKER_ICC, icc_data, icc_data_length); | 97 jpeg_write_marker(cinfo, JPEG_MARKER_ICC, icc_data, icc_data_length); |
98 } | 98 } |
99 icc_data[12] = (uint8_t)icc_segment_num; | 99 icc_data[12] = (uint8_t)icc_segment_num; |
100 FX_DWORD icc_size = (icc_segment_num - 1) * icc_segment_size; | 100 FX_DWORD icc_size = (icc_segment_num - 1) * icc_segment_size; |
101 FXSYS_memcpy32(icc_data + JPEG_OVERHEAD_LEN, icc_buf_ptr + icc_size, icc_len
gth - icc_size); | 101 FXSYS_memcpy32(icc_data + JPEG_OVERHEAD_LEN, icc_buf_ptr + icc_size, icc_len
gth - icc_size); |
102 jpeg_write_marker(cinfo, JPEG_MARKER_ICC, icc_data, JPEG_OVERHEAD_LEN + icc_
length - icc_size); | 102 jpeg_write_marker(cinfo, JPEG_MARKER_ICC, icc_data, JPEG_OVERHEAD_LEN + icc_
length - icc_size); |
103 FX_Free(icc_data); | 103 FX_Free(icc_data); |
104 return TRUE; | 104 return TRUE; |
105 } | 105 } |
106 extern "C" { | 106 extern "C" { |
107 static void _dest_do_nothing(j_compress_ptr cinfo) {} | 107 static void _dest_do_nothing(j_compress_ptr cinfo) {} |
108 }; | 108 }; |
109 extern "C" { | 109 extern "C" { |
110 static boolean _dest_empty(j_compress_ptr cinfo) | 110 static boolean _dest_empty(j_compress_ptr cinfo) |
111 { | 111 { |
112 return FALSE; | 112 return FALSE; |
113 } | 113 } |
114 }; | 114 }; |
115 #define JPEG_BLOCK_SIZE 1048576 | 115 #define JPEG_BLOCK_SIZE 1048576 |
116 static void _JpegEncode(const CFX_DIBSource* pSource, FX_LPBYTE& dest_buf, FX_ST
RSIZE& dest_size, int quality, FX_LPCBYTE icc_buf, FX_DWORD icc_length) | 116 static void _JpegEncode(const CFX_DIBSource* pSource, uint8_t*& dest_buf, FX_STR
SIZE& dest_size, int quality, const uint8_t* icc_buf, FX_DWORD icc_length) |
117 { | 117 { |
118 struct jpeg_error_mgr jerr; | 118 struct jpeg_error_mgr jerr; |
119 jerr.error_exit = _error_do_nothing; | 119 jerr.error_exit = _error_do_nothing; |
120 jerr.emit_message = _error_do_nothing1; | 120 jerr.emit_message = _error_do_nothing1; |
121 jerr.output_message = _error_do_nothing; | 121 jerr.output_message = _error_do_nothing; |
122 jerr.format_message = _error_do_nothing2; | 122 jerr.format_message = _error_do_nothing2; |
123 jerr.reset_error_mgr = _error_do_nothing; | 123 jerr.reset_error_mgr = _error_do_nothing; |
124 | 124 |
125 struct jpeg_compress_struct cinfo; | 125 struct jpeg_compress_struct cinfo; |
126 memset(&cinfo, 0, sizeof(cinfo)); | 126 memset(&cinfo, 0, sizeof(cinfo)); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 cinfo.image_width = width; | 164 cinfo.image_width = width; |
165 cinfo.image_height = height; | 165 cinfo.image_height = height; |
166 cinfo.input_components = nComponents; | 166 cinfo.input_components = nComponents; |
167 if (nComponents == 1) { | 167 if (nComponents == 1) { |
168 cinfo.in_color_space = JCS_GRAYSCALE; | 168 cinfo.in_color_space = JCS_GRAYSCALE; |
169 } else if (nComponents == 3) { | 169 } else if (nComponents == 3) { |
170 cinfo.in_color_space = JCS_RGB; | 170 cinfo.in_color_space = JCS_RGB; |
171 } else { | 171 } else { |
172 cinfo.in_color_space = JCS_CMYK; | 172 cinfo.in_color_space = JCS_CMYK; |
173 } | 173 } |
174 FX_LPBYTE line_buf = NULL; | 174 uint8_t* line_buf = NULL; |
175 if (nComponents > 1) { | 175 if (nComponents > 1) { |
176 line_buf = FX_Alloc2D(uint8_t, width, nComponents); | 176 line_buf = FX_Alloc2D(uint8_t, width, nComponents); |
177 } | 177 } |
178 jpeg_set_defaults(&cinfo); | 178 jpeg_set_defaults(&cinfo); |
179 if(quality != 75) { | 179 if(quality != 75) { |
180 jpeg_set_quality(&cinfo, quality, TRUE); | 180 jpeg_set_quality(&cinfo, quality, TRUE); |
181 } | 181 } |
182 jpeg_start_compress(&cinfo, TRUE); | 182 jpeg_start_compress(&cinfo, TRUE); |
183 _JpegEmbedIccProfile(&cinfo, icc_buf, icc_length); | 183 _JpegEmbedIccProfile(&cinfo, icc_buf, icc_length); |
184 JSAMPROW row_pointer[1]; | 184 JSAMPROW row_pointer[1]; |
185 JDIMENSION row; | 185 JDIMENSION row; |
186 while (cinfo.next_scanline < cinfo.image_height) { | 186 while (cinfo.next_scanline < cinfo.image_height) { |
187 FX_LPCBYTE src_scan = pSource->GetScanline(cinfo.next_scanline); | 187 const uint8_t* src_scan = pSource->GetScanline(cinfo.next_scanline); |
188 if (nComponents > 1) { | 188 if (nComponents > 1) { |
189 FX_LPBYTE dest_scan = line_buf; | 189 uint8_t* dest_scan = line_buf; |
190 if (nComponents == 3) { | 190 if (nComponents == 3) { |
191 for (int i = 0; i < width; i ++) { | 191 for (int i = 0; i < width; i ++) { |
192 dest_scan[0] = src_scan[2]; | 192 dest_scan[0] = src_scan[2]; |
193 dest_scan[1] = src_scan[1]; | 193 dest_scan[1] = src_scan[1]; |
194 dest_scan[2] = src_scan[0]; | 194 dest_scan[2] = src_scan[0]; |
195 dest_scan += 3; | 195 dest_scan += 3; |
196 src_scan += Bpp; | 196 src_scan += Bpp; |
197 } | 197 } |
198 } else { | 198 } else { |
199 for (int i = 0; i < pitch; i ++) { | 199 for (int i = 0; i < pitch; i ++) { |
200 *dest_scan++ = ~*src_scan++; | 200 *dest_scan++ = ~*src_scan++; |
201 } | 201 } |
202 } | 202 } |
203 row_pointer[0] = line_buf; | 203 row_pointer[0] = line_buf; |
204 } else { | 204 } else { |
205 row_pointer[0] = (FX_LPBYTE)src_scan; | 205 row_pointer[0] = (uint8_t*)src_scan; |
206 } | 206 } |
207 row = cinfo.next_scanline; | 207 row = cinfo.next_scanline; |
208 jpeg_write_scanlines(&cinfo, row_pointer, 1); | 208 jpeg_write_scanlines(&cinfo, row_pointer, 1); |
209 if (cinfo.next_scanline == row) { | 209 if (cinfo.next_scanline == row) { |
210 dest_buf = FX_Realloc(uint8_t, dest_buf, dest_buf_length + JPEG_BLOC
K_SIZE); | 210 dest_buf = FX_Realloc(uint8_t, dest_buf, dest_buf_length + JPEG_BLOC
K_SIZE); |
211 dest.next_output_byte = dest_buf + dest_buf_length - dest.free_in_bu
ffer; | 211 dest.next_output_byte = dest_buf + dest_buf_length - dest.free_in_bu
ffer; |
212 dest_buf_length += JPEG_BLOCK_SIZE; | 212 dest_buf_length += JPEG_BLOCK_SIZE; |
213 dest.free_in_buffer += JPEG_BLOCK_SIZE; | 213 dest.free_in_buffer += JPEG_BLOCK_SIZE; |
214 } | 214 } |
215 } | 215 } |
216 jpeg_finish_compress(&cinfo); | 216 jpeg_finish_compress(&cinfo); |
217 jpeg_destroy_compress(&cinfo); | 217 jpeg_destroy_compress(&cinfo); |
218 if (line_buf) { | 218 if (line_buf) { |
219 FX_Free(line_buf); | 219 FX_Free(line_buf); |
220 } | 220 } |
221 dest_size = dest_buf_length - (FX_STRSIZE)dest.free_in_buffer; | 221 dest_size = dest_buf_length - (FX_STRSIZE)dest.free_in_buffer; |
222 } | 222 } |
223 static FX_BOOL _JpegLoadInfo(FX_LPCBYTE src_buf, FX_DWORD src_size, int& width,
int& height, | 223 static FX_BOOL _JpegLoadInfo(const uint8_t* src_buf, FX_DWORD src_size, int& wid
th, int& height, |
224 int& num_components, int& bits_per_components, FX_B
OOL& color_transform, | 224 int& num_components, int& bits_per_components, FX_B
OOL& color_transform, |
225 FX_LPBYTE* icc_buf_ptr, FX_DWORD* icc_length) | 225 uint8_t** icc_buf_ptr, FX_DWORD* icc_length) |
226 { | 226 { |
227 _JpegScanSOI(src_buf, src_size); | 227 _JpegScanSOI(src_buf, src_size); |
228 struct jpeg_decompress_struct cinfo; | 228 struct jpeg_decompress_struct cinfo; |
229 struct jpeg_error_mgr jerr; | 229 struct jpeg_error_mgr jerr; |
230 jerr.error_exit = _error_fatal; | 230 jerr.error_exit = _error_fatal; |
231 jerr.emit_message = _error_do_nothing1; | 231 jerr.emit_message = _error_do_nothing1; |
232 jerr.output_message = _error_do_nothing; | 232 jerr.output_message = _error_do_nothing; |
233 jerr.format_message = _error_do_nothing2; | 233 jerr.format_message = _error_do_nothing2; |
234 jerr.reset_error_mgr = _error_do_nothing; | 234 jerr.reset_error_mgr = _error_do_nothing; |
235 jerr.trace_level = 0; | 235 jerr.trace_level = 0; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 *icc_length = 0; | 273 *icc_length = 0; |
274 } | 274 } |
275 jpeg_destroy_decompress(&cinfo); | 275 jpeg_destroy_decompress(&cinfo); |
276 return TRUE; | 276 return TRUE; |
277 } | 277 } |
278 class CCodec_JpegDecoder : public CCodec_ScanlineDecoder | 278 class CCodec_JpegDecoder : public CCodec_ScanlineDecoder |
279 { | 279 { |
280 public: | 280 public: |
281 CCodec_JpegDecoder(); | 281 CCodec_JpegDecoder(); |
282 ~CCodec_JpegDecoder(); | 282 ~CCodec_JpegDecoder(); |
283 FX_BOOL» » » » Create(FX_LPCBYTE src_buf, FX_DWORD src_
size, int width, int height, int nComps, | 283 FX_BOOL» » » » Create(const uint8_t* src_buf, FX_DWORD
src_size, int width, int height, int nComps, |
284 FX_BOOL ColorTransform, IFX_JpegProvider* pJP); | 284 FX_BOOL ColorTransform, IFX_JpegProvider* pJP); |
285 virtual void Destroy() | 285 virtual void Destroy() |
286 { | 286 { |
287 delete this; | 287 delete this; |
288 } | 288 } |
289 virtual void v_DownScale(int dest_width, int dest_height); | 289 virtual void v_DownScale(int dest_width, int dest_height); |
290 virtual FX_BOOL v_Rewind(); | 290 virtual FX_BOOL v_Rewind(); |
291 virtual FX_LPBYTE» v_GetNextLine(); | 291 virtual uint8_t*» v_GetNextLine(); |
292 virtual FX_DWORD GetSrcOffset(); | 292 virtual FX_DWORD GetSrcOffset(); |
293 jmp_buf m_JmpBuf; | 293 jmp_buf m_JmpBuf; |
294 struct jpeg_decompress_struct cinfo; | 294 struct jpeg_decompress_struct cinfo; |
295 struct jpeg_error_mgr jerr; | 295 struct jpeg_error_mgr jerr; |
296 struct jpeg_source_mgr src; | 296 struct jpeg_source_mgr src; |
297 FX_LPCBYTE» m_SrcBuf; | 297 const uint8_t*» m_SrcBuf; |
298 FX_DWORD m_SrcSize; | 298 FX_DWORD m_SrcSize; |
299 FX_LPBYTE» m_pScanlineBuf; | 299 uint8_t*» m_pScanlineBuf; |
300 FX_BOOL InitDecode(); | 300 FX_BOOL InitDecode(); |
301 FX_BOOL m_bInited, m_bStarted, m_bJpegTransform; | 301 FX_BOOL m_bInited, m_bStarted, m_bJpegTransform; |
302 protected: | 302 protected: |
303 IFX_JpegProvider* m_pExtProvider; | 303 IFX_JpegProvider* m_pExtProvider; |
304 void* m_pExtContext; | 304 void* m_pExtContext; |
305 FX_DWORD m_nDefaultScaleDenom; | 305 FX_DWORD m_nDefaultScaleDenom; |
306 }; | 306 }; |
307 CCodec_JpegDecoder::CCodec_JpegDecoder() | 307 CCodec_JpegDecoder::CCodec_JpegDecoder() |
308 { | 308 { |
309 m_pScanlineBuf = NULL; | 309 m_pScanlineBuf = NULL; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 if (cinfo.num_components == 3 && !m_bJpegTransform) { | 359 if (cinfo.num_components == 3 && !m_bJpegTransform) { |
360 cinfo.out_color_space = cinfo.jpeg_color_space; | 360 cinfo.out_color_space = cinfo.jpeg_color_space; |
361 } | 361 } |
362 m_OrigWidth = cinfo.image_width; | 362 m_OrigWidth = cinfo.image_width; |
363 m_OrigHeight = cinfo.image_height; | 363 m_OrigHeight = cinfo.image_height; |
364 m_OutputWidth = m_OrigWidth; | 364 m_OutputWidth = m_OrigWidth; |
365 m_OutputHeight = m_OrigHeight; | 365 m_OutputHeight = m_OrigHeight; |
366 m_nDefaultScaleDenom = cinfo.scale_denom; | 366 m_nDefaultScaleDenom = cinfo.scale_denom; |
367 return TRUE; | 367 return TRUE; |
368 } | 368 } |
369 FX_BOOL CCodec_JpegDecoder::Create(FX_LPCBYTE src_buf, FX_DWORD src_size, int wi
dth, int height, | 369 FX_BOOL CCodec_JpegDecoder::Create(const uint8_t* src_buf, FX_DWORD src_size, in
t width, int height, |
370 int nComps, FX_BOOL ColorTransform, IFX_JpegP
rovider* pJP) | 370 int nComps, FX_BOOL ColorTransform, IFX_JpegP
rovider* pJP) |
371 { | 371 { |
372 if (pJP) { | 372 if (pJP) { |
373 m_pExtProvider = pJP; | 373 m_pExtProvider = pJP; |
374 m_pExtContext = m_pExtProvider->CreateDecoder(src_buf, src_size, width,
height, nComps, ColorTransform); | 374 m_pExtContext = m_pExtProvider->CreateDecoder(src_buf, src_size, width,
height, nComps, ColorTransform); |
375 return m_pExtContext != NULL; | 375 return m_pExtContext != NULL; |
376 } | 376 } |
377 _JpegScanSOI(src_buf, src_size); | 377 _JpegScanSOI(src_buf, src_size); |
378 m_SrcBuf = src_buf; | 378 m_SrcBuf = src_buf; |
379 m_SrcSize = src_size; | 379 m_SrcSize = src_size; |
380 jerr.error_exit = _error_fatal; | 380 jerr.error_exit = _error_fatal; |
381 jerr.emit_message = _error_do_nothing1; | 381 jerr.emit_message = _error_do_nothing1; |
382 jerr.output_message = _error_do_nothing; | 382 jerr.output_message = _error_do_nothing; |
383 jerr.format_message = _error_do_nothing2; | 383 jerr.format_message = _error_do_nothing2; |
384 jerr.reset_error_mgr = _error_do_nothing; | 384 jerr.reset_error_mgr = _error_do_nothing; |
385 src.init_source = _src_do_nothing; | 385 src.init_source = _src_do_nothing; |
386 src.term_source = _src_do_nothing; | 386 src.term_source = _src_do_nothing; |
387 src.skip_input_data = _src_skip_data; | 387 src.skip_input_data = _src_skip_data; |
388 src.fill_input_buffer = _src_fill_buffer; | 388 src.fill_input_buffer = _src_fill_buffer; |
389 src.resync_to_restart = _src_resync; | 389 src.resync_to_restart = _src_resync; |
390 m_bJpegTransform = ColorTransform; | 390 m_bJpegTransform = ColorTransform; |
391 if(src_size > 1 && FXSYS_memcmp32(src_buf + src_size - 2, "\xFF\xD9", 2) !=
0) { | 391 if(src_size > 1 && FXSYS_memcmp32(src_buf + src_size - 2, "\xFF\xD9", 2) !=
0) { |
392 ((FX_LPBYTE)src_buf)[src_size - 2] = 0xFF; | 392 ((uint8_t*)src_buf)[src_size - 2] = 0xFF; |
393 ((FX_LPBYTE)src_buf)[src_size - 1] = 0xD9; | 393 ((uint8_t*)src_buf)[src_size - 1] = 0xD9; |
394 } | 394 } |
395 m_OutputWidth = m_OrigWidth = width; | 395 m_OutputWidth = m_OrigWidth = width; |
396 m_OutputHeight = m_OrigHeight = height; | 396 m_OutputHeight = m_OrigHeight = height; |
397 if (!InitDecode()) { | 397 if (!InitDecode()) { |
398 return FALSE; | 398 return FALSE; |
399 } | 399 } |
400 if (cinfo.num_components < nComps) { | 400 if (cinfo.num_components < nComps) { |
401 return FALSE; | 401 return FALSE; |
402 } | 402 } |
403 if ((int)cinfo.image_width < width) { | 403 if ((int)cinfo.image_width < width) { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 jpeg_destroy_decompress(&cinfo); | 463 jpeg_destroy_decompress(&cinfo); |
464 return FALSE; | 464 return FALSE; |
465 } | 465 } |
466 if ((int)cinfo.output_width > m_OrigWidth) { | 466 if ((int)cinfo.output_width > m_OrigWidth) { |
467 FXSYS_assert(FALSE); | 467 FXSYS_assert(FALSE); |
468 return FALSE; | 468 return FALSE; |
469 } | 469 } |
470 m_bStarted = TRUE; | 470 m_bStarted = TRUE; |
471 return TRUE; | 471 return TRUE; |
472 } | 472 } |
473 FX_LPBYTE CCodec_JpegDecoder::v_GetNextLine() | 473 uint8_t* CCodec_JpegDecoder::v_GetNextLine() |
474 { | 474 { |
475 if (m_pExtProvider) { | 475 if (m_pExtProvider) { |
476 return m_pExtProvider->GetNextLine(m_pExtContext); | 476 return m_pExtProvider->GetNextLine(m_pExtContext); |
477 } | 477 } |
478 int nlines = jpeg_read_scanlines(&cinfo, &m_pScanlineBuf, 1); | 478 int nlines = jpeg_read_scanlines(&cinfo, &m_pScanlineBuf, 1); |
479 if (nlines < 1) { | 479 if (nlines < 1) { |
480 return NULL; | 480 return NULL; |
481 } | 481 } |
482 return m_pScanlineBuf; | 482 return m_pScanlineBuf; |
483 } | 483 } |
484 FX_DWORD CCodec_JpegDecoder::GetSrcOffset() | 484 FX_DWORD CCodec_JpegDecoder::GetSrcOffset() |
485 { | 485 { |
486 if (m_pExtProvider) { | 486 if (m_pExtProvider) { |
487 return m_pExtProvider->GetSrcOffset(m_pExtContext); | 487 return m_pExtProvider->GetSrcOffset(m_pExtContext); |
488 } | 488 } |
489 return (FX_DWORD)(m_SrcSize - src.bytes_in_buffer); | 489 return (FX_DWORD)(m_SrcSize - src.bytes_in_buffer); |
490 } | 490 } |
491 ICodec_ScanlineDecoder*»CCodec_JpegModule::CreateDecoder(FX_LPCBYTE src_buf, FX_
DWORD src_size, | 491 ICodec_ScanlineDecoder*»CCodec_JpegModule::CreateDecoder(const uint8_t* src_buf,
FX_DWORD src_size, |
492 int width, int height, int nComps, FX_BOOL ColorTransform) | 492 int width, int height, int nComps, FX_BOOL ColorTransform) |
493 { | 493 { |
494 if (src_buf == NULL || src_size == 0) { | 494 if (src_buf == NULL || src_size == 0) { |
495 return NULL; | 495 return NULL; |
496 } | 496 } |
497 CCodec_JpegDecoder* pDecoder = new CCodec_JpegDecoder; | 497 CCodec_JpegDecoder* pDecoder = new CCodec_JpegDecoder; |
498 if (!pDecoder->Create(src_buf, src_size, width, height, nComps, ColorTransfo
rm, m_pExtProvider)) { | 498 if (!pDecoder->Create(src_buf, src_size, width, height, nComps, ColorTransfo
rm, m_pExtProvider)) { |
499 delete pDecoder; | 499 delete pDecoder; |
500 return NULL; | 500 return NULL; |
501 } | 501 } |
502 return pDecoder; | 502 return pDecoder; |
503 } | 503 } |
504 FX_BOOL CCodec_JpegModule::LoadInfo(FX_LPCBYTE src_buf, FX_DWORD src_size, int&
width, int& height, | 504 FX_BOOL CCodec_JpegModule::LoadInfo(const uint8_t* src_buf, FX_DWORD src_size, i
nt& width, int& height, |
505 int& num_components, int& bits_per_component
s, FX_BOOL& color_transform, | 505 int& num_components, int& bits_per_component
s, FX_BOOL& color_transform, |
506 FX_LPBYTE* icc_buf_ptr, FX_DWORD* icc_length
) | 506 uint8_t** icc_buf_ptr, FX_DWORD* icc_length) |
507 { | 507 { |
508 if (m_pExtProvider) { | 508 if (m_pExtProvider) { |
509 return m_pExtProvider->LoadInfo(src_buf, src_size, width, height, | 509 return m_pExtProvider->LoadInfo(src_buf, src_size, width, height, |
510 num_components, bits_per_components, col
or_transform, | 510 num_components, bits_per_components, col
or_transform, |
511 icc_buf_ptr, icc_length); | 511 icc_buf_ptr, icc_length); |
512 } | 512 } |
513 return _JpegLoadInfo(src_buf, src_size, width, height, num_components, bits_
per_components, color_transform, icc_buf_ptr, icc_length); | 513 return _JpegLoadInfo(src_buf, src_size, width, height, num_components, bits_
per_components, color_transform, icc_buf_ptr, icc_length); |
514 } | 514 } |
515 FX_BOOL CCodec_JpegModule::Encode(const CFX_DIBSource* pSource, FX_LPBYTE& dest_
buf, FX_STRSIZE& dest_size, int quality, FX_LPCBYTE icc_buf, FX_DWORD icc_length
) | 515 FX_BOOL CCodec_JpegModule::Encode(const CFX_DIBSource* pSource, uint8_t*& dest_b
uf, FX_STRSIZE& dest_size, int quality, const uint8_t* icc_buf, FX_DWORD icc_len
gth) |
516 { | 516 { |
517 if (m_pExtProvider) { | 517 if (m_pExtProvider) { |
518 return m_pExtProvider->Encode(pSource, dest_buf, dest_size, quality, icc
_buf, icc_length); | 518 return m_pExtProvider->Encode(pSource, dest_buf, dest_size, quality, icc
_buf, icc_length); |
519 } | 519 } |
520 if(pSource->GetBPP() < 8 || pSource->GetPalette() != NULL) { | 520 if(pSource->GetBPP() < 8 || pSource->GetPalette() != NULL) { |
521 ASSERT(pSource->GetBPP() >= 8 && pSource->GetPalette() == NULL); | 521 ASSERT(pSource->GetBPP() >= 8 && pSource->GetPalette() == NULL); |
522 return FALSE; | 522 return FALSE; |
523 } | 523 } |
524 _JpegEncode(pSource, dest_buf, dest_size, quality, icc_buf, icc_length); | 524 _JpegEncode(pSource, dest_buf, dest_size, quality, icc_buf, icc_length); |
525 return TRUE; | 525 return TRUE; |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
655 if (m_pExtProvider) { | 655 if (m_pExtProvider) { |
656 return m_pExtProvider->ReadScanline(pContext, dest_buf); | 656 return m_pExtProvider->ReadScanline(pContext, dest_buf); |
657 } | 657 } |
658 FXJPEG_Context* p = (FXJPEG_Context*)pContext; | 658 FXJPEG_Context* p = (FXJPEG_Context*)pContext; |
659 if (setjmp(p->m_JumpMark) == -1) { | 659 if (setjmp(p->m_JumpMark) == -1) { |
660 return FALSE; | 660 return FALSE; |
661 } | 661 } |
662 int nlines = jpeg_read_scanlines(&p->m_Info, &dest_buf, 1); | 662 int nlines = jpeg_read_scanlines(&p->m_Info, &dest_buf, 1); |
663 return nlines == 1; | 663 return nlines == 1; |
664 } | 664 } |
665 FX_DWORD CCodec_JpegModule::GetAvailInput(void* pContext, FX_LPBYTE* avail_buf_p
tr) | 665 FX_DWORD CCodec_JpegModule::GetAvailInput(void* pContext, uint8_t** avail_buf_pt
r) |
666 { | 666 { |
667 if (m_pExtProvider) { | 667 if (m_pExtProvider) { |
668 return m_pExtProvider->GetAvailInput(pContext, avail_buf_ptr); | 668 return m_pExtProvider->GetAvailInput(pContext, avail_buf_ptr); |
669 } | 669 } |
670 if(avail_buf_ptr != NULL) { | 670 if(avail_buf_ptr != NULL) { |
671 *avail_buf_ptr = NULL; | 671 *avail_buf_ptr = NULL; |
672 if(((FXJPEG_Context*)pContext)->m_SrcMgr.bytes_in_buffer > 0) { | 672 if(((FXJPEG_Context*)pContext)->m_SrcMgr.bytes_in_buffer > 0) { |
673 *avail_buf_ptr = (FX_LPBYTE)((FXJPEG_Context*)pContext)->m_SrcMgr.ne
xt_input_byte; | 673 *avail_buf_ptr = (uint8_t*)((FXJPEG_Context*)pContext)->m_SrcMgr.nex
t_input_byte; |
674 } | 674 } |
675 } | 675 } |
676 return (FX_DWORD)((FXJPEG_Context*)pContext)->m_SrcMgr.bytes_in_buffer; | 676 return (FX_DWORD)((FXJPEG_Context*)pContext)->m_SrcMgr.bytes_in_buffer; |
677 } | 677 } |
OLD | NEW |