-
Notifications
You must be signed in to change notification settings - Fork 0
/
tvzero.cpp
97 lines (69 loc) · 2.05 KB
/
tvzero.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
#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 = 0x5D24;
const char* FilterName = "TV Zero";
const char* FilterDescription = "No-scaling TV-like effect using interlacing and gamma reduction";
bool ComparisonThreshold = false;
const int FilterScaleX = 1;
const int FilterScaleY = 1;
#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 < 1 ? 1 : scale;
scale = scale > 4 ? 4 : scale;
auto Channels = 3;
Init(srcx, srcy);
for (auto y = 0; y < srcy; y++)
{
for (auto x = 0; x < srcx; x++)
{
auto pixel = CLR(Input, srcx, srcy, x, y);
auto R = Red(pixel);
auto G = Green(pixel);
auto B = Blue(pixel);
auto subPixel = RGBINT((R * 5) >> 3, (G * 5) >> 3, (B * 5) >> 3);
auto subPixel2 = RGBINT((R * 5) >> 4, (G * 5) >> 4, (B * 5) >> 4);
auto subPixel3 = RGBINT((R * 5) >> 5, (G * 5) >> 5, (B * 5) >> 5);
auto dst = (y * srcx + x) * Channels;
auto row = y % scale;
switch(row)
{
case 1:
ScaledImage[dst] = Red(subPixel);
ScaledImage[dst + 1] = Green(subPixel);
ScaledImage[dst + 2] = Blue(subPixel);
break;
case 2:
ScaledImage[dst] = Red(subPixel2);
ScaledImage[dst + 1] = Green(subPixel2);
ScaledImage[dst + 2] = Blue(subPixel2);
break;
case 3:
ScaledImage[dst] = Red(subPixel3);
ScaledImage[dst + 1] = Green(subPixel3);
ScaledImage[dst + 2] = Blue(subPixel3);
break;
default:
ScaledImage[dst] = Red(pixel);
ScaledImage[dst + 1] = Green(pixel);
ScaledImage[dst + 2] = Blue(pixel);
break;
}
}
}
}
}
}