Index: src/codec/SkCodec.cpp |
diff --git a/src/codec/SkCodec.cpp b/src/codec/SkCodec.cpp |
index ec36bc75e94e00edd22b857b179a9033a95fe5c1..d557087c01879f257fd64a2d8e7400cce920b765 100644 |
--- a/src/codec/SkCodec.cpp |
+++ b/src/codec/SkCodec.cpp |
@@ -7,24 +7,34 @@ |
#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); |
- // TODO: Avoid rewinding. |
- if (!stream->rewind()) { |
- return NULL; |
- } |
- if (isPng) { |
- streamDeleter.detach(); |
- return SkPngCodec::NewFromStream(stream); |
+ for (uint32_t i = 0; i < SK_ARRAY_COUNT(gDecoderProcs); i++) { |
+ DecoderProc proc = gDecoderProcs[i]; |
+ const bool correctFormat = proc.IsFormat(stream); |
+ if (!stream->rewind()) { |
+ return NULL; |
+ } |
+ if (correctFormat) { |
+ return proc.NewFromStream(stream); |
+ } |
} |
- // TODO: Check other image types. |
return NULL; |
} |