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

Side by Side Diff: Source/WebKit/chromium/tests/ImageDecoderTest.cpp

Issue 15350006: Decode GIF image frames on demand. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Don't preserve the last frame and frames at intervals Created 7 years, 7 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
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2013 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
33 #include "core/platform/image-decoders/ImageDecoder.h"
34
35 #include "wtf/OwnPtr.h"
36 #include "wtf/PassOwnPtr.h"
37 #include "wtf/Vector.h"
38 #include <gtest/gtest.h>
39
40 using namespace WebCore;
41
42 class TestImageDecoder : public ImageDecoder {
43 public:
44 TestImageDecoder()
45 : ImageDecoder(ImageSource::AlphaNotPremultiplied, ImageSource::GammaAnd ColorProfileApplied)
46 {
47 }
48
49 virtual String filenameExtension() const OVERRIDE { return ""; }
50 virtual ImageFrame* frameBufferAtIndex(size_t) OVERRIDE { return 0; }
51
52 size_t findRequiredPreviousFrame(size_t frameIndex)
53 {
54 return ImageDecoder::findRequiredPreviousFrame(frameIndex);
55 }
56
57 Vector<ImageFrame, 1>& frameBufferCache()
58 {
59 return m_frameBufferCache;
60 }
61
62 void resetRequiredPreviousFrames()
63 {
64 for (size_t i = 0; i < m_frameBufferCache.size(); ++i)
65 m_frameBufferCache[i].setRequiredPreviousFrameIndex(findRequiredPrev iousFrame(i));
66 }
67 };
68
69 TEST(ImageDecoderTest, findRequiredPreviousFrame)
70 {
71 OwnPtr<TestImageDecoder> decoder(adoptPtr(new TestImageDecoder()));
72 Vector<ImageFrame, 1>& decoderFrameBufferCache = decoder->frameBufferCache() ;
73
74 const size_t numFrames = 6;
75 const unsigned defaultWidth = 100;
76 const unsigned defaultHeight = 100;
77 decoder->setSize(defaultWidth, defaultHeight);
78 decoderFrameBufferCache.resize(numFrames);
79 for (size_t i = 0; i < numFrames; ++i)
80 decoderFrameBufferCache[i].setOriginalFrameRect(IntRect(0, 0, defaultWid th, defaultHeight));
81
82 decoderFrameBufferCache[1].setDisposalMethod(ImageFrame::DisposeKeep);
83 decoderFrameBufferCache[2].setDisposalMethod(ImageFrame::DisposeOverwritePre vious);
84 decoderFrameBufferCache[3].setDisposalMethod(ImageFrame::DisposeOverwritePre vious);
85 decoderFrameBufferCache[4].setDisposalMethod(ImageFrame::DisposeKeep);
86
87 // The first frame doesn't require any previous frame.
88 EXPECT_EQ(notFound, decoder->findRequiredPreviousFrame(0));
89 // The previous DisposeNotSpecified frame is required.
90 EXPECT_EQ(0u, decoder->findRequiredPreviousFrame(1));
91 // DisposeKeep is treated as DisposeNotSpecified.
92 EXPECT_EQ(1u, decoder->findRequiredPreviousFrame(2));
93 // Previous DisposeOverwritePrevious frames are skipped.
94 EXPECT_EQ(1u, decoder->findRequiredPreviousFrame(3));
95 EXPECT_EQ(1u, decoder->findRequiredPreviousFrame(4));
96 EXPECT_EQ(4u, decoder->findRequiredPreviousFrame(5));
97
98 // Fully covering DisposeOverwriteBgcolor previous frame resets the starting state.
99 decoderFrameBufferCache[1].setDisposalMethod(ImageFrame::DisposeOverwriteBgc olor);
Alpha Left Google 2013/05/22 20:18:09 I suggest this be a separate test case.
Xianzhu 2013/05/22 23:43:29 Done.
100 EXPECT_EQ(notFound, decoder->findRequiredPreviousFrame(2));
101
102 // DisposeOverwritePrevious of the first frame is treated as DisposeOverwrit eBgcolor.
Alpha Left Google 2013/05/22 20:18:09 I suggest this be a separate test case.
Xianzhu 2013/05/22 23:43:29 Done.
103 decoderFrameBufferCache[0].setDisposalMethod(ImageFrame::DisposeOverwritePre vious);
104 EXPECT_EQ(notFound, decoder->findRequiredPreviousFrame(1));
105 decoderFrameBufferCache[0].setDisposalMethod(ImageFrame::DisposeOverwriteBgc olor);
106 EXPECT_EQ(notFound, decoder->findRequiredPreviousFrame(1));
107
108 // Partially converting DisposeOverriteBgcolor previous frame is treated Dis poseKeep.
Alpha Left Google 2013/05/22 20:18:09 nit: I can't parse this sentence please rewrite it
Xianzhu 2013/05/22 23:43:29 Done.
109 decoderFrameBufferCache[1].setOriginalFrameRect(IntRect(50, 50, 50, 50));
Alpha Left Google 2013/05/22 20:18:09 I suggest this be a separate test case.
Xianzhu 2013/05/22 23:43:29 Done.
110 EXPECT_EQ(1u, decoder->findRequiredPreviousFrame(2));
111
Alpha Left Google 2013/05/22 20:18:09 Please add a condition that a DisposeKeep or Dispo
Xianzhu 2013/05/22 23:43:29 This will be tested in GIFImageDecoderTest because
112 // The above rule doesn't apply if the previous frame is the first frame.
113 decoderFrameBufferCache[0].setOriginalFrameRect(IntRect(50, 50, 50, 50));
114 EXPECT_EQ(notFound, decoder->findRequiredPreviousFrame(1));
115 }
116
117 TEST(ImageDecoderTest, clearFrameBufferCache)
118 {
119 OwnPtr<TestImageDecoder> decoder(adoptPtr(new TestImageDecoder()));
120 Vector<ImageFrame, 1>& decoderFrameBufferCache = decoder->frameBufferCache() ;
121
122 const unsigned defaultWidth = 100;
123 const unsigned defaultHeight = 100;
124 decoder->setSize(defaultWidth, defaultHeight);
125
126 // This should no nothing.
Alpha Left Google 2013/05/22 20:18:09 nit: do
Xianzhu 2013/05/22 23:43:29 Done.
127 decoder->clearFrameBufferCache(0);
128
129 const size_t numFrames = 20;
130 decoderFrameBufferCache.resize(numFrames);
131 for (size_t i = 0; i < numFrames; ++i) {
132 decoderFrameBufferCache[i].setOriginalFrameRect(IntRect(0, 0, defaultWid th, defaultHeight));
133 decoderFrameBufferCache[i].setStatus(ImageFrame::FrameComplete);
134 }
135
136 decoderFrameBufferCache[9].setStatus(ImageFrame::FramePartial);
137 decoder->resetRequiredPreviousFrames();
138
139 decoder->clearFrameBufferCache(7);
140 // Should preserve the the clearExceptFrame.
141 EXPECT_EQ(ImageFrame::FrameComplete, decoderFrameBufferCache[7].status());
142 // Should preserve non-completed frames.
143 EXPECT_EQ(ImageFrame::FramePartial, decoderFrameBufferCache[9].status());
Alpha Left Google 2013/05/22 20:18:09 The test only clear (7) which doesn't cover 9 anyw
Xianzhu 2013/05/22 23:43:29 Done.
144 // All other frames should be cleared.
145 for (size_t i = 0; i < numFrames; ++i) {
146 if (i != 7 && i != 9)
147 EXPECT_EQ(ImageFrame::FrameEmpty, decoderFrameBufferCache[i].status( ));
Alpha Left Google 2013/05/22 20:18:09 nit: If this expect fails it's not clear from the
Xianzhu 2013/05/22 23:43:29 Done.
148 }
149
150 // Repeated clearFrameBufferCache should not change the state.
Alpha Left Google 2013/05/22 20:18:09 This should be a separate test case.
Xianzhu 2013/05/22 23:43:29 Done.
151 decoder->resetRequiredPreviousFrames();
152 Vector<ImageFrame, 1> oldFrameBufferCache = decoderFrameBufferCache;
153 decoder->clearFrameBufferCache(7);
154 for (size_t i = 0; i < numFrames; ++i)
155 EXPECT_EQ(oldFrameBufferCache[i].status(), decoderFrameBufferCache[i].st atus());
156
157 decoderFrameBufferCache[5].setStatus(ImageFrame::FrameComplete);
158 decoderFrameBufferCache[7].setDisposalMethod(ImageFrame::DisposeOverwritePre vious);
159 decoderFrameBufferCache[8].setDisposalMethod(ImageFrame::DisposeOverwritePre vious);
160 decoderFrameBufferCache[9].clearPixelData();
161 decoder->resetRequiredPreviousFrames();
162
163 decoder->clearFrameBufferCache(9);
164 // Should preserve the frame that is required to decode the clearExceptFrame .
165 EXPECT_EQ(ImageFrame::FrameComplete, decoderFrameBufferCache[5].status());
166
167 // This should not crash.
168 decoder->clearFrameBufferCache(notFound);
Alpha Left Google 2013/05/22 20:18:09 This should be a separate test case.
Xianzhu 2013/05/22 23:43:29 Done.
169 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698