diff --git a/Pinta.Core/Effects/ColorBgra.cs b/Pinta.Core/Effects/ColorBgra.cs index 3f8c9dd64..1ca6fa585 100644 --- a/Pinta.Core/Effects/ColorBgra.cs +++ b/Pinta.Core/Effects/ColorBgra.cs @@ -322,14 +322,12 @@ public static double Lerp (double from, double to, double frac) /// public static ColorBgra Lerp (ColorBgra from, ColorBgra to, double frac) { - ColorBgra ret = new ColorBgra { - B = Utility.ClampToByte (Lerp (from.B, to.B, frac)), - G = Utility.ClampToByte (Lerp (from.G, to.G, frac)), - R = Utility.ClampToByte (Lerp (from.R, to.R, frac)), - A = Utility.ClampToByte (Lerp (from.A, to.A, frac)) - }; - - return ret; + return FromBgra ( + b: Utility.ClampToByte (Lerp (from.B, to.B, frac)), + g: Utility.ClampToByte (Lerp (from.G, to.G, frac)), + r: Utility.ClampToByte (Lerp (from.R, to.R, frac)), + a: Utility.ClampToByte (Lerp (from.A, to.A, frac)) + ); } /// diff --git a/Pinta.Core/Effects/GradientRenderer.cs b/Pinta.Core/Effects/GradientRenderer.cs index b8fe67923..38923db7a 100644 --- a/Pinta.Core/Effects/GradientRenderer.cs +++ b/Pinta.Core/Effects/GradientRenderer.cs @@ -145,8 +145,8 @@ public void Render (ImageSurface surface, ReadOnlySpan rois) for (int y = rect.Top; y <= rect.Bottom; ++y) { var row = src_data.Slice (y * src_width, src_width); for (int x = rect.Left; x <= rect.Right; ++x) { - ref ColorBgra pixel = ref row[x]; - pixel = GetFinalSolidColor (bounds, pixel); + ColorBgra originalPixel = row[x]; + row[x] = GetFinalSolidColor (bounds, originalPixel); } } } @@ -184,31 +184,30 @@ private bool ProcessGradientLine (byte startAlpha, byte endAlpha, int y, Rectang for (var x = rect.Left; x <= right; ++x) { var lerpByte = ComputeByteLerp (x, y); var lerpAlpha = lerp_alphas[lerpByte]; - ref ColorBgra pixel = ref row[x]; - pixel = ColorBgra.FromBgra ( - b: Utility.FastScaleByteByByte (pixel.B, lerpAlpha), - g: Utility.FastScaleByteByByte (pixel.G, lerpAlpha), - r: Utility.FastScaleByteByByte (pixel.R, lerpAlpha), - a: Utility.FastScaleByteByByte (pixel.A, lerpAlpha) + ColorBgra originalPixel = row[x]; + row[x] = ColorBgra.FromBgra ( + b: Utility.FastScaleByteByByte (originalPixel.B, lerpAlpha), + g: Utility.FastScaleByteByByte (originalPixel.G, lerpAlpha), + r: Utility.FastScaleByteByByte (originalPixel.R, lerpAlpha), + a: Utility.FastScaleByteByByte (originalPixel.A, lerpAlpha) ); } } else if (alpha_only && !alpha_blending) { for (var x = rect.Left; x <= right; ++x) { var lerpByte = ComputeByteLerp (x, y); var lerpAlpha = lerp_alphas[lerpByte]; - ref ColorBgra pixel = ref row[x]; - - var color = pixel.ToStraightAlpha (); + ColorBgra original = row[x]; + var color = original.ToStraightAlpha (); color.A = lerpAlpha; - pixel = color.ToPremultipliedAlpha (); + row[x] = color.ToPremultipliedAlpha (); } } else if (!alpha_only && (alpha_blending && (startAlpha != 255 || endAlpha != 255))) { // If we're doing all color channels, and we're doing alpha blending, and if alpha blending is necessary for (var x = rect.Left; x <= right; ++x) { var lerpByte = ComputeByteLerp (x, y); var lerpColor = lerp_colors[lerpByte]; - ref ColorBgra pixel = ref row[x]; - pixel = normal_blend_op.Apply (pixel, lerpColor); + ColorBgra originalPixel = row[x]; + row[x] = normal_blend_op.Apply (originalPixel, lerpColor); } //if (!this.alphaOnly && !this.alphaBlending) // or sC.A == 255 && eC.A == 255 } else { diff --git a/Pinta.Core/Effects/UnaryPixelOps.cs b/Pinta.Core/Effects/UnaryPixelOps.cs index 474cc8eda..8d58c81a3 100644 --- a/Pinta.Core/Effects/UnaryPixelOps.cs +++ b/Pinta.Core/Effects/UnaryPixelOps.cs @@ -311,21 +311,22 @@ public override ColorBgra Apply (in ColorBgra color) public override void Apply (Span dst, ReadOnlySpan src) { for (int i = 0; i < src.Length; ++i) { - ref ColorBgra result = ref dst[i]; byte val = src[i].GetIntensityByte (); dst[i] = ColorBgra.FromBgra (val, val, val, src[i].A); - result.R = result.G = result.B = val; - result.A = src[i].A; } } public override void Apply (Span dst) { for (int i = 0; i < dst.Length; ++i) { - ref ColorBgra result = ref dst[i]; - byte val = result.GetIntensityByte (); - result.R = result.G = result.B = val; - + ColorBgra original = dst[i]; + byte val = original.GetIntensityByte (); + dst[i] = ColorBgra.FromBgra ( + b: val, + g: val, + r: val, + a: original.A + ); } } } @@ -381,9 +382,8 @@ public ChannelCurve () public override void Apply (Span dst, ReadOnlySpan src) { for (int i = 0; i < src.Length; ++i) { - ref ColorBgra d = ref dst[i]; ColorBgra s = src[i]; - d = ColorBgra.FromBgra ( + dst[i] = ColorBgra.FromBgra ( b: CurveB[s.B], g: CurveG[s.G], r: CurveR[s.R], @@ -395,11 +395,13 @@ public override void Apply (Span dst, ReadOnlySpan src) public override void Apply (Span dst) { for (int i = 0; i < dst.Length; ++i) { - ref ColorBgra d = ref dst[i]; - d.B = CurveB[d.B]; - d.G = CurveG[d.G]; - d.R = CurveR[d.R]; - + ColorBgra original = dst[i]; + dst[i] = ColorBgra.FromBgra ( + b: CurveB[original.B], + g: CurveG[original.G], + r: CurveR[original.R], + a: original.A + ); } } @@ -794,23 +796,27 @@ public override ColorBgra Apply (in ColorBgra color) public override void Apply (Span dst, ReadOnlySpan src) { for (int i = 0; i < src.Length; ++i) { - ref ColorBgra d = ref dst[i]; - ColorBgra s = src[i]; - d.B = blue_levels[s.B]; - d.G = green_levels[s.G]; - d.R = red_levels[s.R]; - d.A = s.A; + ColorBgra source = src[i]; + dst[i] = ColorBgra.FromBgra ( + b: blue_levels[source.B], + g: green_levels[source.G], + r: red_levels[source.R], + a: source.A + ); + } } public override void Apply (Span dst) { for (int i = 0; i < dst.Length; ++i) { - ref ColorBgra d = ref dst[i]; - d.B = blue_levels[d.B]; - d.G = green_levels[d.G]; - d.R = red_levels[d.R]; - + ColorBgra original = dst[i]; + dst[i] = ColorBgra.FromBgra ( + b: blue_levels[original.B], + g: green_levels[original.G], + r: red_levels[original.R], + a: original.A + ); } } } diff --git a/Pinta.Core/Extensions/CairoExtensions.cs b/Pinta.Core/Extensions/CairoExtensions.cs index 38a14dbea..7c5951e37 100644 --- a/Pinta.Core/Extensions/CairoExtensions.cs +++ b/Pinta.Core/Extensions/CairoExtensions.cs @@ -390,14 +390,12 @@ public static GdkPixbuf.Pixbuf ToPixbuf (this Cairo.ImageSurface surfSource) public static ColorBgra ToColorBgra (this Cairo.Color color) { - ColorBgra c = new ColorBgra { - R = (byte) (color.R * 255), - G = (byte) (color.G * 255), - B = (byte) (color.B * 255), - A = (byte) (color.A * 255) - }; - - return c; + return ColorBgra.FromBgra ( + b: (byte) (color.B * 255), + g: (byte) (color.G * 255), + r: (byte) (color.R * 255), + a: (byte) (color.A * 255) + ); } public static Cairo.Color ToCairoColor (this ColorBgra color) diff --git a/Pinta.Effects/Effects/AddNoiseEffect.cs b/Pinta.Effects/Effects/AddNoiseEffect.cs index cb7b2570e..eff0a9774 100644 --- a/Pinta.Effects/Effects/AddNoiseEffect.cs +++ b/Pinta.Effects/Effects/AddNoiseEffect.cs @@ -146,12 +146,13 @@ public override void Render (ImageSurface src, ImageSurface dst, ReadOnlySpan> 12); ColorBgra src_pixel = src_row[x]; - ref ColorBgra dst_pixel = ref dst_row[x]; - dst_pixel.R = Utility.ClampToByte (src_pixel.R + ((r * dev + 32768) >> 16)); - dst_pixel.G = Utility.ClampToByte (src_pixel.G + ((g * dev + 32768) >> 16)); - dst_pixel.B = Utility.ClampToByte (src_pixel.B + ((b * dev + 32768) >> 16)); - dst_pixel.A = src_pixel.A; + dst_row[x] = ColorBgra.FromBgra ( + b: Utility.ClampToByte (src_pixel.B + ((b * dev + 32768) >> 16)), + g: Utility.ClampToByte (src_pixel.G + ((g * dev + 32768) >> 16)), + r: Utility.ClampToByte (src_pixel.R + ((r * dev + 32768) >> 16)), + a: src_pixel.A + ); } } } diff --git a/Pinta.Effects/Effects/InkSketchEffect.cs b/Pinta.Effects/Effects/InkSketchEffect.cs index 405476fe7..1a462a509 100644 --- a/Pinta.Effects/Effects/InkSketchEffect.cs +++ b/Pinta.Effects/Effects/InkSketchEffect.cs @@ -142,8 +142,8 @@ public override void Render (ImageSurface src, ImageSurface dest, ReadOnlySpan 0) { - dst_pixel = ColorBgra.FromBgra ( + dst_row[x] = ColorBgra.FromBgra ( Utility.ClampToByte (sb / sa), Utility.ClampToByte (sg / sa), Utility.ClampToByte (sr / sa), Utility.ClampToByte (sa / sc)); } else { - dst_pixel.Bgra = 0; + dst_row[x].Bgra = 0; } } } diff --git a/Pinta.Effects/Effects/ZoomBlurEffect.cs b/Pinta.Effects/Effects/ZoomBlurEffect.cs index 82f9eb77a..6b626de70 100644 --- a/Pinta.Effects/Effects/ZoomBlurEffect.cs +++ b/Pinta.Effects/Effects/ZoomBlurEffect.cs @@ -102,16 +102,15 @@ public override void Render (ImageSurface src, ImageSurface dst, ReadOnlySpan