r1006: configure: Use libx264_pic instead of libx264 if available.
[cinelerra_cv/mob.git] / cinelerra / overlayframe.h
blob7e2c14d63f0b65f43c27891b23c11222a368aaaf
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 float 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 float 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 float 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 float 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 float in_x1_float;
153 float in_y1_float;
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_f(int* &table,
273 int out_x1,
274 int out_x2,
275 float in_x1,
276 float in_x2);
278 OverlayFrame *overlay;
279 ScaleTranslateEngine *scale_translate;
282 class ScaleTranslateEngine : public LoadServer
284 public:
285 ScaleTranslateEngine(OverlayFrame *overlay, int cpus);
286 ~ScaleTranslateEngine();
288 void init_packages();
289 LoadClient* new_client();
290 LoadPackage* new_package();
292 OverlayFrame *overlay;
295 // Arguments
296 VFrame *output;
297 VFrame *input;
298 float in_x1;
299 float in_y1;
300 float in_x2;
301 float in_y2;
302 int out_x1;
303 int out_y1;
304 int out_x2;
305 int out_y2;
306 float alpha;
307 int mode;
324 class BlendEngine;
326 class BlendPackage : public LoadPackage
328 public:
329 BlendPackage();
331 int out_row1, out_row2;
335 class BlendUnit : public LoadClient
337 public:
338 BlendUnit(BlendEngine *server, OverlayFrame *overlay);
339 ~BlendUnit();
341 void process_package(LoadPackage *package);
342 void translation_array_f(transfer_table_f* &table,
343 float out_x1,
344 float out_x2,
345 float in_x1,
346 float in_x2,
347 int in_total,
348 int out_total,
349 int &out_x1_int,
350 int &out_x2_int);
351 void translate(VFrame *output,
352 VFrame *input,
353 float in_x1,
354 float in_y1,
355 float in_x2,
356 float in_y2,
357 float out_x1,
358 float out_y1,
359 float out_x2,
360 float out_y2,
361 float alpha,
362 int mode,
363 int row1,
364 int row2);
366 OverlayFrame *overlay;
367 BlendEngine *blend_engine;
370 class BlendEngine : public LoadServer
372 public:
373 BlendEngine(OverlayFrame *overlay, int cpus);
374 ~BlendEngine();
376 void init_packages();
377 LoadClient* new_client();
378 LoadPackage* new_package();
380 OverlayFrame *overlay;
383 // Arguments
384 VFrame *output;
385 VFrame *input;
386 float alpha;
387 int mode;
402 class OverlayFrame
404 public:
405 OverlayFrame(int cpus = 1);
406 virtual ~OverlayFrame();
408 // Alpha is from 0 - 1
409 int overlay(VFrame *output,
410 VFrame *input,
411 float in_x1,
412 float in_y1,
413 float in_x2,
414 float in_y2,
415 float out_x1,
416 float out_y1,
417 float out_x2,
418 float out_y2,
419 float alpha, // 0 - 1
420 int mode,
421 int interpolation_type);
422 int use_alpha, use_float, mode, interpolate;
423 int color_model;
425 BlendEngine *blend_engine;
426 ScaleEngine *scale_engine;
427 TranslateEngine *translate_engine;
428 ScaleTranslateEngine *scaletranslate_engine;
431 VFrame *temp_frame;
432 int cpus;
436 #endif