forked from vchukanov/cppimagefilterbase
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbwFilter.cpp
More file actions
33 lines (32 loc) · 812 Bytes
/
bwFilter.cpp
File metadata and controls
33 lines (32 loc) · 812 Bytes
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
29
30
31
32
33
#include "bwFilter.h"
void bwFilter::applyFilter(image_data imgData) {
int x;
int newCoord[4];
if (u != 0)
newCoord[0] = imgData.h / u;
else
newCoord[0] = 0;
if (l != 0)
newCoord[1] = imgData.w / l;
else
newCoord[1] = 0;
if (b != 0)
newCoord[2] = imgData.h / b;
else
newCoord[2] = 0;
if (r != 0)
newCoord[3] = imgData.w / r;
else
newCoord[3] = 0;
for (int i = newCoord[0]; i < newCoord[2]; i++)
{
for (int j = newCoord[1]; j < newCoord[3]; j++)
{
int pos = (i * imgData.w + j) * imgData.compPerPixel;
x = (3 * imgData.pixels[pos] + 6 * imgData.pixels[pos + 1] + imgData.pixels[pos + 2]) / 10;
imgData.pixels[pos] = (unsigned char)x;
imgData.pixels[pos + 1] = (unsigned char)x;
imgData.pixels[pos + 2] = (unsigned char)x;
}
}
}