4 * Copyright (C) 1997-2014 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 // Only performed when text mask changes.
31 // Update glyph cache with every glyph used in the title.
32 // A parallel text renderer draws one character per CPU.
33 // The titler direct copies all the text currently visible onto the text mask.
34 // in integer coordinates.
35 // The text mask is in the same color space as the output but always has
39 // Performed every frame.
40 // The text mask is overlayed with fractional translation and fading on the output.
49 class TitleOutlineEngine;
54 #include "bcfontentry.h"
55 #include "loadbalance.h"
57 #include "pluginvclient.h"
58 #include "titlewindow.h"
61 #include FT_FREETYPE_H
62 #include <sys/types.h>
67 #define BOTTOM_TO_TOP 0x1
68 #define TOP_TO_BOTTOM 0x2
69 #define RIGHT_TO_LEFT 0x3
70 #define LEFT_TO_RIGHT 0x4
72 // Horizontal justification
73 #define JUSTIFY_LEFT 0x0
74 #define JUSTIFY_CENTER 0x1
75 #define JUSTIFY_RIGHT 0x2
77 // Vertical justification
78 #define JUSTIFY_TOP 0x0
79 #define JUSTIFY_MID 0x1
80 #define JUSTIFY_BOTTOM 0x2
88 void to_wtext(const char *from_enc, const char *text, int tlen);
89 // Only used to clear glyphs
90 int equivalent(TitleConfig &that);
91 void copy_from(TitleConfig &that);
92 void interpolate(TitleConfig &prev,
96 int64_t current_frame);
100 char font[BCTEXTLEN];
108 int motion_strategy; // Motion of title across frame
110 int loop; // Loop motion path
111 float pixels_per_second; // Speed of motion
114 // Number of seconds the fade in and fade out of the title take
115 double fade_in, fade_out;
116 // Position in frame relative to top left
118 // Pixels down and right of dropshadow
121 // Calculated during every frame for motion strategy
122 int64_t prev_keyframe_position;
123 int64_t next_keyframe_position;
128 wchar_t wtext[BCTEXTLEN];
132 // Encoding to convert from
133 char encoding[BCTEXTLEN];
136 // Width of the stroke
139 int window_w, window_h;
149 int width, height, pitch;
151 int left, top, right, bottom;
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 BC_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
214 class TitleUnit : public LoadClient
217 TitleUnit(TitleMain *plugin, TitleEngine *server);
218 void process_package(LoadPackage *package);
219 void draw_glyph(VFrame *output, VFrame *data, TitleGlyph *glyph, int x, int y);
224 class TitleEngine : public LoadServer
227 TitleEngine(TitleMain *plugin, int cpus);
228 void init_packages();
229 LoadClient* new_client();
230 LoadPackage* new_package();
240 class TitleOutlinePackage : public LoadPackage
243 TitleOutlinePackage();
248 class TitleOutlineUnit : public LoadClient
251 TitleOutlineUnit(TitleMain *plugin, TitleOutlineEngine *server);
252 void process_package(LoadPackage *package);
254 TitleOutlineEngine *engine;
257 class TitleOutlineEngine : public LoadServer
260 TitleOutlineEngine(TitleMain *plugin, int cpus);
261 void init_packages();
263 LoadClient* new_client();
264 LoadPackage* new_package();
277 // Overlay text mask with fractional translation
278 // We don't use OverlayFrame to enable alpha blending on non alpha
280 class TitleTranslatePackage : public LoadPackage
283 TitleTranslatePackage();
291 int in_x2; // Might be same as in_x1 for boundary
293 float output_fraction;
296 class TitleTranslateUnit : public LoadClient
299 TitleTranslateUnit(TitleMain *plugin, TitleTranslate *server);
301 static void translation_array_f(transfer_table_f* &table,
302 float out_x1, float out_x2, float in_x1, float in_x2,
303 int in_total, int out_total, int &out_x1_int, int &out_x2_int);
304 void process_package(LoadPackage *package);
308 class TitleTranslate : public LoadServer
311 TitleTranslate(TitleMain *plugin, int cpus);
313 void init_packages();
315 LoadClient* new_client();
316 LoadPackage* new_package();
318 transfer_table_f *y_table;
319 transfer_table_f *x_table;
322 // Result of translation_array_f
347 // Position of each character relative to total text extents
355 class TitleMain : public PluginVClient
358 TitleMain(PluginServer *server);
361 // required for all realtime plugins
362 PLUGIN_CLASS_MEMBERS(TitleConfig)
363 int process_realtime(VFrame *input_ptr, VFrame *output_ptr);
367 void save_data(KeyFrame *keyframe);
368 void read_data(KeyFrame *keyframe);
370 void build_previews(TitleWindow *gui);
376 TitleGlyph *get_glyph(FT_ULong char_code);
377 BC_FontEntry* get_font();
378 int get_char_advance(FT_ULong current, FT_ULong next);
379 int get_char_height();
380 int get_char_width(FT_ULong c);
381 void get_total_extents();
383 int check_char_code_path(FT_Library &freetype_library,
387 int load_freetype_face(FT_Library &freetype_library,
388 FT_Face &freetype_face,
390 void get_color_components(int *r, int *g, int *b, int *a, int is_outline);
395 // backward compatibility
396 void convert_encoding();
397 static const char* motion_to_text(int motion);
398 static int text_to_motion(const char *text);
400 ArrayList<TitleGlyph*> glyphs;
403 // Stage 1 parameters must be compared to redraw the text mask
405 VFrame *text_mask_stroke;
406 VFrame *outline_mask;
407 GlyphEngine *glyph_engine;
408 TitleEngine *title_engine;
409 TitleTranslate *translate;
410 TitleOutlineEngine *outline_engine;
412 // Necessary to get character width
413 FT_Library freetype_library; // Freetype library
414 FT_Face freetype_face;
416 // Visible area of all text present in the mask.
417 // Horizontal characters aren't clipped because column positions are
419 int visible_row1, visible_char1;
420 int visible_row2, visible_char2;
421 // Positions of the top pixels of the rows
423 public: // x1,y1 x2,y2 are abs
424 int x0, y0, x1, y1, x2, y2;
426 class RowGeom : public Geom {
427 public: // x1,x2 y1,y2 are rel x0,y0
428 int left() { return x0+x1; }
429 int top() { return y0+y1; }
430 int right() { return x0+x2; }
431 int bottom() { return y0+y2; }
436 // relative position of all text to output
438 float text_x1, text_y1, text_x2, text_y2;
439 // Position of each character relative to total text extents
440 char_pos_t *char_pos;
441 // relative position of visible part of text to output
447 // Max dimensions for all characters. Not equal to config.size
448 // Must be calculated from rendering characters
451 // Relative position of mask to output is text_x1, mask_y1
452 // We can either round it to nearest ints to speed up replication while the text
453 // itself is offset fractionally
454 // or replicate with fractional offsetting. Since fraction offsetting usually
455 // happens during motion and motion would require floating point offsetting
456 // for every frame we replicate with fractional offsetting.
460 VFrame *input, *output;
462 int need_reconfigure;