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

Unified Diff: Source/WebKit/chromium/tests/WEBPImageDecoderTest.cpp

Issue 13980003: Add animation support for WebP images (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 8 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: Source/WebKit/chromium/tests/WEBPImageDecoderTest.cpp
diff --git a/Source/WebKit/chromium/tests/GIFImageDecoderTest.cpp b/Source/WebKit/chromium/tests/WEBPImageDecoderTest.cpp
similarity index 55%
copy from Source/WebKit/chromium/tests/GIFImageDecoderTest.cpp
copy to Source/WebKit/chromium/tests/WEBPImageDecoderTest.cpp
index f2486e36c9d2d118aab253a8eb86408812b7d32e..5c0483ede45b2c9aa101c9c37ba8bdbd993efa27 100644
--- a/Source/WebKit/chromium/tests/GIFImageDecoderTest.cpp
+++ b/Source/WebKit/chromium/tests/WEBPImageDecoderTest.cpp
@@ -30,11 +30,13 @@
#include "config.h"
-#include "core/platform/image-decoders/gif/GIFImageDecoder.h"
+#include "core/platform/image-decoders/webp/WEBPImageDecoder.h"
-#include <gtest/gtest.h>
+#include "core/page/RuntimeEnabledFeatures.h"
#include "core/platform/FileSystem.h"
#include "core/platform/SharedBuffer.h"
+#include <base/basictypes.h>
+#include <gtest/gtest.h>
#include <public/Platform.h>
#include <public/WebData.h>
#include <public/WebSize.h>
@@ -68,9 +70,9 @@ static PassRefPtr<SharedBuffer> readFile(const char* fileName)
return SharedBuffer::adoptVector(buffer);
}
-static PassOwnPtr<GIFImageDecoder> createDecoder()
+static PassOwnPtr<WEBPImageDecoder> createDecoder()
{
- return adoptPtr(new GIFImageDecoder(ImageSource::AlphaNotPremultiplied, ImageSource::GammaAndColorProfileApplied));
+ return adoptPtr(new WEBPImageDecoder(ImageSource::AlphaNotPremultiplied, ImageSource::GammaAndColorProfileApplied));
}
static unsigned hashSkBitmap(const SkBitmap& bitmap)
@@ -78,111 +80,98 @@ static unsigned hashSkBitmap(const SkBitmap& bitmap)
return StringHasher::hashMemory(bitmap.getPixels(), bitmap.getSize());
}
-TEST(GIFImageDecoderTest, decodeTwoFrames)
-{
- OwnPtr<GIFImageDecoder> decoder(createDecoder());
-
- RefPtr<SharedBuffer> data = readFile("/LayoutTests/fast/images/resources/animated.gif");
- ASSERT_TRUE(data.get());
- decoder->setData(data.get(), true);
- EXPECT_EQ(cAnimationLoopOnce, decoder->repetitionCount());
-
- ImageFrame* frame = decoder->frameBufferAtIndex(0);
- EXPECT_EQ(ImageFrame::FrameComplete, frame->status());
- EXPECT_EQ(16, frame->getSkBitmap().width());
- EXPECT_EQ(16, frame->getSkBitmap().height());
-
- frame = decoder->frameBufferAtIndex(1);
- EXPECT_EQ(ImageFrame::FrameComplete, frame->status());
- EXPECT_EQ(16, frame->getSkBitmap().width());
- EXPECT_EQ(16, frame->getSkBitmap().height());
-
- EXPECT_EQ(2u, decoder->frameCount());
- EXPECT_EQ(cAnimationLoopInfinite, decoder->repetitionCount());
-}
+class WEBPImageDecoderTest : public ::testing::Test {
+protected:
+ virtual void SetUp()
+ {
+ // Enable animated WebP for all the tests.
+ WebCore::RuntimeEnabledFeatures::setAnimatedWebPEnabled(true);
+ }
+};
-TEST(GIFImageDecoderTest, parseAndDecode)
+TEST_F(WEBPImageDecoderTest, verifyAnimationParameters)
Noel Gordon 2013/04/29 18:41:57 I like that you added "Animation" to the test name
urvang (Google) 2013/04/30 13:14:15 Changed the name of the fixture class itself to in
{
- OwnPtr<GIFImageDecoder> decoder(createDecoder());
-
- RefPtr<SharedBuffer> data = readFile("/LayoutTests/fast/images/resources/animated.gif");
- ASSERT_TRUE(data.get());
- decoder->setData(data.get(), true);
+ OwnPtr<WEBPImageDecoder> decoder(createDecoder());
EXPECT_EQ(cAnimationLoopOnce, decoder->repetitionCount());
- // This call will parse the entire file.
- EXPECT_EQ(2u, decoder->frameCount());
-
- ImageFrame* frame = decoder->frameBufferAtIndex(0);
- EXPECT_EQ(ImageFrame::FrameComplete, frame->status());
- EXPECT_EQ(16, frame->getSkBitmap().width());
- EXPECT_EQ(16, frame->getSkBitmap().height());
-
- frame = decoder->frameBufferAtIndex(1);
- EXPECT_EQ(ImageFrame::FrameComplete, frame->status());
- EXPECT_EQ(16, frame->getSkBitmap().width());
- EXPECT_EQ(16, frame->getSkBitmap().height());
- EXPECT_EQ(cAnimationLoopInfinite, decoder->repetitionCount());
-}
-
-TEST(GIFImageDecoderTest, parseByteByByte)
-{
- OwnPtr<GIFImageDecoder> decoder(createDecoder());
-
- RefPtr<SharedBuffer> data = readFile("/LayoutTests/fast/images/resources/animated.gif");
+ RefPtr<SharedBuffer> data = readFile("/LayoutTests/fast/images/resources/webp-animated.webp");
ASSERT_TRUE(data.get());
+ decoder->setData(data.get(), true);
- size_t frameCount = 0;
-
- // Pass data to decoder byte by byte.
- for (unsigned length = 1; length <= data->size(); ++length) {
- RefPtr<SharedBuffer> tempData = SharedBuffer::create(data->data(), length);
- decoder->setData(tempData.get(), length == data->size());
-
- EXPECT_LE(frameCount, decoder->frameCount());
- frameCount = decoder->frameCount();
+ const int canvasWidth = 11;
+ const int canvasHeight = 29;
+ const int hasAlpha = true;
+ const struct AnimParam {
+ int xOffset, yOffset, width, height;
+ ImageFrame::FrameDisposalMethod dispose;
+ unsigned duration;
+ } animParams[] = {
+ { 0, 0, 11, 29, ImageFrame::DisposeKeep, 1000u },
+ { 2, 10, 7, 17, ImageFrame::DisposeKeep, 500u },
+ { 2, 2, 7, 16, ImageFrame::DisposeKeep, 1000u },
+ };
+
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(animParams); ++i) {
+ const ImageFrame* const frame = decoder->frameBufferAtIndex(i);
+ EXPECT_EQ(ImageFrame::FrameComplete, frame->status());
+ EXPECT_EQ(canvasWidth, frame->getSkBitmap().width());
+ EXPECT_EQ(canvasHeight, frame->getSkBitmap().height());
+ EXPECT_EQ(hasAlpha, frame->hasAlpha());
+ EXPECT_EQ(animParams[i].xOffset, frame->originalFrameRect().x());
+ EXPECT_EQ(animParams[i].yOffset, frame->originalFrameRect().y());
+ EXPECT_EQ(animParams[i].width, frame->originalFrameRect().width());
+ EXPECT_EQ(animParams[i].height, frame->originalFrameRect().height());
+ EXPECT_EQ(animParams[i].dispose, frame->disposalMethod());
+ EXPECT_EQ(animParams[i].duration, frame->duration());
}
- EXPECT_EQ(2u, decoder->frameCount());
-
- decoder->frameBufferAtIndex(0);
- decoder->frameBufferAtIndex(1);
+ EXPECT_EQ(ARRAYSIZE_UNSAFE(animParams), decoder->frameCount());
EXPECT_EQ(cAnimationLoopInfinite, decoder->repetitionCount());
}
-TEST(GIFImageDecoderTest, parseAndDecodeByteByByte)
+TEST_F(WEBPImageDecoderTest, parseAndDecodeByteByByte)
{
- OwnPtr<GIFImageDecoder> decoder(createDecoder());
-
- RefPtr<SharedBuffer> data = readFile("/LayoutTests/fast/images/resources/animated-gif-with-offsets.gif");
- ASSERT_TRUE(data.get());
-
- size_t frameCount = 0;
- size_t framesDecoded = 0;
-
- // Pass data to decoder byte by byte.
- for (unsigned length = 1; length <= data->size(); ++length) {
- RefPtr<SharedBuffer> tempData = SharedBuffer::create(data->data(), length);
- decoder->setData(tempData.get(), length == data->size());
-
- EXPECT_LE(frameCount, decoder->frameCount());
- frameCount = decoder->frameCount();
+ const struct TestImage {
+ const char* filename;
+ unsigned frameCount;
+ int repetitionCount;
+ } testImages[] = {
+ { "/LayoutTests/fast/images/resources/webp-animated.webp", 3u, cAnimationLoopInfinite },
+ { "/LayoutTests/fast/images/resources/webp-animated-icc-xmp.webp", 13u, 32000 },
+ };
+
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(testImages); ++i) {
+ OwnPtr<WEBPImageDecoder> decoder(createDecoder());
+ RefPtr<SharedBuffer> data = readFile(testImages[i].filename);
+ ASSERT_TRUE(data.get());
+
+ size_t frameCount = 0;
+ size_t framesDecoded = 0;
+
+ // Pass data to decoder byte by byte.
+ for (unsigned length = 1; length <= data->size(); ++length) {
+ RefPtr<SharedBuffer> tempData = SharedBuffer::create(data->data(), length);
+ decoder->setData(tempData.get(), length == data->size());
+
+ EXPECT_LE(frameCount, decoder->frameCount());
+ frameCount = decoder->frameCount();
+
+ ImageFrame* frame = decoder->frameBufferAtIndex(frameCount - 1);
+ if (frame && frame->status() == ImageFrame::FrameComplete && framesDecoded < frameCount)
+ ++framesDecoded;
+ }
- ImageFrame* frame = decoder->frameBufferAtIndex(frameCount - 1);
- if (frame && frame->status() == ImageFrame::FrameComplete && framesDecoded < frameCount)
- ++framesDecoded;
+ EXPECT_EQ(testImages[i].frameCount, decoder->frameCount());
+ EXPECT_EQ(testImages[i].frameCount, framesDecoded);
+ EXPECT_EQ(testImages[i].repetitionCount, decoder->repetitionCount());
}
-
- EXPECT_EQ(5u, decoder->frameCount());
- EXPECT_EQ(5u, framesDecoded);
- EXPECT_EQ(cAnimationLoopInfinite, decoder->repetitionCount());
}
-TEST(GIFImageDecoderTest, brokenSecondFrame)
+TEST_F(WEBPImageDecoderTest, invalidImage)
{
- OwnPtr<GIFImageDecoder> decoder(createDecoder());
+ OwnPtr<WEBPImageDecoder> decoder(createDecoder());
- RefPtr<SharedBuffer> data = readFile("/Source/WebKit/chromium/tests/data/broken.gif");
+ RefPtr<SharedBuffer> data = readFile("/LayoutTests/fast/images/resources/invalid-animated-webp.webp");
ASSERT_TRUE(data.get());
decoder->setData(data.get(), true);
@@ -192,13 +181,13 @@ TEST(GIFImageDecoderTest, brokenSecondFrame)
EXPECT_EQ(cAnimationLoopOnce, decoder->repetitionCount());
}
-TEST(GIFImageDecoderTest, progressiveDecode)
+TEST_F(WEBPImageDecoderTest, progressiveDecode)
{
- RefPtr<SharedBuffer> fullData = readFile("/Source/WebKit/chromium/tests/data/radient.gif");
+ RefPtr<SharedBuffer> fullData = readFile("/LayoutTests/fast/images/resources/webp-animated.webp");
ASSERT_TRUE(fullData.get());
const size_t fullLength = fullData->size();
- OwnPtr<GIFImageDecoder> decoder;
+ OwnPtr<WEBPImageDecoder> decoder;
ImageFrame* frame;
Vector<unsigned> truncatedHashes;

Powered by Google App Engine
This is Rietveld 408576698