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

Unified Diff: third_party/WebKit/Source/platform/image-decoders/png/PNGImageDecoderTest.cpp

Issue 1567053002: Animated PNG implementation Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Moved some code to PNGImageReader.cpp and PNGImageReader.h Created 4 years, 1 month 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/png/PNGImageDecoderTest.cpp
diff --git a/third_party/WebKit/Source/platform/image-decoders/png/PNGImageDecoderTest.cpp b/third_party/WebKit/Source/platform/image-decoders/png/PNGImageDecoderTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..967c5e744c3c85140bcaefd8d0d01cb31c8a4707
--- /dev/null
+++ b/third_party/WebKit/Source/platform/image-decoders/png/PNGImageDecoderTest.cpp
@@ -0,0 +1,128 @@
+/*
+ * Copyright (C) 2015 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "platform/image-decoders/png/PNGImageDecoder.h"
+
+#include "platform/RuntimeEnabledFeatures.h"
+#include "platform/SharedBuffer.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "wtf/PtrUtil.h"
+#include "wtf/Vector.h"
+#include <memory>
+
+namespace blink {
+
+namespace {
+
+std::unique_ptr<ImageDecoder> createDecoder(
+ ImageDecoder::AlphaOption alphaOption) {
+ return wrapUnique(new PNGImageDecoder(alphaOption,
+ ImageDecoder::ColorSpaceApplied,
+ ImageDecoder::noDecodedImageByteLimit));
+}
+
+std::unique_ptr<ImageDecoder> createDecoder() {
+ return createDecoder(ImageDecoder::AlphaNotPremultiplied);
+}
+
+} // namespace
+
+TEST(AnimatedPNGTests, verifyAnimationParameters) {
+ const char apngTest[] =
+ "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A\x00\x00\x00\x0D\x49\x48\x44\x52\x00\x00"
+ "\x00\x15\x00\x00\x00\x0D\x08\x02\x00\x00\x00\xC9\xF0\xB2\x37\x00\x00\x00"
+ "\x08\x61\x63\x54\x4C\x00\x00\x00\x04\x00\x00\x00\x09\x05\x11\xDE\x74\x00"
+ "\x00\x00\x1A\x66\x63\x54\x4C\x00\x00\x00\x00\x00\x00\x00\x15\x00\x00\x00"
+ "\x0D\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x01\x00\x00\xE9\xF5\x40"
+ "\x3D\x00\x00\x00\x10\x49\x44\x41\x54\x28\xCF\x63\x60\x18\x05\xA3\x60\x14"
+ "\x90\x0B\x00\x03\x40\x00\x01\x4D\x3F\x5A\x07\x00\x00\x00\x1A\x66\x63\x54"
+ "\x4C\x00\x00\x00\x01\x00\x00\x00\x0B\x00\x00\x00\x05\x00\x00\x00\x02\x00"
+ "\x00\x00\x02\x00\x01\x00\x01\x00\x01\x82\xC4\xD3\x8C\x00\x00\x00\x19\x66"
+ "\x64\x41\x54\x00\x00\x00\x02\x08\xD7\x63\x7C\x27\xA8\xC4\x80\x17\x30\x31"
+ "\x10\x02\xF4\x51\x01\x00\xC2\x70\x01\x2B\x28\x9D\xA1\x05\x00\x00\x00\x1A"
+ "\x66\x63\x54\x4C\x00\x00\x00\x03\x00\x00\x00\x0B\x00\x00\x00\x05\x00\x00"
+ "\x00\x05\x00\x00\x00\x04\x00\x01\x00\x01\x02\x00\x60\x88\x72\xC8\x00\x00"
+ "\x00\x19\x66\x64\x41\x54\x00\x00\x00\x04\x08\xD7\x63\xFC\xFF\x4E\x90\x01"
+ "\x2F\x60\x62\x20\x04\xE8\xA3\x02\x00\x53\xA9\x02\x08\x05\x03\x10\x85\x00"
+ "\x00\x00\x1A\x66\x63\x54\x4C\x00\x00\x00\x05\x00\x00\x00\x0B\x00\x00\x00"
+ "\x05\x00\x00\x00\x08\x00\x00\x00\x06\x00\x03\x00\x01\x00\x01\xEE\xB8\x5D"
+ "\xE8\x00\x00\x00\x19\x66\x64\x41\x54\x00\x00\x00\x06\x08\xD7\x63\x54\xFA"
+ "\x2F\xC8\x80\x17\x30\x31\x10\x02\xF4\x51\x01\x00\xCC\xDD\x01\x3C\x8A\x53"
+ "\x30\xE8\x00\x00\x00\x00\x49\x45\x4E\x44\xAE\x42\x60\x82";
+
+ RuntimeEnabledFeatures::setAnimatedPNGEnabled(true);
+ std::unique_ptr<ImageDecoder> decoder = createDecoder();
+
+ RefPtr<SharedBuffer> data =
+ SharedBuffer::create(apngTest, sizeof(apngTest) - 1);
+ ASSERT_TRUE(data.get());
+ decoder->setData(data.get(), true);
+
+ const int canvasWidth = 21;
+ const int canvasHeight = 13;
+ const int repetitionCount = 8;
+ const struct AnimParam {
+ int xOffset, yOffset, width, height;
+ ImageFrame::DisposalMethod disposalMethod;
+ ImageFrame::AlphaBlendSource alphaBlendSource;
+ unsigned duration;
+ bool hasAlpha;
+ } frameParameters[] = {
+ {0, 0, 21, 13, ImageFrame::DisposeKeep, ImageFrame::BlendAtopBgcolor,
+ 1000u, false},
+ {2, 2, 11, 5, ImageFrame::DisposeKeep, ImageFrame::BlendAtopPreviousFrame,
+ 1000u, false},
+ {5, 4, 11, 5, ImageFrame::DisposeOverwritePrevious,
+ ImageFrame::BlendAtopBgcolor, 1000u, false},
+ {8, 6, 11, 5, ImageFrame::DisposeKeep, ImageFrame::BlendAtopPreviousFrame,
+ 3000u, false},
+ };
+
+ for (size_t i = 0; i < WTF_ARRAY_LENGTH(frameParameters); ++i) {
+ const ImageFrame* const frame = decoder->frameBufferAtIndex(i);
+ EXPECT_EQ(ImageFrame::FrameComplete, frame->getStatus());
+ EXPECT_EQ(canvasWidth, frame->bitmap().width());
+ EXPECT_EQ(canvasHeight, frame->bitmap().height());
+ EXPECT_EQ(frameParameters[i].xOffset, frame->originalFrameRect().x());
+ EXPECT_EQ(frameParameters[i].yOffset, frame->originalFrameRect().y());
+ EXPECT_EQ(frameParameters[i].width, frame->originalFrameRect().width());
+ EXPECT_EQ(frameParameters[i].height, frame->originalFrameRect().height());
+ EXPECT_EQ(frameParameters[i].disposalMethod, frame->getDisposalMethod());
+ EXPECT_EQ(frameParameters[i].alphaBlendSource,
+ frame->getAlphaBlendSource());
+ EXPECT_EQ(frameParameters[i].duration, frame->duration());
+ EXPECT_EQ(frameParameters[i].hasAlpha, frame->hasAlpha());
+ }
+
+ EXPECT_EQ(WTF_ARRAY_LENGTH(frameParameters), decoder->frameCount());
+ EXPECT_EQ(repetitionCount, decoder->repetitionCount());
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698