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
];
113 char timecodeformat
[BCTEXTLEN
];
114 // Width of the stroke
150 // character in 8 bit charset
152 // character in UCS-4
154 int width
, height
, pitch
, advance_w
, left
, top
, freetype_index
;
165 // Draw a single character into the glyph cache
167 class GlyphPackage
: public LoadPackage
175 class GlyphUnit
: public LoadClient
178 GlyphUnit(TitleMain
*plugin
, GlyphEngine
*server
);
180 void process_package(LoadPackage
*package
);
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
191 GlyphEngine(TitleMain
*plugin
, int cpus
);
192 void init_packages();
193 LoadClient
* new_client();
194 LoadPackage
* new_package();
204 // Copy a single character to the text mask
205 class TitlePackage
: public LoadPackage
213 class TitleUnit
: public LoadClient
216 TitleUnit(TitleMain
*plugin
, TitleEngine
*server
);
217 void process_package(LoadPackage
*package
);
218 void draw_glyph(VFrame
*output
, TitleGlyph
*glyph
, int x
, int y
);
222 class TitleEngine
: public LoadServer
225 TitleEngine(TitleMain
*plugin
, int cpus
);
226 void init_packages();
227 LoadClient
* new_client();
228 LoadPackage
* new_package();
241 // Overlay text mask with fractional translation
242 // We don't use OverlayFrame to enable alpha blending on non alpha
244 class TitleTranslatePackage
: public LoadPackage
247 TitleTranslatePackage();
252 class TitleTranslateUnit
: public LoadClient
255 TitleTranslateUnit(TitleMain
*plugin
, TitleTranslate
*server
);
256 void process_package(LoadPackage
*package
);
260 class TitleTranslate
: public LoadServer
263 TitleTranslate(TitleMain
*plugin
, int cpus
);
265 void init_packages();
266 LoadClient
* new_client();
267 LoadPackage
* new_package();
269 transfer_table_f
*y_table
;
270 transfer_table_f
*x_table
;
273 // Result of translation_array_f
298 // Position of each character relative to total text extents
302 } title_char_position_t
;
306 class TitleMain
: public PluginVClient
309 TitleMain(PluginServer
*server
);
312 // required for all realtime plugins
313 int process_realtime(VFrame
*input_ptr
, VFrame
*output_ptr
);
316 char* plugin_title();
321 int load_configuration();
322 void save_data(KeyFrame
*keyframe
);
323 void read_data(KeyFrame
*keyframe
);
334 FontEntry
* get_font_entry(char *title
,
337 FontEntry
* get_font();
338 int get_char_advance(int current
, int next
);
339 int get_char_height();
340 void get_total_extents();
342 int load_freetype_face(FT_Library
&freetype_library
,
343 FT_Face
&freetype_face
,
350 static char* motion_to_text(int motion
);
351 static int text_to_motion(char *text
);
352 // a thread for the GUI
354 // Current configuration
357 int window_w
, window_h
;
359 static ArrayList
<FontEntry
*> *fonts
;
362 ArrayList
<TitleGlyph
*> glyphs
;
365 // Stage 1 parameters must be compared to redraw the 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
383 // relative position of all text to output
388 // relative position of visible part of text to output
395 // Must be calculated from rendering characters
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.
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
415 VFrame
*input
, *output
;
417 int need_reconfigure
;