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
This commit is contained in:
RKrom 2013-03-01 09:19:01 +00:00
commit 8b5578ea2c

View file

@ -653,35 +653,41 @@ namespace GreenshotPlugin.Core {
} }
/// <summary> /// <summary>
/// Create a new Bitmap with the BoxBlur result of the sourceBitmap /// Apply BoxBlur to the destinationBitmap
/// </summary> /// </summary>
/// <param name="sourceBitmap">Bitmap to blur</param> /// <param name="destinationBitmap">Bitmap to blur</param>
/// <param name="range">Must be ODD!</param> /// <param name="range">Must be ODD!</param>
/// <returns>Bitmap</returns> public static void ApplyBoxBlur(Bitmap destinationBitmap, int range) {
public static Bitmap 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);
}
}
/// <summary>
/// Apply BoxBlur to the fastBitmap
/// </summary>
/// <param name="fastBitmap">IFastBitmap to blur</param>
/// <param name="range">Must be ODD!</param>
public static void ApplyBoxBlur(IFastBitmap fastBitmap, int range) {
// Range must be odd! // Range must be odd!
if ((range & 1) == 0) { if ((range & 1) == 0) {
range++; 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) // Box blurs are frequently used to approximate a Gaussian blur.
using (IFastBitmap fastBitmap = FastBitmap.Create(destinationBitmap)) { // 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.
// Box blurs are frequently used to approximate a Gaussian blur. // 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.
// 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. // (Might also be a mistake in our blur, but for now it looks great)
// 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. if (fastBitmap.hasAlphaChannel) {
// (Might also be a mistake in our blur, but for now it looks great) BoxBlurHorizontalAlpha(fastBitmap, range);
if (fastBitmap.hasAlphaChannel) { BoxBlurVerticalAlpha(fastBitmap, range);
BoxBlurHorizontalAlpha(fastBitmap, range); BoxBlurHorizontalAlpha(fastBitmap, range);
BoxBlurVerticalAlpha(fastBitmap, range); BoxBlurVerticalAlpha(fastBitmap, range);
BoxBlurHorizontalAlpha(fastBitmap, range); } else {
BoxBlurVerticalAlpha(fastBitmap, range); BoxBlurHorizontal(fastBitmap, range);
} else { BoxBlurVertical(fastBitmap, range);
BoxBlurHorizontal(fastBitmap, range); BoxBlurHorizontal(fastBitmap, range);
BoxBlurVertical(fastBitmap, range); BoxBlurVertical(fastBitmap, range);
BoxBlurHorizontal(fastBitmap, range);
BoxBlurVertical(fastBitmap, range);
}
return fastBitmap.UnlockAndReturnBitmap();
} }
} }