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"
|
2016-09-16 18:45:58 +00:00
|
|
|
#include "SkCodecPriv.h"
|
2016-10-18 17:02:51 +00:00
|
|
|
#include "SkColorSpace_XYZ.h"
|
2016-06-03 15:25:21 +00:00
|
|
|
#include "SkColorSpaceXform.h"
|
|
|
|
#include "SkCommandLineFlags.h"
|
|
|
|
|
|
|
|
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-10-16 14:20:41 +00:00
|
|
|
DEFINE_bool(nonstd, false, "Convert to non-standard 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))
|
|
|
|
{
|
|
|
|
fName.appendf("Color%s", FLAGS_xform_only ? "Xform" : "Codec");
|
|
|
|
fName.appendf("_%s", name);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* ColorCodecBench::onGetName() {
|
|
|
|
return fName.c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ColorCodecBench::isSuitableFor(Backend backend) {
|
|
|
|
return kNonRendering_Backend == backend;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ColorCodecBench::decodeAndXform() {
|
2016-11-03 18:40:50 +00:00
|
|
|
std::unique_ptr<SkCodec> codec(SkCodec::NewFromData(fEncoded));
|
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
|
|
|
}
|
|
|
|
|
|
|
|
void ColorCodecBench::xformOnly() {
|
2016-11-01 16:19:50 +00:00
|
|
|
std::unique_ptr<SkColorSpaceXform> xform = SkColorSpaceXform::New(fSrcSpace.get(),
|
2016-09-22 14:02:24 +00:00
|
|
|
fDstSpace.get());
|
2016-06-03 15:25:21 +00:00
|
|
|
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-10-11 19:15:03 +00:00
|
|
|
SkAssertResult(xform->apply(select_xform_format(fDstInfo.colorType()), dst,
|
|
|
|
SkColorSpaceXform::kRGBA_8888_ColorFormat, src,
|
|
|
|
fSrcInfo.width(), 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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ColorCodecBench::onDelayedSetup() {
|
2016-11-03 18:40:50 +00:00
|
|
|
std::unique_ptr<SkCodec> codec(SkCodec::NewFromData(fEncoded));
|
2016-07-29 13:23:33 +00:00
|
|
|
fSrcInfo = codec->getInfo().makeColorType(kRGBA_8888_SkColorType);
|
2016-09-14 14:06:08 +00:00
|
|
|
fDstInfo = fSrcInfo;
|
2016-07-29 13:23:33 +00:00
|
|
|
|
2016-11-01 16:19:50 +00:00
|
|
|
fDstSpace = nullptr;
|
|
|
|
if (FLAGS_srgb) {
|
2017-02-07 18:56:11 +00:00
|
|
|
fDstSpace = SkColorSpace::MakeSRGB();
|
2016-11-01 16:19:50 +00:00
|
|
|
} else if (FLAGS_nonstd) {
|
2016-10-28 16:51:08 +00:00
|
|
|
SkColorSpaceTransferFn gamma;
|
|
|
|
gamma.fA = 1.0f;
|
|
|
|
gamma.fB = gamma.fC = gamma.fD = gamma.fE = gamma.fF = 0.0f;
|
|
|
|
gamma.fG = 4.0f;
|
2016-10-16 14:20:41 +00:00
|
|
|
SkMatrix44 matrix = SkMatrix44(SkMatrix44::kUninitialized_Constructor);
|
|
|
|
matrix.set3x3(0.30f, 0.31f, 0.28f, 0.32f, 0.33f, 0.29f, 0.27f, 0.30f, 0.30f);
|
2016-10-28 16:51:08 +00:00
|
|
|
fDstSpace = SkColorSpace::MakeRGB(gamma, matrix);
|
2016-11-01 16:19:50 +00:00
|
|
|
} else {
|
|
|
|
sk_sp<SkData> dstData = SkData::MakeFromFileName(
|
|
|
|
GetResourcePath("icc_profiles/HP_ZR30w.icc").c_str());
|
|
|
|
SkASSERT(dstData);
|
|
|
|
fDstSpace = SkColorSpace::MakeICC(dstData->data(), dstData->size());
|
2016-10-16 14:20:41 +00:00
|
|
|
}
|
2016-11-01 16:19:50 +00:00
|
|
|
SkASSERT(fDstSpace);
|
2016-09-14 14:06:08 +00:00
|
|
|
fDstInfo = fDstInfo.makeColorSpace(fDstSpace);
|
2016-09-08 18:55:16 +00:00
|
|
|
|
2016-11-01 16:19:50 +00:00
|
|
|
if (FLAGS_half) {
|
|
|
|
fDstInfo = fDstInfo.makeColorType(kRGBA_F16_SkColorType);
|
|
|
|
SkASSERT(SkColorSpace_Base::Type::kXYZ == as_CSB(fDstSpace)->type());
|
|
|
|
fDstSpace = static_cast<SkColorSpace_XYZ*>(fDstSpace.get())->makeLinearGamma();
|
|
|
|
}
|
|
|
|
|
2016-07-29 13:23:33 +00:00
|
|
|
fDst.reset(fDstInfo.getSafeSize(fDstInfo.minRowBytes()));
|
|
|
|
|
|
|
|
if (FLAGS_xform_only) {
|
|
|
|
fSrc.reset(fSrcInfo.getSafeSize(fSrcInfo.minRowBytes()));
|
2017-01-12 15:13:40 +00:00
|
|
|
fSrcSpace = codec->getInfo().refColorSpace();
|
2016-07-29 13:23:33 +00:00
|
|
|
codec->getPixels(fSrcInfo, fSrc.get(), fSrcInfo.minRowBytes());
|
|
|
|
}
|
2016-06-03 15:25:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ColorCodecBench::onDraw(int n, SkCanvas*) {
|
|
|
|
for (int i = 0; i < n; i++) {
|
2016-11-01 16:19:50 +00:00
|
|
|
if (FLAGS_xform_only) {
|
|
|
|
this->xformOnly();
|
|
|
|
} else {
|
|
|
|
this->decodeAndXform();
|
2016-06-03 15:25:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|