Skip to content

Commit

Permalink
Update SKPaintUtil.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
wieslawsoltes committed Jan 18, 2020
1 parent edfc024 commit 39e7180
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/Svg.Skia/SKPaintUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ public static float[] CreateIdentityColorMatrixArray()

public static SKImageFilter? CreateColorMatrix(SvgVisualElement svgVisualElement, SKRect skBounds, SvgColourMatrix svgColourMatrix, SKImageFilter? input = null, SKImageFilter.CropRect? cropRect = null)
{
float[] matrix;
var skColorFilter = default(SKColorFilter);

switch (svgColourMatrix.Type)
{
Expand All @@ -644,7 +644,7 @@ public static float[] CreateIdentityColorMatrixArray()
var angle = (float)DegreeToRadian(value);
var a1 = Math.Cos(angle);
var a2 = Math.Sin(angle);
matrix = new float[]
float[] matrix = new float[]
{
(float)(0.213 + a1 * +0.787 + a2 * -0.213),
(float)(0.715 + a1 * -0.715 + a2 * -0.715),
Expand All @@ -657,34 +657,39 @@ public static float[] CreateIdentityColorMatrixArray()
(float)(0.072 + a1 * +0.928 + a2 * +0.072), 0, 0,
0, 0, 0, 1, 0
};
skColorFilter = SKColorFilter.CreateColorMatrix(matrix);
}
break;
case SvgColourMatrixType.LuminanceToAlpha:
{
matrix = new float[]
float[] matrix = new float[]
{
0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
0.2125f, 0.7154f, 0.0721f, 0, 0
};
skColorFilter = SKColorFilter.CreateColorMatrix(matrix);
//skColorFilter = SKColorFilter.CreateLumaColor();
}
break;
case SvgColourMatrixType.Saturate:
{
float value = (string.IsNullOrEmpty(svgColourMatrix.Values) ? 1 : float.Parse(svgColourMatrix.Values, NumberStyles.Any, CultureInfo.InvariantCulture));
matrix = new float[]
float[] matrix = new float[]
{
(float)(0.213+0.787*value), (float)(0.715-0.715*value), (float)(0.072-0.072*value), 0, 0,
(float)(0.213-0.213*value), (float)(0.715+0.285*value), (float)(0.072-0.072*value), 0, 0,
(float)(0.213-0.213*value), (float)(0.715-0.715*value), (float)(0.072+0.928*value), 0, 0,
0, 0, 0, 1, 0
};
skColorFilter = SKColorFilter.CreateColorMatrix(matrix);
};
break;
default:
case SvgColourMatrixType.Matrix:
{
float[] matrix;
if (string.IsNullOrEmpty(svgColourMatrix.Values))
{
matrix = CreateIdentityColorMatrixArray();
Expand All @@ -705,12 +710,11 @@ public static float[] CreateIdentityColorMatrixArray()
matrix = CreateIdentityColorMatrixArray();
}
}
skColorFilter = SKColorFilter.CreateColorMatrix(matrix);
}
break;
}

var skColorFilter = SKColorFilter.CreateColorMatrix(matrix);

return SKImageFilter.CreateColorFilter(skColorFilter, input, cropRect);
}

Expand Down

0 comments on commit 39e7180

Please sign in to comment.