From fcf4b971014abddf939474ad13d629c1183e2a5d Mon Sep 17 00:00:00 2001 From: Nathan Brown Date: Mon, 31 Oct 2022 21:58:07 -0700 Subject: [PATCH 1/4] OfficeUtils fix (cherry picked from commit bfa75aea0208966f2a93a0e6ddb52270940417cd) (cherry picked from commit 275d7b4149818db1cda771dfd2641b250dbb5e66) (cherry picked from commit 0d81a3f26e908c3a65be77503b0e78c35048579d) --- src/Greenshot.Plugin.Office/OfficeUtils.cs | 60 +++++++++++----------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/src/Greenshot.Plugin.Office/OfficeUtils.cs b/src/Greenshot.Plugin.Office/OfficeUtils.cs index 52ca8d7cb..305611c5d 100644 --- a/src/Greenshot.Plugin.Office/OfficeUtils.cs +++ b/src/Greenshot.Plugin.Office/OfficeUtils.cs @@ -1,43 +1,45 @@ using System.Linq; using Microsoft.Win32; -namespace Greenshot.Plugin.Office; - -/// -/// A small utility class for helping with office -/// -internal static class OfficeUtils +namespace Greenshot.Plugin.Office { - private static readonly string[] OfficeRootKeys = { @"SOFTWARE\Microsoft\Office", @"SOFTWARE\WOW6432Node\Microsoft\Office" }; /// - /// Get the path to the office exe + /// A small utility class for helping with office /// - /// Name of the office executable - public static string GetOfficeExePath(string exeName) + internal static class OfficeUtils { - string strKeyName = exeName switch - { - "WINWORD.EXE" => "Word", - "EXCEL.EXE" => "Excel", - "POWERPNT.EXE" => "PowerPoint", - "OUTLOOK.EXE" => "Outlook", - "ONENOTE.EXE" => "OneNote", - _ => "" - }; + private static readonly string[] OfficeRootKeys = { @"SOFTWARE\Microsoft\Office", @"SOFTWARE\WOW6432Node\Microsoft\Office" }; - foreach (string strRootKey in OfficeRootKeys) + /// + /// Get the path to the office exe + /// + /// Name of the office executable + public static string GetOfficeExePath(string exeName) { - using RegistryKey rootKey = Registry.LocalMachine.OpenSubKey(strRootKey); - if (rootKey is null) continue; - - foreach (string officeVersion in rootKey.GetSubKeyNames().Where(r => r.Contains(".")).Reverse()) + string strKeyName = exeName switch { - using RegistryKey installRootKey = Registry.LocalMachine.OpenSubKey($@"{strRootKey}\{officeVersion}\{strKeyName}\InstallRoot"); - if (installRootKey == null) continue; - return $@"{installRootKey.GetValue("Path")}\{exeName}"; + "WINWORD.EXE" => "Word", + "EXCEL.EXE" => "Excel", + "POWERPNT.EXE" => "PowerPoint", + "OUTLOOK.EXE" => "Outlook", + "ONENOTE.EXE" => "OneNote", + _ => "" + }; + + foreach (string strRootKey in OfficeRootKeys) + { + using RegistryKey rootKey = Registry.LocalMachine.OpenSubKey(strRootKey); + if (rootKey is null) continue; + + foreach (string officeVersion in rootKey.GetSubKeyNames().Where(r => r.Contains(".")).Reverse()) + { + using RegistryKey installRootKey = Registry.LocalMachine.OpenSubKey($@"{strRootKey}\{officeVersion}\{strKeyName}\InstallRoot"); + if (installRootKey == null) continue; + return $@"{installRootKey.GetValue("Path")}\{exeName}"; + } } + return null; } - return null; } -} +} \ No newline at end of file From f34aa8d9f227837ac237ff80d258172e5034827f Mon Sep 17 00:00:00 2001 From: Nathan Brown Date: Sun, 20 Aug 2023 17:00:00 -0700 Subject: [PATCH 2/4] Prevent overlapping Area Highlight filters --- .../Interfaces/Drawing/IDrawableContainer.cs | 2 ++ src/Greenshot.Editor/Drawing/DrawableContainer.cs | 10 ++++++---- src/Greenshot.Editor/Drawing/DrawableContainerList.cs | 3 ++- src/Greenshot.Editor/Drawing/Filters/AbstractFilter.cs | 3 ++- src/Greenshot.Editor/Drawing/Filters/BlurFilter.cs | 7 ++++++- .../Drawing/Filters/BrightnessFilter.cs | 7 ++++++- .../Drawing/Filters/GrayscaleFilter.cs | 3 ++- .../Drawing/Filters/HighlightFilter.cs | 3 ++- src/Greenshot.Editor/Drawing/Filters/IFilter.cs | 3 ++- .../Drawing/Filters/MagnifierFilter.cs | 3 ++- .../Drawing/Filters/PixelizationFilter.cs | 2 +- 11 files changed, 33 insertions(+), 13 deletions(-) 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..9776d995d 100644 --- a/src/Greenshot.Editor/Drawing/DrawableContainer.cs +++ b/src/Greenshot.Editor/Drawing/DrawableContainer.cs @@ -396,9 +396,11 @@ namespace Greenshot.Editor.Drawing public bool HasFilters => Filters.Count > 0; + public bool IsAreaHighlightContainer => Filters.Any(f => f is BrightnessFilter) && Filters.Any(f => f is BlurFilter); + 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 +416,7 @@ namespace Greenshot.Editor.Drawing { if (filter.Invert) { - filter.Apply(graphics, bmp, Bounds, renderMode); + filter.Apply(graphics, bmp, Bounds, renderMode, areasToExcludeFromFilters); } else { @@ -423,11 +425,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..c4cbbc17b 100644 --- a/src/Greenshot.Editor/Drawing/DrawableContainerList.cs +++ b/src/Greenshot.Editor/Drawing/DrawableContainerList.cs @@ -338,7 +338,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..b382bd1d5 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); 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); From dd0cdf4724f4d67bbe88b7aa81e60bf2476d8851 Mon Sep 17 00:00:00 2001 From: nathbrow Date: Thu, 17 Jul 2025 14:45:22 -0700 Subject: [PATCH 3/4] Apply exclusion to grayscale filters as well (cherry picked from commit e0b04a11f02e6188e364ea26de96944d9927291a) --- src/Greenshot.Editor/Drawing/DrawableContainer.cs | 2 +- src/Greenshot.Editor/Drawing/Filters/GrayscaleFilter.cs | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Greenshot.Editor/Drawing/DrawableContainer.cs b/src/Greenshot.Editor/Drawing/DrawableContainer.cs index 9776d995d..08371753b 100644 --- a/src/Greenshot.Editor/Drawing/DrawableContainer.cs +++ b/src/Greenshot.Editor/Drawing/DrawableContainer.cs @@ -396,7 +396,7 @@ namespace Greenshot.Editor.Drawing public bool HasFilters => Filters.Count > 0; - public bool IsAreaHighlightContainer => Filters.Any(f => f is BrightnessFilter) && Filters.Any(f => f is BlurFilter); + 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); diff --git a/src/Greenshot.Editor/Drawing/Filters/GrayscaleFilter.cs b/src/Greenshot.Editor/Drawing/Filters/GrayscaleFilter.cs index b382bd1d5..0eeaa76bd 100644 --- a/src/Greenshot.Editor/Drawing/Filters/GrayscaleFilter.cs +++ b/src/Greenshot.Editor/Drawing/Filters/GrayscaleFilter.cs @@ -55,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[] From d0bbb6d059d8a63af6be7e41b17442a78279f16e Mon Sep 17 00:00:00 2001 From: nathbrow Date: Thu, 17 Jul 2025 13:37:32 -0700 Subject: [PATCH 4/4] Only apply the first blur and brightness filters (cherry picked from commit 73ddbc8ac919b2400d446f0cf36191c9ecd55846) --- .../Drawing/DrawableContainer.cs | 24 ++++++++++++++++++- .../Drawing/DrawableContainerList.cs | 3 +++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/Greenshot.Editor/Drawing/DrawableContainer.cs b/src/Greenshot.Editor/Drawing/DrawableContainer.cs index 08371753b..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) { @@ -416,7 +419,26 @@ namespace Greenshot.Editor.Drawing { if (filter.Invert) { - filter.Apply(graphics, bmp, Bounds, renderMode, areasToExcludeFromFilters); + 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 { diff --git a/src/Greenshot.Editor/Drawing/DrawableContainerList.cs b/src/Greenshot.Editor/Drawing/DrawableContainerList.cs index c4cbbc17b..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;