forked from handaimaoh/removedirtvs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shared.cpp
125 lines (109 loc) · 5.01 KB
/
shared.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
#include "shared.h"
#ifdef VS_TARGET_CPU_X86
#include <emmintrin.h>
#else
# error "Please specify VS_TARGET_CPU_X86 to build"
#endif
static __forceinline uint32_t aligned_diff(const uint8_t *sp1, int32_t spitch1, const uint8_t *sp2, int32_t spitch2, int32_t hblocks, int32_t incpitch, int32_t height)
{
__m128i xmm0 = _mm_setzero_si128();
__m128i xmm1 = _mm_setzero_si128();
spitch2 += incpitch;
incpitch += spitch1;
int32_t counter = hblocks;
do {
__m128i xmm2 = _mm_load_si128((__m128i*)sp1);
__m128i xmm3 = _mm_load_si128((__m128i*)(sp1+16));
__m128i xmm4 = _mm_load_si128((__m128i*)sp2);
__m128i xmm5 = _mm_load_si128((__m128i*)(sp2+16));
xmm2 = _mm_sad_epu8(xmm2, xmm4);
xmm3 = _mm_sad_epu8(xmm3, xmm5);
xmm0 = _mm_add_epi32(xmm0, xmm2);
xmm1 = _mm_add_epi32(xmm1, xmm3);
sp1 += 32;
sp2 += 32;
if (--counter > 0) {
continue;
}
sp1 += incpitch;
sp2 += spitch2;
counter = hblocks;
} while (--height > 0);
xmm0 = _mm_add_epi32(xmm0, xmm1);
return (uint32_t)_mm_cvtsi128_si32(xmm0);
}
static __forceinline uint32_t unaligned_diff(const uint8_t *sp1, int32_t spitch1, const uint8_t *sp2, int32_t spitch2, int32_t hblocks, int32_t incpitch, int32_t height)
{
__m128i xmm0 = _mm_setzero_si128();
__m128i xmm1 = _mm_setzero_si128();
spitch2 += incpitch;
incpitch += spitch1;
int32_t counter = hblocks;
do {
__m128i xmm2 = _mm_loadu_si128((__m128i*)sp1);
__m128i xmm3 = _mm_loadu_si128((__m128i*)(sp1+16));
__m128i xmm4 = _mm_loadu_si128((__m128i*)sp2);
__m128i xmm5 = _mm_loadu_si128((__m128i*)(sp2+16));
xmm2 = _mm_sad_epu8(xmm2, xmm4);
xmm3 = _mm_sad_epu8(xmm3, xmm5);
xmm0 = _mm_add_epi32(xmm0, xmm2);
xmm1 = _mm_add_epi32(xmm1, xmm3);
sp1 += 32;
sp2 += 32;
if (--counter > 0) {
continue;
}
} while (--height > 0);
xmm0 = _mm_add_epi32(xmm0, xmm1);
return (uint32_t)_mm_cvtsi128_si32(xmm0);
}
uint32_t gdiff(const uint8_t *sp1, int32_t spitch1, const uint8_t *sp2, int32_t spitch2, int32_t hblocks, int32_t incpitch, int32_t height)
{
if((((uint32_t)sp1 & (16 - 1)) + ((uint32_t)sp2 & (16 - 1))) == 0) {
return aligned_diff(sp1, spitch1, sp2, spitch2, hblocks, incpitch, height);
} else {
return unaligned_diff(sp1, spitch1, sp2, spitch2, hblocks, incpitch, height);
}
}
void copyChroma(VSFrameRef *dest, const VSFrameRef *source, const VSVideoInfo *vi, const VSAPI *vsapi)
{
int32_t destPitch = vsapi->getStride(dest, 1);
int32_t srcPitch = vsapi->getStride(source, 1);
vs_bitblt(vsapi->getWritePtr(dest, 1), destPitch, vsapi->getReadPtr(source, 1), srcPitch, vi->width >> vi->format->subSamplingW, vi->height >> vi->format->subSamplingH);
vs_bitblt(vsapi->getWritePtr(dest, 2), destPitch, vsapi->getReadPtr(source, 2), srcPitch, vi->width >> vi->format->subSamplingW, vi->height >> vi->format->subSamplingH);
}
VS_EXTERNAL_API(void) VapourSynthPluginInit(VSConfigPlugin configFunc, VSRegisterFunction registerFunc, VSPlugin *plugin)
{
configFunc("com.fakeurl.removedirtvs", "rdvs", "RemoveDirt VapourSynth Port", VAPOURSYNTH_API_VERSION, 1, plugin);
registerFunc("SCSelect", "input:clip;"\
"sceneBegin:clip;"\
"sceneEnd:clip;"\
"globalMotion:clip;"\
"dfactor:float:opt;", SCSelectCreate, 0, plugin);
registerFunc("RestoreMotionBlocks", "input:clip;"\
"restore:clip;"\
"neighbour:clip:opt;"\
"neighbour2:clip:opt;"\
"alternative:clip:opt;"\
"gmthreshold:int:opt;"\
"mthreshold:int:opt;"\
"noise:int:opt;"\
"noisy:int:opt;"\
"dist:int:opt;"\
"tolerance:int:opt;"\
"dmode:int:opt;"\
"pthreshold:int:opt;"\
"cthreshold:int:opt;"\
"grey:int:opt;", RestoreMotionBlocksCreate, 0, plugin);
registerFunc("DupBlocks", "input:clip;"\
"gmthreshold:int:opt;"\
"mthreshold:int:opt;"\
"noise:int:opt;"\
"noisy:int:opt;"\
"dist:int:opt;"\
"tolerance:int:opt;"\
"dmode:int:opt;"\
"pthreshold:int:opt;"\
"cthreshold:int:opt;"\
"grey:int:opt;", DupBlocksCreate, 0, plugin);
}