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

Side by Side Diff: third_party/WebKit/Source/platform/image-decoders/gif/GIFImageDecoderTest.cpp

Issue 2490473005: Pull up equivalent image decoding tests (Closed)
Patch Set: Separate API for file and dir + file 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
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 19 matching lines...) Expand all
30 30
31 #include "platform/image-decoders/gif/GIFImageDecoder.h" 31 #include "platform/image-decoders/gif/GIFImageDecoder.h"
32 32
33 #include "platform/SharedBuffer.h" 33 #include "platform/SharedBuffer.h"
34 #include "platform/image-decoders/ImageDecoderTestHelpers.h" 34 #include "platform/image-decoders/ImageDecoderTestHelpers.h"
35 #include "public/platform/WebData.h" 35 #include "public/platform/WebData.h"
36 #include "public/platform/WebSize.h" 36 #include "public/platform/WebSize.h"
37 #include "testing/gtest/include/gtest/gtest.h" 37 #include "testing/gtest/include/gtest/gtest.h"
38 #include "wtf/PtrUtil.h" 38 #include "wtf/PtrUtil.h"
39 #include "wtf/Vector.h" 39 #include "wtf/Vector.h"
40 #include "wtf/text/StringBuilder.h"
scroggo_chromium 2016/11/11 13:18:42 I think this is no longer needed?
joostouwerling 2016/11/11 14:43:58 Done.
40 #include <memory> 41 #include <memory>
41 42
42 namespace blink { 43 namespace blink {
43 44
44 namespace { 45 namespace {
45 46
46 const char layoutTestResourcesDir[] = "LayoutTests/fast/images/resources"; 47 const char layoutTestResourcesDir[] = "LayoutTests/fast/images/resources";
47 48
48 std::unique_ptr<ImageDecoder> createDecoder() { 49 std::unique_ptr<ImageDecoder> createDecoder() {
49 return wrapUnique(new GIFImageDecoder(ImageDecoder::AlphaNotPremultiplied, 50 return wrapUnique(new GIFImageDecoder(ImageDecoder::AlphaNotPremultiplied,
50 ImageDecoder::ColorSpaceApplied, 51 ImageDecoder::ColorSpaceApplied,
51 ImageDecoder::noDecodedImageByteLimit)); 52 ImageDecoder::noDecodedImageByteLimit));
52 } 53 }
53 54
54 void testRandomFrameDecode(const char* dir, const char* gifFile) { 55 void testRepetitionCount(const char* dir,
55 SCOPED_TRACE(gifFile); 56 const char* file,
57 int expectedRepetitionCount) {
58 std::unique_ptr<ImageDecoder> decoder = createDecoder();
59 RefPtr<SharedBuffer> data = readFile(dir, file);
60 ASSERT_TRUE(data.get());
61 decoder->setData(data.get(), true);
62 EXPECT_EQ(cAnimationLoopOnce,
63 decoder->repetitionCount()); // Default value before decode.
56 64
57 RefPtr<SharedBuffer> fullData = readFile(dir, gifFile); 65 for (size_t i = 0; i < decoder->frameCount(); ++i) {
58 ASSERT_TRUE(fullData.get()); 66 ImageFrame* frame = decoder->frameBufferAtIndex(i);
59 Vector<unsigned> baselineHashes; 67 EXPECT_EQ(ImageFrame::FrameComplete, frame->getStatus());
60 createDecodingBaseline(&createDecoder, fullData.get(), &baselineHashes);
61 size_t frameCount = baselineHashes.size();
62
63 // Random decoding should get the same results as sequential decoding.
64 std::unique_ptr<ImageDecoder> decoder = createDecoder();
65 decoder->setData(fullData.get(), true);
66 const size_t skippingStep = 5;
67 for (size_t i = 0; i < skippingStep; ++i) {
68 for (size_t j = i; j < frameCount; j += skippingStep) {
69 SCOPED_TRACE(testing::Message() << "Random i:" << i << " j:" << j);
70 ImageFrame* frame = decoder->frameBufferAtIndex(j);
71 EXPECT_EQ(baselineHashes[j], hashBitmap(frame->bitmap()));
72 }
73 } 68 }
74 69
75 // Decoding in reverse order. 70 EXPECT_EQ(expectedRepetitionCount,
76 decoder = createDecoder(); 71 decoder->repetitionCount()); // Expected value after decode.
77 decoder->setData(fullData.get(), true);
78 for (size_t i = frameCount; i; --i) {
79 SCOPED_TRACE(testing::Message() << "Reverse i:" << i);
80 ImageFrame* frame = decoder->frameBufferAtIndex(i - 1);
81 EXPECT_EQ(baselineHashes[i - 1], hashBitmap(frame->bitmap()));
82 }
83 }
84
85 void testRandomDecodeAfterClearFrameBufferCache(const char* dir,
86 const char* gifFile) {
87 SCOPED_TRACE(gifFile);
88
89 RefPtr<SharedBuffer> data = readFile(dir, gifFile);
90 ASSERT_TRUE(data.get());
91 Vector<unsigned> baselineHashes;
92 createDecodingBaseline(&createDecoder, data.get(), &baselineHashes);
93 size_t frameCount = baselineHashes.size();
94
95 std::unique_ptr<ImageDecoder> decoder = createDecoder();
96 decoder->setData(data.get(), true);
97 for (size_t clearExceptFrame = 0; clearExceptFrame < frameCount;
98 ++clearExceptFrame) {
99 decoder->clearCacheExceptFrame(clearExceptFrame);
100 const size_t skippingStep = 5;
101 for (size_t i = 0; i < skippingStep; ++i) {
102 for (size_t j = 0; j < frameCount; j += skippingStep) {
103 SCOPED_TRACE(testing::Message() << "Random i:" << i << " j:" << j);
104 ImageFrame* frame = decoder->frameBufferAtIndex(j);
105 EXPECT_EQ(baselineHashes[j], hashBitmap(frame->bitmap()));
106 }
107 }
108 }
109 } 72 }
110 73
111 } // anonymous namespace 74 } // anonymous namespace
112 75
113 TEST(GIFImageDecoderTest, decodeTwoFrames) { 76 TEST(GIFImageDecoderTest, decodeTwoFrames) {
114 std::unique_ptr<ImageDecoder> decoder = createDecoder(); 77 std::unique_ptr<ImageDecoder> decoder = createDecoder();
115 78
116 RefPtr<SharedBuffer> data = readFile(layoutTestResourcesDir, "animated.gif"); 79 RefPtr<SharedBuffer> data = readFile(layoutTestResourcesDir, "animated.gif");
117 ASSERT_TRUE(data.get()); 80 ASSERT_TRUE(data.get());
118 decoder->setData(data.get(), true); 81 decoder->setData(data.get(), true);
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 ASSERT_TRUE(data.get()); 181 ASSERT_TRUE(data.get());
219 decoder->setData(data.get(), true); 182 decoder->setData(data.get(), true);
220 183
221 // One frame is detected but cannot be decoded. 184 // One frame is detected but cannot be decoded.
222 EXPECT_EQ(1u, decoder->frameCount()); 185 EXPECT_EQ(1u, decoder->frameCount());
223 ImageFrame* frame = decoder->frameBufferAtIndex(1); 186 ImageFrame* frame = decoder->frameBufferAtIndex(1);
224 EXPECT_FALSE(frame); 187 EXPECT_FALSE(frame);
225 } 188 }
226 189
227 TEST(GIFImageDecoderTest, progressiveDecode) { 190 TEST(GIFImageDecoderTest, progressiveDecode) {
228 RefPtr<SharedBuffer> fullData = readFile(decodersTestingDir, "radient.gif"); 191 testProgressiveDecoding(&createDecoder, decodersTestingDir, "radient.gif");
229 ASSERT_TRUE(fullData.get());
230 const size_t fullLength = fullData->size();
231
232 std::unique_ptr<ImageDecoder> decoder;
233 ImageFrame* frame;
234
235 Vector<unsigned> truncatedHashes;
236 Vector<unsigned> progressiveHashes;
237
238 // Compute hashes when the file is truncated.
239 const size_t increment = 1;
240 for (size_t i = 1; i <= fullLength; i += increment) {
241 decoder = createDecoder();
242 RefPtr<SharedBuffer> data = SharedBuffer::create(fullData->data(), i);
243 decoder->setData(data.get(), i == fullLength);
244 frame = decoder->frameBufferAtIndex(0);
245 if (!frame) {
246 truncatedHashes.append(0);
247 continue;
248 }
249 truncatedHashes.append(hashBitmap(frame->bitmap()));
250 }
251
252 // Compute hashes when the file is progressively decoded.
253 decoder = createDecoder();
254 EXPECT_EQ(cAnimationLoopOnce, decoder->repetitionCount());
255 for (size_t i = 1; i <= fullLength; i += increment) {
256 RefPtr<SharedBuffer> data = SharedBuffer::create(fullData->data(), i);
257 decoder->setData(data.get(), i == fullLength);
258 frame = decoder->frameBufferAtIndex(0);
259 if (!frame) {
260 progressiveHashes.append(0);
261 continue;
262 }
263 progressiveHashes.append(hashBitmap(frame->bitmap()));
264 }
265 EXPECT_EQ(cAnimationNone, decoder->repetitionCount());
266
267 bool match = true;
268 for (size_t i = 0; i < truncatedHashes.size(); ++i) {
269 if (truncatedHashes[i] != progressiveHashes[i]) {
270 match = false;
271 break;
272 }
273 }
274 EXPECT_TRUE(match);
275 } 192 }
276 193
277 TEST(GIFImageDecoderTest, allDataReceivedTruncation) { 194 TEST(GIFImageDecoderTest, allDataReceivedTruncation) {
278 std::unique_ptr<ImageDecoder> decoder = createDecoder(); 195 std::unique_ptr<ImageDecoder> decoder = createDecoder();
279 196
280 RefPtr<SharedBuffer> data = readFile(layoutTestResourcesDir, "animated.gif"); 197 RefPtr<SharedBuffer> data = readFile(layoutTestResourcesDir, "animated.gif");
281 ASSERT_TRUE(data.get()); 198 ASSERT_TRUE(data.get());
282 199
283 ASSERT_GE(data->size(), 10u); 200 ASSERT_GE(data->size(), 10u);
284 RefPtr<SharedBuffer> tempData = 201 RefPtr<SharedBuffer> tempData =
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 decoder->frameBufferAtIndex(i)->requiredPreviousFrameIndex()); 299 decoder->frameBufferAtIndex(i)->requiredPreviousFrameIndex());
383 300
384 decoder->setData(fullData.get(), true); 301 decoder->setData(fullData.get(), true);
385 for (size_t i = 0; i < frameCount; ++i) 302 for (size_t i = 0; i < frameCount; ++i)
386 EXPECT_EQ(kNotFound, 303 EXPECT_EQ(kNotFound,
387 decoder->frameBufferAtIndex(i)->requiredPreviousFrameIndex()); 304 decoder->frameBufferAtIndex(i)->requiredPreviousFrameIndex());
388 } 305 }
389 306
390 TEST(GIFImageDecoderTest, randomFrameDecode) { 307 TEST(GIFImageDecoderTest, randomFrameDecode) {
391 // Single frame image. 308 // Single frame image.
392 testRandomFrameDecode(decodersTestingDir, "radient.gif"); 309 testRandomFrameDecode(&createDecoder, decodersTestingDir, "radient.gif");
393 // Multiple frame images. 310 // Multiple frame images.
394 testRandomFrameDecode(layoutTestResourcesDir, 311 testRandomFrameDecode(&createDecoder, layoutTestResourcesDir,
395 "animated-gif-with-offsets.gif"); 312 "animated-gif-with-offsets.gif");
396 testRandomFrameDecode(layoutTestResourcesDir, "animated-10color.gif"); 313 testRandomFrameDecode(&createDecoder, layoutTestResourcesDir,
314 "animated-10color.gif");
397 } 315 }
398 316
399 TEST(GIFImageDecoderTest, randomDecodeAfterClearFrameBufferCache) { 317 TEST(GIFImageDecoderTest, randomDecodeAfterClearFrameBufferCache) {
400 // Single frame image. 318 // Single frame image.
401 testRandomDecodeAfterClearFrameBufferCache(decodersTestingDir, "radient.gif"); 319 testRandomDecodeAfterClearFrameBufferCache(&createDecoder, decodersTestingDir,
320 "radient.gif");
402 // Multiple frame images. 321 // Multiple frame images.
403 testRandomDecodeAfterClearFrameBufferCache(layoutTestResourcesDir, 322 testRandomDecodeAfterClearFrameBufferCache(
404 "animated-gif-with-offsets.gif"); 323 &createDecoder, layoutTestResourcesDir, "animated-gif-with-offsets.gif");
405 testRandomDecodeAfterClearFrameBufferCache(layoutTestResourcesDir, 324 testRandomDecodeAfterClearFrameBufferCache(
406 "animated-10color.gif"); 325 &createDecoder, layoutTestResourcesDir, "animated-10color.gif");
407 } 326 }
408 327
409 TEST(GIFImageDecoderTest, resumePartialDecodeAfterClearFrameBufferCache) { 328 TEST(GIFImageDecoderTest, resumePartialDecodeAfterClearFrameBufferCache) {
410 RefPtr<SharedBuffer> fullData = 329 RefPtr<SharedBuffer> fullData =
411 readFile(layoutTestResourcesDir, "animated-10color.gif"); 330 readFile(layoutTestResourcesDir, "animated-10color.gif");
412 ASSERT_TRUE(fullData.get()); 331 ASSERT_TRUE(fullData.get());
413 Vector<unsigned> baselineHashes; 332 Vector<unsigned> baselineHashes;
414 createDecodingBaseline(&createDecoder, fullData.get(), &baselineHashes); 333 createDecodingBaseline(&createDecoder, fullData.get(), &baselineHashes);
415 size_t frameCount = baselineHashes.size(); 334 size_t frameCount = baselineHashes.size();
416 335
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 frameSize = decoder->decodedSize(); 424 frameSize = decoder->decodedSize();
506 continue; 425 continue;
507 } 426 }
508 427
509 ASSERT_EQ(frameSize.width(), decoder->decodedSize().width()); 428 ASSERT_EQ(frameSize.width(), decoder->decodedSize().width());
510 ASSERT_EQ(frameSize.height(), decoder->decodedSize().height()); 429 ASSERT_EQ(frameSize.height(), decoder->decodedSize().height());
511 } 430 }
512 } 431 }
513 432
514 TEST(GIFImageDecoderTest, verifyRepetitionCount) { 433 TEST(GIFImageDecoderTest, verifyRepetitionCount) {
515 const int expectedRepetitionCount = 2; 434 testRepetitionCount(layoutTestResourcesDir, "full2loop.gif", 2);
516 std::unique_ptr<ImageDecoder> decoder = createDecoder(); 435 testRepetitionCount(decodersTestingDir, "radient.gif", cAnimationNone);
517 RefPtr<SharedBuffer> data = readFile(layoutTestResourcesDir, "full2loop.gif");
518 ASSERT_TRUE(data.get());
519 decoder->setData(data.get(), true);
520 EXPECT_EQ(cAnimationLoopOnce,
521 decoder->repetitionCount()); // Default value before decode.
522
523 for (size_t i = 0; i < decoder->frameCount(); ++i) {
524 ImageFrame* frame = decoder->frameBufferAtIndex(i);
525 EXPECT_EQ(ImageFrame::FrameComplete, frame->getStatus());
526 }
527
528 EXPECT_EQ(expectedRepetitionCount,
529 decoder->repetitionCount()); // Expected value after decode.
530 } 436 }
531 437
532 TEST(GIFImageDecoderTest, bitmapAlphaType) { 438 TEST(GIFImageDecoderTest, bitmapAlphaType) {
533 RefPtr<SharedBuffer> fullData = readFile(decodersTestingDir, "radient.gif"); 439 RefPtr<SharedBuffer> fullData = readFile(decodersTestingDir, "radient.gif");
534 ASSERT_TRUE(fullData.get()); 440 ASSERT_TRUE(fullData.get());
535 441
536 // Empirically chosen truncation size: 442 // Empirically chosen truncation size:
537 // a) large enough to produce a partial frame && 443 // a) large enough to produce a partial frame &&
538 // b) small enough to not fully decode the frame 444 // b) small enough to not fully decode the frame
539 const size_t kTruncateSize = 800; 445 const size_t kTruncateSize = 800;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 EXPECT_TRUE(premulFrame && 479 EXPECT_TRUE(premulFrame &&
574 premulFrame->getStatus() == ImageFrame::FrameComplete); 480 premulFrame->getStatus() == ImageFrame::FrameComplete);
575 EXPECT_EQ(premulFrame->bitmap().alphaType(), kOpaque_SkAlphaType); 481 EXPECT_EQ(premulFrame->bitmap().alphaType(), kOpaque_SkAlphaType);
576 unpremulFrame = unpremulDecoder->frameBufferAtIndex(0); 482 unpremulFrame = unpremulDecoder->frameBufferAtIndex(0);
577 EXPECT_TRUE(unpremulFrame && 483 EXPECT_TRUE(unpremulFrame &&
578 unpremulFrame->getStatus() == ImageFrame::FrameComplete); 484 unpremulFrame->getStatus() == ImageFrame::FrameComplete);
579 EXPECT_EQ(unpremulFrame->bitmap().alphaType(), kOpaque_SkAlphaType); 485 EXPECT_EQ(unpremulFrame->bitmap().alphaType(), kOpaque_SkAlphaType);
580 } 486 }
581 487
582 } // namespace blink 488 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698