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

Unified Diff: src/codec/SkCodec.cpp

Issue 1040453002: Add SkPngChunkReader. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Update SkImageDecoder_empty Created 5 years, 1 month 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
« no previous file with comments | « include/core/SkPngChunkReader.h ('k') | src/codec/SkCodec_libpng.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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)
« no previous file with comments | « include/core/SkPngChunkReader.h ('k') | src/codec/SkCodec_libpng.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698