| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 | 9 |
| 10 #include "SkImageDecoder.h" | 10 #include "SkImageDecoder.h" |
| 11 #include "SkImageEncoder.h" | 11 #include "SkImageEncoder.h" |
| 12 #include "SkColor.h" | 12 #include "SkColor.h" |
| 13 #include "SkColorPriv.h" | 13 #include "SkColorPriv.h" |
| 14 #include "SkDither.h" | 14 #include "SkDither.h" |
| 15 #include "SkMath.h" | 15 #include "SkMath.h" |
| 16 #include "SkRTConf.h" |
| 16 #include "SkScaledBitmapSampler.h" | 17 #include "SkScaledBitmapSampler.h" |
| 17 #include "SkStream.h" | 18 #include "SkStream.h" |
| 18 #include "SkTemplates.h" | 19 #include "SkTemplates.h" |
| 19 #include "SkUtils.h" | 20 #include "SkUtils.h" |
| 20 #include "transform_scanline.h" | 21 #include "transform_scanline.h" |
| 21 | |
| 22 #if defined(SK_DEBUG) | |
| 23 #include "SkRTConf.h" // SK_CONF_DECLARE | |
| 24 #endif // defined(SK_DEBUG) | |
| 25 | |
| 26 extern "C" { | 22 extern "C" { |
| 27 #include "png.h" | 23 #include "png.h" |
| 28 } | 24 } |
| 29 | 25 |
| 30 /* These were dropped in libpng >= 1.4 */ | 26 /* These were dropped in libpng >= 1.4 */ |
| 31 #ifndef png_infopp_NULL | 27 #ifndef png_infopp_NULL |
| 32 #define png_infopp_NULL NULL | 28 #define png_infopp_NULL NULL |
| 33 #endif | 29 #endif |
| 34 | 30 |
| 35 #ifndef png_bytepp_NULL | 31 #ifndef png_bytepp_NULL |
| 36 #define png_bytepp_NULL NULL | 32 #define png_bytepp_NULL NULL |
| 37 #endif | 33 #endif |
| 38 | 34 |
| 39 #ifndef int_p_NULL | 35 #ifndef int_p_NULL |
| 40 #define int_p_NULL NULL | 36 #define int_p_NULL NULL |
| 41 #endif | 37 #endif |
| 42 | 38 |
| 43 #ifndef png_flush_ptr_NULL | 39 #ifndef png_flush_ptr_NULL |
| 44 #define png_flush_ptr_NULL NULL | 40 #define png_flush_ptr_NULL NULL |
| 45 #endif | 41 #endif |
| 46 | 42 |
| 47 #if defined(SK_DEBUG) | 43 #if defined(SK_DEBUG) |
| 44 #define DEFAULT_FOR_SUPPRESS_PNG_IMAGE_DECODER_WARNINGS false |
| 45 #else // !defined(SK_DEBUG) |
| 46 #define DEFAULT_FOR_SUPPRESS_PNG_IMAGE_DECODER_WARNINGS true |
| 47 #endif // defined(SK_DEBUG) |
| 48 SK_CONF_DECLARE(bool, c_suppressPNGImageDecoderWarnings, | 48 SK_CONF_DECLARE(bool, c_suppressPNGImageDecoderWarnings, |
| 49 "images.png.suppressDecoderWarnings", false, | 49 "images.png.suppressDecoderWarnings", |
| 50 "Suppress most PNG warnings when calling image decode functions."); | 50 DEFAULT_FOR_SUPPRESS_PNG_IMAGE_DECODER_WARNINGS, |
| 51 #endif // defined(SK_DEBUG) | 51 "Suppress most PNG warnings when calling image decode " |
| 52 "functions."); |
| 53 |
| 52 | 54 |
| 53 | 55 |
| 54 class SkPNGImageIndex { | 56 class SkPNGImageIndex { |
| 55 public: | 57 public: |
| 56 SkPNGImageIndex(SkStreamRewindable* stream, png_structp png_ptr, png_infop i
nfo_ptr) | 58 SkPNGImageIndex(SkStreamRewindable* stream, png_structp png_ptr, png_infop i
nfo_ptr) |
| 57 : fStream(stream) | 59 : fStream(stream) |
| 58 , fPng_ptr(png_ptr) | 60 , fPng_ptr(png_ptr) |
| 59 , fInfo_ptr(info_ptr) | 61 , fInfo_ptr(info_ptr) |
| 60 , fConfig(SkBitmap::kNo_Config) { | 62 , fConfig(SkBitmap::kNo_Config) { |
| 61 SkASSERT(stream != NULL); | 63 SkASSERT(stream != NULL); |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 } | 217 } |
| 216 | 218 |
| 217 bool SkPNGImageDecoder::onDecodeInit(SkStream* sk_stream, png_structp *png_ptrp, | 219 bool SkPNGImageDecoder::onDecodeInit(SkStream* sk_stream, png_structp *png_ptrp, |
| 218 png_infop *info_ptrp) { | 220 png_infop *info_ptrp) { |
| 219 /* Create and initialize the png_struct with the desired error handler | 221 /* Create and initialize the png_struct with the desired error handler |
| 220 * functions. If you want to use the default stderr and longjump method, | 222 * functions. If you want to use the default stderr and longjump method, |
| 221 * you can supply NULL for the last three parameters. We also supply the | 223 * you can supply NULL for the last three parameters. We also supply the |
| 222 * the compiler header file version, so that we know if the application | 224 * the compiler header file version, so that we know if the application |
| 223 * was compiled with a compatible version of the library. */ | 225 * was compiled with a compatible version of the library. */ |
| 224 | 226 |
| 225 #if defined(SK_DEBUG) | |
| 226 png_error_ptr user_warning_fn = | 227 png_error_ptr user_warning_fn = |
| 227 (c_suppressPNGImageDecoderWarnings) ? (&do_nothing_warning_fn) : NULL; | 228 (c_suppressPNGImageDecoderWarnings) ? (&do_nothing_warning_fn) : NULL; |
| 228 /* NULL means to leave as default library behavior. */ | 229 /* NULL means to leave as default library behavior. */ |
| 229 /* c_suppressPNGImageDecoderWarnings defaults to false. */ | 230 /* c_suppressPNGImageDecoderWarnings default depends on SK_DEBUG. */ |
| 230 /* To suppress warnings with a SK_DEBUG binary, set the | 231 /* To suppress warnings with a SK_DEBUG binary, set the |
| 231 * environment variable "skia_images_png_suppressDecoderWarnings" | 232 * environment variable "skia_images_png_suppressDecoderWarnings" |
| 232 * to "true". Inside a program that links to skia: | 233 * to "true". Inside a program that links to skia: |
| 233 * SK_CONF_SET("images.png.suppressDecoderWarnings", true); */ | 234 * SK_CONF_SET("images.png.suppressDecoderWarnings", true); */ |
| 234 #else // Always suppress in release mode | |
| 235 png_error_ptr user_warning_fn = &do_nothing_warning_fn; | |
| 236 #endif // defined(SK_DEBUG) | |
| 237 | 235 |
| 238 png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, | 236 png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, |
| 239 NULL, sk_error_fn, user_warning_fn); | 237 NULL, sk_error_fn, user_warning_fn); |
| 240 // png_voidp user_error_ptr, user_error_fn, user_warning_fn); | 238 // png_voidp user_error_ptr, user_error_fn, user_warning_fn); |
| 241 if (png_ptr == NULL) { | 239 if (png_ptr == NULL) { |
| 242 return false; | 240 return false; |
| 243 } | 241 } |
| 244 | 242 |
| 245 *png_ptrp = png_ptr; | 243 *png_ptrp = png_ptr; |
| 246 | 244 |
| (...skipping 1002 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1249 return SkImageDecoder::kUnknown_Format; | 1247 return SkImageDecoder::kUnknown_Format; |
| 1250 } | 1248 } |
| 1251 | 1249 |
| 1252 SkImageEncoder* sk_libpng_efactory(SkImageEncoder::Type t) { | 1250 SkImageEncoder* sk_libpng_efactory(SkImageEncoder::Type t) { |
| 1253 return (SkImageEncoder::kPNG_Type == t) ? SkNEW(SkPNGImageEncoder) : NULL; | 1251 return (SkImageEncoder::kPNG_Type == t) ? SkNEW(SkPNGImageEncoder) : NULL; |
| 1254 } | 1252 } |
| 1255 | 1253 |
| 1256 static SkImageDecoder_DecodeReg gDReg(sk_libpng_dfactory); | 1254 static SkImageDecoder_DecodeReg gDReg(sk_libpng_dfactory); |
| 1257 static SkImageDecoder_FormatReg gFormatReg(get_format_png); | 1255 static SkImageDecoder_FormatReg gFormatReg(get_format_png); |
| 1258 static SkImageEncoder_EncodeReg gEReg(sk_libpng_efactory); | 1256 static SkImageEncoder_EncodeReg gEReg(sk_libpng_efactory); |
| OLD | NEW |