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
26 #define KW_NUDGE _("nudge")
27 #define KW_COLOR _("color")
28 #define KW_ALPHA _("alpha")
29 #define KW_FONT _("font")
30 #define KW_SIZE _("size")
31 #define KW_BOLD _("bold")
32 #define KW_ITALIC _("italic")
33 #define KW_CAPS _("caps")
35 #define KW_BLINK _("blink")
36 #define KW_FIXED _("fixed")
37 #define KW_SUP _("sup")
38 #define KW_PNG _("png")
55 class TitleOutlinePackage;
56 class TitleOutlineUnit;
57 class TitleOutlineEngine;
58 class TitleTranslatePackage;
59 class TitleTranslateUnit;
77 #include "bcfontentry.h"
79 #include "indexable.inc"
80 #include "loadbalance.h"
82 #include "overlayframe.h"
83 #include "pluginvclient.h"
84 #include "renderengine.inc"
85 #include "titlerwindow.h"
88 #include FT_FREETYPE_H
89 #include <sys/types.h>
96 #define BOTTOM_TO_TOP 0x1
97 #define TOP_TO_BOTTOM 0x2
98 #define RIGHT_TO_LEFT 0x3
99 #define LEFT_TO_RIGHT 0x4
101 // Horizontal justification
102 #define JUSTIFY_LEFT 0x0
103 #define JUSTIFY_CENTER 0x1
104 #define JUSTIFY_RIGHT 0x2
106 // Vertical justification
107 #define JUSTIFY_TOP 0x0
108 #define JUSTIFY_MID 0x1
109 #define JUSTIFY_BOTTOM 0x2
115 #define FLAG_UNDER 0x0001
116 #define FLAG_FIXED 0x0002
117 #define FLAG_SUPER 0x0004
118 #define FLAG_SUBER 0x0008
119 #define FLAG_BLINK 0x0010
127 void to_wtext(const char *from_enc, const char *text, int tlen);
128 // Only used to clear glyphs
129 int equivalent(TitleConfig &that);
130 void copy_from(TitleConfig &that);
131 void interpolate(TitleConfig &prev,
135 int64_t current_frame);
138 char font[BCTEXTLEN];
139 // Encoding to convert from
140 char encoding[BCTEXTLEN];
150 int motion_strategy; // Motion of title across frame
152 int loop; // Loop motion path
155 // Number of seconds the fade in and fade out of the title take
156 double fade_in, fade_out;
157 float pixels_per_second; // Speed of motion
159 wchar_t wtext[3*BCTEXTLEN];
161 // Position in frame relative to top left
162 float title_x, title_y;
163 int title_w, title_h;
165 int window_w, window_h;
166 // Calculated during every frame for motion strategy
167 int64_t prev_keyframe_position;
168 int64_t next_keyframe_position;
173 char background_path[BCTEXTLEN];
181 // loop background playback
194 int width, height, style;
197 int left, top, right, bottom;
198 VFrame *data, *data_stroke;
200 class TitleGlyphs : public ArrayList<TitleGlyph *> {
202 void clear() { remove_all_objects(); }
203 int count() { return size(); }
206 ~TitleGlyphs() { clear(); }
214 TitleImage(const char *path, VFrame *vfrm);
217 class TitleImages : public ArrayList<TitleImage *> {
219 void clear() { remove_all_objects(); }
220 int count() { return size(); }
223 ~TitleImages() { clear(); }
227 // Position of each image box in a row
239 TitleChar *init(int typ, void *vp);
241 class TitleChars : public ArrayList<TitleChar *> {
244 void reset() { next = 0; }
245 void clear() { remove_all_objects(); reset(); }
246 int count() { return next; }
247 TitleChar *add(int typ, void *vp) {
248 TitleChar *ret = next < size() ? get(next++) : 0;
249 if( !ret ) { append(ret = new TitleChar()); next = size(); }
250 return ret->init(typ, vp);
252 TitleChars() { reset(); }
253 ~TitleChars() { clear(); }
258 float x0, y0, x1, y1, x2, y2;
260 void bound(float lt, float tp, float rt, float bt) {
261 if( x1 > lt ) x1 = lt;
262 if( y1 < tp ) y1 = tp;
263 if( x2 < rt ) x2 = rt;
264 if( y2 > bt ) y2 = bt;
267 class TitleRows : public ArrayList<TitleRow *> {
270 void reset() { next = 0; }
271 void clear() { remove_all_objects(); reset(); }
272 int count() { return next; }
274 TitleRow *ret = next < size() ? get(next++) : 0;
275 if( !ret ) { append(ret = new TitleRow()); next = size(); }
278 TitleRows() { reset(); }
279 ~TitleRows() { clear(); }
282 // Draw a single character into the glyph cache
284 class GlyphPackage : public LoadPackage
292 class GlyphUnit : public LoadClient
295 GlyphUnit(TitleMain *plugin, GlyphEngine *server);
297 void process_package(LoadPackage *package);
300 FT_Library freetype_library; // Freetype library
301 FT_Face freetype_face;
304 class GlyphEngine : public LoadServer
307 GlyphEngine(TitleMain *plugin, int cpus);
308 void init_packages();
309 LoadClient* new_client();
310 LoadPackage* new_package();
315 // Copy a single character to the text mask
316 class TitlePackage : public LoadPackage
329 class TitleUnit : public LoadClient
332 TitleUnit(TitleMain *plugin, TitleEngine *server);
333 void process_package(LoadPackage *package);
334 void draw_frame(int mode, VFrame *dst, VFrame *src, int x, int y);
341 class TitleEngine : public LoadServer
344 TitleEngine(TitleMain *plugin, int cpus);
345 void init_packages();
346 LoadClient* new_client();
347 LoadPackage* new_package();
354 class TitleOutlinePackage : public LoadPackage
357 TitleOutlinePackage();
362 class TitleOutlineUnit : public LoadClient
365 TitleOutlineUnit(TitleMain *plugin, TitleOutlineEngine *server);
366 void process_package(LoadPackage *package);
368 TitleOutlineEngine *engine;
371 class TitleOutlineEngine : public LoadServer
374 TitleOutlineEngine(TitleMain *plugin, int cpus);
375 void init_packages();
377 LoadClient* new_client();
378 LoadPackage* new_package();
383 template<class typ> class TitleStack : public ArrayList<typ>
385 typ &last() { return ArrayList<typ>::last(); }
386 int size() { return ArrayList<typ>::size(); }
387 typ &append(typ &v) { return ArrayList<typ>::append(v); }
388 void remove() { return ArrayList<typ>::remove(); }
391 TitleStack(TitleParser *p, typ v) : parser(p) { append(v); }
392 operator typ&() { return last(); }
393 typ &push(typ &v) { return append(v); }
394 int pop() { return size()>1 ? (remove(),0) : 1; }
395 int set(const char *txt);
396 int unset(const char *txt);
399 template<class typ> int TitleStack<typ>::set(const char *txt)
401 typ v = !*txt ? 1 : strtol(txt,(char **)&txt,0);
402 if( *txt || v < 0 || v > 1 ) return 1;
406 template<class typ> int TitleStack<typ>::unset(const char *txt)
411 class TitleCurNudge : public TitleStack<int> {
413 TitleCurNudge(TitleParser *parser, TitleMain *plugin);
414 int set(const char *txt);
417 class TitleCurColor : public TitleStack<int> {
419 TitleCurColor(TitleParser *parser, TitleMain *plugin);
420 int set(const char *txt);
423 class TitleCurAlpha : public TitleStack<int> {
425 TitleCurAlpha(TitleParser *parser, TitleMain *plugin);
426 int set(const char *txt);
429 class TitleCurSize : public TitleStack<float> {
431 TitleCurSize(TitleParser *parser, TitleMain *plugin);
432 int set(const char *txt);
433 int unset(const char *txt);
436 class TitleCurBold : public TitleStack<int> {
438 TitleCurBold(TitleParser *parser, TitleMain *plugin);
439 int set(const char *txt);
440 int unset(const char *txt);
443 class TitleCurItalic : public TitleStack<int> {
445 TitleCurItalic(TitleParser *parser, TitleMain *plugin);
446 int set(const char *txt);
447 int unset(const char *txt);
450 class TitleCurFont : public TitleStack<BC_FontEntry*>
453 BC_FontEntry *get(const char *txt, int style);
454 BC_FontEntry *set(const char *txt, int style);
456 virtual int set(const char *txt=0);
457 virtual int unset(const char *txt);
458 TitleCurFont(TitleParser *parser, TitleMain *plugin);
461 class TitleCurCaps : public TitleStack<int> {
463 TitleCurCaps(TitleParser *parser, TitleMain *plugin);
464 int set(const char *txt);
467 class TitleCurUnder : public TitleStack<int> {
469 TitleCurUnder(TitleParser *parser, TitleMain *plugin);
472 class TitleCurBlink : public TitleStack<float> {
474 TitleCurBlink(TitleParser *parser, TitleMain *plugin);
475 int set(const char *txt);
478 class TitleCurFixed : public TitleStack<int> {
480 TitleCurFixed(TitleParser *parser, TitleMain *plugin);
481 int set(const char *txt);
484 class TitleCurSuper : public TitleStack<int> {
486 TitleCurSuper(TitleParser *parser, TitleMain *plugin);
487 int set(const char *txt);
493 const wchar_t *bfr, *out, *lmt;
497 long tell() { return out - bfr; }
498 void seek(long pos) { out = bfr + pos; }
499 bool eof() { return out >= lmt; }
500 int wcur() { return eof() ? -1 : *out; }
501 int wnext() { return eof() ? -1 : *out++; }
502 int wget(wchar_t &wch);
503 int tget(wchar_t &wch);
504 wchar_t wid[BCSTRLEN], wtxt[BCTEXTLEN];
505 char id[BCSTRLEN], text[BCTEXTLEN];
506 int set_attributes(int ret);
508 TitleCurNudge cur_nudge;
509 TitleCurColor cur_color;
510 TitleCurAlpha cur_alpha;
511 TitleCurSize cur_size;
512 TitleCurBold cur_bold;
513 TitleCurItalic cur_italic;
514 TitleCurFont cur_font;
515 TitleCurCaps cur_caps;
516 TitleCurUnder cur_under;
517 TitleCurBlink cur_blink;
518 TitleCurFixed cur_fixed;
519 TitleCurSuper cur_super;
521 TitleParser(TitleMain *main);
525 // Overlay text mask with fractional translation
526 // We don't use OverlayFrame to enable alpha blending on non alpha
528 class TitleTranslatePackage : public LoadPackage
531 TitleTranslatePackage();
535 class TitleTranslateUnit : public LoadClient
538 TitleTranslateUnit(TitleMain *plugin, TitleTranslate *server);
540 void process_package(LoadPackage *package);
544 class TitleTranslate : public LoadServer
547 TitleTranslate(TitleMain *plugin, int cpus);
552 float in_w, in_h, out_w, out_h;
553 float ix1, iy1, ix2, iy2;
554 float ox1, oy1, ox2, oy2;
556 void copy(VFrame *input);
557 LoadClient* new_client();
558 LoadPackage* new_package();
559 void init_packages();
563 class TitleMain : public PluginVClient
566 TitleMain(PluginServer *server);
569 // required for all realtime plugins
570 PLUGIN_CLASS_MEMBERS(TitleConfig)
571 int process_realtime(VFrame *input_ptr, VFrame *output_ptr);
575 void save_data(KeyFrame *keyframe);
576 void read_data(KeyFrame *keyframe);
577 void insert_text(const wchar_t *wtxt, int pos);
579 void build_previews(TitleWindow *gui);
582 int set_font(BC_FontEntry*&font, const char *txt);
583 int set_font(BC_FontEntry*&font, const char *txt, int style);
584 int set_size(int &size, const char *txt);
585 int set_color(int &color, const char *txt);
586 int set_bold(int &bold, const char *txt);
587 int set_italic(int &italic, const char *txt);
588 int set_caps(int &caps, const char *txt);
589 int set_under(int &under, const char *txt);
591 int draw_text(int need_redraw);
592 int draw_underline(VFrame *mask, int alpha);
596 int get_visible_text();
597 int check_char_code_path(FT_Library &freetype_library,
598 char *path_old, FT_ULong &char_code, char *path_new);
599 int load_freetype_face(FT_Library &freetype_library,
600 FT_Face &freetype_face, const char *path);
601 int load_font(BC_FontEntry *font);
602 Indexable *open_background(const char *filename);
603 int read_background(VFrame *frame, int64_t position, int color_model);
604 void draw_background();
605 static BC_FontEntry* get_font(const char *font_name, int style);
606 BC_FontEntry* config_font();
607 TitleGlyph *get_glyph(FT_ULong char_code, BC_FontEntry *font, int size, int style);
608 int get_width(TitleGlyph *cur, TitleGlyph *nxt);
610 VFrame *add_image(const char *path);
611 VFrame *get_image(const char *path);
613 // backward compatibility
614 void convert_encoding();
615 static const char* motion_to_text(int motion);
616 static int text_to_motion(const char *text);
620 GlyphEngine *glyph_engine;
621 TitleEngine *title_engine;
622 VFrame *outline_mask;
623 TitleOutlineEngine *outline_engine;
624 TitleTranslate *translate;
626 TitleChars title_chars;
627 TitleRows title_rows;
628 TitleGlyphs title_glyphs;
629 TitleImages title_images;
631 FT_Library freetype_library;
632 FT_Face freetype_face;
633 char text_font[BCTEXTLEN];
635 int window_w, window_h;
636 int fuzz, fuzz1, fuzz2;
637 float title_x, title_y;
638 int title_w, title_h;
640 float text_x, text_y, text_w, text_h;
641 float text_x1, text_y1, text_x2, text_y2;
643 int mask_x, mask_y; int mask_w, mask_h;
644 int mask_x1, mask_y1, mask_x2, mask_y2;
647 int visible_row1, visible_char1;
648 int visible_row2, visible_char2;
651 VFrame *input, *output;
652 int output_model, text_model, mask_model;
654 Indexable *background;
657 RenderEngine *render_engine;
658 CICache *video_cache;
659 OverlayFrame *overlay_frame;
661 int64_t last_position;
662 int need_reconfigure;