Chromium Code Reviews| Index: Source/platform/image-decoders/jpeg/JPEGImageDecoder.cpp |
| diff --git a/Source/platform/image-decoders/jpeg/JPEGImageDecoder.cpp b/Source/platform/image-decoders/jpeg/JPEGImageDecoder.cpp |
| index bb1db2b50ff9f8d441cea9d4e0a49abf0059a11a..3316317d5bd920c7506db194dc0d3f0126b8f340 100644 |
| --- a/Source/platform/image-decoders/jpeg/JPEGImageDecoder.cpp |
| +++ b/Source/platform/image-decoders/jpeg/JPEGImageDecoder.cpp |
| @@ -89,6 +89,7 @@ namespace blink { |
| struct decoder_error_mgr { |
| struct jpeg_error_mgr pub; // "public" fields for IJG library |
| + int num_corrupt_warnings; // Counts corrupt warning messages |
| jmp_buf setjmp_buffer; // For handling catastropic errors |
| }; |
| @@ -116,6 +117,7 @@ boolean fill_input_buffer(j_decompress_ptr jd); |
| void skip_input_data(j_decompress_ptr jd, long num_bytes); |
| void term_source(j_decompress_ptr jd); |
| void error_exit(j_common_ptr cinfo); |
| +void emit_message(j_common_ptr cinfo, int msg_level); |
| // Implementation of a JPEG src object that understands our state machine |
| struct decoder_source_mgr { |
| @@ -312,9 +314,11 @@ public: |
| { |
| memset(&m_info, 0, sizeof(jpeg_decompress_struct)); |
| - // Set up the normal JPEG error routines, then override error_exit. |
| + // Set up the normal JPEG error routines and install overrides. |
| m_info.err = jpeg_std_error(&m_err.pub); |
| + m_err.pub.emit_message = emit_message; |
|
scroggo_chromium
2015/06/15 15:57:06
Besides error reporting, it looks like the behavio
Noel Gordon
2015/06/18 12:10:07
Good points. Since we have corruption for sequent
|
| m_err.pub.error_exit = error_exit; |
| + m_err.num_corrupt_warnings = 0; |
| // Allocate and initialize JPEG decompression object. |
| jpeg_create_decompress(&m_info); |
| @@ -489,8 +493,12 @@ public: |
| m_info.dct_method = dctMethod(); |
| m_info.dither_mode = ditherMode(); |
| m_info.do_fancy_upsampling = doFancyUpsampling(); |
| - m_info.enable_2pass_quant = false; |
| m_info.do_block_smoothing = true; |
| + m_info.enable_2pass_quant = false; |
| + m_info.enable_external_quant = false; |
|
scroggo_chromium
2015/06/15 15:57:06
Are these (setting to false and 0) necessary or ju
Noel Gordon
2015/06/18 12:10:07
For completeness. Two variables related to buffere
scroggo_chromium
2015/06/18 13:19:24
Either way. I just wanted to make sure I understan
|
| + m_info.enable_1pass_quant = false; |
| + m_info.quantize_colors = false; |
| + m_info.colormap = 0; |
| // Make a one-row-high sample array that will go away when done with |
| // image. Always make it big enough to hold an RGB row. Since this |
| @@ -527,6 +535,9 @@ public: |
| if (m_state == JPEG_DECOMPRESS_PROGRESSIVE) { |
| int status; |
| do { |
| + decoder_error_mgr* err = reinterpret_cast_ptr<decoder_error_mgr *>(m_info.err); |
| + if (err->num_corrupt_warnings) |
| + break; |
| status = jpeg_consume_input(&m_info); |
| } while ((status != JPEG_SUSPENDED) && (status != JPEG_REACHED_EOI)); |
| @@ -642,10 +653,27 @@ private: |
| void error_exit(j_common_ptr cinfo) |
| { |
| // Return control to the setjmp point. |
| - decoder_error_mgr *err = reinterpret_cast_ptr<decoder_error_mgr *>(cinfo->err); |
| + decoder_error_mgr* err = reinterpret_cast_ptr<decoder_error_mgr *>(cinfo->err); |
| longjmp(err->setjmp_buffer, -1); |
| } |
| +void emit_message(j_common_ptr cinfo, int msg_level) |
| +{ |
| + if (msg_level >= 0) |
| + return; |
| + |
| + decoder_error_mgr* err = reinterpret_cast_ptr<decoder_error_mgr *>(cinfo->err); |
| + err->pub.num_warnings++; |
| + |
| + // Detect and count corrupt JPEG warning messages. |
| + const char* warning = 0; |
| + int code = err->pub.msg_code; |
| + if (code > 0 && code <= err->pub.last_jpeg_message) |
| + warning = err->pub.jpeg_message_table[code]; |
| + if (warning && !strncmp("Corrupt JPEG", warning, 12)) |
| + err->num_corrupt_warnings++; |
|
scroggo_chromium
2015/06/15 15:57:05
This appears to be used as a boolean. Do we need t
Noel Gordon
2015/06/18 12:10:07
For debug but also compat with the way libjpeg int
scroggo_chromium
2015/06/18 13:19:24
sgtm
|
| +} |
| + |
| void init_source(j_decompress_ptr) |
| { |
| } |