diff --git a/src/Greenshot.Base/Interfaces/Drawing/IDrawableContainer.cs b/src/Greenshot.Base/Interfaces/Drawing/IDrawableContainer.cs index 80e2bd140..0e887ff48 100644 --- a/src/Greenshot.Base/Interfaces/Drawing/IDrawableContainer.cs +++ b/src/Greenshot.Base/Interfaces/Drawing/IDrawableContainer.cs @@ -61,6 +61,8 @@ namespace Greenshot.Base.Interfaces.Drawing bool HasFilters { get; } + bool IsAreaHighlightContainer { get; } + EditStatus Status { get; set; } void Invalidate(); diff --git a/src/Greenshot.Editor/Drawing/DrawableContainer.cs b/src/Greenshot.Editor/Drawing/DrawableContainer.cs index cac23dc3a..04d79af04 100644 --- a/src/Greenshot.Editor/Drawing/DrawableContainer.cs +++ b/src/Greenshot.Editor/Drawing/DrawableContainer.cs @@ -57,6 +57,9 @@ namespace Greenshot.Editor.Drawing private const int M11 = 0; private const int M22 = 3; + public static bool IsBlurFilterApplied = false; + public static bool IsBrightnessFilterApplied = false; + [OnDeserialized] private void OnDeserializedInit(StreamingContext context) { @@ -396,9 +399,11 @@ namespace Greenshot.Editor.Drawing public bool HasFilters => Filters.Count > 0; + public bool IsAreaHighlightContainer => Filters.Any(f => f.Invert && (f is BrightnessFilter || f is BlurFilter || f is GrayscaleFilter)); + public abstract void Draw(Graphics graphics, RenderMode renderMode); - public virtual void DrawContent(Graphics graphics, Bitmap bmp, RenderMode renderMode, NativeRect clipRectangle) + public virtual void DrawContent(Graphics graphics, Bitmap bmp, RenderMode renderMode, NativeRect clipRectangle, IEnumerable areasToExcludeFromFilters) { if (Children.Count > 0) { @@ -414,7 +419,26 @@ namespace Greenshot.Editor.Drawing { if (filter.Invert) { - filter.Apply(graphics, bmp, Bounds, renderMode); + if (filter is BlurFilter) + { + if (!IsBlurFilterApplied) + { + filter.Apply(graphics, bmp, Bounds, renderMode, areasToExcludeFromFilters); + IsBlurFilterApplied = true; + } + } + else if (filter is BrightnessFilter) + { + if (!IsBrightnessFilterApplied) + { + filter.Apply(graphics, bmp, Bounds, renderMode, areasToExcludeFromFilters); + IsBrightnessFilterApplied = true; + } + } + else + { + filter.Apply(graphics, bmp, Bounds, renderMode, areasToExcludeFromFilters); + } } else { @@ -423,11 +447,11 @@ namespace Greenshot.Editor.Drawing { // quick&dirty bugfix, because MagnifierFilter behaves differently when drawn only partially // what we should actually do to resolve this is add a better magnifier which is not that special - filter.Apply(graphics, bmp, Bounds, renderMode); + filter.Apply(graphics, bmp, Bounds, renderMode, areasToExcludeFromFilters); } else { - filter.Apply(graphics, bmp, drawingRect, renderMode); + filter.Apply(graphics, bmp, drawingRect, renderMode, areasToExcludeFromFilters); } } } diff --git a/src/Greenshot.Editor/Drawing/DrawableContainerList.cs b/src/Greenshot.Editor/Drawing/DrawableContainerList.cs index ef30c037f..a9050f80e 100644 --- a/src/Greenshot.Editor/Drawing/DrawableContainerList.cs +++ b/src/Greenshot.Editor/Drawing/DrawableContainerList.cs @@ -328,6 +328,9 @@ namespace Greenshot.Editor.Drawing return; } + DrawableContainer.IsBlurFilterApplied = false; + DrawableContainer.IsBrightnessFilterApplied = false; + foreach (var drawableContainer in this) { var dc = (DrawableContainer) drawableContainer; @@ -338,7 +341,8 @@ namespace Greenshot.Editor.Drawing if (dc.DrawingBounds.IntersectsWith(clipRectangle)) { - dc.DrawContent(g, bitmap, renderMode, clipRectangle); + IEnumerable areaHighlightContainers = this.Where(c => c.IsAreaHighlightContainer).Select(c => c.Bounds); + dc.DrawContent(g, bitmap, renderMode, clipRectangle, areaHighlightContainers); } } } diff --git a/src/Greenshot.Editor/Drawing/Filters/AbstractFilter.cs b/src/Greenshot.Editor/Drawing/Filters/AbstractFilter.cs index c972ed77d..abd59a4bf 100644 --- a/src/Greenshot.Editor/Drawing/Filters/AbstractFilter.cs +++ b/src/Greenshot.Editor/Drawing/Filters/AbstractFilter.cs @@ -20,6 +20,7 @@ */ using System; +using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using Dapplo.Windows.Common.Structs; @@ -74,7 +75,7 @@ namespace Greenshot.Editor.Drawing.Filters return parent; } - public abstract void Apply(Graphics graphics, Bitmap applyBitmap, NativeRect rect, RenderMode renderMode); + public abstract void Apply(Graphics graphics, Bitmap applyBitmap, NativeRect rect, RenderMode renderMode, IEnumerable areasToExcludeFromFilters = null); protected void OnPropertyChanged(string propertyName) { diff --git a/src/Greenshot.Editor/Drawing/Filters/BlurFilter.cs b/src/Greenshot.Editor/Drawing/Filters/BlurFilter.cs index 010cfd2cb..74c745dd8 100644 --- a/src/Greenshot.Editor/Drawing/Filters/BlurFilter.cs +++ b/src/Greenshot.Editor/Drawing/Filters/BlurFilter.cs @@ -20,6 +20,7 @@ */ using System; +using System.Collections.Generic; using System.Drawing; using System.Drawing.Drawing2D; using Dapplo.Windows.Common.Structs; @@ -51,7 +52,7 @@ namespace Greenshot.Editor.Drawing.Filters AddField(GetType(), FieldType.PREVIEW_QUALITY, 1.0d); } - public override void Apply(Graphics graphics, Bitmap applyBitmap, NativeRect rect, RenderMode renderMode) + public override void Apply(Graphics graphics, Bitmap applyBitmap, NativeRect rect, RenderMode renderMode, IEnumerable areasToExcludeFromFilters = null) { int blurRadius = GetFieldValueAsInt(FieldType.BLUR_RADIUS); var applyRect = ImageHelper.CreateIntersectRectangle(applyBitmap.Size, rect, Invert); @@ -65,6 +66,10 @@ namespace Greenshot.Editor.Drawing.Filters { graphics.SetClip(applyRect); graphics.ExcludeClip(rect); + foreach (NativeRect area in areasToExcludeFromFilters) + { + graphics.ExcludeClip(area); + } } if (GdiPlusApi.IsBlurPossible(blurRadius)) diff --git a/src/Greenshot.Editor/Drawing/Filters/BrightnessFilter.cs b/src/Greenshot.Editor/Drawing/Filters/BrightnessFilter.cs index 639b0e5ac..e0f97735d 100644 --- a/src/Greenshot.Editor/Drawing/Filters/BrightnessFilter.cs +++ b/src/Greenshot.Editor/Drawing/Filters/BrightnessFilter.cs @@ -20,6 +20,7 @@ */ using System; +using System.Collections.Generic; using System.Drawing; using System.Drawing.Drawing2D; using System.Drawing.Imaging; @@ -45,7 +46,7 @@ namespace Greenshot.Editor.Drawing.Filters /// /// NativeRect /// - public override void Apply(Graphics graphics, Bitmap applyBitmap, NativeRect rect, RenderMode renderMode) + public override void Apply(Graphics graphics, Bitmap applyBitmap, NativeRect rect, RenderMode renderMode, IEnumerable areasToExcludeFromFilters = null) { var applyRect = ImageHelper.CreateIntersectRectangle(applyBitmap.Size, rect, Invert); @@ -60,6 +61,10 @@ namespace Greenshot.Editor.Drawing.Filters { graphics.SetClip(applyRect); graphics.ExcludeClip(rect); + foreach (NativeRect area in areasToExcludeFromFilters) + { + graphics.ExcludeClip(area); + } } float brightness = GetFieldValueAsFloat(FieldType.BRIGHTNESS); diff --git a/src/Greenshot.Editor/Drawing/Filters/GrayscaleFilter.cs b/src/Greenshot.Editor/Drawing/Filters/GrayscaleFilter.cs index 441102980..0eeaa76bd 100644 --- a/src/Greenshot.Editor/Drawing/Filters/GrayscaleFilter.cs +++ b/src/Greenshot.Editor/Drawing/Filters/GrayscaleFilter.cs @@ -20,6 +20,7 @@ */ using System; +using System.Collections.Generic; using System.Drawing; using System.Drawing.Drawing2D; using System.Drawing.Imaging; @@ -39,7 +40,7 @@ namespace Greenshot.Editor.Drawing.Filters { } - public override void Apply(Graphics graphics, Bitmap applyBitmap, NativeRect rect, RenderMode renderMode) + public override void Apply(Graphics graphics, Bitmap applyBitmap, NativeRect rect, RenderMode renderMode, IEnumerable areasToExcludeFromFilters = null) { var applyRect = ImageHelper.CreateIntersectRectangle(applyBitmap.Size, rect, Invert); @@ -54,6 +55,10 @@ namespace Greenshot.Editor.Drawing.Filters { graphics.SetClip(applyRect); graphics.ExcludeClip(rect); + foreach (NativeRect area in areasToExcludeFromFilters) + { + graphics.ExcludeClip(area); + } } ColorMatrix grayscaleMatrix = new ColorMatrix(new[] diff --git a/src/Greenshot.Editor/Drawing/Filters/HighlightFilter.cs b/src/Greenshot.Editor/Drawing/Filters/HighlightFilter.cs index 24624d193..b3965a84e 100644 --- a/src/Greenshot.Editor/Drawing/Filters/HighlightFilter.cs +++ b/src/Greenshot.Editor/Drawing/Filters/HighlightFilter.cs @@ -20,6 +20,7 @@ */ using System; +using System.Collections.Generic; using System.Drawing; using System.Drawing.Drawing2D; using Dapplo.Windows.Common.Structs; @@ -47,7 +48,7 @@ namespace Greenshot.Editor.Drawing.Filters /// /// NativeRect /// - public override void Apply(Graphics graphics, Bitmap applyBitmap, NativeRect rect, RenderMode renderMode) + public override void Apply(Graphics graphics, Bitmap applyBitmap, NativeRect rect, RenderMode renderMode, IEnumerable areasToExcludeFromFilters = null) { var applyRect = ImageHelper.CreateIntersectRectangle(applyBitmap.Size, rect, Invert); diff --git a/src/Greenshot.Editor/Drawing/Filters/IFilter.cs b/src/Greenshot.Editor/Drawing/Filters/IFilter.cs index 8c6d3d21d..2c214bacf 100644 --- a/src/Greenshot.Editor/Drawing/Filters/IFilter.cs +++ b/src/Greenshot.Editor/Drawing/Filters/IFilter.cs @@ -19,6 +19,7 @@ * along with this program. If not, see . */ +using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using Dapplo.Windows.Common.Structs; @@ -29,7 +30,7 @@ namespace Greenshot.Editor.Drawing.Filters public interface IFilter : INotifyPropertyChanged, IFieldHolder { DrawableContainer Parent { get; set; } - void Apply(Graphics graphics, Bitmap bmp, NativeRect rect, RenderMode renderMode); + void Apply(Graphics graphics, Bitmap bmp, NativeRect rect, RenderMode renderMode, IEnumerable areasToExcludeFromFilters = null); DrawableContainer GetParent(); bool Invert { get; set; } } diff --git a/src/Greenshot.Editor/Drawing/Filters/MagnifierFilter.cs b/src/Greenshot.Editor/Drawing/Filters/MagnifierFilter.cs index 70d829a2e..47474a8e8 100644 --- a/src/Greenshot.Editor/Drawing/Filters/MagnifierFilter.cs +++ b/src/Greenshot.Editor/Drawing/Filters/MagnifierFilter.cs @@ -20,6 +20,7 @@ */ using System; +using System.Collections.Generic; using System.Drawing; using System.Drawing.Drawing2D; using Dapplo.Windows.Common.Structs; @@ -40,7 +41,7 @@ namespace Greenshot.Editor.Drawing.Filters AddField(GetType(), FieldType.MAGNIFICATION_FACTOR, 2); } - public override void Apply(Graphics graphics, Bitmap applyBitmap, NativeRect rect, RenderMode renderMode) + public override void Apply(Graphics graphics, Bitmap applyBitmap, NativeRect rect, RenderMode renderMode, IEnumerable areasToExcludeFromFilters = null) { var applyRect = ImageHelper.CreateIntersectRectangle(applyBitmap.Size, rect, Invert); diff --git a/src/Greenshot.Editor/Drawing/Filters/PixelizationFilter.cs b/src/Greenshot.Editor/Drawing/Filters/PixelizationFilter.cs index fa677b128..d7d4d87fc 100644 --- a/src/Greenshot.Editor/Drawing/Filters/PixelizationFilter.cs +++ b/src/Greenshot.Editor/Drawing/Filters/PixelizationFilter.cs @@ -41,7 +41,7 @@ namespace Greenshot.Editor.Drawing.Filters AddField(GetType(), FieldType.PIXEL_SIZE, 5); } - public override void Apply(Graphics graphics, Bitmap applyBitmap, NativeRect rect, RenderMode renderMode) + public override void Apply(Graphics graphics, Bitmap applyBitmap, NativeRect rect, RenderMode renderMode, IEnumerable areasToExcludeFromFilters = null) { int pixelSize = GetFieldValueAsInt(FieldType.PIXEL_SIZE); ImageHelper.CreateIntersectRectangle(applyBitmap.Size, rect, Invert);