Skip to content
This repository was archived by the owner on Sep 21, 2023. It is now read-only.

Commit 8cd8331

Browse files
committed
Finalize initial requirements
1 parent f9f1894 commit 8cd8331

File tree

8 files changed

+311
-108
lines changed

8 files changed

+311
-108
lines changed

winforms-image-processor/winforms-image-processor/Filters/Constants.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ static class Constants
1212

1313
public static double filterBrightnessValue = 10;
1414

15-
public static double filterContrastValue = 10
15+
public static double filterContrastValue = 10;
1616
}
1717
}

winforms-image-processor/winforms-image-processor/Filters/FilterManager.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ static public byte[] Contrast(byte[] buffer)
114114

115115
static public byte[] ApplyKernel(byte[] buffer, int stride, CustomKernel customKernel)
116116
{
117-
double[,] kernel = customKernel.kernel;
117+
double[,] kernel = customKernel.GetKernel();
118118
byte[] result = new byte[buffer.Length];
119119

120120
// 1D Bitmap byte data
@@ -130,7 +130,9 @@ static public byte[] ApplyKernel(byte[] buffer, int stride, CustomKernel customK
130130
bool ignorePixel = false;
131131

132132
// Kernel Columns
133-
for (int j = -kernel.GetLength(0) / 2; j <= kernel.GetLength(0) / 2; j++)
133+
int lowerColBound = -kernel.GetLength(0) / 2 - customKernel.anchor.X;
134+
int upperColBound = kernel.GetLength(0) / 2 - customKernel.anchor.X;
135+
for (int j = lowerColBound; j <= upperColBound; j++)
134136
{
135137
if ((i + 4 * j < 0) || (i + 4 * j >= buffer.Length) || ignorePixel)
136138
{
@@ -139,7 +141,9 @@ static public byte[] ApplyKernel(byte[] buffer, int stride, CustomKernel customK
139141
}
140142

141143
// Kernel Rows
142-
for (int k = -kernel.GetLength(1) / 2; k <= kernel.GetLength(1) / 2; k++)
144+
int lowerRowBound = -kernel.GetLength(1) / 2 - customKernel.anchor.Y;
145+
int upperRowBound = kernel.GetLength(1) / 2 - customKernel.anchor.Y;
146+
for (int k = lowerRowBound; k <= upperRowBound; k++)
143147
{
144148
if ((i + 4 * j + k * stride < 0) || (i + 4 * j + k * stride >= buffer.Length))
145149
{
@@ -148,8 +152,8 @@ static public byte[] ApplyKernel(byte[] buffer, int stride, CustomKernel customK
148152
}
149153

150154
newByte += kernel[
151-
j + kernel.GetLength(0) / 2,
152-
k + kernel.GetLength(1) / 2]
155+
j - lowerColBound,
156+
k - lowerRowBound]
153157
* buffer[i + 4 * j + k * stride]
154158
+ customKernel.offset;
155159
}
Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
1+
using System.Diagnostics;
2+
using System.Drawing;
43
using System.Text;
5-
using System.Threading.Tasks;
64

75
namespace winforms_image_processor
86
{
@@ -12,14 +10,16 @@ public struct CustomKernel
1210
public int divisor;
1311

1412
public int offset;
15-
public int anchor;
13+
public Point anchor;
1614

17-
public CustomKernel(double[,] kernel, int div, int off, int anch)
15+
public CustomKernel(double[,] kernel, int div, int off, Point anch)
1816
{
1917
this.kernel = kernel;
2018
divisor = div;
2119
offset = off;
2220
anchor = anch;
21+
22+
Debug.Print(this.ToString());
2323
}
2424

2525
public double[,] GetKernel()
@@ -30,17 +30,34 @@ public CustomKernel(double[,] kernel, int div, int off, int anch)
3030
kernelCopy[i, j] = kernel[i, j] / divisor;
3131
return kernelCopy;
3232
}
33+
34+
public override string ToString()
35+
{
36+
StringBuilder sb = new StringBuilder("Kernel with following values:\n");
37+
foreach (int i in kernel)
38+
{
39+
sb.Append(i);
40+
sb.Append(", ");
41+
}
42+
sb.Append("\n");
43+
sb.Append(divisor);
44+
sb.Append("\n");
45+
sb.Append(offset);
46+
sb.Append("\n");
47+
sb.Append(anchor.ToString());
48+
return sb.ToString();
49+
}
3350
}
3451

3552
public static class Kernel
3653
{
37-
public static CustomKernel customKernel = new CustomKernel(new double[3, 3] { { 0, 0, 0 }, { 0, 1, 0 }, { 0, 0, 0 } }, 1, 0, 4);
54+
public static CustomKernel customKernel = new CustomKernel(new double[3, 3] { { 0, 0, 0 }, { 0, 1, 0 }, { 0, 0, 0 } }, 1, 0, Point.Empty);
3855

39-
public static CustomKernel SharpenKernel = new CustomKernel(new double[3, 3] { { 0, -1, 0 }, { -1, 5, -1 }, { 0, -1, 0 } }, 1, 0, 4);
40-
public static CustomKernel OutlineKernel = new CustomKernel(new double[3, 3] { { -1, -1, -1 }, { -1, 8, -1 }, { -1, -1, -1 } }, 1, 0, 4);
41-
public static CustomKernel EmbossKernel = new CustomKernel(new double[3, 3] { { -2, -1, 0 }, { -1, 1, 1 }, { 0, 1, 2 } }, 1, 0, 4);
42-
public static CustomKernel BoxBlurKernel = new CustomKernel(new double[3, 3] { { 1, 1, 1 }, { 1, 1, 1 }, { 1, 1, 1 } }, 9, 0, 4);
43-
public static CustomKernel GaussianBlurKernel = new CustomKernel(new double[3, 3] { { 1, 2, 1 }, { 2, 4, 2 }, { 1, 2, 1 } }, 16, 0, 4);
56+
public static CustomKernel SharpenKernel = new CustomKernel(new double[3, 3] { { 0, -1, 0 }, { -1, 5, -1 }, { 0, -1, 0 } }, 1, 0, Point.Empty);
57+
public static CustomKernel OutlineKernel = new CustomKernel(new double[3, 3] { { -1, -1, -1 }, { -1, 8, -1 }, { -1, -1, -1 } }, 1, 0, Point.Empty);
58+
public static CustomKernel EmbossKernel = new CustomKernel(new double[3, 3] { { -2, -1, 0 }, { -1, 1, 1 }, { 0, 1, 2 } }, 1, 0, Point.Empty);
59+
public static CustomKernel BoxBlurKernel = new CustomKernel(new double[3, 3] { { 1, 1, 1 }, { 1, 1, 1 }, { 1, 1, 1 } }, 9, 0, Point.Empty);
60+
public static CustomKernel GaussianBlurKernel = new CustomKernel(new double[3, 3] { { 1, 2, 1 }, { 2, 4, 2 }, { 1, 2, 1 } }, 16, 0, Point.Empty);
4461

4562
}
4663
}

winforms-image-processor/winforms-image-processor/Form/ImageProcessorForm.Designer.cs

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

winforms-image-processor/winforms-image-processor/Form/ImageProcessorForm.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ public ImageProcessorForm()
2424
subItem.CheckOnClick = true;
2525
filtersToolStripMenuItem.DropDownItems.Add(subItem);
2626
}
27+
28+
FltPictureBox.ContextMenuStrip = contextMenuStrip1;
2729
}
2830

2931
private void StateChange(object sender, EventArgs e)
@@ -106,5 +108,10 @@ private void customKernelToolStripMenuItem_Click(object sender, EventArgs e)
106108

107109
FltPictureBox.Image = CacheManager.GetBitmapForFilterState();
108110
}
111+
112+
private void copyToolStripMenuItem_Click(object sender, EventArgs e)
113+
{
114+
Clipboard.SetImage(FltPictureBox.Image);
115+
}
109116
}
110117
}

winforms-image-processor/winforms-image-processor/Form/ImageProcessorForm.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,7 @@
120120
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
121121
<value>17, 17</value>
122122
</metadata>
123+
<metadata name="contextMenuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
124+
<value>132, 17</value>
125+
</metadata>
123126
</root>

0 commit comments

Comments
 (0)