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

Unified Diff: src/images/SkImageDecoder_libico.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_libico.cpp
diff --git a/src/images/SkImageDecoder_libico.cpp b/src/images/SkImageDecoder_libico.cpp
index ffc59e0003e1ca6706f3ea985cab37d680fdc432..38883c259a38d8a6ba04e131ab60315a9907e394 100644
--- a/src/images/SkImageDecoder_libico.cpp
+++ b/src/images/SkImageDecoder_libico.cpp
@@ -20,6 +20,8 @@ public:
return kICO_Format;
}
+ virtual Format onGetFormat(SkStream*) const SK_OVERRIDE;
+
protected:
virtual bool onDecode(SkStream* stream, SkBitmap* bm, Mode) SK_OVERRIDE;
@@ -369,13 +371,7 @@ static void editPixelBit32(const int pixelNo, const unsigned char* buf,
*address = SkPreMultiplyARGB(alpha, red, green, blue);
}
-///////////////////////////////////////////////////////////////////////////////
-DEFINE_DECODER_CREATOR(ICOImageDecoder);
-/////////////////////////////////////////////////////////////////////////////////////////
-
-#include "SkTRegistry.h"
-
-static SkImageDecoder* sk_libico_dfactory(SkStream* stream) {
+static bool is_ico(SkStream* stream) {
// Check to see if the first four bytes are 0,0,1,0
// FIXME: Is that required and sufficient?
SkAutoMalloc autoMal(4);
@@ -385,9 +381,29 @@ static SkImageDecoder* sk_libico_dfactory(SkStream* stream) {
int type = read2Bytes(buf, 2);
if (reserved != 0 || type != 1) {
// This stream does not represent an ICO image.
- return NULL;
+ return false;
+ }
+ return true;
+}
+
+SkImageDecoder::Format SkICOImageDecoder::onGetFormat(SkStream* stream) const {
+ if (is_ico(stream)) {
+ return kICO_Format;
+ }
+ return kUnknown_Format;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+DEFINE_DECODER_CREATOR(ICOImageDecoder);
+/////////////////////////////////////////////////////////////////////////////////////////
+
+#include "SkTRegistry.h"
+
+static SkImageDecoder* sk_libico_dfactory(SkStream* stream) {
+ if (is_ico(stream)) {
+ return SkNEW(SkICOImageDecoder);
}
- return SkNEW(SkICOImageDecoder);
+ return NULL;
}
static SkTRegistry<SkImageDecoder*, SkStream*> gReg(sk_libico_dfactory);

Powered by Google App Engine
This is Rietveld 408576698