pull from android: use registry to build up list of image codecs
git-svn-id: http://skia.googlecode.com/svn/trunk@76 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/images/SkImageDecoder_libico.cpp b/src/images/SkImageDecoder_libico.cpp
index b179a6b..9f21e13 100644
--- a/src/images/SkImageDecoder_libico.cpp
+++ b/src/images/SkImageDecoder_libico.cpp
@@ -44,23 +44,6 @@
/////////////////////////////////////////////////////////////////////////////////////////
-SkImageDecoder* SkImageDecoder_ICO_Factory(SkStream*);
-SkImageDecoder* SkImageDecoder_ICO_Factory(SkStream* stream)
-{
- //i'm going to check if we basically have 0,0,1,0 (reserved = 0, type = 1)
- //is that required and sufficient?
- SkAutoMalloc autoMal(4);
- unsigned char* buf = (unsigned char*)autoMal.get();
- stream->read((void*)buf, 4);
- int reserved = read2Bytes(buf, 0);
- int type = read2Bytes(buf, 2);
- if (reserved != 0 || type != 1) //it's not an ico
- return NULL;
- return SkNEW(SkICOImageDecoder);
-}
-
-/////////////////////////////////////////////////////////////////////////////////////////
-
SkICOImageDecoder::SkICOImageDecoder()
{
}
@@ -386,3 +369,24 @@
*address = SkPackARGB32(alpha, red & alpha, green & alpha, blue & alpha);
}
+/////////////////////////////////////////////////////////////////////////////////////////
+
+#include "SkTRegistry.h"
+
+static SkImageDecoder* Factory(SkStream* stream) {
+ // Check to see if the first four bytes are 0,0,1,0
+ // FIXME: Is that required and sufficient?
+ SkAutoMalloc autoMal(4);
+ unsigned char* buf = (unsigned char*)autoMal.get();
+ stream->read((void*)buf, 4);
+ int reserved = read2Bytes(buf, 0);
+ int type = read2Bytes(buf, 2);
+ if (reserved != 0 || type != 1) {
+ // This stream does not represent an ICO image.
+ return NULL;
+ }
+ return SkNEW(SkICOImageDecoder);
+}
+
+static SkTRegistry<SkImageDecoder*, SkStream*> gReg(Factory);
+