aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/GifTest.cpp
diff options
context:
space:
mode:
authorGravatar Leon Scroggins III <scroggo@google.com>2016-12-16 14:17:03 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2016-12-16 19:51:52 +0000
commit4cd68653e32928536854769ba132db5b43b5d337 (patch)
tree80302bfde52d791a27d445c9a58a71365c3f20ea /tests/GifTest.cpp
parentf856fd1ccdd839646159767f6aa9a2f2a1b97f04 (diff)
Only attempt index8 if underlying GIF is index8
Recent changes (crrev.com/2045293002) made it so that a GIF may not support index 8. In that case, make SkAndroidCodec not suggest index 8. Add a test and a new test file. randPixelsOffset.gif is the same as randPixels.gif, except its frame is offset. Since it does not have a transparent index, we have to decode to kN32. Change-Id: I1c09ab9094083de3dfc436632b3c26dbde1dccbd Reviewed-on: https://skia-review.googlesource.com/6196 Commit-Queue: Leon Scroggins <scroggo@google.com> Reviewed-by: Matt Sarett <msarett@google.com>
Diffstat (limited to 'tests/GifTest.cpp')
-rw-r--r--tests/GifTest.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/GifTest.cpp b/tests/GifTest.cpp
index 12bfb5348f..dae2bc9329 100644
--- a/tests/GifTest.cpp
+++ b/tests/GifTest.cpp
@@ -273,3 +273,41 @@ DEF_TEST(Codec_GifTruncated, r) {
std::unique_ptr<SkCodec> codec(SkCodec::NewFromData(data));
REPORTER_ASSERT(r, !codec);
}
+
+// There was a bug where SkAndroidCodec::computeOutputColorType returned kIndex_8 for
+// GIFs that did not support kIndex_8. Verify that for such an image, the method computes
+// something that it can actually decode to.
+DEF_TEST(Codec_GifIndex8, r) {
+ std::unique_ptr<SkStream> stream(GetResourceAsStream("randPixelsOffset.gif"));
+ if (!stream) {
+ return;
+ }
+
+ std::unique_ptr<SkAndroidCodec> codec(SkAndroidCodec::NewFromStream(stream.release()));
+ REPORTER_ASSERT(r, codec);
+ if (!codec) {
+ return;
+ }
+
+ REPORTER_ASSERT(r, codec->getInfo().colorType() == kN32_SkColorType);
+ const SkColorType outputColorType = codec->computeOutputColorType(kN32_SkColorType);
+ REPORTER_ASSERT(r, outputColorType == kN32_SkColorType);
+
+ SkAndroidCodec::AndroidOptions options;
+ sk_sp<SkColorTable> colorTable(nullptr);
+ int maxColors = 256;
+ if (kIndex_8_SkColorType == outputColorType) {
+ SkPMColor colors[256];
+ colorTable.reset(new SkColorTable(colors, maxColors));
+ options.fColorPtr = const_cast<SkPMColor*>(colorTable->readColors());
+ options.fColorCount = &maxColors;
+ }
+
+ auto info = codec->getInfo().makeColorType(outputColorType);
+ SkBitmap bm;
+ bm.setInfo(info);
+ bm.allocPixels(colorTable.get());
+
+ REPORTER_ASSERT(r, SkCodec::kSuccess == codec->getAndroidPixels(info, bm.getPixels(),
+ bm.rowBytes(), &options));
+}