| 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/typed_arrays/ArrayBuffer.h" | 40 #include "wtf/typed_arrays/ArrayBuffer.h" |
| 41 #include <memory> | 41 #include <memory> |
| 42 | 42 |
| 43 namespace blink { | 43 namespace blink { |
| 44 | 44 |
| 45 static const size_t LargeEnoughSize = 1000 * 1000; | 45 static const size_t LargeEnoughSize = 1000 * 1000; |
| 46 | 46 |
| 47 namespace { | 47 namespace { |
| 48 | 48 |
| 49 std::unique_ptr<ImageDecoder> createDecoder(size_t maxDecodedBytes) { | 49 std::unique_ptr<ImageDecoder> createDecoder(size_t maxDecodedBytes) { |
| 50 return wrapUnique(new JPEGImageDecoder( | 50 return WTF::wrapUnique(new JPEGImageDecoder( |
| 51 ImageDecoder::AlphaNotPremultiplied, | 51 ImageDecoder::AlphaNotPremultiplied, |
| 52 ColorBehavior::transformToTargetForTesting(), maxDecodedBytes)); | 52 ColorBehavior::transformToTargetForTesting(), maxDecodedBytes)); |
| 53 } | 53 } |
| 54 | 54 |
| 55 std::unique_ptr<ImageDecoder> createDecoder() { | 55 std::unique_ptr<ImageDecoder> createDecoder() { |
| 56 return createDecoder(ImageDecoder::noDecodedImageByteLimit); | 56 return createDecoder(ImageDecoder::noDecodedImageByteLimit); |
| 57 } | 57 } |
| 58 | 58 |
| 59 } // anonymous namespace | 59 } // anonymous namespace |
| 60 | 60 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 82 unsigned* outputUVHeight, | 82 unsigned* outputUVHeight, |
| 83 const char* imageFilePath) { | 83 const char* imageFilePath) { |
| 84 RefPtr<SharedBuffer> data = readFile(imageFilePath); | 84 RefPtr<SharedBuffer> data = readFile(imageFilePath); |
| 85 ASSERT_TRUE(data); | 85 ASSERT_TRUE(data); |
| 86 | 86 |
| 87 std::unique_ptr<ImageDecoder> decoder = createDecoder(maxDecodedBytes); | 87 std::unique_ptr<ImageDecoder> decoder = createDecoder(maxDecodedBytes); |
| 88 decoder->setData(data.get(), true); | 88 decoder->setData(data.get(), true); |
| 89 | 89 |
| 90 // Setting a dummy ImagePlanes object signals to the decoder that we want to | 90 // Setting a dummy ImagePlanes object signals to the decoder that we want to |
| 91 // do YUV decoding. | 91 // do YUV decoding. |
| 92 std::unique_ptr<ImagePlanes> dummyImagePlanes = makeUnique<ImagePlanes>(); | 92 std::unique_ptr<ImagePlanes> dummyImagePlanes = |
| 93 WTF::makeUnique<ImagePlanes>(); |
| 93 decoder->setImagePlanes(std::move(dummyImagePlanes)); | 94 decoder->setImagePlanes(std::move(dummyImagePlanes)); |
| 94 | 95 |
| 95 bool sizeIsAvailable = decoder->isSizeAvailable(); | 96 bool sizeIsAvailable = decoder->isSizeAvailable(); |
| 96 ASSERT_TRUE(sizeIsAvailable); | 97 ASSERT_TRUE(sizeIsAvailable); |
| 97 | 98 |
| 98 IntSize size = decoder->decodedSize(); | 99 IntSize size = decoder->decodedSize(); |
| 99 IntSize ySize = decoder->decodedYUVSize(0); | 100 IntSize ySize = decoder->decodedYUVSize(0); |
| 100 IntSize uSize = decoder->decodedYUVSize(1); | 101 IntSize uSize = decoder->decodedYUVSize(1); |
| 101 IntSize vSize = decoder->decodedYUVSize(2); | 102 IntSize vSize = decoder->decodedYUVSize(2); |
| 102 | 103 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 118 RefPtr<ArrayBuffer> buffer(ArrayBuffer::create( | 119 RefPtr<ArrayBuffer> buffer(ArrayBuffer::create( |
| 119 rowBytes[0] * ySize.height() + rowBytes[1] * uSize.height() + | 120 rowBytes[0] * ySize.height() + rowBytes[1] * uSize.height() + |
| 120 rowBytes[2] * vSize.height(), | 121 rowBytes[2] * vSize.height(), |
| 121 1)); | 122 1)); |
| 122 void* planes[3]; | 123 void* planes[3]; |
| 123 planes[0] = buffer->data(); | 124 planes[0] = buffer->data(); |
| 124 planes[1] = ((char*)planes[0]) + rowBytes[0] * ySize.height(); | 125 planes[1] = ((char*)planes[0]) + rowBytes[0] * ySize.height(); |
| 125 planes[2] = ((char*)planes[1]) + rowBytes[1] * uSize.height(); | 126 planes[2] = ((char*)planes[1]) + rowBytes[1] * uSize.height(); |
| 126 | 127 |
| 127 std::unique_ptr<ImagePlanes> imagePlanes = | 128 std::unique_ptr<ImagePlanes> imagePlanes = |
| 128 makeUnique<ImagePlanes>(planes, rowBytes); | 129 WTF::makeUnique<ImagePlanes>(planes, rowBytes); |
| 129 decoder->setImagePlanes(std::move(imagePlanes)); | 130 decoder->setImagePlanes(std::move(imagePlanes)); |
| 130 | 131 |
| 131 ASSERT_TRUE(decoder->decodeToYUV()); | 132 ASSERT_TRUE(decoder->decodeToYUV()); |
| 132 } | 133 } |
| 133 | 134 |
| 134 // Tests failure on a too big image. | 135 // Tests failure on a too big image. |
| 135 TEST(JPEGImageDecoderTest, tooBig) { | 136 TEST(JPEGImageDecoderTest, tooBig) { |
| 136 std::unique_ptr<ImageDecoder> decoder = createDecoder(100); | 137 std::unique_ptr<ImageDecoder> decoder = createDecoder(100); |
| 137 EXPECT_FALSE(decoder->setSize(10000, 10000)); | 138 EXPECT_FALSE(decoder->setSize(10000, 10000)); |
| 138 EXPECT_TRUE(decoder->failed()); | 139 EXPECT_TRUE(decoder->failed()); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 EXPECT_EQ(77u, outputUVHeight); | 255 EXPECT_EQ(77u, outputUVHeight); |
| 255 | 256 |
| 256 // Make sure we revert to RGBA decoding when we're about to downscale, | 257 // Make sure we revert to RGBA decoding when we're about to downscale, |
| 257 // which can occur on memory-constrained android devices. | 258 // which can occur on memory-constrained android devices. |
| 258 RefPtr<SharedBuffer> data = readFile(jpegFile); | 259 RefPtr<SharedBuffer> data = readFile(jpegFile); |
| 259 ASSERT_TRUE(data); | 260 ASSERT_TRUE(data); |
| 260 | 261 |
| 261 std::unique_ptr<ImageDecoder> decoder = createDecoder(230 * 230 * 4); | 262 std::unique_ptr<ImageDecoder> decoder = createDecoder(230 * 230 * 4); |
| 262 decoder->setData(data.get(), true); | 263 decoder->setData(data.get(), true); |
| 263 | 264 |
| 264 std::unique_ptr<ImagePlanes> imagePlanes = makeUnique<ImagePlanes>(); | 265 std::unique_ptr<ImagePlanes> imagePlanes = WTF::makeUnique<ImagePlanes>(); |
| 265 decoder->setImagePlanes(std::move(imagePlanes)); | 266 decoder->setImagePlanes(std::move(imagePlanes)); |
| 266 ASSERT_TRUE(decoder->isSizeAvailable()); | 267 ASSERT_TRUE(decoder->isSizeAvailable()); |
| 267 ASSERT_FALSE(decoder->canDecodeToYUV()); | 268 ASSERT_FALSE(decoder->canDecodeToYUV()); |
| 268 } | 269 } |
| 269 | 270 |
| 270 TEST(JPEGImageDecoderTest, | 271 TEST(JPEGImageDecoderTest, |
| 271 byteByByteBaselineJPEGWithColorProfileAndRestartMarkers) { | 272 byteByByteBaselineJPEGWithColorProfileAndRestartMarkers) { |
| 272 testByteByByteDecode(&createDecoder, | 273 testByteByByteDecode(&createDecoder, |
| 273 "/LayoutTests/images/resources/" | 274 "/LayoutTests/images/resources/" |
| 274 "small-square-with-colorspin-profile.jpg", | 275 "small-square-with-colorspin-profile.jpg", |
| (...skipping 30 matching lines...) Expand all Loading... |
| 305 ASSERT_TRUE(testData.get()); | 306 ASSERT_TRUE(testData.get()); |
| 306 | 307 |
| 307 std::unique_ptr<ImageDecoder> testDecoder = createDecoder(); | 308 std::unique_ptr<ImageDecoder> testDecoder = createDecoder(); |
| 308 testDecoder->setData(testData.get(), true); | 309 testDecoder->setData(testData.get(), true); |
| 309 EXPECT_EQ(1u, testDecoder->frameCount()); | 310 EXPECT_EQ(1u, testDecoder->frameCount()); |
| 310 ASSERT_TRUE(testDecoder->frameBufferAtIndex(0)); | 311 ASSERT_TRUE(testDecoder->frameBufferAtIndex(0)); |
| 311 EXPECT_TRUE(testDecoder->failed()); | 312 EXPECT_TRUE(testDecoder->failed()); |
| 312 } | 313 } |
| 313 | 314 |
| 314 } // namespace blink | 315 } // namespace blink |
| OLD | NEW |