diff --git a/NuGet.Config b/NuGet.Config index ec28e4393..cb86a24b5 100644 --- a/NuGet.Config +++ b/NuGet.Config @@ -10,5 +10,6 @@ + \ No newline at end of file diff --git a/build.cake b/build.cake index a2d6a4794..1068f4a23 100644 --- a/build.cake +++ b/build.cake @@ -176,17 +176,23 @@ Task("AssemblyVersion") Task("EnableDNC30") .Does(() => { - ReplaceRegexInFiles("./**/*.csproj", ".*", "net471;netcoreapp3.0"); + ReplaceRegexInFiles("./**/*.csproj", ".*", "net472;netcoreapp3.0"); ReplaceRegexInFiles("./**/*.csproj", "", ""); }); Task("DisableDNC30") .Does(() => { - ReplaceRegexInFiles("./**/*.csproj", "net471;netcoreapp3.0", "net471"); + ReplaceRegexInFiles("./**/*.csproj", "net472;netcoreapp3.0", "net472"); ReplaceRegexInFiles("./**/*.csproj", "", ""); }); +Task("ChangeNETVersion") + .Does(() => +{ + ReplaceRegexInFiles("./**/*.csproj", "net471", "net472"); +}); + // Clean all unneeded files, so we build on a clean file system Task("Clean") .Does(() => diff --git a/src/Directory.Build.props b/src/Directory.Build.props index a7ae9a39a..6e1abed21 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -8,12 +8,12 @@ https://github.com/greenshot/greenshot https://www.gnu.org/licenses/gpl.html latest - - true + + true 1.0.0 1.0.0 1.0.0 - {HintPathFromItem};{TargetFrameworkDirectory};{RawFileName};{GAC}; + {HintPathFromItem};{TargetFrameworkDirectory};{RawFileName};{GAC}; true false $(registry:HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion@ProductName) @@ -48,8 +48,8 @@ True - - + + diff --git a/src/Greenshot.Addon.Confluence/Greenshot.Addon.Confluence.csproj b/src/Greenshot.Addon.Confluence/Greenshot.Addon.Confluence.csproj index e4e8aa82a..7a5fd93ca 100644 --- a/src/Greenshot.Addon.Confluence/Greenshot.Addon.Confluence.csproj +++ b/src/Greenshot.Addon.Confluence/Greenshot.Addon.Confluence.csproj @@ -3,7 +3,7 @@ Greenshot.Addon.Confluence Greenshot.Addon.Confluence - net471;netcoreapp3.0 + net472;netcoreapp3.0 @@ -12,7 +12,7 @@ - + diff --git a/src/Greenshot.Addon.Dropbox/Greenshot.Addon.Dropbox.csproj b/src/Greenshot.Addon.Dropbox/Greenshot.Addon.Dropbox.csproj index 125d361ef..6b7cb9569 100644 --- a/src/Greenshot.Addon.Dropbox/Greenshot.Addon.Dropbox.csproj +++ b/src/Greenshot.Addon.Dropbox/Greenshot.Addon.Dropbox.csproj @@ -3,7 +3,7 @@ Greenshot.Addon.Dropbox Greenshot.Addon.Dropbox - net471;netcoreapp3.0 + net472;netcoreapp3.0 @@ -12,7 +12,7 @@ - + diff --git a/src/Greenshot.Addon.ExternalCommand/Greenshot.Addon.ExternalCommand.csproj b/src/Greenshot.Addon.ExternalCommand/Greenshot.Addon.ExternalCommand.csproj index 99a470892..aec53479a 100644 --- a/src/Greenshot.Addon.ExternalCommand/Greenshot.Addon.ExternalCommand.csproj +++ b/src/Greenshot.Addon.ExternalCommand/Greenshot.Addon.ExternalCommand.csproj @@ -3,7 +3,7 @@ Greenshot.Addon.ExternalCommand Greenshot.Addon.ExternalCommand - net471;netcoreapp3.0 + net472;netcoreapp3.0 @@ -12,7 +12,7 @@ - + diff --git a/src/Greenshot.Addon.Flickr/Greenshot.Addon.Flickr.csproj b/src/Greenshot.Addon.Flickr/Greenshot.Addon.Flickr.csproj index 9529e88c2..1867d03b3 100644 --- a/src/Greenshot.Addon.Flickr/Greenshot.Addon.Flickr.csproj +++ b/src/Greenshot.Addon.Flickr/Greenshot.Addon.Flickr.csproj @@ -3,7 +3,7 @@ Greenshot.Addon.Flickr Greenshot.Addon.Flickr - net471;netcoreapp3.0 + net472;netcoreapp3.0 @@ -12,7 +12,7 @@ - + diff --git a/src/Greenshot.Addon.GooglePhotos/Greenshot.Addon.GooglePhotos.csproj b/src/Greenshot.Addon.GooglePhotos/Greenshot.Addon.GooglePhotos.csproj index 6d2ac9fd1..8e32b2894 100644 --- a/src/Greenshot.Addon.GooglePhotos/Greenshot.Addon.GooglePhotos.csproj +++ b/src/Greenshot.Addon.GooglePhotos/Greenshot.Addon.GooglePhotos.csproj @@ -3,7 +3,7 @@ Greenshot.Addon.GooglePhotos Greenshot.Addon.GooglePhotos - net471;netcoreapp3.0 + net472;netcoreapp3.0 @@ -12,7 +12,7 @@ - + diff --git a/src/Greenshot.Addon.Imgur/Greenshot.Addon.Imgur.csproj b/src/Greenshot.Addon.Imgur/Greenshot.Addon.Imgur.csproj index 9367db99b..4efc8feb3 100644 --- a/src/Greenshot.Addon.Imgur/Greenshot.Addon.Imgur.csproj +++ b/src/Greenshot.Addon.Imgur/Greenshot.Addon.Imgur.csproj @@ -3,7 +3,7 @@ Greenshot.Addon.Imgur Greenshot.Addon.Imgur - net471;netcoreapp3.0 + net472;netcoreapp3.0 @@ -12,7 +12,7 @@ - + @@ -55,6 +55,6 @@ all runtime; build; native; contentfiles; analyzers - + diff --git a/src/Greenshot.Addon.InternetExplorer/Greenshot.Addon.InternetExplorer.csproj b/src/Greenshot.Addon.InternetExplorer/Greenshot.Addon.InternetExplorer.csproj index 1f41c244d..4e941d2a0 100644 --- a/src/Greenshot.Addon.InternetExplorer/Greenshot.Addon.InternetExplorer.csproj +++ b/src/Greenshot.Addon.InternetExplorer/Greenshot.Addon.InternetExplorer.csproj @@ -1,11 +1,11 @@ - net471;netcoreapp3.0 + net472;netcoreapp3.0 true - + diff --git a/src/Greenshot.Addon.Jira/Greenshot.Addon.Jira.csproj b/src/Greenshot.Addon.Jira/Greenshot.Addon.Jira.csproj index af77bf7a3..1579a303e 100644 --- a/src/Greenshot.Addon.Jira/Greenshot.Addon.Jira.csproj +++ b/src/Greenshot.Addon.Jira/Greenshot.Addon.Jira.csproj @@ -3,7 +3,7 @@ Greenshot.Addon.Jira Greenshot.Addon.Jira - net471 + net472 @@ -12,7 +12,7 @@ - + diff --git a/src/Greenshot.Addon.LegacyEditor/Greenshot.Addon.LegacyEditor.csproj b/src/Greenshot.Addon.LegacyEditor/Greenshot.Addon.LegacyEditor.csproj index 5a2aa6a98..970bae2dc 100644 --- a/src/Greenshot.Addon.LegacyEditor/Greenshot.Addon.LegacyEditor.csproj +++ b/src/Greenshot.Addon.LegacyEditor/Greenshot.Addon.LegacyEditor.csproj @@ -3,7 +3,7 @@ Greenshot.Addon.LegacyEditor Greenshot.Addon.LegacyEditor - net471;netcoreapp3.0 + net472;netcoreapp3.0 true @@ -13,7 +13,7 @@ - + diff --git a/src/Greenshot.Addon.Lutim/Greenshot.Addon.Lutim.csproj b/src/Greenshot.Addon.Lutim/Greenshot.Addon.Lutim.csproj index bc274a0df..a0e367258 100644 --- a/src/Greenshot.Addon.Lutim/Greenshot.Addon.Lutim.csproj +++ b/src/Greenshot.Addon.Lutim/Greenshot.Addon.Lutim.csproj @@ -3,7 +3,7 @@ Greenshot.Addon.Lutim Greenshot.Addon.Lutim - net471;netcoreapp3.0 + net472;netcoreapp3.0 @@ -12,7 +12,7 @@ - + @@ -51,7 +51,7 @@ - + all runtime; build; native; contentfiles; analyzers diff --git a/src/Greenshot.Addon.OCR/Greenshot.Addon.OCR.csproj b/src/Greenshot.Addon.OCR/Greenshot.Addon.OCR.csproj index 1e53b6b74..1a1900a39 100644 --- a/src/Greenshot.Addon.OCR/Greenshot.Addon.OCR.csproj +++ b/src/Greenshot.Addon.OCR/Greenshot.Addon.OCR.csproj @@ -3,7 +3,7 @@ Greenshot.Addon.OCR Greenshot.Addon.OCR - net471;netcoreapp3.0 + net472;netcoreapp3.0 @@ -12,7 +12,7 @@ - + diff --git a/src/Greenshot.Addon.OcrCommand/Greenshot.Addon.OcrCommand.csproj b/src/Greenshot.Addon.OcrCommand/Greenshot.Addon.OcrCommand.csproj index aa44937c0..2ba2850cd 100644 --- a/src/Greenshot.Addon.OcrCommand/Greenshot.Addon.OcrCommand.csproj +++ b/src/Greenshot.Addon.OcrCommand/Greenshot.Addon.OcrCommand.csproj @@ -2,12 +2,12 @@ WinExe - net471 + net472 Greenshot.Addon.OcrCommand GreenshotOCRCommand - + diff --git a/src/Greenshot.Addon.Office/Greenshot.Addon.Office.csproj b/src/Greenshot.Addon.Office/Greenshot.Addon.Office.csproj index ff62f25c6..955f8ab68 100644 --- a/src/Greenshot.Addon.Office/Greenshot.Addon.Office.csproj +++ b/src/Greenshot.Addon.Office/Greenshot.Addon.Office.csproj @@ -3,7 +3,7 @@ Greenshot.Addon.Office Greenshot.Addon.Office - net471;netcoreapp3.0 + net472;netcoreapp3.0 @@ -12,7 +12,7 @@ - + diff --git a/src/Greenshot.Addon.OneDrive/Greenshot.Addon.OneDrive.csproj b/src/Greenshot.Addon.OneDrive/Greenshot.Addon.OneDrive.csproj index 7ba142c0a..7ca70ce7f 100644 --- a/src/Greenshot.Addon.OneDrive/Greenshot.Addon.OneDrive.csproj +++ b/src/Greenshot.Addon.OneDrive/Greenshot.Addon.OneDrive.csproj @@ -3,7 +3,7 @@ Greenshot.Addon.OneDrive Greenshot.Addon.OneDrive - net471;netcoreapp3.0 + net472;netcoreapp3.0 @@ -12,7 +12,7 @@ - + @@ -51,7 +51,7 @@ - + all runtime; build; native; contentfiles; analyzers diff --git a/src/Greenshot.Addon.Photobucket/Greenshot.Addon.Photobucket.csproj b/src/Greenshot.Addon.Photobucket/Greenshot.Addon.Photobucket.csproj index ffc842088..da487eee3 100644 --- a/src/Greenshot.Addon.Photobucket/Greenshot.Addon.Photobucket.csproj +++ b/src/Greenshot.Addon.Photobucket/Greenshot.Addon.Photobucket.csproj @@ -3,7 +3,7 @@ Greenshot.Addon.Photobucket Greenshot.Addon.Photobucket - net471;netcoreapp3.0 + net472;netcoreapp3.0 @@ -12,7 +12,7 @@ - + diff --git a/src/Greenshot.Addon.Tfs/Greenshot.Addon.Tfs.csproj b/src/Greenshot.Addon.Tfs/Greenshot.Addon.Tfs.csproj index b420a57f5..8b0dff972 100644 --- a/src/Greenshot.Addon.Tfs/Greenshot.Addon.Tfs.csproj +++ b/src/Greenshot.Addon.Tfs/Greenshot.Addon.Tfs.csproj @@ -3,7 +3,7 @@ Greenshot.Addon.Tfs Greenshot.Addon.Tfs - net471;netcoreapp3.0 + net472;netcoreapp3.0 @@ -12,7 +12,7 @@ - + @@ -51,7 +51,7 @@ - + all runtime; build; native; contentfiles; analyzers diff --git a/src/Greenshot.Addon.Win10/Greenshot.Addon.Win10.csproj b/src/Greenshot.Addon.Win10/Greenshot.Addon.Win10.csproj index c1235909f..3f3a8a8f9 100644 --- a/src/Greenshot.Addon.Win10/Greenshot.Addon.Win10.csproj +++ b/src/Greenshot.Addon.Win10/Greenshot.Addon.Win10.csproj @@ -3,7 +3,7 @@ Greenshot.Addon.Win10 Greenshot.Addon.Win10 - net471;netcoreapp3.0 + net472;netcoreapp3.0 @@ -13,21 +13,13 @@ - C:\Program Files (x86)\Windows Kits\10\UnionMetadata\10.0.16299.0\Windows.winmd - + - - - - False - C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.Runtime.WindowsRuntime.dll - global - C:\Program Files (x86)\Windows Kits\10\UnionMetadata\10.0.16299.0\Windows.winmd @@ -62,5 +54,7 @@ + + \ No newline at end of file diff --git a/src/Greenshot.Addon.Win10/Win10FormEnhancer.cs b/src/Greenshot.Addon.Win10/Win10FormEnhancer.cs index e43e33a68..aef9fb15d 100644 --- a/src/Greenshot.Addon.Win10/Win10FormEnhancer.cs +++ b/src/Greenshot.Addon.Win10/Win10FormEnhancer.cs @@ -40,24 +40,33 @@ namespace Greenshot.Addon.Win10 public void InitializeComponent(Form target) { - // TODO: Fix the code below, when the following is solved: https://github.com/windows-toolkit/Microsoft.Toolkit.Win32/issues/16#issuecomment-451337186 + if (target is null) + { + return; + } return; // InkCanvas - inkCanvasHost = new WindowsXamlHost(); - inkCanvasHost.InitialTypeName = "Windows.UI.Xaml.Controls.InkCanvas"; + inkCanvasHost = new WindowsXamlHost + { + InitialTypeName = "Windows.UI.Xaml.Controls.InkCanvas", + Dock = DockStyle.Fill, + BackColor = Color.Transparent, + + }; inkCanvasHost.ChildChanged += InkCanvas_ChildChanged; - // InkToolbar - inkToolbarHost = new WindowsXamlHost(); - inkToolbarHost.InitialTypeName = "Windows.UI.Xaml.Controls.InkToolbar"; - inkToolbarHost.ChildChanged += InkToolbar_ChildChanged; - // Layout - inkToolbarHost.Top = 0; - inkToolbarHost.Left = 0; - inkToolbarHost.Height = 50; - inkToolbarHost.Dock = DockStyle.Top; - inkCanvasHost.Dock = DockStyle.Fill; - inkCanvasHost.BackColor = Color.Transparent; + // InkToolbar + inkToolbarHost = new WindowsXamlHost + { + InitialTypeName = "Windows.UI.Xaml.Controls.InkToolbar", + // Layout + Top = 0, + Left = 0, + Height = 50, + Dock = DockStyle.Top, + BackColor = Color.Transparent + }; + inkToolbarHost.ChildChanged += InkToolbar_ChildChanged; // Add to Window target.Controls.Add(inkToolbarHost); diff --git a/src/Greenshot.Addons/Core/DotNetScreenCapture.cs b/src/Greenshot.Addons/Core/DotNetScreenCapture.cs new file mode 100644 index 000000000..b25a7c9b7 --- /dev/null +++ b/src/Greenshot.Addons/Core/DotNetScreenCapture.cs @@ -0,0 +1,96 @@ +#region Greenshot GNU General Public License + +// Greenshot - a free and open source screenshot tool +// Copyright (C) 2007-2018 Thomas Braun, Jens Klingen, Robin Krom +// +// For more information see: http://getgreenshot.org/ +// The Greenshot project is hosted on GitHub https://github.com/greenshot/greenshot +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 1 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#endregion + +#region Usings + +using System; +using System.Drawing; +using System.Runtime.InteropServices; +using System.Windows; +using System.Windows.Interop; +using System.Windows.Media.Imaging; +using Dapplo.Windows.Common.Structs; +using Dapplo.Windows.Gdi32; +using Dapplo.Windows.Gdi32.Enums; +using Dapplo.Windows.Gdi32.SafeHandles; +using Dapplo.Windows.Gdi32.Structs; +using Dapplo.Windows.User32; + +#endregion + +namespace Greenshot.Addons.Core +{ + /// + /// This allows us to repeatedly capture the screen via DotNet + /// + public class DotNetScreenCapture : IDisposable + { + + + /// + /// Return the source rectangle + /// + public NativeRect SourceRect { get; } + + /// + /// Return the source rectangle + /// + public NativeSize DestinationSize { get; } + + /// + /// The constructor + /// + /// NativeRect, optional, with the source area from the screen + /// NativeSize, optional, specifying the resulting size + public DotNetScreenCapture(NativeRect? sourceCaptureBounds = null, NativeSize? requestedSize = null) + { + + } + + /// + /// Capture a frame from the screen + /// + public void CaptureFrame() + { + + } + + + /// + /// Get the frame, captured with the previous CaptureFrame call, as + /// + /// Bitmap + public Bitmap CurrentFrameAsBitmap() + { + return null; + } + + /// + /// Dispose all DC, DIB, handles etc + /// + public void Dispose() + { + + } + } +} \ No newline at end of file diff --git a/src/Greenshot.Addons/Greenshot.Addons.csproj b/src/Greenshot.Addons/Greenshot.Addons.csproj index cbbab137e..8ecde1fac 100644 --- a/src/Greenshot.Addons/Greenshot.Addons.csproj +++ b/src/Greenshot.Addons/Greenshot.Addons.csproj @@ -1,7 +1,7 @@ - net471;netcoreapp3.0 + net472;netcoreapp3.0 true @@ -9,7 +9,7 @@ - + @@ -72,10 +72,10 @@ runtime; build; native; contentfiles; analyzers - 3.0.0-alpha0096 + 3.0.0-alpha0103 - 2.4.0 + 2.4.1 diff --git a/src/Greenshot.Core/Greenshot.Core.csproj b/src/Greenshot.Core/Greenshot.Core.csproj index 24a244c47..1b596e401 100644 --- a/src/Greenshot.Core/Greenshot.Core.csproj +++ b/src/Greenshot.Core/Greenshot.Core.csproj @@ -1,11 +1,11 @@ - net471;netcoreapp3.0 + net472;netcoreapp3.0 true - + diff --git a/src/Greenshot.Gfx.Experimental/BoxBlurSpan.cs b/src/Greenshot.Gfx.Experimental/BoxBlurSpan.cs index 07d6a7123..43531e41d 100644 --- a/src/Greenshot.Gfx.Experimental/BoxBlurSpan.cs +++ b/src/Greenshot.Gfx.Experimental/BoxBlurSpan.cs @@ -71,6 +71,7 @@ namespace Greenshot.Gfx.Experimental PixelStride = pixelStride, BitmapSize = destinationBitmap.Height * pixelStride }; + if (isAlpha) { ApplyBoxBlurSpanAlpha(spanInfo, range); @@ -150,10 +151,9 @@ namespace Greenshot.Gfx.Experimental Parallel.For(spanInfo.Top, spanInfo.Bottom, y => { - Span rgb24; - unsafe { rgb24 = new Span((byte*)spanInfo.Pointer, spanInfo.BitmapSize); } - unsafe - { + + unsafe { + var rgb24 = new Span((byte*)spanInfo.Pointer, spanInfo.BitmapSize); Span averages = stackalloc Rgb24[range]; var r = 0; var g = 0; @@ -217,10 +217,8 @@ namespace Greenshot.Gfx.Experimental var halfRange = range / 2; Parallel.For(spanInfo.Left, spanInfo.Right, x => { - Span rgb24; - unsafe { rgb24 = new Span((byte*)spanInfo.Pointer, spanInfo.BitmapSize); } - unsafe - { + unsafe { + var rgb24 = new Span((byte*)spanInfo.Pointer, spanInfo.BitmapSize); Span averages = stackalloc Rgb24[range]; var hits = 0; var r = 0; @@ -228,7 +226,7 @@ namespace Greenshot.Gfx.Experimental var b = 0; for (var y = spanInfo.Top; y < spanInfo.Top + halfRange; y++) { - ref Rgb24 color = ref rgb24[x + y * spanInfo.PixelStride]; + ref Rgb24 color = ref rgb24[y * spanInfo.PixelStride + x]; r += color.R; g += color.G; b += color.B; @@ -257,7 +255,7 @@ namespace Greenshot.Gfx.Experimental hits++; } - ref Rgb24 average = ref averages[(y % range)]; + ref Rgb24 average = ref averages[y % range]; average.R = (byte)(r / hits); average.G = (byte)(g / hits); average.B = (byte)(b / hits); @@ -285,19 +283,18 @@ namespace Greenshot.Gfx.Experimental Parallel.For(spanInfo.Top, spanInfo.Bottom, y => { - Span argb32; - unsafe { argb32 = new Span((byte*)spanInfo.Pointer, spanInfo.BitmapSize); } - unsafe - { + unsafe { + var argb32 = new Span((byte*)spanInfo.Pointer, spanInfo.BitmapSize); Span averages = stackalloc Bgra32[range]; var a = 0; var r = 0; var g = 0; var b = 0; var hits = halfRange; + var lineOffset = y * spanInfo.PixelStride; for (var x = spanInfo.Left; x < spanInfo.Left + halfRange; x++) { - ref Bgra32 color = ref argb32[x + y * spanInfo.PixelStride]; + ref Bgra32 color = ref argb32[x + lineOffset]; a += color.A; r += color.R; g += color.G; @@ -309,7 +306,7 @@ namespace Greenshot.Gfx.Experimental if (leftSide >= spanInfo.Left) { // Get value at the left side of range - ref Bgra32 color = ref argb32[leftSide + y * spanInfo.PixelStride]; + ref Bgra32 color = ref argb32[leftSide + lineOffset]; a -= color.A; r -= color.R; g -= color.G; @@ -320,7 +317,7 @@ namespace Greenshot.Gfx.Experimental var rightSide = x + halfRange; if (rightSide < spanInfo.Right) { - ref Bgra32 color = ref argb32[rightSide + y * spanInfo.PixelStride]; + ref Bgra32 color = ref argb32[rightSide + lineOffset]; a += color.A; r += color.R; g += color.G; @@ -328,7 +325,7 @@ namespace Greenshot.Gfx.Experimental hits++; } - ref Bgra32 average = ref averages[(x % range)]; + ref Bgra32 average = ref averages[x % range]; average.A = (byte)(a / hits); average.R = (byte)(r / hits); average.G = (byte)(g / hits); @@ -339,7 +336,7 @@ namespace Greenshot.Gfx.Experimental // Now we can write the value from the calculated avarages var readLocation = (leftSide % range); - argb32[leftSide + y * spanInfo.PixelStride] = averages[readLocation]; + argb32[leftSide + lineOffset] = averages[readLocation]; } } } diff --git a/src/Greenshot.Gfx.Experimental/Greenshot.Gfx.Experimental.csproj b/src/Greenshot.Gfx.Experimental/Greenshot.Gfx.Experimental.csproj index 75af664e7..a7e118396 100644 --- a/src/Greenshot.Gfx.Experimental/Greenshot.Gfx.Experimental.csproj +++ b/src/Greenshot.Gfx.Experimental/Greenshot.Gfx.Experimental.csproj @@ -1,11 +1,11 @@ - net471;netcoreapp3.0 + net472;netcoreapp3.0 true - + diff --git a/src/Greenshot.Gfx.Experimental/Structs/Bgr32.cs b/src/Greenshot.Gfx.Experimental/Structs/Bgr32.cs new file mode 100644 index 000000000..bce03887b --- /dev/null +++ b/src/Greenshot.Gfx.Experimental/Structs/Bgr32.cs @@ -0,0 +1,49 @@ +#region Greenshot GNU General Public License + +// Greenshot - a free and open source screenshot tool +// Copyright (C) 2007-2018 Thomas Braun, Jens Klingen, Robin Krom +// +// For more information see: http://getgreenshot.org/ +// The Greenshot project is hosted on GitHub https://github.com/greenshot/greenshot +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 1 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#endregion + +namespace Greenshot.Gfx.Experimental.Structs +{ + /// + /// A struct with the BGR values for a 32bit pixel + /// + public struct Bgr32 + { + /// + /// Blue component of the pixel + /// + public byte B; + /// + /// Green component of the pixel + /// + public byte G; + /// + /// Red component of the pixel + /// + public byte R; + /// + /// Unused component of the pixel + /// + public readonly byte Unused; + } + +} diff --git a/src/Greenshot.Gfx.Experimental/Structs/Bgra32.cs b/src/Greenshot.Gfx.Experimental/Structs/Bgra32.cs index 40ee0ccc9..c6fe55c82 100644 --- a/src/Greenshot.Gfx.Experimental/Structs/Bgra32.cs +++ b/src/Greenshot.Gfx.Experimental/Structs/Bgra32.cs @@ -24,13 +24,25 @@ namespace Greenshot.Gfx.Experimental.Structs { /// - /// Default BGRA values for a 32bit bitmapsource + /// A struct with the BGR values for a 32bit pixel /// public struct Bgra32 { + /// + /// Blue component of the pixel + /// public byte B; + /// + /// Green component of the pixel + /// public byte G; + /// + /// Red component of the pixel + /// public byte R; + /// + /// Alpha component of the pixel + /// public byte A; } diff --git a/src/Greenshot.Gfx.Experimental/Structs/Rgb24.cs b/src/Greenshot.Gfx.Experimental/Structs/Rgb24.cs index fd3ce4ff8..a1c83cf16 100644 --- a/src/Greenshot.Gfx.Experimental/Structs/Rgb24.cs +++ b/src/Greenshot.Gfx.Experimental/Structs/Rgb24.cs @@ -1,12 +1,21 @@ namespace Greenshot.Gfx.Experimental.Structs { /// - /// Default RGB values for a 24bit bitmap + /// A struct with the BGR values for a 24bit pixel /// public struct Rgb24 { + /// + /// Blue component of the pixel + /// public byte B; + /// + /// Green component of the pixel + /// public byte G; + /// + /// Red component of the pixel + /// public byte R; } } diff --git a/src/Greenshot.Gfx.Experimental/Structs/SpanInfo.cs b/src/Greenshot.Gfx.Experimental/Structs/SpanInfo.cs index a3e35fbe3..f675816e0 100644 --- a/src/Greenshot.Gfx.Experimental/Structs/SpanInfo.cs +++ b/src/Greenshot.Gfx.Experimental/Structs/SpanInfo.cs @@ -2,7 +2,7 @@ namespace Greenshot.Gfx.Experimental.Structs { - public struct SpanInfo + public class SpanInfo { public IntPtr Pointer; public int PixelStride; diff --git a/src/Greenshot.Gfx.Experimental/UnmanagedBitmap.cs b/src/Greenshot.Gfx.Experimental/UnmanagedBitmap.cs new file mode 100644 index 000000000..45c21b435 --- /dev/null +++ b/src/Greenshot.Gfx.Experimental/UnmanagedBitmap.cs @@ -0,0 +1,149 @@ +#region Greenshot GNU General Public License + +// Greenshot - a free and open source screenshot tool +// Copyright (C) 2007-2018 Thomas Braun, Jens Klingen, Robin Krom +// +// For more information see: http://getgreenshot.org/ +// The Greenshot project is hosted on GitHub https://github.com/greenshot/greenshot +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 1 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#endregion + +using System; +using System.Buffers; +using System.Drawing; +using System.Drawing.Imaging; +using System.Runtime.InteropServices; + + +namespace Greenshot.Gfx.Experimental +{ + /// + /// A bitmap with memory from Marshal.AllocHGlobal + /// + /// struct for the pixel information + public class UnmanagedBitmap : MemoryManager where TPixelLayout : unmanaged + { + private readonly object _lock = new object(); + private readonly int _byteLength; + private readonly int _bytesPerPixel; + private readonly int _stride; + private bool _isDisposed; + private readonly IntPtr _hGlobal; + + /// + /// Width of the bitmap + /// + public int Width { get; } + + /// + /// Height of the bitmap + /// + public int Height { get; } + + /// + /// The format of the pixels + /// + public PixelFormat Format { get; } + + /// + /// The constructor for the UnmanagedBitmap + /// + /// int + /// int + /// PixelFormat + public UnmanagedBitmap(int width, int height, PixelFormat pixelFormat) + { + _bytesPerPixel = Marshal.SizeOf(); + Width = width; + Height = height; + Format = pixelFormat; + _stride = width * _bytesPerPixel; + _byteLength = height * _stride; + _hGlobal = Marshal.AllocHGlobal(_byteLength); + GC.AddMemoryPressure(_byteLength); + } + + /// + public override unsafe Span GetSpan() => new Span(_hGlobal.ToPointer(), _byteLength); + + /// + /// Retrusn + /// + public override Memory Memory => CreateMemory(0, Width * Height); + + /// + /// NotSupportedException + /// + /// int + /// MemoryHandle + public override MemoryHandle Pin(int elementIndex = 0) + { + throw new NotSupportedException("Pinning not needed"); + } + + /// + /// NotSupportedException + /// + public override void Unpin() + { + throw new NotSupportedException("Pinning not needed"); + } + + /// + /// Convert this to a real bitmap + /// + /// + public Bitmap AsBitmap() + { + return new Bitmap(Width, Height, _stride, Format, _hGlobal); + } + + #region Implementation of IDisposable + + /// + /// Dispose implementation + /// + /// + protected override void Dispose(bool disposing) + { + if (_isDisposed) + { + return; + } + lock (_lock) + { + if (_isDisposed) + { + return; + } + + _isDisposed = true; + Marshal.FreeHGlobal(_hGlobal); + GC.RemoveMemoryPressure(_byteLength); + } + } + + /// + /// The actual dispose + /// + public void Dispose() + { + Dispose(true); + } + + #endregion + } +} diff --git a/src/Greenshot.Gfx/Greenshot.Gfx.csproj b/src/Greenshot.Gfx/Greenshot.Gfx.csproj index 9e7d2e8e1..daab46aee 100644 --- a/src/Greenshot.Gfx/Greenshot.Gfx.csproj +++ b/src/Greenshot.Gfx/Greenshot.Gfx.csproj @@ -1,11 +1,11 @@ - net471;netcoreapp3.0 + net472;netcoreapp3.0 true - + @@ -31,8 +31,9 @@ 1.2.21 + - 2.4.0 + 2.4.1 diff --git a/src/Greenshot.PerformanceTests/GfxPerformance.cs b/src/Greenshot.PerformanceTests/GfxPerformance.cs index 40b2d2b00..6e92432da 100644 --- a/src/Greenshot.PerformanceTests/GfxPerformance.cs +++ b/src/Greenshot.PerformanceTests/GfxPerformance.cs @@ -5,6 +5,9 @@ using Greenshot.Gfx; using Greenshot.Gfx.Experimental; using Greenshot.Gfx.Quantizer; using Greenshot.Tests.Implementation; +using SixLabors.ImageSharp; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; namespace Greenshot.PerformanceTests { @@ -14,6 +17,12 @@ namespace Greenshot.PerformanceTests [MinColumn, MaxColumn, MemoryDiagnoser] public class GfxPerformance { + [GlobalSetup] + public void Setup() + { + BoxBlurImageSharp(); + } + [Benchmark] [Arguments(PixelFormat.Format24bppRgb)] [Arguments(PixelFormat.Format32bppRgb)] @@ -69,6 +78,21 @@ namespace Greenshot.PerformanceTests } } + + [Benchmark] + public void BoxBlurImageSharp() + { + var color = NamedColors.Blue; + var solidBlueBrush = SixLabors.ImageSharp.Processing.Brushes.Solid(color); + var graphicsOptions = new GraphicsOptions(false); + using (var image = new Image(SixLabors.ImageSharp.Configuration.Default, 400, 400, NamedColors.White)) + { + image.Mutate(c => c + .Fill(new GraphicsOptions(false), solidBlueBrush, new SixLabors.Primitives.Rectangle(30, 30, 340, 340)) + .BoxBlur(10)); + } + } + [Benchmark] [Arguments(PixelFormat.Format24bppRgb)] [Arguments(PixelFormat.Format32bppRgb)] diff --git a/src/Greenshot.PerformanceTests/Greenshot.PerformanceTests.csproj b/src/Greenshot.PerformanceTests/Greenshot.PerformanceTests.csproj index a18afd4ab..bd108bc9c 100644 --- a/src/Greenshot.PerformanceTests/Greenshot.PerformanceTests.csproj +++ b/src/Greenshot.PerformanceTests/Greenshot.PerformanceTests.csproj @@ -4,7 +4,7 @@ Greenshot.PerformanceTests Greenshot.PerformanceTests Exe - net471;netcoreapp3.0 + net472;netcoreapp3.0 true @@ -20,7 +20,7 @@ - + @@ -56,7 +56,7 @@ - + @@ -67,6 +67,8 @@ + + diff --git a/src/Greenshot.PerformanceTests/Program.cs b/src/Greenshot.PerformanceTests/Program.cs index 5dd3e2843..6f028942b 100644 --- a/src/Greenshot.PerformanceTests/Program.cs +++ b/src/Greenshot.PerformanceTests/Program.cs @@ -22,9 +22,6 @@ #endregion using System; -using BenchmarkDotNet.Configs; -using BenchmarkDotNet.Environments; -using BenchmarkDotNet.Jobs; using BenchmarkDotNet.Running; namespace Greenshot.PerformanceTests @@ -37,10 +34,7 @@ namespace Greenshot.PerformanceTests // ReSharper disable once UnusedParameter.Local private static void Main(string[] args) { - var job = Job.Default.With(Platform.X64); - var config = DefaultConfig.Instance.With(job).KeepBenchmarkFiles(true); - //BenchmarkRunner.Run(config); - BenchmarkRunner.Run(config); + BenchmarkRunner.Run(); Console.ReadLine(); } } diff --git a/src/Greenshot.Tests/BlurTests.cs b/src/Greenshot.Tests/BlurTests.cs index cf94dda14..fe26ee63f 100644 --- a/src/Greenshot.Tests/BlurTests.cs +++ b/src/Greenshot.Tests/BlurTests.cs @@ -23,9 +23,13 @@ using System.Drawing; using System.Drawing.Imaging; +using System.IO; using Greenshot.Gfx; using Greenshot.Gfx.Experimental; using Greenshot.Tests.Implementation; +using SixLabors.ImageSharp; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; using Xunit; namespace Greenshot.Tests @@ -35,6 +39,43 @@ namespace Greenshot.Tests /// public class BlurTests { + [Fact] + public void Test_BoxBlurSharpImage() + { + using (var bitmapOld = BitmapFactory.CreateEmpty(400, 400, PixelFormat.Format32bppArgb, Color.White)) + { + using (var graphics = Graphics.FromImage(bitmapOld)) + using (var pen = new SolidBrush(Color.Blue)) + { + graphics.FillRectangle(pen, new Rectangle(30, 30, 340, 340)); + bitmapOld.ApplyOldBoxBlur(10); + bitmapOld.Save(@"old.png", ImageFormat.Png); + } + + using (var tmpStream = new MemoryStream()) + using (var image = new Image(SixLabors.ImageSharp.Configuration.Default, 400, 400, Rgba32.White)) + { + var color = Rgba32.Blue; + color.A = 255; + var solidBlueBrush = SixLabors.ImageSharp.Processing.Brushes.Solid(color); + var g = new GraphicsOptions(false); + image.Mutate(c => c + .Fill(new GraphicsOptions(false), solidBlueBrush, new SixLabors.Primitives.Rectangle(30, 30, 340, 340)) + .BoxBlur(10)); + image.SaveAsPng(tmpStream); + + tmpStream.Seek(0, SeekOrigin.Begin); + using (var bitmapNew = (Bitmap)System.Drawing.Image.FromStream(tmpStream)) + { + bitmapNew.Save(@"new.png", ImageFormat.Png); + Assert.True(bitmapOld.IsEqualTo(bitmapNew), "New blur doesn't compare to old."); + } + } + + } + } + + [Theory] [InlineData(PixelFormat.Format24bppRgb)] [InlineData(PixelFormat.Format32bppRgb)] diff --git a/src/Greenshot.Tests/Greenshot.Tests.csproj b/src/Greenshot.Tests/Greenshot.Tests.csproj index 11c512573..2d764d5ee 100644 --- a/src/Greenshot.Tests/Greenshot.Tests.csproj +++ b/src/Greenshot.Tests/Greenshot.Tests.csproj @@ -1,7 +1,7 @@ - net471;netcoreapp3.0 + net472;netcoreapp3.0 true @@ -17,7 +17,7 @@ - + @@ -67,7 +67,7 @@ - + @@ -78,6 +78,7 @@ + @@ -87,7 +88,7 @@ runtime; build; native; contentfiles; analyzers all - + diff --git a/src/Greenshot/Greenshot.csproj b/src/Greenshot/Greenshot.csproj index a2c411b51..d2d9e46e0 100644 --- a/src/Greenshot/Greenshot.csproj +++ b/src/Greenshot/Greenshot.csproj @@ -2,16 +2,17 @@ WinExe - net471;netcoreapp3.0 + net472;netcoreapp3.0 latest icons\applicationIcon\icon.ico True greenshot.manifest Greenshot Greenshot + win-x86 - + PreserveNewest @@ -35,7 +36,7 @@ - + @@ -96,8 +97,8 @@ runtime; build; native; contentfiles; analyzers - - + + diff --git a/src/Greenshot/GreenshotAutofacModule.cs b/src/Greenshot/GreenshotAutofacModule.cs index b7b071a89..66ae3d2cb 100644 --- a/src/Greenshot/GreenshotAutofacModule.cs +++ b/src/Greenshot/GreenshotAutofacModule.cs @@ -55,8 +55,8 @@ namespace Greenshot // Specify the directories for the translations manually, this is a workaround builder.Register(context => LanguageConfigBuilder.Create() .WithSpecificDirectories(GenerateScanDirectories( -#if NET471 - "net471", +#if NET472 + "net472", #else "netcoreapp3.0", #endif diff --git a/src/NuGet.Config b/src/NuGet.Config new file mode 100644 index 000000000..79e7784da --- /dev/null +++ b/src/NuGet.Config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file