diff options
Diffstat (limited to 'tests/GifTest.cpp')
-rw-r--r-- | tests/GifTest.cpp | 54 |
1 files changed, 53 insertions, 1 deletions
diff --git a/tests/GifTest.cpp b/tests/GifTest.cpp index 7728d27dcb..0168d89d83 100644 --- a/tests/GifTest.cpp +++ b/tests/GifTest.cpp @@ -238,11 +238,25 @@ DEF_TEST(Gif_Sampled, r) { return; } + // Construct a color table for the decode if necessary + sk_sp<SkColorTable> colorTable(nullptr); + SkPMColor* colorPtr = nullptr; + int* colorCountPtr = nullptr; + int maxColors = 256; + if (kIndex_8_SkColorType == codec->getInfo().colorType()) { + SkPMColor colors[256]; + colorTable.reset(new SkColorTable(colors, maxColors)); + colorPtr = const_cast<SkPMColor*>(colorTable->readColors()); + colorCountPtr = &maxColors; + } + SkAndroidCodec::AndroidOptions options; options.fSampleSize = 4; + options.fColorPtr = colorPtr; + options.fColorCount = colorCountPtr; SkBitmap bm; - bm.allocPixels(codec->getInfo()); + bm.allocPixels(codec->getInfo(), colorTable); const SkCodec::Result result = codec->getAndroidPixels(codec->getInfo(), bm.getPixels(), bm.rowBytes(), &options); REPORTER_ASSERT(r, result == SkCodec::kSuccess); @@ -259,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)); +} |