Fixed initialisation of tf in file_open(). Without setting the memory to 0,
[cinelerra_cv/mob.git] / plugins / titler / title.h
blob19c24ab0947bc1f660c881eafc37b509d302b991
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 "bchash.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 // Time Code Format
113 char timecodeformat[BCTEXTLEN];
114 // Width of the stroke
115 double stroke_width;
118 class FontEntry
120 public:
121 FontEntry();
122 ~FontEntry();
124 void dump();
126 char *path;
127 char *foundary;
128 char *family;
129 char *weight;
130 char *slant;
131 char *swidth;
132 char *adstyle;
133 int pixelsize;
134 int pointsize;
135 int xres;
136 int yres;
137 char *spacing;
138 int avg_width;
139 char *registry;
140 char *encoding;
141 char *fixed_title;
142 int fixed_style;
145 class TitleGlyph
147 public:
148 TitleGlyph();
149 ~TitleGlyph();
150 // character in 8 bit charset
151 int c;
152 // character in UCS-4
153 FT_ULong char_code;
154 int width, height, pitch, advance_w, left, top, freetype_index;
155 VFrame *data;
156 VFrame *data_stroke;
165 // Draw a single character into the glyph cache
167 class GlyphPackage : public LoadPackage
169 public:
170 GlyphPackage();
171 TitleGlyph *glyph;
175 class GlyphUnit : public LoadClient
177 public:
178 GlyphUnit(TitleMain *plugin, GlyphEngine *server);
179 ~GlyphUnit();
180 void process_package(LoadPackage *package);
182 TitleMain *plugin;
183 FontEntry *current_font; // Current font configured by freetype
184 FT_Library freetype_library; // Freetype library
185 FT_Face freetype_face;
188 class GlyphEngine : public LoadServer
190 public:
191 GlyphEngine(TitleMain *plugin, int cpus);
192 void init_packages();
193 LoadClient* new_client();
194 LoadPackage* new_package();
195 TitleMain *plugin;
204 // Copy a single character to the text mask
205 class TitlePackage : public LoadPackage
207 public:
208 TitlePackage();
209 int x, y, c;
213 class TitleUnit : public LoadClient
215 public:
216 TitleUnit(TitleMain *plugin, TitleEngine *server);
217 void process_package(LoadPackage *package);
218 void draw_glyph(VFrame *output, TitleGlyph *glyph, int x, int y);
219 TitleMain *plugin;
222 class TitleEngine : public LoadServer
224 public:
225 TitleEngine(TitleMain *plugin, int cpus);
226 void init_packages();
227 LoadClient* new_client();
228 LoadPackage* new_package();
229 TitleMain *plugin;
241 // Overlay text mask with fractional translation
242 // We don't use OverlayFrame to enable alpha blending on non alpha
243 // output.
244 class TitleTranslatePackage : public LoadPackage
246 public:
247 TitleTranslatePackage();
248 int y1, y2;
252 class TitleTranslateUnit : public LoadClient
254 public:
255 TitleTranslateUnit(TitleMain *plugin, TitleTranslate *server);
256 void process_package(LoadPackage *package);
257 TitleMain *plugin;
260 class TitleTranslate : public LoadServer
262 public:
263 TitleTranslate(TitleMain *plugin, int cpus);
264 ~TitleTranslate();
265 void init_packages();
266 LoadClient* new_client();
267 LoadPackage* new_package();
268 TitleMain *plugin;
269 transfer_table_f *y_table;
270 transfer_table_f *x_table;
271 int output_w;
272 int output_h;
273 // Result of translation_array_f
274 int out_x1_int;
275 int out_x2_int;
276 int out_y1_int;
277 int out_y2_int;
278 // Values to process
279 int out_x1;
280 int out_x2;
281 int out_y1;
282 int out_y2;
298 // Position of each character relative to total text extents
299 typedef struct
301 int x, y, w;
302 } title_char_position_t;
306 class TitleMain : public PluginVClient
308 public:
309 TitleMain(PluginServer *server);
310 ~TitleMain();
312 // required for all realtime plugins
313 int process_realtime(VFrame *input_ptr, VFrame *output_ptr);
314 int is_realtime();
315 int is_synthesis();
316 char* plugin_title();
317 int show_gui();
318 void raise_window();
319 void update_gui();
320 int set_string();
321 int load_configuration();
322 void save_data(KeyFrame *keyframe);
323 void read_data(KeyFrame *keyframe);
324 int load_defaults();
325 int save_defaults();
326 VFrame* new_picon();
330 void build_fonts();
331 void draw_glyphs();
332 int draw_mask();
333 void overlay_mask();
334 FontEntry* get_font_entry(char *title,
335 int style,
336 int size);
337 FontEntry* get_font();
338 int get_char_advance(int current, int next);
339 int get_char_height();
340 void get_total_extents();
341 void clear_glyphs();
342 int load_freetype_face(FT_Library &freetype_library,
343 FT_Face &freetype_face,
344 char *path);
350 static char* motion_to_text(int motion);
351 static int text_to_motion(char *text);
352 // a thread for the GUI
353 TitleThread *thread;
354 // Current configuration
355 TitleConfig config;
356 // Size of window
357 int window_w, window_h;
359 static ArrayList<FontEntry*> *fonts;
361 BC_Hash *defaults;
362 ArrayList<TitleGlyph*> glyphs;
363 Mutex glyph_lock;
365 // Stage 1 parameters must be compared to redraw the text mask
366 VFrame *text_mask;
367 VFrame *text_mask_stroke;
368 GlyphEngine *glyph_engine;
369 TitleEngine *title_engine;
370 TitleTranslate *translate;
372 // Necessary to get character width
373 FT_Library freetype_library; // Freetype library
374 FT_Face freetype_face;
376 // Visible area of all text present in the mask.
377 // Horizontal characters aren't clipped because column positions are
378 // proportional.
379 int visible_row1;
380 int visible_row2;
381 int visible_char1;
382 int visible_char2;
383 // relative position of all text to output
384 float text_y1;
385 float text_y2;
386 float text_x1;
387 float text_x2;
388 // relative position of visible part of text to output
389 float mask_y1;
390 float mask_y2;
392 // Fade value
393 int alpha;
395 // Must be calculated from rendering characters
396 int ascent;
397 // Relative position of mask to output is text_x1, mask_y1
398 // We can either round it to nearest ints to speed up replication while the text
399 // itself is offset fractionally
400 // or replicate with fractional offsetting. Since fraction offsetting usually
401 // happens during motion and motion would require floating point offsetting
402 // for every frame we replicate with fractional offsetting.
406 // Text is always row aligned to mask boundaries.
407 int text_len;
408 int text_rows;
409 int text_w;
410 int text_h;
411 // Position of each character relative to total text extents
412 title_char_position_t *char_positions;
413 // Positions of the bottom pixels of the rows
414 int *rows_bottom;
415 VFrame *input, *output;
417 int need_reconfigure;
421 #endif