2016-06-03 15:25:21 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2016 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ColorCodecBench.h"
|
|
|
|
#include "Resources.h"
|
|
|
|
#include "SkCodec.h"
|
|
|
|
#include "SkColorSpaceXform.h"
|
|
|
|
#include "SkCommandLineFlags.h"
|
|
|
|
|
2016-06-06 15:20:37 +00:00
|
|
|
#if defined(SK_TEST_QCMS)
|
2016-06-20 13:07:45 +00:00
|
|
|
DEFINE_bool(qcms, false, "Bench qcms color conversion");
|
2016-06-03 15:25:21 +00:00
|
|
|
#endif
|
|
|
|
DEFINE_bool(xform_only, false, "Only time the color xform, do not include the decode time");
|
2016-06-20 13:07:45 +00:00
|
|
|
DEFINE_bool(srgb, false, "Convert to srgb dst space");
|
2016-07-19 16:07:55 +00:00
|
|
|
DEFINE_bool(half, false, "Convert to half floats");
|
2016-06-03 15:25:21 +00:00
|
|
|
|
|
|
|
ColorCodecBench::ColorCodecBench(const char* name, sk_sp<SkData> encoded)
|
|
|
|
: fEncoded(std::move(encoded))
|
2016-06-06 15:20:37 +00:00
|
|
|
#if defined(SK_TEST_QCMS)
|
2016-06-03 15:25:21 +00:00
|
|
|
, fDstSpaceQCMS(nullptr)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
fName.appendf("Color%s", FLAGS_xform_only ? "Xform" : "Codec");
|
2016-06-06 15:20:37 +00:00
|
|
|
#if defined(SK_TEST_QCMS)
|
2016-06-03 15:25:21 +00:00
|
|
|
fName.appendf("%s", FLAGS_qcms ? "QCMS" : "");
|
|
|
|
#endif
|
|
|
|
fName.appendf("_%s", name);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* ColorCodecBench::onGetName() {
|
|
|
|
return fName.c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ColorCodecBench::isSuitableFor(Backend backend) {
|
|
|
|
return kNonRendering_Backend == backend;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ColorCodecBench::decodeAndXform() {
|
|
|
|
SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(fEncoded.get()));
|
2016-07-29 13:23:33 +00:00
|
|
|
SkASSERT(codec);
|
2016-07-29 00:11:18 +00:00
|
|
|
|
|
|
|
#ifdef SK_DEBUG
|
2016-07-29 13:23:33 +00:00
|
|
|
SkCodec::Result result =
|
2016-07-29 00:11:18 +00:00
|
|
|
#endif
|
2016-07-29 13:23:33 +00:00
|
|
|
codec->getPixels(fDstInfo, fDst.get(), fDstInfo.minRowBytes());
|
|
|
|
SkASSERT(SkCodec::kSuccess == result);
|
2016-06-03 15:25:21 +00:00
|
|
|
}
|
|
|
|
|
2016-06-06 15:20:37 +00:00
|
|
|
#if defined(SK_TEST_QCMS)
|
2016-06-03 15:25:21 +00:00
|
|
|
void ColorCodecBench::decodeAndXformQCMS() {
|
|
|
|
SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(fEncoded.get()));
|
|
|
|
#ifdef SK_DEBUG
|
|
|
|
const SkCodec::Result result =
|
|
|
|
#endif
|
2016-07-19 16:07:55 +00:00
|
|
|
codec->startScanlineDecode(fSrcInfo);
|
2016-06-03 15:25:21 +00:00
|
|
|
SkASSERT(SkCodec::kSuccess == result);
|
|
|
|
|
|
|
|
SkAutoTCallVProc<qcms_profile, qcms_profile_release>
|
|
|
|
srcSpace(qcms_profile_from_memory(fSrcData->data(), fSrcData->size()));
|
|
|
|
SkASSERT(srcSpace);
|
|
|
|
|
|
|
|
SkAutoTCallVProc<qcms_transform, qcms_transform_release>
|
|
|
|
transform (qcms_transform_create(srcSpace, QCMS_DATA_RGBA_8, fDstSpaceQCMS.get(),
|
|
|
|
QCMS_DATA_RGBA_8, QCMS_INTENT_PERCEPTUAL));
|
|
|
|
SkASSERT(transform);
|
|
|
|
|
|
|
|
#ifdef SK_PMCOLOR_IS_RGBA
|
|
|
|
qcms_output_type outType = QCMS_OUTPUT_RGBX;
|
|
|
|
#else
|
|
|
|
qcms_output_type outType = QCMS_OUTPUT_BGRX;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void* dst = fDst.get();
|
2016-07-19 16:07:55 +00:00
|
|
|
for (int y = 0; y < fSrcInfo.height(); y++) {
|
2016-06-03 15:25:21 +00:00
|
|
|
#ifdef SK_DEBUG
|
|
|
|
const int rows =
|
|
|
|
#endif
|
|
|
|
codec->getScanlines(fSrc.get(), 1, 0);
|
|
|
|
SkASSERT(1 == rows);
|
|
|
|
|
2016-07-19 16:07:55 +00:00
|
|
|
qcms_transform_data_type(transform, fSrc.get(), dst, fSrcInfo.width(), outType);
|
|
|
|
dst = SkTAddOffset<void>(dst, fDstInfo.minRowBytes());
|
2016-06-03 15:25:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void ColorCodecBench::xformOnly() {
|
|
|
|
sk_sp<SkColorSpace> srcSpace = SkColorSpace::NewICC(fSrcData->data(), fSrcData->size());
|
|
|
|
if (!srcSpace) {
|
|
|
|
srcSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named);
|
|
|
|
}
|
|
|
|
std::unique_ptr<SkColorSpaceXform> xform = SkColorSpaceXform::New(srcSpace, fDstSpace);
|
|
|
|
SkASSERT(xform);
|
|
|
|
|
|
|
|
void* dst = fDst.get();
|
|
|
|
void* src = fSrc.get();
|
2016-07-19 16:07:55 +00:00
|
|
|
for (int y = 0; y < fSrcInfo.height(); y++) {
|
2016-08-03 19:59:27 +00:00
|
|
|
xform->apply(dst, (uint32_t*) src, fSrcInfo.width(), fDstInfo.colorType(),
|
|
|
|
fDstInfo.alphaType());
|
2016-07-19 16:07:55 +00:00
|
|
|
dst = SkTAddOffset<void>(dst, fDstInfo.minRowBytes());
|
|
|
|
src = SkTAddOffset<void>(src, fSrcInfo.minRowBytes());
|
2016-06-03 15:25:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-06 15:20:37 +00:00
|
|
|
#if defined(SK_TEST_QCMS)
|
2016-06-03 15:25:21 +00:00
|
|
|
void ColorCodecBench::xformOnlyQCMS() {
|
|
|
|
SkAutoTCallVProc<qcms_profile, qcms_profile_release>
|
|
|
|
srcSpace(qcms_profile_from_memory(fSrcData->data(), fSrcData->size()));
|
|
|
|
SkASSERT(srcSpace);
|
|
|
|
|
|
|
|
SkAutoTCallVProc<qcms_transform, qcms_transform_release>
|
|
|
|
transform (qcms_transform_create(srcSpace, QCMS_DATA_RGBA_8, fDstSpaceQCMS.get(),
|
|
|
|
QCMS_DATA_RGBA_8, QCMS_INTENT_PERCEPTUAL));
|
|
|
|
SkASSERT(transform);
|
|
|
|
|
|
|
|
#ifdef SK_PMCOLOR_IS_RGBA
|
|
|
|
qcms_output_type outType = QCMS_OUTPUT_RGBX;
|
|
|
|
#else
|
|
|
|
qcms_output_type outType = QCMS_OUTPUT_BGRX;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void* dst = fDst.get();
|
|
|
|
void* src = fSrc.get();
|
2016-07-19 16:07:55 +00:00
|
|
|
for (int y = 0; y < fSrcInfo.height(); y++) {
|
2016-06-03 15:25:21 +00:00
|
|
|
// Transform in place
|
2016-07-19 16:07:55 +00:00
|
|
|
qcms_transform_data_type(transform, src, dst, fSrcInfo.width(), outType);
|
|
|
|
dst = SkTAddOffset<void>(dst, fDstInfo.minRowBytes());
|
|
|
|
src = SkTAddOffset<void>(src, fSrcInfo.minRowBytes());
|
2016-06-03 15:25:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void ColorCodecBench::onDelayedSetup() {
|
|
|
|
SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(fEncoded.get()));
|
|
|
|
fSrcData = codec->getICCData();
|
|
|
|
sk_sp<SkData> dstData = SkData::MakeFromFileName(
|
2016-07-29 15:58:33 +00:00
|
|
|
GetResourcePath("icc_profiles/HP_ZR30w.icc").c_str());
|
2016-06-03 15:25:21 +00:00
|
|
|
SkASSERT(dstData);
|
|
|
|
|
2016-07-29 13:23:33 +00:00
|
|
|
fDstSpace = nullptr;
|
2016-06-06 15:20:37 +00:00
|
|
|
#if defined(SK_TEST_QCMS)
|
2016-06-03 15:25:21 +00:00
|
|
|
if (FLAGS_qcms) {
|
2016-06-20 13:07:45 +00:00
|
|
|
fDstSpaceQCMS.reset(FLAGS_srgb ?
|
|
|
|
qcms_profile_sRGB() :
|
|
|
|
qcms_profile_from_memory(dstData->data(), dstData->size()));
|
2016-06-03 15:25:21 +00:00
|
|
|
SkASSERT(fDstSpaceQCMS);
|
2016-06-08 21:43:53 +00:00
|
|
|
|
|
|
|
// This call takes a non-trivial amount of time, but I think it's the most fair to
|
|
|
|
// treat it as overhead. It only needs to happen once.
|
|
|
|
qcms_profile_precache_output_transform(fDstSpaceQCMS);
|
2016-06-03 15:25:21 +00:00
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
2016-06-20 13:07:45 +00:00
|
|
|
fDstSpace = FLAGS_srgb ? SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named) :
|
|
|
|
SkColorSpace::NewICC(dstData->data(), dstData->size());
|
2016-06-03 15:25:21 +00:00
|
|
|
SkASSERT(fDstSpace);
|
|
|
|
}
|
2016-07-29 13:23:33 +00:00
|
|
|
|
|
|
|
fSrcInfo = codec->getInfo().makeColorType(kRGBA_8888_SkColorType);
|
|
|
|
|
|
|
|
if (FLAGS_half) {
|
|
|
|
fDstInfo = fDstInfo.makeColorType(kRGBA_F16_SkColorType);
|
2016-09-08 18:55:16 +00:00
|
|
|
fDstSpace = fDstSpace->makeLinearGamma();
|
2016-07-29 13:23:33 +00:00
|
|
|
}
|
2016-09-08 18:55:16 +00:00
|
|
|
|
|
|
|
fDstInfo = fSrcInfo.makeColorSpace(fDstSpace);
|
|
|
|
|
2016-07-29 13:23:33 +00:00
|
|
|
fDst.reset(fDstInfo.getSafeSize(fDstInfo.minRowBytes()));
|
|
|
|
|
|
|
|
if (FLAGS_xform_only) {
|
|
|
|
fSrc.reset(fSrcInfo.getSafeSize(fSrcInfo.minRowBytes()));
|
|
|
|
codec->getPixels(fSrcInfo, fSrc.get(), fSrcInfo.minRowBytes());
|
|
|
|
}
|
|
|
|
#if defined(SK_TEST_QCMS)
|
|
|
|
else if (FLAGS_qcms) {
|
|
|
|
// Set-up a row buffer to decode into before transforming to dst.
|
|
|
|
fSrc.reset(fSrcInfo.minRowBytes());
|
|
|
|
}
|
|
|
|
#endif
|
2016-06-03 15:25:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ColorCodecBench::onDraw(int n, SkCanvas*) {
|
2016-07-19 20:00:35 +00:00
|
|
|
#if defined(SK_TEST_QCMS)
|
2016-08-15 15:10:44 +00:00
|
|
|
if (FLAGS_qcms && FLAGS_half) {
|
2016-07-19 16:07:55 +00:00
|
|
|
SkDebugf("Error: Contradicting flags.\n");
|
|
|
|
return;
|
|
|
|
}
|
2016-08-15 15:10:44 +00:00
|
|
|
#endif
|
2016-07-19 16:07:55 +00:00
|
|
|
|
2016-06-03 15:25:21 +00:00
|
|
|
for (int i = 0; i < n; i++) {
|
2016-06-06 15:20:37 +00:00
|
|
|
#if defined(SK_TEST_QCMS)
|
2016-06-03 15:25:21 +00:00
|
|
|
if (FLAGS_qcms) {
|
|
|
|
if (FLAGS_xform_only) {
|
|
|
|
this->xformOnlyQCMS();
|
|
|
|
} else {
|
|
|
|
this->decodeAndXformQCMS();
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
if (FLAGS_xform_only) {
|
|
|
|
this->xformOnly();
|
|
|
|
} else {
|
|
|
|
this->decodeAndXform();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|