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

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

Issue 1719533002: Modify YUV codecs to match Skia's API change (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Response to Patch Set 3 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 18 matching lines...) Expand all
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 "public/platform/WebData.h" 36 #include "public/platform/WebData.h"
37 #include "public/platform/WebSize.h" 37 #include "public/platform/WebSize.h"
38 #include "testing/gtest/include/gtest/gtest.h" 38 #include "testing/gtest/include/gtest/gtest.h"
39 #include "wtf/ArrayBuffer.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
46 namespace { 47 namespace {
47 48
48 PassOwnPtr<ImageDecoder> createDecoder(size_t maxDecodedBytes) 49 PassOwnPtr<ImageDecoder> createDecoder(size_t maxDecodedBytes)
(...skipping 24 matching lines...) Expand all
73 } 74 }
74 75
75 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)
76 { 77 {
77 RefPtr<SharedBuffer> data = readFile(imageFilePath); 78 RefPtr<SharedBuffer> data = readFile(imageFilePath);
78 ASSERT_TRUE(data); 79 ASSERT_TRUE(data);
79 80
80 OwnPtr<ImageDecoder> decoder = createDecoder(maxDecodedBytes); 81 OwnPtr<ImageDecoder> decoder = createDecoder(maxDecodedBytes);
81 decoder->setData(data.get(), true); 82 decoder->setData(data.get(), true);
82 83
83 OwnPtr<ImagePlanes> imagePlanes = adoptPtr(new ImagePlanes()); 84 // Setting a dummy ImagePlanes object signals to the decoder that we want to do YUV decoding.
84 decoder->setImagePlanes(imagePlanes.release()); 85 OwnPtr<ImagePlanes> dummyImagePlanes = adoptPtr(new ImagePlanes());
86 decoder->setImagePlanes(dummyImagePlanes.release());
87
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);
90 IntSize uSize = decoder->decodedYUVSize(1, ImageDecoder::ActualSize); 93 IntSize uSize = decoder->decodedYUVSize(1);
91 IntSize vSize = decoder->decodedYUVSize(2, ImageDecoder::ActualSize); 94 IntSize vSize = decoder->decodedYUVSize(2);
92 95
93 ASSERT_TRUE(size.width() == ySize.width()); 96 ASSERT_TRUE(size.width() == ySize.width());
94 ASSERT_TRUE(size.height() == ySize.height()); 97 ASSERT_TRUE(size.height() == ySize.height());
95 ASSERT_TRUE(uSize.width() == vSize.width()); 98 ASSERT_TRUE(uSize.width() == vSize.width());
96 ASSERT_TRUE(uSize.height() == vSize.height()); 99 ASSERT_TRUE(uSize.height() == vSize.height());
97 100
98 *outputYWidth = ySize.width(); 101 *outputYWidth = ySize.width();
99 *outputYHeight = ySize.height(); 102 *outputYHeight = ySize.height();
100 *outputUVWidth = uSize.width(); 103 *outputUVWidth = uSize.width();
101 *outputUVHeight = uSize.height(); 104 *outputUVHeight = uSize.height();
105
106 size_t rowBytes[3];
107 rowBytes[0] = decoder->decodedYUVWidthBytes(0);
108 rowBytes[1] = decoder->decodedYUVWidthBytes(1);
109 rowBytes[2] = decoder->decodedYUVWidthBytes(2);
110
111 RefPtr<ArrayBuffer> buffer(ArrayBuffer::create(rowBytes[0] * ySize.height() + rowBytes[1] * uSize.height() + rowBytes[2] * vSize.height(), 1));
112 void* planes[3];
113 planes[0] = buffer->data();
114 planes[1] = ((char*) planes[0]) + rowBytes[0] * ySize.height();
115 planes[2] = ((char*) planes[1]) + rowBytes[1] * uSize.height();
116 OwnPtr<ImagePlanes> imagePlanes = adoptPtr(new ImagePlanes(planes, rowBytes) );
Noel Gordon 2016/03/03 01:25:28 Nit: space before this line.
msarett 2016/03/04 19:49:08 Done.
117 decoder->setImagePlanes(imagePlanes.release());
118
119 ASSERT_TRUE(decoder->decodeToYUV());
102 } 120 }
103 121
104 // Tests failure on a too big image. 122 // Tests failure on a too big image.
105 TEST(JPEGImageDecoderTest, tooBig) 123 TEST(JPEGImageDecoderTest, tooBig)
106 { 124 {
107 OwnPtr<ImageDecoder> decoder = createDecoder(100); 125 OwnPtr<ImageDecoder> decoder = createDecoder(100);
108 EXPECT_FALSE(decoder->setSize(10000, 10000)); 126 EXPECT_FALSE(decoder->setSize(10000, 10000));
109 EXPECT_TRUE(decoder->failed()); 127 EXPECT_TRUE(decoder->failed());
110 } 128 }
111 129
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 TEST(JPEGImageDecoderTest, yuv) 227 TEST(JPEGImageDecoderTest, yuv)
210 { 228 {
211 const char* jpegFile = "/LayoutTests/fast/images/resources/lenna.jpg"; // 25 6x256, YUV 4:2:0 229 const char* jpegFile = "/LayoutTests/fast/images/resources/lenna.jpg"; // 25 6x256, YUV 4:2:0
212 unsigned outputYWidth, outputYHeight, outputUVWidth, outputUVHeight; 230 unsigned outputYWidth, outputYHeight, outputUVWidth, outputUVHeight;
213 readYUV(LargeEnoughSize, &outputYWidth, &outputYHeight, &outputUVWidth, &out putUVHeight, jpegFile); 231 readYUV(LargeEnoughSize, &outputYWidth, &outputYHeight, &outputUVWidth, &out putUVHeight, jpegFile);
214 EXPECT_EQ(256u, outputYWidth); 232 EXPECT_EQ(256u, outputYWidth);
215 EXPECT_EQ(256u, outputYHeight); 233 EXPECT_EQ(256u, outputYHeight);
216 EXPECT_EQ(128u, outputUVWidth); 234 EXPECT_EQ(128u, outputUVWidth);
217 EXPECT_EQ(128u, outputUVHeight); 235 EXPECT_EQ(128u, outputUVHeight);
218 236
237 const char* jpegFileImageSizeNotMultipleOf8 = "/LayoutTests/fast/images/reso urces/cropped_mandrill.jpg"; // 439x154
Noel Gordon 2016/03/03 01:25:28 Thanks for the name fix: works for me.
msarett 2016/03/04 19:49:08 Acknowledged.
238 readYUV(LargeEnoughSize, &outputYWidth, &outputYHeight, &outputUVWidth, &out putUVHeight, jpegFileImageSizeNotMultipleOf8);
239 EXPECT_EQ(439u, outputYWidth);
240 EXPECT_EQ(154u, outputYHeight);
241 EXPECT_EQ(220u, outputUVWidth);
242 EXPECT_EQ(77u, outputUVHeight);
243
219 // Make sure we revert to RGBA decoding when we're about to downscale, 244 // Make sure we revert to RGBA decoding when we're about to downscale,
220 // which can occur on memory-constrained android devices. 245 // which can occur on memory-constrained android devices.
221 RefPtr<SharedBuffer> data = readFile(jpegFile); 246 RefPtr<SharedBuffer> data = readFile(jpegFile);
222 ASSERT_TRUE(data); 247 ASSERT_TRUE(data);
223 248
224 OwnPtr<ImageDecoder> decoder = createDecoder(230 * 230 * 4); 249 OwnPtr<ImageDecoder> decoder = createDecoder(230 * 230 * 4);
225 decoder->setData(data.get(), true); 250 decoder->setData(data.get(), true);
226 251
227 OwnPtr<ImagePlanes> imagePlanes = adoptPtr(new ImagePlanes()); 252 OwnPtr<ImagePlanes> imagePlanes = adoptPtr(new ImagePlanes());
228 decoder->setImagePlanes(imagePlanes.release()); 253 decoder->setImagePlanes(imagePlanes.release());
(...skipping 20 matching lines...) Expand all
249 // not break JPEG decoding at a critical point: in between a call to decode the 274 // 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 275 // size (when JPEGImageDecoder stops while it may still have input data to
251 // read) and a call to do a full decode. 276 // read) and a call to do a full decode.
252 TEST(JPEGImageDecoderTest, mergeBuffer) 277 TEST(JPEGImageDecoderTest, mergeBuffer)
253 { 278 {
254 const char* jpegFile = "/LayoutTests/fast/images/resources/lenna.jpg"; 279 const char* jpegFile = "/LayoutTests/fast/images/resources/lenna.jpg";
255 testMergeBuffer(&createDecoder, jpegFile); 280 testMergeBuffer(&createDecoder, jpegFile);
256 } 281 }
257 282
258 } // namespace blink 283 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698