Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
LoneWandererProductions committed Nov 10, 2024
1 parent 3aa346a commit 3f0645b
Show file tree
Hide file tree
Showing 12 changed files with 103 additions and 100 deletions.
1 change: 1 addition & 0 deletions Imaging/ColorHsv.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
4 changes: 2 additions & 2 deletions Imaging/IImageRender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ internal interface IImageRender
Bitmap CutBitmap(Bitmap image, int x, int y, int height, int width);

/// <summary>
/// Cuts the bitmap.
/// Cuts the bitmap.
/// </summary>
/// <param name="image">The image.</param>
/// <param name="width">The width.</param>
Expand All @@ -137,7 +137,7 @@ internal interface IImageRender
/// <param name="shapeParams">The shape parameters.</param>
/// <param name="startPoint">The start point.</param>
/// <returns>
/// The cut Image, based on the shape
/// The cut Image, based on the shape
/// </returns>
/// <exception cref="ArgumentNullException"></exception>
Bitmap CutBitmap(Bitmap image, int width, int height, MaskShape shape, object shapeParams = null,
Expand Down
48 changes: 24 additions & 24 deletions Imaging/ImageFilterStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Imaging/ImageMask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace Imaging
{
/// <summary>
/// Handle all the possible selections on an Image
/// Handle all the possible selections on an Image
/// </summary>
internal static class ImageMask
{
Expand Down
44 changes: 22 additions & 22 deletions Imaging/ImageRegister.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public sealed class ImageRegister
/// Source:
/// https://docs.rainmeter.net/tips/colormatrix-guide/
/// </summary>
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 }
Expand All @@ -165,13 +165,13 @@ public sealed class ImageRegister
/// <summary>
/// The box blur
/// </summary>
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 } };

/// <summary>
/// The brightness Filter
/// Adjusts the brightness of the image by scaling the color values.
/// </summary>
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 }
Expand All @@ -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.
/// </summary>
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 }
Expand All @@ -191,7 +191,7 @@ public sealed class ImageRegister
/// The contrast Filter
/// Adjusts the contrast of the image by scaling the differences between pixel values.
/// </summary>
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 }
Expand All @@ -200,17 +200,17 @@ public sealed class ImageRegister
/// <summary>
/// The edge enhance
/// </summary>
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 } };

/// <summary>
/// The emboss filter
/// </summary>
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 } };

/// <summary>
/// The gaussian blur
/// </summary>
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 } };

/// <summary>
/// the color matrix needed to GrayScale an image
Expand All @@ -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)
/// </summary>
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 }
Expand All @@ -238,7 +238,7 @@ public sealed class ImageRegister
/// The hue shift Filter
/// Shifts the hue of the image, effectively rotating the color wheel.
/// </summary>
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 }
Expand All @@ -249,7 +249,7 @@ public sealed class ImageRegister
/// Source:
/// https://archive.ph/hzR2W
/// </summary>
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 }
Expand All @@ -259,23 +259,23 @@ public sealed class ImageRegister
/// The kernel 135 degrees
/// Defines directional edge detection kernel for crosshatching
/// </summary>
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 } };

/// <summary>
/// The kernel 45 degrees
/// Defines directional edge detection kernel for crosshatching
/// </summary>
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 } };

/// <summary>
/// The laplacian filter
/// </summary>
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 } };

/// <summary>
/// The motion blur
/// </summary>
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 }
};
Expand All @@ -285,7 +285,7 @@ public sealed class ImageRegister
/// Source:
/// https://docs.rainmeter.net/tips/colormatrix-guide/
/// </summary>
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 },
Expand All @@ -297,7 +297,7 @@ public sealed class ImageRegister
/// Source:
/// https://archive.ph/hzR2W
/// </summary>
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 }
Expand All @@ -306,29 +306,29 @@ public sealed class ImageRegister
/// <summary>
/// The sharpen filter
/// </summary>
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 } };


/// <summary>
/// The sobel x kernel
/// </summary>
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 } };

/// <summary>
/// The sobel y kernel
/// </summary>
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 } };

/// <summary>
/// The unsharp mask
/// </summary>
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 } };

/// <summary>
/// The vintage Filter
/// Applies a vintage effect by modifying the color matrix to mimic old photo tones.
/// </summary>
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 }
Expand Down
7 changes: 4 additions & 3 deletions Imaging/ImageRender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public Bitmap CutBitmap(Bitmap image, int x, int y, int height, int width)

/// <inheritdoc />
/// <summary>
/// Cuts the bitmap.
/// Cuts the bitmap.
/// </summary>
/// <param name="image">The image.</param>
/// <param name="width">The width.</param>
Expand All @@ -190,9 +190,10 @@ public Bitmap CutBitmap(Bitmap image, int x, int y, int height, int width)
/// <param name="startPoint">The start point.</param>
/// <returns>The selected Image area.</returns>
/// <exception cref="T:System.ArgumentOutOfRangeException">shape - null</exception>
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);
Expand Down
2 changes: 1 addition & 1 deletion SlimViewer/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@
<commonControls:ColorPickerMenu x:Name="ColorPick" Grid.Row="0" Grid.Column="9" HorizontalAlignment="Left"
ColorChangedCommand="{Binding ColorChangedCommand}" />
<ContentControl Grid.Row="0" Grid.Column="8" Content="{Binding SelectedTool}"
ContentTemplateSelector="{DynamicResource ToolOptionsTemplateSelector}"
ContentTemplateSelector="{DynamicResource ToolOptionsTemplateSelector}"
Grid.RowSpan="4" />
<Slider Minimum="0.1" Maximum="5.0" Value="{Binding ZoomScale, ElementName=ImageZoom, Mode=TwoWay}"
Grid.Row="2" Grid.Column="2" IsEnabled="{Binding Path =IsActive}" />
Expand Down
2 changes: 0 additions & 2 deletions SlimViews/FillTypeVisibilityConverter .cs
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand All @@ -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;
}
Expand Down
Loading

0 comments on commit 3f0645b

Please sign in to comment.