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

Side by Side Diff: src/images/SkImageDecoder_libjpeg.cpp

Issue 27230002: Runtime configuration setting for suppressing JPEG decoder errors. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: rebase Created 7 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | tools/test_image_decoder.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 /* 1 /*
2 * Copyright 2007 The Android Open Source Project 2 * Copyright 2007 The Android Open Source Project
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 8
9 #include "SkImageDecoder.h" 9 #include "SkImageDecoder.h"
10 #include "SkImageEncoder.h" 10 #include "SkImageEncoder.h"
(...skipping 21 matching lines...) Expand all
32 //#define TIME_DECODE 32 //#define TIME_DECODE
33 33
34 // this enables our rgb->yuv code, which is faster than libjpeg on ARM 34 // this enables our rgb->yuv code, which is faster than libjpeg on ARM
35 #define WE_CONVERT_TO_YUV 35 #define WE_CONVERT_TO_YUV
36 36
37 // If ANDROID_RGB is defined by in the jpeg headers it indicates that jpeg offer s 37 // If ANDROID_RGB is defined by in the jpeg headers it indicates that jpeg offer s
38 // support for two additional formats (1) JCS_RGBA_8888 and (2) JCS_RGB_565. 38 // support for two additional formats (1) JCS_RGBA_8888 and (2) JCS_RGB_565.
39 39
40 #if defined(SK_DEBUG) 40 #if defined(SK_DEBUG)
41 #define DEFAULT_FOR_SUPPRESS_JPEG_IMAGE_DECODER_WARNINGS false 41 #define DEFAULT_FOR_SUPPRESS_JPEG_IMAGE_DECODER_WARNINGS false
42 #define DEFAULT_FOR_SUPPRESS_JPEG_IMAGE_DECODER_ERRORS false
42 #else // !defined(SK_DEBUG) 43 #else // !defined(SK_DEBUG)
43 #define DEFAULT_FOR_SUPPRESS_JPEG_IMAGE_DECODER_WARNINGS true 44 #define DEFAULT_FOR_SUPPRESS_JPEG_IMAGE_DECODER_WARNINGS true
45 #define DEFAULT_FOR_SUPPRESS_JPEG_IMAGE_DECODER_ERRORS true
44 #endif // defined(SK_DEBUG) 46 #endif // defined(SK_DEBUG)
45 SK_CONF_DECLARE(bool, c_suppressJPEGImageDecoderWarnings, 47 SK_CONF_DECLARE(bool, c_suppressJPEGImageDecoderWarnings,
46 "images.jpeg.suppressDecoderWarnings", 48 "images.jpeg.suppressDecoderWarnings",
47 DEFAULT_FOR_SUPPRESS_JPEG_IMAGE_DECODER_WARNINGS, 49 DEFAULT_FOR_SUPPRESS_JPEG_IMAGE_DECODER_WARNINGS,
48 "Suppress most JPG warnings when calling decode functions."); 50 "Suppress most JPG warnings when calling decode functions.");
51 SK_CONF_DECLARE(bool, c_suppressJPEGImageDecoderErrors,
52 "images.jpeg.suppressDecoderErrors",
53 DEFAULT_FOR_SUPPRESS_JPEG_IMAGE_DECODER_ERRORS,
54 "Suppress most JPG error messages when decode "
55 "function fails.");
49 56
50 ////////////////////////////////////////////////////////////////////////// 57 //////////////////////////////////////////////////////////////////////////
51 ////////////////////////////////////////////////////////////////////////// 58 //////////////////////////////////////////////////////////////////////////
52 59
53 static void overwrite_mem_buffer_size(jpeg_decompress_struct* cinfo) { 60 static void overwrite_mem_buffer_size(jpeg_decompress_struct* cinfo) {
54 #ifdef SK_BUILD_FOR_ANDROID 61 #ifdef SK_BUILD_FOR_ANDROID
55 /* Check if the device indicates that it has a large amount of system memory 62 /* Check if the device indicates that it has a large amount of system memory
56 * if so, increase the memory allocation to 30MB instead of the default 5MB. 63 * if so, increase the memory allocation to 30MB instead of the default 5MB.
57 */ 64 */
58 #ifdef ANDROID_LARGE_MEMORY_DEVICE 65 #ifdef ANDROID_LARGE_MEMORY_DEVICE
59 cinfo->mem->max_memory_to_use = 30 * 1024 * 1024; 66 cinfo->mem->max_memory_to_use = 30 * 1024 * 1024;
60 #else 67 #else
61 cinfo->mem->max_memory_to_use = 5 * 1024 * 1024; 68 cinfo->mem->max_memory_to_use = 5 * 1024 * 1024;
62 #endif 69 #endif
63 #endif // SK_BUILD_FOR_ANDROID 70 #endif // SK_BUILD_FOR_ANDROID
64 } 71 }
65 72
66 ////////////////////////////////////////////////////////////////////////// 73 //////////////////////////////////////////////////////////////////////////
67 ////////////////////////////////////////////////////////////////////////// 74 //////////////////////////////////////////////////////////////////////////
68 75
69 static void do_nothing_emit_message(jpeg_common_struct*, int) { 76 static void do_nothing_emit_message(jpeg_common_struct*, int) {
70 /* do nothing */ 77 /* do nothing */
71 } 78 }
79 static void do_nothing_output_message(j_common_ptr) {
80 /* do nothing */
81 }
72 82
73 static void initialize_info(jpeg_decompress_struct* cinfo, skjpeg_source_mgr* sr c_mgr) { 83 static void initialize_info(jpeg_decompress_struct* cinfo, skjpeg_source_mgr* sr c_mgr) {
74 SkASSERT(cinfo != NULL); 84 SkASSERT(cinfo != NULL);
75 SkASSERT(src_mgr != NULL); 85 SkASSERT(src_mgr != NULL);
76 jpeg_create_decompress(cinfo); 86 jpeg_create_decompress(cinfo);
77 overwrite_mem_buffer_size(cinfo); 87 overwrite_mem_buffer_size(cinfo);
78 cinfo->src = src_mgr; 88 cinfo->src = src_mgr;
79 /* To suppress warnings with a SK_DEBUG binary, set the 89 /* To suppress warnings with a SK_DEBUG binary, set the
80 * environment variable "skia_images_jpeg_suppressDecoderWarnings" 90 * environment variable "skia_images_jpeg_suppressDecoderWarnings"
81 * to "true". Inside a program that links to skia: 91 * to "true". Inside a program that links to skia:
82 * SK_CONF_SET("images.jpeg.suppressDecoderWarnings", true); */ 92 * SK_CONF_SET("images.jpeg.suppressDecoderWarnings", true); */
83 if (c_suppressJPEGImageDecoderWarnings) { 93 if (c_suppressJPEGImageDecoderWarnings) {
84 cinfo->err->emit_message = &do_nothing_emit_message; 94 cinfo->err->emit_message = &do_nothing_emit_message;
85 } 95 }
96 /* To suppress error messages with a SK_DEBUG binary, set the
97 * environment variable "skia_images_jpeg_suppressDecoderErrors"
98 * to "true". Inside a program that links to skia:
99 * SK_CONF_SET("images.jpeg.suppressDecoderErrors", true); */
100 if (c_suppressJPEGImageDecoderErrors) {
101 cinfo->err->output_message = &do_nothing_output_message;
102 }
86 } 103 }
87 104
88 #ifdef SK_BUILD_FOR_ANDROID 105 #ifdef SK_BUILD_FOR_ANDROID
89 class SkJPEGImageIndex { 106 class SkJPEGImageIndex {
90 public: 107 public:
91 SkJPEGImageIndex(SkStreamRewindable* stream, SkImageDecoder* decoder) 108 SkJPEGImageIndex(SkStreamRewindable* stream, SkImageDecoder* decoder)
92 : fSrcMgr(stream, decoder) 109 : fSrcMgr(stream, decoder)
93 , fInfoInitialized(false) 110 , fInfoInitialized(false)
94 , fHuffmanCreated(false) 111 , fHuffmanCreated(false)
95 , fDecompressStarted(false) 112 , fDecompressStarted(false)
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 } 319 }
303 } 320 }
304 return true; 321 return true;
305 } 322 }
306 #endif 323 #endif
307 324
308 // This guy exists just to aid in debugging, as it allows debuggers to just 325 // This guy exists just to aid in debugging, as it allows debuggers to just
309 // set a break-point in one place to see all error exists. 326 // set a break-point in one place to see all error exists.
310 static bool return_false(const jpeg_decompress_struct& cinfo, 327 static bool return_false(const jpeg_decompress_struct& cinfo,
311 const SkBitmap& bm, const char caller[]) { 328 const SkBitmap& bm, const char caller[]) {
312 #ifdef SK_DEBUG 329 if (!(c_suppressJPEGImageDecoderErrors)) {
313 char buffer[JMSG_LENGTH_MAX]; 330 char buffer[JMSG_LENGTH_MAX];
314 cinfo.err->format_message((const j_common_ptr)&cinfo, buffer); 331 cinfo.err->format_message((const j_common_ptr)&cinfo, buffer);
315 SkDebugf("libjpeg error %d <%s> from %s [%d %d]\n", cinfo.err->msg_code, 332 SkDebugf("libjpeg error %d <%s> from %s [%d %d]\n",
316 buffer, caller, bm.width(), bm.height()); 333 cinfo.err->msg_code, buffer, caller, bm.width(), bm.height());
317 #endif 334 }
318 return false; // must always return false 335 return false; // must always return false
319 } 336 }
320 337
321 // Convert a scanline of CMYK samples to RGBX in place. Note that this 338 // Convert a scanline of CMYK samples to RGBX in place. Note that this
322 // method moves the "scanline" pointer in its processing 339 // method moves the "scanline" pointer in its processing
323 static void convert_CMYK_to_RGB(uint8_t* scanline, unsigned int width) { 340 static void convert_CMYK_to_RGB(uint8_t* scanline, unsigned int width) {
324 // At this point we've received CMYK pixels from libjpeg. We 341 // At this point we've received CMYK pixels from libjpeg. We
325 // perform a crude conversion to RGB (based on the formulae 342 // perform a crude conversion to RGB (based on the formulae
326 // from easyrgb.com): 343 // from easyrgb.com):
327 // CMYK -> CMY 344 // CMYK -> CMY
(...skipping 870 matching lines...) Expand 10 before | Expand all | Expand 10 after
1198 return SkImageDecoder::kUnknown_Format; 1215 return SkImageDecoder::kUnknown_Format;
1199 } 1216 }
1200 1217
1201 static SkImageEncoder* sk_libjpeg_efactory(SkImageEncoder::Type t) { 1218 static SkImageEncoder* sk_libjpeg_efactory(SkImageEncoder::Type t) {
1202 return (SkImageEncoder::kJPEG_Type == t) ? SkNEW(SkJPEGImageEncoder) : NULL; 1219 return (SkImageEncoder::kJPEG_Type == t) ? SkNEW(SkJPEGImageEncoder) : NULL;
1203 } 1220 }
1204 1221
1205 static SkImageDecoder_DecodeReg gDReg(sk_libjpeg_dfactory); 1222 static SkImageDecoder_DecodeReg gDReg(sk_libjpeg_dfactory);
1206 static SkImageDecoder_FormatReg gFormatReg(get_format_jpeg); 1223 static SkImageDecoder_FormatReg gFormatReg(get_format_jpeg);
1207 static SkImageEncoder_EncodeReg gEReg(sk_libjpeg_efactory); 1224 static SkImageEncoder_EncodeReg gEReg(sk_libjpeg_efactory);
OLDNEW
« no previous file with comments | « no previous file | tools/test_image_decoder.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698