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 29 matching lines...) Expand all Loading... |
40 #include "wtf/Vector.h" | 40 #include "wtf/Vector.h" |
41 #include "wtf/dtoa/utils.h" | 41 #include "wtf/dtoa/utils.h" |
42 #include <memory> | 42 #include <memory> |
43 | 43 |
44 namespace blink { | 44 namespace blink { |
45 | 45 |
46 namespace { | 46 namespace { |
47 | 47 |
48 std::unique_ptr<ImageDecoder> createDecoder( | 48 std::unique_ptr<ImageDecoder> createDecoder( |
49 ImageDecoder::AlphaOption alphaOption) { | 49 ImageDecoder::AlphaOption alphaOption) { |
50 return wrapUnique(new WEBPImageDecoder( | 50 return wrapUnique( |
51 alphaOption, ImageDecoder::GammaAndColorProfileApplied, | 51 new WEBPImageDecoder(alphaOption, ImageDecoder::ColorSpaceApplied, |
52 ImageDecoder::noDecodedImageByteLimit)); | 52 ImageDecoder::noDecodedImageByteLimit)); |
53 } | 53 } |
54 | 54 |
55 std::unique_ptr<ImageDecoder> createDecoder() { | 55 std::unique_ptr<ImageDecoder> createDecoder() { |
56 return createDecoder(ImageDecoder::AlphaNotPremultiplied); | 56 return createDecoder(ImageDecoder::AlphaNotPremultiplied); |
57 } | 57 } |
58 | 58 |
59 void testRandomFrameDecode(const char* webpFile) { | 59 void testRandomFrameDecode(const char* webpFile) { |
60 SCOPED_TRACE(webpFile); | 60 SCOPED_TRACE(webpFile); |
61 | 61 |
62 RefPtr<SharedBuffer> fullData = readFile(webpFile); | 62 RefPtr<SharedBuffer> fullData = readFile(webpFile); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 decoder->setData(reallocatedData.get(), true); | 128 decoder->setData(reallocatedData.get(), true); |
129 | 129 |
130 for (size_t i = 0; i < frameCount; ++i) { | 130 for (size_t i = 0; i < frameCount; ++i) { |
131 const ImageFrame* const frame = decoder->frameBufferAtIndex(i); | 131 const ImageFrame* const frame = decoder->frameBufferAtIndex(i); |
132 EXPECT_EQ(ImageFrame::FrameComplete, frame->getStatus()); | 132 EXPECT_EQ(ImageFrame::FrameComplete, frame->getStatus()); |
133 } | 133 } |
134 } | 134 } |
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 hasColorSpace, |
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 | 145 // Send data to the decoder byte-by-byte and use the provided frame offset in |
146 // the data to check that isSizeAvailable() changes state only when that | 146 // the data to check that isSizeAvailable() changes state only when that |
147 // offset is reached. Also check other decoder state. | 147 // offset is reached. Also check other decoder state. |
148 for (size_t length = 1; length <= frameOffset; ++length) { | 148 for (size_t length = 1; length <= frameOffset; ++length) { |
149 RefPtr<SharedBuffer> tempData = SharedBuffer::create(data->data(), length); | 149 RefPtr<SharedBuffer> tempData = SharedBuffer::create(data->data(), length); |
150 decoder->setData(tempData.get(), false); | 150 decoder->setData(tempData.get(), false); |
151 | 151 |
152 if (length < frameOffset) { | 152 if (length < frameOffset) { |
153 EXPECT_FALSE(decoder->isSizeAvailable()); | 153 EXPECT_FALSE(decoder->isSizeAvailable()); |
154 EXPECT_TRUE(decoder->size().isEmpty()); | 154 EXPECT_TRUE(decoder->size().isEmpty()); |
155 EXPECT_FALSE(decoder->hasColorProfile()); | 155 EXPECT_FALSE(decoder->hasColorSpace()); |
156 EXPECT_EQ(0u, decoder->frameCount()); | 156 EXPECT_EQ(0u, decoder->frameCount()); |
157 EXPECT_EQ(cAnimationLoopOnce, decoder->repetitionCount()); | 157 EXPECT_EQ(cAnimationLoopOnce, decoder->repetitionCount()); |
158 EXPECT_FALSE(decoder->frameBufferAtIndex(0)); | 158 EXPECT_FALSE(decoder->frameBufferAtIndex(0)); |
159 } else { | 159 } else { |
160 EXPECT_TRUE(decoder->isSizeAvailable()); | 160 EXPECT_TRUE(decoder->isSizeAvailable()); |
161 EXPECT_FALSE(decoder->size().isEmpty()); | 161 EXPECT_FALSE(decoder->size().isEmpty()); |
162 if (hasColorProfile) | 162 EXPECT_EQ(decoder->hasColorSpace(), hasColorSpace); |
163 EXPECT_TRUE(decoder->hasColorProfile()); | |
164 else | |
165 EXPECT_FALSE(decoder->hasColorProfile()); | |
166 EXPECT_EQ(1u, decoder->frameCount()); | 163 EXPECT_EQ(1u, decoder->frameCount()); |
167 EXPECT_EQ(expectedRepetitionCount, decoder->repetitionCount()); | 164 EXPECT_EQ(expectedRepetitionCount, decoder->repetitionCount()); |
168 } | 165 } |
169 | 166 |
170 EXPECT_FALSE(decoder->failed()); | 167 EXPECT_FALSE(decoder->failed()); |
171 if (decoder->failed()) | 168 if (decoder->failed()) |
172 return; | 169 return; |
173 } | 170 } |
174 } | 171 } |
175 | 172 |
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
730 std::unique_ptr<ImageDecoder> decoder = createDecoder(); | 727 std::unique_ptr<ImageDecoder> decoder = createDecoder(); |
731 RefPtr<SharedBuffer> data = readFile( | 728 RefPtr<SharedBuffer> data = readFile( |
732 "/LayoutTests/fast/images/resources/webp-color-profile-lossy.webp"); | 729 "/LayoutTests/fast/images/resources/webp-color-profile-lossy.webp"); |
733 ASSERT_TRUE(data.get()); | 730 ASSERT_TRUE(data.get()); |
734 decoder->setData(data.get(), true); | 731 decoder->setData(data.get(), true); |
735 EXPECT_EQ(1u, decoder->frameCount()); | 732 EXPECT_EQ(1u, decoder->frameCount()); |
736 EXPECT_EQ(cAnimationNone, decoder->repetitionCount()); | 733 EXPECT_EQ(cAnimationNone, decoder->repetitionCount()); |
737 } | 734 } |
738 | 735 |
739 } // namespace blink | 736 } // namespace blink |
OLD | NEW |