Index: tests/JpegTest.cpp |
diff --git a/tests/JpegTest.cpp b/tests/JpegTest.cpp |
index d61b0bd3111cd89f62930c3ed9cff2d81b3abea9..4d558468ed396745e42ee630571aaba205bd73cf 100644 |
--- a/tests/JpegTest.cpp |
+++ b/tests/JpegTest.cpp |
@@ -6,10 +6,12 @@ |
*/ |
#include "SkBitmap.h" |
+#include "SkCodec.h" |
#include "SkDecodingImageGenerator.h" |
#include "SkForceLinking.h" |
#include "SkImageDecoder.h" |
#include "SkPixelRef.h" |
+#include "Resources.h" |
#include "SkStream.h" |
#include "SkTemplates.h" |
#include "Test.h" |
@@ -491,3 +493,124 @@ DEF_TEST(Jpeg_YUV, reporter) { |
// Get the YUV planes |
REPORTER_ASSERT(reporter, gen->getYUV8Planes(yuvSizes, planes, rowBytes, nullptr)); |
} |
+ |
+static SkStreamAsset* resource(const char path[]) { |
+ SkString fullPath = GetResourcePath(path); |
+ return SkStream::NewFromFile(fullPath.c_str()); |
+} |
+ |
+static void codec_yuv(skiatest::Reporter* reporter, |
+ const char path[], |
+ SkISize expectedSizes[3]) { |
+ SkAutoTDelete<SkStream> stream(resource(path)); |
+ if (!stream) { |
+ SkDebugf("Missing resource '%s'\n", path); |
+ return; |
+ } |
+ SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.detach())); |
+ REPORTER_ASSERT(reporter, codec); |
+ if (!codec) { |
+ return; |
+ } |
+ |
+ // Test getYUV8Sizes() |
+ SkISize sizes[3]; |
+ bool success = codec->getYUV8Sizes(nullptr); |
+ REPORTER_ASSERT(reporter, !success); |
+ success = codec->getYUV8Sizes(sizes); |
+ if (expectedSizes) { |
scroggo
2016/01/04 18:29:16
Instead of this if/else block, how do you feel abo
msarett
2016/01/12 14:25:27
Done.
|
+ REPORTER_ASSERT(reporter, success); |
+ } else { |
+ // Passing in nullptr for expectedSizes indicates that we expect YUV |
+ // to not be supported. |
+ REPORTER_ASSERT(reporter, !success); |
+ } |
+ if (!success) { |
+ return; |
+ } |
+ REPORTER_ASSERT(reporter, expectedSizes[0].width() == sizes[0].width()); |
scroggo
2016/01/04 18:29:16
Alternatively, you could do a memcmp? I don't have
msarett
2016/01/12 14:25:27
Done.
|
+ REPORTER_ASSERT(reporter, expectedSizes[0].height() == sizes[0].height()); |
+ REPORTER_ASSERT(reporter, expectedSizes[1].width() == sizes[1].width()); |
+ REPORTER_ASSERT(reporter, expectedSizes[1].height() == sizes[1].height()); |
+ REPORTER_ASSERT(reporter, expectedSizes[2].width() == sizes[2].width()); |
+ REPORTER_ASSERT(reporter, expectedSizes[2].height() == sizes[2].height()); |
+ |
+ // Calculate rowBytes for the YUV decode |
scroggo
2016/01/04 18:29:16
nit: It seems like no "calculation" is done. Looks
msarett
2016/01/12 14:25:27
Acknowledged. Removed this code anyway.
|
+ size_t rowBytes[3]; |
+ rowBytes[0] = sizes[0].width(); |
+ rowBytes[1] = sizes[1].width(); |
+ rowBytes[2] = sizes[2].width(); |
+ |
+ // Allocate the memory for the YUV decode |
+ size_t totalBytes = rowBytes[0] * sizes[0].height() + rowBytes[1] * sizes[1].height() + |
+ rowBytes[2] * sizes[2].height(); |
+ SkAutoMalloc storage(totalBytes); |
+ void* planes[3]; |
+ planes[0] = storage.get(); |
+ planes[1] = SkTAddOffset<void>(planes[0], rowBytes[0] * sizes[0].height()); |
+ planes[2] = SkTAddOffset<void>(planes[1], rowBytes[1] * sizes[1].height()); |
+ |
+ // Test getYUV8Planes() |
+ REPORTER_ASSERT(reporter, SkCodec::kInvalidInput == |
+ codec->getYUV8Planes(sizes, planes, nullptr, nullptr)); |
+ REPORTER_ASSERT(reporter, SkCodec::kInvalidInput == |
+ codec->getYUV8Planes(sizes, nullptr, rowBytes, nullptr)); |
+ REPORTER_ASSERT(reporter, SkCodec::kInvalidInput == |
+ codec->getYUV8Planes(nullptr, planes, rowBytes, nullptr)); |
+ REPORTER_ASSERT(reporter, SkCodec::kSuccess == |
+ codec->getYUV8Planes(sizes, planes, rowBytes, nullptr)); |
+ SkYUVColorSpace colorSpace; |
+ REPORTER_ASSERT(reporter, SkCodec::kSuccess == |
+ codec->getYUV8Planes(sizes, planes, rowBytes, &colorSpace)); |
+ REPORTER_ASSERT(reporter, SkYUVColorSpace::kJPEG_SkYUVColorSpace == colorSpace); |
+} |
+ |
+DEF_TEST(Jpeg_YUV_Codec, r) { |
+ SkISize sizes[3]; |
+ |
+ sizes[0].set(128, 128); |
+ sizes[1].set(64, 64); |
+ sizes[2].set(64, 64); |
+ codec_yuv(r, "color_wheel.jpg", sizes); |
+ |
+ // H2V2 |
+ sizes[0].set(512, 512); |
+ sizes[1].set(256, 256); |
+ sizes[2].set(256, 256); |
+ codec_yuv(r, "mandrill_512_q075.jpg", sizes); |
+ |
+ // H1V1 |
+ sizes[1].set(512, 512); |
+ sizes[2].set(512, 512); |
+ codec_yuv(r, "mandrill_h1v1.jpg", sizes); |
+ |
+ // H2V1 |
+ sizes[1].set(256, 512); |
+ sizes[2].set(256, 512); |
+ codec_yuv(r, "mandrill_h2v1.jpg", sizes); |
+ |
+ // Non-power of two dimensions |
+ sizes[0].set(440, 154); |
+ sizes[1].set(224, 77); |
+ sizes[2].set(224, 77); |
+ codec_yuv(r, "cropped_mandrill.jpg", sizes); |
+ |
+ sizes[0].set(8, 8); |
+ sizes[1].set(8, 4); |
+ sizes[2].set(8, 4); |
+ codec_yuv(r, "randPixels.jpg", sizes); |
+ |
+ // Progressive images |
+ sizes[0].set(512, 512); |
+ sizes[1].set(512, 512); |
+ sizes[2].set(512, 512); |
+ codec_yuv(r, "brickwork-texture.jpg", sizes); |
+ codec_yuv(r, "brickwork_normal-map.jpg", sizes); |
+ |
+ // A CMYK encoded image should fail. |
+ codec_yuv(r, "CMYK.jpg", nullptr); |
+ // A grayscale encoded image should fail. |
+ codec_yuv(r, "grayscale.jpg", nullptr); |
+ // A PNG should fail. |
+ codec_yuv(r, "arrow.png", nullptr); |
+} |