| 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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 | 135 |
| 136 void testByteByByteSizeAvailable(const char* webpFile, | 136 void testByteByByteSizeAvailable(const char* webpFile, |
| 137 size_t frameOffset, | 137 size_t frameOffset, |
| 138 bool hasColorProfile, | 138 bool hasColorProfile, |
| 139 int expectedRepetitionCount) { | 139 int expectedRepetitionCount) { |
| 140 std::unique_ptr<ImageDecoder> decoder = createDecoder(); | 140 std::unique_ptr<ImageDecoder> decoder = createDecoder(); |
| 141 RefPtr<SharedBuffer> data = readFile(webpFile); | 141 RefPtr<SharedBuffer> data = readFile(webpFile); |
| 142 ASSERT_TRUE(data.get()); | 142 ASSERT_TRUE(data.get()); |
| 143 EXPECT_LT(frameOffset, data->size()); | 143 EXPECT_LT(frameOffset, data->size()); |
| 144 | 144 |
| 145 // Send data to the decoder byte-by-byte and use the provided frame offset in
the data to check | 145 // Send data to the decoder byte-by-byte and use the provided frame offset in |
| 146 // isSizeAvailable() changes state only when that offset is reached, and the a
ssociated decoder | 146 // the data to check that isSizeAvailable() changes state only when that |
| 147 // state also: size, colorProfile, frameCount, repetitionCount ... | 147 // offset is reached. Also check other decoder state. |
| 148 | |
| 149 for (size_t length = 1; length <= frameOffset; ++length) { | 148 for (size_t length = 1; length <= frameOffset; ++length) { |
| 150 RefPtr<SharedBuffer> tempData = SharedBuffer::create(data->data(), length); | 149 RefPtr<SharedBuffer> tempData = SharedBuffer::create(data->data(), length); |
| 151 decoder->setData(tempData.get(), false); | 150 decoder->setData(tempData.get(), false); |
| 152 | 151 |
| 153 if (length < frameOffset) { | 152 if (length < frameOffset) { |
| 154 EXPECT_FALSE(decoder->isSizeAvailable()); | 153 EXPECT_FALSE(decoder->isSizeAvailable()); |
| 155 EXPECT_TRUE(decoder->size().isEmpty()); | 154 EXPECT_TRUE(decoder->size().isEmpty()); |
| 156 EXPECT_FALSE(decoder->hasColorProfile()); | 155 EXPECT_FALSE(decoder->hasColorProfile()); |
| 157 EXPECT_EQ(0u, decoder->frameCount()); | 156 EXPECT_EQ(0u, decoder->frameCount()); |
| 158 EXPECT_EQ(cAnimationLoopOnce, decoder->repetitionCount()); | 157 EXPECT_EQ(cAnimationLoopOnce, decoder->repetitionCount()); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 maxDifference = difference; | 229 maxDifference = difference; |
| 231 } | 230 } |
| 232 } | 231 } |
| 233 } | 232 } |
| 234 | 233 |
| 235 // Pre-multiplication could round the RGBA channel values. So, we declare | 234 // Pre-multiplication could round the RGBA channel values. So, we declare |
| 236 // that the frames match if the RGBA channel values differ by at most 2. | 235 // that the frames match if the RGBA channel values differ by at most 2. |
| 237 EXPECT_GE(2, maxDifference) << webpFile; | 236 EXPECT_GE(2, maxDifference) << webpFile; |
| 238 } | 237 } |
| 239 | 238 |
| 240 // Verify that result of alpha blending is similar for AlphaPremultiplied and Al
phaNotPremultiplied cases. | 239 // Verifies that result of alpha blending is similar for AlphaPremultiplied and |
| 240 // AlphaNotPremultiplied cases. |
| 241 void testAlphaBlending(const char* webpFile) { | 241 void testAlphaBlending(const char* webpFile) { |
| 242 RefPtr<SharedBuffer> data = readFile(webpFile); | 242 RefPtr<SharedBuffer> data = readFile(webpFile); |
| 243 ASSERT_TRUE(data.get()); | 243 ASSERT_TRUE(data.get()); |
| 244 | 244 |
| 245 std::unique_ptr<ImageDecoder> decoderA = | 245 std::unique_ptr<ImageDecoder> decoderA = |
| 246 createDecoder(ImageDecoder::AlphaPremultiplied); | 246 createDecoder(ImageDecoder::AlphaPremultiplied); |
| 247 decoderA->setData(data.get(), true); | 247 decoderA->setData(data.get(), true); |
| 248 | 248 |
| 249 std::unique_ptr<ImageDecoder> decoderB = | 249 std::unique_ptr<ImageDecoder> decoderB = |
| 250 createDecoder(ImageDecoder::AlphaNotPremultiplied); | 250 createDecoder(ImageDecoder::AlphaNotPremultiplied); |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 | 473 |
| 474 ImageFrame* frame = decoder->frameBufferAtIndex(1); | 474 ImageFrame* frame = decoder->frameBufferAtIndex(1); |
| 475 ASSERT_TRUE(frame); | 475 ASSERT_TRUE(frame); |
| 476 EXPECT_EQ(ImageFrame::FrameComplete, frame->getStatus()); | 476 EXPECT_EQ(ImageFrame::FrameComplete, frame->getStatus()); |
| 477 frame = decoder->frameBufferAtIndex(2); | 477 frame = decoder->frameBufferAtIndex(2); |
| 478 ASSERT_TRUE(frame); | 478 ASSERT_TRUE(frame); |
| 479 EXPECT_EQ(ImageFrame::FramePartial, frame->getStatus()); | 479 EXPECT_EQ(ImageFrame::FramePartial, frame->getStatus()); |
| 480 EXPECT_TRUE(decoder->failed()); | 480 EXPECT_TRUE(decoder->failed()); |
| 481 } | 481 } |
| 482 | 482 |
| 483 // Reproduce a crash that used to happen for a specific file with specific seque
nce of method calls. | 483 // Tests for a crash that used to happen for a specific file with specific |
| 484 // sequence of method calls. |
| 484 TEST(AnimatedWebPTests, reproCrash) { | 485 TEST(AnimatedWebPTests, reproCrash) { |
| 485 std::unique_ptr<ImageDecoder> decoder = createDecoder(); | 486 std::unique_ptr<ImageDecoder> decoder = createDecoder(); |
| 486 | 487 |
| 487 RefPtr<SharedBuffer> fullData = | 488 RefPtr<SharedBuffer> fullData = |
| 488 readFile("/LayoutTests/fast/images/resources/invalid_vp8_vp8x.webp"); | 489 readFile("/LayoutTests/fast/images/resources/invalid_vp8_vp8x.webp"); |
| 489 ASSERT_TRUE(fullData.get()); | 490 ASSERT_TRUE(fullData.get()); |
| 490 | 491 |
| 491 // Parse partial data up to which error in bitstream is not detected. | 492 // Parse partial data up to which error in bitstream is not detected. |
| 492 const size_t partialSize = 32768; | 493 const size_t partialSize = 32768; |
| 493 ASSERT_GT(fullData->size(), partialSize); | 494 ASSERT_GT(fullData->size(), partialSize); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 588 EXPECT_EQ(1000.0, decoder->frameDurationAtIndex(2)); | 589 EXPECT_EQ(1000.0, decoder->frameDurationAtIndex(2)); |
| 589 } | 590 } |
| 590 | 591 |
| 591 TEST(AnimatedWebPTests, updateRequiredPreviousFrameAfterFirstDecode) { | 592 TEST(AnimatedWebPTests, updateRequiredPreviousFrameAfterFirstDecode) { |
| 592 std::unique_ptr<ImageDecoder> decoder = createDecoder(); | 593 std::unique_ptr<ImageDecoder> decoder = createDecoder(); |
| 593 | 594 |
| 594 RefPtr<SharedBuffer> fullData = | 595 RefPtr<SharedBuffer> fullData = |
| 595 readFile("/LayoutTests/fast/images/resources/webp-animated.webp"); | 596 readFile("/LayoutTests/fast/images/resources/webp-animated.webp"); |
| 596 ASSERT_TRUE(fullData.get()); | 597 ASSERT_TRUE(fullData.get()); |
| 597 | 598 |
| 598 // Give it data that is enough to parse but not decode in order to check the s
tatus | 599 // Check the status of requiredPreviousFrameIndex before decoding, by |
| 599 // of requiredPreviousFrameIndex before decoding. | 600 // supplying data sufficient to parse but not decode. |
| 600 size_t partialSize = 1; | 601 size_t partialSize = 1; |
| 601 do { | 602 do { |
| 602 RefPtr<SharedBuffer> data = | 603 RefPtr<SharedBuffer> data = |
| 603 SharedBuffer::create(fullData->data(), partialSize); | 604 SharedBuffer::create(fullData->data(), partialSize); |
| 604 decoder->setData(data.get(), false); | 605 decoder->setData(data.get(), false); |
| 605 ++partialSize; | 606 ++partialSize; |
| 606 } while (!decoder->frameCount() || | 607 } while (!decoder->frameCount() || |
| 607 decoder->frameBufferAtIndex(0)->getStatus() == | 608 decoder->frameBufferAtIndex(0)->getStatus() == |
| 608 ImageFrame::FrameEmpty); | 609 ImageFrame::FrameEmpty); |
| 609 | 610 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 706 false, 32000); | 707 false, 32000); |
| 707 } | 708 } |
| 708 | 709 |
| 709 TEST(StaticWebPTests, truncatedImage) { | 710 TEST(StaticWebPTests, truncatedImage) { |
| 710 // VP8 data is truncated. | 711 // VP8 data is truncated. |
| 711 testInvalidImage("/LayoutTests/fast/images/resources/truncated.webp", false); | 712 testInvalidImage("/LayoutTests/fast/images/resources/truncated.webp", false); |
| 712 // Chunk size in RIFF header doesn't match the file size. | 713 // Chunk size in RIFF header doesn't match the file size. |
| 713 testInvalidImage("/LayoutTests/fast/images/resources/truncated2.webp", true); | 714 testInvalidImage("/LayoutTests/fast/images/resources/truncated2.webp", true); |
| 714 } | 715 } |
| 715 | 716 |
| 717 // Regression test for a bug where some valid images were failing to decode |
| 718 // incrementally. |
| 716 TEST(StaticWebPTests, incrementalDecode) { | 719 TEST(StaticWebPTests, incrementalDecode) { |
| 717 // Regression test for a bug where some valid images were failing to decode in
crementally. | |
| 718 testByteByByteDecode(&createDecoder, | 720 testByteByByteDecode(&createDecoder, |
| 719 "/LayoutTests/fast/images/resources/crbug.364830.webp", | 721 "/LayoutTests/fast/images/resources/crbug.364830.webp", |
| 720 1u, cAnimationNone); | 722 1u, cAnimationNone); |
| 721 } | 723 } |
| 722 | 724 |
| 723 TEST(StaticWebPTests, isSizeAvailable) { | 725 TEST(StaticWebPTests, isSizeAvailable) { |
| 724 testByteByByteSizeAvailable( | 726 testByteByByteSizeAvailable( |
| 725 "/LayoutTests/fast/images/resources/webp-color-profile-lossy.webp", 520u, | 727 "/LayoutTests/fast/images/resources/webp-color-profile-lossy.webp", 520u, |
| 726 true, cAnimationNone); | 728 true, cAnimationNone); |
| 727 testByteByByteSizeAvailable("/LayoutTests/fast/images/resources/test.webp", | 729 testByteByByteSizeAvailable("/LayoutTests/fast/images/resources/test.webp", |
| 728 30u, false, cAnimationNone); | 730 30u, false, cAnimationNone); |
| 729 } | 731 } |
| 730 | 732 |
| 731 TEST(StaticWebPTests, notAnimated) { | 733 TEST(StaticWebPTests, notAnimated) { |
| 732 std::unique_ptr<ImageDecoder> decoder = createDecoder(); | 734 std::unique_ptr<ImageDecoder> decoder = createDecoder(); |
| 733 RefPtr<SharedBuffer> data = readFile( | 735 RefPtr<SharedBuffer> data = readFile( |
| 734 "/LayoutTests/fast/images/resources/webp-color-profile-lossy.webp"); | 736 "/LayoutTests/fast/images/resources/webp-color-profile-lossy.webp"); |
| 735 ASSERT_TRUE(data.get()); | 737 ASSERT_TRUE(data.get()); |
| 736 decoder->setData(data.get(), true); | 738 decoder->setData(data.get(), true); |
| 737 EXPECT_EQ(1u, decoder->frameCount()); | 739 EXPECT_EQ(1u, decoder->frameCount()); |
| 738 EXPECT_EQ(cAnimationNone, decoder->repetitionCount()); | 740 EXPECT_EQ(cAnimationNone, decoder->repetitionCount()); |
| 739 } | 741 } |
| 740 | 742 |
| 741 } // namespace blink | 743 } // namespace blink |
| OLD | NEW |