-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSimpleLUT.hpp
118 lines (87 loc) · 3.87 KB
/
SimpleLUT.hpp
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
#pragma warning (disable : 4100)
#include "avisynth.h"
#include <vector>
#include <cmath>
#include <stdint.h>
#include <algorithm>
#define PICK_TEMPLATE(srcBitDepth, dstBitDepth, template_function) \
(srcBitDepth == 8 ? \
dstBitDepth == 8 ? template_function <uint8_t,uint8_t> : \
dstBitDepth == 32 ? template_function <uint8_t,uint32_t> : \
template_function <uint8_t,uint16_t> \
: \
dstBitDepth == 8 ? template_function <uint16_t,uint8_t> : \
dstBitDepth == 32 ? template_function <uint16_t,uint32_t> : \
template_function <uint16_t,uint16_t>)
#define no_planes std::vector<int>({0})
#define planes_y std::vector<int>({PLANAR_Y})
#define planes_yuv std::vector<int>({PLANAR_Y, PLANAR_U, PLANAR_V})
#define planes_yuva std::vector<int>({PLANAR_Y, PLANAR_U, PLANAR_V, PLANAR_A})
#define planes_rgb std::vector<int>({PLANAR_R, PLANAR_G, PLANAR_B})
#define planes_rgba std::vector<int>({PLANAR_R, PLANAR_G, PLANAR_B, PLANAR_A})
int getPixelTypeAccordingToBitDepth(int generic_flag, int bitDepth);
const std::vector<int> getPlanesVector(const VideoInfo& vi, const char* description, IScriptEnvironment* env);
class LUTClip : public IClip {
private:
VideoInfo vi;
PVideoFrame frame;
int width, height;
int num_planes, num_values;
std::vector<int> planes;
int src_num;
template<typename pixel_t> void write_planar_lut() const;
public:
LUTClip(const char* plane_string, int dimensions, int bitDepth, int src_num, IScriptEnvironment* env);
PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment* env);
bool __stdcall GetParity(int n);
const VideoInfo& __stdcall GetVideoInfo();
int __stdcall SetCacheHints(int cachehints,int frame_range);
void __stdcall GetAudio(void* buf, int64_t start, int64_t count, IScriptEnvironment* env);
static AVSValue __cdecl Create_LUTClip(AVSValue args, void*, IScriptEnvironment* env);
};
class ApplyLUT : public GenericVideoFilter {
private:
std::vector<PClip> src_clips;
PClip lut_clip;
int mode;
bool optMakeWritable;
int num_src_clips, num_src_planes;
std::vector<VideoInfo> vi_src;
std::vector<std::vector<int>> src_planes, src_width, src_height;
int srcBitDepth, dstBitDepth, src_pitch_bitshift, dst_pitch_bitshift;
VideoInfo vi_lut;
int num_lut_planes, lut_dimensions;
PVideoFrame lut;
int num_dst_planes;
std::vector<int> dst_planes, dst_width, dst_height;
int num_writable_candidates;
std::vector<int> writable_candidates;
// Pointer to wrapper function
void(ApplyLUT::*wrapper_to_use) (std::vector<PVideoFrame>& src, PVideoFrame& dst) const;
const int MAX_NUM_PLANES = 3;
enum Condition {
SRC_SAME_RES,
SRC_NO_SUBSAMPLING,
SRC_NOT_INTERLEAVED,
DST_NOT_INTERLEAVED,
DST_NOT_YUV_INTERLEAVED
};
static int pitchBitShift(int bitDepth);
void fillSrcAndLutInfo(IScriptEnvironment* env);
bool conditionNotFulfilled(Condition cond) const;
void takeFirstPlaneFromEachSource();
int generateSubsampledPixelType(IScriptEnvironment* env);
void setDstFormatAndWrapperFunction(IScriptEnvironment* env);
void fillDstInfo();
void findWritableCandidates();
#ifdef ENABLE_CONSTRUCTOR_TESTING
void constructorTesting(IScriptEnvironment* env);
#endif
#include "SimpleLUT_ApplyLUT_WriteFunctions.tpp"
public:
ApplyLUT(PClip _child, std::vector<PClip> _src_clips, PClip _lut_clip, int _mode, bool _optMakeWritable, IScriptEnvironment* env);
PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment* env);
int __stdcall SetCacheHints(int cachehints,int frame_range);
static AVSValue __cdecl Create(AVSValue args, void*, IScriptEnvironment* env);
};
extern "C" __declspec(dllexport) const char* __stdcall AvisynthPluginInit3(IScriptEnvironment* env, AVS_Linkage* vectors);