| 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 void readYUV(size_t maxDecodedBytes, unsigned* outputYWidth, unsigned* outputYHe
ight, unsigned* outputUVWidth, unsigned* outputUVHeight, const char* imageFilePa
th) | 76 void readYUV(size_t maxDecodedBytes, unsigned* outputYWidth, unsigned* outputYHe
ight, unsigned* outputUVWidth, unsigned* outputUVHeight, const char* imageFilePa
th) |
| 77 { | 77 { |
| 78 RefPtr<SharedBuffer> data = readFile(imageFilePath); | 78 RefPtr<SharedBuffer> data = readFile(imageFilePath); |
| 79 ASSERT_TRUE(data); | 79 ASSERT_TRUE(data); |
| 80 | 80 |
| 81 OwnPtr<ImageDecoder> decoder = createDecoder(maxDecodedBytes); | 81 OwnPtr<ImageDecoder> decoder = createDecoder(maxDecodedBytes); |
| 82 decoder->setData(data.get(), true); | 82 decoder->setData(data.get(), true); |
| 83 | 83 |
| 84 // Setting a dummy ImagePlanes object signals to the decoder that we want to
do YUV decoding. | 84 // Setting a dummy ImagePlanes object signals to the decoder that we want to
do YUV decoding. |
| 85 OwnPtr<ImagePlanes> dummyImagePlanes = adoptPtr(new ImagePlanes()); | 85 OwnPtr<ImagePlanes> dummyImagePlanes = adoptPtr(new ImagePlanes()); |
| 86 decoder->setImagePlanes(dummyImagePlanes.release()); | 86 decoder->setImagePlanes(std::move(dummyImagePlanes)); |
| 87 | 87 |
| 88 bool sizeIsAvailable = decoder->isSizeAvailable(); | 88 bool sizeIsAvailable = decoder->isSizeAvailable(); |
| 89 ASSERT_TRUE(sizeIsAvailable); | 89 ASSERT_TRUE(sizeIsAvailable); |
| 90 | 90 |
| 91 IntSize size = decoder->decodedSize(); | 91 IntSize size = decoder->decodedSize(); |
| 92 IntSize ySize = decoder->decodedYUVSize(0); | 92 IntSize ySize = decoder->decodedYUVSize(0); |
| 93 IntSize uSize = decoder->decodedYUVSize(1); | 93 IntSize uSize = decoder->decodedYUVSize(1); |
| 94 IntSize vSize = decoder->decodedYUVSize(2); | 94 IntSize vSize = decoder->decodedYUVSize(2); |
| 95 | 95 |
| 96 ASSERT_TRUE(size.width() == ySize.width()); | 96 ASSERT_TRUE(size.width() == ySize.width()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 108 rowBytes[1] = decoder->decodedYUVWidthBytes(1); | 108 rowBytes[1] = decoder->decodedYUVWidthBytes(1); |
| 109 rowBytes[2] = decoder->decodedYUVWidthBytes(2); | 109 rowBytes[2] = decoder->decodedYUVWidthBytes(2); |
| 110 | 110 |
| 111 RefPtr<ArrayBuffer> buffer(ArrayBuffer::create(rowBytes[0] * ySize.height()
+ rowBytes[1] * uSize.height() + rowBytes[2] * vSize.height(), 1)); | 111 RefPtr<ArrayBuffer> buffer(ArrayBuffer::create(rowBytes[0] * ySize.height()
+ rowBytes[1] * uSize.height() + rowBytes[2] * vSize.height(), 1)); |
| 112 void* planes[3]; | 112 void* planes[3]; |
| 113 planes[0] = buffer->data(); | 113 planes[0] = buffer->data(); |
| 114 planes[1] = ((char*) planes[0]) + rowBytes[0] * ySize.height(); | 114 planes[1] = ((char*) planes[0]) + rowBytes[0] * ySize.height(); |
| 115 planes[2] = ((char*) planes[1]) + rowBytes[1] * uSize.height(); | 115 planes[2] = ((char*) planes[1]) + rowBytes[1] * uSize.height(); |
| 116 | 116 |
| 117 OwnPtr<ImagePlanes> imagePlanes = adoptPtr(new ImagePlanes(planes, rowBytes)
); | 117 OwnPtr<ImagePlanes> imagePlanes = adoptPtr(new ImagePlanes(planes, rowBytes)
); |
| 118 decoder->setImagePlanes(imagePlanes.release()); | 118 decoder->setImagePlanes(std::move(imagePlanes)); |
| 119 | 119 |
| 120 ASSERT_TRUE(decoder->decodeToYUV()); | 120 ASSERT_TRUE(decoder->decodeToYUV()); |
| 121 } | 121 } |
| 122 | 122 |
| 123 // Tests failure on a too big image. | 123 // Tests failure on a too big image. |
| 124 TEST(JPEGImageDecoderTest, tooBig) | 124 TEST(JPEGImageDecoderTest, tooBig) |
| 125 { | 125 { |
| 126 OwnPtr<ImageDecoder> decoder = createDecoder(100); | 126 OwnPtr<ImageDecoder> decoder = createDecoder(100); |
| 127 EXPECT_FALSE(decoder->setSize(10000, 10000)); | 127 EXPECT_FALSE(decoder->setSize(10000, 10000)); |
| 128 EXPECT_TRUE(decoder->failed()); | 128 EXPECT_TRUE(decoder->failed()); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 | 244 |
| 245 // Make sure we revert to RGBA decoding when we're about to downscale, | 245 // Make sure we revert to RGBA decoding when we're about to downscale, |
| 246 // which can occur on memory-constrained android devices. | 246 // which can occur on memory-constrained android devices. |
| 247 RefPtr<SharedBuffer> data = readFile(jpegFile); | 247 RefPtr<SharedBuffer> data = readFile(jpegFile); |
| 248 ASSERT_TRUE(data); | 248 ASSERT_TRUE(data); |
| 249 | 249 |
| 250 OwnPtr<ImageDecoder> decoder = createDecoder(230 * 230 * 4); | 250 OwnPtr<ImageDecoder> decoder = createDecoder(230 * 230 * 4); |
| 251 decoder->setData(data.get(), true); | 251 decoder->setData(data.get(), true); |
| 252 | 252 |
| 253 OwnPtr<ImagePlanes> imagePlanes = adoptPtr(new ImagePlanes()); | 253 OwnPtr<ImagePlanes> imagePlanes = adoptPtr(new ImagePlanes()); |
| 254 decoder->setImagePlanes(imagePlanes.release()); | 254 decoder->setImagePlanes(std::move(imagePlanes)); |
| 255 ASSERT_TRUE(decoder->isSizeAvailable()); | 255 ASSERT_TRUE(decoder->isSizeAvailable()); |
| 256 ASSERT_FALSE(decoder->canDecodeToYUV()); | 256 ASSERT_FALSE(decoder->canDecodeToYUV()); |
| 257 } | 257 } |
| 258 | 258 |
| 259 TEST(JPEGImageDecoderTest, byteByByteBaselineJPEGWithColorProfileAndRestartMarke
rs) | 259 TEST(JPEGImageDecoderTest, byteByByteBaselineJPEGWithColorProfileAndRestartMarke
rs) |
| 260 { | 260 { |
| 261 testByteByByteDecode(&createDecoder, "/LayoutTests/fast/images/resources/sma
ll-square-with-colorspin-profile.jpg", 1u, cAnimationNone); | 261 testByteByByteDecode(&createDecoder, "/LayoutTests/fast/images/resources/sma
ll-square-with-colorspin-profile.jpg", 1u, cAnimationNone); |
| 262 } | 262 } |
| 263 | 263 |
| 264 TEST(JPEGImageDecoderTest, byteByByteProgressiveJPEG) | 264 TEST(JPEGImageDecoderTest, byteByByteProgressiveJPEG) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 275 // not break JPEG decoding at a critical point: in between a call to decode the | 275 // not break JPEG decoding at a critical point: in between a call to decode the |
| 276 // size (when JPEGImageDecoder stops while it may still have input data to | 276 // size (when JPEGImageDecoder stops while it may still have input data to |
| 277 // read) and a call to do a full decode. | 277 // read) and a call to do a full decode. |
| 278 TEST(JPEGImageDecoderTest, mergeBuffer) | 278 TEST(JPEGImageDecoderTest, mergeBuffer) |
| 279 { | 279 { |
| 280 const char* jpegFile = "/LayoutTests/fast/images/resources/lenna.jpg"; | 280 const char* jpegFile = "/LayoutTests/fast/images/resources/lenna.jpg"; |
| 281 testMergeBuffer(&createDecoder, jpegFile); | 281 testMergeBuffer(&createDecoder, jpegFile); |
| 282 } | 282 } |
| 283 | 283 |
| 284 } // namespace blink | 284 } // namespace blink |
| OLD | NEW |