forked from rodrigomas/DCTLs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Mean_7x7.dctl
36 lines (27 loc) · 975 Bytes
/
Mean_7x7.dctl
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
// Mean 7x7
__DEVICE__ float mean(float p_Table[], int m) {
float temp = 0.0f;
for(int i = 0; i < m; ++i) {
temp += p_Table[i]; }
return (temp / m);
}
__DEVICE__ float3 transform(int p_Width, int p_Height, int p_X, int p_Y, __TEXTURE__ p_TexR, __TEXTURE__ p_TexG, __TEXTURE__ p_TexB)
{
// Enter length for sample area e.g. 3 for 3x3, 5 for 5x5, 7 for 7x7, etc.
int length = 7;
int area = length * length;
float colRGB[3];
float TableR[area], TableG[area], TableB[area];
for (int i = 0; i < area; ++i) {
int offset = (length - 1) / 2;
int xx = (i >= length ? _fmod(i, length/1.0f) : i) - offset;
int yy = _floor(i / (length/1.0f)) - offset;
TableR[i] = _tex2D(p_TexR, p_X + xx, p_Y + yy);
TableG[i] = _tex2D(p_TexG, p_X + xx, p_Y + yy);
TableB[i] = _tex2D(p_TexB, p_X + xx, p_Y + yy);
}
for (int c = 0; c < 3; ++c) {
colRGB[c] = c == 0 ? mean(TableR, area) : c == 1 ? mean(TableG, area) : mean(TableB, area);
}
return make_float3(colRGB[0], colRGB[1], colRGB[2]);
}