Index: src/images/SkImageDecoder_libpng.cpp |
diff --git a/src/images/SkImageDecoder_libpng.cpp b/src/images/SkImageDecoder_libpng.cpp |
index efa4595545709a7b5de1063b6d5a66b23609f38a..aec89489459fec613d04aa88b8fce632885e134f 100644 |
--- a/src/images/SkImageDecoder_libpng.cpp |
+++ b/src/images/SkImageDecoder_libpng.cpp |
@@ -47,6 +47,7 @@ public: |
virtual Format getFormat() const SK_OVERRIDE { |
return kPNG_Format; |
} |
+ |
virtual ~SkPNGImageDecoder() { |
SkDELETE(fImageIndex); |
} |
@@ -1086,18 +1087,33 @@ DEFINE_ENCODER_CREATOR(PNGImageEncoder); |
#include "SkTRegistry.h" |
-SkImageDecoder* sk_libpng_dfactory(SkStream* stream) { |
+static bool is_png(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)) { |
+ return true; |
+ } |
+ return false; |
+} |
+ |
+SkImageDecoder* sk_libpng_dfactory(SkStream* stream) { |
+ if (is_png(stream)) { |
return SkNEW(SkPNGImageDecoder); |
} |
return NULL; |
} |
+static SkImageDecoder::Format get_format_png(SkStream* stream) { |
+ if (is_png(stream)) { |
+ return SkImageDecoder::kPNG_Format; |
+ } |
+ return SkImageDecoder::kUnknown_Format; |
+} |
+ |
SkImageEncoder* sk_libpng_efactory(SkImageEncoder::Type t) { |
return (SkImageEncoder::kPNG_Type == t) ? SkNEW(SkPNGImageEncoder) : NULL; |
} |
static SkTRegistry<SkImageEncoder*, SkImageEncoder::Type> gEReg(sk_libpng_efactory); |
+static SkTRegistry<SkImageDecoder::Format, SkStream*> gFormatReg(get_format_png); |
static SkTRegistry<SkImageDecoder*, SkStream*> gDReg(sk_libpng_dfactory); |