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

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

Issue 1312843006: Animated PNG implementation (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 4 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
« no previous file with comments | « Source/platform/image-decoders/png/PNGImageDecoder.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/platform/image-decoders/png/PNGImageDecoderTest.cpp
diff --git a/Source/platform/image-decoders/png/PNGImageDecoderTest.cpp b/Source/platform/image-decoders/png/PNGImageDecoderTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..3f71fece49914a014b22f52235412ad37307c231
--- /dev/null
+++ b/Source/platform/image-decoders/png/PNGImageDecoderTest.cpp
@@ -0,0 +1,121 @@
+/*
+ * 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 "config.h"
+#include "platform/image-decoders/png/PNGImageDecoder.h"
+
+#include "platform/RuntimeEnabledFeatures.h"
+#include "platform/SharedBuffer.h"
+#include "public/platform/Platform.h"
+#include "public/platform/WebData.h"
+#include "public/platform/WebSize.h"
+#include "public/platform/WebUnitTestSupport.h"
+#include "wtf/OwnPtr.h"
+#include "wtf/PassOwnPtr.h"
+#include "wtf/StringHasher.h"
+#include "wtf/Vector.h"
+#include "wtf/dtoa/utils.h"
+#include <gtest/gtest.h>
+
+namespace blink {
+
+namespace {
+
+PassOwnPtr<PNGImageDecoder> createDecoder(ImageDecoder::AlphaOption alphaOption = ImageDecoder::AlphaNotPremultiplied)
+{
+ return adoptPtr(new PNGImageDecoder(alphaOption, ImageDecoder::GammaAndColorProfileApplied, ImageDecoder::noDecodedImageByteLimit));
+}
+
+} // 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";
+
+ OwnPtr<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 < ARRAY_SIZE(frameParameters); ++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(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->disposalMethod());
+ EXPECT_EQ(frameParameters[i].alphaBlendSource, frame->alphaBlendSource());
+ EXPECT_EQ(frameParameters[i].duration, frame->duration());
+ EXPECT_EQ(frameParameters[i].hasAlpha, frame->hasAlpha());
+ }
+
+ EXPECT_EQ(ARRAY_SIZE(frameParameters), decoder->frameCount());
+ EXPECT_EQ(repetitionCount, decoder->repetitionCount());
+}
+
+} // namespace blink
« no previous file with comments | « Source/platform/image-decoders/png/PNGImageDecoder.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698