From: Matt Sarett Date: Mon, 6 Feb 2017 17:59:48 +0000 (-0500) Subject: SkColorSpace: remove named API, add gamut API X-Git-Tag: accepted/tizen/5.0/unified/20181102.025319~55^2~468 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ecaaf6f1c156e5690200322fc2636380c1f63dd8;p=platform%2Fupstream%2FlibSkiaSharp.git SkColorSpace: remove named API, add gamut API BUG=skia: Change-Id: I01c5e1874c9a034febc64e25b3aaafb5050393a6 Reviewed-on: https://skia-review.googlesource.com/8021 Reviewed-by: Brian Osman Reviewed-by: Mike Reed Commit-Queue: Matt Sarett --- diff --git a/bench/ColorCodecBench.cpp b/bench/ColorCodecBench.cpp index 06afdc6..867b8a1 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 56b66ce..2037495 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 0391798..29f2889 100644 --- a/bench/SkLinearBitmapPipelineBench.cpp +++ b/bench/SkLinearBitmapPipelineBench.cpp @@ -93,7 +93,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 0f1e482..92475d3 100644 --- a/bench/nanobench.cpp +++ b/bench/nanobench.cpp @@ -456,10 +456,10 @@ static void create_config(const SkCommandLineConfig* config, SkTArray* 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 ca8647f..81506a7 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 88b1963..3b849c1 100644 --- a/dm/DMSrcSink.cpp +++ b/dm/DMSrcSink.cpp @@ -1014,7 +1014,7 @@ Error ColorCodecSrc::draw(SkCanvas* canvas) const { sk_sp 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 e954fc3..227c387 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 colorSpaces[] { - SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named), + SkColorSpace::MakeSRGB(), nullptr, }; for (auto colorSpace : colorSpaces) { diff --git a/gm/color4f.cpp b/gm/color4f.cpp index b5cda9f..2ebe931 100644 --- a/gm/color4f.cpp +++ b/gm/color4f.cpp @@ -76,7 +76,7 @@ DEF_SIMPLE_GM(color4f, canvas, 1024, 260) { sk_sp 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 6aea549..dfb3437 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 srcSpace = SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named); + sk_sp srcSpace = SkColorSpace::MakeSRGB(); sk_sp dstSpace = SkColorSpace::MakeRGB(SkColorSpace::kLinear_RenderTargetGamma, wideGamut); std::unique_ptr 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 s = SkShader::MakeColorShader(colors[i], space); SkPaint paint; paint.setShader(s); diff --git a/gm/encode-srgb.cpp b/gm/encode-srgb.cpp index ef889c8..991e6a1 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 fix_for_colortype(sk_sp 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 colorSpaces[] = { - nullptr, SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named), + nullptr, SkColorSpace::MakeSRGB(), }; SkBitmap bitmap; diff --git a/gm/gamma.cpp b/gm/gamma.cpp index 09f80dd..ef93d1b 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 d513bc6..3e57377 100644 --- a/gm/gamut.cpp +++ b/gm/gamut.cpp @@ -133,12 +133,12 @@ static void draw_gamut_grid(SkCanvas* canvas, SkTArray MakeLinear(const SkPoint pts[2], const GradData& data, static sk_sp 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 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 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 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 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 1a4b712..e232af3 100644 --- a/gm/image.cpp +++ b/gm/image.cpp @@ -247,7 +247,7 @@ static sk_sp 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 make_codec(const SkImageInfo& info, GrContext*, void (*draw)(SkCanvas*)) { @@ -346,7 +346,7 @@ static SkImageGenerator* gen_picture(const SkImageInfo& info) { sk_sp 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) { diff --git a/gm/image_pict.cpp b/gm/image_pict.cpp index c168bc9..286470d 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 522d373..02e6679 100644 --- a/gm/image_shader.cpp +++ b/gm/image_shader.cpp @@ -49,7 +49,7 @@ static sk_sp make_texture(GrContext* ctx, SkPicture* pic, const SkImage static sk_sp 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 make_encode_gen(GrContext* ctx, SkPicture* pic, const SkImageInfo& info) { diff --git a/gm/mipmap.cpp b/gm/mipmap.cpp index fa25828..f7bd715 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 limg = make(nullptr); - sk_sp simg = make(SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named)); + sk_sp 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 limg = make_g8_gradient(nullptr); - sk_sp simg = make_g8_gradient(SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named)); + sk_sp 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 3c59f10..3f8553c 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 df7fb07..ad9bf8d 100644 --- a/gm/readpixels.cpp +++ b/gm/readpixels.cpp @@ -86,7 +86,7 @@ static sk_sp 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 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 srgb = fix_for_colortype( - SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named).get(), dstColorType); + SkColorSpace::MakeSRGB().get(), dstColorType); sk_sp 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 colorSpaces[] = { make_wide_gamut(), - SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named), + SkColorSpace::MakeSRGB(), make_small_gamut(), }; @@ -237,7 +237,7 @@ protected: }; const sk_sp 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 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 449b229..0d7cab1 100644 --- a/gm/verylargebitmap.cpp +++ b/gm/verylargebitmap.cpp @@ -34,7 +34,7 @@ static sk_sp 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 (*ImageMakerProc)(int width, int height, SkColor colors[2]); diff --git a/gn/android_framework_defines.gni b/gn/android_framework_defines.gni index b693d28..45241d8 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 1bcb44f..0399ca8 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 MakeNamed(Named); +#endif + + /** + * Create the sRGB color space. + */ + static sk_sp 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 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 MakeRGB(RenderTargetGamma gamma, Gamut gamut); static sk_sp MakeRGB(RenderTargetGamma gamma, const SkMatrix44& toXYZD50); + static sk_sp MakeRGB(const SkColorSpaceTransferFn& coeffs, Gamut gamut); static sk_sp MakeRGB(const SkColorSpaceTransferFn& coeffs, - const SkMatrix44& toXYZD50); - - /** - * Create a common, named SkColorSpace. - */ - static sk_sp MakeNamed(Named); + const SkMatrix44& toXYZD50); /** * Create an SkColorSpace from an ICC profile. diff --git a/samplecode/SampleApp.cpp b/samplecode/SampleApp.cpp index 5b0b9d6..81a8fe8 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 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 26b9638..5fc7bfc 100644 --- a/src/codec/SkAndroidCodec.cpp +++ b/src/codec/SkAndroidCodec.cpp @@ -131,9 +131,9 @@ sk_sp 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 66ad0ca..cd46a54 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 af0e8bc..2903717 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 03a901b..995aaa6 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 468b0b8..b6258ab 100644 --- a/src/codec/SkPngCodec.cpp +++ b/src/codec/SkPngCodec.cpp @@ -352,7 +352,7 @@ sk_sp 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 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 843ccf0..1684a16 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 6356e30..d59789b 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 dbc141e..bd69f65 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 32d9b43..5c8bde6 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_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 3c1ce25..645410c 100644 --- a/src/core/SkColorSpace.cpp +++ b/src/core/SkColorSpace.cpp @@ -117,17 +117,17 @@ sk_sp 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::MakeRGB(const SkColorSpaceTransferFn& coeffs, std::move(gammas), toXYZD50, nullptr)); } +sk_sp SkColorSpace::MakeRGB(RenderTargetGamma gamma, Gamut gamut) { + SkMatrix44 toXYZD50(SkMatrix44::kUninitialized_Constructor); + to_xyz_d50(&toXYZD50, gamut); + return SkColorSpace::MakeRGB(gamma, toXYZD50); +} + +sk_sp 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::MakeNamed(Named named) { + return SkColorSpace_Base::MakeNamed((SkColorSpace_Base::Named) named); +} +#endif + +sk_sp SkColorSpace_Base::MakeNamed(Named named) { static SkOnce sRGBOnce; static SkOnce adobeRGBOnce; static SkOnce sRGBLinearOnce; @@ -232,6 +250,14 @@ sk_sp SkColorSpace::MakeNamed(Named named) { return nullptr; } +sk_sp SkColorSpace::MakeSRGB() { + return SkColorSpace_Base::MakeNamed(SkColorSpace_Base::kSRGB_Named); +} + +sk_sp 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::Deserialize(const void* data, size_t length) { data = SkTAddOffset(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 5b09036..26ccd5e 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 3321945..99248b8 100644 --- a/src/core/SkColorSpace_A2B.h +++ b/src/core/SkColorSpace_A2B.h @@ -55,12 +55,12 @@ public: sk_sp 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 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 88905b3..a3210aa 100644 --- a/src/core/SkColorSpace_Base.h +++ b/src/core/SkColorSpace_Base.h @@ -194,6 +194,14 @@ public: static sk_sp MakeRGB(SkGammaNamed gammaNamed, const SkMatrix44& toXYZD50); + enum Named : uint8_t { + kSRGB_Named, + kAdobeRGB_Named, + kSRGBLinear_Named, + }; + + static sk_sp MakeNamed(Named); + protected: SkColorSpace_Base(sk_sp profileData); diff --git a/src/core/SkImageCacherator.cpp b/src/core/SkImageCacherator.cpp index 1556683..8920fc6 100644 --- a/src/core/SkImageCacherator.cpp +++ b/src/core/SkImageCacherator.cpp @@ -96,7 +96,7 @@ SkImageCacherator::Validator::Validator(sk_sp 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 1b7c09b..5d0710d 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 5a60409..821c882 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(Sk4b::Load(&color)) * (1/255.0f)).store(&color4f); diff --git a/src/core/SkShader.cpp b/src/core/SkShader.cpp index 9da760f..81aae11 100644 --- a/src/core/SkShader.cpp +++ b/src/core/SkShader.cpp @@ -280,7 +280,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 03a2db0..f50311b 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 8e90b04..918d8d4 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 35af494..1d3b775 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 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(SK_ARRAY_COUNT(gColorSpaces)))]; } @@ -310,8 +310,8 @@ sk_sp TestColorXform(SkRandom* random) { static bool gOnce; if (!gOnce) { gOnce = true; - sk_sp srgb = SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named); - sk_sp adobe = SkColorSpace::MakeNamed(SkColorSpace::kAdobeRGB_Named); + sk_sp srgb = SkColorSpace::MakeSRGB(); + sk_sp 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 ad43eef..0dbe577 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 e54cfb7..f86bb9f 100644 --- a/src/views/SkWindow.cpp +++ b/src/views/SkWindow.cpp @@ -354,7 +354,7 @@ sk_sp SkWindow::makeGpuBackedSurface(const AttachmentInfo& attachment sk_sp 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 65e0450..2bc735a 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 namedColorSpace = SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named); + sk_sp 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 namedColorSpace = SkColorSpace::MakeNamed(SkColorSpace::kSRGBLinear_Named); + sk_sp 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(srgb.get()); sk_sp 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 namedColorSpace = SkColorSpace::MakeNamed(SkColorSpace::kAdobeRGB_Named); + sk_sp 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 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 srgb = SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named); - sk_sp adobe = SkColorSpace::MakeNamed(SkColorSpace::kAdobeRGB_Named); + sk_sp srgb = SkColorSpace::MakeSRGB(); + sk_sp adobe = SkColorSpace_Base::MakeNamed(SkColorSpace_Base::kAdobeRGB_Named); sk_sp data = SkData::MakeFromFileName( GetResourcePath("icc_profiles/HP_ZR30w.icc").c_str()); sk_sp z30 = SkColorSpace::MakeICC(data->data(), data->size()); @@ -356,7 +357,7 @@ DEF_TEST(ColorSpace_Primaries, r) { sk_sp 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 srgb = SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named); + sk_sp srgb = SkColorSpace::MakeSRGB(); SkColorSpaceTransferFn fn; fn.fA = 1.0f; diff --git a/tests/ColorSpaceXformTest.cpp b/tests/ColorSpaceXformTest.cpp index bdcdd3e..f8a5c8f 100644 --- a/tests/ColorSpaceXformTest.cpp +++ b/tests/ColorSpaceXformTest.cpp @@ -326,8 +326,8 @@ DEF_TEST(SkColorSpaceXform_LoadTail, r) { std::unique_ptr srcPixel(new uint64_t[1]); srcPixel[0] = 0; uint32_t dstPixel; - sk_sp adobe = SkColorSpace::MakeNamed(SkColorSpace::kAdobeRGB_Named); - sk_sp srgb = SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named); + sk_sp adobe = SkColorSpace_Base::MakeNamed(SkColorSpace_Base::kAdobeRGB_Named); + sk_sp srgb = SkColorSpace::MakeSRGB(); std::unique_ptr 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 794483c..5d541bd 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 srgb = ICCTest::MakeICC(SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named)); + sk_sp srgb = ICCTest::MakeICC(SkColorSpace::MakeSRGB()); test_raw_transfer_fn(r, srgb.get()); sk_sp 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 cbbe331..81f1d76 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 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 500efef..14f6057 100644 --- a/tests/ImageTest.cpp +++ b/tests/ImageTest.cpp @@ -131,7 +131,7 @@ static sk_sp 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 diff --git a/tests/SRGBMipMapTest.cpp b/tests/SRGBMipMapTest.cpp index 22d6890..dbdcaec 100644 --- a/tests/SRGBMipMapTest.cpp +++ b/tests/SRGBMipMapTest.cpp @@ -121,7 +121,7 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SRGBMipMaps, reporter, ctxInfo) { sk_sp texture(texProvider->createTexture(desc, SkBudgeted::kNo, texData, 0)); // Create two render target contexts (L32 and S32) - sk_sp srgbColorSpace = SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named); + sk_sp srgbColorSpace = SkColorSpace::MakeSRGB(); sk_sp l32RenderTargetContext = context->makeRenderTargetContext( SkBackingFit::kExact, rtS, rtS, kRGBA_8888_GrPixelConfig, nullptr); sk_sp s32RenderTargetContext = context->makeRenderTargetContext( diff --git a/tests/SkBlend_optsTest.cpp b/tests/SkBlend_optsTest.cpp index 554818a..f8cf2d8 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 srgbColorSpace = SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named); + sk_sp 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 922acef..2141885 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 551efff..94683a0 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 srgbColorSpace = SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named); + sk_sp srgbColorSpace = SkColorSpace::MakeSRGB(); test_specialimage_image(reporter, srgbColorSpace.get()); } diff --git a/tests/SurfaceTest.cpp b/tests/SurfaceTest.cpp index 2097ab3..dd71943 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(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 9675eed..70fe0e2 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 c2b33b0..73d6d2b 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 sRGBSpace = SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named); + sk_sp 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 adobeRGBSpace = SkColorSpace::MakeNamed(SkColorSpace::kAdobeRGB_Named); + sk_sp 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 2e3d37b..3299006 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 6dcb2f1..65ba372 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 84925b4..b0fd224 100644 --- a/tools/picture_utils.cpp +++ b/tools/picture_utils.cpp @@ -82,7 +82,7 @@ namespace sk_tools { SkAutoTMalloc 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 ff8849a..0fbccc3 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 0ffd4ea..0b52a81 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 49a331b..0b93afc 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 4802e21..898710f 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 3da8dd1..8efe9bd 100644 --- a/tools/viewer/sk_app/WindowContext.cpp +++ b/tools/viewer/sk_app/WindowContext.cpp @@ -43,7 +43,7 @@ sk_sp 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 WindowContext::createSurface( } } else { sk_sp 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 9f68396..20a7631 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; }