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

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

Issue 418653002: Allowing YUV data to be retrieved from the JPEG Decoder. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Added missing PLATFORM_EXPORT Created 6 years, 5 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 29 matching lines...) Expand all
40 #include "wtf/OwnPtr.h" 40 #include "wtf/OwnPtr.h"
41 #include "wtf/PassOwnPtr.h" 41 #include "wtf/PassOwnPtr.h"
42 #include "wtf/StringHasher.h" 42 #include "wtf/StringHasher.h"
43 #include "wtf/Vector.h" 43 #include "wtf/Vector.h"
44 44
45 #include <gtest/gtest.h> 45 #include <gtest/gtest.h>
46 46
47 using namespace blink; 47 using namespace blink;
48 using namespace blink; 48 using namespace blink;
49 49
50 static const size_t LargeEnoughSize = 1000 * 1000;
51
50 namespace { 52 namespace {
51 53
52 PassRefPtr<SharedBuffer> readFile(const char* fileName) 54 PassRefPtr<SharedBuffer> readFile(const char* fileName)
53 { 55 {
54 String filePath = Platform::current()->unitTestSupport()->webKitRootDir(); 56 String filePath = Platform::current()->unitTestSupport()->webKitRootDir();
55 filePath.append(fileName); 57 filePath.append(fileName);
56 58
57 return Platform::current()->unitTestSupport()->readFromFile(filePath); 59 return Platform::current()->unitTestSupport()->readFromFile(filePath);
58 } 60 }
59 61
(...skipping 12 matching lines...) Expand all
72 OwnPtr<JPEGImageDecoder> decoder = createDecoder(maxDecodedBytes); 74 OwnPtr<JPEGImageDecoder> decoder = createDecoder(maxDecodedBytes);
73 decoder->setData(data.get(), true); 75 decoder->setData(data.get(), true);
74 76
75 ImageFrame* frame = decoder->frameBufferAtIndex(0); 77 ImageFrame* frame = decoder->frameBufferAtIndex(0);
76 ASSERT_TRUE(frame); 78 ASSERT_TRUE(frame);
77 *outputWidth = frame->getSkBitmap().width(); 79 *outputWidth = frame->getSkBitmap().width();
78 *outputHeight = frame->getSkBitmap().height(); 80 *outputHeight = frame->getSkBitmap().height();
79 EXPECT_EQ(IntSize(*outputWidth, *outputHeight), decoder->decodedSize()); 81 EXPECT_EQ(IntSize(*outputWidth, *outputHeight), decoder->decodedSize());
80 } 82 }
81 83
84 void readYUV(size_t maxDecodedBytes, unsigned* outputYWidth, unsigned* outputYHe ight, unsigned* outputUVWidth, unsigned* outputUVHeight, const char* imageFilePa th)
85 {
86 RefPtr<SharedBuffer> data = readFile(imageFilePath);
87 ASSERT_TRUE(data.get());
88
89 OwnPtr<JPEGImageDecoder> decoder = createDecoder(maxDecodedBytes);
90 decoder->setData(data.get(), true);
91
92 OwnPtr<ImagePlanes> imagePlanes = adoptPtr(new ImagePlanes());
93 decoder->setImagePlanes(imagePlanes);
94 bool sizeIsAvailable = decoder->isSizeAvailable();
95 ASSERT_TRUE(sizeIsAvailable);
96
97 IntSize size = decoder->decodedSize();
98 IntSize ySize = decoder->decodedYUVSize(0);
99 IntSize uSize = decoder->decodedYUVSize(1);
100 IntSize vSize = decoder->decodedYUVSize(2);
101
102 ASSERT_TRUE(size.width() == ySize.width());
103 ASSERT_TRUE(size.height() == ySize.height());
104 ASSERT_TRUE(uSize.width() == vSize.width());
105 ASSERT_TRUE(uSize.height() == vSize.height());
106
107 *outputYWidth = ySize.width();
108 *outputYHeight = ySize.height();
109 *outputUVWidth = uSize.width();
110 *outputUVHeight = uSize.height();
111 }
112
82 // Tests failure on a too big image. 113 // Tests failure on a too big image.
83 TEST(JPEGImageDecoderTest, tooBig) 114 TEST(JPEGImageDecoderTest, tooBig)
84 { 115 {
85 OwnPtr<JPEGImageDecoder> decoder = createDecoder(100); 116 OwnPtr<JPEGImageDecoder> decoder = createDecoder(100);
86 EXPECT_FALSE(decoder->setSize(10000, 10000)); 117 EXPECT_FALSE(decoder->setSize(10000, 10000));
87 EXPECT_TRUE(decoder->failed()); 118 EXPECT_TRUE(decoder->failed());
88 } 119 }
89 120
90 // Tests that JPEG decoder can downsample image whose width and height are multi ple of 8, 121 // Tests that JPEG decoder can downsample image whose width and height are multi ple of 8,
91 // to ensure we compute the correct decodedSize and pass correct parameters to l ibjpeg to 122 // to ensure we compute the correct decodedSize and pass correct parameters to l ibjpeg to
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 downsample(230 * 230 * 4, &outputWidth, &outputHeight, jpegFile); 203 downsample(230 * 230 * 4, &outputWidth, &outputHeight, jpegFile);
173 EXPECT_EQ(241u, outputWidth); 204 EXPECT_EQ(241u, outputWidth);
174 EXPECT_EQ(182u, outputHeight); 205 EXPECT_EQ(182u, outputHeight);
175 } 206 }
176 207
177 // Tests that upsampling is not allowed. 208 // Tests that upsampling is not allowed.
178 TEST(JPEGImageDecoderTest, upsample) 209 TEST(JPEGImageDecoderTest, upsample)
179 { 210 {
180 const char* jpegFile = "/LayoutTests/fast/images/resources/lenna.jpg"; // 25 6x256 211 const char* jpegFile = "/LayoutTests/fast/images/resources/lenna.jpg"; // 25 6x256
181 unsigned outputWidth, outputHeight; 212 unsigned outputWidth, outputHeight;
182 downsample(1000 * 1000, &outputWidth, &outputHeight, jpegFile); 213 downsample(LargeEnoughSize, &outputWidth, &outputHeight, jpegFile);
183 EXPECT_EQ(256u, outputWidth); 214 EXPECT_EQ(256u, outputWidth);
184 EXPECT_EQ(256u, outputHeight); 215 EXPECT_EQ(256u, outputHeight);
185 } 216 }
217
218 TEST(JPEGImageDecoderTest, yuv)
219 {
220 const char* jpegFile = "/LayoutTests/fast/images/resources/lenna.jpg"; // 25 6x256, YUV 4:2:0
221 unsigned outputYWidth, outputYHeight, outputUVWidth, outputUVHeight;
222 readYUV(LargeEnoughSize, &outputYWidth, &outputYHeight, &outputUVWidth, &out putUVHeight, jpegFile);
223 EXPECT_EQ(256u, outputYWidth);
224 EXPECT_EQ(256u, outputYHeight);
225 EXPECT_EQ(128u, outputUVWidth);
226 EXPECT_EQ(128u, outputUVHeight);
227 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698