Skip to content

Commit

Permalink
Merge pull request #197 from wieslawsoltes/UseColorForSrgbColorSpace
Browse files Browse the repository at this point in the history
Use Color for Srgb color space
  • Loading branch information
wieslawsoltes authored Jan 6, 2024
2 parents 3a6ee74 + b4baafd commit 4f496f5
Showing 1 changed file with 32 additions and 0 deletions.
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

0 comments on commit 4f496f5

Please sign in to comment.