OLD | NEW |
---|---|
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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
52 ImageDecoder::noDecodedImageByteLimit)); | 52 ImageDecoder::noDecodedImageByteLimit)); |
53 } | 53 } |
54 | 54 |
55 void testRepetitionCount(const char* dir, | 55 void testRepetitionCount(const char* dir, |
56 const char* file, | 56 const char* file, |
57 int expectedRepetitionCount) { | 57 int expectedRepetitionCount) { |
58 std::unique_ptr<ImageDecoder> decoder = createDecoder(); | 58 std::unique_ptr<ImageDecoder> decoder = createDecoder(); |
59 RefPtr<SharedBuffer> data = readFile(dir, file); | 59 RefPtr<SharedBuffer> data = readFile(dir, file); |
60 ASSERT_TRUE(data.get()); | 60 ASSERT_TRUE(data.get()); |
61 decoder->setData(data.get(), true); | 61 decoder->setData(data.get(), true); |
62 EXPECT_EQ(cAnimationLoopOnce, | 62 EXPECT_EQ(expectedRepetitionCount, decoder->repetitionCount()); |
63 decoder->repetitionCount()); // Default value before decode. | |
64 | |
65 for (size_t i = 0; i < decoder->frameCount(); ++i) { | |
66 ImageFrame* frame = decoder->frameBufferAtIndex(i); | |
67 EXPECT_EQ(ImageFrame::FrameComplete, frame->getStatus()); | |
68 } | |
69 | |
70 EXPECT_EQ(expectedRepetitionCount, | |
71 decoder->repetitionCount()); // Expected value after decode. | |
72 } | 63 } |
73 | 64 |
74 } // anonymous namespace | 65 } // anonymous namespace |
75 | 66 |
76 TEST(GIFImageDecoderTest, decodeTwoFrames) { | 67 TEST(GIFImageDecoderTest, decodeTwoFrames) { |
77 std::unique_ptr<ImageDecoder> decoder = createDecoder(); | 68 std::unique_ptr<ImageDecoder> decoder = createDecoder(); |
78 | 69 |
79 RefPtr<SharedBuffer> data = readFile(layoutTestResourcesDir, "animated.gif"); | 70 RefPtr<SharedBuffer> data = readFile(layoutTestResourcesDir, "animated.gif"); |
80 ASSERT_TRUE(data.get()); | 71 ASSERT_TRUE(data.get()); |
81 decoder->setData(data.get(), true); | 72 decoder->setData(data.get(), true); |
82 EXPECT_EQ(cAnimationLoopOnce, decoder->repetitionCount()); | |
83 | 73 |
84 ImageFrame* frame = decoder->frameBufferAtIndex(0); | 74 ImageFrame* frame = decoder->frameBufferAtIndex(0); |
85 uint32_t generationID0 = frame->bitmap().getGenerationID(); | 75 uint32_t generationID0 = frame->bitmap().getGenerationID(); |
86 EXPECT_EQ(ImageFrame::FrameComplete, frame->getStatus()); | 76 EXPECT_EQ(ImageFrame::FrameComplete, frame->getStatus()); |
87 EXPECT_EQ(16, frame->bitmap().width()); | 77 EXPECT_EQ(16, frame->bitmap().width()); |
88 EXPECT_EQ(16, frame->bitmap().height()); | 78 EXPECT_EQ(16, frame->bitmap().height()); |
89 | 79 |
90 frame = decoder->frameBufferAtIndex(1); | 80 frame = decoder->frameBufferAtIndex(1); |
91 uint32_t generationID1 = frame->bitmap().getGenerationID(); | 81 uint32_t generationID1 = frame->bitmap().getGenerationID(); |
92 EXPECT_EQ(ImageFrame::FrameComplete, frame->getStatus()); | 82 EXPECT_EQ(ImageFrame::FrameComplete, frame->getStatus()); |
93 EXPECT_EQ(16, frame->bitmap().width()); | 83 EXPECT_EQ(16, frame->bitmap().width()); |
94 EXPECT_EQ(16, frame->bitmap().height()); | 84 EXPECT_EQ(16, frame->bitmap().height()); |
95 EXPECT_TRUE(generationID0 != generationID1); | 85 EXPECT_TRUE(generationID0 != generationID1); |
96 | 86 |
97 EXPECT_EQ(2u, decoder->frameCount()); | 87 EXPECT_EQ(2u, decoder->frameCount()); |
98 EXPECT_EQ(cAnimationLoopInfinite, decoder->repetitionCount()); | 88 EXPECT_EQ(cAnimationLoopInfinite, decoder->repetitionCount()); |
99 } | 89 } |
100 | 90 |
101 TEST(GIFImageDecoderTest, parseAndDecode) { | 91 TEST(GIFImageDecoderTest, parseAndDecode) { |
102 std::unique_ptr<ImageDecoder> decoder = createDecoder(); | 92 std::unique_ptr<ImageDecoder> decoder = createDecoder(); |
103 | 93 |
104 RefPtr<SharedBuffer> data = readFile(layoutTestResourcesDir, "animated.gif"); | 94 RefPtr<SharedBuffer> data = readFile(layoutTestResourcesDir, "animated.gif"); |
105 ASSERT_TRUE(data.get()); | 95 ASSERT_TRUE(data.get()); |
106 decoder->setData(data.get(), true); | 96 decoder->setData(data.get(), true); |
107 EXPECT_EQ(cAnimationLoopOnce, decoder->repetitionCount()); | |
108 | |
109 // This call will parse the entire file. | |
110 EXPECT_EQ(2u, decoder->frameCount()); | |
111 | 97 |
112 ImageFrame* frame = decoder->frameBufferAtIndex(0); | 98 ImageFrame* frame = decoder->frameBufferAtIndex(0); |
113 EXPECT_EQ(ImageFrame::FrameComplete, frame->getStatus()); | 99 EXPECT_EQ(ImageFrame::FrameComplete, frame->getStatus()); |
114 EXPECT_EQ(16, frame->bitmap().width()); | 100 EXPECT_EQ(16, frame->bitmap().width()); |
115 EXPECT_EQ(16, frame->bitmap().height()); | 101 EXPECT_EQ(16, frame->bitmap().height()); |
116 | 102 |
117 frame = decoder->frameBufferAtIndex(1); | 103 frame = decoder->frameBufferAtIndex(1); |
118 EXPECT_EQ(ImageFrame::FrameComplete, frame->getStatus()); | 104 EXPECT_EQ(ImageFrame::FrameComplete, frame->getStatus()); |
119 EXPECT_EQ(16, frame->bitmap().width()); | 105 EXPECT_EQ(16, frame->bitmap().width()); |
120 EXPECT_EQ(16, frame->bitmap().height()); | 106 EXPECT_EQ(16, frame->bitmap().height()); |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
300 RefPtr<SharedBuffer> testData = readFile(decodersTestingDir, "bad-code.gif"); | 286 RefPtr<SharedBuffer> testData = readFile(decodersTestingDir, "bad-code.gif"); |
301 ASSERT_TRUE(testData.get()); | 287 ASSERT_TRUE(testData.get()); |
302 | 288 |
303 std::unique_ptr<ImageDecoder> testDecoder = createDecoder(); | 289 std::unique_ptr<ImageDecoder> testDecoder = createDecoder(); |
304 testDecoder->setData(testData.get(), true); | 290 testDecoder->setData(testData.get(), true); |
305 EXPECT_EQ(1u, testDecoder->frameCount()); | 291 EXPECT_EQ(1u, testDecoder->frameCount()); |
306 ASSERT_TRUE(testDecoder->frameBufferAtIndex(0)); | 292 ASSERT_TRUE(testDecoder->frameBufferAtIndex(0)); |
307 EXPECT_TRUE(testDecoder->failed()); | 293 EXPECT_TRUE(testDecoder->failed()); |
308 } | 294 } |
309 | 295 |
310 TEST(GIFImageDecoderTest, invalidDisposalMethod) { | |
311 std::unique_ptr<ImageDecoder> decoder = createDecoder(); | |
312 | |
313 // The image has 2 frames, with disposal method 4 and 5, respectively. | |
314 RefPtr<SharedBuffer> data = | |
315 readFile(decodersTestingDir, "invalid-disposal-method.gif"); | |
316 ASSERT_TRUE(data.get()); | |
317 decoder->setData(data.get(), true); | |
318 | |
319 EXPECT_EQ(2u, decoder->frameCount()); | |
320 // Disposal method 4 is converted to ImageFrame::DisposeOverwritePrevious. | |
321 EXPECT_EQ(ImageFrame::DisposeOverwritePrevious, | |
322 decoder->frameBufferAtIndex(0)->getDisposalMethod()); | |
323 // Disposal method 5 is ignored. | |
324 EXPECT_EQ(ImageFrame::DisposeNotSpecified, | |
325 decoder->frameBufferAtIndex(1)->getDisposalMethod()); | |
326 } | |
327 | |
328 TEST(GIFImageDecoderTest, firstFrameHasGreaterSizeThanScreenSize) { | 296 TEST(GIFImageDecoderTest, firstFrameHasGreaterSizeThanScreenSize) { |
329 RefPtr<SharedBuffer> fullData = readFile( | 297 RefPtr<SharedBuffer> fullData = readFile( |
330 decodersTestingDir, "first-frame-has-greater-size-than-screen-size.gif"); | 298 decodersTestingDir, "first-frame-has-greater-size-than-screen-size.gif"); |
331 ASSERT_TRUE(fullData.get()); | 299 ASSERT_TRUE(fullData.get()); |
332 | 300 |
333 std::unique_ptr<ImageDecoder> decoder; | 301 std::unique_ptr<ImageDecoder> decoder; |
334 IntSize frameSize; | 302 IntSize frameSize; |
335 | 303 |
336 // Compute hashes when the file is truncated. | 304 // Compute hashes when the file is truncated. |
337 for (size_t i = 1; i <= fullData->size(); ++i) { | 305 for (size_t i = 1; i <= fullData->size(); ++i) { |
(...skipping 14 matching lines...) Expand all Loading... | |
352 | 320 |
353 TEST(GIFImageDecoderTest, verifyRepetitionCount) { | 321 TEST(GIFImageDecoderTest, verifyRepetitionCount) { |
354 testRepetitionCount(layoutTestResourcesDir, "full2loop.gif", 2); | 322 testRepetitionCount(layoutTestResourcesDir, "full2loop.gif", 2); |
355 testRepetitionCount(decodersTestingDir, "radient.gif", cAnimationNone); | 323 testRepetitionCount(decodersTestingDir, "radient.gif", cAnimationNone); |
356 } | 324 } |
357 | 325 |
358 TEST(GIFImageDecoderTest, bitmapAlphaType) { | 326 TEST(GIFImageDecoderTest, bitmapAlphaType) { |
359 RefPtr<SharedBuffer> fullData = readFile(decodersTestingDir, "radient.gif"); | 327 RefPtr<SharedBuffer> fullData = readFile(decodersTestingDir, "radient.gif"); |
360 ASSERT_TRUE(fullData.get()); | 328 ASSERT_TRUE(fullData.get()); |
361 | 329 |
362 // Empirically chosen truncation size: | |
363 // a) large enough to produce a partial frame && | |
364 // b) small enough to not fully decode the frame | |
365 const size_t kTruncateSize = 800; | |
366 ASSERT_TRUE(kTruncateSize < fullData->size()); | |
367 RefPtr<SharedBuffer> partialData = | |
368 SharedBuffer::create(fullData->data(), kTruncateSize); | |
369 | |
370 std::unique_ptr<ImageDecoder> premulDecoder = WTF::wrapUnique( | 330 std::unique_ptr<ImageDecoder> premulDecoder = WTF::wrapUnique( |
371 new GIFImageDecoder(ImageDecoder::AlphaPremultiplied, | 331 new GIFImageDecoder(ImageDecoder::AlphaPremultiplied, |
372 ColorBehavior::transformToTargetForTesting(), | 332 ColorBehavior::transformToTargetForTesting(), |
373 ImageDecoder::noDecodedImageByteLimit)); | 333 ImageDecoder::noDecodedImageByteLimit)); |
374 std::unique_ptr<ImageDecoder> unpremulDecoder = WTF::wrapUnique( | 334 std::unique_ptr<ImageDecoder> unpremulDecoder = WTF::wrapUnique( |
375 new GIFImageDecoder(ImageDecoder::AlphaNotPremultiplied, | 335 new GIFImageDecoder(ImageDecoder::AlphaNotPremultiplied, |
376 ColorBehavior::transformToTargetForTesting(), | 336 ColorBehavior::transformToTargetForTesting(), |
377 ImageDecoder::noDecodedImageByteLimit)); | 337 ImageDecoder::noDecodedImageByteLimit)); |
378 | 338 |
379 // Partially decoded frame => the frame alpha type is unknown and should | |
380 // reflect the requested format. | |
381 premulDecoder->setData(partialData.get(), false); | |
382 ASSERT_TRUE(premulDecoder->frameCount()); | |
383 unpremulDecoder->setData(partialData.get(), false); | |
384 ASSERT_TRUE(unpremulDecoder->frameCount()); | |
385 ImageFrame* premulFrame = premulDecoder->frameBufferAtIndex(0); | |
386 EXPECT_TRUE(premulFrame && | |
387 premulFrame->getStatus() != ImageFrame::FrameComplete); | |
388 EXPECT_EQ(premulFrame->bitmap().alphaType(), kPremul_SkAlphaType); | |
389 ImageFrame* unpremulFrame = unpremulDecoder->frameBufferAtIndex(0); | |
390 EXPECT_TRUE(unpremulFrame && | |
391 unpremulFrame->getStatus() != ImageFrame::FrameComplete); | |
392 EXPECT_EQ(unpremulFrame->bitmap().alphaType(), kUnpremul_SkAlphaType); | |
393 | |
394 // Fully decoded frame => the frame alpha type is known (opaque). | |
395 premulDecoder->setData(fullData.get(), true); | 339 premulDecoder->setData(fullData.get(), true); |
396 ASSERT_TRUE(premulDecoder->frameCount()); | 340 ASSERT_TRUE(premulDecoder->frameCount()); |
397 unpremulDecoder->setData(fullData.get(), true); | 341 unpremulDecoder->setData(fullData.get(), true); |
398 ASSERT_TRUE(unpremulDecoder->frameCount()); | 342 ASSERT_TRUE(unpremulDecoder->frameCount()); |
399 premulFrame = premulDecoder->frameBufferAtIndex(0); | 343 ImageFrame* premulFrame = premulDecoder->frameBufferAtIndex(0); |
400 EXPECT_TRUE(premulFrame && | 344 EXPECT_TRUE(premulFrame && |
401 premulFrame->getStatus() == ImageFrame::FrameComplete); | 345 premulFrame->getStatus() == ImageFrame::FrameComplete); |
402 EXPECT_EQ(premulFrame->bitmap().alphaType(), kOpaque_SkAlphaType); | 346 EXPECT_EQ(premulFrame->bitmap().alphaType(), kPremul_SkAlphaType); |
msarett1
2017/03/07 13:27:18
I don't think radient.gif is one of those edge cas
cblume
2017/03/07 19:36:29
You are right.
radient.gif is only marked as trans
scroggo_chromium
2017/03/07 21:35:08
That sounds reasonable to me.
scroggo_chromium
2017/03/07 22:06:14
Oh yeah - we already do report whether the first f
| |
403 unpremulFrame = unpremulDecoder->frameBufferAtIndex(0); | 347 ImageFrame* unpremulFrame = unpremulDecoder->frameBufferAtIndex(0); |
404 EXPECT_TRUE(unpremulFrame && | 348 EXPECT_TRUE(unpremulFrame && |
405 unpremulFrame->getStatus() == ImageFrame::FrameComplete); | 349 unpremulFrame->getStatus() == ImageFrame::FrameComplete); |
406 EXPECT_EQ(unpremulFrame->bitmap().alphaType(), kOpaque_SkAlphaType); | 350 EXPECT_EQ(unpremulFrame->bitmap().alphaType(), kUnpremul_SkAlphaType); |
407 } | 351 } |
408 | 352 |
409 } // namespace blink | 353 } // namespace blink |
OLD | NEW |