-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnearest.cpp
59 lines (46 loc) · 1.24 KB
/
nearest.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
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include "includes/FilterCommon.h"
extern "C"
{
static unsigned char* ScaledImage = NULL;
const int FilterID = 0x5D23;
const char* FilterName = "Nearest-neighbor";
const char* FilterDescription = "Image scaling by nearest-neighbor interpolation";
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);
auto SizeX = srcx * ScaleX();
auto SizeY = srcy * ScaleY();
auto Channels = 3;
int x_ratio = (int)((srcx << 16) / SizeX) + 1;
int y_ratio = (int)((srcy << 16) / SizeY) + 1;
for (int i = 0; i < SizeY; i++)
{
for (int j = 0; j < SizeX; j++)
{
auto x2 = ((j * x_ratio) >> 16);
auto y2 = ((i * y_ratio) >> 16);
auto dst = (i * SizeX + j) * Channels;
auto src = (y2 * srcx + x2) * Channels;
for (auto Channel = 0; Channel < Channels; Channel++)
{
ScaledImage[dst + Channel] = Input[src + Channel];
}
}
}
}
}
}