-
Notifications
You must be signed in to change notification settings - Fork 0
/
Filter.cs
28 lines (23 loc) · 954 Bytes
/
Filter.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
using System.ComponentModel;
using System.Drawing;
namespace OpenGLDemo
{
internal abstract class Filter
{
public abstract Color calculateNewPixelColor(Bitmap sourceImage, int x, int y);
public virtual Bitmap processImage(Bitmap sourceImage, BackgroundWorker worker)
{
Bitmap resultImage = new Bitmap(sourceImage.Width, sourceImage.Height);
for (int i = 0; i < sourceImage.Width; i++)
{
worker.ReportProgress((int)((float)i / sourceImage.Width * 100));
if (worker.CancellationPending)
return null;
for (int j = 0; j < sourceImage.Height; j++)
resultImage.SetPixel(i, j, calculateNewPixelColor(sourceImage, i, j));
}
return resultImage;
}
public int Clamp(int value, int min, int max) { return value < min ? min : value > max ? max : value; }
}
}