Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(168)

Side by Side Diff: third_party/WebKit/Source/platform/image-decoders/jpeg/JPEGImageDecoderTest.cpp

Issue 1812273003: Eliminate copies of encoded image data (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 15 matching lines...) Expand all
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "platform/image-decoders/jpeg/JPEGImageDecoder.h" 31 #include "platform/image-decoders/jpeg/JPEGImageDecoder.h"
32 32
33 #include "platform/SharedBuffer.h" 33 #include "platform/SharedBuffer.h"
34 #include "platform/image-decoders/ImageAnimation.h" 34 #include "platform/image-decoders/ImageAnimation.h"
35 #include "platform/image-decoders/ImageDecoderTestHelpers.h" 35 #include "platform/image-decoders/ImageDecoderTestHelpers.h"
36 #include "platform/image-decoders/SharedBufferSegmentReader.h"
36 #include "public/platform/WebData.h" 37 #include "public/platform/WebData.h"
37 #include "public/platform/WebSize.h" 38 #include "public/platform/WebSize.h"
38 #include "testing/gtest/include/gtest/gtest.h" 39 #include "testing/gtest/include/gtest/gtest.h"
39 #include "wtf/OwnPtr.h" 40 #include "wtf/OwnPtr.h"
40 #include "wtf/PassOwnPtr.h" 41 #include "wtf/PassOwnPtr.h"
41 42
42 namespace blink { 43 namespace blink {
43 44
44 static const size_t LargeEnoughSize = 1000 * 1000; 45 static const size_t LargeEnoughSize = 1000 * 1000;
45 46
(...skipping 10 matching lines...) Expand all
56 } 57 }
57 58
58 } // anonymous namespace 59 } // anonymous namespace
59 60
60 void downsample(size_t maxDecodedBytes, unsigned* outputWidth, unsigned* outputH eight, const char* imageFilePath) 61 void downsample(size_t maxDecodedBytes, unsigned* outputWidth, unsigned* outputH eight, const char* imageFilePath)
61 { 62 {
62 RefPtr<SharedBuffer> data = readFile(imageFilePath); 63 RefPtr<SharedBuffer> data = readFile(imageFilePath);
63 ASSERT_TRUE(data); 64 ASSERT_TRUE(data);
64 65
65 OwnPtr<ImageDecoder> decoder = createDecoder(maxDecodedBytes); 66 OwnPtr<ImageDecoder> decoder = createDecoder(maxDecodedBytes);
66 decoder->setData(data.get(), true); 67 RefPtr<SharedBufferSegmentReader> segmentReader = adoptRef(new SharedBufferS egmentReader(data));
68 decoder->setData(segmentReader.get(), true);
67 69
68 ImageFrame* frame = decoder->frameBufferAtIndex(0); 70 ImageFrame* frame = decoder->frameBufferAtIndex(0);
69 ASSERT_TRUE(frame); 71 ASSERT_TRUE(frame);
70 *outputWidth = frame->getSkBitmap().width(); 72 *outputWidth = frame->getSkBitmap().width();
71 *outputHeight = frame->getSkBitmap().height(); 73 *outputHeight = frame->getSkBitmap().height();
72 EXPECT_EQ(IntSize(*outputWidth, *outputHeight), decoder->decodedSize()); 74 EXPECT_EQ(IntSize(*outputWidth, *outputHeight), decoder->decodedSize());
73 } 75 }
74 76
75 void readYUV(size_t maxDecodedBytes, unsigned* outputYWidth, unsigned* outputYHe ight, unsigned* outputUVWidth, unsigned* outputUVHeight, const char* imageFilePa th) 77 void readYUV(size_t maxDecodedBytes, unsigned* outputYWidth, unsigned* outputYHe ight, unsigned* outputUVWidth, unsigned* outputUVHeight, const char* imageFilePa th)
76 { 78 {
77 RefPtr<SharedBuffer> data = readFile(imageFilePath); 79 RefPtr<SharedBuffer> data = readFile(imageFilePath);
78 ASSERT_TRUE(data); 80 ASSERT_TRUE(data);
79 81
80 OwnPtr<ImageDecoder> decoder = createDecoder(maxDecodedBytes); 82 OwnPtr<ImageDecoder> decoder = createDecoder(maxDecodedBytes);
81 decoder->setData(data.get(), true); 83 RefPtr<SharedBufferSegmentReader> segmentReader = adoptRef(new SharedBufferS egmentReader(data));
84 decoder->setData(segmentReader.get(), true);
82 85
83 OwnPtr<ImagePlanes> imagePlanes = adoptPtr(new ImagePlanes()); 86 OwnPtr<ImagePlanes> imagePlanes = adoptPtr(new ImagePlanes());
84 decoder->setImagePlanes(imagePlanes.release()); 87 decoder->setImagePlanes(imagePlanes.release());
85 bool sizeIsAvailable = decoder->isSizeAvailable(); 88 bool sizeIsAvailable = decoder->isSizeAvailable();
86 ASSERT_TRUE(sizeIsAvailable); 89 ASSERT_TRUE(sizeIsAvailable);
87 90
88 IntSize size = decoder->decodedSize(); 91 IntSize size = decoder->decodedSize();
89 IntSize ySize = decoder->decodedYUVSize(0, ImageDecoder::ActualSize); 92 IntSize ySize = decoder->decodedYUVSize(0, ImageDecoder::ActualSize);
90 IntSize uSize = decoder->decodedYUVSize(1, ImageDecoder::ActualSize); 93 IntSize uSize = decoder->decodedYUVSize(1, ImageDecoder::ActualSize);
91 IntSize vSize = decoder->decodedYUVSize(2, ImageDecoder::ActualSize); 94 IntSize vSize = decoder->decodedYUVSize(2, ImageDecoder::ActualSize);
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 EXPECT_EQ(256u, outputYHeight); 218 EXPECT_EQ(256u, outputYHeight);
216 EXPECT_EQ(128u, outputUVWidth); 219 EXPECT_EQ(128u, outputUVWidth);
217 EXPECT_EQ(128u, outputUVHeight); 220 EXPECT_EQ(128u, outputUVHeight);
218 221
219 // Make sure we revert to RGBA decoding when we're about to downscale, 222 // Make sure we revert to RGBA decoding when we're about to downscale,
220 // which can occur on memory-constrained android devices. 223 // which can occur on memory-constrained android devices.
221 RefPtr<SharedBuffer> data = readFile(jpegFile); 224 RefPtr<SharedBuffer> data = readFile(jpegFile);
222 ASSERT_TRUE(data); 225 ASSERT_TRUE(data);
223 226
224 OwnPtr<ImageDecoder> decoder = createDecoder(230 * 230 * 4); 227 OwnPtr<ImageDecoder> decoder = createDecoder(230 * 230 * 4);
225 decoder->setData(data.get(), true); 228 RefPtr<SharedBufferSegmentReader> segmentReader = adoptRef(new SharedBufferS egmentReader(data));
229 decoder->setData(segmentReader.get(), true);
226 230
227 OwnPtr<ImagePlanes> imagePlanes = adoptPtr(new ImagePlanes()); 231 OwnPtr<ImagePlanes> imagePlanes = adoptPtr(new ImagePlanes());
228 decoder->setImagePlanes(imagePlanes.release()); 232 decoder->setImagePlanes(imagePlanes.release());
229 ASSERT_TRUE(decoder->isSizeAvailable()); 233 ASSERT_TRUE(decoder->isSizeAvailable());
230 ASSERT_FALSE(decoder->canDecodeToYUV()); 234 ASSERT_FALSE(decoder->canDecodeToYUV());
231 } 235 }
232 236
233 TEST(JPEGImageDecoderTest, byteByByteBaselineJPEGWithColorProfileAndRestartMarke rs) 237 TEST(JPEGImageDecoderTest, byteByByteBaselineJPEGWithColorProfileAndRestartMarke rs)
234 { 238 {
235 testByteByByteDecode(&createDecoder, "/LayoutTests/fast/images/resources/sma ll-square-with-colorspin-profile.jpg", 1u, cAnimationNone); 239 testByteByByteDecode(&createDecoder, "/LayoutTests/fast/images/resources/sma ll-square-with-colorspin-profile.jpg", 1u, cAnimationNone);
(...skipping 13 matching lines...) Expand all
249 // not break JPEG decoding at a critical point: in between a call to decode the 253 // 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 254 // size (when JPEGImageDecoder stops while it may still have input data to
251 // read) and a call to do a full decode. 255 // read) and a call to do a full decode.
252 TEST(JPEGImageDecoderTest, mergeBuffer) 256 TEST(JPEGImageDecoderTest, mergeBuffer)
253 { 257 {
254 const char* jpegFile = "/LayoutTests/fast/images/resources/lenna.jpg"; 258 const char* jpegFile = "/LayoutTests/fast/images/resources/lenna.jpg";
255 testMergeBuffer(&createDecoder, jpegFile); 259 testMergeBuffer(&createDecoder, jpegFile);
256 } 260 }
257 261
258 } // namespace blink 262 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698