Chromium Code Reviews| 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 73 } | 73 } |
| 74 | 74 |
| 75 void readYUV(size_t maxDecodedBytes, unsigned* outputYWidth, unsigned* outputYHe ight, unsigned* outputUVWidth, unsigned* outputUVHeight, const char* imageFilePa th) | 75 void readYUV(size_t maxDecodedBytes, unsigned* outputYWidth, unsigned* outputYHe ight, unsigned* outputUVWidth, unsigned* outputUVHeight, const char* imageFilePa th) |
| 76 { | 76 { |
| 77 RefPtr<SharedBuffer> data = readFile(imageFilePath); | 77 RefPtr<SharedBuffer> data = readFile(imageFilePath); |
| 78 ASSERT_TRUE(data); | 78 ASSERT_TRUE(data); |
| 79 | 79 |
| 80 OwnPtr<ImageDecoder> decoder = createDecoder(maxDecodedBytes); | 80 OwnPtr<ImageDecoder> decoder = createDecoder(maxDecodedBytes); |
| 81 decoder->setData(data.get(), true); | 81 decoder->setData(data.get(), true); |
| 82 | 82 |
| 83 OwnPtr<ImagePlanes> imagePlanes = adoptPtr(new ImagePlanes()); | 83 // Setting a dummy ImagePlanes object signals to the decoder that we want to do YUV decoding. |
| 84 decoder->setImagePlanes(imagePlanes.release()); | 84 OwnPtr<ImagePlanes> dummyImagePlanes = adoptPtr(new ImagePlanes()); |
| 85 decoder->setImagePlanes(dummyImagePlanes.release()); | |
| 86 | |
| 85 bool sizeIsAvailable = decoder->isSizeAvailable(); | 87 bool sizeIsAvailable = decoder->isSizeAvailable(); |
| 86 ASSERT_TRUE(sizeIsAvailable); | 88 ASSERT_TRUE(sizeIsAvailable); |
| 87 | 89 |
| 88 IntSize size = decoder->decodedSize(); | 90 IntSize size = decoder->decodedSize(); |
| 89 IntSize ySize = decoder->decodedYUVSize(0, ImageDecoder::ActualSize); | 91 IntSize ySize = decoder->decodedYUVSize(0); |
| 90 IntSize uSize = decoder->decodedYUVSize(1, ImageDecoder::ActualSize); | 92 IntSize uSize = decoder->decodedYUVSize(1); |
| 91 IntSize vSize = decoder->decodedYUVSize(2, ImageDecoder::ActualSize); | 93 IntSize vSize = decoder->decodedYUVSize(2); |
| 92 | 94 |
| 93 ASSERT_TRUE(size.width() == ySize.width()); | 95 ASSERT_TRUE(size.width() == ySize.width()); |
| 94 ASSERT_TRUE(size.height() == ySize.height()); | 96 ASSERT_TRUE(size.height() == ySize.height()); |
| 95 ASSERT_TRUE(uSize.width() == vSize.width()); | 97 ASSERT_TRUE(uSize.width() == vSize.width()); |
| 96 ASSERT_TRUE(uSize.height() == vSize.height()); | 98 ASSERT_TRUE(uSize.height() == vSize.height()); |
| 97 | 99 |
| 98 *outputYWidth = ySize.width(); | 100 *outputYWidth = ySize.width(); |
| 99 *outputYHeight = ySize.height(); | 101 *outputYHeight = ySize.height(); |
| 100 *outputUVWidth = uSize.width(); | 102 *outputUVWidth = uSize.width(); |
| 101 *outputUVHeight = uSize.height(); | 103 *outputUVHeight = uSize.height(); |
| 104 | |
| 105 size_t rowBytes[3]; | |
| 106 rowBytes[0] = decoder->decodedYUVWidthBytes(0); | |
| 107 rowBytes[1] = decoder->decodedYUVWidthBytes(1); | |
| 108 rowBytes[2] = decoder->decodedYUVWidthBytes(2); | |
| 109 | |
| 110 SkAutoMalloc buffer(rowBytes[0] * ySize.height() + rowBytes[1] * uSize.heigh t() + rowBytes[2] * vSize.height()); | |
| 111 void* planes[3]; | |
| 112 planes[0] = buffer.get(); | |
| 113 planes[1] = ((char*) planes[0]) + rowBytes[0] * ySize.height(); | |
| 114 planes[2] = ((char*) planes[1]) + rowBytes[1] * uSize.height(); | |
| 115 OwnPtr<ImagePlanes> imagePlanes = adoptPtr(new ImagePlanes(planes, rowBytes) ); | |
| 116 decoder->setImagePlanes(imagePlanes.release()); | |
| 117 | |
| 118 ASSERT_TRUE(decoder->decodeToYUV()); | |
| 102 } | 119 } |
| 103 | 120 |
| 104 // Tests failure on a too big image. | 121 // Tests failure on a too big image. |
| 105 TEST(JPEGImageDecoderTest, tooBig) | 122 TEST(JPEGImageDecoderTest, tooBig) |
| 106 { | 123 { |
| 107 OwnPtr<ImageDecoder> decoder = createDecoder(100); | 124 OwnPtr<ImageDecoder> decoder = createDecoder(100); |
| 108 EXPECT_FALSE(decoder->setSize(10000, 10000)); | 125 EXPECT_FALSE(decoder->setSize(10000, 10000)); |
| 109 EXPECT_TRUE(decoder->failed()); | 126 EXPECT_TRUE(decoder->failed()); |
| 110 } | 127 } |
| 111 | 128 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 209 TEST(JPEGImageDecoderTest, yuv) | 226 TEST(JPEGImageDecoderTest, yuv) |
| 210 { | 227 { |
| 211 const char* jpegFile = "/LayoutTests/fast/images/resources/lenna.jpg"; // 25 6x256, YUV 4:2:0 | 228 const char* jpegFile = "/LayoutTests/fast/images/resources/lenna.jpg"; // 25 6x256, YUV 4:2:0 |
| 212 unsigned outputYWidth, outputYHeight, outputUVWidth, outputUVHeight; | 229 unsigned outputYWidth, outputYHeight, outputUVWidth, outputUVHeight; |
| 213 readYUV(LargeEnoughSize, &outputYWidth, &outputYHeight, &outputUVWidth, &out putUVHeight, jpegFile); | 230 readYUV(LargeEnoughSize, &outputYWidth, &outputYHeight, &outputUVWidth, &out putUVHeight, jpegFile); |
| 214 EXPECT_EQ(256u, outputYWidth); | 231 EXPECT_EQ(256u, outputYWidth); |
| 215 EXPECT_EQ(256u, outputYHeight); | 232 EXPECT_EQ(256u, outputYHeight); |
| 216 EXPECT_EQ(128u, outputUVWidth); | 233 EXPECT_EQ(128u, outputUVWidth); |
| 217 EXPECT_EQ(128u, outputUVHeight); | 234 EXPECT_EQ(128u, outputUVHeight); |
| 218 | 235 |
| 236 const char* jpegFileNon8 = "/LayoutTests/fast/images/resources/non8dims.jpg" ; // 227x149 | |
|
msarett
2016/02/22 20:56:31
Does this need to be a public image? I might need
scroggo_chromium
2016/02/22 21:10:32
Yes.
msarett
2016/02/22 21:42:44
Done.
| |
| 237 readYUV(LargeEnoughSize, &outputYWidth, &outputYHeight, &outputUVWidth, &out putUVHeight, jpegFileNon8); | |
| 238 EXPECT_EQ(227u, outputYWidth); | |
| 239 EXPECT_EQ(149u, outputYHeight); | |
| 240 EXPECT_EQ(114u, outputUVWidth); | |
| 241 EXPECT_EQ(75u, outputUVHeight); | |
| 242 | |
| 219 // Make sure we revert to RGBA decoding when we're about to downscale, | 243 // Make sure we revert to RGBA decoding when we're about to downscale, |
| 220 // which can occur on memory-constrained android devices. | 244 // which can occur on memory-constrained android devices. |
| 221 RefPtr<SharedBuffer> data = readFile(jpegFile); | 245 RefPtr<SharedBuffer> data = readFile(jpegFile); |
| 222 ASSERT_TRUE(data); | 246 ASSERT_TRUE(data); |
| 223 | 247 |
| 224 OwnPtr<ImageDecoder> decoder = createDecoder(230 * 230 * 4); | 248 OwnPtr<ImageDecoder> decoder = createDecoder(230 * 230 * 4); |
| 225 decoder->setData(data.get(), true); | 249 decoder->setData(data.get(), true); |
| 226 | 250 |
| 227 OwnPtr<ImagePlanes> imagePlanes = adoptPtr(new ImagePlanes()); | 251 OwnPtr<ImagePlanes> imagePlanes = adoptPtr(new ImagePlanes()); |
| 228 decoder->setImagePlanes(imagePlanes.release()); | 252 decoder->setImagePlanes(imagePlanes.release()); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 249 // not break JPEG decoding at a critical point: in between a call to decode the | 273 // not break JPEG decoding at a critical point: in between a call to decode the |
| 250 // size (when JPEGImageDecoder stops while it may still have input data to | 274 // size (when JPEGImageDecoder stops while it may still have input data to |
| 251 // read) and a call to do a full decode. | 275 // read) and a call to do a full decode. |
| 252 TEST(JPEGImageDecoderTest, mergeBuffer) | 276 TEST(JPEGImageDecoderTest, mergeBuffer) |
| 253 { | 277 { |
| 254 const char* jpegFile = "/LayoutTests/fast/images/resources/lenna.jpg"; | 278 const char* jpegFile = "/LayoutTests/fast/images/resources/lenna.jpg"; |
| 255 testMergeBuffer(&createDecoder, jpegFile); | 279 testMergeBuffer(&createDecoder, jpegFile); |
| 256 } | 280 } |
| 257 | 281 |
| 258 } // namespace blink | 282 } // namespace blink |
| OLD | NEW |