-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGLuFilter.cpp
More file actions
44 lines (37 loc) · 1.1 KB
/
GLuFilter.cpp
File metadata and controls
44 lines (37 loc) · 1.1 KB
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
34
35
36
37
38
39
40
41
42
43
44
//
// GLuFilter.cpp
//
// Implementation of the GLuFilter
//
#include "GLuFilter.h"
#include <cmath>
#include "impressionistDoc.h"
GLuFilter::GLuFilter(float* matrix, int width, int height)
{
this->matrix = new float[width * height];
for (int i = 0; i < width*height; i++)
{
this->matrix[i] = matrix[i];
}
filterWidth = width;
filterHeight = height;
}
float GLuFilter::filterPixel(ImpressionistDoc* doc, int rgbOffset, Point origin, int sourceWidth, int sourceHeight)
{
int centerX = origin.x - (filterWidth / 2);
int centerY = origin.y - (filterHeight / 2);
float filteredValue = 0;
for (int i = 0; i < filterWidth; i++)
{
for (int j = 0; j < filterHeight; j++)
{
// Clamp the pixel matrix inbound
int x = (centerX + i < sourceWidth) ? abs(centerX + i) : 2 * (sourceWidth - 1) - (centerX + i);
int y = (centerY + j < sourceHeight) ? abs(centerY + j) : 2 * (sourceHeight - 1) - (centerY + j);
// Get index for 1D array
int filterPosition = j * filterWidth + i;
filteredValue += float(doc->GetOriginalPixel(x, y)[rgbOffset] * this->matrix[filterPosition]);
}
}
return filteredValue;
}