SkColorSpace: remove named API, add gamut API

Reland from: https://skia-review.googlesource.com/c/8021/

BUG=skia:

Change-Id: I18985f130587b15fccbc86b76b2bb5c49ba5ba8a
Reviewed-on: https://skia-review.googlesource.com/8136
Reviewed-by: Matt Sarett <msarett@google.com>
Commit-Queue: Matt Sarett <msarett@google.com>
This commit is contained in:
Matt Sarett 2017-02-07 13:56:11 -05:00 committed by Skia Commit-Bot
parent 4f51aa57ea
commit 77a7a1b57c
66 changed files with 266 additions and 147 deletions

View File

@ -67,7 +67,7 @@ void ColorCodecBench::onDelayedSetup() {
fDstSpace = nullptr;
if (FLAGS_srgb) {
fDstSpace = SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named);
fDstSpace = SkColorSpace::MakeSRGB();
} else if (FLAGS_nonstd) {
SkColorSpaceTransferFn gamma;
gamma.fA = 1.0f;

View File

@ -36,7 +36,7 @@ protected:
if (nullptr == context) {
return;
}
auto srgb = SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named);
auto srgb = SkColorSpace::MakeSRGB();
SkImageInfo info = SkImageInfo::Make(fW, fH, kN32_SkColorType, kPremul_SkAlphaType,
srgb);
fSurface = SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info);

View File

@ -91,7 +91,7 @@ struct CommonBitmapFPBenchmark : public Benchmark {
sk_ignore_unused_variable(trash);
fInfo = SkImageInfo::MakeN32Premul(width, height, fIsSRGB ?
SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named) : nullptr);
SkColorSpace::MakeSRGB() : nullptr);
}
bool isSuitableFor(Backend backend) override {

View File

@ -456,10 +456,10 @@ static void create_config(const SkCommandLineConfig* config, SkTArray<Config>* c
kN32_SkColorType, kPremul_SkAlphaType, nullptr)
CPU_CONFIG(565, kRaster_Backend,
kRGB_565_SkColorType, kOpaque_SkAlphaType, nullptr)
auto srgbColorSpace = SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named);
auto srgbColorSpace = SkColorSpace::MakeSRGB();
CPU_CONFIG(srgb, kRaster_Backend,
kN32_SkColorType, kPremul_SkAlphaType, srgbColorSpace)
auto srgbLinearColorSpace = SkColorSpace::MakeNamed(SkColorSpace::kSRGBLinear_Named);
auto srgbLinearColorSpace = SkColorSpace::MakeSRGBLinear();
CPU_CONFIG(f16, kRaster_Backend,
kRGBA_F16_SkColorType, kPremul_SkAlphaType, srgbLinearColorSpace)
}

View File

