From 29f6636a5faad017f07980727eb29a13febfaf3d Mon Sep 17 00:00:00 2001 From: "reed@google.com" Date: Fri, 25 Feb 2011 15:07:30 +0000 Subject: [PATCH] Stop using deprecated APIs. Fix by twiz. http://codereview.appspot.com/4249041/ BUG=http://code.google.com/p/skia/issues/detail?id=151 git-svn-id: http://skia.googlecode.com/svn/trunk@857 2bbb7eff-a529-9590-31e7-b0007b416f81 --- src/images/SkImageDecoder_libpng.cpp | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/images/SkImageDecoder_libpng.cpp b/src/images/SkImageDecoder_libpng.cpp index cccbfa6667..897126324d 100644 --- a/src/images/SkImageDecoder_libpng.cpp +++ b/src/images/SkImageDecoder_libpng.cpp @@ -58,7 +58,7 @@ private: }; static void sk_read_fn(png_structp png_ptr, png_bytep data, png_size_t length) { - SkStream* sk_stream = (SkStream*) png_ptr->io_ptr; + SkStream* sk_stream = (SkStream*)png_get_io_ptr(png_ptr); size_t bytes = sk_stream->read(data, length); if (bytes != length) { png_error(png_ptr, "Read Error!"); @@ -201,9 +201,9 @@ bool SkPNGImageDecoder::onDecode(SkStream* sk_stream, SkBitmap* decodedBitmap, } /* Expand grayscale images to the full 8 bits from 1, 2, or 4 bits/pixel */ if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) { - png_set_gray_1_2_4_to_8(png_ptr); + png_set_expand_gray_1_2_4_to_8(png_ptr); } - + /* Make a grayscale image into RGB. */ if (color_type == PNG_COLOR_TYPE_GRAY || color_type == PNG_COLOR_TYPE_GRAY_ALPHA) { @@ -218,15 +218,19 @@ bool SkPNGImageDecoder::onDecode(SkStream* sk_stream, SkBitmap* decodedBitmap, // check for sBIT chunk data, in case we should disable dithering because // our data is not truely 8bits per component if (doDither) { + png_color_8p sig_bit = NULL; + bool has_sbit = PNG_INFO_sBIT == png_get_sBIT(png_ptr, info_ptr, + &sig_bit); #if 0 - SkDebugf("----- sBIT %d %d %d %d\n", info_ptr->sig_bit.red, - info_ptr->sig_bit.green, info_ptr->sig_bit.blue, - info_ptr->sig_bit.alpha); + if (has_sbit) { + SkDebugf("----- sBIT %d %d %d %d\n", sig_bit->red, sig_bit->green, + sig_bit->blue, sig_bit->alpha); + } #endif // 0 seems to indicate no information available - if (pos_le(info_ptr->sig_bit.red, SK_R16_BITS) && - pos_le(info_ptr->sig_bit.green, SK_G16_BITS) && - pos_le(info_ptr->sig_bit.blue, SK_B16_BITS)) { + if (has_sbit && pos_le(sig_bit->red, SK_R16_BITS) && + pos_le(sig_bit->green, SK_G16_BITS) && + pos_le(sig_bit->blue, SK_B16_BITS)) { doDither = false; } } @@ -501,7 +505,7 @@ bool SkPNGImageDecoder::onDecode(SkStream* sk_stream, SkBitmap* decodedBitmap, #include "SkUnPreMultiply.h" static void sk_write_fn(png_structp png_ptr, png_bytep data, png_size_t len) { - SkWStream* sk_stream = (SkWStream*)png_ptr->io_ptr; + SkWStream* sk_stream = (SkWStream*)png_get_io_ptr(png_ptr); if (!sk_stream->write(data, len)) { png_error(png_ptr, "sk_write_fn Error!"); }