Index: src/codec/SkCodec.cpp |
diff --git a/src/codec/SkCodec.cpp b/src/codec/SkCodec.cpp |
index 071a4b837121301a34edce31dc51f96bd05e30bc..11eb1f98479461b7307695ac49d44cde6f85cecb 100644 |
--- a/src/codec/SkCodec.cpp |
+++ b/src/codec/SkCodec.cpp |
@@ -25,7 +25,6 @@ struct DecoderProc { |
}; |
static const DecoderProc gDecoderProcs[] = { |
- { SkPngCodec::IsPng, SkPngCodec::NewFromStream }, |
#if !defined(GOOGLE3) |
{ SkJpegCodec::IsJpeg, SkJpegCodec::NewFromStream }, |
#endif |
@@ -36,7 +35,8 @@ static const DecoderProc gDecoderProcs[] = { |
{ SkWbmpCodec::IsWbmp, SkWbmpCodec::NewFromStream } |
}; |
-SkCodec* SkCodec::NewFromStream(SkStream* stream) { |
+SkCodec* SkCodec::NewFromStream(SkStream* stream, |
+ SkPngChunkReader* chunkReader) { |
if (!stream) { |
return nullptr; |
} |
@@ -44,15 +44,24 @@ SkCodec* SkCodec::NewFromStream(SkStream* stream) { |
SkAutoTDelete<SkStream> streamDeleter(stream); |
SkAutoTDelete<SkCodec> codec(nullptr); |
- 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 nullptr; |
- } |
- if (correctFormat) { |
- codec.reset(proc.NewFromStream(streamDeleter.detach())); |
- break; |
+ // PNG is special, since we want to be able to supply an SkPngChunkReader. |
+ // But this code follows the same pattern as the loop. |
+ const bool isPng = SkPngCodec::IsPng(stream); |
+ if (!stream->rewind()) { |
+ return NULL; |
+ } |
+ if (isPng) { |
+ codec.reset(SkPngCodec::NewFromStream(streamDeleter.detach(), chunkReader)); |
+ } else { |
+ for (DecoderProc proc : gDecoderProcs) { |
+ const bool correctFormat = proc.IsFormat(stream); |
+ if (!stream->rewind()) { |
+ return nullptr; |
+ } |
+ if (correctFormat) { |
+ codec.reset(proc.NewFromStream(streamDeleter.detach())); |
+ break; |
+ } |
} |
} |
@@ -68,11 +77,11 @@ SkCodec* SkCodec::NewFromStream(SkStream* stream) { |
} |
} |
-SkCodec* SkCodec::NewFromData(SkData* data) { |
+SkCodec* SkCodec::NewFromData(SkData* data, SkPngChunkReader* reader) { |
if (!data) { |
return nullptr; |
} |
- return NewFromStream(new SkMemoryStream(data)); |
+ return NewFromStream(new SkMemoryStream(data), reader); |
} |
SkCodec::SkCodec(const SkImageInfo& info, SkStream* stream) |