diff options
author | francoisk777@gmail.com <francoisk777@gmail.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-15 20:50:02 +0000 |
---|---|---|
committer | francoisk777@gmail.com <francoisk777@gmail.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-15 20:50:02 +0000 |
commit | 1f8c6333e38c842d91cafc16ce822d04d930a804 (patch) | |
tree | 9d1c76265628936df4085d8c56a353ed1a444978 /ui/gfx/codec | |
parent | 9bf0fef85fb5c5f69e1a528921bef4e972066db4 (diff) | |
download | chromium_src-1f8c6333e38c842d91cafc16ce822d04d930a804.zip chromium_src-1f8c6333e38c842d91cafc16ce822d04d930a804.tar.gz chromium_src-1f8c6333e38c842d91cafc16ce822d04d930a804.tar.bz2 |
gfx::PNGCodec: User-defined error/warning handling functions
Adds user-defined error and warning handling functions to gfx::PNGCodec which
allows us to log libpng errors using Chrome's logging facilities instead of
stderr.
This CL was split out of http://codereview.chromium.org/9496004/.
TEST=Run ui_unittests --gtest_filter=PNGCodec.DecodeCorrupted and a libpng
error message should now be displayed.
Review URL: http://codereview.chromium.org/9699072
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@126986 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/gfx/codec')
-rw-r--r-- | ui/gfx/codec/png_codec.cc | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/ui/gfx/codec/png_codec.cc b/ui/gfx/codec/png_codec.cc index f61ca55..3b3a8c99 100644 --- a/ui/gfx/codec/png_codec.cc +++ b/ui/gfx/codec/png_codec.cc @@ -383,6 +383,27 @@ bool BuildPNGStruct(const unsigned char* input, size_t input_size, return true; } +// Libpng user error and warning functions which allows us to print libpng +// errors and warnings using Chrome's logging facilities instead of stderr. + +void LogLibPNGDecodeError(png_structp png_ptr, png_const_charp error_msg) { + DLOG(ERROR) << "libpng decode error: " << error_msg; + longjmp(png_jmpbuf(png_ptr), 1); +} + +void LogLibPNGDecodeWarning(png_structp png_ptr, png_const_charp warning_msg) { + DLOG(ERROR) << "libpng decode warning: " << warning_msg; +} + +void LogLibPNGEncodeError(png_structp png_ptr, png_const_charp error_msg) { + DLOG(ERROR) << "libpng encode error: " << error_msg; + longjmp(png_jmpbuf(png_ptr), 1); +} + +void LogLibPNGEncodeWarning(png_structp png_ptr, png_const_charp warning_msg) { + DLOG(ERROR) << "libpng encode warning: " << warning_msg; +} + } // namespace // static @@ -404,6 +425,7 @@ bool PNGCodec::Decode(const unsigned char* input, size_t input_size, PngDecoderState state(format, output); + png_set_error_fn(png_ptr, NULL, LogLibPNGDecodeError, LogLibPNGDecodeWarning); png_set_progressive_read_fn(png_ptr, &state, &DecodeInfoCallback, &DecodeRowCallback, &DecodeEndCallback); png_process_data(png_ptr, @@ -601,6 +623,7 @@ bool DoLibpngWrite(png_struct* png_ptr, png_info* info_ptr, // Set our callback for libpng to give us the data. png_set_write_fn(png_ptr, state, EncoderWriteCallback, FakeFlushCallback); + png_set_error_fn(png_ptr, NULL, LogLibPNGEncodeError, LogLibPNGEncodeWarning); png_set_IHDR(png_ptr, info_ptr, width, height, 8, png_output_color_type, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, |