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
19 // Performed every frame.
20 // The text mask is overlayed with fractional translation and fading on the output.
33 #include "loadbalance.h"
35 #include "overlayframe.h"
36 #include "pluginvclient.h"
37 #include "titlewindow.h"
40 #include FT_FREETYPE_H
41 #include <sys/types.h>
44 #define FONT_ITALIC 0x1
46 #define FONT_OUTLINE 0x4
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
72 // Only used to clear glyphs
73 int equivalent(TitleConfig &that);
74 void copy_from(TitleConfig &that);
75 void interpolate(TitleConfig &prev,
79 int64_t current_frame);
88 // Motion of title across frame
93 float pixels_per_second;
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
100 // Pixels down and right of dropshadow
102 // Calculated during every frame for motion strategy
103 int64_t prev_keyframe_position;
104 int64_t next_keyframe_position;
109 char text[BCTEXTLEN];
110 // Encoding to convert from
111 char encoding[BCTEXTLEN];
112 // Width of the stroke
148 // character in 8 bit charset
150 // character in UCS-4
152 int width, height, pitch, advance_w, left, top, freetype_index;
163 // Draw a single character into the glyph cache
165 class GlyphPackage : public LoadPackage
173 class GlyphUnit : public LoadClient
176 GlyphUnit(TitleMain *plugin, GlyphEngine *server);
178 void process_package(LoadPackage *package);
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
189 GlyphEngine(TitleMain *plugin, int cpus);
190 void init_packages();
191 LoadClient* new_client();
192 LoadPackage* new_package();
202 // Copy a single character to the text mask
203 class TitlePackage : public LoadPackage
211 class TitleUnit : public LoadClient
214 TitleUnit(TitleMain *plugin, TitleEngine *server);
215 void process_package(LoadPackage *package);
216 void draw_glyph(VFrame *output, TitleGlyph *glyph, int x, int y);
220 class TitleEngine : public LoadServer
223 TitleEngine(TitleMain *plugin, int cpus);
224 void init_packages();
225 LoadClient* new_client();
226 LoadPackage* new_package();
239 // Overlay text mask with fractional translation
240 // We don't use OverlayFrame to enable alpha blending on non alpha
242 class TitleTranslatePackage : public LoadPackage
245 TitleTranslatePackage();
250 class TitleTranslateUnit : public LoadClient
253 TitleTranslateUnit(TitleMain *plugin, TitleTranslate *server);
254 void process_package(LoadPackage *package);
258 class TitleTranslate : public LoadServer
261 TitleTranslate(TitleMain *plugin, int cpus);
263 void init_packages();
264 LoadClient* new_client();
265 LoadPackage* new_package();
267 transfer_table_f *y_table;
268 transfer_table_f *x_table;
271 // Result of translation_array_f
296 // Position of each character relative to total text extents
300 } title_char_position_t;
304 class TitleMain : public PluginVClient
307 TitleMain(PluginServer *server);
310 // required for all realtime plugins
311 int process_realtime(VFrame *input_ptr, VFrame *output_ptr);
314 char* plugin_title();
319 int load_configuration();
320 void save_data(KeyFrame *keyframe);
321 void read_data(KeyFrame *keyframe);
331 FontEntry* get_font_entry(char *title,
334 FontEntry* get_font();
335 int get_char_advance(int current, int next);
336 int get_char_height();
337 void get_total_extents();
339 int load_freetype_face(FT_Library &freetype_library,
340 FT_Face &freetype_face,
347 static char* motion_to_text(int motion);
348 static int text_to_motion(char *text);
349 // a thread for the GUI
351 // Current configuration
354 int window_w, window_h;
356 static ArrayList<FontEntry*> *fonts;
359 ArrayList<TitleGlyph*> glyphs;
362 // Stage 1 parameters must be compared to redraw the text mask
364 VFrame *text_mask_stroke;
365 GlyphEngine *glyph_engine;
366 TitleEngine *title_engine;
367 TitleTranslate *translate;
369 // Necessary to get character width
370 FT_Library freetype_library; // Freetype library
371 FT_Face freetype_face;
373 // Visible area of all text present in the mask.
374 // Horizontal characters aren't clipped because column positions are
380 // relative position of all text to output
385 // relative position of visible part of text to output
392 // Must be calculated from rendering characters
394 // Relative position of mask to output is text_x1, mask_y1
395 // We can either round it to nearest ints to speed up replication while the text
396 // itself is offset fractionally
397 // or replicate with fractional offsetting. Since fraction offsetting usually
398 // happens during motion and motion would require floating point offsetting
399 // for every frame we replicate with fractional offsetting.
403 // Text is always row aligned to mask boundaries.
408 // Position of each character relative to total text extents
409 title_char_position_t *char_positions;
410 // Positions of the bottom pixels of the rows
412 VFrame *input, *output;
414 int need_reconfigure;