-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdes2x.cpp
70 lines (57 loc) · 1.82 KB
/
des2x.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
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include "includes/FilterCommon.h"
#include "includes/Interpolate.h"
extern "C"
{
static unsigned char* ScaledImage = NULL;
const int FilterID = 0x5D17;
const char* FilterName = "DES 2X";
const char* FilterDescription = "FNES' DES2 filter";
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);
int P[5];
for (auto y = 0; y < srcy; y++)
{
for (auto x = 0; x < srcx; x++)
{
auto n = CLR(Input, srcx, srcy, x, y, 0, -1);
auto w = CLR(Input, srcx, srcy, x, y, -1, 0);
auto c = CLR(Input, srcx, srcy, x, y, 0, 0);
auto e = CLR(Input, srcx, srcy, x, y, 1, 0);
auto s = CLR(Input, srcx, srcy, x, y, 0, 1);
auto se = CLR(Input, srcx, srcy, x, y, 1, 1);
auto d1 = (((IsLike(w, n)) && (IsNotLike(n, e)) && (IsNotLike(w, s))) ? w : c);
auto d2 = (((IsLike(n, e)) && (IsNotLike(n, w)) && (IsNotLike(e, s))) ? e : c);
auto d3 = (((IsLike(w, s)) && (IsNotLike(w, n)) && (IsNotLike(s, e))) ? w : c);
auto d4 = (((IsLike(s, e)) && (IsNotLike(w, s)) && (IsNotLike(n, e))) ? e : c);
auto cx = c;
auto ce = Interpolate(cx, e, 3, 1);
auto cs = Interpolate(cx, s, 3, 1);
auto cse = Interpolate(cx, se, 3, 1);
P[1] = Interpolate(d1, cx, 3, 1);
P[2] = Interpolate(d2, ce, 3, 1);
P[3] = Interpolate(d3, cs, 3, 1);
P[4] = Interpolate(d4, cse, 3, 1);
for (auto Pixel = 1; Pixel < 5; Pixel++)
{
Write4RGB(ScaledImage, srcx, srcy, x, y, Pixel, P[Pixel]);
}
}
}
}
}
}