Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(649)

Unified Diff: src/images/SkImageDecoder_libgif.cpp

Issue 14363003: Updates to skimage tool to use it for testing. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Implement onGetFormat for other decoders. Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/images/SkImageDecoder_libgif.cpp
diff --git a/src/images/SkImageDecoder_libgif.cpp b/src/images/SkImageDecoder_libgif.cpp
index 3e4cda8a0bac26611ca1760c3da18aeaaf0f973c..1553af27c1d95bf7f5de7378c537d3671756d32d 100644
--- a/src/images/SkImageDecoder_libgif.cpp
+++ b/src/images/SkImageDecoder_libgif.cpp
@@ -22,6 +22,8 @@ public:
return kGIF_Format;
}
+ virtual Format onGetFormat(SkStream*) const SK_OVERRIDE;
+
protected:
virtual bool onDecode(SkStream* stream, SkBitmap* bm, Mode mode) SK_OVERRIDE;
@@ -91,9 +93,6 @@ private:
///////////////////////////////////////////////////////////////////////////////
-//#define GIF_STAMP "GIF" /* First chars in file - GIF stamp. */
-//#define GIF_STAMP_LEN (sizeof(GIF_STAMP) - 1)
-
static int DecodeCallBackProc(GifFileType* fileType, GifByteType* out,
int size) {
SkStream* stream = (SkStream*) fileType->UserData;
@@ -361,6 +360,25 @@ DONE:
return true;
}
+static bool is_gif(SkStream* stream) {
+ char buf[GIF_STAMP_LEN];
+ if (stream->read(buf, GIF_STAMP_LEN) == GIF_STAMP_LEN) {
+ if (memcmp(GIF_STAMP, buf, GIF_STAMP_LEN) == 0 ||
+ memcmp(GIF87_STAMP, buf, GIF_STAMP_LEN) == 0 ||
+ memcmp(GIF89_STAMP, buf, GIF_STAMP_LEN) == 0) {
+ return true;
+ }
+ }
+ return false;
+}
+
+SkImageDecoder::Format SkGIFImageDecoder::onGetFormat(SkStream* stream) const {
+ if (is_gif(stream)) {
+ return kGIF_Format;
+ }
+ return kUnknown_Format;
+}
+
///////////////////////////////////////////////////////////////////////////////
DEFINE_DECODER_CREATOR(GIFImageDecoder);
///////////////////////////////////////////////////////////////////////////////
@@ -368,13 +386,8 @@ DEFINE_DECODER_CREATOR(GIFImageDecoder);
#include "SkTRegistry.h"
static SkImageDecoder* sk_libgif_dfactory(SkStream* stream) {
- char buf[GIF_STAMP_LEN];
- if (stream->read(buf, GIF_STAMP_LEN) == GIF_STAMP_LEN) {
- if (memcmp(GIF_STAMP, buf, GIF_STAMP_LEN) == 0 ||
- memcmp(GIF87_STAMP, buf, GIF_STAMP_LEN) == 0 ||
- memcmp(GIF89_STAMP, buf, GIF_STAMP_LEN) == 0) {
- return SkNEW(SkGIFImageDecoder);
- }
+ if (is_gif(stream)) {
+ return SkNEW(SkGIFImageDecoder);
}
return NULL;
}

Powered by Google App Engine
This is Rietveld 408576698