@ -860,8 +860,8 @@ static Sink* create_sink(const SkCommandLineConfig* config) {
#define SINK(t, sink, ...) if (config->getBackend().equals(t)) { return new sink(__VA_ARGS__); }
if (FLAGS_cpu) {
auto srgbColorSpace = SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named);
auto srgbLinearColorSpace = SkColorSpace::MakeNamed(SkColorSpace::kSRGBLinear_Named);
auto srgbColorSpace = SkColorSpace::MakeSRGB();
auto srgbLinearColorSpace = SkColorSpace::MakeSRGBLinear();
SINK("565", RasterSink, kRGB_565_SkColorType);
SINK("8888", RasterSink, kN32_SkColorType);

View File

@ -1014,7 +1014,7 @@ Error ColorCodecSrc::draw(SkCanvas* canvas) const {
sk_sp<SkColorSpace> dstSpace = nullptr;
if (kDst_sRGB_Mode == fMode) {
dstSpace = SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named);
dstSpace = SkColorSpace::MakeSRGB();
} else if (kDst_HPZR30w_Mode == fMode) {
dstSpace = SkColorSpace::MakeICC(dstData->data(), dstData->size());
}

View File

@ -266,7 +266,7 @@ DEF_SIMPLE_GM(all_variants_8888, canvas, 4 * SCALE + 30, 2 * SCALE + 10) {
sk_tool_utils::draw_checkerboard(canvas, SK_ColorLTGRAY, SK_ColorWHITE, 8);
sk_sp<SkColorSpace> colorSpaces[] {
SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named),
SkColorSpace::MakeSRGB(),
nullptr,
};
for (auto colorSpace : colorSpaces) {

View File

@ -76,7 +76,7 @@ DEF_SIMPLE_GM(color4f, canvas, 1024, 260) {
sk_sp<SkColorSpace> colorSpaces[]{
nullptr,
SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named)
SkColorSpace::MakeSRGB()
};
for (auto colorSpace : colorSpaces) {
const SkImageInfo info = SkImageInfo::Make(1024, 100, kN32_SkColorType, kPremul_SkAlphaType,
@ -95,7 +95,7 @@ DEF_SIMPLE_GM(color4f, canvas, 1024, 260) {
DEF_SIMPLE_GM(color4shader, canvas, 360, 480) {
canvas->translate(10, 10);
auto srgb = SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named);
auto srgb = SkColorSpace::MakeSRGB();
SkMatrix44 mat(SkMatrix44::kUninitialized_Constructor);
// red -> blue, green -> red, blue -> green (sRGB)

View File

@ -35,7 +35,7 @@ protected:
SkMatrix44 wideGamut(SkMatrix44::kUninitialized_Constructor);
wideGamut.set3x3RowMajorf(kWideGamutRGB_toXYZD50);
sk_sp<SkColorSpace> srcSpace = SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named);
sk_sp<SkColorSpace> srcSpace = SkColorSpace::MakeSRGB();
sk_sp<SkColorSpace> dstSpace =
SkColorSpace::MakeRGB(SkColorSpace::kLinear_RenderTargetGamma, wideGamut);
std::unique_ptr<SkColorSpaceXform> xform = SkColorSpaceXform::New(srcSpace.get(),
@ -60,7 +60,7 @@ protected:
canvas->save();
for (int i = 0; i < kNumColors; i++) {
auto space = SkColorSpace::MakeNamed(SkColorSpace::kSRGBLinear_Named);
auto space = SkColorSpace::MakeSRGBLinear();
sk_sp<SkShader> s = SkShader::MakeColorShader(colors[i], space);
SkPaint paint;
paint.setShader(s);

View File

@ -28,7 +28,7 @@ static inline int div_round_up(int a, int b) {
sk_sp<SkColorSpace> fix_for_colortype(sk_sp<SkColorSpace> colorSpace, SkColorType colorType) {
if (kRGBA_F16_SkColorType == colorType) {
if (!colorSpace) {
return SkColorSpace::MakeNamed(SkColorSpace::kSRGBLinear_Named);
return SkColorSpace::MakeSRGBLinear();
}
return as_CSB(colorSpace)->makeLinearGamma();
@ -176,7 +176,7 @@ protected:
kUnpremul_SkAlphaType, kPremul_SkAlphaType, kOpaque_SkAlphaType,
};
const sk_sp<SkColorSpace> colorSpaces[] = {
nullptr, SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named),
nullptr, SkColorSpace::MakeSRGB(),
};
SkBitmap bitmap;

View File

@ -19,7 +19,7 @@ DEF_SIMPLE_GM(gamma, canvas, 850, 200) {
const SkScalar tx = sz + 15.0f;
const SkRect r = SkRect::MakeXYWH(0, 0, sz, sz);
SkShader::TileMode rpt = SkShader::kRepeat_TileMode;
auto srgbColorSpace = SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named);
auto srgbColorSpace = SkColorSpace::MakeSRGB();
SkBitmap ditherBmp;
ditherBmp.allocN32Pixels(2, 2);

View File

@ -133,12 +133,12 @@ static void draw_gamut_grid(SkCanvas* canvas, SkTArray<std::unique_ptr<CellRende
switch (origInfo.colorType()) {
case kRGBA_8888_SkColorType:
case kBGRA_8888_SkColorType:
srgbCS = SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named);
srgbCS = SkColorSpace::MakeSRGB();
wideCS = SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma,
wideGamutRGB_toXYZD50);
break;
case kRGBA_F16_SkColorType:
srgbCS = SkColorSpace::MakeNamed(SkColorSpace::kSRGBLinear_Named);
srgbCS = SkColorSpace::MakeSRGBLinear();
wideCS = SkColorSpace::MakeRGB(SkColorSpace::kLinear_RenderTargetGamma,
wideGamutRGB_toXYZD50);
break;

View File

@ -61,7 +61,7 @@ static sk_sp<SkShader> MakeLinear(const SkPoint pts[2], const GradData& data,
static sk_sp<SkShader> MakeLinear4f(const SkPoint pts[2], const GradData& data,
SkShader::TileMode tm, const SkMatrix& localMatrix) {
auto srgb = SkColorSpace::MakeNamed(SkColorSpace::kSRGBLinear_Named);
auto srgb = SkColorSpace::MakeSRGBLinear();
return SkGradientShader::MakeLinear(pts, data.fColors4f, srgb, data.fPos, data.fCount, tm, 0,
&localMatrix);
}
@ -80,7 +80,7 @@ static sk_sp<SkShader> MakeRadial4f(const SkPoint pts[2], const GradData& data,
SkPoint center;
center.set(SkScalarAve(pts[0].fX, pts[1].fX),
SkScalarAve(pts[0].fY, pts[1].fY));
auto srgb = SkColorSpace::MakeNamed(SkColorSpace::kSRGBLinear_Named);
auto srgb = SkColorSpace::MakeSRGBLinear();
return SkGradientShader::MakeRadial(center, center.fX, data.fColors4f, srgb, data.fPos,
data.fCount, tm, 0, &localMatrix);
}
@ -99,7 +99,7 @@ static sk_sp<SkShader> MakeSweep4f(const SkPoint pts[2], const GradData& data,
SkPoint center;
center.set(SkScalarAve(pts[0].fX, pts[1].fX),
SkScalarAve(pts[0].fY, pts[1].fY));
auto srgb = SkColorSpace::MakeNamed(SkColorSpace::kSRGBLinear_Named);
auto srgb = SkColorSpace::MakeSRGBLinear();
return SkGradientShader::MakeSweep(center.fX, center.fY, data.fColors4f, srgb, data.fPos,
data.fCount, 0, &localMatrix);
}
@ -124,7 +124,7 @@ static sk_sp<SkShader> Make2Radial4f(const SkPoint pts[2], const GradData& data,
SkScalarAve(pts[0].fY, pts[1].fY));
center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3) / 5),
SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1) / 4));
auto srgb = SkColorSpace::MakeNamed(SkColorSpace::kSRGBLinear_Named);
auto srgb = SkColorSpace::MakeSRGBLinear();
return SkGradientShader::MakeTwoPointConical(center1, (pts[1].fX - pts[0].fX) / 7,
center0, (pts[1].fX - pts[0].fX) / 2,
data.fColors4f, srgb, data.fPos, data.fCount, tm,
@ -150,7 +150,7 @@ static sk_sp<SkShader> Make2Conical4f(const SkPoint pts[2], const GradData& data
SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
center0.set(pts[0].fX + radius0, pts[0].fY + radius0);
center1.set(pts[1].fX - radius1, pts[1].fY - radius1);
auto srgb = SkColorSpace::MakeNamed(SkColorSpace::kSRGBLinear_Named);
auto srgb = SkColorSpace::MakeSRGBLinear();
return SkGradientShader::MakeTwoPointConical(center1, radius1, center0, radius0,
data.fColors4f, srgb, data.fPos,
data.fCount, tm, 0, &localMatrix);

View File

@ -247,7 +247,7 @@ static sk_sp<SkImage> make_picture(const SkImageInfo& info, GrContext*, void (*d
draw(recorder.beginRecording(SkRect::MakeIWH(info.width(), info.height())));
return SkImage::MakeFromPicture(recorder.finishRecordingAsPicture(),
info.dimensions(), nullptr, nullptr, SkImage::BitDepth::kU8,
SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named));
SkColorSpace::MakeSRGB());
}
static sk_sp<SkImage> make_codec(const SkImageInfo& info, GrContext*, void (*draw)(SkCanvas*)) {
@ -346,7 +346,7 @@ static SkImageGenerator* gen_picture(const SkImageInfo& info) {
sk_sp<SkPicture> pict(recorder.finishRecordingAsPicture());
return SkImageGenerator::NewFromPicture(info.dimensions(), pict.get(), nullptr, nullptr,
SkImage::BitDepth::kU8,
SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named));
SkColorSpace::MakeSRGB());
}
static SkImageGenerator* gen_png(const SkImageInfo& info) {
@ -476,7 +476,7 @@ DEF_SIMPLE_GM(new_texture_image, canvas, 280, 60) {
SkPictureRecorder recorder;
SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(kSize), SkIntToScalar(kSize));
render_image(canvas);
sk_sp<SkColorSpace> srgbColorSpace = SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named);
sk_sp<SkColorSpace> srgbColorSpace = SkColorSpace::MakeSRGB();
return SkImage::MakeFromPicture(recorder.finishRecordingAsPicture(),
SkISize::Make(kSize, kSize), nullptr, nullptr,
SkImage::BitDepth::kU8, srgbColorSpace);

View File

@ -62,7 +62,7 @@ protected:
// extract enough just for the oval.
const SkISize size = SkISize::Make(100, 100);
auto srgbColorSpace = SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named);
auto srgbColorSpace = SkColorSpace::MakeSRGB();
SkMatrix matrix;
matrix.setTranslate(-100, -100);
@ -112,7 +112,7 @@ static SkImageGenerator* make_pic_generator(GrContext*, SkPicture* pic) {
matrix.setTranslate(-100, -100);
return SkImageGenerator::NewFromPicture(SkISize::Make(100, 100), pic, &matrix, nullptr,
SkImage::BitDepth::kU8,
SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named));
SkColorSpace::MakeSRGB());
}
class RasterGenerator : public SkImageGenerator {

View File

@ -49,7 +49,7 @@ static sk_sp<SkImage> make_texture(GrContext* ctx, SkPicture* pic, const SkImage
static sk_sp<SkImage> make_pict_gen(GrContext*, SkPicture* pic, const SkImageInfo& info) {
return SkImage::MakeFromPicture(sk_ref_sp(pic), info.dimensions(), nullptr, nullptr,
SkImage::BitDepth::kU8,
SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named));
SkColorSpace::MakeSRGB());
}
static sk_sp<SkImage> make_encode_gen(GrContext* ctx, SkPicture* pic, const SkImageInfo& info) {

View File

@ -89,7 +89,7 @@ static void show_mips(SkCanvas* canvas, SkImage* img) {
*/
DEF_SIMPLE_GM(mipmap_srgb, canvas, 260, 230) {
sk_sp<SkImage> limg = make(nullptr);
sk_sp<SkImage> simg = make(SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named));
sk_sp<SkImage> simg = make(SkColorSpace::MakeSRGB());
canvas->translate(10, 10);
show_mips(canvas, limg.get());
@ -140,7 +140,7 @@ static void show_mips_only(SkCanvas* canvas, SkImage* img) {
*/
DEF_SIMPLE_GM(mipmap_gray8_srgb, canvas, 260, 230) {
sk_sp<SkImage> limg = make_g8_gradient(nullptr);
sk_sp<SkImage> simg = make_g8_gradient(SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named));
sk_sp<SkImage> simg = make_g8_gradient(SkColorSpace::MakeSRGB());
canvas->translate(10, 10);
show_mips_only(canvas, limg.get());

View File

@ -138,7 +138,7 @@ protected:
{ SkISize::Make(200, 100), -1, -1, 0.5f },
};
auto srgbColorSpace = SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named);
auto srgbColorSpace = SkColorSpace::MakeSRGB();
const unsigned kDrawsPerRow = 4;
const SkScalar kDrawSize = 250;

View File

@ -86,7 +86,7 @@ static sk_sp<SkImage> make_tagged_picture_image() {
return SkImage::MakeFromPicture(recorder.finishRecordingAsPicture(),
SkISize::Make(kWidth, kHeight), nullptr, nullptr,
SkImage::BitDepth::kU8,
SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named));
SkColorSpace::MakeSRGB());
}
static sk_sp<SkImage> make_untagged_picture_image() {
@ -144,7 +144,7 @@ static void draw_image(SkCanvas* canvas, SkImage* image, SkColorType dstColorTyp
// Now that we have called readPixels(), dump the raw pixels into an srgb image.
sk_sp<SkColorSpace> srgb = fix_for_colortype(
SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named).get(), dstColorType);
SkColorSpace::MakeSRGB().get(), dstColorType);
sk_sp<SkImage> raw = SkImage::MakeRasterData(dstInfo.makeColorSpace(srgb), data, rowBytes);
canvas->drawImage(raw.get(), 0.0f, 0.0f, nullptr);
}
@ -179,7 +179,7 @@ protected:
};
const sk_sp<SkColorSpace> colorSpaces[] = {
make_wide_gamut(),
SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named),
SkColorSpace::MakeSRGB(),
make_small_gamut(),
};
@ -237,7 +237,7 @@ protected:
};
const sk_sp<SkColorSpace> colorSpaces[] = {
make_wide_gamut(),
SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named),
SkColorSpace::MakeSRGB(),
make_small_gamut(),
};
const SkImage::CachingHint hints[] = {
@ -304,7 +304,7 @@ protected:
};
const sk_sp<SkColorSpace> colorSpaces[] = {
make_wide_gamut(),
SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named),
SkColorSpace::MakeSRGB(),
make_small_gamut(),
};
const SkImage::CachingHint hints[] = {

View File

@ -34,7 +34,7 @@ static sk_sp<SkImage> make_picture_image(int width, int height, SkColor colors[2
return SkImage::MakeFromPicture(recorder.finishRecordingAsPicture(),
SkISize::Make(width, height), nullptr, nullptr,
SkImage::BitDepth::kU8,
SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named));
SkColorSpace::MakeSRGB());
}
typedef sk_sp<SkImage> (*ImageMakerProc)(int width, int height, SkColor colors[2]);

