This commit is contained in:
Nathan_B 2025-08-19 14:04:22 +08:00 committed by GitHub
commit 3ddd60556c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 62 additions and 13 deletions

View file

@ -61,6 +61,8 @@ namespace Greenshot.Base.Interfaces.Drawing
bool HasFilters { get; }
bool IsAreaHighlightContainer { get; }
EditStatus Status { get; set; }
void Invalidate();

View file

@ -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<NativeRect> 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);
}
}
}

View file

@ -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<NativeRect> areaHighlightContainers = this.Where(c => c.IsAreaHighlightContainer).Select(c => c.Bounds);
dc.DrawContent(g, bitmap, renderMode, clipRectangle, areaHighlightContainers);
}
}
}

View file

@ -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<NativeRect> areasToExcludeFromFilters = null);
protected void OnPropertyChanged(string propertyName)
{

View file

@ -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<NativeRect> 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))

View file

@ -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
/// <param name="applyBitmap"></param>
/// <param name="rect">NativeRect</param>
/// <param name="renderMode"></param>
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<NativeRect> 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);

View file

@ -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<NativeRect> 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[]

View file

@ -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
/// <param name="applyBitmap"></param>
/// <param name="rect">NativeRect</param>
/// <param name="renderMode"></param>
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<NativeRect> areasToExcludeFromFilters = null)
{
var applyRect = ImageHelper.CreateIntersectRectangle(applyBitmap.Size, rect, Invert);

View file

@ -19,6 +19,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
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<NativeRect> areasToExcludeFromFilters = null);
DrawableContainer GetParent();
bool Invert { get; set; }
}

View file

@ -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<NativeRect> areasToExcludeFromFilters = null)
{
var applyRect = ImageHelper.CreateIntersectRectangle(applyBitmap.Size, rect, Invert);

View file

@ -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<NativeRect> areasToExcludeFromFilters = null)
{
int pixelSize = GetFieldValueAsInt(FieldType.PIXEL_SIZE);
ImageHelper.CreateIntersectRectangle(applyBitmap.Size, rect, Invert);