Runtime configuration setting for suppressing JPEG decoder errors.
Add new runtime config variable, images.jpeg.suppressDecoderErrors which defaults to false in Debug and true otherwise. When Jpeg errors are suppressed and an error happens, SkJPEGImageDecoder::onDecode() will return silently false (Consequently, so will SkImageDecoder's DecodeFile() and DecodeMemory() functions). Also, the test_image_decoder program now respects runtime configuration settings. BUG=skia:1680 R=scroggo@google.com Review URL: https://codereview.chromium.org/27230002 git-svn-id: http://skia.googlecode.com/svn/trunk@11763 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
0cd2ac6c72
commit
04b57f87ab
@ -39,13 +39,20 @@ extern "C" {
|
||||
|
||||
#if defined(SK_DEBUG)
|
||||
#define DEFAULT_FOR_SUPPRESS_JPEG_IMAGE_DECODER_WARNINGS false
|
||||
#define DEFAULT_FOR_SUPPRESS_JPEG_IMAGE_DECODER_ERRORS false
|
||||
#else // !defined(SK_DEBUG)
|
||||
#define DEFAULT_FOR_SUPPRESS_JPEG_IMAGE_DECODER_WARNINGS true
|
||||
#define DEFAULT_FOR_SUPPRESS_JPEG_IMAGE_DECODER_ERRORS true
|
||||
#endif // defined(SK_DEBUG)
|
||||
SK_CONF_DECLARE(bool, c_suppressJPEGImageDecoderWarnings,
|
||||
"images.jpeg.suppressDecoderWarnings",
|
||||
DEFAULT_FOR_SUPPRESS_JPEG_IMAGE_DECODER_WARNINGS,
|
||||
"Suppress most JPG warnings when calling decode functions.");
|
||||
SK_CONF_DECLARE(bool, c_suppressJPEGImageDecoderErrors,
|
||||
"images.jpeg.suppressDecoderErrors",
|
||||
DEFAULT_FOR_SUPPRESS_JPEG_IMAGE_DECODER_ERRORS,
|
||||
"Suppress most JPG error messages when decode "
|
||||
"function fails.");
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
@ -69,6 +76,9 @@ static void overwrite_mem_buffer_size(jpeg_decompress_struct* cinfo) {
|
||||
static void do_nothing_emit_message(jpeg_common_struct*, int) {
|
||||
/* do nothing */
|
||||
}
|
||||
static void do_nothing_output_message(j_common_ptr) {
|
||||
/* do nothing */
|
||||
}
|
||||
|
||||
static void initialize_info(jpeg_decompress_struct* cinfo, skjpeg_source_mgr* src_mgr) {
|
||||
SkASSERT(cinfo != NULL);
|
||||
@ -83,6 +93,13 @@ static void initialize_info(jpeg_decompress_struct* cinfo, skjpeg_source_mgr* sr
|
||||
if (c_suppressJPEGImageDecoderWarnings) {
|
||||
cinfo->err->emit_message = &do_nothing_emit_message;
|
||||
}
|
||||
/* To suppress error messages with a SK_DEBUG binary, set the
|
||||
* environment variable "skia_images_jpeg_suppressDecoderErrors"
|
||||
* to "true". Inside a program that links to skia:
|
||||
* SK_CONF_SET("images.jpeg.suppressDecoderErrors", true); */
|
||||
if (c_suppressJPEGImageDecoderErrors) {
|
||||
cinfo->err->output_message = &do_nothing_output_message;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef SK_BUILD_FOR_ANDROID
|
||||
@ -309,12 +326,12 @@ static bool skip_src_rows_tile(jpeg_decompress_struct* cinfo,
|
||||
// set a break-point in one place to see all error exists.
|
||||
static bool return_false(const jpeg_decompress_struct& cinfo,
|
||||
const SkBitmap& bm, const char caller[]) {
|
||||
#ifdef SK_DEBUG
|
||||
char buffer[JMSG_LENGTH_MAX];
|
||||
cinfo.err->format_message((const j_common_ptr)&cinfo, buffer);
|
||||
SkDebugf("libjpeg error %d <%s> from %s [%d %d]\n", cinfo.err->msg_code,
|
||||
buffer, caller, bm.width(), bm.height());
|
||||
#endif
|
||||
if (!(c_suppressJPEGImageDecoderErrors)) {
|
||||
char buffer[JMSG_LENGTH_MAX];
|
||||
cinfo.err->format_message((const j_common_ptr)&cinfo, buffer);
|
||||
SkDebugf("libjpeg error %d <%s> from %s [%d %d]\n",
|
||||
cinfo.err->msg_code, buffer, caller, bm.width(), bm.height());
|
||||
}
|
||||
return false; // must always return false
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,7 @@ int tool_main(int argc, char** argv) {
|
||||
SkDebugf("Usage:\n %s imagefile\n\n", argv[0]);
|
||||
return 3;
|
||||
}
|
||||
SkAutoGraphics ag; // Enable use of SkRTConfig
|
||||
SkBitmap bitmap;
|
||||
if (!(SkImageDecoder::DecodeFile(argv[1], &bitmap))) {
|
||||
return 2;
|
||||
|
Loading…
Reference in New Issue
Block a user