r553: Modern gccs require __attribute__((used)) for variables used only in assembly.
[cinelerra_cv/mob.git] / cinelerra / overlayframe.h
bloba3bd899d4236d5f647e453ec2c04260707a4ff41
1 #ifndef OVERLAYFRAME_H
2 #define OVERLAYFRAME_H
4 #include "loadbalance.h"
5 #include "overlayframe.inc"
6 #include "vframe.inc"
9 // Issues encoutered with overlay
11 // Floating point vs. int. On both alpha and Intel
12 // the floating point interpolation is over
13 // 2x faster than integer interpolation. Pipelined CPUs probably don't benefit
14 // at all in long sequences of integer calculations. Integer interpolation uses 32
15 // siginificant bits while floating point uses 24, however.
17 // Single step vs. two step process.
19 // A single step process would require performing blend with the output
20 // of BILINEAR or BICUBIC and trimming the output to fractional pixels.
21 // This is easy.
23 // However reading the input for
24 // BILINEAR and BICUBIC would require trimming the input to fractional
25 // pixels often repeatedly since the interpolation reads the same pixels more
26 // than once. This is hard.
28 // In the two step process one step worries purely about scaling, ignoring
29 // trimming at the input and output so redundant trimming is not done here.
31 // The translation engine focuses purely on trimming input pixels and
32 // blending with the output.
34 // Another advantage to the two step process is further optimization can be achieved
35 // by leaving out translation or scaling.
37 // Translation
39 typedef struct
41 int in_x1;
42 int in_fraction1;
43 int in_x2; // Might be same as in_x1 for boundary
44 int in_fraction2;
45 int output_fraction;
46 } transfer_table_i;
48 typedef struct
50 int in_x1;
51 float in_fraction1;
52 int in_x2; // Might be same as in_x1 for boundary
53 float in_fraction2;
54 float output_fraction;
55 } transfer_table_f;
57 typedef struct
59 int input_pixel1;
60 int input_pixel2;
61 float input_fraction1;
62 float input_fraction2;
63 float input_fraction3;
64 float total_fraction;
65 } bilinear_table_t;
67 class ScaleEngine;
69 class ScalePackage : public LoadPackage
71 public:
72 ScalePackage();
74 int out_row1, out_row2;
77 class ScaleUnit : public LoadClient
79 public:
80 ScaleUnit(ScaleEngine *server, OverlayFrame *overlay);
81 ~ScaleUnit();
83 float cubic_bspline(float x);
85 void tabulate_bcubic_f(float* &coef_table,
86 int* &coord_table,
87 float scale,
88 int start,
89 int pixels,
90 int total_pixels,
91 float coefficient);
92 void tabulate_blinear_f(int* &table_int1,
93 int* &table_int2,
94 float* &table_frac,
95 float* &table_antifrac,
96 float scale,
97 int pixel1,
98 int pixel2,
99 int start,
100 int total_pixels);
102 void tabulate_bcubic_i(int* &coef_table,
103 int* &coord_table,
104 float scale,
105 int start,
106 int pixels,
107 int total_pixels,
108 float coefficient);
109 void tabulate_blinear_i(int* &table_int1,
110 int* &table_int2,
111 int* &table_frac,
112 int* &table_antifrac,
113 float scale,
114 int pixel1,
115 int pixel2,
116 int start,
117 int total_pixels);
118 void tabulate_reduction(bilinear_table_t* &table,
119 float scale,
120 int pixel1,
121 int out_total,
122 int in_total);
123 void tabulate_enlarge(bilinear_table_t* &table,
124 float scale,
125 int pixel1,
126 int out_total,
127 int in_total);
128 void dump_bilinear(bilinear_table_t *table, int total);
130 void process_package(LoadPackage *package);
132 OverlayFrame *overlay;
133 ScaleEngine *engine;
136 class ScaleEngine : public LoadServer
138 public:
139 ScaleEngine(OverlayFrame *overlay, int cpus);
140 ~ScaleEngine();
142 void init_packages();
143 LoadClient* new_client();
144 LoadPackage* new_package();
146 OverlayFrame *overlay;
147 // Global parameters for scaling units
148 VFrame *scale_output;
149 VFrame *scale_input;
150 float w_scale;
151 float h_scale;
152 int in_x1_int;
153 int in_y1_int;
154 int out_w_int;
155 int out_h_int;
156 int interpolation_type;
165 class TranslateEngine;
167 class TranslatePackage : public LoadPackage
169 public:
170 TranslatePackage();
172 int out_row1, out_row2;
176 class TranslateUnit : public LoadClient
178 public:
179 TranslateUnit(TranslateEngine *server, OverlayFrame *overlay);
180 ~TranslateUnit();
182 void process_package(LoadPackage *package);
183 static void translation_array_f(transfer_table_f* &table,
184 float out_x1,
185 float out_x2,
186 float in_x1,
187 float in_x2,
188 int in_total,
189 int out_total,
190 int &out_x1_int,
191 int &out_x2_int);
192 void translation_array_i(transfer_table_i* &table,
193 float out_x1,
194 float out_x2,
195 float in_x1,
196 float in_x2,
197 int in_total,
198 int out_total,
199 int &out_x1_int,
200 int &out_x2_int);
201 void translate(VFrame *output,
202 VFrame *input,
203 float in_x1,
204 float in_y1,
205 float in_x2,
206 float in_y2,
207 float out_x1,
208 float out_y1,
209 float out_x2,
210 float out_y2,
211 float alpha,
212 int mode,
213 int row1,
214 int row2);
216 OverlayFrame *overlay;
217 TranslateEngine *engine;
220 class TranslateEngine : public LoadServer
222 public:
223 TranslateEngine(OverlayFrame *overlay, int cpus);
224 ~TranslateEngine();
226 void init_packages();
227 LoadClient* new_client();
228 LoadPackage* new_package();
230 OverlayFrame *overlay;
231 // Global parameters for translate units
232 VFrame *translate_output;
233 VFrame *translate_input;
234 float translate_in_x1;
235 float translate_in_y1;
236 float translate_in_x2;
237 float translate_in_y2;
238 float translate_out_x1;
239 float translate_out_y1;
240 float translate_out_x2;
241 float translate_out_y2;
242 float translate_alpha;
243 int translate_mode;
254 class ScaleTranslateEngine;
256 class ScaleTranslatePackage : public LoadPackage
258 public:
259 ScaleTranslatePackage();
261 int out_row1, out_row2;
265 class ScaleTranslateUnit : public LoadClient
267 public:
268 ScaleTranslateUnit(ScaleTranslateEngine *server, OverlayFrame *overlay);
269 ~ScaleTranslateUnit();
271 void process_package(LoadPackage *package);
272 void scale_array(int* &table,
273 int out_x1,
274 int out_x2,
275 int in_x1,
276 int in_x2,
277 int is_x);
279 OverlayFrame *overlay;
280 ScaleTranslateEngine *scale_translate;
283 class ScaleTranslateEngine : public LoadServer
285 public:
286 ScaleTranslateEngine(OverlayFrame *overlay, int cpus);
287 ~ScaleTranslateEngine();
289 void init_packages();
290 LoadClient* new_client();
291 LoadPackage* new_package();
293 OverlayFrame *overlay;
296 // Arguments
297 VFrame *output;
298 VFrame *input;
299 int in_x1;
300 int in_y1;
301 int in_x2;
302 int in_y2;
303 int out_x1;
304 int out_y1;
305 int out_x2;
306 int out_y2;
307 float alpha;
308 int mode;
325 class BlendEngine;
327 class BlendPackage : public LoadPackage
329 public:
330 BlendPackage();
332 int out_row1, out_row2;
336 class BlendUnit : public LoadClient
338 public:
339 BlendUnit(BlendEngine *server, OverlayFrame *overlay);
340 ~BlendUnit();
342 void process_package(LoadPackage *package);
343 void translation_array_f(transfer_table_f* &table,
344 float out_x1,
345 float out_x2,
346 float in_x1,
347 float in_x2,
348 int in_total,
349 int out_total,
350 int &out_x1_int,
351 int &out_x2_int);
352 void translate(VFrame *output,
353 VFrame *input,
354 float in_x1,
355 float in_y1,
356 float in_x2,
357 float in_y2,
358 float out_x1,
359 float out_y1,
360 float out_x2,
361 float out_y2,
362 float alpha,
363 int mode,
364 int row1,
365 int row2);
367 OverlayFrame *overlay;
368 BlendEngine *blend_engine;
371 class BlendEngine : public LoadServer
373 public:
374 BlendEngine(OverlayFrame *overlay, int cpus);
375 ~BlendEngine();
377 void init_packages();
378 LoadClient* new_client();
379 LoadPackage* new_package();
381 OverlayFrame *overlay;
384 // Arguments
385 VFrame *output;
386 VFrame *input;
387 float alpha;
388 int mode;
403 class OverlayFrame
405 public:
406 OverlayFrame(int cpus = 1);
407 virtual ~OverlayFrame();
409 // Alpha is from 0 - 1
410 int overlay(VFrame *output,
411 VFrame *input,
412 float in_x1,
413 float in_y1,
414 float in_x2,
415 float in_y2,
416 float out_x1,
417 float out_y1,
418 float out_x2,
419 float out_y2,
420 float alpha, // 0 - 1
421 int mode,
422 int interpolation_type);
423 int use_alpha, use_float, mode, interpolate;
424 int color_model;
426 BlendEngine *blend_engine;
427 ScaleEngine *scale_engine;
428 TranslateEngine *translate_engine;
429 ScaleTranslateEngine *scaletranslate_engine;
432 VFrame *temp_frame;
433 int cpus;
437 #endif