2016-02-11 22:17:17 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2013 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2017-01-11 17:21:57 +00:00
|
|
|
#include "Resources.h"
|
2017-01-11 17:44:43 +00:00
|
|
|
#include "SkAutoMalloc.h"
|
|
|
|
#include "SkCodec.h"
|
2016-02-11 22:17:17 +00:00
|
|
|
#include "SkStream.h"
|
|
|
|
#include "SkTemplates.h"
|
2016-03-10 13:44:43 +00:00
|
|
|
#include "SkYUVSizeInfo.h"
|
2016-02-11 22:17:17 +00:00
|
|
|
#include "Test.h"
|
|
|
|
|
|
|
|
static void codec_yuv(skiatest::Reporter* reporter,
|
2018-10-18 18:36:59 +00:00
|
|
|
const char path[],
|
|
|
|
SkISize expectedSizes[4]) {
|
2016-11-03 18:40:50 +00:00
|
|
|
std::unique_ptr<SkStream> stream(GetResourceAsStream(path));
|
2016-02-11 22:17:17 +00:00
|
|
|
if (!stream) {
|
|
|
|
return;
|
|
|
|
}
|
2017-07-23 19:30:02 +00:00
|
|
|
std::unique_ptr<SkCodec> codec(SkCodec::MakeFromStream(std::move(stream)));
|
2016-02-11 22:17:17 +00:00
|
|
|
REPORTER_ASSERT(reporter, codec);
|
|
|
|
if (!codec) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test queryYUV8()
|
2016-03-10 13:44:43 +00:00
|
|
|
SkYUVSizeInfo info;
|
2018-10-18 18:36:59 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
bool success = codec->queryYUV8(nullptr, nullptr);
|
|
|
|
REPORTER_ASSERT(reporter, !success);
|
|
|
|
success = codec->queryYUV8(&info, nullptr);
|
|
|
|
REPORTER_ASSERT(reporter, (expectedSizes == nullptr) == !success);
|
|
|
|
if (!success) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < SkYUVSizeInfo::kMaxCount; ++i) {
|
|
|
|
REPORTER_ASSERT(reporter, info.fSizes[i] == expectedSizes[i]);
|
|
|
|
REPORTER_ASSERT(reporter,
|
|
|
|
info.fWidthBytes[i] == (uint32_t) SkAlign8(info.fSizes[i].width()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
SkYUVColorSpace colorSpace;
|
|
|
|
bool success = codec->queryYUV8(&info, &colorSpace);
|
|
|
|
REPORTER_ASSERT(reporter, (expectedSizes == nullptr) == !success);
|
|
|
|
if (!success) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < SkYUVSizeInfo::kMaxCount; ++i) {
|
|
|
|
REPORTER_ASSERT(reporter, info.fSizes[i] == expectedSizes[i]);
|
|
|
|
REPORTER_ASSERT(reporter,
|
|
|
|
info.fWidthBytes[i] == (uint32_t) SkAlign8(info.fSizes[i].width()));
|
|
|
|
}
|
|
|
|
REPORTER_ASSERT(reporter, kJPEG_SkYUVColorSpace == colorSpace);
|
2016-02-11 22:17:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Allocate the memory for the YUV decode
|
2018-10-18 18:36:59 +00:00
|
|
|
size_t totalBytes = info.computeTotalBytes();
|
|
|
|
|
2016-02-11 22:17:17 +00:00
|
|
|
SkAutoMalloc storage(totalBytes);
|
2018-10-18 18:36:59 +00:00
|
|
|
void* planes[SkYUVSizeInfo::kMaxCount];
|
|
|
|
|
|
|
|
info.computePlanes(storage.get(), planes);
|
2016-02-11 22:17:17 +00:00
|
|
|
|
|
|
|
// Test getYUV8Planes()
|
2018-10-18 18:36:59 +00:00
|
|
|
REPORTER_ASSERT(reporter, SkCodec::kInvalidInput == codec->getYUV8Planes(info, nullptr));
|
|
|
|
REPORTER_ASSERT(reporter, SkCodec::kSuccess == codec->getYUV8Planes(info, planes));
|
2016-02-11 22:17:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DEF_TEST(Jpeg_YUV_Codec, r) {
|
2018-10-18 18:36:59 +00:00
|
|
|
SkISize sizes[4];
|
2016-02-11 22:17:17 +00:00
|
|
|
|
|
|
|
sizes[0].set(128, 128);
|
|
|
|
sizes[1].set(64, 64);
|
|
|
|
sizes[2].set(64, 64);
|
2018-10-18 18:36:59 +00:00
|
|
|
sizes[3].set(0, 0);
|
2017-12-08 15:21:31 +00:00
|
|
|
codec_yuv(r, "images/color_wheel.jpg", sizes);
|
2016-02-11 22:17:17 +00:00
|
|
|
|
|
|
|
// H2V2
|
|
|
|
sizes[0].set(512, 512);
|
|
|
|
sizes[1].set(256, 256);
|
|
|
|
sizes[2].set(256, 256);
|
2017-12-08 15:21:31 +00:00
|
|
|
codec_yuv(r, "images/mandrill_512_q075.jpg", sizes);
|
2016-02-11 22:17:17 +00:00
|
|
|
|
|
|
|
// H1V1
|
|
|
|
sizes[1].set(512, 512);
|
|
|
|
sizes[2].set(512, 512);
|
2017-12-08 15:21:31 +00:00
|
|
|
codec_yuv(r, "images/mandrill_h1v1.jpg", sizes);
|
2016-02-11 22:17:17 +00:00
|
|
|
|
|
|
|
// H2V1
|
|
|
|
sizes[1].set(256, 512);
|
|
|
|
sizes[2].set(256, 512);
|
2017-12-08 15:21:31 +00:00
|
|
|
codec_yuv(r, "images/mandrill_h2v1.jpg", sizes);
|
2016-02-11 22:17:17 +00:00
|
|
|
|
|
|
|
// Non-power of two dimensions
|
|
|
|
sizes[0].set(439, 154);
|
|
|
|
sizes[1].set(220, 77);
|
|
|
|
sizes[2].set(220, 77);
|
2017-12-08 15:21:31 +00:00
|
|
|
codec_yuv(r, "images/cropped_mandrill.jpg", sizes);
|
2016-02-11 22:17:17 +00:00
|
|
|
|
|
|
|
sizes[0].set(8, 8);
|
|
|
|
sizes[1].set(4, 4);
|
|
|
|
sizes[2].set(4, 4);
|
2017-12-08 15:21:31 +00:00
|
|
|
codec_yuv(r, "images/randPixels.jpg", sizes);
|
2016-02-11 22:17:17 +00:00
|
|
|
|
|
|
|
// Progressive images
|
|
|
|
sizes[0].set(512, 512);
|
|
|
|
sizes[1].set(512, 512);
|
|
|
|
sizes[2].set(512, 512);
|
2017-12-08 15:21:31 +00:00
|
|
|
codec_yuv(r, "images/brickwork-texture.jpg", sizes);
|
|
|
|
codec_yuv(r, "images/brickwork_normal-map.jpg", sizes);
|
2016-02-11 22:17:17 +00:00
|
|
|
|
|
|
|
// A CMYK encoded image should fail.
|
2017-12-08 15:21:31 +00:00
|
|
|
codec_yuv(r, "images/CMYK.jpg", nullptr);
|
2016-02-11 22:17:17 +00:00
|
|
|
// A grayscale encoded image should fail.
|
2017-12-08 15:21:31 +00:00
|
|
|
codec_yuv(r, "images/grayscale.jpg", nullptr);
|
2016-02-11 22:17:17 +00:00
|
|
|
// A PNG should fail.
|
2017-12-08 15:21:31 +00:00
|
|
|
codec_yuv(r, "images/arrow.png", nullptr);
|
2016-02-11 22:17:17 +00:00
|
|
|
}
|