Support for libpng > 1.2.
* Add conditional defines for deprecated NULL type casts. * Use wrapper functions for accessing png_structp & png_infop fields (direct access is deprecated). Tested on Fedora 17 (libpng 1.5) and Ubuntu 12.04 (libpng 1.2). Note: there is one png_structp direct field acces left in SkPNGImageDecoder::onDecodeRegion() for which libpng does not provide a wrapper method (png_ptr->pass = 0). That should be OK for now as the code is only enabled when SK_BUILD_FOR_ANDROID is set, and the Android libpng version is striclty controlled. But it may become an issue in the future when/if Android decides to update libpng, so we should investigate a solution. R=scroggo@google.com, reed@google.com, djsollen@google.com Author: fmalita@google.com Review URL: https://chromiumcodereview.appspot.com/14645018 git-svn-id: http://skia.googlecode.com/svn/trunk@8956 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
b631eec0e6
commit
c1c5695f8f
@ -23,6 +23,23 @@ extern "C" {
|
||||
#include "png.h"
|
||||
}
|
||||
|
||||
/* These were dropped in libpng >= 1.4 */
|
||||
#ifndef png_infopp_NULL
|
||||
#define png_infopp_NULL NULL
|
||||
#endif
|
||||
|
||||
#ifndef png_bytepp_NULL
|
||||
#define png_bytepp_NULL NULL
|
||||
#endif
|
||||
|
||||
#ifndef int_p_NULL
|
||||
#define int_p_NULL NULL
|
||||
#endif
|
||||
|
||||
#ifndef png_flush_ptr_NULL
|
||||
#define png_flush_ptr_NULL NULL
|
||||
#endif
|
||||
|
||||
class SkPNGImageIndex {
|
||||
public:
|
||||
SkPNGImageIndex(png_structp png_ptr, png_infop info_ptr) {
|
||||
@ -90,7 +107,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!");
|
||||
@ -99,7 +116,7 @@ static void sk_read_fn(png_structp png_ptr, png_bytep data, png_size_t length) {
|
||||
|
||||
#ifdef SK_BUILD_FOR_ANDROID
|
||||
static void sk_seek_fn(png_structp png_ptr, png_uint_32 offset) {
|
||||
SkStream* sk_stream = (SkStream*) png_ptr->io_ptr;
|
||||
SkStream* sk_stream = (SkStream*) png_get_io_ptr(png_ptr);
|
||||
sk_stream->rewind();
|
||||
(void)sk_stream->skip(offset);
|
||||
}
|
||||
@ -240,7 +257,7 @@ bool SkPNGImageDecoder::onDecodeInit(SkStream* sk_stream, png_structp *png_ptrp,
|
||||
}
|
||||
/* Expand grayscale images to the full 8 bits from 1, 2, or 4 bits/pixel */
|
||||
if (colorType == PNG_COLOR_TYPE_GRAY && bitDepth < 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. */
|
||||
@ -437,16 +454,16 @@ bool SkPNGImageDecoder::getBitmapConfig(png_structp png_ptr, png_infop info_ptr,
|
||||
|
||||
// check for sBIT chunk data, in case we should disable dithering because
|
||||
// our data is not truely 8bits per component
|
||||
if (*doDitherp) {
|
||||
png_color_8p sig_bit;
|
||||
if (*doDitherp && 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);
|
||||
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 (pos_le(sig_bit->red, SK_R16_BITS) &&
|
||||
pos_le(sig_bit->green, SK_G16_BITS) &&
|
||||
pos_le(sig_bit->blue, SK_B16_BITS)) {
|
||||
*doDitherp = false;
|
||||
}
|
||||
}
|
||||
@ -709,7 +726,14 @@ bool SkPNGImageDecoder::onDecodeRegion(SkBitmap* bm, const SkIRect& region) {
|
||||
* and update info structure. REQUIRED if you are expecting libpng to
|
||||
* update the palette for you (ie you selected such a transform above).
|
||||
*/
|
||||
|
||||
// Direct access to png_ptr fields is deprecated in libpng > 1.2.
|
||||
#if defined(PNG_1_0_X) || defined (PNG_1_2_X)
|
||||
png_ptr->pass = 0;
|
||||
#else
|
||||
// FIXME: Figure out what (if anything) to do when Android moves to
|
||||
// libpng > 1.2.
|
||||
#endif
|
||||
png_read_update_info(png_ptr, info_ptr);
|
||||
|
||||
int actualTop = rect.fTop;
|
||||
@ -817,7 +841,7 @@ bool SkPNGImageDecoder::onDecodeRegion(SkBitmap* bm, const SkIRect& region) {
|
||||
#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!");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user