diff --git a/Makefile b/Makefile index a0027ee102..afc62c9f3a 100644 --- a/Makefile +++ b/Makefile @@ -61,7 +61,7 @@ ifeq ($(SKIA_BUILD_FOR),mac) SRC_LIST += src/ports/SkFontHost_mac.cpp else LINKER_OPTS += -lpng -lfreetype - DEFINES += -DSK_BUILD_FOR_UNIX + DEFINES += -DSK_BUILD_FOR_UNIX -DSK_ENABLE_LIBPNG # needed for freetype support C_INCLUDES += -I/usr/include/freetype2 diff --git a/src/images/SkImageDecoder_Factory.cpp b/src/images/SkImageDecoder_Factory.cpp index bd81d1fc1d..e7c71e52c9 100644 --- a/src/images/SkImageDecoder_Factory.cpp +++ b/src/images/SkImageDecoder_Factory.cpp @@ -24,10 +24,15 @@ typedef SkTRegistry DecodeReg; template DecodeReg* DecodeReg::gHead; +#ifdef SK_ENABLE_LIBPNG + extern SkImageDecoder* sk_libpng_dfactory(SkStream*); +#endif + SkImageDecoder* SkImageDecoder::Factory(SkStream* stream) { + SkImageDecoder* codec = NULL; const DecodeReg* curr = DecodeReg::Head(); while (curr) { - SkImageDecoder* codec = curr->factory()(stream); + codec = curr->factory()(stream); // we rewind here, because we promise later when we call "decode", that // the stream will be at its beginning. stream->rewind(); @@ -36,6 +41,13 @@ SkImageDecoder* SkImageDecoder::Factory(SkStream* stream) { } curr = curr->next(); } +#ifdef SK_ENABLE_LIBPNG + codec = sk_libpng_dfactory(stream); + stream->rewind(); + if (codec) { + return codec; + } +#endif return NULL; } diff --git a/src/images/SkImageDecoder_libpng.cpp b/src/images/SkImageDecoder_libpng.cpp index 3548fc8393..267c066a65 100644 --- a/src/images/SkImageDecoder_libpng.cpp +++ b/src/images/SkImageDecoder_libpng.cpp @@ -845,7 +845,12 @@ bool SkPNGImageEncoder::onEncode(SkWStream* stream, const SkBitmap& bitmap, #include "SkTRegistry.h" -static SkImageDecoder* DFactory(SkStream* stream) { +#ifdef SK_ENABLE_LIBPNG + SkImageDecoder* sk_libpng_dfactory(SkStream*); + SkImageEncoder* sk_libpng_efactory(SkImageEncoder::Type); +#endif + +SkImageDecoder* sk_libpng_dfactory(SkStream* stream) { char buf[PNG_BYTES_TO_CHECK]; if (stream->read(buf, PNG_BYTES_TO_CHECK) == PNG_BYTES_TO_CHECK && !png_sig_cmp((png_bytep) buf, (png_size_t)0, PNG_BYTES_TO_CHECK)) { @@ -854,9 +859,9 @@ static SkImageDecoder* DFactory(SkStream* stream) { return NULL; } -static SkImageEncoder* EFactory(SkImageEncoder::Type t) { +SkImageEncoder* sk_libpng_efactory(SkImageEncoder::Type t) { return (SkImageEncoder::kPNG_Type == t) ? SkNEW(SkPNGImageEncoder) : NULL; } -static SkTRegistry gEReg(EFactory); -static SkTRegistry gDReg(DFactory); +static SkTRegistry gEReg(sk_libpng_efactory); +static SkTRegistry gDReg(sk_libpng_dfactory); diff --git a/src/images/SkImageEncoder_Factory.cpp b/src/images/SkImageEncoder_Factory.cpp index d673167523..0bb4d1aed9 100644 --- a/src/images/SkImageEncoder_Factory.cpp +++ b/src/images/SkImageEncoder_Factory.cpp @@ -21,15 +21,24 @@ typedef SkTRegistry EncodeReg; template EncodeReg* EncodeReg::gHead; +#ifdef SK_ENABLE_LIBPNG + extern SkImageEncoder* sk_libpng_efactory(SkImageEncoder::Type); +#endif + SkImageEncoder* SkImageEncoder::Create(Type t) { + SkImageEncoder* codec = NULL; const EncodeReg* curr = EncodeReg::Head(); while (curr) { - SkImageEncoder* codec = curr->factory()(t); - if (codec) { + if ((codec = curr->factory()(t)) != NULL) { return codec; } curr = curr->next(); } +#ifdef SK_ENABLE_LIBPNG + if ((codec = sk_libpng_efactory(t)) != NULL) { + return codec; + } +#endif return NULL; }