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

Side by Side 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 unified diff | Download patch
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 "platform/image-decoders/png/PNGImageDecoder.h"
32
33 #include "platform/RuntimeEnabledFeatures.h"
34 #include "platform/SharedBuffer.h"
35 #include "testing/gtest/include/gtest/gtest.h"
36 #include "wtf/PtrUtil.h"
37 #include "wtf/Vector.h"
38 #include <memory>
39
40 namespace blink {
41
42 namespace {
43
44 std::unique_ptr<ImageDecoder> createDecoder(
45 ImageDecoder::AlphaOption alphaOption) {
46 return wrapUnique(new PNGImageDecoder(alphaOption,
47 ImageDecoder::ColorSpaceApplied,
48 ImageDecoder::noDecodedImageByteLimit));
49 }
50
51 std::unique_ptr<ImageDecoder> createDecoder() {
52 return createDecoder(ImageDecoder::AlphaNotPremultiplied);
53 }
54
55 } // namespace
56
57 TEST(AnimatedPNGTests, verifyAnimationParameters) {
58 const char apngTest[] =
59 "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A\x00\x00\x00\x0D\x49\x48\x44\x52\x00\x00"
60 "\x00\x15\x00\x00\x00\x0D\x08\x02\x00\x00\x00\xC9\xF0\xB2\x37\x00\x00\x00"
61 "\x08\x61\x63\x54\x4C\x00\x00\x00\x04\x00\x00\x00\x09\x05\x11\xDE\x74\x00"
62 "\x00\x00\x1A\x66\x63\x54\x4C\x00\x00\x00\x00\x00\x00\x00\x15\x00\x00\x00"
63 "\x0D\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x01\x00\x00\xE9\xF5\x40"
64 "\x3D\x00\x00\x00\x10\x49\x44\x41\x54\x28\xCF\x63\x60\x18\x05\xA3\x60\x14"
65 "\x90\x0B\x00\x03\x40\x00\x01\x4D\x3F\x5A\x07\x00\x00\x00\x1A\x66\x63\x54"
66 "\x4C\x00\x00\x00\x01\x00\x00\x00\x0B\x00\x00\x00\x05\x00\x00\x00\x02\x00"
67 "\x00\x00\x02\x00\x01\x00\x01\x00\x01\x82\xC4\xD3\x8C\x00\x00\x00\x19\x66"
68 "\x64\x41\x54\x00\x00\x00\x02\x08\xD7\x63\x7C\x27\xA8\xC4\x80\x17\x30\x31"
69 "\x10\x02\xF4\x51\x01\x00\xC2\x70\x01\x2B\x28\x9D\xA1\x05\x00\x00\x00\x1A"
70 "\x66\x63\x54\x4C\x00\x00\x00\x03\x00\x00\x00\x0B\x00\x00\x00\x05\x00\x00"
71 "\x00\x05\x00\x00\x00\x04\x00\x01\x00\x01\x02\x00\x60\x88\x72\xC8\x00\x00"
72 "\x00\x19\x66\x64\x41\x54\x00\x00\x00\x04\x08\xD7\x63\xFC\xFF\x4E\x90\x01"
73 "\x2F\x60\x62\x20\x04\xE8\xA3\x02\x00\x53\xA9\x02\x08\x05\x03\x10\x85\x00"
74 "\x00\x00\x1A\x66\x63\x54\x4C\x00\x00\x00\x05\x00\x00\x00\x0B\x00\x00\x00"
75 "\x05\x00\x00\x00\x08\x00\x00\x00\x06\x00\x03\x00\x01\x00\x01\xEE\xB8\x5D"
76 "\xE8\x00\x00\x00\x19\x66\x64\x41\x54\x00\x00\x00\x06\x08\xD7\x63\x54\xFA"
77 "\x2F\xC8\x80\x17\x30\x31\x10\x02\xF4\x51\x01\x00\xCC\xDD\x01\x3C\x8A\x53"
78 "\x30\xE8\x00\x00\x00\x00\x49\x45\x4E\x44\xAE\x42\x60\x82";
79
80 RuntimeEnabledFeatures::setAnimatedPNGEnabled(true);
81 std::unique_ptr<ImageDecoder> decoder = createDecoder();
82
83 RefPtr<SharedBuffer> data =
84 SharedBuffer::create(apngTest, sizeof(apngTest) - 1);
85 ASSERT_TRUE(data.get());
86 decoder->setData(data.get(), true);
87
88 const int canvasWidth = 21;
89 const int canvasHeight = 13;
90 const int repetitionCount = 8;
91 const struct AnimParam {
92 int xOffset, yOffset, width, height;
93 ImageFrame::DisposalMethod disposalMethod;
94 ImageFrame::AlphaBlendSource alphaBlendSource;
95 unsigned duration;
96 bool hasAlpha;
97 } frameParameters[] = {
98 {0, 0, 21, 13, ImageFrame::DisposeKeep, ImageFrame::BlendAtopBgcolor,
99 1000u, false},
100 {2, 2, 11, 5, ImageFrame::DisposeKeep, ImageFrame::BlendAtopPreviousFrame,
101 1000u, false},
102 {5, 4, 11, 5, ImageFrame::DisposeOverwritePrevious,
103 ImageFrame::BlendAtopBgcolor, 1000u, false},
104 {8, 6, 11, 5, ImageFrame::DisposeKeep, ImageFrame::BlendAtopPreviousFrame,
105 3000u, false},
106 };
107
108 for (size_t i = 0; i < WTF_ARRAY_LENGTH(frameParameters); ++i) {
109 const ImageFrame* const frame = decoder->frameBufferAtIndex(i);
110 EXPECT_EQ(ImageFrame::FrameComplete, frame->getStatus());
111 EXPECT_EQ(canvasWidth, frame->bitmap().width());
112 EXPECT_EQ(canvasHeight, frame->bitmap().height());
113 EXPECT_EQ(frameParameters[i].xOffset, frame->originalFrameRect().x());
114 EXPECT_EQ(frameParameters[i].yOffset, frame->originalFrameRect().y());
115 EXPECT_EQ(frameParameters[i].width, frame->originalFrameRect().width());
116 EXPECT_EQ(frameParameters[i].height, frame->originalFrameRect().height());
117 EXPECT_EQ(frameParameters[i].disposalMethod, frame->getDisposalMethod());
118 EXPECT_EQ(frameParameters[i].alphaBlendSource,
119 frame->getAlphaBlendSource());
120 EXPECT_EQ(frameParameters[i].duration, frame->duration());
121 EXPECT_EQ(frameParameters[i].hasAlpha, frame->hasAlpha());
122 }
123
124 EXPECT_EQ(WTF_ARRAY_LENGTH(frameParameters), decoder->frameCount());
125 EXPECT_EQ(repetitionCount, decoder->repetitionCount());
126 }
127
128 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698