-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhq2xn.cpp
121 lines (95 loc) · 3.12 KB
/
hq2xn.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
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include "includes/FilterCommon.h"
#include "includes/hq.h"
extern "C"
{
static unsigned char* ScaledImage = NULL;
const int FilterID = 0x5D1C;
const char* FilterName = "HQ 2Xn";
const char* FilterDescription = "Maxim Stepin's High Quality 2Xn Magnification";
bool ComparisonThreshold = true;
const int FilterScaleX = 2;
int FilterScaleY = 2;
#include "includes/Init.h"
void Apply(int argc, void** argv)
{
if (argc >= 4)
{
auto Input = ((unsigned char*)(argv[0]));
auto srcx = *((int*)(argv[1]));
auto srcy = *((int*)(argv[2]));
auto scale = *((int*)(argv[3]));
scale = scale < 2 ? 2 : scale;
scale = scale > 4 ? 4 : scale;
FilterScaleY = scale;
Init(srcx, srcy);
int P[17];
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 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 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);
unsigned char pattern = 0;
if ((IsNotLike(c4, c0)))
pattern |= 1;
if ((IsNotLike(c4, c1)))
pattern |= 2;
if ((IsNotLike(c4, c2)))
pattern |= 4;
if ((IsNotLike(c4, c3)))
pattern |= 8;
if ((IsNotLike(c4, c5)))
pattern |= 16;
if ((IsNotLike(c4, c6)))
pattern |= 32;
if ((IsNotLike(c4, c7)))
pattern |= 64;
if ((IsNotLike(c4, c8)))
pattern |= 128;
switch(scale)
{
case 4: // 2x4
Hq2x4Kernel(pattern, c0, c1, c2, c3, c4, c5, c6, c7, c8, P);
Write16RGB(ScaledImage, srcx, srcy, x, y, 1, P[1]);
Write16RGB(ScaledImage, srcx, srcy, x, y, 2, P[2]);
Write16RGB(ScaledImage, srcx, srcy, x, y, 5, P[5]);
Write16RGB(ScaledImage, srcx, srcy, x, y, 6, P[6]);
Write16RGB(ScaledImage, srcx, srcy, x, y, 9, P[9]);
Write16RGB(ScaledImage, srcx, srcy, x, y, 10, P[10]);
Write16RGB(ScaledImage, srcx, srcy, x, y, 13, P[13]);
Write16RGB(ScaledImage, srcx, srcy, x, y, 14, P[14]);
break;
case 3: // 2x3
Hq2x3Kernel(pattern, c0, c1, c2, c3, c4, c5, c6, c7, c8, P);
Write9RGB(ScaledImage, srcx, srcy, x, y, 1, P[1]);
Write9RGB(ScaledImage, srcx, srcy, x, y, 2, P[2]);
Write9RGB(ScaledImage, srcx, srcy, x, y, 4, P[4]);
Write9RGB(ScaledImage, srcx, srcy, x, y, 5, P[5]);
Write9RGB(ScaledImage, srcx, srcy, x, y, 7, P[7]);
Write9RGB(ScaledImage, srcx, srcy, x, y, 8, P[8]);
break;
default: // 2x2
Hq2xKernel(pattern, c0, c1, c2, c3, c4, c5, c6, c7, c8, P);
for (auto Pixel = 1; Pixel < 5; Pixel++)
{
Write4RGB(ScaledImage, srcx, srcy, x, y, Pixel, P[Pixel]);
}
break;
}
}
}
}
}
}