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

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: Update DEPS again 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
« no previous file with comments | « third_party/WebKit/Source/platform/image-decoders/jpeg/JPEGImageDecoder.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
117 OwnPtr<ImagePlanes> imagePlanes = adoptPtr(new ImagePlanes(planes, rowBytes) );
118 decoder->setImagePlanes(imagePlanes.release());
119
120 ASSERT_TRUE(decoder->decodeToYUV());
102 } 121 }
103 122
104 // Tests failure on a too big image. 123 // Tests failure on a too big image.
105 TEST(JPEGImageDecoderTest, tooBig) 124 TEST(JPEGImageDecoderTest, tooBig)
106 { 125 {
107 OwnPtr<ImageDecoder> decoder = createDecoder(100); 126 OwnPtr<ImageDecoder> decoder = createDecoder(100);
108 EXPECT_FALSE(decoder->setSize(10000, 10000)); 127 EXPECT_FALSE(decoder->setSize(10000, 10000));
109 EXPECT_TRUE(decoder->failed()); 128 EXPECT_TRUE(decoder->failed());
110 } 129 }
111 130
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 TEST(JPEGImageDecoderTest, yuv) 228 TEST(JPEGImageDecoderTest, yuv)
210 { 229 {
211 const char* jpegFile = "/LayoutTests/fast/images/resources/lenna.jpg"; // 25 6x256, YUV 4:2:0 230 const char* jpegFile = "/LayoutTests/fast/images/resources/lenna.jpg"; // 25 6x256, YUV 4:2:0
212 unsigned outputYWidth, outputYHeight, outputUVWidth, outputUVHeight; 231 unsigned outputYWidth, outputYHeight, outputUVWidth, outputUVHeight;
213 readYUV(LargeEnoughSize, &outputYWidth, &outputYHeight, &outputUVWidth, &out putUVHeight, jpegFile); 232 readYUV(LargeEnoughSize, &outputYWidth, &outputYHeight, &outputUVWidth, &out putUVHeight, jpegFile);
214 EXPECT_EQ(256u, outputYWidth); 233 EXPECT_EQ(256u, outputYWidth);
215 EXPECT_EQ(256u, outputYHeight); 234 EXPECT_EQ(256u, outputYHeight);
216 EXPECT_EQ(128u, outputUVWidth); 235 EXPECT_EQ(128u, outputUVWidth);
217 EXPECT_EQ(128u, outputUVHeight); 236 EXPECT_EQ(128u, outputUVHeight);
218 237
238 const char* jpegFileImageSizeNotMultipleOf8 = "/LayoutTests/fast/images/reso urces/cropped_mandrill.jpg"; // 439x154
239 readYUV(LargeEnoughSize, &outputYWidth, &outputYHeight, &outputUVWidth, &out putUVHeight, jpegFileImageSizeNotMultipleOf8);
240 EXPECT_EQ(439u, outputYWidth);
241 EXPECT_EQ(154u, outputYHeight);
242 EXPECT_EQ(220u, outputUVWidth);
243 EXPECT_EQ(77u, outputUVHeight);
244
219 // 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,
220 // which can occur on memory-constrained android devices. 246 // which can occur on memory-constrained android devices.
221 RefPtr<SharedBuffer> data = readFile(jpegFile); 247 RefPtr<SharedBuffer> data = readFile(jpegFile);
222 ASSERT_TRUE(data); 248 ASSERT_TRUE(data);
223 249
224 OwnPtr<ImageDecoder> decoder = createDecoder(230 * 230 * 4); 250 OwnPtr<ImageDecoder> decoder = createDecoder(230 * 230 * 4);
225 decoder->setData(data.get(), true); 251 decoder->setData(data.get(), true);
226 252
227 OwnPtr<ImagePlanes> imagePlanes = adoptPtr(new ImagePlanes()); 253 OwnPtr<ImagePlanes> imagePlanes = adoptPtr(new ImagePlanes());
228 decoder->setImagePlanes(imagePlanes.release()); 254 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 275 // 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 276 // size (when JPEGImageDecoder stops while it may still have input data to
251 // read) and a call to do a full decode. 277 // read) and a call to do a full decode.
252 TEST(JPEGImageDecoderTest, mergeBuffer) 278 TEST(JPEGImageDecoderTest, mergeBuffer)
253 { 279 {
254 const char* jpegFile = "/LayoutTests/fast/images/resources/lenna.jpg"; 280 const char* jpegFile = "/LayoutTests/fast/images/resources/lenna.jpg";
255 testMergeBuffer(&createDecoder, jpegFile); 281 testMergeBuffer(&createDecoder, jpegFile);
256 } 282 }
257 283
258 } // namespace blink 284 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/image-decoders/jpeg/JPEGImageDecoder.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698