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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: Source/platform/image-decoders/jpeg/JPEGImageDecoderTest.cpp
diff --git a/Source/platform/image-decoders/jpeg/JPEGImageDecoderTest.cpp b/Source/platform/image-decoders/jpeg/JPEGImageDecoderTest.cpp
index 0fabc53c64dfa3772da4b4cdcf19a0d607b48b11..b2b281c757a2a295ee8cc0a60067434da1b894a9 100644
--- a/Source/platform/image-decoders/jpeg/JPEGImageDecoderTest.cpp
+++ b/Source/platform/image-decoders/jpeg/JPEGImageDecoderTest.cpp
@@ -47,6 +47,8 @@
using namespace blink;
using namespace blink;
+static const size_t LargeEnoughSize = 1000 * 1000;
+
namespace {
PassRefPtr<SharedBuffer> readFile(const char* fileName)
@@ -79,6 +81,35 @@ void downsample(size_t maxDecodedBytes, unsigned* outputWidth, unsigned* outputH
EXPECT_EQ(IntSize(*outputWidth, *outputHeight), decoder->decodedSize());
}
+void readYUV(size_t maxDecodedBytes, unsigned* outputYWidth, unsigned* outputYHeight, unsigned* outputUVWidth, unsigned* outputUVHeight, const char* imageFilePath)
+{
+ RefPtr<SharedBuffer> data = readFile(imageFilePath);
+ ASSERT_TRUE(data.get());
+
+ OwnPtr<JPEGImageDecoder> decoder = createDecoder(maxDecodedBytes);
+ decoder->setData(data.get(), true);
+
+ OwnPtr<ImagePlanes> imagePlanes = adoptPtr(new ImagePlanes());
+ decoder->setImagePlanes(imagePlanes);
+ bool sizeIsAvailable = decoder->isSizeAvailable();
+ ASSERT_TRUE(sizeIsAvailable);
+
+ IntSize size = decoder->decodedSize();
+ IntSize ySize = decoder->decodedYUVSize(0);
+ IntSize uSize = decoder->decodedYUVSize(1);
+ IntSize vSize = decoder->decodedYUVSize(2);
+
+ ASSERT_TRUE(size.width() == ySize.width());
+ ASSERT_TRUE(size.height() == ySize.height());
+ ASSERT_TRUE(uSize.width() == vSize.width());
+ ASSERT_TRUE(uSize.height() == vSize.height());
+
+ *outputYWidth = ySize.width();
+ *outputYHeight = ySize.height();
+ *outputUVWidth = uSize.width();
+ *outputUVHeight = uSize.height();
+}
+
// Tests failure on a too big image.
TEST(JPEGImageDecoderTest, tooBig)
{
@@ -179,7 +210,18 @@ TEST(JPEGImageDecoderTest, upsample)
{
const char* jpegFile = "/LayoutTests/fast/images/resources/lenna.jpg"; // 256x256
unsigned outputWidth, outputHeight;
- downsample(1000 * 1000, &outputWidth, &outputHeight, jpegFile);
+ downsample(LargeEnoughSize, &outputWidth, &outputHeight, jpegFile);
EXPECT_EQ(256u, outputWidth);
EXPECT_EQ(256u, outputHeight);
}
+
+TEST(JPEGImageDecoderTest, yuv)
+{
+ const char* jpegFile = "/LayoutTests/fast/images/resources/lenna.jpg"; // 256x256, YUV 4:2:0
+ unsigned outputYWidth, outputYHeight, outputUVWidth, outputUVHeight;
+ readYUV(LargeEnoughSize, &outputYWidth, &outputYHeight, &outputUVWidth, &outputUVHeight, jpegFile);
+ EXPECT_EQ(256u, outputYWidth);
+ EXPECT_EQ(256u, outputYHeight);
+ EXPECT_EQ(128u, outputUVWidth);
+ EXPECT_EQ(128u, outputUVHeight);
+}

Powered by Google App Engine
This is Rietveld 408576698