View File

@ -16,4 +16,5 @@ android_framework_defines = [
"SK_SUPPORT_LEGACY_SHADER_ISABITMAP",
"SK_SUPPORT_LEGACY_EMBOSSMASKFILTER",
"SK_SUPPORT_EXOTIC_CLIPOPS",
"SK_USE_LEGACY_NAMED_COLOR_SPACE",
]

View File

@ -53,6 +53,7 @@ struct SK_API SkColorSpaceTransferFn {
class SK_API SkColorSpace : public SkRefCnt {
public:
#ifdef SK_USE_LEGACY_NAMED_COLOR_SPACE
/**
* Common, named profiles that we can recognize.
*/
@ -76,6 +77,23 @@ public:
kSRGBLinear_Named,
};
/**
* Create a common, named SkColorSpace.
*/
static sk_sp<SkColorSpace> MakeNamed(Named);
#endif
/**
* Create the sRGB color space.
*/
static sk_sp<SkColorSpace> MakeSRGB();
/**
* Colorspace with the sRGB primaries, but a linear (1.0) gamma. Commonly used for
* half-float surfaces, and high precision individual colors (gradient stops, etc...)
*/
static sk_sp<SkColorSpace> MakeSRGBLinear();
enum RenderTargetGamma : uint8_t {
kLinear_RenderTargetGamma,
@ -86,21 +104,24 @@ public:
kSRGB_RenderTargetGamma,
};
enum Gamut {
kSRGB_Gamut,
kAdobeRGB_Gamut,
kDCIP3_D65_Gamut,
kRec2020_Gamut,
};
/**
* Create an SkColorSpace from a transfer function and a color gamut.
*
* Transfer function can be specified as a render target, as the coefficients to an equation,
* or as three exponents (R, G, B).
* Gamut is specified using the matrix transformation to XYZ D50.
* Transfer function can be specified as an enum or as the coefficients to an equation.
* Gamut can be specified as an enum or as the matrix transformation to XYZ D50.
*/
static sk_sp<SkColorSpace> MakeRGB(RenderTargetGamma gamma, Gamut gamut);
static sk_sp<SkColorSpace> MakeRGB(RenderTargetGamma gamma, const SkMatrix44& toXYZD50);
static sk_sp<SkColorSpace> MakeRGB(const SkColorSpaceTransferFn& coeffs, Gamut gamut);
static sk_sp<SkColorSpace> MakeRGB(const SkColorSpaceTransferFn& coeffs,
const SkMatrix44& toXYZD50);
/**
* Create a common, named SkColorSpace.
*/
static sk_sp<SkColorSpace> MakeNamed(Named);
const SkMatrix44& toXYZD50);
/**
* Create an SkColorSpace from an ICC profile.

View File

@ -342,8 +342,8 @@ public:
// the "correct" output (because we generated the pixel values we wanted in the
// offscreen canvas).
auto colorSpace = kRGBA_F16_SkColorType == info.colorType()
? SkColorSpace::MakeNamed(SkColorSpace::kSRGBLinear_Named)
: SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named);
? SkColorSpace::MakeSRGBLinear()
: SkColorSpace::MakeSRGB();
auto offscreenImage = SkImage::MakeRasterData(info.makeColorSpace(colorSpace), data,
rowBytes);
@ -1659,7 +1659,7 @@ bool SampleWindow::onEvent(const SkEvent& evt) {
sk_sp<SkColorSpace> colorSpace = nullptr;
switch (gConfig[selected].fColorSpace) {
case kSRGB_OutputColorSpace:
colorSpace = SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named);
colorSpace = SkColorSpace::MakeSRGB();
break;
case kNarrow_OutputColorSpace:
{
@ -1680,7 +1680,7 @@ bool SampleWindow::onEvent(const SkEvent& evt) {
colorSpace = getMonitorColorSpace();
if (!colorSpace) {
// Fallback for platforms / machines where we can't get a monitor profile
colorSpace = SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named);
colorSpace = SkColorSpace::MakeSRGB();
}
break;
case kLegacy_OutputColorSpace:

View File

@ -131,9 +131,9 @@ sk_sp<SkColorSpace> SkAndroidCodec::computeOutputColorSpace(SkColorType outputCo
case kRGBA_8888_SkColorType:
case kBGRA_8888_SkColorType:
case kIndex_8_SkColorType:
return SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named);
return SkColorSpace::MakeSRGB();
case kRGBA_F16_SkColorType:
return SkColorSpace::MakeNamed(SkColorSpace::kSRGBLinear_Named);
return SkColorSpace::MakeSRGBLinear();
default:
// Color correction not supported for k565 and kGray.
return nullptr;

View File

@ -593,7 +593,7 @@ SkCodec* SkBmpCodec::NewFromStream(SkStream* stream, bool inIco) {
SkBmpCodec::SkBmpCodec(int width, int height, const SkEncodedInfo& info, SkStream* stream,
uint16_t bitsPerPixel, SkCodec::SkScanlineOrder rowOrder)
: INHERITED(width, height, info, stream, SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named))
: INHERITED(width, height, info, stream, SkColorSpace::MakeSRGB())
, fBitsPerPixel(bitsPerPixel)
, fRowOrder(rowOrder)
, fSrcRowBytes(SkAlign4(compute_row_bytes(width, fBitsPerPixel)))

View File

@ -106,7 +106,7 @@ SkCodec* SkGifCodec::NewFromStream(SkStream* stream) {
const auto imageInfo = SkImageInfo::Make(reader->screenWidth(), reader->screenHeight(),
colorType, alphaType,
SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named));
SkColorSpace::MakeSRGB());
return new SkGifCodec(encodedInfo, imageInfo, reader.release());
}

View File

@ -252,7 +252,7 @@ bool SkJpegCodec::ReadHeader(SkStream* stream, SkCodec** codecOut,
}
if (!colorSpace) {
// Treat unmarked jpegs as sRGB.
colorSpace = SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named);
colorSpace = SkColorSpace::MakeSRGB();
}
const int width = decoderMgr->dinfo()->image_width;

View File

@ -352,7 +352,7 @@ sk_sp<SkColorSpace> read_color_space(png_structp png_ptr, png_infop info_ptr,
// FIXME (msarett): Extract this information from the sRGB chunk once
// we are able to handle this information in
// SkColorSpace.
return SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named);
return SkColorSpace::MakeSRGB();
}
// Next, check for chromaticities.
@ -408,7 +408,7 @@ sk_sp<SkColorSpace> read_color_space(png_structp png_ptr, png_infop info_ptr,
// Report that there is no color space information in the PNG.
// Guess sRGB in this case.
return SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named);
return SkColorSpace::MakeSRGB();
}
void SkPngCodec::allocateStorage(const SkImageInfo& dstInfo) {
@ -1012,7 +1012,7 @@ void AutoCleanPng::infoCallback() {
const bool unsupportedICC = !colorSpace;
if (!colorSpace) {
// Treat unsupported/invalid color spaces as sRGB.
colorSpace = SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named);
colorSpace = SkColorSpace::MakeSRGB();
}
SkEncodedInfo encodedInfo = SkEncodedInfo::Make(color, alpha, bitDepth);

View File

@ -794,5 +794,5 @@ SkRawCodec::~SkRawCodec() {}
SkRawCodec::SkRawCodec(SkDngImage* dngImage)
: INHERITED(dngImage->width(), dngImage->height(), dngImage->getEncodedInfo(), nullptr,
SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named))
SkColorSpace::MakeSRGB())
, fDngImage(dngImage) {}

View File

@ -107,7 +107,7 @@ bool SkWbmpCodec::readRow(uint8_t* row) {
}
SkWbmpCodec::SkWbmpCodec(int width, int height, const SkEncodedInfo& info, SkStream* stream)
: INHERITED(width, height, info, stream, SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named))
: INHERITED(width, height, info, stream, SkColorSpace::MakeSRGB())
, fSrcRowBytes(get_src_row_bytes(this->getInfo().width()))
, fSwizzler(nullptr)
, fColorTable(nullptr)

View File

@ -70,7 +70,7 @@ SkCodec* SkWebpCodec::NewFromStream(SkStream* stream) {
}
}
if (!colorSpace) {
colorSpace = SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named);
colorSpace = SkColorSpace::MakeSRGB();
}
// Since we do not yet support animation, we get the |width|, |height|, |color|, and |alpha|

View File

@ -319,7 +319,7 @@ bool SkColorShader::onAppendStages(SkRasterPipeline* p,
auto color = scratch->make<SkPM4f>(SkPM4f_from_SkColor(fColor, dst));
p->append(SkRasterPipeline::constant_color, color);
return append_gamut_transform(p, scratch,
SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named).get(), dst);
SkColorSpace::MakeSRGB().get(), dst);
}
bool SkColor4Shader::onAppendStages(SkRasterPipeline* p,

View File

@ -117,17 +117,17 @@ sk_sp<SkColorSpace> SkColorSpace_Base::MakeRGB(SkGammaNamed gammaNamed, const Sk
switch (gammaNamed) {
case kSRGB_SkGammaNamed:
if (xyz_almost_equal(toXYZD50, gSRGB_toXYZD50)) {
return SkColorSpace::MakeNamed(kSRGB_Named);
return SkColorSpace_Base::MakeNamed(kSRGB_Named);
}
break;
case k2Dot2Curve_SkGammaNamed:
if (xyz_almost_equal(toXYZD50, gAdobeRGB_toXYZD50)) {
return SkColorSpace::MakeNamed(kAdobeRGB_Named);
return SkColorSpace_Base::MakeNamed(kAdobeRGB_Named);
}
break;
case kLinear_SkGammaNamed:
if (xyz_almost_equal(toXYZD50, gSRGB_toXYZD50)) {
return SkColorSpace::MakeNamed(kSRGBLinear_Named);
return SkColorSpace_Base::MakeNamed(kSRGBLinear_Named);
}
break;
case kNonStandard_SkGammaNamed:
@ -183,11 +183,29 @@ sk_sp<SkColorSpace> SkColorSpace::MakeRGB(const SkColorSpaceTransferFn& coeffs,
std::move(gammas), toXYZD50, nullptr));
}
sk_sp<SkColorSpace> SkColorSpace::MakeRGB(RenderTargetGamma gamma, Gamut gamut) {
SkMatrix44 toXYZD50(SkMatrix44::kUninitialized_Constructor);
to_xyz_d50(&toXYZD50, gamut);
return SkColorSpace::MakeRGB(gamma, toXYZD50);
}
sk_sp<SkColorSpace> SkColorSpace::MakeRGB(const SkColorSpaceTransferFn& coeffs, Gamut gamut) {
SkMatrix44 toXYZD50(SkMatrix44::kUninitialized_Constructor);
to_xyz_d50(&toXYZD50, gamut);
return SkColorSpace::MakeRGB(coeffs, toXYZD50);
}
static SkColorSpace* gAdobeRGB;
static SkColorSpace* gSRGB;
static SkColorSpace* gSRGBLinear;
#ifdef SK_USE_LEGACY_NAMED_COLOR_SPACE
sk_sp<SkColorSpace> SkColorSpace::MakeNamed(Named named) {
return SkColorSpace_Base::MakeNamed((SkColorSpace_Base::Named) named);
}
#endif
sk_sp<SkColorSpace> SkColorSpace_Base::MakeNamed(Named named) {
static SkOnce sRGBOnce;
static SkOnce adobeRGBOnce;
static SkOnce sRGBLinearOnce;
@ -232,6 +250,14 @@ sk_sp<SkColorSpace> SkColorSpace::MakeNamed(Named named) {
return nullptr;
}
sk_sp<SkColorSpace> SkColorSpace::MakeSRGB() {
return SkColorSpace_Base::MakeNamed(SkColorSpace_Base::kSRGB_Named);
}
sk_sp<SkColorSpace> SkColorSpace::MakeSRGBLinear() {
return SkColorSpace_Base::MakeNamed(SkColorSpace_Base::kSRGBLinear_Named);
}
///////////////////////////////////////////////////////////////////////////////////////////////////
bool SkColorSpace::gammaCloseToSRGB() const {
@ -290,7 +316,7 @@ struct ColorSpaceHeader {
SkASSERT(k0_Version == version);
header.fVersion = (uint8_t) version;
SkASSERT(named <= SkColorSpace::kSRGBLinear_Named);
SkASSERT(named <= SkColorSpace_Base::kSRGBLinear_Named);
header.fNamed = (uint8_t) named;
SkASSERT(gammaNamed <= kNonStandard_SkGammaNamed);
@ -318,20 +344,20 @@ size_t SkColorSpace::writeToMemory(void* memory) const {
const SkGammaNamed gammaNamed = thisXYZ->gammaNamed();
if (this == gSRGB) {
if (memory) {
*((ColorSpaceHeader*) memory) =
ColorSpaceHeader::Pack(k0_Version, kSRGB_Named, gammaNamed, 0);
*((ColorSpaceHeader*) memory) = ColorSpaceHeader::Pack(
k0_Version, SkColorSpace_Base::kSRGB_Named, gammaNamed, 0);
}
return sizeof(ColorSpaceHeader);
} else if (this == gAdobeRGB) {
if (memory) {
*((ColorSpaceHeader*) memory) =
ColorSpaceHeader::Pack(k0_Version, kAdobeRGB_Named, gammaNamed, 0);
*((ColorSpaceHeader*) memory) = ColorSpaceHeader::Pack(
k0_Version, SkColorSpace_Base::kAdobeRGB_Named, gammaNamed, 0);
}
return sizeof(ColorSpaceHeader);
} else if (this == gSRGBLinear) {
if (memory) {
*((ColorSpaceHeader*) memory) =
ColorSpaceHeader::Pack(k0_Version, kSRGBLinear_Named, gammaNamed, 0);
*((ColorSpaceHeader*) memory) = ColorSpaceHeader::Pack(
k0_Version, SkColorSpace_Base::kSRGBLinear_Named, gammaNamed, 0);
}
return sizeof(ColorSpaceHeader);
}
@ -423,7 +449,7 @@ sk_sp<SkColorSpace> SkColorSpace::Deserialize(const void* data, size_t length) {
data = SkTAddOffset<const void>(data, sizeof(ColorSpaceHeader));
length -= sizeof(ColorSpaceHeader);
if (0 == header.fFlags) {
return MakeNamed((Named) header.fNamed);
return SkColorSpace_Base::MakeNamed((SkColorSpace_Base::Named) header.fNamed);
}
switch ((SkGammaNamed) header.fGammaNamed) {

View File

@ -23,6 +23,35 @@ static constexpr float gAdobeRGB_toXYZD50[] {
0.0194811f, 0.0608902f, 0.7448387f, // Rz, Gz, Bz
};
static constexpr float gDCIP3_toXYZD50[] {
0.515102f, 0.291965f, 0.157153f, // Rx, Gx, Bx
0.241182f, 0.692236f, 0.0665819f, // Ry, Gy, Gz
-0.00104941f, 0.0418818f, 0.784378f, // Rz, Gz, Bz
};
static constexpr float gRec2020_toXYZD50[] {
0.673459f, 0.165661f, 0.125100f, // Rx, Gx, Bx
0.279033f, 0.675338f, 0.0456288f, // Ry, Gy, Gz
-0.00193139f, 0.0299794f, 0.797162f, // Rz, Gz, Bz
};
static inline void to_xyz_d50(SkMatrix44* toXYZD50, SkColorSpace::Gamut gamut) {
switch (gamut) {
case SkColorSpace::kSRGB_Gamut:
toXYZD50->set3x3RowMajorf(gSRGB_toXYZD50);
break;
case SkColorSpace::kAdobeRGB_Gamut:
toXYZD50->set3x3RowMajorf(gAdobeRGB_toXYZD50);
break;
case SkColorSpace::kDCIP3_D65_Gamut:
toXYZD50->set3x3RowMajorf(gDCIP3_toXYZD50);
break;
case SkColorSpace::kRec2020_Gamut:
toXYZD50->set3x3RowMajorf(gRec2020_toXYZD50);
break;
}
}
static inline bool color_space_almost_equal(float a, float b) {
return SkTAbs(a - b) < 0.01f;
}

View File

@ -55,12 +55,12 @@ public:
sk_sp<SkColorSpace> makeLinearGamma() override {
// TODO: Analyze the extrema of our projection into XYZ and use suitable primaries?
// For now, just fall back to a default, because we don't have a good answer.
return SkColorSpace::MakeNamed(SkColorSpace::kSRGBLinear_Named);
return SkColorSpace::MakeSRGBLinear();
}
sk_sp<SkColorSpace> makeSRGBGamma() override {
// See comment in makeLinearGamma
return SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named);
return SkColorSpace::MakeSRGB();
}
Type type() const override { return Type::kA2B; }

View File

@ -194,6 +194,14 @@ public:
static sk_sp<SkColorSpace> MakeRGB(SkGammaNamed gammaNamed, const SkMatrix44& toXYZD50);
enum Named : uint8_t {
kSRGB_Named,
kAdobeRGB_Named,
kSRGBLinear_Named,
};
static sk_sp<SkColorSpace> MakeNamed(Named);
protected:
SkColorSpace_Base(sk_sp<SkData> profileData);

View File

@ -96,7 +96,7 @@ SkImageCacherator::Validator::Validator(sk_sp<SharedGenerator> gen, const SkIRec
// construct a source-to-dest gamut transformation matrix.
if (fInfo.colorSpace() &&
SkColorSpace_Base::Type::kXYZ != as_CSB(fInfo.colorSpace())->type()) {
fInfo = fInfo.makeColorSpace(SkColorSpace::MakeNamed(SkColorSpace::kSRGBLinear_Named));
fInfo = fInfo.makeColorSpace(SkColorSpace::MakeSRGBLinear());
}
}

View File

@ -19,7 +19,7 @@ static bool color_type_is_valid(SkColorType colorType) {
SkImageInfo SkImageInfo::MakeS32(int width, int height, SkAlphaType at) {
return SkImageInfo(width, height, kN32_SkColorType, at,
SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named));
SkColorSpace::MakeSRGB());
}
static const int kColorTypeMask = 0x0F;

View File

@ -157,7 +157,7 @@ static inline SkColor4f SkColor4f_from_SkColor(SkColor color, SkColorSpace* dst)
if (dst) {
// sRGB gamma, sRGB gamut.
color4f = to_colorspace(SkColor4f::FromColor(color),
SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named).get(), dst);
SkColorSpace::MakeSRGB().get(), dst);
} else {
// Linear gamma, dst gamut.
swizzle_rb(SkNx_cast<float>(Sk4b::Load(&color)) * (1/255.0f)).store(&color4f);

View File

@ -301,7 +301,7 @@ bool SkShader::onAppendStages(SkRasterPipeline* p,
// Legacy shaders aren't aware of color spaces. We can pretty
// safely assume they're in sRGB gamut.
return append_gamut_transform(p, alloc,
SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named).get(), cs);
SkColorSpace::MakeSRGB().get(), cs);
}
return false;
}

View File

@ -217,7 +217,7 @@ SkGradientShaderBase::SkGradientShaderBase(const Descriptor& desc, const SkMatri
if (!desc.fColorSpace) {
// This happens if we were constructed from SkColors, so our colors are really sRGB
fColorSpace = SkColorSpace::MakeNamed(SkColorSpace::kSRGBLinear_Named);
fColorSpace = SkColorSpace::MakeSRGBLinear();
} else {
// The color space refers to the float colors, so it must be linear gamma
SkASSERT(desc.fColorSpace->gammaIsLinear());
@ -740,12 +740,12 @@ void SkGradientShaderBase::getGradientTableBitmap(SkBitmap* bitmap,
case GradientBitmapType::kSRGB:
info = SkImageInfo::Make(kCache32Count, 1, kRGBA_8888_SkColorType,
kPremul_SkAlphaType,
SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named));
SkColorSpace::MakeSRGB());
break;
case GradientBitmapType::kHalfFloat:
info = SkImageInfo::Make(
kCache32Count, 1, kRGBA_F16_SkColorType, kPremul_SkAlphaType,
SkColorSpace::MakeNamed(SkColorSpace::kSRGBLinear_Named));
SkColorSpace::MakeSRGBLinear());
break;
default:
SkFAIL("Unexpected bitmap type");

View File

@ -89,7 +89,7 @@ GrRenderTargetContext::GrRenderTargetContext(GrContext* context,
, fSurfaceProps(SkSurfacePropsCopyOrDefault(surfaceProps)) {
if (fColorSpace) {
// sRGB sources are very common (SkColor, etc...), so we cache that gamut transformation
auto srgbColorSpace = SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named);
auto srgbColorSpace = SkColorSpace::MakeSRGB();
fColorXformFromSRGB = GrColorSpaceXform::Make(srgbColorSpace.get(), fColorSpace.get());
}
SkDEBUGCODE(this->validate();)

View File

@ -8,7 +8,7 @@
#include "GrTestUtils.h"
#include "GrProcessorUnitTest.h"
#include "GrStyle.h"
#include "SkColorSpace.h"
#include "SkColorSpace_Base.h"
#include "SkDashPathPriv.h"
#include "SkMatrix.h"
#include "SkPath.h"
@ -299,8 +299,8 @@ sk_sp<SkColorSpace> TestColorSpace(SkRandom* random) {
// No color space (legacy mode)
gColorSpaces[0] = nullptr;
// sRGB or Adobe
gColorSpaces[1] = SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named);
gColorSpaces[2] = SkColorSpace::MakeNamed(SkColorSpace::kAdobeRGB_Named);
gColorSpaces[1] = SkColorSpace::MakeSRGB();
gColorSpaces[2] = SkColorSpace_Base::MakeNamed(SkColorSpace_Base::kAdobeRGB_Named);
}
return gColorSpaces[random->nextULessThan(static_cast<uint32_t>(SK_ARRAY_COUNT(gColorSpaces)))];
}
@ -310,8 +310,8 @@ sk_sp<GrColorSpaceXform> TestColorXform(SkRandom* random) {
static bool gOnce;
if (!gOnce) {
gOnce = true;
sk_sp<SkColorSpace> srgb = SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named);
sk_sp<SkColorSpace> adobe = SkColorSpace::MakeNamed(SkColorSpace::kAdobeRGB_Named);
sk_sp<SkColorSpace> srgb = SkColorSpace::MakeSRGB();
sk_sp<SkColorSpace> adobe = SkColorSpace_Base::MakeNamed(SkColorSpace_Base::kAdobeRGB_Named);
// No gamut change
gXforms[0] = nullptr;
// To larger gamut

View File

@ -303,7 +303,7 @@ GrColor4f SkColorToPremulGrColor4f(SkColor c, SkColorSpace* dstColorSpace) {
GrColor4f SkColorToUnpremulGrColor4f(SkColor c, SkColorSpace* dstColorSpace) {
if (dstColorSpace) {
auto srgbColorSpace = SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named);
auto srgbColorSpace = SkColorSpace::MakeSRGB();
auto gamutXform = GrColorSpaceXform::Make(srgbColorSpace.get(), dstColorSpace);
return SkColorToUnpremulGrColor4f(c, true, gamutXform.get());
} else {

View File

@ -354,7 +354,7 @@ sk_sp<SkSurface> SkWindow::makeGpuBackedSurface(const AttachmentInfo& attachment
sk_sp<SkColorSpace> colorSpace =
grContext->caps()->srgbSupport() && info().colorSpace()
? SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named) : nullptr;
? SkColorSpace::MakeSRGB() : nullptr;
return SkSurface::MakeFromBackendRenderTarget(grContext, desc, colorSpace, &fSurfaceProps);
}

View File

@ -74,7 +74,7 @@ static constexpr float g_sRGB_G[]{ 0.3853f, 0.7170f, 0.0971f };
static constexpr float g_sRGB_B[]{ 0.1430f, 0.0606f, 0.7139f };
DEF_TEST(ColorSpace_sRGB, r) {
test_space(r, SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named).get(),
test_space(r, SkColorSpace::MakeSRGB().get(),
g_sRGB_R, g_sRGB_G, g_sRGB_B, kSRGB_SkGammaNamed);
}
@ -103,7 +103,7 @@ DEF_TEST(ColorSpaceParseICCProfiles, r) {
DEF_TEST(ColorSpaceSRGBCompare, r) {
// Create an sRGB color space by name
sk_sp<SkColorSpace> namedColorSpace = SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named);
sk_sp<SkColorSpace> namedColorSpace = SkColorSpace::MakeSRGB();
// Create an sRGB color space by value
SkMatrix44 srgbToxyzD50(SkMatrix44::kUninitialized_Constructor);
@ -132,10 +132,10 @@ DEF_TEST(ColorSpaceSRGBCompare, r) {
DEF_TEST(ColorSpaceSRGBLinearCompare, r) {
// Create the linear sRGB color space by name
sk_sp<SkColorSpace> namedColorSpace = SkColorSpace::MakeNamed(SkColorSpace::kSRGBLinear_Named);
sk_sp<SkColorSpace> namedColorSpace = SkColorSpace::MakeSRGBLinear();
// Create the linear sRGB color space via the sRGB color space's makeLinearGamma()
auto srgb = SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named);
auto srgb = SkColorSpace::MakeSRGB();
auto srgbXYZ = static_cast<SkColorSpace_XYZ*>(srgb.get());
sk_sp<SkColorSpace> viaSrgbColorSpace = srgbXYZ->makeLinearGamma();
REPORTER_ASSERT(r, namedColorSpace == viaSrgbColorSpace);
@ -178,7 +178,8 @@ DEF_TEST(ColorSpaceSRGBLinearCompare, r) {
DEF_TEST(ColorSpaceAdobeCompare, r) {
// Create an sRGB color space by name
sk_sp<SkColorSpace> namedColorSpace = SkColorSpace::MakeNamed(SkColorSpace::kAdobeRGB_Named);
sk_sp<SkColorSpace> namedColorSpace =
SkColorSpace_Base::MakeNamed(SkColorSpace_Base::kAdobeRGB_Named);
// Create an sRGB color space by value
SkMatrix44 adobeToxyzD50(SkMatrix44::kUninitialized_Constructor);
@ -198,16 +199,16 @@ DEF_TEST(ColorSpaceAdobeCompare, r) {
DEF_TEST(ColorSpace_Named, r) {
const struct {
SkColorSpace::Named fNamed;
SkGammaNamed fExpectedGamma;
SkColorSpace_Base::Named fNamed;
SkGammaNamed fExpectedGamma;
} recs[] {
{ SkColorSpace::kSRGB_Named, kSRGB_SkGammaNamed },
{ SkColorSpace::kAdobeRGB_Named, k2Dot2Curve_SkGammaNamed },
{ SkColorSpace::kSRGBLinear_Named, kLinear_SkGammaNamed },
{ SkColorSpace_Base::kSRGB_Named, kSRGB_SkGammaNamed },
{ SkColorSpace_Base::kAdobeRGB_Named, k2Dot2Curve_SkGammaNamed },
{ SkColorSpace_Base::kSRGBLinear_Named, kLinear_SkGammaNamed },
};
for (auto rec : recs) {
auto cs = SkColorSpace::MakeNamed(rec.fNamed);
auto cs = SkColorSpace_Base::MakeNamed(rec.fNamed);
REPORTER_ASSERT(r, cs);
if (cs) {
SkASSERT(SkColorSpace_Base::Type::kXYZ == as_CSB(cs)->type());
@ -240,9 +241,9 @@ static void test_serialize(skiatest::Reporter* r, SkColorSpace* space, bool isNa
}
DEF_TEST(ColorSpace_Serialize, r) {
test_serialize(r, SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named).get(), true);
test_serialize(r, SkColorSpace::MakeNamed(SkColorSpace::kAdobeRGB_Named).get(), true);
test_serialize(r, SkColorSpace::MakeNamed(SkColorSpace::kSRGBLinear_Named).get(), true);
test_serialize(r, SkColorSpace::MakeSRGB().get(), true);
test_serialize(r, SkColorSpace_Base::MakeNamed(SkColorSpace_Base::kAdobeRGB_Named).get(), true);
test_serialize(r, SkColorSpace::MakeSRGBLinear().get(), true);
sk_sp<SkData> monitorData = SkData::MakeFromFileName(
GetResourcePath("icc_profiles/HP_ZR30w.icc").c_str());
@ -267,8 +268,8 @@ DEF_TEST(ColorSpace_Serialize, r) {
}
DEF_TEST(ColorSpace_Equals, r) {
sk_sp<SkColorSpace> srgb = SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named);
sk_sp<SkColorSpace> adobe = SkColorSpace::MakeNamed(SkColorSpace::kAdobeRGB_Named);
sk_sp<SkColorSpace> srgb = SkColorSpace::MakeSRGB();
sk_sp<SkColorSpace> adobe = SkColorSpace_Base::MakeNamed(SkColorSpace_Base::kAdobeRGB_Named);
sk_sp<SkData> data = SkData::MakeFromFileName(
GetResourcePath("icc_profiles/HP_ZR30w.icc").c_str());
sk_sp<SkColorSpace> z30 = SkColorSpace::MakeICC(data->data(), data->size());
@ -356,7 +357,7 @@ DEF_TEST(ColorSpace_Primaries, r) {
sk_sp<SkColorSpace> space = SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma,
srgbToXYZ);
REPORTER_ASSERT(r, SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named) == space);
REPORTER_ASSERT(r, SkColorSpace::MakeSRGB() == space);
// AdobeRGB primaries (D65)
SkColorSpacePrimaries adobe;
@ -377,7 +378,7 @@ DEF_TEST(ColorSpace_Primaries, r) {
fn.fB = fn.fC = fn.fD = fn.fE = fn.fF = 0.0f;
fn.fG = 2.2f;
space = SkColorSpace::MakeRGB(fn, adobeToXYZ);
REPORTER_ASSERT(r, SkColorSpace::MakeNamed(SkColorSpace::kAdobeRGB_Named) == space);
REPORTER_ASSERT(r, SkColorSpace_Base::MakeNamed(SkColorSpace_Base::kAdobeRGB_Named) == space);
// ProPhoto (D50)
SkColorSpacePrimaries proPhoto;
@ -410,6 +411,37 @@ DEF_TEST(ColorSpace_Primaries, r) {
0.1852204f, 0.5915984f, 0.0555518f,
0.1446290f, 0.0974520f, 0.7708399f);
check_primaries(r, ntsc, ntscToXYZ);
// DCI P3 (D65)
SkColorSpacePrimaries p3;
p3.fRX = 0.680f;
p3.fRY = 0.320f;
p3.fGX = 0.265f;
p3.fGY = 0.690f;
p3.fBX = 0.150f;
p3.fBY = 0.060f;
p3.fWX = 0.3127f;
p3.fWY = 0.3290f;
space = SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma,
SkColorSpace::kDCIP3_D65_Gamut);
SkMatrix44 reference(SkMatrix44::kUninitialized_Constructor);
SkAssertResult(space->toXYZD50(&reference));
check_primaries(r, p3, reference);
// Rec 2020 (D65)
SkColorSpacePrimaries rec2020;
rec2020.fRX = 0.708f;
rec2020.fRY = 0.292f;
rec2020.fGX = 0.170f;
rec2020.fGY = 0.797f;
rec2020.fBX = 0.131f;
rec2020.fBY = 0.046f;
rec2020.fWX = 0.3127f;
rec2020.fWY = 0.3290f;
space = SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma,
SkColorSpace::kRec2020_Gamut);
SkAssertResult(space->toXYZD50(&reference));
check_primaries(r, rec2020, reference);
}
DEF_TEST(ColorSpace_InvalidICC, r) {
@ -421,7 +453,7 @@ DEF_TEST(ColorSpace_InvalidICC, r) {
}
DEF_TEST(ColorSpace_MatrixHash, r) {
sk_sp<SkColorSpace> srgb = SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named);
sk_sp<SkColorSpace> srgb = SkColorSpace::MakeSRGB();
SkColorSpaceTransferFn fn;
fn.fA = 1.0f;

View File

@ -326,8 +326,8 @@ DEF_TEST(SkColorSpaceXform_LoadTail, r) {
std::unique_ptr<uint64_t[]> srcPixel(new uint64_t[1]);
srcPixel[0] = 0;
uint32_t dstPixel;
sk_sp<SkColorSpace> adobe = SkColorSpace::MakeNamed(SkColorSpace::kAdobeRGB_Named);
sk_sp<SkColorSpace> srgb = SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named);
sk_sp<SkColorSpace> adobe = SkColorSpace_Base::MakeNamed(SkColorSpace_Base::kAdobeRGB_Named);
sk_sp<SkColorSpace> srgb = SkColorSpace::MakeSRGB();
std::unique_ptr<SkColorSpaceXform> xform = SkColorSpaceXform::New(adobe.get(), srgb.get());
// ASAN will catch us if we read past the tail.

View File

@ -124,7 +124,7 @@ DEF_TEST(ICC_WriteICC, r) {
SkMatrix44 adobeMatrix(SkMatrix44::kUninitialized_Constructor);
adobeMatrix.set3x3RowMajorf(gAdobeRGB_toXYZD50);
test_write_icc(r, adobeFn, adobeMatrix,
SkColorSpace::MakeNamed(SkColorSpace::kAdobeRGB_Named).get(), false);
SkColorSpace_Base::MakeNamed(SkColorSpace_Base::kAdobeRGB_Named).get(), false);
SkColorSpaceTransferFn srgbFn;
srgbFn.fA = 1.0f / 1.055f;
@ -136,7 +136,7 @@ DEF_TEST(ICC_WriteICC, r) {
srgbFn.fG = 2.4f;
SkMatrix44 srgbMatrix(SkMatrix44::kUninitialized_Constructor);
srgbMatrix.set3x3RowMajorf(gSRGB_toXYZD50);
test_write_icc(r, srgbFn, srgbMatrix, SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named).get(),
test_write_icc(r, srgbFn, srgbMatrix, SkColorSpace::MakeSRGB().get(),
false);
}
@ -166,11 +166,11 @@ public:
};
DEF_TEST(ICC_RawTransferFns, r) {
sk_sp<SkICC> srgb = ICCTest::MakeICC(SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named));
sk_sp<SkICC> srgb = ICCTest::MakeICC(SkColorSpace::MakeSRGB());
test_raw_transfer_fn(r, srgb.get());
sk_sp<SkICC> adobe =
ICCTest::MakeICC(SkColorSpace::MakeNamed(SkColorSpace::kAdobeRGB_Named));
ICCTest::MakeICC(SkColorSpace_Base::MakeNamed(SkColorSpace_Base::kAdobeRGB_Named));
test_raw_transfer_fn(r, adobe.get());
// Lookup-table based gamma curves

View File

@ -12,6 +12,7 @@
#if SK_SUPPORT_GPU
#include "GrContext.h"
#endif
#include "SkColorSpace_Base.h"
#include "SkImage.h"
#include "SkSurface.h"
#include "SkReadBuffer.h"
@ -50,8 +51,8 @@ DEF_TEST(ImageInfo_flattening, reporter) {
sk_sp<SkColorSpace> spaces[] = {
nullptr,
SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named),
SkColorSpace::MakeNamed(SkColorSpace::kAdobeRGB_Named),
SkColorSpace::MakeSRGB(),
SkColorSpace_Base::MakeNamed(SkColorSpace_Base::kAdobeRGB_Named),
space0,
space1,
space2,
@ -126,7 +127,7 @@ DEF_TEST(Image_isAlphaOnly, reporter) {
GetResourceAsImage("color_wheel.jpg"),
SkImage::MakeFromPicture(make_picture(), { 10, 10 }, nullptr, nullptr,
SkImage::BitDepth::kU8,
SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named)),
SkColorSpace::MakeSRGB()),
})
{
REPORTER_ASSERT(reporter, image->isAlphaOnly() == false);

View File

@ -131,7 +131,7 @@ static sk_sp<SkImage> create_picture_image() {
canvas->clear(SK_ColorCYAN);
return SkImage::MakeFromPicture(recorder.finishRecordingAsPicture(), SkISize::Make(10, 10),
nullptr, nullptr, SkImage::BitDepth::kU8,
SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named));
SkColorSpace::MakeSRGB());
};
#endif
// Want to ensure that our Release is called when the owning image is destroyed
@ -486,7 +486,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkImage_makeTextureImage, reporter, contextIn
sk_sp<SkColorSpace> dstColorSpaces[] ={
nullptr,
SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named),
SkColorSpace::MakeSRGB(),
};
for (auto& dstColorSpace : dstColorSpaces) {

View File

@ -121,7 +121,7 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SRGBMipMaps, reporter, ctxInfo) {
sk_sp<GrTexture> texture(texProvider->createTexture(desc, SkBudgeted::kNo, texData, 0));
// Create two render target contexts (L32 and S32)
sk_sp<SkColorSpace> srgbColorSpace = SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named);
sk_sp<SkColorSpace> srgbColorSpace = SkColorSpace::MakeSRGB();
sk_sp<GrRenderTargetContext> l32RenderTargetContext = context->makeRenderTargetContext(
SkBackingFit::kExact, rtS, rtS, kRGBA_8888_GrPixelConfig, nullptr);
sk_sp<GrRenderTargetContext> s32RenderTargetContext = context->makeRenderTargetContext(

View File

@ -52,7 +52,7 @@ static void test_blender(std::string resourceName, skiatest::Reporter* reporter)
return;
}
SkBitmap bm;
sk_sp<SkColorSpace> srgbColorSpace = SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named);
sk_sp<SkColorSpace> srgbColorSpace = SkColorSpace::MakeSRGB();
if (!as_IB(image)->getROPixels(&bm, srgbColorSpace.get())) {
ERRORF(reporter, "Could not read resource");
return;

View File

@ -331,7 +331,7 @@ DEF_TEST(BitmapCache_discarded_image, reporter) {
return SkImage::MakeFromPicture(recorder.finishRecordingAsPicture(),
SkISize::Make(10, 10), nullptr, nullptr,
SkImage::BitDepth::kU8,
SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named));
SkColorSpace::MakeSRGB());
});
}
}

View File

@ -184,7 +184,7 @@ DEF_TEST(SpecialImage_Image_Legacy, reporter) {
}
DEF_TEST(SpecialImage_Image_ColorSpaceAware, reporter) {
sk_sp<SkColorSpace> srgbColorSpace = SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named);
sk_sp<SkColorSpace> srgbColorSpace = SkColorSpace::MakeSRGB();
test_specialimage_image(reporter, srgbColorSpace.get());
}

View File

@ -807,8 +807,8 @@ static void test_surface_creation_and_snapshot_with_color_space(
bool f16Support,
std::function<sk_sp<SkSurface>(const SkImageInfo&)> surfaceMaker) {
auto srgbColorSpace = SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named);
auto adobeColorSpace = SkColorSpace::MakeNamed(SkColorSpace::kAdobeRGB_Named);
auto srgbColorSpace = SkColorSpace::MakeSRGB();
auto adobeColorSpace = SkColorSpace_Base::MakeNamed(SkColorSpace_Base::kAdobeRGB_Named);
const SkMatrix44* srgbMatrix = as_CSB(srgbColorSpace)->toXYZD50();
SkASSERT(srgbMatrix);
SkColorSpaceTransferFn oddGamma;
@ -816,7 +816,7 @@ static void test_surface_creation_and_snapshot_with_color_space(
oddGamma.fB = oddGamma.fC = oddGamma.fD = oddGamma.fE = oddGamma.fF = 0.0f;
oddGamma.fG = 4.0f;
auto oddColorSpace = SkColorSpace::MakeRGB(oddGamma, *srgbMatrix);
auto linearColorSpace = SkColorSpace::MakeNamed(SkColorSpace::kSRGBLinear_Named);
auto linearColorSpace = SkColorSpace::MakeSRGBLinear();
const struct {
SkColorType fColorType;

View File

@ -86,7 +86,7 @@ DEF_TEST(ParseConfigs_DefaultConfigs, reporter) {
SkCommandLineConfigArray configs;
ParseConfigs(config1, &configs);
auto srgbColorSpace = SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named);
auto srgbColorSpace = SkColorSpace::MakeSRGB();
REPORTER_ASSERT(reporter, configs.count() == config1.count());
for (int i = 0; i < config1.count(); ++i) {

View File

@ -311,7 +311,7 @@ int main(int argc, char** argv) {
// Draw the sRGB gamut if requested.
if (FLAGS_sRGB_gamut) {
sk_sp<SkColorSpace> sRGBSpace = SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named);
sk_sp<SkColorSpace> sRGBSpace = SkColorSpace::MakeSRGB();
const SkMatrix44* mat = as_CSB(sRGBSpace)->toXYZD50();
SkASSERT(mat);
draw_gamut(&gamutCanvas, *mat, "sRGB", 0xFFFF9394, false);
@ -319,7 +319,8 @@ int main(int argc, char** argv) {
// Draw the Adobe RGB gamut if requested.
if (FLAGS_adobeRGB) {
sk_sp<SkColorSpace> adobeRGBSpace = SkColorSpace::MakeNamed(SkColorSpace::kAdobeRGB_Named);
sk_sp<SkColorSpace> adobeRGBSpace =
SkColorSpace_Base::MakeNamed(SkColorSpace_Base::kAdobeRGB_Named);
const SkMatrix44* mat = as_CSB(adobeRGBSpace)->toXYZD50();
SkASSERT(mat);
draw_gamut(&gamutCanvas, *mat, "Adobe RGB", 0xFF31a9e1, false);

View File

@ -110,9 +110,9 @@ int main() {
if (options.f16) {
SkASSERT(options.srgb);
colorType = kRGBA_F16_SkColorType;
colorSpace = SkColorSpace::MakeNamed(SkColorSpace::kSRGBLinear_Named);
colorSpace = SkColorSpace::MakeSRGBLinear();
} else if (options.srgb) {
colorSpace = SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named);
colorSpace = SkColorSpace::MakeSRGB();
}
SkImageInfo info = SkImageInfo::Make(options.size.width(), options.size.height(), colorType,
kPremul_SkAlphaType, colorSpace);

View File

@ -291,8 +291,8 @@ static bool parse_option_gpu_color(const SkString& value,
// First, figure out color gamut that we'll work in (default to sRGB)
const bool linearGamma = commands[0].equals("f16");
*outColorSpace = SkColorSpace::MakeNamed(linearGamma ? SkColorSpace::kSRGBLinear_Named
: SkColorSpace::kSRGB_Named);
*outColorSpace = linearGamma ? SkColorSpace::MakeSRGBLinear()
: SkColorSpace::MakeSRGB();
if (commands.count() == 2) {
if (commands[1].equals("srgb")) {
// sRGB gamut (which is our default)

View File

@ -82,7 +82,7 @@ namespace sk_tools {
SkAutoTMalloc<uint32_t> rgba(w*h);
auto srgbColorSpace = SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named);
auto srgbColorSpace = SkColorSpace::MakeSRGB();
if (bitmap. colorType() == kN32_SkColorType &&
bitmap.colorSpace() == srgbColorSpace.get()) {
// These are premul sRGB 8-bit pixels in SkPMColor order.

View File

@ -179,8 +179,8 @@ SkSurface* Request::createCPUSurface() {
SkIRect bounds = this->getBounds();
ColorAndProfile cap = ColorModes[fColorMode];
auto colorSpace = kRGBA_F16_SkColorType == cap.fColorType
? SkColorSpace::MakeNamed(SkColorSpace::kSRGBLinear_Named)
: SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named);
? SkColorSpace::MakeSRGBLinear()
: SkColorSpace::MakeSRGB();
SkImageInfo info = SkImageInfo::Make(bounds.width(), bounds.height(), cap.fColorType,
kPremul_SkAlphaType, cap.fSRGB ? colorSpace : nullptr);
return SkSurface::MakeRaster(info).release();
@ -191,8 +191,8 @@ SkSurface* Request::createGPUSurface() {
SkIRect bounds = this->getBounds();
ColorAndProfile cap = ColorModes[fColorMode];
auto colorSpace = kRGBA_F16_SkColorType == cap.fColorType
? SkColorSpace::MakeNamed(SkColorSpace::kSRGBLinear_Named)
: SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named);
? SkColorSpace::MakeSRGBLinear()
: SkColorSpace::MakeSRGB();
SkImageInfo info = SkImageInfo::Make(bounds.width(), bounds.height(), cap.fColorType,
kPremul_SkAlphaType, cap.fSRGB ? colorSpace: nullptr);
SkSurface* surface = SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info).release();

View File

@ -10,7 +10,7 @@
#include "SkBitmap.h"
#include "SkCodec.h"
#include "SkColorSpaceXform.h"
#include "SkColorSpace.h"
#include "SkColorSpace_Base.h"
#include "SkCanvas.h"
#include "SkData.h"
#include "SkImage.h"
@ -46,7 +46,7 @@ void ImageSlide::load(SkScalar, SkScalar) {
codec->getPixels(codec->getInfo(), fOriginalBitmap.getPixels(), fOriginalBitmap.rowBytes());
SkImageInfo xformedInfo = codec->getInfo().makeColorSpace(
SkColorSpace::MakeNamed(SkColorSpace::kAdobeRGB_Named));
SkColorSpace_Base::MakeNamed(SkColorSpace_Base::kAdobeRGB_Named));
fXformedBitmap.allocPixels(xformedInfo);
codec->getPixels(xformedInfo, fXformedBitmap.getPixels(), fXformedBitmap.rowBytes());
}

View File

@ -165,7 +165,7 @@ Viewer::Viewer(int argc, char** argv, void* platformData)
fCommands.addCommand('c', "Modes", "Toggle sRGB color mode", [this]() {
DisplayParams params = fWindow->getDisplayParams();
params.fColorSpace = (nullptr == params.fColorSpace)
? SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named) : nullptr;
? SkColorSpace::MakeSRGB() : nullptr;
fWindow->setDisplayParams(params);
this->updateTitle();
fWindow->inval();

View File

@ -171,7 +171,7 @@ bool VulkanWindowContext::createSwapchain(int width, int height,
// Pick our surface format. For now, just make sure it matches our sRGB request:
VkFormat surfaceFormat = VK_FORMAT_UNDEFINED;
VkColorSpaceKHR colorSpace = VK_COLORSPACE_SRGB_NONLINEAR_KHR;
auto srgbColorSpace = SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named);
auto srgbColorSpace = SkColorSpace::MakeSRGB();
bool wantSRGB = srgbColorSpace == params.fColorSpace;
for (uint32_t i = 0; i < surfaceFormatCount; ++i) {
GrPixelConfig config;

View File

@ -43,7 +43,7 @@ sk_sp<SkSurface> WindowContext::createSurface(
fWidth, fHeight,
fDisplayParams.fColorType,
kPremul_SkAlphaType,
forceSRGB ? SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named)
forceSRGB ? SkColorSpace::MakeSRGB()
: fDisplayParams.fColorSpace
);
if (this->isGpuContext()) {
@ -54,7 +54,7 @@ sk_sp<SkSurface> WindowContext::createSurface(
}
} else {
sk_sp<SkColorSpace> colorSpace = GrPixelConfigIsSRGB(rtDesc->fConfig)
? SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named) : nullptr;
? SkColorSpace::MakeSRGB() : nullptr;
return SkSurface::MakeFromBackendRenderTarget(fContext, *rtDesc, colorSpace,
&fSurfaceProps);
}

View File

@ -102,7 +102,7 @@ void GLWindowContext_android::onInitializeContext() {
EGL_NONE,
};
const EGLint* windowAttribs = nullptr;
auto srgbColorSpace = SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named);
auto srgbColorSpace = SkColorSpace::MakeSRGB();
if (srgbColorSpace == fDisplayParams.fColorSpace && majorVersion == 1 && minorVersion >= 2) {
windowAttribs = srgbWindowAttribs;
}