From d63d08a9ac08fa590db9edbabb561c1f6511af9b Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Sun, 23 Sep 2018 01:56:05 +0200 Subject: [PATCH] optimize ImageFrame.Clear() --- src/ImageSharp/ImageFrame{TPixel}.cs | 19 ++++++++++--------- .../Processors/Overlays/GlowProcessor.cs | 1 - 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/ImageSharp/ImageFrame{TPixel}.cs b/src/ImageSharp/ImageFrame{TPixel}.cs index 92470e254..be1792ced 100644 --- a/src/ImageSharp/ImageFrame{TPixel}.cs +++ b/src/ImageSharp/ImageFrame{TPixel}.cs @@ -318,15 +318,16 @@ namespace SixLabors.ImageSharp /// The value to initialize the bitmap with. internal void Clear(ParallelOptions parallelOptions, TPixel value) { - Parallel.For( - 0, - this.Height, - parallelOptions, - y => - { - Span targetRow = this.GetPixelRowSpan(y); - targetRow.Fill(value); - }); + Span span = this.GetPixelSpan(); + + if (value.Equals(default)) + { + span.Clear(); + } + else + { + span.Fill(value); + } } /// diff --git a/src/ImageSharp/Processing/Processors/Overlays/GlowProcessor.cs b/src/ImageSharp/Processing/Processors/Overlays/GlowProcessor.cs index d774a10ab..93d6edff1 100644 --- a/src/ImageSharp/Processing/Processors/Overlays/GlowProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Overlays/GlowProcessor.cs @@ -86,7 +86,6 @@ namespace SixLabors.ImageSharp.Processing.Processors.Overlays protected override void OnFrameApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) { // TODO: can we simplify the rectangle calculation? - int startY = sourceRectangle.Y; int endY = sourceRectangle.Bottom; int startX = sourceRectangle.X;