Index: src/codec/SkCodec.cpp |
diff --git a/src/codec/SkCodec.cpp b/src/codec/SkCodec.cpp |
index 69d95a41da24be0231cdd32b8719d2b1d6ea3747..a880fb42fd96885bbca59e41a8e729a78a79f3bd 100644 |
--- a/src/codec/SkCodec.cpp |
+++ b/src/codec/SkCodec.cpp |
@@ -7,23 +7,33 @@ |
#include "SkCodec.h" |
#include "SkData.h" |
+#include "SkCodec_libbmp.h" |
#include "SkCodec_libpng.h" |
#include "SkStream.h" |
+struct DecoderProc { |
+ bool (*IsFormat)(SkStream*); |
+ SkCodec* (*NewFromStream)(SkStream*); |
+}; |
+ |
+static const DecoderProc gDecoderProcs[] = { |
+ { SkPngCodec::IsPng, SkPngCodec::NewFromStream }, |
+ { SkBmpCodec::IsBmp, SkBmpCodec::NewFromStream } |
+}; |
+ |
SkCodec* SkCodec::NewFromStream(SkStream* stream) { |
if (!stream) { |
return NULL; |
} |
- SkAutoTDelete<SkStream> streamDeleter(stream); |
- const bool isPng = SkPngCodec::IsPng(stream); |
- if (!stream->rewind()) { |
+ for (DecoderProc proc : gDecoderProcs) { |
+ const bool correctFormat = proc.IsFormat(stream); |
+ if (!stream->rewind()) { |
return NULL; |
+ } |
+ if (correctFormat) { |
+ return proc.NewFromStream(stream); |
+ } |
} |
- if (isPng) { |
- streamDeleter.detach(); |
- return SkPngCodec::NewFromStream(stream); |
- } |
- // TODO: Check other image types. |
return NULL; |
} |