| Index: tests/JpegTest.cpp
|
| diff --git a/tests/JpegTest.cpp b/tests/JpegTest.cpp
|
| index d61b0bd3111cd89f62930c3ed9cff2d81b3abea9..aadf87a3b5582aa14bc387d0638462f12ddc5ed1 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,121 @@ 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[],
|
| + SkCodec::YUVPlanesSizes* expectedSizes) {
|
| + 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 queryYUV8()
|
| + SkCodec::YUVPlanesSizes sizes;
|
| + SkCodec::YUVPlanesWidthBytes widthBytes;
|
| + bool success = codec->queryYUV8(nullptr, nullptr, nullptr);
|
| + REPORTER_ASSERT(reporter, !success);
|
| + success = codec->queryYUV8(&sizes, nullptr, nullptr);
|
| + REPORTER_ASSERT(reporter, !success);
|
| + success = codec->queryYUV8(nullptr, &widthBytes, nullptr);
|
| + REPORTER_ASSERT(reporter, !success);
|
| + success = codec->queryYUV8(&sizes, &widthBytes, nullptr);
|
| + REPORTER_ASSERT(reporter, (expectedSizes == nullptr) == !success);
|
| + if (!success) {
|
| + return;
|
| + }
|
| + REPORTER_ASSERT(reporter,
|
| + 0 == memcmp((const void*) &sizes, (const void*) expectedSizes, sizeof(sizes)));
|
| + REPORTER_ASSERT(reporter, widthBytes.YWidthBytes == (uint32_t) SkAlign8(sizes.YSize.width()));
|
| + REPORTER_ASSERT(reporter, widthBytes.UWidthBytes == (uint32_t) SkAlign8(sizes.USize.width()));
|
| + REPORTER_ASSERT(reporter, widthBytes.VWidthBytes == (uint32_t) SkAlign8(sizes.VSize.width()));
|
| + SkYUVColorSpace colorSpace;
|
| + success = codec->queryYUV8(&sizes, &widthBytes, &colorSpace);
|
| + REPORTER_ASSERT(reporter,
|
| + 0 == memcmp((const void*) &sizes, (const void*) expectedSizes, sizeof(sizes)));
|
| + REPORTER_ASSERT(reporter, widthBytes.YWidthBytes == (uint32_t) SkAlign8(sizes.YSize.width()));
|
| + REPORTER_ASSERT(reporter, widthBytes.UWidthBytes == (uint32_t) SkAlign8(sizes.USize.width()));
|
| + REPORTER_ASSERT(reporter, widthBytes.VWidthBytes == (uint32_t) SkAlign8(sizes.VSize.width()));
|
| + REPORTER_ASSERT(reporter, kJPEG_SkYUVColorSpace == colorSpace);
|
| +
|
| + // Allocate the memory for the YUV decode
|
| + size_t totalBytes = widthBytes.YWidthBytes * sizes.YSize.height() +
|
| + widthBytes.UWidthBytes * sizes.USize.height() +
|
| + widthBytes.VWidthBytes * sizes.VSize.height();
|
| + SkAutoMalloc storage(totalBytes);
|
| + void* planes[3];
|
| + planes[0] = storage.get();
|
| + planes[1] = SkTAddOffset<void>(planes[0], widthBytes.YWidthBytes * sizes.YSize.height());
|
| + planes[2] = SkTAddOffset<void>(planes[1], widthBytes.UWidthBytes * sizes.USize.height());
|
| +
|
| + // Test getYUV8Planes()
|
| + REPORTER_ASSERT(reporter, SkCodec::kInvalidInput ==
|
| + codec->getYUV8Planes(&sizes, planes, nullptr));
|
| + REPORTER_ASSERT(reporter, SkCodec::kInvalidInput ==
|
| + codec->getYUV8Planes(&sizes, nullptr, &widthBytes));
|
| + REPORTER_ASSERT(reporter, SkCodec::kInvalidInput ==
|
| + codec->getYUV8Planes(nullptr, planes, &widthBytes));
|
| + REPORTER_ASSERT(reporter, SkCodec::kSuccess ==
|
| + codec->getYUV8Planes(&sizes, planes, &widthBytes));
|
| +}
|
| +
|
| +DEF_TEST(Jpeg_YUV_Codec, r) {
|
| + SkCodec::YUVPlanesSizes sizes;
|
| +
|
| + sizes.YSize.set(128, 128);
|
| + sizes.USize.set(64, 64);
|
| + sizes.VSize.set(64, 64);
|
| + codec_yuv(r, "color_wheel.jpg", &sizes);
|
| +
|
| + // H2V2
|
| + sizes.YSize.set(512, 512);
|
| + sizes.USize.set(256, 256);
|
| + sizes.VSize.set(256, 256);
|
| + codec_yuv(r, "mandrill_512_q075.jpg", &sizes);
|
| +
|
| + // H1V1
|
| + sizes.USize.set(512, 512);
|
| + sizes.VSize.set(512, 512);
|
| + codec_yuv(r, "mandrill_h1v1.jpg", &sizes);
|
| +
|
| + // H2V1
|
| + sizes.USize.set(256, 512);
|
| + sizes.VSize.set(256, 512);
|
| + codec_yuv(r, "mandrill_h2v1.jpg", &sizes);
|
| +
|
| + // Non-power of two dimensions
|
| + sizes.YSize.set(439, 154);
|
| + sizes.USize.set(220, 77);
|
| + sizes.VSize.set(220, 77);
|
| + codec_yuv(r, "cropped_mandrill.jpg", &sizes);
|
| +
|
| + sizes.YSize.set(8, 8);
|
| + sizes.USize.set(4, 4);
|
| + sizes.VSize.set(4, 4);
|
| + codec_yuv(r, "randPixels.jpg", &sizes);
|
| +
|
| + // Progressive images
|
| + sizes.YSize.set(512, 512);
|
| + sizes.USize.set(512, 512);
|
| + sizes.VSize.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);
|
| +}
|
|
|