fDstSpace = nullptr;
if (FLAGS_srgb) {
- fDstSpace = SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named);
+ fDstSpace = SkColorSpace::MakeSRGB();
} else if (FLAGS_nonstd) {
SkColorSpaceTransferFn gamma;
gamma.fA = 1.0f;
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);
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 {
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)
}
#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);
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());
}
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) {
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,
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)
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(),
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);
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();
kUnpremul_SkAlphaType, kPremul_SkAlphaType, kOpaque_SkAlphaType,
};
const sk_sp<SkColorSpace> colorSpaces[] = {
- nullptr, SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named),
+ nullptr, SkColorSpace::MakeSRGB(),
};
SkBitmap bitmap;
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);
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;
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);
}
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);
}
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);
}
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,
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);
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*)) {
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) {
// 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);
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 {
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) {
*/
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());
*/
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());
{ 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;
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() {
// 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);
}
};
const sk_sp<SkColorSpace> colorSpaces[] = {
make_wide_gamut(),
- SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named),
+ SkColorSpace::MakeSRGB(),
make_small_gamut(),
};
};
const sk_sp<SkColorSpace> colorSpaces[] = {
make_wide_gamut(),
- SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named),
+ SkColorSpace::MakeSRGB(),
make_small_gamut(),
};
const SkImage::CachingHint hints[] = {
};
const sk_sp<SkColorSpace> colorSpaces[] = {
make_wide_gamut(),
- SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named),
+ SkColorSpace::MakeSRGB(),
make_small_gamut(),
};
const SkImage::CachingHint hints[] = {
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]);
"SK_SUPPORT_LEGACY_SHADER_ISABITMAP",
"SK_SUPPORT_LEGACY_EMBOSSMASKFILTER",
"SK_SUPPORT_EXOTIC_CLIPOPS",
+ "SK_USE_LEGACY_NAMED_COLOR_SPACE",
]
class SK_API SkColorSpace : public SkRefCnt {
public:
+#ifdef SK_USE_LEGACY_NAMED_COLOR_SPACE
/**
* Common, named profiles that we can recognize.
*/
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,
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.
// 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);
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:
{
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:
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;
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)))
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());
}
}
if (!colorSpace) {
// Treat unmarked jpegs as sRGB.
- colorSpace = SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named);
+ colorSpace = SkColorSpace::MakeSRGB();
}
const int width = decoderMgr->dinfo()->image_width;
// 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.
// 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) {
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);
SkRawCodec::SkRawCodec(SkDngImage* dngImage)
: INHERITED(dngImage->width(), dngImage->height(), dngImage->getEncodedInfo(), nullptr,
- SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named))
+ SkColorSpace::MakeSRGB())
, fDngImage(dngImage) {}
}
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)
}
}
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|
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,
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:
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;
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 {
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);
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);
}
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) {
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;
}
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; }
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);
// 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());
}
}
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;
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);
// 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;
}
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());
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");
, 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();)
#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"
// 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)))];
}
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
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 {
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);
}
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);
}
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);
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);
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);
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());
}
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());
}
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());
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;
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;
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) {
}
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;
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.
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;
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);
}
};
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
#if SK_SUPPORT_GPU
#include "GrContext.h"
#endif
+#include "SkColorSpace_Base.h"
#include "SkImage.h"
#include "SkSurface.h"
#include "SkReadBuffer.h"
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,
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);
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
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(
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;
return SkImage::MakeFromPicture(recorder.finishRecordingAsPicture(),
SkISize::Make(10, 10), nullptr, nullptr,
SkImage::BitDepth::kU8,
- SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named));
+ SkColorSpace::MakeSRGB());
});
}
}
}
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());
}
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;
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;
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) {
// 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);
// 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);
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);
// 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)
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.
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();
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();
#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"
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());
}
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();
// 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;
fWidth, fHeight,
fDisplayParams.fColorType,
kPremul_SkAlphaType,
- forceSRGB ? SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named)
+ forceSRGB ? SkColorSpace::MakeSRGB()
: fDisplayParams.fColorSpace
);
if (this->isGpuContext()) {
}
} else {
sk_sp<SkColorSpace> colorSpace = GrPixelConfigIsSRGB(rtDesc->fConfig)
- ? SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named) : nullptr;
+ ? SkColorSpace::MakeSRGB() : nullptr;
return SkSurface::MakeFromBackendRenderTarget(fContext, *rtDesc, colorSpace,
&fSurfaceProps);
}
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;
}