mono / SkiaSharp

SkiaSharp is a cross-platform 2D graphics API for .NET platforms based on Google's Skia Graphics Library. It provides a comprehensive 2D API that can be used across mobile, server and desktop models to render images.
MIT License
4.46k stars 539 forks source link

[FEATURE] Add support for missing SkColorFilters: HSLAMatrix, LinearToSRGBGamma, SRGBToLinearGamma, Lerp, WithWorkingFormat #1775

Open wieslawsoltes opened 3 years ago

wieslawsoltes commented 3 years ago

Is your feature request related to a problem? Please describe. When doing svg filters and processing I need additional color filters that are currently missing from SKColorFilter (especially for color space conversion LinearToSRGBGamma() and SRGBToLinearGamma())

Describe the solution you'd like

API proposal (new members in SKColorFilter class):


public static SkiaSharp.SKColorFilter SKColorFilter.CreateHSLAMatrix(float[] rowMajor);
public static SkiaSharp.SKColorFilter SKColorFilter.CreateLinearToSRGBGamma();
public static SkiaSharp.SKColorFilter SKColorFilter.CreateSRGBToLinearGamma();
public static SkiaSharp.SKColorFilter SKColorFilter.CreateLerp(float t, SKColorFilter dst, SKColorFilter src);

nor sure how WithWorkingFormat would look like

Add below API from skia to SKColorFilter

    // A version of Matrix which operates in HSLA space instead of RGBA.
    // I.e. HSLA-to-RGBA(Matrix(RGBA-to-HSLA(input))).
    static sk_sp<SkColorFilter> HSLAMatrix(const SkColorMatrix&);
    static sk_sp<SkColorFilter> HSLAMatrix(const float rowMajor[20]);

    static sk_sp<SkColorFilter> LinearToSRGBGamma();
    static sk_sp<SkColorFilter> SRGBToLinearGamma();
    static sk_sp<SkColorFilter> Lerp(float t, sk_sp<SkColorFilter> dst, sk_sp<SkColorFilter> src);

    // Runs the child filter in a different working color format than usual (premul in
    // destination surface's color space), with all inputs and outputs expressed in this format.
    // Each non-null {tf,gamut,at} parameter overrides that particular aspect of the color format.
    static sk_sp<SkColorFilter> WithWorkingFormat(sk_sp<SkColorFilter>          child,
                                                  const skcms_TransferFunction* tf,
                                                  const skcms_Matrix3x3*        gamut,
                                                  const SkAlphaType*            at);

https://github.com/google/skia/blob/1f193df9b393d50da39570dab77a0bb5d28ec8ef/include/core/SkColorFilter.h#L78-L93

Describe alternatives you've considered

Additional context

wieslawsoltes commented 2 years ago

@mattleibow Any chance on getting that included in near future ?