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

Unified Diff: third_party/WebKit/Source/platform/graphics/DeferredImageDecoderTest.cpp

Issue 2618633004: Add support for Animated PNG (Closed)
Patch Set: Respond to comments Created 3 years, 9 months 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
Index: third_party/WebKit/Source/platform/graphics/DeferredImageDecoderTest.cpp
diff --git a/third_party/WebKit/Source/platform/graphics/DeferredImageDecoderTest.cpp b/third_party/WebKit/Source/platform/graphics/DeferredImageDecoderTest.cpp
index 70a05909c28840d843f0877d6cf1d78d21d0cb4e..f6fe4af71d6f428fab406c85ae5c587909e0814f 100644
--- a/third_party/WebKit/Source/platform/graphics/DeferredImageDecoderTest.cpp
+++ b/third_party/WebKit/Source/platform/graphics/DeferredImageDecoderTest.cpp
@@ -83,6 +83,19 @@ const unsigned char animatedGIF[] = {
0x01, 0x00, 0x01, 0x00, 0x00, 0x02, 0x02, 0x4c, 0x01, 0x00, 0x3b,
};
+// Raw data for a PNG file with 1x1 white pixels. Modified from animatedGIF.
+const unsigned char whiteGIF[] = {
Noel Gordon 2017/03/08 16:26:14 WhiteGIF, this is PNG no? Comment says that: PNG.
scroggo_chromium 2017/03/08 20:53:22 Comment was incorrect. This is a GIF.
+ 0x47, 0x49, 0x46, 0x38, 0x39, 0x61, 0x01, 0x00, 0x01, 0x00, 0xf0, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x21, 0xff, 0x0b, 0x4e, 0x45,
+ 0x54, 0x53, 0x43, 0x41, 0x50, 0x45, 0x32, 0x2e, 0x30, 0x03, 0x01, 0x00,
+ 0x00, 0x00, 0x21, 0xff, 0x0b, 0x49, 0x6d, 0x61, 0x67, 0x65, 0x4d, 0x61,
+ 0x67, 0x69, 0x63, 0x6b, 0x0d, 0x67, 0x61, 0x6d, 0x6d, 0x61, 0x3d, 0x30,
+ 0x2e, 0x34, 0x35, 0x34, 0x35, 0x35, 0x00, 0x21, 0xff, 0x0b, 0x49, 0x6d,
+ 0x61, 0x67, 0x65, 0x4d, 0x61, 0x67, 0x69, 0x63, 0x6b, 0x0d, 0x67, 0x61,
+ 0x6d, 0x6d, 0x61, 0x3d, 0x30, 0x2e, 0x34, 0x35, 0x34, 0x35, 0x35, 0x00,
+ 0x21, 0xf9, 0x04, 0x00, 0x00, 0x00, 0xff, 0x00, 0x2c, 0x00, 0x00, 0x00,
+ 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x02, 0x02, 0x4c, 0x01, 0x00, 0x3b};
+
} // namespace
class DeferredImageDecoderTest : public ::testing::Test,
@@ -324,33 +337,39 @@ TEST_F(DeferredImageDecoderTest, smallerFrameCount) {
}
TEST_F(DeferredImageDecoderTest, frameOpacity) {
- std::unique_ptr<DeferredImageDecoder> decoder = DeferredImageDecoder::create(
- m_data, true, ImageDecoder::AlphaPremultiplied,
- ColorBehavior::transformToTargetForTesting());
+ for (bool testGIF : {false, true}) {
+ if (testGIF)
+ m_data = SharedBuffer::create(whiteGIF, sizeof(whiteGIF));
- SkImageInfo pixInfo = SkImageInfo::MakeN32Premul(1, 1);
+ std::unique_ptr<DeferredImageDecoder> decoder =
+ DeferredImageDecoder::create(
+ m_data, true, ImageDecoder::AlphaPremultiplied,
+ ColorBehavior::transformToTargetForTesting());
- size_t rowBytes = pixInfo.minRowBytes();
- size_t size = pixInfo.getSafeSize(rowBytes);
+ SkImageInfo pixInfo = SkImageInfo::MakeN32Premul(1, 1);
- Vector<char> storage(size);
- SkPixmap pixmap(pixInfo, storage.data(), rowBytes);
+ size_t rowBytes = pixInfo.minRowBytes();
+ size_t size = pixInfo.getSafeSize(rowBytes);
- // Before decoding, the frame is not known to be opaque.
- sk_sp<SkImage> frame = decoder->createFrameAtIndex(0);
- ASSERT_TRUE(frame);
- EXPECT_FALSE(frame->isOpaque());
+ Vector<char> storage(size);
+ SkPixmap pixmap(pixInfo, storage.data(), rowBytes);
- // Force a lazy decode by reading pixels.
- EXPECT_TRUE(frame->readPixels(pixmap, 0, 0));
+ // Before decoding, the frame is not known to be opaque.
Noel Gordon 2017/03/08 16:26:14 Test seems fine. We've discussed alpha handling i
+ sk_sp<SkImage> frame = decoder->createFrameAtIndex(0);
+ ASSERT_TRUE(frame);
+ EXPECT_FALSE(frame->isOpaque());
- // After decoding, the frame is known to be opaque.
- frame = decoder->createFrameAtIndex(0);
- ASSERT_TRUE(frame);
- EXPECT_TRUE(frame->isOpaque());
+ // Force a lazy decode by reading pixels.
+ EXPECT_TRUE(frame->readPixels(pixmap, 0, 0));
- // Re-generating the opaque-marked frame should not fail.
- EXPECT_TRUE(frame->readPixels(pixmap, 0, 0));
+ // After decoding, the frame is known to be opaque.
+ frame = decoder->createFrameAtIndex(0);
+ ASSERT_TRUE(frame);
+ EXPECT_TRUE(frame->isOpaque());
+
+ // Re-generating the opaque-marked frame should not fail.
+ EXPECT_TRUE(frame->readPixels(pixmap, 0, 0));
+ }
}
// The DeferredImageDecoder would sometimes assume that a frame was a certain

Powered by Google App Engine
This is Rietveld 408576698