From 3f0645b460754617139026411ebc22017133ac5f Mon Sep 17 00:00:00 2001 From: Wayfarer Date: Sun, 10 Nov 2024 20:10:14 +0100 Subject: [PATCH] format --- Imaging/ColorHsv.cs | 1 + Imaging/IImageRender.cs | 4 +- Imaging/ImageFilterStream.cs | 48 ++++++------ Imaging/ImageMask.cs | 2 +- Imaging/ImageRegister.cs | 44 +++++------ Imaging/ImageRender.cs | 7 +- SlimViewer/MainWindow.xaml | 2 +- SlimViews/FillTypeVisibilityConverter .cs | 2 - SlimViews/FilterConfigView.cs | 2 +- .../SelectionToVisibilityConverter .cs | 10 +-- .../Templates/ToolOptionsTemplateSelector.cs | 4 +- SlimViews/Templates/ToolOptionsTemplates.xaml | 77 ++++++++++--------- 12 files changed, 103 insertions(+), 100 deletions(-) diff --git a/Imaging/ColorHsv.cs b/Imaging/ColorHsv.cs index e07d7b2..b76d603 100644 --- a/Imaging/ColorHsv.cs +++ b/Imaging/ColorHsv.cs @@ -348,6 +348,7 @@ public override int GetHashCode() { if (ReferenceEquals(left, right)) return true; // Same reference if (left is null || right is null) return false; // One is null + return left.Equals(right); } diff --git a/Imaging/IImageRender.cs b/Imaging/IImageRender.cs index 906edb6..256e433 100644 --- a/Imaging/IImageRender.cs +++ b/Imaging/IImageRender.cs @@ -128,7 +128,7 @@ internal interface IImageRender Bitmap CutBitmap(Bitmap image, int x, int y, int height, int width); /// - /// Cuts the bitmap. + /// Cuts the bitmap. /// /// The image. /// The width. @@ -137,7 +137,7 @@ internal interface IImageRender /// The shape parameters. /// The start point. /// - /// The cut Image, based on the shape + /// The cut Image, based on the shape /// /// Bitmap CutBitmap(Bitmap image, int width, int height, MaskShape shape, object shapeParams = null, diff --git a/Imaging/ImageFilterStream.cs b/Imaging/ImageFilterStream.cs index d0eb5c2..44e7a6d 100644 --- a/Imaging/ImageFilterStream.cs +++ b/Imaging/ImageFilterStream.cs @@ -78,62 +78,62 @@ internal static Bitmap FilterImage(Bitmap image, ImageFilters filter, ImageRegis switch (filter) { case ImageFilters.GrayScale: - atr.SetColorMatrix(_imageSettings.grayScale); + atr.SetColorMatrix(_imageSettings.GrayScale); break; case ImageFilters.Invert: - atr.SetColorMatrix(_imageSettings.invert); + atr.SetColorMatrix(_imageSettings.Invert); break; case ImageFilters.Sepia: - atr.SetColorMatrix(_imageSettings.sepia); + atr.SetColorMatrix(_imageSettings.Sepia); break; case ImageFilters.BlackAndWhite: - atr.SetColorMatrix(_imageSettings.blackAndWhite); + atr.SetColorMatrix(_imageSettings.BlackAndWhite); break; case ImageFilters.Polaroid: - atr.SetColorMatrix(_imageSettings.polaroid); + atr.SetColorMatrix(_imageSettings.Polaroid); break; case ImageFilters.Contour: return ApplySobel(image); case ImageFilters.Brightness: - atr.SetColorMatrix(_imageSettings.brightness); + atr.SetColorMatrix(_imageSettings.Brightness); break; case ImageFilters.Contrast: - atr.SetColorMatrix(_imageSettings.contrast); + atr.SetColorMatrix(_imageSettings.Contrast); break; case ImageFilters.HueShift: - atr.SetColorMatrix(_imageSettings.hueShift); + atr.SetColorMatrix(_imageSettings.HueShift); break; case ImageFilters.ColorBalance: - atr.SetColorMatrix(_imageSettings.colorBalance); + atr.SetColorMatrix(_imageSettings.ColorBalance); break; case ImageFilters.Vintage: - atr.SetColorMatrix(_imageSettings.vintage); + atr.SetColorMatrix(_imageSettings.Vintage); break; // New convolution-based filters case ImageFilters.Sharpen: settings = _imageSettings?.GetSettings(ImageFilters.Sharpen); - return ApplyFilter(image, _imageSettings?.sharpenFilter, settings.Factor, settings.Bias); + return ApplyFilter(image, _imageSettings?.SharpenFilter, settings.Factor, settings.Bias); case ImageFilters.GaussianBlur: settings = _imageSettings?.GetSettings(ImageFilters.GaussianBlur); - return ApplyFilter(image, _imageSettings?.gaussianBlur, settings.Factor, settings.Bias); + return ApplyFilter(image, _imageSettings?.GaussianBlur, settings.Factor, settings.Bias); case ImageFilters.Emboss: settings = _imageSettings?.GetSettings(ImageFilters.Emboss); - return ApplyFilter(image, _imageSettings?.embossFilter, settings.Factor, settings.Bias); + return ApplyFilter(image, _imageSettings?.EmbossFilter, settings.Factor, settings.Bias); case ImageFilters.BoxBlur: settings = _imageSettings?.GetSettings(ImageFilters.BoxBlur); - return ApplyFilter(image, _imageSettings?.boxBlur, settings.Factor, settings.Bias); + return ApplyFilter(image, _imageSettings?.BoxBlur, settings.Factor, settings.Bias); case ImageFilters.Laplacian: settings = _imageSettings?.GetSettings(ImageFilters.Laplacian); - return ApplyFilter(image, _imageSettings?.laplacianFilter, settings.Factor, settings.Bias); + return ApplyFilter(image, _imageSettings?.LaplacianFilter, settings.Factor, settings.Bias); case ImageFilters.EdgeEnhance: settings = _imageSettings?.GetSettings(ImageFilters.EdgeEnhance); - return ApplyFilter(image, _imageSettings?.edgeEnhance, settings.Factor, settings.Bias); + return ApplyFilter(image, _imageSettings?.EdgeEnhance, settings.Factor, settings.Bias); case ImageFilters.MotionBlur: settings = _imageSettings?.GetSettings(ImageFilters.MotionBlur); - return ApplyFilter(image, _imageSettings?.motionBlur, settings.Factor, settings.Bias); + return ApplyFilter(image, _imageSettings?.MotionBlur, settings.Factor, settings.Bias); case ImageFilters.UnsharpMask: settings = _imageSettings?.GetSettings(ImageFilters.UnsharpMask); - return ApplyFilter(image, _imageSettings?.unsharpMask, settings.Factor, settings.Bias); + return ApplyFilter(image, _imageSettings?.UnsharpMask, settings.Factor, settings.Bias); // custom Filter case ImageFilters.DifferenceOfGaussians: return ApplyDifferenceOfGaussians(image); @@ -334,8 +334,8 @@ private static Bitmap ApplySobel(Bitmap originalImage) var pixel = dbmBase.GetPixel(x + i, y + j); int grayValue = pixel.R; // Since it's a greyscale image, R=G=B // Sobel masks for gradient calculation - gx += _imageSettings.sobelX[i + 1, j + 1] * grayValue; - gy += _imageSettings.sobelY[i + 1, j + 1] * grayValue; + gx += _imageSettings.SobelX[i + 1, j + 1] * grayValue; + gy += _imageSettings.SobelY[i + 1, j + 1] * grayValue; } // Calculate gradient magnitude @@ -394,8 +394,8 @@ private static Bitmap ApplyDifferenceOfGaussians(Image image) private static Bitmap ApplyCrosshatch(Image image) { // Apply the 45-degree and 135-degree filters - var hatch45 = ApplyFilter(image, _imageSettings.kernel45Degrees); - var hatch135 = ApplyFilter(image, _imageSettings.kernel135Degrees); + var hatch45 = ApplyFilter(image, _imageSettings.Kernel45Degrees); + var hatch135 = ApplyFilter(image, _imageSettings.Kernel135Degrees); // Combine the two hatching directions return ImageOverlays.AddImages(hatch45, hatch135); @@ -616,8 +616,8 @@ private static void DetermineRegionSizeAndShape(DirectBitmap dbmBase, int x, int out int regionWidth, out int regionHeight) { // Compute gradient magnitude using Sobel operators - var gradientX = ApplyKernel(dbmBase, x, y, _imageSettings.sobelX); - var gradientY = ApplyKernel(dbmBase, x, y, _imageSettings.sobelY); + var gradientX = ApplyKernel(dbmBase, x, y, _imageSettings.SobelX); + var gradientY = ApplyKernel(dbmBase, x, y, _imageSettings.SobelY); var gradientMagnitude = Math.Sqrt(gradientX * gradientX + gradientY * gradientY); // Compute local variance diff --git a/Imaging/ImageMask.cs b/Imaging/ImageMask.cs index cf3207c..854c3d2 100644 --- a/Imaging/ImageMask.cs +++ b/Imaging/ImageMask.cs @@ -11,7 +11,7 @@ namespace Imaging { /// - /// Handle all the possible selections on an Image + /// Handle all the possible selections on an Image /// internal static class ImageMask { diff --git a/Imaging/ImageRegister.cs b/Imaging/ImageRegister.cs index d88bac3..12235b1 100644 --- a/Imaging/ImageRegister.cs +++ b/Imaging/ImageRegister.cs @@ -156,7 +156,7 @@ public sealed class ImageRegister /// Source: /// https://docs.rainmeter.net/tips/colormatrix-guide/ /// - internal readonly ColorMatrix blackAndWhite = new(new[] + internal readonly ColorMatrix BlackAndWhite = new(new[] { new[] { 1.5f, 1.5f, 1.5f, 0, 0 }, new[] { 1.5f, 1.5f, 1.5f, 0, 0 }, new[] { 1.5f, 1.5f, 1.5f, 0, 0 }, new float[] { 0, 0, 0, 1, 0 }, new float[] { -1, -1, -1, 0, 1 } @@ -165,13 +165,13 @@ public sealed class ImageRegister /// /// The box blur /// - internal readonly double[,] boxBlur = { { 1, 1, 1 }, { 1, 1, 1 }, { 1, 1, 1 } }; + internal readonly double[,] BoxBlur = { { 1, 1, 1 }, { 1, 1, 1 }, { 1, 1, 1 } }; /// /// The brightness Filter /// Adjusts the brightness of the image by scaling the color values. /// - internal readonly ColorMatrix brightness = new(new[] + internal readonly ColorMatrix Brightness = new(new[] { new[] { 1.2f, 0, 0, 0, 0 }, new[] { 0, 1.2f, 0, 0, 0 }, new[] { 0, 0, 1.2f, 0, 0 }, new float[] { 0, 0, 0, 1, 0 }, new float[] { 0, 0, 0, 0, 1 } @@ -181,7 +181,7 @@ public sealed class ImageRegister /// The color balance Filter /// Adjusts the balance of colors to emphasize or de-emphasize specific color channels. /// - internal readonly ColorMatrix colorBalance = new(new[] + internal readonly ColorMatrix ColorBalance = new(new[] { new[] { 1f, 0.2f, -0.2f, 0, 0 }, new[] { -0.2f, 1f, 0.2f, 0, 0 }, new[] { 0.2f, -0.2f, 1f, 0, 0 }, new float[] { 0, 0, 0, 1, 0 }, new float[] { 0, 0, 0, 0, 1 } @@ -191,7 +191,7 @@ public sealed class ImageRegister /// The contrast Filter /// Adjusts the contrast of the image by scaling the differences between pixel values. /// - internal readonly ColorMatrix contrast = new(new[] + internal readonly ColorMatrix Contrast = new(new[] { new[] { 1.5f, 0, 0, 0, -0.2f }, new[] { 0, 1.5f, 0, 0, -0.2f }, new[] { 0, 0, 1.5f, 0, -0.2f }, new float[] { 0, 0, 0, 1, 0 }, new float[] { 0, 0, 0, 0, 1 } @@ -200,17 +200,17 @@ public sealed class ImageRegister /// /// The edge enhance /// - internal readonly double[,] edgeEnhance = { { 0, 0, 0 }, { -1, 1, 0 }, { 0, 0, 0 } }; + internal readonly double[,] EdgeEnhance = { { 0, 0, 0 }, { -1, 1, 0 }, { 0, 0, 0 } }; /// /// The emboss filter /// - internal readonly double[,] embossFilter = { { -2, -1, 0 }, { -1, 1, 1 }, { 0, 1, 2 } }; + internal readonly double[,] EmbossFilter = { { -2, -1, 0 }, { -1, 1, 1 }, { 0, 1, 2 } }; /// /// The gaussian blur /// - internal readonly double[,] gaussianBlur = { { 1, 2, 1 }, { 2, 4, 2 }, { 1, 2, 1 } }; + internal readonly double[,] GaussianBlur = { { 1, 2, 1 }, { 2, 4, 2 }, { 1, 2, 1 } }; /// /// the color matrix needed to GrayScale an image @@ -228,7 +228,7 @@ public sealed class ImageRegister /// NewB = (m31* R + m32* G + m33* B + m34* A + m35) /// NewA = (m41* R + m42* G + m43* B + m44* A + m45) /// - internal readonly ColorMatrix grayScale = new(new[] + internal readonly ColorMatrix GrayScale = new(new[] { new[] { .3f, .3f, .3f, 0, 0 }, new[] { .59f, .59f, .59f, 0, 0 }, new[] { .11f, .11f, .11f, 0, 0 }, new float[] { 0, 0, 0, 1, 0 }, new float[] { 0, 0, 0, 0, 1 } @@ -238,7 +238,7 @@ public sealed class ImageRegister /// The hue shift Filter /// Shifts the hue of the image, effectively rotating the color wheel. /// - internal readonly ColorMatrix hueShift = new(new[] + internal readonly ColorMatrix HueShift = new(new[] { new[] { 0.213f, 0.715f, 0.072f, 0, 0 }, new[] { 0.213f, 0.715f, 0.072f, 0, 0 }, new[] { 0.213f, 0.715f, 0.072f, 0, 0 }, new float[] { 0, 0, 0, 1, 0 }, new float[] { 0, 0, 0, 0, 1 } @@ -249,7 +249,7 @@ public sealed class ImageRegister /// Source: /// https://archive.ph/hzR2W /// - internal readonly ColorMatrix invert = new(new[] + internal readonly ColorMatrix Invert = new(new[] { new float[] { -1, 0, 0, 0, 0 }, new float[] { 0, -1, 0, 0, 0 }, new float[] { 0, 0, -1, 0, 0 }, new float[] { 0, 0, 0, 1, 0 }, new float[] { 1, 1, 1, 0, 1 } @@ -259,23 +259,23 @@ public sealed class ImageRegister /// The kernel 135 degrees /// Defines directional edge detection kernel for crosshatching /// - internal readonly double[,] kernel135Degrees = { { 2, -1, -1 }, { -1, 2, -1 }, { -1, -1, 2 } }; + internal readonly double[,] Kernel135Degrees = { { 2, -1, -1 }, { -1, 2, -1 }, { -1, -1, 2 } }; /// /// The kernel 45 degrees /// Defines directional edge detection kernel for crosshatching /// - internal readonly double[,] kernel45Degrees = { { -1, -1, 2 }, { -1, 2, -1 }, { 2, -1, -1 } }; + internal readonly double[,] Kernel45Degrees = { { -1, -1, 2 }, { -1, 2, -1 }, { 2, -1, -1 } }; /// /// The laplacian filter /// - internal readonly double[,] laplacianFilter = { { 0, -1, 0 }, { -1, 4, -1 }, { 0, -1, 0 } }; + internal readonly double[,] LaplacianFilter = { { 0, -1, 0 }, { -1, 4, -1 }, { 0, -1, 0 } }; /// /// The motion blur /// - internal readonly double[,] motionBlur = + internal readonly double[,] MotionBlur = { { 1, 0, 0, 0, 0 }, { 0, 1, 0, 0, 0 }, { 0, 0, 1, 0, 0 }, { 0, 0, 0, 1, 0 }, { 0, 0, 0, 0, 1 } }; @@ -285,7 +285,7 @@ public sealed class ImageRegister /// Source: /// https://docs.rainmeter.net/tips/colormatrix-guide/ /// - internal readonly ColorMatrix polaroid = new(new[] + internal readonly ColorMatrix Polaroid = new(new[] { new[] { 1.438f, -0.062f, -0.062f, 0, 0 }, new[] { -0.122f, 1.378f, -0.122f, 0, 0 }, new[] { 0.016f, -0.016f, 1.483f, 0, 0 }, new float[] { 0, 0, 0, 1, 0 }, @@ -297,7 +297,7 @@ public sealed class ImageRegister /// Source: /// https://archive.ph/hzR2W /// - internal readonly ColorMatrix sepia = new(new[] + internal readonly ColorMatrix Sepia = new(new[] { new[] { .393f, .349f, .272f, 0, 0 }, new[] { .769f, .686f, .534f, 0, 0 }, new[] { 0.189f, 0.168f, 0.131f, 0, 0 }, new float[] { 0, 0, 0, 1, 0 }, new float[] { 0, 0, 0, 0, 1 } @@ -306,29 +306,29 @@ public sealed class ImageRegister /// /// The sharpen filter /// - internal readonly double[,] sharpenFilter = { { 0, -1, 0 }, { -1, 5, -1 }, { 0, -1, 0 } }; + internal readonly double[,] SharpenFilter = { { 0, -1, 0 }, { -1, 5, -1 }, { 0, -1, 0 } }; /// /// The sobel x kernel /// - internal readonly int[,] sobelX = { { -1, 0, 1 }, { -2, 0, 2 }, { -1, 0, 1 } }; + internal readonly int[,] SobelX = { { -1, 0, 1 }, { -2, 0, 2 }, { -1, 0, 1 } }; /// /// The sobel y kernel /// - internal readonly int[,] sobelY = { { -1, -2, -1 }, { 0, 0, 0 }, { 1, 2, 1 } }; + internal readonly int[,] SobelY = { { -1, -2, -1 }, { 0, 0, 0 }, { 1, 2, 1 } }; /// /// The unsharp mask /// - internal readonly double[,] unsharpMask = { { -1, -1, -1 }, { -1, 9, -1 }, { -1, -1, -1 } }; + internal readonly double[,] UnsharpMask = { { -1, -1, -1 }, { -1, 9, -1 }, { -1, -1, -1 } }; /// /// The vintage Filter /// Applies a vintage effect by modifying the color matrix to mimic old photo tones. /// - internal readonly ColorMatrix vintage = new(new[] + internal readonly ColorMatrix Vintage = new(new[] { new[] { 0.393f, 0.349f, 0.272f, 0, 0 }, new[] { 0.769f, 0.686f, 0.534f, 0, 0 }, new[] { 0.189f, 0.168f, 0.131f, 0, 0 }, new float[] { 0, 0, 0, 1, 0 }, new float[] { 0, 0, 0, 0, 1 } diff --git a/Imaging/ImageRender.cs b/Imaging/ImageRender.cs index 48042aa..fcdc44b 100644 --- a/Imaging/ImageRender.cs +++ b/Imaging/ImageRender.cs @@ -180,7 +180,7 @@ public Bitmap CutBitmap(Bitmap image, int x, int y, int height, int width) /// /// - /// Cuts the bitmap. + /// Cuts the bitmap. /// /// The image. /// The width. @@ -190,9 +190,10 @@ public Bitmap CutBitmap(Bitmap image, int x, int y, int height, int width) /// The start point. /// The selected Image area. /// shape - null - public Bitmap CutBitmap(Bitmap image, int width, int height, MaskShape shape, object shapeParams = null, Point? startPoint = null) + public Bitmap CutBitmap(Bitmap image, int width, int height, MaskShape shape, object shapeParams = null, + Point? startPoint = null) { - var btm= ImageStream.CutBitmap(image, 0, 0, image.Height, image.Width); + var btm = ImageStream.CutBitmap(image, 0, 0, image.Height, image.Width); // If no start point is provided, default to (0, 0) var actualStartPoint = startPoint ?? new Point(0, 0); diff --git a/SlimViewer/MainWindow.xaml b/SlimViewer/MainWindow.xaml index 0214261..56206ff 100644 --- a/SlimViewer/MainWindow.xaml +++ b/SlimViewer/MainWindow.xaml @@ -245,7 +245,7 @@ diff --git a/SlimViews/FillTypeVisibilityConverter .cs b/SlimViews/FillTypeVisibilityConverter .cs index ec2dbc6..7318c48 100644 --- a/SlimViews/FillTypeVisibilityConverter .cs +++ b/SlimViews/FillTypeVisibilityConverter .cs @@ -10,7 +10,6 @@ public class FillTypeVisibilityConverter : IValueConverter public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value is int selectedIndex && parameter is string targetFillType) - { switch (targetFillType) { case "SolidColor": @@ -20,7 +19,6 @@ public object Convert(object value, Type targetType, object parameter, CultureIn case "Filter": return selectedIndex == 2 ? Visibility.Visible : Visibility.Collapsed; } - } return Visibility.Collapsed; } diff --git a/SlimViews/FilterConfigView.cs b/SlimViews/FilterConfigView.cs index 418fdfe..454f968 100644 --- a/SlimViews/FilterConfigView.cs +++ b/SlimViews/FilterConfigView.cs @@ -41,7 +41,7 @@ public sealed class FilterConfigView : INotifyPropertyChanged /// /// The current configuration /// - private ImageFilterConfig _currentConfig; + private readonly ImageFilterConfig _currentConfig; /// /// The factor diff --git a/SlimViews/Templates/SelectionToVisibilityConverter .cs b/SlimViews/Templates/SelectionToVisibilityConverter .cs index b8bc332..5d69509 100644 --- a/SlimViews/Templates/SelectionToVisibilityConverter .cs +++ b/SlimViews/Templates/SelectionToVisibilityConverter .cs @@ -15,20 +15,20 @@ namespace SlimViews.Templates { /// /// - /// Handles Visibility of the Tool Combobox + /// Handles Visibility of the Tool Combobox /// /// public sealed class SelectionToVisibilityConverter : IValueConverter { /// - /// Converts a value. + /// Converts a value. /// /// The value produced by the binding source. /// The type of the binding target property. /// The converter parameter to use. /// The culture to use in the converter. /// - /// A converted value. If the method returns , the valid null value is used. + /// A converted value. If the method returns , the valid null value is used. /// public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { @@ -36,14 +36,14 @@ public object Convert(object value, Type targetType, object parameter, CultureIn } /// - /// Converts a value. + /// Converts a value. /// /// The value that is produced by the binding target. /// The type to convert to. /// The converter parameter to use. /// The culture to use in the converter. /// - /// A converted value. If the method returns , the valid null value is used. + /// A converted value. If the method returns , the valid null value is used. /// /// public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) diff --git a/SlimViews/Templates/ToolOptionsTemplateSelector.cs b/SlimViews/Templates/ToolOptionsTemplateSelector.cs index 9a0d4a4..e0647fe 100644 --- a/SlimViews/Templates/ToolOptionsTemplateSelector.cs +++ b/SlimViews/Templates/ToolOptionsTemplateSelector.cs @@ -27,10 +27,10 @@ public sealed class ToolOptionsTemplateSelector : DataTemplateSelector public DataTemplate PaintToolTemplate { get; set; } /// - /// Gets or sets the erase tool options. + /// Gets or sets the erase tool options. /// /// - /// The erase tool options. + /// The erase tool options. /// public DataTemplate EraseToolTemplate { get; set; } diff --git a/SlimViews/Templates/ToolOptionsTemplates.xaml b/SlimViews/Templates/ToolOptionsTemplates.xaml index af598c5..c8609dd 100644 --- a/SlimViews/Templates/ToolOptionsTemplates.xaml +++ b/SlimViews/Templates/ToolOptionsTemplates.xaml @@ -5,25 +5,25 @@ xmlns:templates="clr-namespace:SlimViews.Templates"> - + - - - - + + + + - - + + - @@ -35,18 +35,18 @@ - - - - + + + + - - + + - @@ -58,17 +58,17 @@ - - - + + + - - + + - @@ -80,23 +80,23 @@ - - - - - - + + + + + + - - + + -