| 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 TEST(JPEGImageDecoderTest, tooBig) { | 135 TEST(JPEGImageDecoderTest, tooBig) { |
| 136 std::unique_ptr<ImageDecoder> decoder = createDecoder(100); | 136 std::unique_ptr<ImageDecoder> decoder = createDecoder(100); |
| 137 EXPECT_FALSE(decoder->setSize(10000, 10000)); | 137 EXPECT_FALSE(decoder->setSize(10000, 10000)); |
| 138 EXPECT_TRUE(decoder->failed()); | 138 EXPECT_TRUE(decoder->failed()); |
| 139 } | 139 } |
| 140 | 140 |
| 141 // Tests that the JPEG decoder can downsample image whose width and height are | 141 // Tests that the JPEG decoder can downsample image whose width and height are |
| 142 // multiples of 8, to ensure we compute the correct decodedSize and pass correct | 142 // multiples of 8, to ensure we compute the correct decodedSize and pass correct |
| 143 // parameters to libjpeg to output the image with the expected size. | 143 // parameters to libjpeg to output the image with the expected size. |
| 144 TEST(JPEGImageDecoderTest, downsampleImageSizeMultipleOf8) { | 144 TEST(JPEGImageDecoderTest, downsampleImageSizeMultipleOf8) { |
| 145 const char* jpegFile = | 145 const char* jpegFile = "/LayoutTests/images/resources/lenna.jpg"; // 256x256 |
| 146 "/LayoutTests/fast/images/resources/lenna.jpg"; // 256x256 | |
| 147 unsigned outputWidth, outputHeight; | 146 unsigned outputWidth, outputHeight; |
| 148 | 147 |
| 149 // 1/8 downsample. | 148 // 1/8 downsample. |
| 150 downsample(40 * 40 * 4, &outputWidth, &outputHeight, jpegFile); | 149 downsample(40 * 40 * 4, &outputWidth, &outputHeight, jpegFile); |
| 151 EXPECT_EQ(32u, outputWidth); | 150 EXPECT_EQ(32u, outputWidth); |
| 152 EXPECT_EQ(32u, outputHeight); | 151 EXPECT_EQ(32u, outputHeight); |
| 153 | 152 |
| 154 // 2/8 downsample. | 153 // 2/8 downsample. |
| 155 downsample(70 * 70 * 4, &outputWidth, &outputHeight, jpegFile); | 154 downsample(70 * 70 * 4, &outputWidth, &outputHeight, jpegFile); |
| 156 EXPECT_EQ(64u, outputWidth); | 155 EXPECT_EQ(64u, outputWidth); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 179 // 7/8 downsample. | 178 // 7/8 downsample. |
| 180 downsample(230 * 230 * 4, &outputWidth, &outputHeight, jpegFile); | 179 downsample(230 * 230 * 4, &outputWidth, &outputHeight, jpegFile); |
| 181 EXPECT_EQ(224u, outputWidth); | 180 EXPECT_EQ(224u, outputWidth); |
| 182 EXPECT_EQ(224u, outputHeight); | 181 EXPECT_EQ(224u, outputHeight); |
| 183 } | 182 } |
| 184 | 183 |
| 185 // Tests that JPEG decoder can downsample image whose width and height are not | 184 // Tests that JPEG decoder can downsample image whose width and height are not |
| 186 // multiple of 8. Ensures that we round using the same algorithm as libjpeg. | 185 // multiple of 8. Ensures that we round using the same algorithm as libjpeg. |
| 187 TEST(JPEGImageDecoderTest, downsampleImageSizeNotMultipleOf8) { | 186 TEST(JPEGImageDecoderTest, downsampleImageSizeNotMultipleOf8) { |
| 188 const char* jpegFile = | 187 const char* jpegFile = |
| 189 "/LayoutTests/fast/images/resources/icc-v2-gbr.jpg"; // 275x207 | 188 "/LayoutTests/images/resources/icc-v2-gbr.jpg"; // 275x207 |
| 190 unsigned outputWidth, outputHeight; | 189 unsigned outputWidth, outputHeight; |
| 191 | 190 |
| 192 // 1/8 downsample. | 191 // 1/8 downsample. |
| 193 downsample(40 * 40 * 4, &outputWidth, &outputHeight, jpegFile); | 192 downsample(40 * 40 * 4, &outputWidth, &outputHeight, jpegFile); |
| 194 EXPECT_EQ(35u, outputWidth); | 193 EXPECT_EQ(35u, outputWidth); |
| 195 EXPECT_EQ(26u, outputHeight); | 194 EXPECT_EQ(26u, outputHeight); |
| 196 | 195 |
| 197 // 2/8 downsample. | 196 // 2/8 downsample. |
| 198 downsample(70 * 70 * 4, &outputWidth, &outputHeight, jpegFile); | 197 downsample(70 * 70 * 4, &outputWidth, &outputHeight, jpegFile); |
| 199 EXPECT_EQ(69u, outputWidth); | 198 EXPECT_EQ(69u, outputWidth); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 220 EXPECT_EQ(156u, outputHeight); | 219 EXPECT_EQ(156u, outputHeight); |
| 221 | 220 |
| 222 // 7/8 downsample. | 221 // 7/8 downsample. |
| 223 downsample(230 * 230 * 4, &outputWidth, &outputHeight, jpegFile); | 222 downsample(230 * 230 * 4, &outputWidth, &outputHeight, jpegFile); |
| 224 EXPECT_EQ(241u, outputWidth); | 223 EXPECT_EQ(241u, outputWidth); |
| 225 EXPECT_EQ(182u, outputHeight); | 224 EXPECT_EQ(182u, outputHeight); |
| 226 } | 225 } |
| 227 | 226 |
| 228 // Tests that upsampling is not allowed. | 227 // Tests that upsampling is not allowed. |
| 229 TEST(JPEGImageDecoderTest, upsample) { | 228 TEST(JPEGImageDecoderTest, upsample) { |
| 230 const char* jpegFile = | 229 const char* jpegFile = "/LayoutTests/images/resources/lenna.jpg"; // 256x256 |
| 231 "/LayoutTests/fast/images/resources/lenna.jpg"; // 256x256 | |
| 232 unsigned outputWidth, outputHeight; | 230 unsigned outputWidth, outputHeight; |
| 233 downsample(LargeEnoughSize, &outputWidth, &outputHeight, jpegFile); | 231 downsample(LargeEnoughSize, &outputWidth, &outputHeight, jpegFile); |
| 234 EXPECT_EQ(256u, outputWidth); | 232 EXPECT_EQ(256u, outputWidth); |
| 235 EXPECT_EQ(256u, outputHeight); | 233 EXPECT_EQ(256u, outputHeight); |
| 236 } | 234 } |
| 237 | 235 |
| 238 TEST(JPEGImageDecoderTest, yuv) { | 236 TEST(JPEGImageDecoderTest, yuv) { |
| 239 const char* jpegFile = | 237 const char* jpegFile = |
| 240 "/LayoutTests/fast/images/resources/lenna.jpg"; // 256x256, YUV 4:2:0 | 238 "/LayoutTests/images/resources/lenna.jpg"; // 256x256, YUV 4:2:0 |
| 241 unsigned outputYWidth, outputYHeight, outputUVWidth, outputUVHeight; | 239 unsigned outputYWidth, outputYHeight, outputUVWidth, outputUVHeight; |
| 242 readYUV(LargeEnoughSize, &outputYWidth, &outputYHeight, &outputUVWidth, | 240 readYUV(LargeEnoughSize, &outputYWidth, &outputYHeight, &outputUVWidth, |
| 243 &outputUVHeight, jpegFile); | 241 &outputUVHeight, jpegFile); |
| 244 EXPECT_EQ(256u, outputYWidth); | 242 EXPECT_EQ(256u, outputYWidth); |
| 245 EXPECT_EQ(256u, outputYHeight); | 243 EXPECT_EQ(256u, outputYHeight); |
| 246 EXPECT_EQ(128u, outputUVWidth); | 244 EXPECT_EQ(128u, outputUVWidth); |
| 247 EXPECT_EQ(128u, outputUVHeight); | 245 EXPECT_EQ(128u, outputUVHeight); |
| 248 | 246 |
| 249 const char* jpegFileImageSizeNotMultipleOf8 = | 247 const char* jpegFileImageSizeNotMultipleOf8 = |
| 250 "/LayoutTests/fast/images/resources/cropped_mandrill.jpg"; // 439x154 | 248 "/LayoutTests/images/resources/cropped_mandrill.jpg"; // 439x154 |
| 251 readYUV(LargeEnoughSize, &outputYWidth, &outputYHeight, &outputUVWidth, | 249 readYUV(LargeEnoughSize, &outputYWidth, &outputYHeight, &outputUVWidth, |
| 252 &outputUVHeight, jpegFileImageSizeNotMultipleOf8); | 250 &outputUVHeight, jpegFileImageSizeNotMultipleOf8); |
| 253 EXPECT_EQ(439u, outputYWidth); | 251 EXPECT_EQ(439u, outputYWidth); |
| 254 EXPECT_EQ(154u, outputYHeight); | 252 EXPECT_EQ(154u, outputYHeight); |
| 255 EXPECT_EQ(220u, outputUVWidth); | 253 EXPECT_EQ(220u, outputUVWidth); |
| 256 EXPECT_EQ(77u, outputUVHeight); | 254 EXPECT_EQ(77u, outputUVHeight); |
| 257 | 255 |
| 258 // Make sure we revert to RGBA decoding when we're about to downscale, | 256 // Make sure we revert to RGBA decoding when we're about to downscale, |
| 259 // which can occur on memory-constrained android devices. | 257 // which can occur on memory-constrained android devices. |
| 260 RefPtr<SharedBuffer> data = readFile(jpegFile); | 258 RefPtr<SharedBuffer> data = readFile(jpegFile); |
| 261 ASSERT_TRUE(data); | 259 ASSERT_TRUE(data); |
| 262 | 260 |
| 263 std::unique_ptr<ImageDecoder> decoder = createDecoder(230 * 230 * 4); | 261 std::unique_ptr<ImageDecoder> decoder = createDecoder(230 * 230 * 4); |
| 264 decoder->setData(data.get(), true); | 262 decoder->setData(data.get(), true); |
| 265 | 263 |
| 266 std::unique_ptr<ImagePlanes> imagePlanes = wrapUnique(new ImagePlanes()); | 264 std::unique_ptr<ImagePlanes> imagePlanes = wrapUnique(new ImagePlanes()); |
| 267 decoder->setImagePlanes(std::move(imagePlanes)); | 265 decoder->setImagePlanes(std::move(imagePlanes)); |
| 268 ASSERT_TRUE(decoder->isSizeAvailable()); | 266 ASSERT_TRUE(decoder->isSizeAvailable()); |
| 269 ASSERT_FALSE(decoder->canDecodeToYUV()); | 267 ASSERT_FALSE(decoder->canDecodeToYUV()); |
| 270 } | 268 } |
| 271 | 269 |
| 272 TEST(JPEGImageDecoderTest, | 270 TEST(JPEGImageDecoderTest, |
| 273 byteByByteBaselineJPEGWithColorProfileAndRestartMarkers) { | 271 byteByByteBaselineJPEGWithColorProfileAndRestartMarkers) { |
| 274 testByteByByteDecode(&createDecoder, | 272 testByteByByteDecode(&createDecoder, |
| 275 "/LayoutTests/fast/images/resources/" | 273 "/LayoutTests/images/resources/" |
| 276 "small-square-with-colorspin-profile.jpg", | 274 "small-square-with-colorspin-profile.jpg", |
| 277 1u, cAnimationNone); | 275 1u, cAnimationNone); |
| 278 } | 276 } |
| 279 | 277 |
| 280 TEST(JPEGImageDecoderTest, byteByByteProgressiveJPEG) { | 278 TEST(JPEGImageDecoderTest, byteByByteProgressiveJPEG) { |
| 281 testByteByByteDecode(&createDecoder, | 279 testByteByByteDecode(&createDecoder, |
| 282 "/LayoutTests/fast/images/resources/bug106024.jpg", 1u, | 280 "/LayoutTests/images/resources/bug106024.jpg", 1u, |
| 283 cAnimationNone); | 281 cAnimationNone); |
| 284 } | 282 } |
| 285 | 283 |
| 286 TEST(JPEGImageDecoderTest, byteByByteRGBJPEGWithAdobeMarkers) { | 284 TEST(JPEGImageDecoderTest, byteByByteRGBJPEGWithAdobeMarkers) { |
| 287 testByteByByteDecode( | 285 testByteByByteDecode( |
| 288 &createDecoder, | 286 &createDecoder, |
| 289 "/LayoutTests/fast/images/resources/rgb-jpeg-with-adobe-marker-only.jpg", | 287 "/LayoutTests/images/resources/rgb-jpeg-with-adobe-marker-only.jpg", 1u, |
| 290 1u, cAnimationNone); | 288 cAnimationNone); |
| 291 } | 289 } |
| 292 | 290 |
| 293 // This test verifies that calling SharedBuffer::mergeSegmentsIntoBuffer() does | 291 // This test verifies that calling SharedBuffer::mergeSegmentsIntoBuffer() does |
| 294 // not break JPEG decoding at a critical point: in between a call to decode the | 292 // not break JPEG decoding at a critical point: in between a call to decode the |
| 295 // size (when JPEGImageDecoder stops while it may still have input data to | 293 // size (when JPEGImageDecoder stops while it may still have input data to |
| 296 // read) and a call to do a full decode. | 294 // read) and a call to do a full decode. |
| 297 TEST(JPEGImageDecoderTest, mergeBuffer) { | 295 TEST(JPEGImageDecoderTest, mergeBuffer) { |
| 298 const char* jpegFile = "/LayoutTests/fast/images/resources/lenna.jpg"; | 296 const char* jpegFile = "/LayoutTests/images/resources/lenna.jpg"; |
| 299 testMergeBuffer(&createDecoder, jpegFile); | 297 testMergeBuffer(&createDecoder, jpegFile); |
| 300 } | 298 } |
| 301 | 299 |
| 302 // This tests decoding a JPEG with many progressive scans. Decoding should | 300 // This tests decoding a JPEG with many progressive scans. Decoding should |
| 303 // fail, but not hang (crbug.com/642462). | 301 // fail, but not hang (crbug.com/642462). |
| 304 TEST(JPEGImageDecoderTest, manyProgressiveScans) { | 302 TEST(JPEGImageDecoderTest, manyProgressiveScans) { |
| 305 RefPtr<SharedBuffer> testData = | 303 RefPtr<SharedBuffer> testData = |
| 306 readFile(decodersTestingDir, "many-progressive-scans.jpg"); | 304 readFile(decodersTestingDir, "many-progressive-scans.jpg"); |
| 307 ASSERT_TRUE(testData.get()); | 305 ASSERT_TRUE(testData.get()); |
| 308 | 306 |
| 309 std::unique_ptr<ImageDecoder> testDecoder = createDecoder(); | 307 std::unique_ptr<ImageDecoder> testDecoder = createDecoder(); |
| 310 testDecoder->setData(testData.get(), true); | 308 testDecoder->setData(testData.get(), true); |
| 311 EXPECT_EQ(1u, testDecoder->frameCount()); | 309 EXPECT_EQ(1u, testDecoder->frameCount()); |
| 312 ASSERT_TRUE(testDecoder->frameBufferAtIndex(0)); | 310 ASSERT_TRUE(testDecoder->frameBufferAtIndex(0)); |
| 313 EXPECT_TRUE(testDecoder->failed()); | 311 EXPECT_TRUE(testDecoder->failed()); |
| 314 } | 312 } |
| 315 | 313 |
| 316 } // namespace blink | 314 } // namespace blink |
| OLD | NEW |