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

Unified Diff: third_party/WebKit/Source/platform/image-decoders/gif/GIFImageDecoderTest.cpp

Issue 1820733004: Propagate the decoder frame premul info to SkBitmap (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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/image-decoders/gif/GIFImageDecoderTest.cpp
diff --git a/third_party/WebKit/Source/platform/image-decoders/gif/GIFImageDecoderTest.cpp b/third_party/WebKit/Source/platform/image-decoders/gif/GIFImageDecoderTest.cpp
index 92d0d5826a12cbc575a8d55bf56a5feefed3322c..7538833ab4a34fd01aeeb03940713b8871fb77d9 100644
--- a/third_party/WebKit/Source/platform/image-decoders/gif/GIFImageDecoderTest.cpp
+++ b/third_party/WebKit/Source/platform/image-decoders/gif/GIFImageDecoderTest.cpp
@@ -516,4 +516,50 @@ TEST(GIFImageDecoderTest, verifyRepetitionCount)
EXPECT_EQ(expectedRepetitionCount, decoder->repetitionCount()); // Expected value after decode.
}
+TEST(GIFImageDecoderTest, bitmapAlphaType)
+{
+ RefPtr<SharedBuffer> fullData = readFile(decodersTestingDir, "radient.gif");
+ ASSERT_TRUE(fullData.get());
+
+ // Empirically chosen
Noel Gordon 2016/03/21 22:37:16 // Empirically chosen truncation size:
f(malita) 2016/03/21 22:46:24 Done.
+ // a) large enough to produce a partial frame &&
+ // b) small enough to not fully decode the frame
+ static size_t kTruncateSize = 800;
Noel Gordon 2016/03/21 22:37:16 static -> const ?
f(malita) 2016/03/21 22:46:24 doh, done.
+ ASSERT_TRUE(kTruncateSize < fullData->size());
+ RefPtr<SharedBuffer> partialData = SharedBuffer::create(fullData->data(), kTruncateSize);
+
+ OwnPtr<ImageDecoder> premulDecoder = adoptPtr(new GIFImageDecoder(
+ ImageDecoder::AlphaPremultiplied,
+ ImageDecoder::GammaAndColorProfileApplied,
+ ImageDecoder::noDecodedImageByteLimit));
+ OwnPtr<ImageDecoder> unpremulDecoder = adoptPtr(new GIFImageDecoder(
+ ImageDecoder::AlphaNotPremultiplied,
+ ImageDecoder::GammaAndColorProfileApplied,
+ ImageDecoder::noDecodedImageByteLimit));
+
+ // Partial frame => alpha type reflects the requested format.
Noel Gordon 2016/03/21 22:37:16 "Partial frame => alpha" -> "Partially decoded fra
f(malita) 2016/03/21 22:46:24 Done.
+ premulDecoder->setData(partialData.get(), false);
+ ASSERT_TRUE(premulDecoder->frameCount());
+ unpremulDecoder->setData(partialData.get(), false);
+ ASSERT_TRUE(unpremulDecoder->frameCount());
+ ImageFrame* premulFrame = premulDecoder->frameBufferAtIndex(0);
+ EXPECT_TRUE(premulFrame && premulFrame->getStatus() != ImageFrame::FrameComplete);
+ EXPECT_EQ(premulFrame->bitmap().alphaType(), kPremul_SkAlphaType);
+ ImageFrame* unpremulFrame = unpremulDecoder->frameBufferAtIndex(0);
+ EXPECT_TRUE(unpremulFrame && unpremulFrame->getStatus() != ImageFrame::FrameComplete);
+ EXPECT_EQ(unpremulFrame->bitmap().alphaType(), kUnpremul_SkAlphaType);
+
+ // Full frame => alpha type is known to be opaque
Noel Gordon 2016/03/21 22:37:16 "Full frame =>" -> "Fully decoded frame => the fra
f(malita) 2016/03/21 22:46:24 Done.
+ premulDecoder->setData(fullData.get(), false);
Noel Gordon 2016/03/21 22:37:16 false -> true
f(malita) 2016/03/21 22:46:24 Done.
+ ASSERT_TRUE(premulDecoder->frameCount());
+ unpremulDecoder->setData(fullData.get(), false);
Noel Gordon 2016/03/21 22:37:16 false -> true
f(malita) 2016/03/21 22:46:24 Done.
+ ASSERT_TRUE(unpremulDecoder->frameCount());
+ premulFrame = premulDecoder->frameBufferAtIndex(0);
+ EXPECT_TRUE(premulFrame && premulFrame->getStatus() == ImageFrame::FrameComplete);
+ EXPECT_EQ(premulFrame->bitmap().alphaType(), kOpaque_SkAlphaType);
+ unpremulFrame = unpremulDecoder->frameBufferAtIndex(0);
+ EXPECT_TRUE(unpremulFrame && unpremulFrame->getStatus() == ImageFrame::FrameComplete);
+ EXPECT_EQ(unpremulFrame->bitmap().alphaType(), kOpaque_SkAlphaType);
+}
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698