Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(775)

Side by Side Diff: core/fxcodec/codec/fx_codec_jpeg.cpp

Issue 1832173003: Remove FX_DWORD from core/ and delete definition (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/fxcodec/codec/fx_codec_jbig.cpp ('k') | core/fxcodec/codec/fx_codec_jpx_opj.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "core/fxcodec/codec/codec_int.h" 9 #include "core/fxcodec/codec/codec_int.h"
10 #include "core/fxcrt/include/fx_safe_types.h" 10 #include "core/fxcrt/include/fx_safe_types.h"
11 #include "core/include/fxcodec/fx_codec.h" 11 #include "core/include/fxcodec/fx_codec.h"
12 #include "core/include/fxge/fx_dib.h" 12 #include "core/include/fxge/fx_dib.h"
13 13
14 extern "C" { 14 extern "C" {
15 #undef FAR 15 #undef FAR
16 #if defined(USE_SYSTEM_LIBJPEG) 16 #if defined(USE_SYSTEM_LIBJPEG)
17 #include <jpeglib.h> 17 #include <jpeglib.h>
18 #elif defined(USE_LIBJPEG_TURBO) 18 #elif defined(USE_LIBJPEG_TURBO)
19 #include "third_party/libjpeg_turbo/jpeglib.h" 19 #include "third_party/libjpeg_turbo/jpeglib.h"
20 #else 20 #else
21 #include "third_party/libjpeg/jpeglib.h" 21 #include "third_party/libjpeg/jpeglib.h"
22 #endif 22 #endif
23 } 23 }
24 24
25 extern "C" { 25 extern "C" {
26 static void _JpegScanSOI(const uint8_t*& src_buf, FX_DWORD& src_size) { 26 static void _JpegScanSOI(const uint8_t*& src_buf, uint32_t& src_size) {
27 if (src_size == 0) { 27 if (src_size == 0) {
28 return; 28 return;
29 } 29 }
30 FX_DWORD offset = 0; 30 uint32_t offset = 0;
31 while (offset < src_size - 1) { 31 while (offset < src_size - 1) {
32 if (src_buf[offset] == 0xff && src_buf[offset + 1] == 0xd8) { 32 if (src_buf[offset] == 0xff && src_buf[offset + 1] == 0xd8) {
33 src_buf += offset; 33 src_buf += offset;
34 src_size -= offset; 34 src_size -= offset;
35 return; 35 return;
36 } 36 }
37 offset++; 37 offset++;
38 } 38 }
39 } 39 }
40 }; 40 };
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 extern "C" { 74 extern "C" {
75 static void _error_do_nothing2(j_common_ptr cinfo, char*) {} 75 static void _error_do_nothing2(j_common_ptr cinfo, char*) {}
76 }; 76 };
77 #define JPEG_MARKER_EXIF (JPEG_APP0 + 1) 77 #define JPEG_MARKER_EXIF (JPEG_APP0 + 1)
78 #define JPEG_MARKER_ICC (JPEG_APP0 + 2) 78 #define JPEG_MARKER_ICC (JPEG_APP0 + 2)
79 #define JPEG_MARKER_AUTHORTIME (JPEG_APP0 + 3) 79 #define JPEG_MARKER_AUTHORTIME (JPEG_APP0 + 3)
80 #define JPEG_MARKER_MAXSIZE 0xFFFF 80 #define JPEG_MARKER_MAXSIZE 0xFFFF
81 #define JPEG_OVERHEAD_LEN 14 81 #define JPEG_OVERHEAD_LEN 14
82 static FX_BOOL _JpegEmbedIccProfile(j_compress_ptr cinfo, 82 static FX_BOOL _JpegEmbedIccProfile(j_compress_ptr cinfo,
83 const uint8_t* icc_buf_ptr, 83 const uint8_t* icc_buf_ptr,
84 FX_DWORD icc_length) { 84 uint32_t icc_length) {
85 if (!icc_buf_ptr || icc_length == 0) { 85 if (!icc_buf_ptr || icc_length == 0) {
86 return FALSE; 86 return FALSE;
87 } 87 }
88 FX_DWORD icc_segment_size = (JPEG_MARKER_MAXSIZE - 2 - JPEG_OVERHEAD_LEN); 88 uint32_t icc_segment_size = (JPEG_MARKER_MAXSIZE - 2 - JPEG_OVERHEAD_LEN);
89 FX_DWORD icc_segment_num = (icc_length / icc_segment_size) + 1; 89 uint32_t icc_segment_num = (icc_length / icc_segment_size) + 1;
90 if (icc_segment_num > 255) { 90 if (icc_segment_num > 255) {
91 return FALSE; 91 return FALSE;
92 } 92 }
93 FX_DWORD icc_data_length = 93 uint32_t icc_data_length =
94 JPEG_OVERHEAD_LEN + (icc_segment_num > 1 ? icc_segment_size : icc_length); 94 JPEG_OVERHEAD_LEN + (icc_segment_num > 1 ? icc_segment_size : icc_length);
95 uint8_t* icc_data = FX_Alloc(uint8_t, icc_data_length); 95 uint8_t* icc_data = FX_Alloc(uint8_t, icc_data_length);
96 FXSYS_memcpy(icc_data, "\x49\x43\x43\x5f\x50\x52\x4f\x46\x49\x4c\x45\x00", 96 FXSYS_memcpy(icc_data, "\x49\x43\x43\x5f\x50\x52\x4f\x46\x49\x4c\x45\x00",
97 12); 97 12);
98 icc_data[13] = (uint8_t)icc_segment_num; 98 icc_data[13] = (uint8_t)icc_segment_num;
99 for (uint8_t i = 0; i < (icc_segment_num - 1); i++) { 99 for (uint8_t i = 0; i < (icc_segment_num - 1); i++) {
100 icc_data[12] = i + 1; 100 icc_data[12] = i + 1;
101 FXSYS_memcpy(icc_data + JPEG_OVERHEAD_LEN, 101 FXSYS_memcpy(icc_data + JPEG_OVERHEAD_LEN,
102 icc_buf_ptr + i * icc_segment_size, icc_segment_size); 102 icc_buf_ptr + i * icc_segment_size, icc_segment_size);
103 jpeg_write_marker(cinfo, JPEG_MARKER_ICC, icc_data, icc_data_length); 103 jpeg_write_marker(cinfo, JPEG_MARKER_ICC, icc_data, icc_data_length);
104 } 104 }
105 icc_data[12] = (uint8_t)icc_segment_num; 105 icc_data[12] = (uint8_t)icc_segment_num;
106 FX_DWORD icc_size = (icc_segment_num - 1) * icc_segment_size; 106 uint32_t icc_size = (icc_segment_num - 1) * icc_segment_size;
107 FXSYS_memcpy(icc_data + JPEG_OVERHEAD_LEN, icc_buf_ptr + icc_size, 107 FXSYS_memcpy(icc_data + JPEG_OVERHEAD_LEN, icc_buf_ptr + icc_size,
108 icc_length - icc_size); 108 icc_length - icc_size);
109 jpeg_write_marker(cinfo, JPEG_MARKER_ICC, icc_data, 109 jpeg_write_marker(cinfo, JPEG_MARKER_ICC, icc_data,
110 JPEG_OVERHEAD_LEN + icc_length - icc_size); 110 JPEG_OVERHEAD_LEN + icc_length - icc_size);
111 FX_Free(icc_data); 111 FX_Free(icc_data);
112 return TRUE; 112 return TRUE;
113 } 113 }
114 extern "C" { 114 extern "C" {
115 static void _dest_do_nothing(j_compress_ptr cinfo) {} 115 static void _dest_do_nothing(j_compress_ptr cinfo) {}
116 }; 116 };
117 extern "C" { 117 extern "C" {
118 static boolean _dest_empty(j_compress_ptr cinfo) { 118 static boolean _dest_empty(j_compress_ptr cinfo) {
119 return FALSE; 119 return FALSE;
120 } 120 }
121 }; 121 };
122 #define JPEG_BLOCK_SIZE 1048576 122 #define JPEG_BLOCK_SIZE 1048576
123 static void _JpegEncode(const CFX_DIBSource* pSource, 123 static void _JpegEncode(const CFX_DIBSource* pSource,
124 uint8_t*& dest_buf, 124 uint8_t*& dest_buf,
125 FX_STRSIZE& dest_size, 125 FX_STRSIZE& dest_size,
126 int quality, 126 int quality,
127 const uint8_t* icc_buf, 127 const uint8_t* icc_buf,
128 FX_DWORD icc_length) { 128 uint32_t icc_length) {
129 struct jpeg_error_mgr jerr; 129 struct jpeg_error_mgr jerr;
130 jerr.error_exit = _error_do_nothing; 130 jerr.error_exit = _error_do_nothing;
131 jerr.emit_message = _error_do_nothing1; 131 jerr.emit_message = _error_do_nothing1;
132 jerr.output_message = _error_do_nothing; 132 jerr.output_message = _error_do_nothing;
133 jerr.format_message = _error_do_nothing2; 133 jerr.format_message = _error_do_nothing2;
134 jerr.reset_error_mgr = _error_do_nothing; 134 jerr.reset_error_mgr = _error_do_nothing;
135 135
136 struct jpeg_compress_struct cinfo; 136 struct jpeg_compress_struct cinfo;
137 memset(&cinfo, 0, sizeof(cinfo)); 137 memset(&cinfo, 0, sizeof(cinfo));
138 cinfo.err = &jerr; 138 cinfo.err = &jerr;
139 jpeg_create_compress(&cinfo); 139 jpeg_create_compress(&cinfo);
140 int Bpp = pSource->GetBPP() / 8; 140 int Bpp = pSource->GetBPP() / 8;
141 FX_DWORD nComponents = Bpp >= 3 ? (pSource->IsCmykImage() ? 4 : 3) : 1; 141 uint32_t nComponents = Bpp >= 3 ? (pSource->IsCmykImage() ? 4 : 3) : 1;
142 FX_DWORD pitch = pSource->GetPitch(); 142 uint32_t pitch = pSource->GetPitch();
143 FX_DWORD width = pdfium::base::checked_cast<FX_DWORD>(pSource->GetWidth()); 143 uint32_t width = pdfium::base::checked_cast<uint32_t>(pSource->GetWidth());
144 FX_DWORD height = pdfium::base::checked_cast<FX_DWORD>(pSource->GetHeight()); 144 uint32_t height = pdfium::base::checked_cast<uint32_t>(pSource->GetHeight());
145 FX_SAFE_DWORD safe_buf_len = width; 145 FX_SAFE_DWORD safe_buf_len = width;
146 safe_buf_len *= height; 146 safe_buf_len *= height;
147 safe_buf_len *= nComponents; 147 safe_buf_len *= nComponents;
148 safe_buf_len += 1024; 148 safe_buf_len += 1024;
149 if (icc_length) { 149 if (icc_length) {
150 safe_buf_len += 255 * 18; 150 safe_buf_len += 255 * 18;
151 safe_buf_len += icc_length; 151 safe_buf_len += icc_length;
152 } 152 }
153 FX_DWORD dest_buf_length = 0; 153 uint32_t dest_buf_length = 0;
154 if (!safe_buf_len.IsValid()) { 154 if (!safe_buf_len.IsValid()) {
155 dest_buf = nullptr; 155 dest_buf = nullptr;
156 } else { 156 } else {
157 dest_buf_length = safe_buf_len.ValueOrDie(); 157 dest_buf_length = safe_buf_len.ValueOrDie();
158 dest_buf = FX_TryAlloc(uint8_t, dest_buf_length); 158 dest_buf = FX_TryAlloc(uint8_t, dest_buf_length);
159 const int MIN_TRY_BUF_LEN = 1024; 159 const int MIN_TRY_BUF_LEN = 1024;
160 while (!dest_buf && dest_buf_length > MIN_TRY_BUF_LEN) { 160 while (!dest_buf && dest_buf_length > MIN_TRY_BUF_LEN) {
161 dest_buf_length >>= 1; 161 dest_buf_length >>= 1;
162 dest_buf = FX_TryAlloc(uint8_t, dest_buf_length); 162 dest_buf = FX_TryAlloc(uint8_t, dest_buf_length);
163 } 163 }
(...skipping 28 matching lines...) Expand all
192 } 192 }
193 jpeg_start_compress(&cinfo, TRUE); 193 jpeg_start_compress(&cinfo, TRUE);
194 _JpegEmbedIccProfile(&cinfo, icc_buf, icc_length); 194 _JpegEmbedIccProfile(&cinfo, icc_buf, icc_length);
195 JSAMPROW row_pointer[1]; 195 JSAMPROW row_pointer[1];
196 JDIMENSION row; 196 JDIMENSION row;
197 while (cinfo.next_scanline < cinfo.image_height) { 197 while (cinfo.next_scanline < cinfo.image_height) {
198 const uint8_t* src_scan = pSource->GetScanline(cinfo.next_scanline); 198 const uint8_t* src_scan = pSource->GetScanline(cinfo.next_scanline);
199 if (nComponents > 1) { 199 if (nComponents > 1) {
200 uint8_t* dest_scan = line_buf; 200 uint8_t* dest_scan = line_buf;
201 if (nComponents == 3) { 201 if (nComponents == 3) {
202 for (FX_DWORD i = 0; i < width; i++) { 202 for (uint32_t i = 0; i < width; i++) {
203 dest_scan[0] = src_scan[2]; 203 dest_scan[0] = src_scan[2];
204 dest_scan[1] = src_scan[1]; 204 dest_scan[1] = src_scan[1];
205 dest_scan[2] = src_scan[0]; 205 dest_scan[2] = src_scan[0];
206 dest_scan += 3; 206 dest_scan += 3;
207 src_scan += Bpp; 207 src_scan += Bpp;
208 } 208 }
209 } else { 209 } else {
210 for (FX_DWORD i = 0; i < pitch; i++) { 210 for (uint32_t i = 0; i < pitch; i++) {
211 *dest_scan++ = ~*src_scan++; 211 *dest_scan++ = ~*src_scan++;
212 } 212 }
213 } 213 }
214 row_pointer[0] = line_buf; 214 row_pointer[0] = line_buf;
215 } else { 215 } else {
216 row_pointer[0] = (uint8_t*)src_scan; 216 row_pointer[0] = (uint8_t*)src_scan;
217 } 217 }
218 row = cinfo.next_scanline; 218 row = cinfo.next_scanline;
219 jpeg_write_scanlines(&cinfo, row_pointer, 1); 219 jpeg_write_scanlines(&cinfo, row_pointer, 1);
220 if (cinfo.next_scanline == row) { 220 if (cinfo.next_scanline == row) {
(...skipping 18 matching lines...) Expand all
239 } 239 }
240 if (pAttribute) { 240 if (pAttribute) {
241 pAttribute->m_nXDPI = pInfo->X_density; 241 pAttribute->m_nXDPI = pInfo->X_density;
242 pAttribute->m_nYDPI = pInfo->Y_density; 242 pAttribute->m_nYDPI = pInfo->Y_density;
243 pAttribute->m_wDPIUnit = pInfo->density_unit; 243 pAttribute->m_wDPIUnit = pInfo->density_unit;
244 } 244 }
245 } 245 }
246 #endif // PDF_ENABLE_XFA 246 #endif // PDF_ENABLE_XFA
247 247
248 static FX_BOOL _JpegLoadInfo(const uint8_t* src_buf, 248 static FX_BOOL _JpegLoadInfo(const uint8_t* src_buf,
249 FX_DWORD src_size, 249 uint32_t src_size,
250 int& width, 250 int& width,
251 int& height, 251 int& height,
252 int& num_components, 252 int& num_components,
253 int& bits_per_components, 253 int& bits_per_components,
254 FX_BOOL& color_transform, 254 FX_BOOL& color_transform,
255 uint8_t** icc_buf_ptr, 255 uint8_t** icc_buf_ptr,
256 FX_DWORD* icc_length) { 256 uint32_t* icc_length) {
257 _JpegScanSOI(src_buf, src_size); 257 _JpegScanSOI(src_buf, src_size);
258 struct jpeg_decompress_struct cinfo; 258 struct jpeg_decompress_struct cinfo;
259 struct jpeg_error_mgr jerr; 259 struct jpeg_error_mgr jerr;
260 jerr.error_exit = _error_fatal; 260 jerr.error_exit = _error_fatal;
261 jerr.emit_message = _error_do_nothing1; 261 jerr.emit_message = _error_do_nothing1;
262 jerr.output_message = _error_do_nothing; 262 jerr.output_message = _error_do_nothing;
263 jerr.format_message = _error_do_nothing2; 263 jerr.format_message = _error_do_nothing2;
264 jerr.reset_error_mgr = _error_do_nothing; 264 jerr.reset_error_mgr = _error_do_nothing;
265 jerr.trace_level = 0; 265 jerr.trace_level = 0;
266 cinfo.err = &jerr; 266 cinfo.err = &jerr;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 jpeg_destroy_decompress(&cinfo); 306 jpeg_destroy_decompress(&cinfo);
307 return TRUE; 307 return TRUE;
308 } 308 }
309 309
310 class CCodec_JpegDecoder : public CCodec_ScanlineDecoder { 310 class CCodec_JpegDecoder : public CCodec_ScanlineDecoder {
311 public: 311 public:
312 CCodec_JpegDecoder(); 312 CCodec_JpegDecoder();
313 ~CCodec_JpegDecoder() override; 313 ~CCodec_JpegDecoder() override;
314 314
315 FX_BOOL Create(const uint8_t* src_buf, 315 FX_BOOL Create(const uint8_t* src_buf,
316 FX_DWORD src_size, 316 uint32_t src_size,
317 int width, 317 int width,
318 int height, 318 int height,
319 int nComps, 319 int nComps,
320 FX_BOOL ColorTransform); 320 FX_BOOL ColorTransform);
321 void Destroy() { delete this; } 321 void Destroy() { delete this; }
322 322
323 // CCodec_ScanlineDecoder 323 // CCodec_ScanlineDecoder
324 void v_DownScale(int dest_width, int dest_height) override; 324 void v_DownScale(int dest_width, int dest_height) override;
325 FX_BOOL v_Rewind() override; 325 FX_BOOL v_Rewind() override;
326 uint8_t* v_GetNextLine() override; 326 uint8_t* v_GetNextLine() override;
327 FX_DWORD GetSrcOffset() override; 327 uint32_t GetSrcOffset() override;
328 328
329 FX_BOOL InitDecode(); 329 FX_BOOL InitDecode();
330 330
331 jmp_buf m_JmpBuf; 331 jmp_buf m_JmpBuf;
332 struct jpeg_decompress_struct cinfo; 332 struct jpeg_decompress_struct cinfo;
333 struct jpeg_error_mgr jerr; 333 struct jpeg_error_mgr jerr;
334 struct jpeg_source_mgr src; 334 struct jpeg_source_mgr src;
335 const uint8_t* m_SrcBuf; 335 const uint8_t* m_SrcBuf;
336 FX_DWORD m_SrcSize; 336 uint32_t m_SrcSize;
337 uint8_t* m_pScanlineBuf; 337 uint8_t* m_pScanlineBuf;
338 338
339 FX_BOOL m_bInited; 339 FX_BOOL m_bInited;
340 FX_BOOL m_bStarted; 340 FX_BOOL m_bStarted;
341 FX_BOOL m_bJpegTransform; 341 FX_BOOL m_bJpegTransform;
342 342
343 protected: 343 protected:
344 FX_DWORD m_nDefaultScaleDenom; 344 uint32_t m_nDefaultScaleDenom;
345 }; 345 };
346 346
347 CCodec_JpegDecoder::CCodec_JpegDecoder() { 347 CCodec_JpegDecoder::CCodec_JpegDecoder() {
348 m_pScanlineBuf = NULL; 348 m_pScanlineBuf = NULL;
349 m_DownScale = 1; 349 m_DownScale = 1;
350 m_bStarted = FALSE; 350 m_bStarted = FALSE;
351 m_bInited = FALSE; 351 m_bInited = FALSE;
352 FXSYS_memset(&cinfo, 0, sizeof(cinfo)); 352 FXSYS_memset(&cinfo, 0, sizeof(cinfo));
353 FXSYS_memset(&jerr, 0, sizeof(jerr)); 353 FXSYS_memset(&jerr, 0, sizeof(jerr));
354 FXSYS_memset(&src, 0, sizeof(src)); 354 FXSYS_memset(&src, 0, sizeof(src));
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 cinfo.out_color_space = cinfo.jpeg_color_space; 389 cinfo.out_color_space = cinfo.jpeg_color_space;
390 } 390 }
391 m_OrigWidth = cinfo.image_width; 391 m_OrigWidth = cinfo.image_width;
392 m_OrigHeight = cinfo.image_height; 392 m_OrigHeight = cinfo.image_height;
393 m_OutputWidth = m_OrigWidth; 393 m_OutputWidth = m_OrigWidth;
394 m_OutputHeight = m_OrigHeight; 394 m_OutputHeight = m_OrigHeight;
395 m_nDefaultScaleDenom = cinfo.scale_denom; 395 m_nDefaultScaleDenom = cinfo.scale_denom;
396 return TRUE; 396 return TRUE;
397 } 397 }
398 FX_BOOL CCodec_JpegDecoder::Create(const uint8_t* src_buf, 398 FX_BOOL CCodec_JpegDecoder::Create(const uint8_t* src_buf,
399 FX_DWORD src_size, 399 uint32_t src_size,
400 int width, 400 int width,
401 int height, 401 int height,
402 int nComps, 402 int nComps,
403 FX_BOOL ColorTransform) { 403 FX_BOOL ColorTransform) {
404 _JpegScanSOI(src_buf, src_size); 404 _JpegScanSOI(src_buf, src_size);
405 m_SrcBuf = src_buf; 405 m_SrcBuf = src_buf;
406 m_SrcSize = src_size; 406 m_SrcSize = src_size;
407 jerr.error_exit = _error_fatal; 407 jerr.error_exit = _error_fatal;
408 jerr.emit_message = _error_do_nothing1; 408 jerr.emit_message = _error_do_nothing1;
409 jerr.output_message = _error_do_nothing; 409 jerr.output_message = _error_do_nothing;
(...skipping 15 matching lines...) Expand all
425 if (!InitDecode()) { 425 if (!InitDecode()) {
426 return FALSE; 426 return FALSE;
427 } 427 }
428 if (cinfo.num_components < nComps) { 428 if (cinfo.num_components < nComps) {
429 return FALSE; 429 return FALSE;
430 } 430 }
431 if ((int)cinfo.image_width < width) { 431 if ((int)cinfo.image_width < width) {
432 return FALSE; 432 return FALSE;
433 } 433 }
434 m_Pitch = 434 m_Pitch =
435 (static_cast<FX_DWORD>(cinfo.image_width) * cinfo.num_components + 3) / 435 (static_cast<uint32_t>(cinfo.image_width) * cinfo.num_components + 3) /
436 4 * 4; 436 4 * 4;
437 m_pScanlineBuf = FX_Alloc(uint8_t, m_Pitch); 437 m_pScanlineBuf = FX_Alloc(uint8_t, m_Pitch);
438 m_nComps = cinfo.num_components; 438 m_nComps = cinfo.num_components;
439 m_bpc = 8; 439 m_bpc = 8;
440 m_bColorTransformed = FALSE; 440 m_bColorTransformed = FALSE;
441 m_bStarted = FALSE; 441 m_bStarted = FALSE;
442 return TRUE; 442 return TRUE;
443 } 443 }
444 extern "C" { 444 extern "C" {
445 int32_t FX_GetDownsampleRatio(int32_t originWidth, 445 int32_t FX_GetDownsampleRatio(int32_t originWidth,
(...skipping 14 matching lines...) Expand all
460 } 460 }
461 return 1; 461 return 1;
462 } 462 }
463 } 463 }
464 void CCodec_JpegDecoder::v_DownScale(int dest_width, int dest_height) { 464 void CCodec_JpegDecoder::v_DownScale(int dest_width, int dest_height) {
465 int old_scale = m_DownScale; 465 int old_scale = m_DownScale;
466 m_DownScale = 466 m_DownScale =
467 FX_GetDownsampleRatio(m_OrigWidth, m_OrigHeight, dest_width, dest_height); 467 FX_GetDownsampleRatio(m_OrigWidth, m_OrigHeight, dest_width, dest_height);
468 m_OutputWidth = (m_OrigWidth + m_DownScale - 1) / m_DownScale; 468 m_OutputWidth = (m_OrigWidth + m_DownScale - 1) / m_DownScale;
469 m_OutputHeight = (m_OrigHeight + m_DownScale - 1) / m_DownScale; 469 m_OutputHeight = (m_OrigHeight + m_DownScale - 1) / m_DownScale;
470 m_Pitch = (static_cast<FX_DWORD>(m_OutputWidth) * m_nComps + 3) / 4 * 4; 470 m_Pitch = (static_cast<uint32_t>(m_OutputWidth) * m_nComps + 3) / 4 * 4;
471 if (old_scale != m_DownScale) { 471 if (old_scale != m_DownScale) {
472 m_NextLine = -1; 472 m_NextLine = -1;
473 } 473 }
474 } 474 }
475 FX_BOOL CCodec_JpegDecoder::v_Rewind() { 475 FX_BOOL CCodec_JpegDecoder::v_Rewind() {
476 if (m_bStarted) { 476 if (m_bStarted) {
477 jpeg_destroy_decompress(&cinfo); 477 jpeg_destroy_decompress(&cinfo);
478 if (!InitDecode()) { 478 if (!InitDecode()) {
479 return FALSE; 479 return FALSE;
480 } 480 }
(...skipping 18 matching lines...) Expand all
499 uint8_t* CCodec_JpegDecoder::v_GetNextLine() { 499 uint8_t* CCodec_JpegDecoder::v_GetNextLine() {
500 if (setjmp(m_JmpBuf) == -1) 500 if (setjmp(m_JmpBuf) == -1)
501 return nullptr; 501 return nullptr;
502 502
503 int nlines = jpeg_read_scanlines(&cinfo, &m_pScanlineBuf, 1); 503 int nlines = jpeg_read_scanlines(&cinfo, &m_pScanlineBuf, 1);
504 if (nlines < 1) { 504 if (nlines < 1) {
505 return nullptr; 505 return nullptr;
506 } 506 }
507 return m_pScanlineBuf; 507 return m_pScanlineBuf;
508 } 508 }
509 FX_DWORD CCodec_JpegDecoder::GetSrcOffset() { 509 uint32_t CCodec_JpegDecoder::GetSrcOffset() {
510 return (FX_DWORD)(m_SrcSize - src.bytes_in_buffer); 510 return (uint32_t)(m_SrcSize - src.bytes_in_buffer);
511 } 511 }
512 ICodec_ScanlineDecoder* CCodec_JpegModule::CreateDecoder( 512 ICodec_ScanlineDecoder* CCodec_JpegModule::CreateDecoder(
513 const uint8_t* src_buf, 513 const uint8_t* src_buf,
514 FX_DWORD src_size, 514 uint32_t src_size,
515 int width, 515 int width,
516 int height, 516 int height,
517 int nComps, 517 int nComps,
518 FX_BOOL ColorTransform) { 518 FX_BOOL ColorTransform) {
519 if (!src_buf || src_size == 0) { 519 if (!src_buf || src_size == 0) {
520 return NULL; 520 return NULL;
521 } 521 }
522 CCodec_JpegDecoder* pDecoder = new CCodec_JpegDecoder; 522 CCodec_JpegDecoder* pDecoder = new CCodec_JpegDecoder;
523 if (!pDecoder->Create(src_buf, src_size, width, height, nComps, 523 if (!pDecoder->Create(src_buf, src_size, width, height, nComps,
524 ColorTransform)) { 524 ColorTransform)) {
525 delete pDecoder; 525 delete pDecoder;
526 return NULL; 526 return NULL;
527 } 527 }
528 return pDecoder; 528 return pDecoder;
529 } 529 }
530 FX_BOOL CCodec_JpegModule::LoadInfo(const uint8_t* src_buf, 530 FX_BOOL CCodec_JpegModule::LoadInfo(const uint8_t* src_buf,
531 FX_DWORD src_size, 531 uint32_t src_size,
532 int& width, 532 int& width,
533 int& height, 533 int& height,
534 int& num_components, 534 int& num_components,
535 int& bits_per_components, 535 int& bits_per_components,
536 FX_BOOL& color_transform, 536 FX_BOOL& color_transform,
537 uint8_t** icc_buf_ptr, 537 uint8_t** icc_buf_ptr,
538 FX_DWORD* icc_length) { 538 uint32_t* icc_length) {
539 return _JpegLoadInfo(src_buf, src_size, width, height, num_components, 539 return _JpegLoadInfo(src_buf, src_size, width, height, num_components,
540 bits_per_components, color_transform, icc_buf_ptr, 540 bits_per_components, color_transform, icc_buf_ptr,
541 icc_length); 541 icc_length);
542 } 542 }
543 FX_BOOL CCodec_JpegModule::Encode(const CFX_DIBSource* pSource, 543 FX_BOOL CCodec_JpegModule::Encode(const CFX_DIBSource* pSource,
544 uint8_t*& dest_buf, 544 uint8_t*& dest_buf,
545 FX_STRSIZE& dest_size, 545 FX_STRSIZE& dest_size,
546 int quality, 546 int quality,
547 const uint8_t* icc_buf, 547 const uint8_t* icc_buf,
548 FX_DWORD icc_length) { 548 uint32_t icc_length) {
549 if (pSource->GetBPP() < 8 || pSource->GetPalette()) 549 if (pSource->GetBPP() < 8 || pSource->GetPalette())
550 return FALSE; 550 return FALSE;
551 551
552 _JpegEncode(pSource, dest_buf, dest_size, quality, icc_buf, icc_length); 552 _JpegEncode(pSource, dest_buf, dest_size, quality, icc_buf, icc_length);
553 return TRUE; 553 return TRUE;
554 } 554 }
555 struct FXJPEG_Context { 555 struct FXJPEG_Context {
556 jmp_buf m_JumpMark; 556 jmp_buf m_JumpMark;
557 jpeg_decompress_struct m_Info; 557 jpeg_decompress_struct m_Info;
558 jpeg_error_mgr m_ErrMgr; 558 jpeg_error_mgr m_ErrMgr;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 p->m_SkipSize = 0; 608 p->m_SkipSize = 0;
609 return p; 609 return p;
610 } 610 }
611 void CCodec_JpegModule::Finish(void* pContext) { 611 void CCodec_JpegModule::Finish(void* pContext) {
612 FXJPEG_Context* p = (FXJPEG_Context*)pContext; 612 FXJPEG_Context* p = (FXJPEG_Context*)pContext;
613 jpeg_destroy_decompress(&p->m_Info); 613 jpeg_destroy_decompress(&p->m_Info);
614 p->m_FreeFunc(p); 614 p->m_FreeFunc(p);
615 } 615 }
616 void CCodec_JpegModule::Input(void* pContext, 616 void CCodec_JpegModule::Input(void* pContext,
617 const unsigned char* src_buf, 617 const unsigned char* src_buf,
618 FX_DWORD src_size) { 618 uint32_t src_size) {
619 FXJPEG_Context* p = (FXJPEG_Context*)pContext; 619 FXJPEG_Context* p = (FXJPEG_Context*)pContext;
620 if (p->m_SkipSize) { 620 if (p->m_SkipSize) {
621 if (p->m_SkipSize > src_size) { 621 if (p->m_SkipSize > src_size) {
622 p->m_SrcMgr.bytes_in_buffer = 0; 622 p->m_SrcMgr.bytes_in_buffer = 0;
623 p->m_SkipSize -= src_size; 623 p->m_SkipSize -= src_size;
624 return; 624 return;
625 } 625 }
626 src_size -= p->m_SkipSize; 626 src_size -= p->m_SkipSize;
627 src_buf += p->m_SkipSize; 627 src_buf += p->m_SkipSize;
628 p->m_SkipSize = 0; 628 p->m_SkipSize = 0;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
672 } 672 }
673 FX_BOOL CCodec_JpegModule::ReadScanline(void* pContext, 673 FX_BOOL CCodec_JpegModule::ReadScanline(void* pContext,
674 unsigned char* dest_buf) { 674 unsigned char* dest_buf) {
675 FXJPEG_Context* p = (FXJPEG_Context*)pContext; 675 FXJPEG_Context* p = (FXJPEG_Context*)pContext;
676 if (setjmp(p->m_JumpMark) == -1) { 676 if (setjmp(p->m_JumpMark) == -1) {
677 return FALSE; 677 return FALSE;
678 } 678 }
679 int nlines = jpeg_read_scanlines(&p->m_Info, &dest_buf, 1); 679 int nlines = jpeg_read_scanlines(&p->m_Info, &dest_buf, 1);
680 return nlines == 1; 680 return nlines == 1;
681 } 681 }
682 FX_DWORD CCodec_JpegModule::GetAvailInput(void* pContext, 682 uint32_t CCodec_JpegModule::GetAvailInput(void* pContext,
683 uint8_t** avail_buf_ptr) { 683 uint8_t** avail_buf_ptr) {
684 if (avail_buf_ptr) { 684 if (avail_buf_ptr) {
685 *avail_buf_ptr = NULL; 685 *avail_buf_ptr = NULL;
686 if (((FXJPEG_Context*)pContext)->m_SrcMgr.bytes_in_buffer > 0) { 686 if (((FXJPEG_Context*)pContext)->m_SrcMgr.bytes_in_buffer > 0) {
687 *avail_buf_ptr = 687 *avail_buf_ptr =
688 (uint8_t*)((FXJPEG_Context*)pContext)->m_SrcMgr.next_input_byte; 688 (uint8_t*)((FXJPEG_Context*)pContext)->m_SrcMgr.next_input_byte;
689 } 689 }
690 } 690 }
691 return (FX_DWORD)((FXJPEG_Context*)pContext)->m_SrcMgr.bytes_in_buffer; 691 return (uint32_t)((FXJPEG_Context*)pContext)->m_SrcMgr.bytes_in_buffer;
692 } 692 }
OLDNEW
« no previous file with comments | « core/fxcodec/codec/fx_codec_jbig.cpp ('k') | core/fxcodec/codec/fx_codec_jpx_opj.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698