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

Side by Side 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, 3 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 unified diff | Download patch
« no previous file with comments | « Source/platform/image-decoders/png/PNGImageDecoder.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2015 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #include "config.h"
32 #include "platform/image-decoders/png/PNGImageDecoder.h"
33
34 #include "platform/RuntimeEnabledFeatures.h"
35 #include "platform/SharedBuffer.h"
36 #include "public/platform/Platform.h"
37 #include "public/platform/WebData.h"
38 #include "public/platform/WebSize.h"
39 #include "public/platform/WebUnitTestSupport.h"
40 #include "wtf/OwnPtr.h"
41 #include "wtf/PassOwnPtr.h"
42 #include "wtf/StringHasher.h"
43 #include "wtf/Vector.h"
44 #include "wtf/dtoa/utils.h"
45 #include <gtest/gtest.h>
46
47 namespace blink {
48
49 namespace {
50
51 PassOwnPtr<PNGImageDecoder> createDecoder(ImageDecoder::AlphaOption alphaOption = ImageDecoder::AlphaNotPremultiplied)
52 {
53 return adoptPtr(new PNGImageDecoder(alphaOption, ImageDecoder::GammaAndColor ProfileApplied, ImageDecoder::noDecodedImageByteLimit));
54 }
55
56 } // namespace
57
58 TEST(AnimatedPNGTests, verifyAnimationParameters)
59 {
60 const char apngTest[] =
61 "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A\x00\x00\x00\x0D\x49\x48\x44\x52\x00\x0 0\x00\x15"
62 "\x00\x00\x00\x0D\x08\x02\x00\x00\x00\xC9\xF0\xB2\x37\x00\x00\x00\x08\x6 1\x63\x54"
63 "\x4C\x00\x00\x00\x04\x00\x00\x00\x09\x05\x11\xDE\x74\x00\x00\x00\x1A\x6 6\x63\x54"
64 "\x4C\x00\x00\x00\x00\x00\x00\x00\x15\x00\x00\x00\x0D\x00\x00\x00\x00\x0 0\x00\x00"
65 "\x00\x00\x01\x00\x01\x00\x00\xE9\xF5\x40\x3D\x00\x00\x00\x10\x49\x44\x4 1\x54\x28"
66 "\xCF\x63\x60\x18\x05\xA3\x60\x14\x90\x0B\x00\x03\x40\x00\x01\x4D\x3F\x5 A\x07\x00"
67 "\x00\x00\x1A\x66\x63\x54\x4C\x00\x00\x00\x01\x00\x00\x00\x0B\x00\x00\x0 0\x05\x00"
68 "\x00\x00\x02\x00\x00\x00\x02\x00\x01\x00\x01\x00\x01\x82\xC4\xD3\x8C\x0 0\x00\x00"
69 "\x19\x66\x64\x41\x54\x00\x00\x00\x02\x08\xD7\x63\x7C\x27\xA8\xC4\x80\x1 7\x30\x31"
70 "\x10\x02\xF4\x51\x01\x00\xC2\x70\x01\x2B\x28\x9D\xA1\x05\x00\x00\x00\x1 A\x66\x63"
71 "\x54\x4C\x00\x00\x00\x03\x00\x00\x00\x0B\x00\x00\x00\x05\x00\x00\x00\x0 5\x00\x00"
72 "\x00\x04\x00\x01\x00\x01\x02\x00\x60\x88\x72\xC8\x00\x00\x00\x19\x66\x6 4\x41\x54"
73 "\x00\x00\x00\x04\x08\xD7\x63\xFC\xFF\x4E\x90\x01\x2F\x60\x62\x20\x04\xE 8\xA3\x02"
74 "\x00\x53\xA9\x02\x08\x05\x03\x10\x85\x00\x00\x00\x1A\x66\x63\x54\x4C\x0 0\x00\x00"
75 "\x05\x00\x00\x00\x0B\x00\x00\x00\x05\x00\x00\x00\x08\x00\x00\x00\x06\x0 0\x03\x00"
76 "\x01\x00\x01\xEE\xB8\x5D\xE8\x00\x00\x00\x19\x66\x64\x41\x54\x00\x00\x0 0\x06\x08"
77 "\xD7\x63\x54\xFA\x2F\xC8\x80\x17\x30\x31\x10\x02\xF4\x51\x01\x00\xCC\xD D\x01\x3C"
78 "\x8A\x53\x30\xE8\x00\x00\x00\x00\x49\x45\x4E\x44\xAE\x42\x60\x82";
79
80 OwnPtr<ImageDecoder> decoder = createDecoder();
81
82 RefPtr<SharedBuffer> data = SharedBuffer::create(apngTest, sizeof(apngTest)- 1);
83 ASSERT_TRUE(data.get());
84 decoder->setData(data.get(), true);
85
86 const int canvasWidth = 21;
87 const int canvasHeight = 13;
88 const int repetitionCount = 8;
89 const struct AnimParam {
90 int xOffset, yOffset, width, height;
91 ImageFrame::DisposalMethod disposalMethod;
92 ImageFrame::AlphaBlendSource alphaBlendSource;
93 unsigned duration;
94 bool hasAlpha;
95 } frameParameters[] = {
96 { 0, 0, 21, 13, ImageFrame::DisposeKeep, ImageFrame::BlendAtopBgcolor, 1 000u, false },
97 { 2, 2, 11, 5, ImageFrame::DisposeKeep, ImageFrame::BlendAtopPreviousFra me, 1000u, false },
98 { 5, 4, 11, 5, ImageFrame::DisposeOverwritePrevious, ImageFrame::BlendAt opBgcolor, 1000u, false },
99 { 8, 6, 11, 5, ImageFrame::DisposeKeep, ImageFrame::BlendAtopPreviousFra me, 3000u, false },
100 };
101
102 for (size_t i = 0; i < ARRAY_SIZE(frameParameters); ++i) {
103 const ImageFrame* const frame = decoder->frameBufferAtIndex(i);
104 EXPECT_EQ(ImageFrame::FrameComplete, frame->status());
105 EXPECT_EQ(canvasWidth, frame->getSkBitmap().width());
106 EXPECT_EQ(canvasHeight, frame->getSkBitmap().height());
107 EXPECT_EQ(frameParameters[i].xOffset, frame->originalFrameRect().x());
108 EXPECT_EQ(frameParameters[i].yOffset, frame->originalFrameRect().y());
109 EXPECT_EQ(frameParameters[i].width, frame->originalFrameRect().width());
110 EXPECT_EQ(frameParameters[i].height, frame->originalFrameRect().height() );
111 EXPECT_EQ(frameParameters[i].disposalMethod, frame->disposalMethod());
112 EXPECT_EQ(frameParameters[i].alphaBlendSource, frame->alphaBlendSource() );
113 EXPECT_EQ(frameParameters[i].duration, frame->duration());
114 EXPECT_EQ(frameParameters[i].hasAlpha, frame->hasAlpha());
115 }
116
117 EXPECT_EQ(ARRAY_SIZE(frameParameters), decoder->frameCount());
118 EXPECT_EQ(repetitionCount, decoder->repetitionCount());
119 }
120
121 } // namespace blink
OLDNEW
« 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