r125: This commit was manufactured by cvs2svn to create tag 'r1_1_7-last'.
[cinelerra_cv/mob.git] / hvirtual / plugins / titler / title.h
blobe5a3a024d6d90bbb5ce76a6349f676651fe4fc03
1 #ifndef TITLE_H
2 #define TITLE_H
7 // Theory:
9 // Stage 1:
10 // Only performed when text mask changes.
11 // Update glyph cache with every glyph used in the title.
12 // A parallel text renderer draws one character per CPU.
13 // The titler direct copies all the text currently visible onto the text mask.
14 // in integer coordinates.
15 // The text mask is in the same color space as the output but always has
16 // an alpha channel.
18 // Stage 2:
19 // Performed every frame.
20 // The text mask is overlayed with fractional translation and fading on the output.
27 class TitleMain;
28 class TitleEngine;
29 class GlyphEngine;
30 class TitleTranslate;
32 #include "defaults.h"
33 #include "loadbalance.h"
34 #include "mutex.h"
35 #include "overlayframe.h"
36 #include "pluginvclient.h"
37 #include "titlewindow.h"
39 #include <ft2build.h>
40 #include FT_FREETYPE_H
41 #include <sys/types.h>
43 // Style bitwise ORed
44 #define FONT_ITALIC 0x1
45 #define FONT_BOLD 0x2
46 #define FONT_OUTLINE 0x4
48 // Motion strategy
49 #define TOTAL_PATHS 5
50 #define NO_MOTION 0x0
51 #define BOTTOM_TO_TOP 0x1
52 #define TOP_TO_BOTTOM 0x2
53 #define RIGHT_TO_LEFT 0x3
54 #define LEFT_TO_RIGHT 0x4
56 // Horizontal justification
57 #define JUSTIFY_LEFT 0x0
58 #define JUSTIFY_CENTER 0x1
59 #define JUSTIFY_RIGHT 0x2
61 // Vertical justification
62 #define JUSTIFY_TOP 0x0
63 #define JUSTIFY_MID 0x1
64 #define JUSTIFY_BOTTOM 0x2
67 class TitleConfig
69 public:
70 TitleConfig();
72 // Only used to clear glyphs
73 int equivalent(TitleConfig &that);
74 void copy_from(TitleConfig &that);
75 void interpolate(TitleConfig &prev,
76 TitleConfig &next,
77 int64_t prev_frame,
78 int64_t next_frame,
79 int64_t current_frame);
82 // Font information
83 char font[BCTEXTLEN];
84 int64_t style;
85 int size;
86 int color;
87 int color_stroke;
88 // Motion of title across frame
89 int motion_strategy;
90 // Loop motion path
91 int loop;
92 // Speed of motion
93 float pixels_per_second;
94 int hjustification;
95 int vjustification;
96 // Number of seconds the fade in and fade out of the title take
97 double fade_in, fade_out;
98 // Position in frame relative to top left
99 float x, y;
100 // Pixels down and right of dropshadow
101 int dropshadow;
102 // Calculated during every frame for motion strategy
103 int64_t prev_keyframe_position;
104 int64_t next_keyframe_position;
105 // Stamp timecode
106 int timecode;
108 // Text to display
109 char text[BCTEXTLEN];
110 // Encoding to convert from
111 char encoding[BCTEXTLEN];
112 // Width of the stroke
113 double stroke_width;
116 class FontEntry
118 public:
119 FontEntry();
120 ~FontEntry();
122 void dump();
124 char *path;
125 char *foundary;
126 char *family;
127 char *weight;
128 char *slant;
129 char *swidth;
130 char *adstyle;
131 int pixelsize;
132 int pointsize;
133 int xres;
134 int yres;
135 char *spacing;
136 int avg_width;
137 char *registry;
138 char *encoding;
139 char *fixed_title;
140 int fixed_style;
143 class TitleGlyph
145 public:
146 TitleGlyph();
147 ~TitleGlyph();
148 // character in 8 bit charset
149 int c;
150 // character in UCS-4
151 FT_ULong char_code;
152 int width, height, pitch, advance_w, left, top, freetype_index;
153 VFrame *data;
154 VFrame *data_stroke;
163 // Draw a single character into the glyph cache
165 class GlyphPackage : public LoadPackage
167 public:
168 GlyphPackage();
169 TitleGlyph *glyph;
173 class GlyphUnit : public LoadClient
175 public:
176 GlyphUnit(TitleMain *plugin, GlyphEngine *server);
177 ~GlyphUnit();
178 void process_package(LoadPackage *package);
180 TitleMain *plugin;
181 FontEntry *current_font; // Current font configured by freetype
182 FT_Library freetype_library; // Freetype library
183 FT_Face freetype_face;
186 class GlyphEngine : public LoadServer
188 public:
189 GlyphEngine(TitleMain *plugin, int cpus);
190 void init_packages();
191 LoadClient* new_client();
192 LoadPackage* new_package();
193 TitleMain *plugin;
202 // Copy a single character to the text mask
203 class TitlePackage : public LoadPackage
205 public:
206 TitlePackage();
207 int x, y, c;
211 class TitleUnit : public LoadClient
213 public:
214 TitleUnit(TitleMain *plugin, TitleEngine *server);
215 void process_package(LoadPackage *package);
216 void draw_glyph(VFrame *output, TitleGlyph *glyph, int x, int y);
217 TitleMain *plugin;
220 class TitleEngine : public LoadServer
222 public:
223 TitleEngine(TitleMain *plugin, int cpus);
224 void init_packages();
225 LoadClient* new_client();
226 LoadPackage* new_package();
227 TitleMain *plugin;
239 // Overlay text mask with fractional translation
240 // We don't use OverlayFrame to enable alpha blending on non alpha
241 // output.
242 class TitleTranslatePackage : public LoadPackage
244 public:
245 TitleTranslatePackage();
246 int y1, y2;
250 class TitleTranslateUnit : public LoadClient
252 public:
253 TitleTranslateUnit(TitleMain *plugin, TitleTranslate *server);
254 void process_package(LoadPackage *package);
255 TitleMain *plugin;
258 class TitleTranslate : public LoadServer
260 public:
261 TitleTranslate(TitleMain *plugin, int cpus);
262 ~TitleTranslate();
263 void init_packages();
264 LoadClient* new_client();
265 LoadPackage* new_package();
266 TitleMain *plugin;
267 transfer_table_f *y_table;
268 transfer_table_f *x_table;
269 int output_w;
270 int output_h;
271 // Result of translation_array_f
272 int out_x1_int;
273 int out_x2_int;
274 int out_y1_int;
275 int out_y2_int;
276 // Values to process
277 int out_x1;
278 int out_x2;
279 int out_y1;
280 int out_y2;
296 // Position of each character relative to total text extents
297 typedef struct
299 int x, y, w;
300 } title_char_position_t;
304 class TitleMain : public PluginVClient
306 public:
307 TitleMain(PluginServer *server);
308 ~TitleMain();
310 // required for all realtime plugins
311 int process_realtime(VFrame *input_ptr, VFrame *output_ptr);
312 int is_realtime();
313 int is_synthesis();
314 char* plugin_title();
315 int show_gui();
316 void raise_window();
317 void update_gui();
318 int set_string();
319 int load_configuration();
320 void save_data(KeyFrame *keyframe);
321 void read_data(KeyFrame *keyframe);
322 int load_defaults();
323 int save_defaults();
324 VFrame* new_picon();
328 void build_fonts();
329 void draw_glyphs();
330 int draw_mask();
331 void overlay_mask();
332 FontEntry* get_font_entry(char *title,
333 int style,
334 int size);
335 FontEntry* get_font();
336 int get_char_advance(int current, int next);
337 int get_char_height();
338 void get_total_extents();
339 void clear_glyphs();
340 int load_freetype_face(FT_Library &freetype_library,
341 FT_Face &freetype_face,
342 char *path);
348 static char* motion_to_text(int motion);
349 static int text_to_motion(char *text);
350 // a thread for the GUI
351 TitleThread *thread;
352 // Current configuration
353 TitleConfig config;
354 // Size of window
355 int window_w, window_h;
357 static ArrayList<FontEntry*> *fonts;
359 Defaults *defaults;
360 ArrayList<TitleGlyph*> glyphs;
361 Mutex glyph_lock;
363 // Stage 1 parameters must be compared to redraw the text mask
364 VFrame *text_mask;
365 VFrame *text_mask_stroke;
366 GlyphEngine *glyph_engine;
367 TitleEngine *title_engine;
368 TitleTranslate *translate;
370 // Necessary to get character width
371 FT_Library freetype_library; // Freetype library
372 FT_Face freetype_face;
374 // Visible area of all text present in the mask.
375 // Horizontal characters aren't clipped because column positions are
376 // proportional.
377 int visible_row1;
378 int visible_row2;
379 int visible_char1;
380 int visible_char2;
381 // relative position of all text to output
382 float text_y1;
383 float text_y2;
384 float text_x1;
385 float text_x2;
386 // relative position of visible part of text to output
387 float mask_y1;
388 float mask_y2;
390 // Fade value
391 int alpha;
393 // Must be calculated from rendering characters
394 int ascent;
395 // Relative position of mask to output is text_x1, mask_y1
396 // We can either round it to nearest ints to speed up replication while the text
397 // itself is offset fractionally
398 // or replicate with fractional offsetting. Since fraction offsetting usually
399 // happens during motion and motion would require floating point offsetting
400 // for every frame we replicate with fractional offsetting.
404 // Text is always row aligned to mask boundaries.
405 int text_len;
406 int text_rows;
407 int text_w;
408 int text_h;
409 // Position of each character relative to total text extents
410 title_char_position_t *char_positions;
411 // Positions of the bottom pixels of the rows
412 int *rows_bottom;
413 VFrame *input, *output;
415 int need_reconfigure;
419 #endif