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

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

Issue 1177483002: Use stdint.h types throughout PDFium. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 5 years, 6 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/src/fxcodec/codec/fx_codec_jbig.cpp ('k') | core/src/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 "../../../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"
11 #include "../../../include/fxge/fx_dib.h" 11 #include "../../../include/fxge/fx_dib.h"
12 #include "codec_int.h" 12 #include "codec_int.h"
13 13
14 extern "C" { 14 extern "C" {
15 static void _JpegScanSOI(const FX_BYTE*& src_buf, FX_DWORD& src_size) 15 static void _JpegScanSOI(const uint8_t*& src_buf, FX_DWORD& src_size)
16 { 16 {
17 if (src_size == 0) { 17 if (src_size == 0) {
18 return; 18 return;
19 } 19 }
20 FX_DWORD offset = 0; 20 FX_DWORD offset = 0;
21 while (offset < src_size - 1) { 21 while (offset < src_size - 1) {
22 if (src_buf[offset] == 0xff && src_buf[offset + 1] == 0xd8) { 22 if (src_buf[offset] == 0xff && src_buf[offset + 1] == 0xd8) {
23 src_buf += offset; 23 src_buf += offset;
24 src_size -= offset; 24 src_size -= offset;
25 return; 25 return;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(FX_BYTE, icc_data_length); 91 FX_LPBYTE 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] = (FX_BYTE)icc_segment_num; 93 icc_data[13] = (uint8_t)icc_segment_num;
94 for (FX_BYTE 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] = (FX_BYTE)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" {
(...skipping 27 matching lines...) Expand all
137 safe_buf_len += 1024; 137 safe_buf_len += 1024;
138 if (icc_length) { 138 if (icc_length) {
139 safe_buf_len += 255 * 18; 139 safe_buf_len += 255 * 18;
140 safe_buf_len += icc_length; 140 safe_buf_len += icc_length;
141 } 141 }
142 FX_DWORD dest_buf_length = 0; 142 FX_DWORD dest_buf_length = 0;
143 if (!safe_buf_len.IsValid()) { 143 if (!safe_buf_len.IsValid()) {
144 dest_buf = nullptr; 144 dest_buf = nullptr;
145 } else { 145 } else {
146 dest_buf_length = safe_buf_len.ValueOrDie(); 146 dest_buf_length = safe_buf_len.ValueOrDie();
147 dest_buf = FX_TryAlloc(FX_BYTE, dest_buf_length); 147 dest_buf = FX_TryAlloc(uint8_t, dest_buf_length);
148 const int MIN_TRY_BUF_LEN = 1024; 148 const int MIN_TRY_BUF_LEN = 1024;
149 while (!dest_buf && dest_buf_length > MIN_TRY_BUF_LEN) { 149 while (!dest_buf && dest_buf_length > MIN_TRY_BUF_LEN) {
150 dest_buf_length >>= 1; 150 dest_buf_length >>= 1;
151 dest_buf = FX_TryAlloc(FX_BYTE, dest_buf_length); 151 dest_buf = FX_TryAlloc(uint8_t, dest_buf_length);
152 } 152 }
153 } 153 }
154 if (!dest_buf) { 154 if (!dest_buf) {
155 FX_OutOfMemoryTerminate(); 155 FX_OutOfMemoryTerminate();
156 } 156 }
157 struct jpeg_destination_mgr dest; 157 struct jpeg_destination_mgr dest;
158 dest.init_destination = _dest_do_nothing; 158 dest.init_destination = _dest_do_nothing;
159 dest.term_destination = _dest_do_nothing; 159 dest.term_destination = _dest_do_nothing;
160 dest.empty_output_buffer = _dest_empty; 160 dest.empty_output_buffer = _dest_empty;
161 dest.next_output_byte = dest_buf; 161 dest.next_output_byte = dest_buf;
162 dest.free_in_buffer = dest_buf_length; 162 dest.free_in_buffer = dest_buf_length;
163 cinfo.dest = &dest; 163 cinfo.dest = &dest;
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 FX_LPBYTE line_buf = NULL;
175 if (nComponents > 1) { 175 if (nComponents > 1) {
176 line_buf = FX_Alloc2D(FX_BYTE, 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) {
(...skipping 13 matching lines...) Expand all
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] = (FX_LPBYTE)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(FX_BYTE, 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 }
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
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) {
404 return FALSE; 404 return FALSE;
405 } 405 }
406 m_Pitch = (cinfo.image_width * cinfo.num_components + 3) / 4 * 4; 406 m_Pitch = (cinfo.image_width * cinfo.num_components + 3) / 4 * 4;
407 m_pScanlineBuf = FX_Alloc(FX_BYTE, m_Pitch); 407 m_pScanlineBuf = FX_Alloc(uint8_t, m_Pitch);
408 m_nComps = cinfo.num_components; 408 m_nComps = cinfo.num_components;
409 m_bpc = 8; 409 m_bpc = 8;
410 m_bColorTransformed = FALSE; 410 m_bColorTransformed = FALSE;
411 m_bStarted = FALSE; 411 m_bStarted = FALSE;
412 return TRUE; 412 return TRUE;
413 } 413 }
414 extern "C" { 414 extern "C" {
415 FX_INT32 FX_GetDownsampleRatio(FX_INT32 originWidth, FX_INT32 originHeight, FX_INT32 downsampleWidth, FX_INT32 downsampleHeight) 415 int32_t FX_GetDownsampleRatio(int32_t originWidth, int32_t originHeight, int 32_t downsampleWidth, int32_t downsampleHeight)
416 { 416 {
417 int iratio_w = originWidth / downsampleWidth; 417 int iratio_w = originWidth / downsampleWidth;
418 int iratio_h = originHeight / downsampleHeight; 418 int iratio_h = originHeight / downsampleHeight;
419 int ratio = (iratio_w > iratio_h) ? iratio_h : iratio_w; 419 int ratio = (iratio_w > iratio_h) ? iratio_h : iratio_w;
420 if (ratio >= 8) { 420 if (ratio >= 8) {
421 return 8; 421 return 8;
422 } else if (ratio >= 4) { 422 } else if (ratio >= 4) {
423 return 4; 423 return 4;
424 } else if (ratio >= 2) { 424 } else if (ratio >= 2) {
425 return 2; 425 return 2;
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 } 557 }
558 static void jpeg_free_func(void* p) 558 static void jpeg_free_func(void* p)
559 { 559 {
560 FX_Free(p); 560 FX_Free(p);
561 } 561 }
562 void* CCodec_JpegModule::Start() 562 void* CCodec_JpegModule::Start()
563 { 563 {
564 if (m_pExtProvider) { 564 if (m_pExtProvider) {
565 return m_pExtProvider->Start(); 565 return m_pExtProvider->Start();
566 } 566 }
567 FXJPEG_Context* p = (FXJPEG_Context*)FX_Alloc(FX_BYTE, sizeof(FXJPEG_Context )); 567 FXJPEG_Context* p = (FXJPEG_Context*)FX_Alloc(uint8_t, sizeof(FXJPEG_Context ));
568 p->m_AllocFunc = jpeg_alloc_func; 568 p->m_AllocFunc = jpeg_alloc_func;
569 p->m_FreeFunc = jpeg_free_func; 569 p->m_FreeFunc = jpeg_free_func;
570 p->m_ErrMgr.error_exit = _error_fatal1; 570 p->m_ErrMgr.error_exit = _error_fatal1;
571 p->m_ErrMgr.emit_message = _error_do_nothing1; 571 p->m_ErrMgr.emit_message = _error_do_nothing1;
572 p->m_ErrMgr.output_message = _error_do_nothing; 572 p->m_ErrMgr.output_message = _error_do_nothing;
573 p->m_ErrMgr.format_message = _error_do_nothing2; 573 p->m_ErrMgr.format_message = _error_do_nothing2;
574 p->m_ErrMgr.reset_error_mgr = _error_do_nothing; 574 p->m_ErrMgr.reset_error_mgr = _error_do_nothing;
575 p->m_SrcMgr.init_source = _src_do_nothing; 575 p->m_SrcMgr.init_source = _src_do_nothing;
576 p->m_SrcMgr.term_source = _src_do_nothing; 576 p->m_SrcMgr.term_source = _src_do_nothing;
577 p->m_SrcMgr.skip_input_data = _src_skip_data1; 577 p->m_SrcMgr.skip_input_data = _src_skip_data1;
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 = (FX_LPBYTE)((FXJPEG_Context*)pContext)->m_SrcMgr.ne xt_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 }
OLDNEW
« no previous file with comments | « core/src/fxcodec/codec/fx_codec_jbig.cpp ('k') | core/src/fxcodec/codec/fx_codec_jpx_opj.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698