aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Matt Sarett <msarett@google.com>2017-02-07 13:56:11 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-02-07 19:33:37 +0000
commit77a7a1b57c16c97f056c1e50c03bdc954947778c (patch)
tree15ffacdee0ba8b0a0c8ac244302ef10ead4f915e
parent4f51aa57eaa4187696f7830ee7bdac096bc47ccc (diff)
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>
-rw-r--r--bench/ColorCodecBench.cpp2
-rw-r--r--bench/GrMipMapBench.cpp2
-rw-r--r--bench/SkLinearBitmapPipelineBench.cpp2
-rw-r--r--bench/nanobench.cpp4
-rw-r--r--dm/DM.cpp4
-rw-r--r--dm/DMSrcSink.cpp2
-rw-r--r--gm/all_bitmap_configs.cpp2
-rw-r--r--gm/color4f.cpp4
-rw-r--r--gm/colorspacexform.cpp4
-rw-r--r--gm/encode-srgb.cpp4
-rw-r--r--gm/gamma.cpp2
-rw-r--r--gm/gamut.cpp4
-rw-r--r--gm/gradients.cpp10
-rw-r--r--gm/image.cpp6
-rw-r--r--gm/image_pict.cpp4
-rw-r--r--gm/image_shader.cpp2
-rw-r--r--gm/mipmap.cpp4
-rw-r--r--gm/pictureimagegenerator.cpp2
-rw-r--r--gm/readpixels.cpp10
-rw-r--r--gm/verylargebitmap.cpp2
-rw-r--r--gn/android_framework_defines.gni1
-rw-r--r--include/core/SkColorSpace.h39
-rw-r--r--samplecode/SampleApp.cpp8
-rw-r--r--src/codec/SkAndroidCodec.cpp4
-rw-r--r--src/codec/SkBmpCodec.cpp2
-rw-r--r--src/codec/SkGifCodec.cpp2
-rw-r--r--src/codec/SkJpegCodec.cpp2
-rw-r--r--src/codec/SkPngCodec.cpp6
-rw-r--r--src/codec/SkRawCodec.cpp2
-rw-r--r--src/codec/SkWbmpCodec.cpp2
-rw-r--r--src/codec/SkWebpCodec.cpp2
-rw-r--r--src/core/SkColorShader.cpp2
-rw-r--r--src/core/SkColorSpace.cpp48
-rw-r--r--src/core/SkColorSpacePriv.h29
-rw-r--r--src/core/SkColorSpace_A2B.h4
-rw-r--r--src/core/SkColorSpace_Base.h8
-rw-r--r--src/core/SkImageCacherator.cpp2
-rw-r--r--src/core/SkImageInfo.cpp2
-rw-r--r--src/core/SkPM4fPriv.h2
-rw-r--r--src/core/SkShader.cpp2
-rw-r--r--src/effects/gradients/SkGradientShader.cpp6
-rw-r--r--src/gpu/GrRenderTargetContext.cpp2
-rw-r--r--src/gpu/GrTestUtils.cpp10
-rw-r--r--src/gpu/SkGr.cpp2
-rw-r--r--src/views/SkWindow.cpp2
-rw-r--r--tests/ColorSpaceTest.cpp70
-rw-r--r--tests/ColorSpaceXformTest.cpp4
-rw-r--r--tests/ICCTest.cpp8
-rw-r--r--tests/ImageIsOpaqueTest.cpp7
-rw-r--r--tests/ImageTest.cpp4
-rw-r--r--tests/SRGBMipMapTest.cpp2
-rw-r--r--tests/SkBlend_optsTest.cpp2
-rw-r--r--tests/SkResourceCacheTest.cpp2
-rw-r--r--tests/SpecialImageTest.cpp2
-rw-r--r--tests/SurfaceTest.cpp6
-rw-r--r--tests/TestConfigParsing.cpp2
-rw-r--r--tools/colorspaceinfo.cpp5
-rw-r--r--tools/fiddle/fiddle_main.cpp4
-rw-r--r--tools/flags/SkCommonFlagsConfig.cpp4
-rw-r--r--tools/picture_utils.cpp2
-rw-r--r--tools/skiaserve/Request.cpp8
-rw-r--r--tools/viewer/ImageSlide.cpp4
-rw-r--r--tools/viewer/Viewer.cpp2
-rw-r--r--tools/viewer/sk_app/VulkanWindowContext.cpp2
-rw-r--r--tools/viewer/sk_app/WindowContext.cpp4
-rw-r--r--tools/viewer/sk_app/android/GLWindowContext_android.cpp2
66 files changed, 266 insertions, 147 deletions
diff --git a/bench/ColorCodecBench.cpp b/bench/ColorCodecBench.cpp
index 06afdc6565..867b8a1418 100644
--- a/bench/ColorCodecBench.cpp
+++ b/bench/ColorCodecBench.cpp
@@ -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;
diff --git a/bench/GrMipMapBench.cpp b/bench/GrMipMapBench.cpp
index 56b66ced25..2037495bc0 100644
--- a/bench/GrMipMapBench.cpp
+++ b/bench/GrMipMapBench.cpp
@@ -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);
diff --git a/bench/SkLinearBitmapPipelineBench.cpp b/bench/SkLinearBitmapPipelineBench.cpp
index 4e892b6a06..a0ed605983 100644
--- a/bench/SkLinearBitmapPipelineBench.cpp
+++ b/bench/SkLinearBitmapPipelineBench.cpp
@@ -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 {
diff --git a/bench/nanobench.cpp b/bench/nanobench.cpp
index 0f1e4825e2..92475d31f8 100644
--- a/bench/nanobench.cpp
+++ b/bench/nanobench.cpp
@@ -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)
}
diff --git a/dm/DM.cpp b/dm/DM.cpp
index ca8647f815..81506a78cc 100644
--- a/dm/DM.cpp
+++ b/dm/DM.cpp
@@ -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);
diff --git a/dm/DMSrcSink.cpp b/dm/DMSrcSink.cpp
index 88b1963662..3b849c14ac 100644
--- a/dm/DMSrcSink.cpp
+++ b/dm/DMSrcSink.cpp
@@ -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());
}
diff --git a/gm/all_bitmap_configs.cpp b/gm/all_bitmap_configs.cpp
index e954fc33e5..227c387f52 100644
--- a/gm/all_bitmap_configs.cpp
+++ b/gm/all_bitmap_configs.cpp
@@ -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) {
diff --git a/gm/color4f.cpp b/gm/color4f.cpp
index b5cda9fa99..2ebe9315a5 100644
--- a/gm/color4f.cpp
+++ b/gm/color4f.cpp
@@ -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)
diff --git a/gm/colorspacexform.cpp b/gm/colorspacexform.cpp
index 6aea549ea8..dfb343778c 100644
--- a/gm/colorspacexform.cpp
+++ b/gm/colorspacexform.cpp
@@ -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);
diff --git a/gm/encode-srgb.cpp b/gm/encode-srgb.cpp
index ef889c8f82..991e6a1c42 100644
--- a/gm/encode-srgb.cpp
+++ b/gm/encode-srgb.cpp
@@ -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;
diff --git a/gm/gamma.cpp b/gm/gamma.cpp
index 09f80dd327..ef93d1b9e5 100644
--- a/gm/gamma.cpp
+++ b/gm/gamma.cpp
@@ -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);
diff --git a/gm/gamut.cpp b/gm/gamut.cpp
index d513bc65c9..3e57377fe9 100644
--- a/gm/gamut.cpp
+++ b/gm/gamut.cpp
@@ -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;
diff --git a/gm/gradients.cpp b/gm/gradients.cpp
index 8ae1dd7901..099e7cd712 100644
--- a/gm/gradients.cpp
+++ b/gm/gradients.cpp
@@ -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);
diff --git a/gm/image.cpp b/gm/image.cpp
index 2b92dfd60e..f2f21923d5 100644
--- a/gm/image.cpp
+++ b/gm/image.cpp
@@ -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);
diff --git a/gm/image_pict.cpp b/gm/image_pict.cpp
index c168bc9fb9..286470d1e9 100644
--- a/gm/image_pict.cpp
+++ b/gm/image_pict.cpp
@@ -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 {
diff --git a/gm/image_shader.cpp b/gm/image_shader.cpp
index 522d37340e..02e667957f 100644
--- a/gm/image_shader.cpp
+++ b/gm/image_shader.cpp
@@ -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) {
diff --git a/gm/mipmap.cpp b/gm/mipmap.cpp
index fa25828f7d..f7bd715016 100644
--- a/gm/mipmap.cpp
+++ b/gm/mipmap.cpp
@@ -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());
diff --git a/gm/pictureimagegenerator.cpp b/gm/pictureimagegenerator.cpp
index 3c59f108d8..3f8553c559 100644
--- a/gm/pictureimagegenerator.cpp
+++ b/gm/pictureimagegenerator.cpp
@@ -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;
diff --git a/gm/readpixels.cpp b/gm/readpixels.cpp
index df7fb0751a..ad9bf8d4f4 100644
--- a/gm/readpixels.cpp
+++ b/gm/readpixels.cpp
@@ -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[] = {
diff --git a/gm/verylargebitmap.cpp b/gm/verylargebitmap.cpp
index 449b22985c..0d7cab150d 100644
--- a/gm/verylargebitmap.cpp
+++ b/gm/verylargebitmap.cpp
@@ -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]);
diff --git a/gn/android_framework_defines.gni b/gn/android_framework_defines.gni
index b693d2808d..45241d8e6b 100644
--- a/gn/android_framework_defines.gni
+++ b/gn/android_framework_defines.gni
@@ -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",
]
diff --git a/include/core/SkColorSpace.h b/include/core/SkColorSpace.h
index 1bcb44fbc5..0399ca8c72 100644
--- a/include/core/SkColorSpace.h
+++ b/include/core/SkColorSpace.h
@@ -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.
diff --git a/samplecode/SampleApp.cpp b/samplecode/SampleApp.cpp
index 5b0b9d605d..81a8fe8fed 100644
--- a/samplecode/SampleApp.cpp
+++ b/samplecode/SampleApp.cpp
@@ -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:
diff --git a/src/codec/SkAndroidCodec.cpp b/src/codec/SkAndroidCodec.cpp
index 26b9638c96..5fc7bfc585 100644
--- a/src/codec/SkAndroidCodec.cpp
+++ b/src/codec/SkAndroidCodec.cpp
@@ -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;
diff --git a/src/codec/SkBmpCodec.cpp b/src/codec/SkBmpCodec.cpp
index 66ad0caa2b..cd46a5495c 100644
--- a/src/codec/SkBmpCodec.cpp
+++ b/src/codec/SkBmpCodec.cpp
@@ -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)))
diff --git a/src/codec/SkGifCodec.cpp b/src/codec/SkGifCodec.cpp
index af0e8bc242..2903717b48 100644
--- a/src/codec/SkGifCodec.cpp
+++ b/src/codec/SkGifCodec.cpp
@@ -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());
}
diff --git a/src/codec/SkJpegCodec.cpp b/src/codec/SkJpegCodec.cpp
index 03a901bed0..995aaa6b96 100644
--- a/src/codec/SkJpegCodec.cpp
+++ b/src/codec/SkJpegCodec.cpp
@@ -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;
diff --git a/src/codec/SkPngCodec.cpp b/src/codec/SkPngCodec.cpp
index 468b0b8731..b6258ab8b0 100644
--- a/src/codec/SkPngCodec.cpp
+++ b/src/codec/SkPngCodec.cpp
@@ -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);
diff --git a/src/codec/SkRawCodec.cpp b/src/codec/SkRawCodec.cpp
index 843ccf0fe5..1684a16884 100644
--- a/src/codec/SkRawCodec.cpp
+++ b/src/codec/SkRawCodec.cpp
@@ -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) {}
diff --git a/src/codec/SkWbmpCodec.cpp b/src/codec/SkWbmpCodec.cpp
index 6356e30536..d59789b66e 100644
--- a/src/codec/SkWbmpCodec.cpp
+++ b/src/codec/SkWbmpCodec.cpp
@@ -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)
diff --git a/src/codec/SkWebpCodec.cpp b/src/codec/SkWebpCodec.cpp
index dbc141ebd6..bd69f658e6 100644
--- a/src/codec/SkWebpCodec.cpp
+++ b/src/codec/SkWebpCodec.cpp
@@ -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|
diff --git a/src/core/SkColorShader.cpp b/src/core/SkColorShader.cpp
index ed2a26b931..11a26cdace 100644
--- a/src/core/SkColorShader.cpp
+++ b/src/core/SkColorShader.cpp
@@ -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,
diff --git a/src/core/SkColorSpace.cpp b/src/core/SkColorSpace.cpp
index 3c1ce257f1..645410c496 100644
--- a/src/core/SkColorSpace.cpp
+++ b/src/core/SkColorSpace.cpp
@@ -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) {
diff --git a/src/core/SkColorSpacePriv.h b/src/core/SkColorSpacePriv.h
index 5b09036ea8..26ccd5e6ca 100644
--- a/src/core/SkColorSpacePriv.h
+++ b/src/core/SkColorSpacePriv.h
@@ -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;
}
diff --git a/src/core/SkColorSpace_A2B.h b/src/core/SkColorSpace_A2B.h
index 33219450dc..99248b80fd 100644
--- a/src/core/SkColorSpace_A2B.h
+++ b/src/core/SkColorSpace_A2B.h
@@ -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; }
diff --git a/src/core/SkColorSpace_Base.h b/src/core/SkColorSpace_Base.h
index 88905b335d..a3210aa13a 100644
--- a/src/core/SkColorSpace_Base.h
+++ b/src/core/SkColorSpace_Base.h
@@ -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);
diff --git a/src/core/SkImageCacherator.cpp b/src/core/SkImageCacherator.cpp
index 1556683456..8920fc6b8a 100644
--- a/src/core/SkImageCacherator.cpp
+++ b/src/core/SkImageCacherator.cpp
@@ -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());
}
}
diff --git a/src/core/SkImageInfo.cpp b/src/core/SkImageInfo.cpp
index 1b7c09b2f9..5d0710dc1f 100644
--- a/src/core/SkImageInfo.cpp
+++ b/src/core/SkImageInfo.cpp
@@ -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;
diff --git a/src/core/SkPM4fPriv.h b/src/core/SkPM4fPriv.h
index 5a60409d84..821c8822cb 100644
--- a/src/core/SkPM4fPriv.h
+++ b/src/core/SkPM4fPriv.h
@@ -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);
diff --git a/src/core/SkShader.cpp b/src/core/SkShader.cpp
index 9f97a7a74a..1c55df762b 100644
--- a/src/core/SkShader.cpp
+++ b/src/core/SkShader.cpp
@@ -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;
}
diff --git a/src/effects/gradients/SkGradientShader.cpp b/src/effects/gradients/SkGradientShader.cpp
index 03a2db0995..f50311b97e 100644
--- a/src/effects/gradients/SkGradientShader.cpp
+++ b/src/effects/gradients/SkGradientShader.cpp
@@ -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");
diff --git a/src/gpu/GrRenderTargetContext.cpp b/src/gpu/GrRenderTargetContext.cpp
index 8e90b04ee5..918d8d41a9 100644
--- a/src/gpu/GrRenderTargetContext.cpp
+++ b/src/gpu/GrRenderTargetContext.cpp
@@ -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();)
diff --git a/src/gpu/GrTestUtils.cpp b/src/gpu/GrTestUtils.cpp
index 35af494c9b..1d3b7756df 100644
--- a/src/gpu/GrTestUtils.cpp
+++ b/src/gpu/GrTestUtils.cpp
@@ -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
diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp
index ad43eef76d..0dbe57758b 100644
--- a/src/gpu/SkGr.cpp
+++ b/src/gpu/SkGr.cpp
@@ -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 {
diff --git a/src/views/SkWindow.cpp b/src/views/SkWindow.cpp
index e54cfb773c..f86bb9f9ef 100644
--- a/src/views/SkWindow.cpp
+++ b/src/views/SkWindow.cpp
@@ -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);
}
diff --git a/tests/ColorSpaceTest.cpp b/tests/ColorSpaceTest.cpp
index 65e0450892..2bc735aaef 100644
--- a/tests/ColorSpaceTest.cpp
+++ b/tests/ColorSpaceTest.cpp
@@ -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;
diff --git a/tests/ColorSpaceXformTest.cpp b/tests/ColorSpaceXformTest.cpp
index bdcdd3e1a4..f8a5c8fec4 100644
--- a/tests/ColorSpaceXformTest.cpp
+++ b/tests/ColorSpaceXformTest.cpp
@@ -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.
diff --git a/tests/ICCTest.cpp b/tests/ICCTest.cpp
index 794483c682..5d541bdc27 100644
--- a/tests/ICCTest.cpp
+++ b/tests/ICCTest.cpp
@@ -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
diff --git a/tests/ImageIsOpaqueTest.cpp b/tests/ImageIsOpaqueTest.cpp
index cbbe331c5b..81f1d76609 100644
--- a/tests/ImageIsOpaqueTest.cpp
+++ b/tests/ImageIsOpaqueTest.cpp
@@ -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);
diff --git a/tests/ImageTest.cpp b/tests/ImageTest.cpp
index 67ddd6cdf5..c4f8abbd00 100644
--- a/tests/ImageTest.cpp
+++ b/tests/ImageTest.cpp
@@ -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) {
diff --git a/tests/SRGBMipMapTest.cpp b/tests/SRGBMipMapTest.cpp
index 22d68903eb..dbdcaeccab 100644
--- a/tests/SRGBMipMapTest.cpp
+++ b/tests/SRGBMipMapTest.cpp
@@ -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(
diff --git a/tests/SkBlend_optsTest.cpp b/tests/SkBlend_optsTest.cpp
index 554818adec..f8cf2d83de 100644
--- a/tests/SkBlend_optsTest.cpp
+++ b/tests/SkBlend_optsTest.cpp
@@ -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;
diff --git a/tests/SkResourceCacheTest.cpp b/tests/SkResourceCacheTest.cpp
index 922aceff25..2141885b11 100644
--- a/tests/SkResourceCacheTest.cpp
+++ b/tests/SkResourceCacheTest.cpp
@@ -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());
});
}
}
diff --git a/tests/SpecialImageTest.cpp b/tests/SpecialImageTest.cpp
index 551efff6c5..94683a0cdf 100644
--- a/tests/SpecialImageTest.cpp
+++ b/tests/SpecialImageTest.cpp
@@ -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());
}
diff --git a/tests/SurfaceTest.cpp b/tests/SurfaceTest.cpp
index 2097ab3fa6..dd71943dd9 100644
--- a/tests/SurfaceTest.cpp
+++ b/tests/SurfaceTest.cpp
@@ -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;
diff --git a/tests/TestConfigParsing.cpp b/tests/TestConfigParsing.cpp
index 9675eedbc9..70fe0e2ff9 100644
--- a/tests/TestConfigParsing.cpp
+++ b/tests/TestConfigParsing.cpp
@@ -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) {
diff --git a/tools/colorspaceinfo.cpp b/tools/colorspaceinfo.cpp
index c2b33b0a39..73d6d2b5b1 100644
--- a/tools/colorspaceinfo.cpp
+++ b/tools/colorspaceinfo.cpp
@@ -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);
diff --git a/tools/fiddle/fiddle_main.cpp b/tools/fiddle/fiddle_main.cpp
index 2e3d37b08f..329900693e 100644
--- a/tools/fiddle/fiddle_main.cpp
+++ b/tools/fiddle/fiddle_main.cpp
@@ -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);
diff --git a/tools/flags/SkCommonFlagsConfig.cpp b/tools/flags/SkCommonFlagsConfig.cpp
index 6dcb2f104d..65ba372d7c 100644
--- a/tools/flags/SkCommonFlagsConfig.cpp
+++ b/tools/flags/SkCommonFlagsConfig.cpp
@@ -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)
diff --git a/tools/picture_utils.cpp b/tools/picture_utils.cpp
index 84925b4dad..b0fd224a94 100644
--- a/tools/picture_utils.cpp
+++ b/tools/picture_utils.cpp
@@ -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.
diff --git a/tools/skiaserve/Request.cpp b/tools/skiaserve/Request.cpp
index ff8849ad96..0fbccc39b3 100644
--- a/tools/skiaserve/Request.cpp
+++ b/tools/skiaserve/Request.cpp
@@ -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();
diff --git a/tools/viewer/ImageSlide.cpp b/tools/viewer/ImageSlide.cpp
index 0ffd4ea080..0b52a81ddc 100644
--- a/tools/viewer/ImageSlide.cpp
+++ b/tools/viewer/ImageSlide.cpp
@@ -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());
}
diff --git a/tools/viewer/Viewer.cpp b/tools/viewer/Viewer.cpp
index 49a331bcf4..0b93afc2b1 100644
--- a/tools/viewer/Viewer.cpp
+++ b/tools/viewer/Viewer.cpp
@@ -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();
diff --git a/tools/viewer/sk_app/VulkanWindowContext.cpp b/tools/viewer/sk_app/VulkanWindowContext.cpp
index 4802e214b4..898710f109 100644
--- a/tools/viewer/sk_app/VulkanWindowContext.cpp
+++ b/tools/viewer/sk_app/VulkanWindowContext.cpp
@@ -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;
diff --git a/tools/viewer/sk_app/WindowContext.cpp b/tools/viewer/sk_app/WindowContext.cpp
index 3da8dd1532..8efe9bd24a 100644
--- a/tools/viewer/sk_app/WindowContext.cpp
+++ b/tools/viewer/sk_app/WindowContext.cpp
@@ -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);
}
diff --git a/tools/viewer/sk_app/android/GLWindowContext_android.cpp b/tools/viewer/sk_app/android/GLWindowContext_android.cpp
index 9f683968c6..20a76314fd 100644
--- a/tools/viewer/sk_app/android/GLWindowContext_android.cpp
+++ b/tools/viewer/sk_app/android/GLWindowContext_android.cpp
@@ -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;
}