Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Color for Srgb color space #197

Merged
merged 1 commit into from
Jan 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/Svg.Model/SvgExtensions.Painting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,14 @@ internal static bool SetColorOrShader(SvgVisualElement svgVisualElement, SvgPain
var skColor = GetColor(svgColourServer, opacity, ignoreAttributes);
var colorInterpolation = GetColorInterpolation(svgVisualElement);
var isLinearRgb = colorInterpolation == SvgColourInterpolation.LinearRGB;

if (colorInterpolation == SvgColourInterpolation.SRGB)
{
skPaint.Color = skColor;
skPaint.Shader = null;
return true;
}

var skColorSpace = isLinearRgb ? SKColorSpace.SrgbLinear : SKColorSpace.Srgb;
var skColorShader = SKShader.CreateColor(skColor, skColorSpace);
if (skColorShader is { })
Expand Down Expand Up @@ -825,6 +833,14 @@ internal static bool SetColorOrShader(SvgVisualElement svgVisualElement, SvgPain
if (fallbackServer is SvgColourServer svgColourServerFallback)
{
var skColor = GetColor(svgColourServerFallback, opacity, ignoreAttributes);

if (skColorSpace == SKColorSpace.Srgb)
{
skPaint.Color = skColor;
skPaint.Shader = null;
return true;
}

var skColorShader = SKShader.CreateColor(skColor, skColorSpace);
if (skColorShader is { })
{
Expand Down Expand Up @@ -852,6 +868,14 @@ internal static bool SetColorOrShader(SvgVisualElement svgVisualElement, SvgPain
if (fallbackServer is SvgColourServer svgColourServerFallback)
{
var skColor = GetColor(svgColourServerFallback, opacity, ignoreAttributes);

if (skColorSpace == SKColorSpace.Srgb)
{
skPaint.Color = skColor;
skPaint.Shader = null;
return true;
}

var skColorShader = SKShader.CreateColor(skColor, skColorSpace);
if (skColorShader is { })
{
Expand Down Expand Up @@ -893,6 +917,14 @@ internal static bool SetColorOrShader(SvgVisualElement svgVisualElement, SvgPain
if (fallbackServer is SvgColourServer svgColourServerFallback)
{
var skColor = GetColor(svgColourServerFallback, opacity, ignoreAttributes);

if (skColorSpace == SKColorSpace.Srgb)
{
skPaint.Color = skColor;
skPaint.Shader = null;
return true;
}

var skColorShader = SKShader.CreateColor(skColor, skColorSpace);
if (skColorShader is { })
{
Expand Down
Loading