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

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: Add repetition count test for radient.gif 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 namespace { 44 namespace {
45 45
46 const char layoutTestResourcesDir[] = "LayoutTests/fast/images/resources"; 46 const char layoutTestResourcesDir[] = "LayoutTests/fast/images/resources";
47 47
48 std::unique_ptr<ImageDecoder> createDecoder() { 48 std::unique_ptr<ImageDecoder> createDecoder() {
49 return wrapUnique(new GIFImageDecoder(ImageDecoder::AlphaNotPremultiplied, 49 return wrapUnique(new GIFImageDecoder(ImageDecoder::AlphaNotPremultiplied,
50 ImageDecoder::ColorSpaceApplied, 50 ImageDecoder::ColorSpaceApplied,
51 ImageDecoder::noDecodedImageByteLimit)); 51 ImageDecoder::noDecodedImageByteLimit));
52 } 52 }
53 53
54 void testRandomFrameDecode(const char* dir, const char* gifFile) { 54 void testRepetitionCount(const char *dir, const char* file,
joostouwerling 2016/11/09 14:25:08 An extra note about the repetition count test for
scroggo_chromium 2016/11/09 14:38:37 No, I think this is fine.
55 SCOPED_TRACE(gifFile); 55 int expectedRepetitionCount) {
56 std::unique_ptr<ImageDecoder> decoder = createDecoder();
57 RefPtr<SharedBuffer> data = readFile(dir, file);
58 ASSERT_TRUE(data.get());
59 decoder->setData(data.get(), true);
60 EXPECT_EQ(cAnimationLoopOnce,
61 decoder->repetitionCount()); // Default value before decode.
56 62
57 RefPtr<SharedBuffer> fullData = readFile(dir, gifFile); 63 for (size_t i = 0; i < decoder->frameCount(); ++i) {
58 ASSERT_TRUE(fullData.get()); 64 ImageFrame* frame = decoder->frameBufferAtIndex(i);
59 Vector<unsigned> baselineHashes; 65 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 } 66 }
74 67
75 // Decoding in reverse order. 68 EXPECT_EQ(expectedRepetitionCount,
76 decoder = createDecoder(); 69 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 } 70 }
110 71
111 } // anonymous namespace 72 } // anonymous namespace
112 73
113 TEST(GIFImageDecoderTest, decodeTwoFrames) { 74 TEST(GIFImageDecoderTest, decodeTwoFrames) {
114 std::unique_ptr<ImageDecoder> decoder = createDecoder(); 75 std::unique_ptr<ImageDecoder> decoder = createDecoder();
115 76
116 RefPtr<SharedBuffer> data = readFile(layoutTestResourcesDir, "animated.gif"); 77 RefPtr<SharedBuffer> data = readFile(layoutTestResourcesDir, "animated.gif");
117 ASSERT_TRUE(data.get()); 78 ASSERT_TRUE(data.get());
118 decoder->setData(data.get(), true); 79 decoder->setData(data.get(), true);
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 ASSERT_TRUE(data.get()); 179 ASSERT_TRUE(data.get());
219 decoder->setData(data.get(), true); 180 decoder->setData(data.get(), true);
220 181
221 // One frame is detected but cannot be decoded. 182 // One frame is detected but cannot be decoded.
222 EXPECT_EQ(1u, decoder->frameCount()); 183 EXPECT_EQ(1u, decoder->frameCount());
223 ImageFrame* frame = decoder->frameBufferAtIndex(1); 184 ImageFrame* frame = decoder->frameBufferAtIndex(1);
224 EXPECT_FALSE(frame); 185 EXPECT_FALSE(frame);
225 } 186 }
226 187
227 TEST(GIFImageDecoderTest, progressiveDecode) { 188 TEST(GIFImageDecoderTest, progressiveDecode) {
228 RefPtr<SharedBuffer> fullData = readFile(decodersTestingDir, "radient.gif"); 189 testProgressiveDecoding(&createDecoder,
229 ASSERT_TRUE(fullData.get()); 190 concatDirAndFile(decodersTestingDir, "radient.gif"));
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 } 191 }
276 192
277 TEST(GIFImageDecoderTest, allDataReceivedTruncation) { 193 TEST(GIFImageDecoderTest, allDataReceivedTruncation) {
278 std::unique_ptr<ImageDecoder> decoder = createDecoder(); 194 std::unique_ptr<ImageDecoder> decoder = createDecoder();
279 195
280 RefPtr<SharedBuffer> data = readFile(layoutTestResourcesDir, "animated.gif"); 196 RefPtr<SharedBuffer> data = readFile(layoutTestResourcesDir, "animated.gif");
281 ASSERT_TRUE(data.get()); 197 ASSERT_TRUE(data.get());
282 198
283 ASSERT_GE(data->size(), 10u); 199 ASSERT_GE(data->size(), 10u);
284 RefPtr<SharedBuffer> tempData = 200 RefPtr<SharedBuffer> tempData =
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 decoder->frameBufferAtIndex(i)->requiredPreviousFrameIndex()); 298 decoder->frameBufferAtIndex(i)->requiredPreviousFrameIndex());
383 299
384 decoder->setData(fullData.get(), true); 300 decoder->setData(fullData.get(), true);
385 for (size_t i = 0; i < frameCount; ++i) 301 for (size_t i = 0; i < frameCount; ++i)
386 EXPECT_EQ(kNotFound, 302 EXPECT_EQ(kNotFound,
387 decoder->frameBufferAtIndex(i)->requiredPreviousFrameIndex()); 303 decoder->frameBufferAtIndex(i)->requiredPreviousFrameIndex());
388 } 304 }
389 305
390 TEST(GIFImageDecoderTest, randomFrameDecode) { 306 TEST(GIFImageDecoderTest, randomFrameDecode) {
391 // Single frame image. 307 // Single frame image.
392 testRandomFrameDecode(decodersTestingDir, "radient.gif"); 308 testRandomFrameDecode(&createDecoder,
309 concatDirAndFile(decodersTestingDir, "radient.gif"));
393 // Multiple frame images. 310 // Multiple frame images.
394 testRandomFrameDecode(layoutTestResourcesDir, 311 testRandomFrameDecode(&createDecoder,
395 "animated-gif-with-offsets.gif"); 312 concatDirAndFile(layoutTestResourcesDir,
396 testRandomFrameDecode(layoutTestResourcesDir, "animated-10color.gif"); 313 "animated-gif-with-offsets.gif"));
314 testRandomFrameDecode(&createDecoder,
315 concatDirAndFile(layoutTestResourcesDir,
316 "animated-10color.gif"));
397 } 317 }
398 318
399 TEST(GIFImageDecoderTest, randomDecodeAfterClearFrameBufferCache) { 319 TEST(GIFImageDecoderTest, randomDecodeAfterClearFrameBufferCache) {
400 // Single frame image. 320 // Single frame image.
401 testRandomDecodeAfterClearFrameBufferCache(decodersTestingDir, "radient.gif"); 321 testRandomDecodeAfterClearFrameBufferCache(&createDecoder,
322 concatDirAndFile(decodersTestingDir, "radient.gif"));
402 // Multiple frame images. 323 // Multiple frame images.
403 testRandomDecodeAfterClearFrameBufferCache(layoutTestResourcesDir, 324 testRandomDecodeAfterClearFrameBufferCache(&createDecoder,
404 "animated-gif-with-offsets.gif"); 325 concatDirAndFile(layoutTestResourcesDir, "animated-gif-with-offsets.gif")) ;
405 testRandomDecodeAfterClearFrameBufferCache(layoutTestResourcesDir, 326 testRandomDecodeAfterClearFrameBufferCache(&createDecoder,
406 "animated-10color.gif"); 327 concatDirAndFile(layoutTestResourcesDir, "animated-10color.gif"));
407 } 328 }
408 329
409 TEST(GIFImageDecoderTest, resumePartialDecodeAfterClearFrameBufferCache) { 330 TEST(GIFImageDecoderTest, resumePartialDecodeAfterClearFrameBufferCache) {
410 RefPtr<SharedBuffer> fullData = 331 RefPtr<SharedBuffer> fullData =
411 readFile(layoutTestResourcesDir, "animated-10color.gif"); 332 readFile(layoutTestResourcesDir, "animated-10color.gif");
412 ASSERT_TRUE(fullData.get()); 333 ASSERT_TRUE(fullData.get());
413 Vector<unsigned> baselineHashes; 334 Vector<unsigned> baselineHashes;
414 createDecodingBaseline(&createDecoder, fullData.get(), &baselineHashes); 335 createDecodingBaseline(&createDecoder, fullData.get(), &baselineHashes);
415 size_t frameCount = baselineHashes.size(); 336 size_t frameCount = baselineHashes.size();
416 337
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 frameSize = decoder->decodedSize(); 426 frameSize = decoder->decodedSize();
506 continue; 427 continue;
507 } 428 }
508 429
509 ASSERT_EQ(frameSize.width(), decoder->decodedSize().width()); 430 ASSERT_EQ(frameSize.width(), decoder->decodedSize().width());
510 ASSERT_EQ(frameSize.height(), decoder->decodedSize().height()); 431 ASSERT_EQ(frameSize.height(), decoder->decodedSize().height());
511 } 432 }
512 } 433 }
513 434
514 TEST(GIFImageDecoderTest, verifyRepetitionCount) { 435 TEST(GIFImageDecoderTest, verifyRepetitionCount) {
515 const int expectedRepetitionCount = 2; 436 testRepetitionCount(layoutTestResourcesDir, "full2loop.gif", 2);
516 std::unique_ptr<ImageDecoder> decoder = createDecoder(); 437 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 } 438 }
531 439
532 TEST(GIFImageDecoderTest, bitmapAlphaType) { 440 TEST(GIFImageDecoderTest, bitmapAlphaType) {
533 RefPtr<SharedBuffer> fullData = readFile(decodersTestingDir, "radient.gif"); 441 RefPtr<SharedBuffer> fullData = readFile(decodersTestingDir, "radient.gif");
534 ASSERT_TRUE(fullData.get()); 442 ASSERT_TRUE(fullData.get());
535 443
536 // Empirically chosen truncation size: 444 // Empirically chosen truncation size:
537 // a) large enough to produce a partial frame && 445 // a) large enough to produce a partial frame &&
538 // b) small enough to not fully decode the frame 446 // b) small enough to not fully decode the frame
539 const size_t kTruncateSize = 800; 447 const size_t kTruncateSize = 800;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 EXPECT_TRUE(premulFrame && 481 EXPECT_TRUE(premulFrame &&
574 premulFrame->getStatus() == ImageFrame::FrameComplete); 482 premulFrame->getStatus() == ImageFrame::FrameComplete);
575 EXPECT_EQ(premulFrame->bitmap().alphaType(), kOpaque_SkAlphaType); 483 EXPECT_EQ(premulFrame->bitmap().alphaType(), kOpaque_SkAlphaType);
576 unpremulFrame = unpremulDecoder->frameBufferAtIndex(0); 484 unpremulFrame = unpremulDecoder->frameBufferAtIndex(0);
577 EXPECT_TRUE(unpremulFrame && 485 EXPECT_TRUE(unpremulFrame &&
578 unpremulFrame->getStatus() == ImageFrame::FrameComplete); 486 unpremulFrame->getStatus() == ImageFrame::FrameComplete);
579 EXPECT_EQ(unpremulFrame->bitmap().alphaType(), kOpaque_SkAlphaType); 487 EXPECT_EQ(unpremulFrame->bitmap().alphaType(), kOpaque_SkAlphaType);
580 } 488 }
581 489
582 } // namespace blink 490 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698