-
Notifications
You must be signed in to change notification settings - Fork 0
/
2xsai.cpp
146 lines (128 loc) · 4 KB
/
2xsai.cpp
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include "includes/FilterCommon.h"
#include "includes/Interpolate.h"
#include "includes/Interpolate4.h"
#include "includes/kreed.h"
extern "C"
{
static unsigned char* ScaledImage = NULL;
const int FilterID = 0x5D07;
const char* FilterName = "2XSaI";
const char* FilterDescription = "Derek Liauw Kie Fa's 2XSaI";
bool ComparisonThreshold = false;
const int FilterScaleX = 2;
const int FilterScaleY = 2;
#include "includes/Init.h"
void Apply(int argc, void** argv)
{
if (argc >= 3)
{
auto Input = ((unsigned char*)(argv[0]));
auto srcx = *((int*)(argv[1]));
auto srcy = *((int*)(argv[2]));
Init(srcx, srcy);
for (auto y = 0; y < srcy; y++)
{
for (auto x = 0; x < srcx; x++)
{
auto c0 = CLR(Input, srcx, srcy, x, y, -1, -1);
auto c1 = CLR(Input, srcx, srcy, x, y, 0, -1);
auto c2 = CLR(Input, srcx, srcy, x, y, 1, -1);
auto d3 = CLR(Input, srcx, srcy, x, y, 2, -1);
auto c3 = CLR(Input, srcx, srcy, x, y, -1, 0);
auto c4 = CLR(Input, srcx, srcy, x, y);
auto c5 = CLR(Input, srcx, srcy, x, y, 1, 0);
auto d4 = CLR(Input, srcx, srcy, x, y, 2, 0);
auto c6 = CLR(Input, srcx, srcy, x, y, -1, 1);
auto c7 = CLR(Input, srcx, srcy, x, y, 0, 1);
auto c8 = CLR(Input, srcx, srcy, x, y, 1, 1);
auto d5 = CLR(Input, srcx, srcy, x, y, 2, 1);
auto d0 = CLR(Input, srcx, srcy, x, y, -1, 2);
auto d1 = CLR(Input, srcx, srcy, x, y, 0, 2);
auto d2 = CLR(Input, srcx, srcy, x, y, 1, 2);
int P[5];
P[1] = P[2] = P[3] = P[4] = c4;
if (IsLike(c4, c8) && IsNotLike(c5, c7)) {
auto c48 = Interpolate(c4, c8);
if ((IsLike(c48, c1) && IsLike(c5, d5)) || (IsLike(c48, c7) && IsLike(c48, c2) && IsNotLike(c5, c1) && IsLike(c5, d3))) {
//nothing
}
else {
P[2] = Interpolate(c48, c5);
}
if ((IsLike(c48, c3) && IsLike(c7, d2)) || (IsLike(c48, c5) && IsLike(c48, c6) && IsNotLike(c3, c7) && IsLike(c7, d0))) {
//nothing
}
else {
P[3] = Interpolate(c48, c7);
}
}
else if (IsLike(c5, c7) && IsNotLike(c4, c8)) {
auto c57 = Interpolate(c5, c7);
if ((IsLike(c57, c2) && IsLike(c4, c6)) || (IsLike(c57, c1) && IsLike(c57, c8) && IsNotLike(c4, c2) && IsLike(c4, c0))) {
P[2] = c57;
}
else {
P[2] = Interpolate(c4, c57);
}
if ((IsLike(c57, c6) && IsLike(c4, c2)) || (IsLike(c57, c3) && IsLike(c57, c8) && IsNotLike(c4, c6) && IsLike(c4, c0))) {
P[3] = c57;
}
else {
P[3] = Interpolate(c4, c57);
}
P[4] = c57;
}
else if (IsLike(c4, c8) && IsLike(c5, c7)) {
auto c48 = Interpolate(c4, c8);
auto c57 = Interpolate(c5, c7);
if (IsNotLike(c48, c57)) {
auto conc2D = 0;
conc2D += _Conc2D(c48, c57, c3, c1);
conc2D -= _Conc2D(c57, c48, d4, c2);
conc2D -= _Conc2D(c57, c48, c6, d1);
conc2D += _Conc2D(c48, c57, d5, d2);
if (conc2D < 0) {
P[4] = c57;
}
else if (conc2D == 0) {
P[4] = Interpolate(c48, c57);
}
P[3] = Interpolate(c48, c57);
P[2] = Interpolate(c48, c57);
}
}
else {
P[4] = Interpolate4(c4, c5, c7, c8);
if (IsLike(c4, c7) && IsLike(c4, c2) && IsNotLike(c5, c1) && IsLike(c5, d3)) {
//nothing
}
else if (IsLike(c5, c1) && IsLike(c5, c8) && IsNotLike(c4, c2) && IsLike(c4, c0)) {
P[2] = Interpolate(c5, c1, c8);
}
else {
P[2] = Interpolate(c4, c5);
}
if (IsLike(c4, c5) && IsLike(c4, c6) && IsNotLike(c3, c7) && IsLike(c7, d0)) {
//nothing
}
else if (IsLike(c7, c3) && IsLike(c7, c8) && IsNotLike(c4, c6) && IsLike(c4, c0)) {
P[3] = Interpolate(c7, c3, c8);
}
else {
P[3] = Interpolate(c4, c7);
}
}
for (auto Pixel = 1; Pixel < 5; Pixel++)
{
Write4RGB(ScaledImage, srcx, srcy, x, y, Pixel, P[Pixel]);
}
}
}
}
}
}