no longer need ffmpeg patch0 which was for Termux
[goodguy/cinelerra.git] / cinelerra-5.1 / plugins / descratch / descratch.h
1 /*
2 DeScratch - Scratches Removing Filter
3 Plugin for Avisynth 2.5
4 Copyright (c)2003-2016 Alexander G. Balakhnin aka Fizick
5 bag@hotmail.ru  http://avisynth.org.ru
6
7 This program is FREE software under GPL licence v2.
8
9 This plugin removes vertical scratches from digitized films.
10 Reworked for cin5 by William Morrow. 03/2018, from the laws of Fizick's
11 Adapted strategy to mark, test, draw during port.
12 */
13
14
15 #ifndef __DESCRATCH_H__
16 #define __DESCRATCH_H__
17
18 #include "bcbutton.h"
19 #include "bchash.h"
20 #include "bcmenuitem.h"
21 #include "bcpopupmenu.h"
22 #include "bcslider.h"
23 #include "bctitle.h"
24 #include "bctoggle.h"
25 #include "mutex.h"
26 #include "overlayframe.h"
27 #include "pluginvclient.h"
28
29 // so that write_pgm can create grey images of inf
30 #define SD_NULL 0
31 #define SD_EXTREM 0x80
32 #define SD_TESTED 0x40
33 #define SD_GOOD   0x20
34 #define SD_REJECT 0x10
35
36 #define MODE_NONE 0
37 #define MODE_LOW 1
38 #define MODE_HIGH 2
39 #define MODE_ALL 3
40
41 class DeScratchConfig;
42 class DeScratchMain;
43 class DeScratchWindow;
44 class DeScratchModeItem;
45 class DeScratchMode;
46 class DeScratchISlider;
47 class DeScratchFSlider;
48 class DeScratchMark;
49 class DeScratchEdgeOnly;
50 class DeScratchReset;
51
52
53 class DeScratchConfig
54 {
55 public:
56         DeScratchConfig();
57         ~DeScratchConfig();
58         void reset();
59         int equivalent(DeScratchConfig &that);
60         void copy_from(DeScratchConfig &that);
61         void interpolate(DeScratchConfig &prev, DeScratchConfig &next,
62                 int64_t prev_frame, int64_t next_frame, int64_t current_frame);
63
64         int threshold;
65         float asymmetry;
66         int min_width;
67         int max_width;
68         float min_len;
69         float max_len;
70         float max_angle;
71         int blur_len;
72         float gap_len;
73         int mode_y;
74         int mode_u;
75         int mode_v;
76         int mark;
77         float ffade;
78         int border;
79         int edge_only;
80 };
81
82 class DeScratchMain : public PluginVClient
83 {
84 public:
85         DeScratchMain(PluginServer *server);
86         ~DeScratchMain();
87
88         PLUGIN_CLASS_MEMBERS(DeScratchConfig)
89         uint8_t *inf;  int sz_inf;
90         int src_w, src_h;
91         VFrame *src, *dst;
92         VFrame *tmpy, *blury;
93         OverlayFrame *overlay_frame;
94         int is_realtime();
95         void update_gui();
96         void save_data(KeyFrame *keyframe);
97         void read_data(KeyFrame *keyframe);
98
99         void set_extrems_plane(int width, int comp, int thresh);
100         void close_gaps();
101         void test_scratches();
102         void mark_scratches_plane();
103         void remove_scratches_plane(int comp);
104         void blur(int scale);
105         void copy(int comp);
106         void pass(int comp, int thresh);
107         void plane_pass(int comp, int mode);
108         void plane_proc(int comp, int mode);
109         int process_realtime(VFrame *input, VFrame *output);
110 };
111
112
113 class DeScratchWindow : public PluginClientWindow
114 {
115 public:
116         DeScratchWindow(DeScratchMain *plugin);
117         ~DeScratchWindow();
118         void update_gui();
119         void create_objects();
120         
121         DeScratchMain *plugin;
122         DeScratchMode *y_mode, *u_mode, *v_mode;
123         DeScratchISlider *threshold;
124         DeScratchFSlider *asymmetry;
125         DeScratchISlider *min_width, *max_width;
126         DeScratchFSlider *min_len, *max_len;
127         DeScratchISlider *blur_len;
128         DeScratchFSlider *gap_len;
129         DeScratchFSlider *max_angle;
130         DeScratchISlider *border;
131         DeScratchMark *mark;
132         DeScratchEdgeOnly *edge_only;
133         DeScratchFSlider *ffade;
134         DeScratchReset *reset;
135 };
136
137 class DeScratchModeItem : public BC_MenuItem
138 {
139 public:
140         DeScratchModeItem(DeScratchMode *popup, int type, const char *text);
141         ~DeScratchModeItem();
142         int handle_event();
143
144         DeScratchMode *popup;
145         int type;
146 };
147
148 class DeScratchMode : public BC_PopupMenu
149 {
150 public:
151         DeScratchMode(DeScratchWindow *win, int x, int y, int *value);
152         ~DeScratchMode();
153         void create_objects();
154         int handle_event();
155         void update(int v);
156         void set_value(int v);
157
158         DeScratchWindow *win;
159         int *value;
160 };
161
162 class DeScratchISlider : public BC_ISlider
163 {
164 public:
165         DeScratchISlider(DeScratchWindow *win,
166                 int x, int y, int w, int min, int max, int *output);
167         ~DeScratchISlider();
168         int handle_event();
169
170         DeScratchWindow *win;
171         int *output;
172 };
173
174 class DeScratchFSlider : public BC_FSlider
175 {
176 public:
177         DeScratchFSlider(DeScratchWindow *win,
178                 int x, int y, int w, float min, float max, float *output);
179         ~DeScratchFSlider();
180         int handle_event();
181
182         DeScratchWindow *win;
183         float *output;
184 };
185
186 class DeScratchMark : public BC_CheckBox
187 {
188 public:
189         DeScratchMark(DeScratchWindow *win, int x, int y);
190         ~DeScratchMark();
191         int handle_event();
192
193         DeScratchWindow *win;
194 };
195
196 class DeScratchEdgeOnly : public BC_CheckBox
197 {
198 public:
199         DeScratchEdgeOnly(DeScratchWindow *win, int x, int y);
200         ~DeScratchEdgeOnly();
201         int handle_event();
202
203         DeScratchWindow *win;
204 };
205
206 class DeScratchReset : public BC_GenericButton
207 {
208 public:
209         DeScratchReset(DeScratchWindow *win, int x, int y);
210         int handle_event();
211
212         DeScratchWindow *win;
213 };
214
215 #endif