Is your feature request related to a problem? Please describe.
I need to draw colors in linear RGBA color space using SKShader.
The SKShader.CreateColor method only has color parameter. Skia has another method with additional parameter color space.
static sk_sp<SkShader> SkShader::MakeColorShader(const SkColor4f&, sk_sp<SkColorSpace>)
Describe the solution you'd like
Add new API for SKShader:
C#
public static SkiaSharp.SKShader CreateColor (SkiaSharp.SKColor color, SKColorSpace colorSpace);
Also gradient shaders take SKColorSpace as additional parameter. So adding those API's is also requested.
https://skia-doc.commondatastorage.googleapis.com/doxygen/doxygen/html/classSkGradientShader.html
static sk_sp< SkShader > MakeLinear (const SkPoint pts[2], const SkColor4f colors[], sk_sp< SkColorSpace > colorSpace, const SkScalar pos[], int count, SkShader::TileMode mode, uint32_t flags, const SkMatrix *localMatrix)
static sk_sp< SkShader > MakeLinear (const SkPoint pts[2], const SkColor4f colors[], sk_sp< SkColorSpace > colorSpace, const SkScalar pos[], int count, SkShader::TileMode mode)
static sk_sp< SkShader > MakeRadial (const SkPoint ¢er, SkScalar radius, const SkColor4f colors[], sk_sp< SkColorSpace > colorSpace, const SkScalar pos[], int count, SkShader::TileMode mode, uint32_t flags, const SkMatrix *localMatrix)
static sk_sp< SkShader > MakeRadial (const SkPoint ¢er, SkScalar radius, const SkColor4f colors[], sk_sp< SkColorSpace > colorSpace, const SkScalar pos[], int count, SkShader::TileMode mode)
static sk_sp< SkShader > MakeTwoPointConical (const SkPoint &start, SkScalar startRadius, const SkPoint &end, SkScalar endRadius, const SkColor4f colors[], sk_sp< SkColorSpace > colorSpace, const SkScalar pos[], int count, SkShader::TileMode mode, uint32_t flags, const SkMatrix *localMatrix)
static sk_sp< SkShader > MakeTwoPointConical (const SkPoint &start, SkScalar startRadius, const SkPoint &end, SkScalar endRadius, const SkColor4f colors[], sk_sp< SkColorSpace > colorSpace, const SkScalar pos[], int count, SkShader::TileMode mode)
static sk_sp< SkShader > MakeSweep (SkScalar cx, SkScalar cy, const SkColor4f colors[], sk_sp< SkColorSpace > colorSpace, const SkScalar pos[], int count, uint32_t flags, const SkMatrix *localMatrix)
static sk_sp< SkShader > MakeSweep (SkScalar cx, SkScalar cy, const SkColor4f colors[], sk_sp< SkColorSpace > colorSpace, const SkScalar pos[], int count)
I can do that :)
This API proposal comes from this article Best Practices for Color Correct Skia.
So PR #1116 adds all the cases where SKColorF is used - which just seems to be SKShader and the Erase method of SKPixmap.
@mattleibow Great! I will try to test changes if that possible.
Just merged the things and I will get a release out ASAP.
Just merged the things and I will get a release out ASAP.
That was quick. Thanks!
Work has been done, features been added, previews published. Check out the brand new preview (1.68.2-preview.29) that just left the gates! https://github.com/mono/SkiaSharp/releases/tag/v1.68.2-preview.29
Now I need to figure out how to do Color Correct Skia, I am experimenting with 1.68.2-preview.29 but getting correct SKColorSpace to work and achieving Color Correct Skia is not yet straightforward.
And now I discovered this (actually read again the doc):
SkShaders (also stored on SkPaint) can be used to create more complex colors. Color and gradient shaders typically accept SkColor4f (float colors). These high precision colors can be in any gamut, but must have a linear transfer function.
Most helpful comment
Work has been done, features been added, previews published. Check out the brand new preview (1.68.2-preview.29) that just left the gates! https://github.com/mono/SkiaSharp/releases/tag/v1.68.2-preview.29