From 8b5578ea2c9ea032749958795a3c85c2e81bbcc6 Mon Sep 17 00:00:00 2001 From: RKrom Date: Fri, 1 Mar 2013 09:19:01 +0000 Subject: [PATCH] Fixed compilation issues on new code which isn't checked in by refactoring the ApplyBlur method. This was needed anyway, as it doesn't return a new bitmap! git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2513 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4 --- GreenshotPlugin/Core/ImageHelper.cs | 52 ++++++++++++++++------------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/GreenshotPlugin/Core/ImageHelper.cs b/GreenshotPlugin/Core/ImageHelper.cs index 07c11452e..a1507af62 100644 --- a/GreenshotPlugin/Core/ImageHelper.cs +++ b/GreenshotPlugin/Core/ImageHelper.cs @@ -653,35 +653,41 @@ namespace GreenshotPlugin.Core { } /// - /// Create a new Bitmap with the BoxBlur result of the sourceBitmap + /// Apply BoxBlur to the destinationBitmap /// - /// Bitmap to blur + /// Bitmap to blur /// Must be ODD! - /// Bitmap - public static Bitmap ApplyBoxBlur(Bitmap destinationBitmap, int range) { + public static void ApplyBoxBlur(Bitmap destinationBitmap, int range) { + // We only need one fastbitmap as we use it as source and target (the reading is done for one line H/V, writing after "parsing" one line H/V) + using (IFastBitmap fastBitmap = FastBitmap.Create(destinationBitmap)) { + ApplyBoxBlur(fastBitmap, range); + } + } + + /// + /// Apply BoxBlur to the fastBitmap + /// + /// IFastBitmap to blur + /// Must be ODD! + public static void ApplyBoxBlur(IFastBitmap fastBitmap, int range) { // Range must be odd! if ((range & 1) == 0) { range++; } - // We only need one fastbitmap as we use it as source and target (the reading is done for one line H/V, writing after "parsing" one line H/V) - using (IFastBitmap fastBitmap = FastBitmap.Create(destinationBitmap)) { - // Box blurs are frequently used to approximate a Gaussian blur. - // By the central limit theorem, if applied 3 times on the same image, a box blur approximates the Gaussian kernel to within about 3%, yielding the same result as a quadratic convolution kernel. - // This might be true, but the GDI+ BlurEffect doesn't look the same, a 2x blur is more simular and we only make 2x Box-Blur. - // (Might also be a mistake in our blur, but for now it looks great) - if (fastBitmap.hasAlphaChannel) { - BoxBlurHorizontalAlpha(fastBitmap, range); - BoxBlurVerticalAlpha(fastBitmap, range); - BoxBlurHorizontalAlpha(fastBitmap, range); - BoxBlurVerticalAlpha(fastBitmap, range); - } else { - BoxBlurHorizontal(fastBitmap, range); - BoxBlurVertical(fastBitmap, range); - BoxBlurHorizontal(fastBitmap, range); - BoxBlurVertical(fastBitmap, range); - } - - return fastBitmap.UnlockAndReturnBitmap(); + // Box blurs are frequently used to approximate a Gaussian blur. + // By the central limit theorem, if applied 3 times on the same image, a box blur approximates the Gaussian kernel to within about 3%, yielding the same result as a quadratic convolution kernel. + // This might be true, but the GDI+ BlurEffect doesn't look the same, a 2x blur is more simular and we only make 2x Box-Blur. + // (Might also be a mistake in our blur, but for now it looks great) + if (fastBitmap.hasAlphaChannel) { + BoxBlurHorizontalAlpha(fastBitmap, range); + BoxBlurVerticalAlpha(fastBitmap, range); + BoxBlurHorizontalAlpha(fastBitmap, range); + BoxBlurVerticalAlpha(fastBitmap, range); + } else { + BoxBlurHorizontal(fastBitmap, range); + BoxBlurVertical(fastBitmap, range); + BoxBlurHorizontal(fastBitmap, range); + BoxBlurVertical(fastBitmap, range); } }