r125: This commit was manufactured by cvs2svn to create tag 'r1_1_7-last'.
[cinelerra_cv/mob.git] / hvirtual / cinelerra / overlayframe.h
blobe2a28feb2a75157a7ed25a85d9a0224fb1c1a70e
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);
84 void tabulate_bcubic_f(float* &coef_table,
85 int* &coord_table,
86 float scale,
87 int start,
88 int pixels,
89 int total_pixels,
90 float coefficient);
91 void tabulate_blinear_f(int* &table_int1,
92 int* &table_int2,
93 float* &table_frac,
94 float* &table_antifrac,
95 float scale,
96 int pixel1,
97 int pixel2,
98 int start,
99 int total_pixels);
101 void tabulate_bcubic_i(int* &coef_table,
102 int* &coord_table,
103 float scale,
104 int start,
105 int pixels,
106 int total_pixels,
107 float coefficient);
108 void tabulate_blinear_i(int* &table_int1,
109 int* &table_int2,
110 int* &table_frac,
111 int* &table_antifrac,
112 float scale,
113 int pixel1,
114 int pixel2,
115 int start,
116 int total_pixels);
117 void tabulate_reduction(bilinear_table_t* &table,
118 float scale,
119 int pixel1,
120 int out_total,
121 int in_total);
122 void tabulate_enlarge(bilinear_table_t* &table,
123 float scale,
124 int pixel1,
125 int out_total,
126 int in_total);
127 void dump_bilinear(bilinear_table_t *table, int total);
129 void process_package(LoadPackage *package);
131 OverlayFrame *overlay;
132 ScaleEngine *engine;
135 class ScaleEngine : public LoadServer
137 public:
138 ScaleEngine(OverlayFrame *overlay, int cpus);
139 ~ScaleEngine();
141 void init_packages();
142 LoadClient* new_client();
143 LoadPackage* new_package();
145 OverlayFrame *overlay;
146 // Global parameters for scaling units
147 VFrame *scale_output;
148 VFrame *scale_input;
149 float w_scale;
150 float h_scale;
151 int in_x1_int;
152 int in_y1_int;
153 int out_w_int;
154 int out_h_int;
155 int interpolation_type;
164 class TranslateEngine;
166 class TranslatePackage : public LoadPackage
168 public:
169 TranslatePackage();
171 int out_row1, out_row2;
175 class TranslateUnit : public LoadClient
177 public:
178 TranslateUnit(TranslateEngine *server, OverlayFrame *overlay);
179 ~TranslateUnit();
181 void process_package(LoadPackage *package);
182 static void translation_array_f(transfer_table_f* &table,
183 float out_x1,
184 float out_x2,
185 float in_x1,
186 float in_x2,
187 int in_total,
188 int out_total,
189 int &out_x1_int,
190 int &out_x2_int);
191 void translation_array_i(transfer_table_i* &table,
192 float out_x1,
193 float out_x2,
194 float in_x1,
195 float in_x2,
196 int in_total,
197 int out_total,
198 int &out_x1_int,
199 int &out_x2_int);
200 void translate(VFrame *output,
201 VFrame *input,
202 float in_x1,
203 float in_y1,
204 float in_x2,
205 float in_y2,
206 float out_x1,
207 float out_y1,
208 float out_x2,
209 float out_y2,
210 float alpha,
211 int mode,
212 int row1,
213 int row2);
215 OverlayFrame *overlay;
216 TranslateEngine *engine;
219 class TranslateEngine : public LoadServer
221 public:
222 TranslateEngine(OverlayFrame *overlay, int cpus);
223 ~TranslateEngine();
225 void init_packages();
226 LoadClient* new_client();
227 LoadPackage* new_package();
229 OverlayFrame *overlay;
230 // Global parameters for translate units
231 VFrame *translate_output;
232 VFrame *translate_input;
233 float translate_in_x1;
234 float translate_in_y1;
235 float translate_in_x2;
236 float translate_in_y2;
237 float translate_out_x1;
238 float translate_out_y1;
239 float translate_out_x2;
240 float translate_out_y2;
241 float translate_alpha;
242 int translate_mode;
253 class ScaleTranslateEngine;
255 class ScaleTranslatePackage : public LoadPackage
257 public:
258 ScaleTranslatePackage();
260 int out_row1, out_row2;
264 class ScaleTranslateUnit : public LoadClient
266 public:
267 ScaleTranslateUnit(ScaleTranslateEngine *server, OverlayFrame *overlay);
268 ~ScaleTranslateUnit();
270 void process_package(LoadPackage *package);
271 void scale_array(int* &table,
272 int out_x1,
273 int out_x2,
274 int in_x1,
275 int in_x2,
276 int is_x);
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 int in_x1;
299 int in_y1;
300 int in_x2;
301 int 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