prevent popup deactivation while button_down
[goodguy/history.git] / cinelerra-5.1 / cinelerra / overlayframe.h.clamp
1 #ifndef OVERLAYFRAME_H
2 #define OVERLAYFRAME_H
3
4 #include "loadbalance.h"
5 #include "overlayframe.inc"
6 #include "vframe.inc"
7
8
9 // Issues encoutered with overlay
10
11 // Floating point vs. int.  On alpha the floating point interpolation is about
12 // 2x faster than integer interpolation.  Integer interpolation uses 32 
13 // siginificant bits while floating point uses 24, however.
14
15 // Single step vs. two step process.
16
17 // A single step process would require performing blend with the output
18 // of BILINEAR or BICUBIC and trimming the output to fractional pixels.
19 // This is easy.  
20
21 // However reading the input for
22 // BILINEAR and BICUBIC would require trimming the input to fractional
23 // pixels often repeatedly since the interpolation reads the same pixels more
24 // than once.  This is hard.
25
26 // In the two step process one step worries purely about scaling, ignoring 
27 // trimming at the input and output so redundant trimming is not done here.
28
29 // The translation engine focuses purely on trimming input pixels and
30 // blending with the output.
31
32 // Translation
33
34 typedef struct
35 {
36         int in_x1;
37         float in_fraction1;
38         int in_x2;       // Might be same as in_x1 for boundary
39         float in_fraction2;
40         float output_fraction;
41 } transfer_table;
42
43
44 class ScaleEngine;
45
46 class ScalePackage : public LoadPackage
47 {
48 public:
49         ScalePackage();
50
51         int out_row1, out_row2;
52 };
53
54 class ScaleUnit : public LoadClient
55 {
56 public:
57         ScaleUnit(ScaleEngine *server, OverlayFrame *overlay);
58         ~ScaleUnit();
59         
60         float cubic_bspline(float x);
61         void tabulate_bicubic(float* &coef_table, 
62                 int* &coord_table,
63                 float scale,
64                 int start, 
65                 int pixels,
66                 int total_pixels,
67                 float coefficient);
68         void tabulate_blinear(int* &table_int1,
69                 int* &table_int2,
70                 float* &table_frac,
71                 float* &table_antifrac,
72                 float scale,
73                 int pixel1,
74                 int pixel2,
75                 int start,
76                 int total_pixels);
77
78         void process_package(LoadPackage *package);
79         
80         OverlayFrame *overlay;
81         ScaleEngine *engine;
82 };
83
84 class ScaleEngine : public LoadServer
85 {
86 public:
87         ScaleEngine(OverlayFrame *overlay, int cpus);
88         ~ScaleEngine();
89         
90         void init_packages();
91         LoadClient* new_client();
92         LoadPackage* new_package();
93         
94         OverlayFrame *overlay;
95 // Global parameters for scaling units
96         VFrame *scale_output;
97         VFrame *scale_input;
98         float w_scale;
99         float h_scale;
100         int in_x1_int;
101         int in_y1_int;
102         int out_w_int;
103         int out_h_int;
104         int interpolation_type;
105 };
106
107
108
109
110
111
112
113 class TranslateEngine;
114
115 class TranslatePackage : public LoadPackage
116 {
117 public:
118         TranslatePackage();
119
120         int out_row1, out_row2;
121 };
122
123
124 class TranslateUnit : public LoadClient
125 {
126 public:
127         TranslateUnit(TranslateEngine *server, OverlayFrame *overlay);
128         ~TranslateUnit();
129
130         void process_package(LoadPackage *package);
131         void translation_array(transfer_table* &table, 
132                 float out_x1, 
133                 float out_x2,
134                 float in_x1,
135                 float in_x2,
136                 int in_total, 
137                 int out_total, 
138                 int &out_x1_int,
139                 int &out_x2_int);
140         void translate(VFrame *output, 
141                         VFrame *input, 
142                         float in_x1,
143                         float in_y1,
144                         float in_x2,
145                         float in_y2,
146                         float out_x1,
147                         float out_y1,
148                         float out_x2,
149                         float out_y2,
150                         float alpha,
151                         int mode,
152                         int row1,
153                         int row2);
154
155         OverlayFrame *overlay;
156         TranslateEngine *engine;
157 };
158
159 class TranslateEngine : public LoadServer
160 {
161 public:
162         TranslateEngine(OverlayFrame *overlay, int cpus);
163         ~TranslateEngine();
164         
165         void init_packages();
166         LoadClient* new_client();
167         LoadPackage* new_package();
168         
169         OverlayFrame *overlay;
170 // Global parameters for translate units
171         VFrame *translate_output;
172         VFrame *translate_input;
173         float translate_in_x1;
174         float translate_in_y1;
175         float translate_in_x2;
176         float translate_in_y2;
177         float translate_out_x1;
178         float translate_out_y1;
179         float translate_out_x2;
180         float translate_out_y2;
181         float translate_alpha;
182         int translate_mode;
183 };
184
185
186
187
188
189
190
191
192
193 class ScaleTranslateEngine;
194
195 class ScaleTranslatePackage : public LoadPackage
196 {
197 public:
198         ScaleTranslatePackage();
199
200         int out_row1, out_row2;
201 };
202
203
204 class ScaleTranslateUnit : public LoadClient
205 {
206 public:
207         ScaleTranslateUnit(ScaleTranslateEngine *server, OverlayFrame *overlay);
208         ~ScaleTranslateUnit();
209
210         void process_package(LoadPackage *package);
211         void scale_array(int* &table, 
212                 int out_x1, 
213                 int out_x2,
214                 int in_x1,
215                 int in_x2,
216                 int is_x);
217         
218         OverlayFrame *overlay;
219         ScaleTranslateEngine *scale_translate;
220 };
221
222 class ScaleTranslateEngine : public LoadServer
223 {
224 public:
225         ScaleTranslateEngine(OverlayFrame *overlay, int cpus);
226         ~ScaleTranslateEngine();
227         
228         void init_packages();
229         LoadClient* new_client();
230         LoadPackage* new_package();
231         
232         OverlayFrame *overlay;
233         
234         
235 // Arguments
236         VFrame *output;
237         VFrame *input;
238         int in_x1;
239         int in_y1;
240         int in_x2;
241         int in_y2;
242         int out_x1;
243         int out_y1;
244         int out_x2;
245         int out_y2;
246         float alpha;
247         int mode;
248 };
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264 class BlendEngine;
265
266 class BlendPackage : public LoadPackage
267 {
268 public:
269         BlendPackage();
270
271         int out_row1, out_row2;
272 };
273
274
275 class BlendUnit : public LoadClient
276 {
277 public:
278         BlendUnit(BlendEngine *server, OverlayFrame *overlay);
279         ~BlendUnit();
280
281         void process_package(LoadPackage *package);
282         void translation_array(transfer_table* &table, 
283                 float out_x1, 
284                 float out_x2,
285                 float in_x1,
286                 float in_x2,
287                 int in_total, 
288                 int out_total, 
289                 int &out_x1_int,
290                 int &out_x2_int);
291         void translate(VFrame *output, 
292                         VFrame *input, 
293                         float in_x1,
294                         float in_y1,
295                         float in_x2,
296                         float in_y2,
297                         float out_x1,
298                         float out_y1,
299                         float out_x2,
300                         float out_y2,
301                         float alpha,
302                         int mode,
303                         int row1,
304                         int row2);
305
306         OverlayFrame *overlay;
307         BlendEngine *blend_engine;
308 };
309
310 class BlendEngine : public LoadServer
311 {
312 public:
313         BlendEngine(OverlayFrame *overlay, int cpus);
314         ~BlendEngine();
315         
316         void init_packages();
317         LoadClient* new_client();
318         LoadPackage* new_package();
319         
320         OverlayFrame *overlay;
321         
322         
323 // Arguments
324         VFrame *output;
325         VFrame *input;
326         float alpha;
327         int mode;
328 };
329
330
331
332
333
334
335
336
337
338
339
340
341
342 class OverlayFrame
343 {
344 public:
345         OverlayFrame(int cpus = 1);
346         virtual ~OverlayFrame();
347
348 // Alpha is from 0 - 1
349         int overlay(VFrame *output, 
350                 VFrame *input, 
351                 float in_x1, 
352                 float in_y1, 
353                 float in_x2, 
354                 float in_y2, 
355                 float out_x1, 
356                 float out_y1, 
357                 float out_x2, 
358                 float out_y2, 
359                 float alpha, 
360                 int mode,
361                 int interpolation_type);
362
363         int overlay(VFrame *output, unsigned char *input,
364                 float in_x1, float in_y1, float in_x2, float in_y2,
365                 float out_x1, float out_y1, float out_x2, float out_y2, 
366                 int alpha, int in_w, int in_h);
367         int use_alpha, use_float, mode, interpolate;
368         int color_model;
369
370         BlendEngine *blend_engine;
371         ScaleEngine *scale_engine;
372         TranslateEngine *translate_engine;
373         ScaleTranslateEngine *scaletranslate_engine;
374
375
376         VFrame *temp_frame;
377         int cpus;
378
379 };
380
381 #endif