-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAntiAliasing.h
75 lines (63 loc) · 1.88 KB
/
AntiAliasing.h
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#pragma once
#include "gz.h"
#include "disp.h"
#include "rend.h"
#include "help.h"
class AntiAliasing
{
public:
void setFilters(AAFilter filters[]) {
memcpy(this->filters, filters, AAKERNEL_SIZE * 3 * sizeof(filters[0][0]));
GzCoord tx;
for (int i = 0; i < AAKERNEL_SIZE; i++) {
tx[0] = filters[i][0];
tx[1] = filters[i][1];
tx[2] = 0;
GzTrxMat(tx, filterTx[i]);
}
}
GzDisplay* getBuffer(int index) {
return samples[index];
}
GzMatrix* getTxMat(int index) {
return &filterTx[index];
}
void setOutput(GzDisplay *display) {
short scolor[3];
for(int i=0;i<display->xres;i++)
for (int j = 0; j < display->yres; j++) {
weightSum(i, j, scolor);
putBuffer(display, i, j, scolor);
}
}
AntiAliasing(GzDisplay* display);
~AntiAliasing();
private:
void weightSum(int i, int j, short scolor[]) {
GzColor color = {0.f, 0.f, 0.f};
/*for (int k = 1; k < 2; k++) {
GzDisplay *display = samples[k];
color[BLUE] += (float)((display->fbuf + ARRAY(i, j))->blue);
color[RED] += (float)((display->fbuf + ARRAY(i, j))->red);
color[GREEN] += (float)((display->fbuf + ARRAY(i, j))->green);
}*/
for (int k = 0; k < AAKERNEL_SIZE; k++) {
GzDisplay *display = samples[k];
color[BLUE] += (float)((display->fbuf + ARRAY(i, j))->blue)*filters[k][2];
color[RED] += (float)((display->fbuf + ARRAY(i, j))->red)*filters[k][2];
color[GREEN] += (float)((display->fbuf + ARRAY(i, j))->green)*filters[k][2];
}
for (int c = 0; c < 3; c++) {
scolor[c] = (short)color[c];
clampVal<short>(&scolor[c], 0, MAXRGBA);
}
}
void putBuffer(GzDisplay *display, int i, int j, short color[]) {
(display->fbuf + ARRAY(i, j))->blue = color[BLUE];
(display->fbuf + ARRAY(i, j))->green = color[GREEN];
(display->fbuf + ARRAY(i, j))->red = color[RED];
}
GzMatrix filterTx[AAKERNEL_SIZE];
GzDisplay *samples[AAKERNEL_SIZE];
AAFilter filters[AAKERNEL_SIZE];
};