update callers to not use SkColorProfileType
Requires https://codereview.chromium.org/2087833002/ to land first. BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2086583002 Review-Url: https://codereview.chromium.org/2086583002
This commit is contained in:
parent
db197a54b5
commit
dabe5d3780
@ -17,12 +17,12 @@
|
||||
struct CommonBitmapFPBenchmark : public Benchmark {
|
||||
CommonBitmapFPBenchmark(
|
||||
SkISize srcSize,
|
||||
SkColorProfileType colorProfile,
|
||||
bool isSRGB,
|
||||
SkMatrix m,
|
||||
bool useBilerp,
|
||||
SkShader::TileMode xTile,
|
||||
SkShader::TileMode yTile)
|
||||
: fColorProfile(colorProfile)
|
||||
: fIsSRGB(isSRGB)
|
||||
, fM{m}
|
||||
, fUseBilerp{useBilerp}
|
||||
, fXTile{xTile}
|
||||
@ -89,7 +89,8 @@ struct CommonBitmapFPBenchmark : public Benchmark {
|
||||
bool trash = fM.invert(&fInvert);
|
||||
sk_ignore_unused_variable(trash);
|
||||
|
||||
fInfo = SkImageInfo::MakeN32Premul(width, height, fColorProfile);
|
||||
fInfo = SkImageInfo::MakeN32Premul(width, height, fIsSRGB ?
|
||||
SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named) : nullptr);
|
||||
}
|
||||
|
||||
bool isSuitableFor(Backend backend) override {
|
||||
@ -100,7 +101,7 @@ struct CommonBitmapFPBenchmark : public Benchmark {
|
||||
|
||||
SkString fName;
|
||||
SkISize fSrcSize;
|
||||
SkColorProfileType fColorProfile;
|
||||
bool fIsSRGB;
|
||||
SkMatrix fM;
|
||||
SkMatrix fInvert;
|
||||
bool fUseBilerp;
|
||||
@ -113,16 +114,16 @@ struct CommonBitmapFPBenchmark : public Benchmark {
|
||||
struct SkBitmapFPGeneral final : public CommonBitmapFPBenchmark {
|
||||
SkBitmapFPGeneral(
|
||||
SkISize srcSize,
|
||||
SkColorProfileType colorProfile,
|
||||
bool isSRGB,
|
||||
SkMatrix m,
|
||||
bool useBilerp,
|
||||
SkShader::TileMode xTile,
|
||||
SkShader::TileMode yTile)
|
||||
: CommonBitmapFPBenchmark(srcSize, colorProfile, m, useBilerp, xTile, yTile) { }
|
||||
: CommonBitmapFPBenchmark(srcSize, isSRGB, m, useBilerp, xTile, yTile) { }
|
||||
|
||||
SkString BaseName() override {
|
||||
SkString name;
|
||||
if (fInfo.isSRGB()) {
|
||||
if (fInfo.gammaCloseToSRGB()) {
|
||||
name.set("sRGB");
|
||||
} else {
|
||||
name.set("Linr");
|
||||
@ -159,12 +160,12 @@ struct SkBitmapFPGeneral final : public CommonBitmapFPBenchmark {
|
||||
struct SkBitmapFPOrigShader : public CommonBitmapFPBenchmark {
|
||||
SkBitmapFPOrigShader(
|
||||
SkISize srcSize,
|
||||
SkColorProfileType colorProfile,
|
||||
bool isSRGB,
|
||||
SkMatrix m,
|
||||
bool useBilerp,
|
||||
SkShader::TileMode xTile,
|
||||
SkShader::TileMode yTile)
|
||||
: CommonBitmapFPBenchmark(srcSize, colorProfile, m, useBilerp, xTile, yTile) { }
|
||||
: CommonBitmapFPBenchmark(srcSize, isSRGB, m, useBilerp, xTile, yTile) { }
|
||||
|
||||
SkString BaseName() override {
|
||||
SkString name{"Orig"};
|
||||
@ -212,80 +213,82 @@ struct SkBitmapFPOrigShader : public CommonBitmapFPBenchmark {
|
||||
sk_sp<SkImage> fImage;
|
||||
};
|
||||
|
||||
const bool gSRGB = true;
|
||||
const bool gLinearRGB = false;
|
||||
static SkISize srcSize = SkISize::Make(120, 100);
|
||||
static SkMatrix mI = SkMatrix::I();
|
||||
DEF_BENCH(return new SkBitmapFPGeneral(
|
||||
srcSize, kSRGB_SkColorProfileType, mI, false,
|
||||
srcSize, gSRGB, mI, false,
|
||||
SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);)
|
||||
|
||||
DEF_BENCH(return new SkBitmapFPGeneral(
|
||||
srcSize, kLinear_SkColorProfileType, mI, false,
|
||||
srcSize, gLinearRGB, mI, false,
|
||||
SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);)
|
||||
|
||||
DEF_BENCH(return new SkBitmapFPOrigShader(
|
||||
srcSize, kLinear_SkColorProfileType, mI, false,
|
||||
srcSize, gLinearRGB, mI, false,
|
||||
SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);)
|
||||
|
||||
DEF_BENCH(return new SkBitmapFPGeneral(
|
||||
srcSize, kSRGB_SkColorProfileType, mI, true,
|
||||
srcSize, gSRGB, mI, true,
|
||||
SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);)
|
||||
|
||||
DEF_BENCH(return new SkBitmapFPGeneral(
|
||||
srcSize, kLinear_SkColorProfileType, mI, true,
|
||||
srcSize, gLinearRGB, mI, true,
|
||||
SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);)
|
||||
|
||||
DEF_BENCH(return new SkBitmapFPOrigShader(
|
||||
srcSize, kLinear_SkColorProfileType, mI, true,
|
||||
srcSize, gLinearRGB, mI, true,
|
||||
SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);)
|
||||
|
||||
static SkMatrix mS = SkMatrix::MakeScale(2.7f, 2.7f);
|
||||
DEF_BENCH(return new SkBitmapFPGeneral(
|
||||
srcSize, kSRGB_SkColorProfileType, mS, false,
|
||||
srcSize, gSRGB, mS, false,
|
||||
SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);)
|
||||
|
||||
DEF_BENCH(return new SkBitmapFPGeneral(
|
||||
srcSize, kLinear_SkColorProfileType, mS, false,
|
||||
srcSize, gLinearRGB, mS, false,
|
||||
SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);)
|
||||
|
||||
DEF_BENCH(return new SkBitmapFPOrigShader(
|
||||
srcSize, kLinear_SkColorProfileType, mS, false,
|
||||
srcSize, gLinearRGB, mS, false,
|
||||
SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);)
|
||||
|
||||
DEF_BENCH(return new SkBitmapFPGeneral(
|
||||
srcSize, kSRGB_SkColorProfileType, mS, true,
|
||||
srcSize, gSRGB, mS, true,
|
||||
SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);)
|
||||
|
||||
DEF_BENCH(return new SkBitmapFPGeneral(
|
||||
srcSize, kLinear_SkColorProfileType, mS, true,
|
||||
srcSize, gLinearRGB, mS, true,
|
||||
SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);)
|
||||
|
||||
DEF_BENCH(return new SkBitmapFPOrigShader(
|
||||
srcSize, kLinear_SkColorProfileType, mS, true,
|
||||
srcSize, gLinearRGB, mS, true,
|
||||
SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);)
|
||||
|
||||
// Repeat
|
||||
DEF_BENCH(return new SkBitmapFPGeneral(
|
||||
srcSize, kSRGB_SkColorProfileType, mS, false,
|
||||
srcSize, gSRGB, mS, false,
|
||||
SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode);)
|
||||
|
||||
DEF_BENCH(return new SkBitmapFPGeneral(
|
||||
srcSize, kLinear_SkColorProfileType, mS, false,
|
||||
srcSize, gLinearRGB, mS, false,
|
||||
SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode);)
|
||||
|
||||
DEF_BENCH(return new SkBitmapFPOrigShader(
|
||||
srcSize, kLinear_SkColorProfileType, mS, false,
|
||||
srcSize, gLinearRGB, mS, false,
|
||||
SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode);)
|
||||
|
||||
DEF_BENCH(return new SkBitmapFPGeneral(
|
||||
srcSize, kSRGB_SkColorProfileType, mS, true,
|
||||
srcSize, gSRGB, mS, true,
|
||||
SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode);)
|
||||
|
||||
DEF_BENCH(return new SkBitmapFPGeneral(
|
||||
srcSize, kLinear_SkColorProfileType, mS, true,
|
||||
srcSize, gLinearRGB, mS, true,
|
||||
SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode);)
|
||||
|
||||
DEF_BENCH(return new SkBitmapFPOrigShader(
|
||||
srcSize, kLinear_SkColorProfileType, mS, true,
|
||||
srcSize, gLinearRGB, mS, true,
|
||||
SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode);)
|
||||
|
||||
static SkMatrix rotate(SkScalar r) {
|
||||
@ -296,50 +299,50 @@ static SkMatrix rotate(SkScalar r) {
|
||||
|
||||
static SkMatrix mR = rotate(30);
|
||||
DEF_BENCH(return new SkBitmapFPGeneral(
|
||||
srcSize, kSRGB_SkColorProfileType, mR, false,
|
||||
srcSize, gSRGB, mR, false,
|
||||
SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);)
|
||||
|
||||
DEF_BENCH(return new SkBitmapFPGeneral(
|
||||
srcSize, kLinear_SkColorProfileType, mR, false,
|
||||
srcSize, gLinearRGB, mR, false,
|
||||
SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);)
|
||||
|
||||
DEF_BENCH(return new SkBitmapFPOrigShader(
|
||||
srcSize, kLinear_SkColorProfileType, mR, false,
|
||||
srcSize, gLinearRGB, mR, false,
|
||||
SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);)
|
||||
|
||||
DEF_BENCH(return new SkBitmapFPGeneral(
|
||||
srcSize, kSRGB_SkColorProfileType, mR, true,
|
||||
srcSize, gSRGB, mR, true,
|
||||
SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);)
|
||||
|
||||
DEF_BENCH(return new SkBitmapFPGeneral(
|
||||
srcSize, kLinear_SkColorProfileType, mR, true,
|
||||
srcSize, gLinearRGB, mR, true,
|
||||
SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);)
|
||||
|
||||
DEF_BENCH(return new SkBitmapFPOrigShader(
|
||||
srcSize, kLinear_SkColorProfileType, mR, true,
|
||||
srcSize, gLinearRGB, mR, true,
|
||||
SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);)
|
||||
|
||||
// Repeat
|
||||
DEF_BENCH(return new SkBitmapFPGeneral(
|
||||
srcSize, kSRGB_SkColorProfileType, mR, false,
|
||||
srcSize, gSRGB, mR, false,
|
||||
SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode);)
|
||||
|
||||
DEF_BENCH(return new SkBitmapFPGeneral(
|
||||
srcSize, kLinear_SkColorProfileType, mR, false,
|
||||
srcSize, gLinearRGB, mR, false,
|
||||
SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode);)
|
||||
|
||||
DEF_BENCH(return new SkBitmapFPOrigShader(
|
||||
srcSize, kLinear_SkColorProfileType, mR, false,
|
||||
srcSize, gLinearRGB, mR, false,
|
||||
SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode);)
|
||||
|
||||
DEF_BENCH(return new SkBitmapFPGeneral(
|
||||
srcSize, kSRGB_SkColorProfileType, mR, true,
|
||||
srcSize, gSRGB, mR, true,
|
||||
SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode);)
|
||||
|
||||
DEF_BENCH(return new SkBitmapFPGeneral(
|
||||
srcSize, kLinear_SkColorProfileType, mR, true,
|
||||
srcSize, gLinearRGB, mR, true,
|
||||
SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode);)
|
||||
|
||||
DEF_BENCH(return new SkBitmapFPOrigShader(
|
||||
srcSize, kLinear_SkColorProfileType, mR, true,
|
||||
srcSize, gLinearRGB, mR, true,
|
||||
SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode);)
|
||||
|
@ -76,7 +76,6 @@ public:
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
SkColorSpace(GammaNamed gammaNamed, const SkMatrix44& toXYZD50, Named named);
|
||||
|
||||
friend Named sk_deduce_named_from_colorspace(SkColorSpace*);
|
||||
|
@ -13,8 +13,6 @@
|
||||
#include "SkRect.h"
|
||||
#include "SkSize.h"
|
||||
|
||||
#define SK_SUPPORT_LEGACY_COLORPROFILETYPE
|
||||
|
||||
class SkReadBuffer;
|
||||
class SkWriteBuffer;
|
||||
|
||||
@ -220,8 +218,8 @@ public:
|
||||
/**
|
||||
* Sets colortype to the native ARGB32 type, and the alphatype to premul.
|
||||
*/
|
||||
static SkImageInfo MakeN32Premul(int width, int height) {
|
||||
return Make(width, height, kN32_SkColorType, kPremul_SkAlphaType, nullptr);
|
||||
static SkImageInfo MakeN32Premul(int width, int height, sk_sp<SkColorSpace> cs = nullptr) {
|
||||
return Make(width, height, kN32_SkColorType, kPremul_SkAlphaType, cs);
|
||||
}
|
||||
|
||||
static SkImageInfo MakeN32Premul(const SkISize& size) {
|
||||
|
@ -354,7 +354,7 @@ struct State32 : State4f {
|
||||
if (is_opaque(paint, shaderContext)) {
|
||||
fFlags |= SkXfermode::kSrcIsOpaque_D32Flag;
|
||||
}
|
||||
if (info.isSRGB()) {
|
||||
if (info.gammaCloseToSRGB()) {
|
||||
fFlags |= SkXfermode::kDstIsSRGB_D32Flag;
|
||||
}
|
||||
fProc1 = SkXfermode::GetD32Proc(fXfer, fFlags | SkXfermode::kSrcIsSingle_D32Flag);
|
||||
|
@ -59,7 +59,7 @@ public:
|
||||
if (dst.colorType() != src.colorType()) {
|
||||
return false;
|
||||
}
|
||||
if (dst.info().profileType() != src.info().profileType()) {
|
||||
if (dst.info().gammaCloseToSRGB() != src.info().gammaCloseToSRGB()) {
|
||||
return false;
|
||||
}
|
||||
if (paint.getMaskFilter() || paint.getColorFilter() || paint.getImageFilter()) {
|
||||
@ -81,8 +81,7 @@ public:
|
||||
|
||||
// At this point memcpy can't be used. The following check for using SrcOver.
|
||||
|
||||
if (dst.colorType() != kN32_SkColorType
|
||||
|| dst.info().profileType() != kSRGB_SkColorProfileType) {
|
||||
if (dst.colorType() != kN32_SkColorType || !dst.info().gammaCloseToSRGB()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -109,7 +108,7 @@ public:
|
||||
|
||||
void blitRect(int x, int y, int width, int height) override {
|
||||
SkASSERT(fDst.colorType() == fSource.colorType());
|
||||
SkASSERT(fDst.info().profileType() == fSource.info().profileType());
|
||||
SkASSERT(fDst.info().gammaCloseToSRGB() == fSource.info().gammaCloseToSRGB());
|
||||
SkASSERT(width > 0 && height > 0);
|
||||
|
||||
if (fUseMemcpy) {
|
||||
@ -175,7 +174,7 @@ SkBlitter* SkBlitter::ChooseSprite(const SkPixmap& dst, const SkPaint& paint,
|
||||
blitter = SkSpriteBlitter::ChooseD16(source, paint, allocator);
|
||||
break;
|
||||
case kN32_SkColorType:
|
||||
if (dst.info().isSRGB()) {
|
||||
if (dst.info().gammaCloseToSRGB()) {
|
||||
blitter = SkSpriteBlitter::ChooseS32(source, paint, allocator);
|
||||
} else {
|
||||
blitter = SkSpriteBlitter::ChooseL32(source, paint, allocator);
|
||||
|
@ -2283,7 +2283,7 @@ void SkCanvas::onDrawImage(const SkImage* image, SkScalar x, SkScalar y, const S
|
||||
drawAsSprite = false;
|
||||
} else{
|
||||
// Until imagefilters are updated, they cannot handle any src type but N32...
|
||||
if (bitmap.info().colorType() != kN32_SkColorType || bitmap.info().isSRGB()) {
|
||||
if (bitmap.info().colorType() != kN32_SkColorType || bitmap.info().gammaCloseToSRGB()) {
|
||||
drawAsSprite = false;
|
||||
}
|
||||
}
|
||||
@ -2368,7 +2368,7 @@ void SkCanvas::onDrawBitmap(const SkBitmap& bitmap, SkScalar x, SkScalar y, cons
|
||||
*paint);
|
||||
if (drawAsSprite && paint->getImageFilter()) {
|
||||
// Until imagefilters are updated, they cannot handle any src type but N32...
|
||||
if (bitmap.info().colorType() != kN32_SkColorType || bitmap.info().isSRGB()) {
|
||||
if (bitmap.info().colorType() != kN32_SkColorType || bitmap.info().gammaCloseToSRGB()) {
|
||||
drawAsSprite = false;
|
||||
}
|
||||
}
|
||||
|
@ -286,7 +286,7 @@ static bool choose_blitprocs(const SkPM4f* pm4, const SkImageInfo& info,
|
||||
}
|
||||
switch (info.colorType()) {
|
||||
case kN32_SkColorType:
|
||||
if (info.isSRGB()) {
|
||||
if (info.gammaCloseToSRGB()) {
|
||||
flags |= SkXfermode::kDstIsSRGB_D32Flag;
|
||||
}
|
||||
state->fStorage[0] = (void*)SkXfermode::GetD32Proc(state->fXfer, flags);
|
||||
|
@ -1561,7 +1561,8 @@ private:
|
||||
|
||||
uint32_t SkDraw::scalerContextFlags() const {
|
||||
uint32_t flags = SkPaint::kBoostContrast_ScalerContextFlag;
|
||||
if (fDevice->imageInfo().isLinear()) {
|
||||
// TODO: how should we handle non-srgb, non-linear gamma?
|
||||
if (!fDevice->imageInfo().gammaCloseToSRGB()) {
|
||||
flags |= SkPaint::kFakeGamma_ScalerContextFlag;
|
||||
}
|
||||
return flags;
|
||||
|
@ -567,22 +567,22 @@ private:
|
||||
|
||||
using Blender = SkLinearBitmapPipeline::BlendProcessorInterface;
|
||||
|
||||
template <SkColorType colorType, template <SkColorType, SkColorProfileType, typename> class Sampler>
|
||||
template <SkColorType colorType, template <SkColorType, SkGammaType, typename> class Sampler>
|
||||
static void choose_specific_sampler(
|
||||
Blender* next,
|
||||
const SkPixmap& srcPixmap,
|
||||
SkLinearBitmapPipeline::SampleStage* sampleStage)
|
||||
{
|
||||
if (srcPixmap.info().profileType() == kSRGB_SkColorProfileType) {
|
||||
using S = Sampler<colorType, kSRGB_SkColorProfileType, Blender>;
|
||||
if (srcPixmap.info().gammaCloseToSRGB()) {
|
||||
using S = Sampler<colorType, kSRGB_SkGammaType, Blender>;
|
||||
sampleStage->initStage<S>(next, srcPixmap);
|
||||
} else {
|
||||
using S = Sampler<colorType, kLinear_SkColorProfileType, Blender>;
|
||||
using S = Sampler<colorType, kLinear_SkGammaType, Blender>;
|
||||
sampleStage->initStage<S>(next, srcPixmap);
|
||||
}
|
||||
}
|
||||
|
||||
template<template <SkColorType, SkColorProfileType, typename> class Sampler>
|
||||
template<template <SkColorType, SkGammaType, typename> class Sampler>
|
||||
static SkLinearBitmapPipeline::SampleProcessorInterface* choose_pixel_sampler_base(
|
||||
Blender* next,
|
||||
const SkPixmap& srcPixmap,
|
||||
@ -592,7 +592,7 @@ static SkLinearBitmapPipeline::SampleProcessorInterface* choose_pixel_sampler_ba
|
||||
const SkImageInfo& imageInfo = srcPixmap.info();
|
||||
switch (imageInfo.colorType()) {
|
||||
case kAlpha_8_SkColorType: {
|
||||
using S = Sampler<kAlpha_8_SkColorType, kLinear_SkColorProfileType, Blender>;
|
||||
using S = Sampler<kAlpha_8_SkColorType, kLinear_SkGammaType, Blender>;
|
||||
sampleStage->initStage<S>(next, srcPixmap, A8TintColor);
|
||||
}
|
||||
break;
|
||||
@ -615,7 +615,7 @@ static SkLinearBitmapPipeline::SampleProcessorInterface* choose_pixel_sampler_ba
|
||||
choose_specific_sampler<kGray_8_SkColorType, Sampler>(next, srcPixmap, sampleStage);
|
||||
break;
|
||||
case kRGBA_F16_SkColorType: {
|
||||
using S = Sampler<kRGBA_F16_SkColorType, kLinear_SkColorProfileType, Blender>;
|
||||
using S = Sampler<kRGBA_F16_SkColorType, kLinear_SkGammaType, Blender>;
|
||||
sampleStage->initStage<S>(next, srcPixmap);
|
||||
}
|
||||
break;
|
||||
@ -772,8 +772,9 @@ bool SkLinearBitmapPipeline::ClonePipelineForBlitting(
|
||||
if (srcPixmap.info().colorType() != kRGBA_8888_SkColorType
|
||||
|| dstInfo.colorType() != kRGBA_8888_SkColorType) { return false; }
|
||||
|
||||
if (srcPixmap.info().profileType() != kSRGB_SkColorProfileType
|
||||
|| dstInfo.profileType() != kSRGB_SkColorProfileType) { return false; }
|
||||
if (!srcPixmap.info().gammaCloseToSRGB() || !dstInfo.gammaCloseToSRGB()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (xferMode != SkXfermode::kSrc_Mode && xferMode != SkXfermode::kSrcOver_Mode) {
|
||||
return false;
|
||||
|
@ -15,6 +15,11 @@
|
||||
|
||||
class SkEmbeddableLinearPipeline;
|
||||
|
||||
enum SkGammaType {
|
||||
kLinear_SkGammaType,
|
||||
kSRGB_SkGammaType,
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// SkLinearBitmapPipeline - encapsulates all the machinery for doing floating point pixel
|
||||
// processing in a linear color space.
|
||||
|
@ -55,14 +55,14 @@ static Sk4s VECTORCALL bilerp4(Sk4s xs, Sk4s ys, Sk4f px00, Sk4f px10,
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PixelGetter is the lowest level interface to the source data. There is a PixelGetter for each
|
||||
// of the different SkColorTypes.
|
||||
template <SkColorType colorType, SkColorProfileType colorProfile> class PixelGetter;
|
||||
template <SkColorType, SkGammaType> class PixelGetter;
|
||||
|
||||
// Alpha handling:
|
||||
// The alpha from the paint (tintColor) is used in the blend part of the pipeline to modulate
|
||||
// the entire bitmap. So, the tint color is given an alpha of 1.0 so that the later alpha can
|
||||
// modulate this color later.
|
||||
template <>
|
||||
class PixelGetter<kAlpha_8_SkColorType, kLinear_SkColorProfileType> {
|
||||
class PixelGetter<kAlpha_8_SkColorType, kLinear_SkGammaType> {
|
||||
public:
|
||||
using Element = uint8_t;
|
||||
PixelGetter(const SkPixmap& srcPixmap, SkColor tintColor)
|
||||
@ -76,63 +76,63 @@ private:
|
||||
const Sk4f fTintColor;
|
||||
};
|
||||
|
||||
template <SkColorProfileType colorProfile>
|
||||
class PixelGetter<kRGB_565_SkColorType, colorProfile> {
|
||||
template <SkGammaType gammaType>
|
||||
class PixelGetter<kRGB_565_SkColorType, gammaType> {
|
||||
public:
|
||||
using Element = uint16_t;
|
||||
PixelGetter(const SkPixmap& srcPixmap) { }
|
||||
|
||||
Sk4f getPixelAt(const uint16_t* src) {
|
||||
SkPMColor pixel = SkPixel16ToPixel32(*src);
|
||||
return colorProfile == kSRGB_SkColorProfileType
|
||||
return gammaType == kSRGB_SkGammaType
|
||||
? Sk4f_fromS32(pixel)
|
||||
: Sk4f_fromL32(pixel);
|
||||
}
|
||||
};
|
||||
|
||||
template <SkColorProfileType colorProfile>
|
||||
class PixelGetter<kARGB_4444_SkColorType, colorProfile> {
|
||||
template <SkGammaType gammaType>
|
||||
class PixelGetter<kARGB_4444_SkColorType, gammaType> {
|
||||
public:
|
||||
using Element = uint16_t;
|
||||
PixelGetter(const SkPixmap& srcPixmap) { }
|
||||
|
||||
Sk4f getPixelAt(const uint16_t* src) {
|
||||
SkPMColor pixel = SkPixel4444ToPixel32(*src);
|
||||
return colorProfile == kSRGB_SkColorProfileType
|
||||
return gammaType == kSRGB_SkGammaType
|
||||
? Sk4f_fromS32(pixel)
|
||||
: Sk4f_fromL32(pixel);
|
||||
}
|
||||
};
|
||||
|
||||
template <SkColorProfileType colorProfile>
|
||||
class PixelGetter<kRGBA_8888_SkColorType, colorProfile> {
|
||||
template <SkGammaType gammaType>
|
||||
class PixelGetter<kRGBA_8888_SkColorType, gammaType> {
|
||||
public:
|
||||
using Element = uint32_t;
|
||||
PixelGetter(const SkPixmap& srcPixmap) { }
|
||||
|
||||
Sk4f getPixelAt(const uint32_t* src) {
|
||||
return colorProfile == kSRGB_SkColorProfileType
|
||||
return gammaType == kSRGB_SkGammaType
|
||||
? Sk4f_fromS32(*src)
|
||||
: Sk4f_fromL32(*src);
|
||||
}
|
||||
};
|
||||
|
||||
template <SkColorProfileType colorProfile>
|
||||
class PixelGetter<kBGRA_8888_SkColorType, colorProfile> {
|
||||
template <SkGammaType gammaType>
|
||||
class PixelGetter<kBGRA_8888_SkColorType, gammaType> {
|
||||
public:
|
||||
using Element = uint32_t;
|
||||
PixelGetter(const SkPixmap& srcPixmap) { }
|
||||
|
||||
Sk4f getPixelAt(const uint32_t* src) {
|
||||
Sk4f pixel = colorProfile == kSRGB_SkColorProfileType
|
||||
Sk4f pixel = gammaType == kSRGB_SkGammaType
|
||||
? Sk4f_fromS32(*src)
|
||||
: Sk4f_fromL32(*src);
|
||||
return swizzle_rb(pixel);
|
||||
}
|
||||
};
|
||||
|
||||
template <SkColorProfileType colorProfile>
|
||||
class PixelGetter<kIndex_8_SkColorType, colorProfile> {
|
||||
template <SkGammaType gammaType>
|
||||
class PixelGetter<kIndex_8_SkColorType, gammaType> {
|
||||
public:
|
||||
using Element = uint8_t;
|
||||
PixelGetter(const SkPixmap& srcPixmap) {
|
||||
@ -166,7 +166,7 @@ private:
|
||||
float invAlpha = 1.0f / alpha;
|
||||
Sk4f normalize = {invAlpha, invAlpha, invAlpha, 1.0f / 255.0f};
|
||||
pixel = pixel * normalize;
|
||||
if (colorProfile == kSRGB_SkColorProfileType) {
|
||||
if (gammaType == kSRGB_SkGammaType) {
|
||||
pixel = linear_to_srgb(pixel);
|
||||
}
|
||||
return pixel;
|
||||
@ -178,8 +178,8 @@ private:
|
||||
Sk4f* fColorTable;
|
||||
};
|
||||
|
||||
template <SkColorProfileType colorProfile>
|
||||
class PixelGetter<kGray_8_SkColorType, colorProfile> {
|
||||
template <SkGammaType gammaType>
|
||||
class PixelGetter<kGray_8_SkColorType, gammaType> {
|
||||
public:
|
||||
using Element = uint8_t;
|
||||
PixelGetter(const SkPixmap& srcPixmap) { }
|
||||
@ -187,14 +187,14 @@ public:
|
||||
Sk4f getPixelAt(const uint8_t* src) {
|
||||
float gray = *src * (1.0f/255.0f);
|
||||
Sk4f pixel = Sk4f{gray, gray, gray, 1.0f};
|
||||
return colorProfile == kSRGB_SkColorProfileType
|
||||
return gammaType == kSRGB_SkGammaType
|
||||
? srgb_to_linear(pixel)
|
||||
: pixel;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
class PixelGetter<kRGBA_F16_SkColorType, kLinear_SkColorProfileType> {
|
||||
class PixelGetter<kRGBA_F16_SkColorType, kLinear_SkGammaType> {
|
||||
public:
|
||||
using Element = uint64_t;
|
||||
PixelGetter(const SkPixmap& srcPixmap) { }
|
||||
@ -206,9 +206,9 @@ public:
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PixelAccessor handles all the same plumbing for all the PixelGetters.
|
||||
template <SkColorType colorType, SkColorProfileType colorProfile>
|
||||
template <SkColorType colorType, SkGammaType gammaType>
|
||||
class PixelAccessor {
|
||||
using Element = typename PixelGetter<colorType, colorProfile>::Element;
|
||||
using Element = typename PixelGetter<colorType, gammaType>::Element;
|
||||
public:
|
||||
template <typename... Args>
|
||||
PixelAccessor(const SkPixmap& srcPixmap, Args&&... args)
|
||||
@ -263,7 +263,7 @@ public:
|
||||
private:
|
||||
const Element* const fSrc;
|
||||
const Sk4i fWidth;
|
||||
PixelGetter<colorType, colorProfile> fGetter;
|
||||
PixelGetter<colorType, gammaType> fGetter;
|
||||
};
|
||||
|
||||
// We're moving through source space at a rate of 1 source pixel per 1 dst pixel.
|
||||
@ -308,7 +308,7 @@ static void src_strategy_blend(Span span, Next* next, Strategy* strategy) {
|
||||
}
|
||||
|
||||
// NearestNeighborSampler - use nearest neighbor filtering to create runs of destination pixels.
|
||||
template<SkColorType colorType, SkColorProfileType colorProfile, typename Next>
|
||||
template<SkColorType colorType, SkGammaType gammaType, typename Next>
|
||||
class NearestNeighborSampler : public SkLinearBitmapPipeline::SampleProcessorInterface {
|
||||
public:
|
||||
template<typename... Args>
|
||||
@ -424,13 +424,13 @@ private:
|
||||
span_fallback(span, this);
|
||||
}
|
||||
|
||||
Next* const fNext;
|
||||
PixelAccessor<colorType, colorProfile> fStrategy;
|
||||
Next* const fNext;
|
||||
PixelAccessor<colorType, gammaType> fStrategy;
|
||||
};
|
||||
|
||||
// -- BilerpSampler --------------------------------------------------------------------------------
|
||||
// BilerpSampler - use a bilerp filter to create runs of destination pixels.
|
||||
template<SkColorType colorType, SkColorProfileType colorProfile, typename Next>
|
||||
template<SkColorType colorType, SkGammaType gammaType, typename Next>
|
||||
class BilerpSampler : public SkLinearBitmapPipeline::SampleProcessorInterface {
|
||||
public:
|
||||
template<typename... Args>
|
||||
@ -801,8 +801,8 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
Next* const fNext;
|
||||
PixelAccessor<colorType, colorProfile> fStrategy;
|
||||
Next* const fNext;
|
||||
PixelAccessor<colorType, gammaType> fStrategy;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
@ -304,14 +304,6 @@ size_t SkMipMap::AllocLevelsSize(int levelCount, size_t pixelSize) {
|
||||
return sk_64_asS32(size);
|
||||
}
|
||||
|
||||
static bool treat_like_srgb(const SkImageInfo& info) {
|
||||
if (info.colorSpace()) {
|
||||
return info.colorSpace()->gammaCloseToSRGB();
|
||||
} else {
|
||||
return kSRGB_SkColorProfileType == info.profileType();
|
||||
}
|
||||
}
|
||||
|
||||
SkMipMap* SkMipMap::Build(const SkPixmap& src, SkSourceGammaTreatment treatment,
|
||||
SkDiscardableFactoryProc fact) {
|
||||
typedef void FilterProc(void*, const void* srcPtr, size_t srcRB, int count);
|
||||
@ -328,7 +320,7 @@ SkMipMap* SkMipMap::Build(const SkPixmap& src, SkSourceGammaTreatment treatment,
|
||||
const SkColorType ct = src.colorType();
|
||||
const SkAlphaType at = src.alphaType();
|
||||
const bool srgbGamma = (SkSourceGammaTreatment::kRespect == treatment)
|
||||
&& treat_like_srgb(src.info());
|
||||
&& src.info().gammaCloseToSRGB();
|
||||
|
||||
switch (ct) {
|
||||
case kRGBA_8888_SkColorType:
|
||||
|
@ -49,7 +49,7 @@ static void load_f16(const SkPixmap& src, int x, int y, SkPM4f span[], int count
|
||||
SkLoadSpanProc SkLoadSpanProc_Choose(const SkImageInfo& info) {
|
||||
switch (info.colorType()) {
|
||||
case kN32_SkColorType:
|
||||
return info.isSRGB() ? load_s32 : load_l32;
|
||||
return info.gammaCloseToSRGB() ? load_s32 : load_l32;
|
||||
case kRGBA_F16_SkColorType:
|
||||
return load_f16;
|
||||
default:
|
||||
|
@ -448,7 +448,7 @@ LinearGradient4fContext::D32_BlitBW(BlitState* state, int x, int y, const SkPixm
|
||||
const LinearGradient4fContext* ctx =
|
||||
static_cast<const LinearGradient4fContext*>(state->fCtx);
|
||||
|
||||
if (dst.info().isLinear()) {
|
||||
if (!dst.info().gammaCloseToSRGB()) {
|
||||
if (ctx->fColorsArePremul) {
|
||||
ctx->shadePremulSpan<DstType::L32, ApplyPremul::False>(
|
||||
x, y, dst.writable_addr32(x, y), count);
|
||||
|
@ -163,6 +163,5 @@ DEF_TEST(ColorSpace_Named, r) {
|
||||
}
|
||||
|
||||
SkImageInfo info = SkImageInfo::MakeS32(10, 10, kPremul_SkAlphaType);
|
||||
REPORTER_ASSERT(r, kSRGB_SkColorProfileType == info.profileType());
|
||||
REPORTER_ASSERT(r, SkColorSpace::kSRGB_GammaNamed == info.colorSpace()->gammaNamed());
|
||||
REPORTER_ASSERT(r, info.gammaCloseToSRGB());
|
||||
}
|
||||
|
@ -26,8 +26,7 @@ static void test_flatten(skiatest::Reporter* reporter, const SkImageInfo& info)
|
||||
SkReadBuffer rb(storage, wb.bytesWritten());
|
||||
|
||||
// pick a noisy byte pattern, so we ensure that unflatten sets all of our fields
|
||||
SkImageInfo info2 = SkImageInfo::Make(0xB8, 0xB8, (SkColorType) 0xB8, (SkAlphaType) 0xB8,
|
||||
(SkColorProfileType) 0xB8);
|
||||
SkImageInfo info2 = SkImageInfo::Make(0xB8, 0xB8, (SkColorType) 0xB8, (SkAlphaType) 0xB8);
|
||||
|
||||
info2.unflatten(rb);
|
||||
REPORTER_ASSERT(reporter, rb.offset() == wb.bytesWritten());
|
||||
@ -38,13 +37,19 @@ static void test_flatten(skiatest::Reporter* reporter, const SkImageInfo& info)
|
||||
}
|
||||
|
||||
DEF_TEST(ImageInfo_flattening, reporter) {
|
||||
sk_sp<SkColorSpace> spaces[] = {
|
||||
nullptr,
|
||||
SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named),
|
||||
SkColorSpace::NewNamed(SkColorSpace::kAdobeRGB_Named),
|
||||
};
|
||||
|
||||
for (int ct = 0; ct <= kLastEnum_SkColorType; ++ct) {
|
||||
for (int at = 0; at <= kLastEnum_SkAlphaType; ++at) {
|
||||
for (int pt = 0; pt <= kLastEnum_SkColorProfileType; ++pt) {
|
||||
for (auto& cs : spaces) {
|
||||
SkImageInfo info = SkImageInfo::Make(100, 200,
|
||||
static_cast<SkColorType>(ct),
|
||||
static_cast<SkAlphaType>(at),
|
||||
static_cast<SkColorProfileType>(pt));
|
||||
cs);
|
||||
test_flatten(reporter, info);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user