From 1f44d213a63e2dd648ad5f6bdafe6b53638f5d69 Mon Sep 17 00:00:00 2001 From: Jaex Date: Mon, 28 Nov 2016 16:24:27 +0300 Subject: [PATCH] Pre calculate pixelate pixel count to increase performance --- ShareX.HelpersLib/Helpers/ImageHelpers.cs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/ShareX.HelpersLib/Helpers/ImageHelpers.cs b/ShareX.HelpersLib/Helpers/ImageHelpers.cs index ba99a073b..ff313b305 100644 --- a/ShareX.HelpersLib/Helpers/ImageHelpers.cs +++ b/ShareX.HelpersLib/Helpers/ImageHelpers.cs @@ -992,10 +992,10 @@ public static void Pixelate(Bitmap bmp, int pixelSize) { for (int x = 0; x < unsafeBitmap.Width; x += pixelSize) { - int r = 0, g = 0, b = 0, a = 0, count = 0; - - int yLimit = Math.Min(y + pixelSize, unsafeBitmap.Height); int xLimit = Math.Min(x + pixelSize, unsafeBitmap.Width); + int yLimit = Math.Min(y + pixelSize, unsafeBitmap.Height); + int pixelCount = (xLimit - x) * (yLimit - y); + int r = 0, g = 0, b = 0, a = 0; for (int y2 = y; y2 < yLimit; y2++) { @@ -1007,11 +1007,10 @@ public static void Pixelate(Bitmap bmp, int pixelSize) g += color.Green; b += color.Blue; a += color.Alpha; - count++; } } - ColorBgra averageColor = new ColorBgra((byte)(b / count), (byte)(g / count), (byte)(r / count), (byte)(a / count)); + ColorBgra averageColor = new ColorBgra((byte)(b / pixelCount), (byte)(g / pixelCount), (byte)(r / pixelCount), (byte)(a / pixelCount)); for (int y2 = y; y2 < yLimit; y2++) {