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_ALIAS _("smooth")
38 #define KW_SUP _("sup")
39 #define KW_PNG _("png")
56 class TitleOutlinePackage;
57 class TitleOutlineUnit;
58 class TitleOutlineEngine;
59 class TitleTranslatePackage;
60 class TitleTranslateUnit;
79 #include "bcfontentry.h"
81 #include "indexable.inc"
82 #include "loadbalance.h"
84 #include "overlayframe.h"
85 #include "pluginvclient.h"
86 #include "renderengine.inc"
87 #include "titlerwindow.h"
90 #include FT_FREETYPE_H
91 #include <sys/types.h>
98 #define BOTTOM_TO_TOP 0x1
99 #define TOP_TO_BOTTOM 0x2
100 #define RIGHT_TO_LEFT 0x3
101 #define LEFT_TO_RIGHT 0x4
103 // Horizontal justification
104 #define JUSTIFY_LEFT 0x0
105 #define JUSTIFY_CENTER 0x1
106 #define JUSTIFY_RIGHT 0x2
108 // Vertical justification
109 #define JUSTIFY_TOP 0x0
110 #define JUSTIFY_MID 0x1
111 #define JUSTIFY_BOTTOM 0x2
118 #define FLAG_UNDER 0x0001
119 #define FLAG_FIXED 0x0002
120 #define FLAG_SUPER 0x0004
121 #define FLAG_SUBER 0x0008
122 #define FLAG_BLINK 0x0010
124 #define FONT_ALIAS 0x08
132 void to_wtext(const char *from_enc, const char *text, int tlen);
133 // Only used to clear glyphs
134 int equivalent(TitleConfig &that);
135 void copy_from(TitleConfig &that);
136 void interpolate(TitleConfig &prev,
140 int64_t current_frame);
143 char font[BCTEXTLEN];
144 // Encoding to convert from
145 char encoding[BCTEXTLEN];
155 int motion_strategy; // Motion of title across frame
157 int loop; // Loop motion path
160 // Number of seconds the fade in and fade out of the title take
161 double fade_in, fade_out;
162 float pixels_per_second; // Speed of motion
164 wchar_t wtext[3*BCTEXTLEN];
166 // Position in frame relative to top left
167 float title_x, title_y;
168 int title_w, title_h;
170 int window_w, window_h;
171 // Calculated during every frame for motion strategy
172 int64_t prev_keyframe_position;
173 int64_t next_keyframe_position;
178 char background_path[BCTEXTLEN];
186 // loop background playback
199 int width, height, style;
202 int left, top, right, bottom;
203 VFrame *data, *data_stroke;
205 class TitleGlyphs : public ArrayList<TitleGlyph *> {
207 void clear() { remove_all_objects(); }
208 int count() { return size(); }
211 ~TitleGlyphs() { clear(); }
219 TitleImage(const char *path, VFrame *vfrm);
222 class TitleImages : public ArrayList<TitleImage *> {
224 void clear() { remove_all_objects(); }
225 int count() { return size(); }
228 ~TitleImages() { clear(); }
232 // Position of each image box in a row
244 TitleChar *init(int typ, void *vp);
246 class TitleChars : public ArrayList<TitleChar *> {
249 void reset() { next = 0; }
250 void clear() { remove_all_objects(); reset(); }
251 int count() { return next; }
252 TitleChar *add(int typ, void *vp) {
253 TitleChar *ret = next < size() ? get(next++) : 0;
254 if( !ret ) { append(ret = new TitleChar()); next = size(); }
255 return ret->init(typ, vp);
257 TitleChars() { reset(); }
258 ~TitleChars() { clear(); }
263 float x0, y0, x1, y1, x2, y2;
265 void bound(float lt, float tp, float rt, float bt) {
266 if( x1 > lt ) x1 = lt;
267 if( y1 < tp ) y1 = tp;
268 if( x2 < rt ) x2 = rt;
269 if( y2 > bt ) y2 = bt;
272 class TitleRows : public ArrayList<TitleRow *> {
275 void reset() { next = 0; }
276 void clear() { remove_all_objects(); reset(); }
277 int count() { return next; }
279 TitleRow *ret = next < size() ? get(next++) : 0;
280 if( !ret ) { append(ret = new TitleRow()); next = size(); }
283 TitleRows() { reset(); }
284 ~TitleRows() { clear(); }
287 // Draw a single character into the glyph cache
289 class GlyphPackage : public LoadPackage
297 class GlyphUnit : public LoadClient
300 GlyphUnit(TitleMain *plugin, GlyphEngine *server);
302 void process_package(LoadPackage *package);
305 FT_Library freetype_library; // Freetype library
306 FT_Face freetype_face;
309 class GlyphEngine : public LoadServer
312 GlyphEngine(TitleMain *plugin, int cpus);
313 void init_packages();
314 LoadClient* new_client();
315 LoadPackage* new_package();
320 // Copy a single character to the text mask
321 class TitlePackage : public LoadPackage
334 class TitleUnit : public LoadClient
337 TitleUnit(TitleMain *plugin, TitleEngine *server);
338 void process_package(LoadPackage *package);
339 void draw_frame(int mode, VFrame *dst, VFrame *src, int x, int y);
346 class TitleEngine : public LoadServer
349 TitleEngine(TitleMain *plugin, int cpus);
350 void init_packages();
351 LoadClient* new_client();
352 LoadPackage* new_package();
359 class TitleOutlinePackage : public LoadPackage
362 TitleOutlinePackage();
367 class TitleOutlineUnit : public LoadClient
370 TitleOutlineUnit(TitleMain *plugin, TitleOutlineEngine *server);
371 void process_package(LoadPackage *package);
373 TitleOutlineEngine *engine;
376 class TitleOutlineEngine : public LoadServer
379 TitleOutlineEngine(TitleMain *plugin, int cpus);
380 void init_packages();
382 LoadClient* new_client();
383 LoadPackage* new_package();
388 template<class typ> class TitleStack : public ArrayList<typ>
390 typ &last() { return ArrayList<typ>::last(); }
391 int size() { return ArrayList<typ>::size(); }
392 typ &append(typ &v) { return ArrayList<typ>::append(v); }
393 void remove() { return ArrayList<typ>::remove(); }
396 TitleStack(TitleParser *p, typ v) : parser(p) { append(v); }
397 operator typ&() { return last(); }
398 typ &push(typ &v) { return append(v); }
399 int pop() { return size()>1 ? (remove(),0) : 1; }
400 int set(const char *txt);
401 int unset(const char *txt);
404 template<class typ> int TitleStack<typ>::set(const char *txt)
406 typ v = !*txt ? 1 : strtol(txt,(char **)&txt,0);
407 if( *txt || v < 0 || v > 1 ) return 1;
411 template<class typ> int TitleStack<typ>::unset(const char *txt)
416 class TitleCurNudge : public TitleStack<int> {
418 TitleCurNudge(TitleParser *parser, TitleMain *plugin);
419 int set(const char *txt);
422 class TitleCurColor : public TitleStack<int> {
424 TitleCurColor(TitleParser *parser, TitleMain *plugin);
425 int set(const char *txt);
428 class TitleCurAlpha : public TitleStack<int> {
430 TitleCurAlpha(TitleParser *parser, TitleMain *plugin);
431 int set(const char *txt);
434 class TitleCurSize : public TitleStack<float> {
436 TitleCurSize(TitleParser *parser, TitleMain *plugin);
437 int set(const char *txt);
438 int unset(const char *txt);
441 class TitleCurBold : public TitleStack<int> {
443 TitleCurBold(TitleParser *parser, TitleMain *plugin);
444 int set(const char *txt);
445 int unset(const char *txt);
448 class TitleCurItalic : public TitleStack<int> {
450 TitleCurItalic(TitleParser *parser, TitleMain *plugin);
451 int set(const char *txt);
452 int unset(const char *txt);
455 class TitleCurFont : public TitleStack<BC_FontEntry*>
458 BC_FontEntry *get(const char *txt, int style);
459 BC_FontEntry *set(const char *txt, int style);
461 virtual int set(const char *txt=0);
462 virtual int unset(const char *txt);
463 TitleCurFont(TitleParser *parser, TitleMain *plugin);
466 class TitleCurCaps : public TitleStack<int> {
468 TitleCurCaps(TitleParser *parser, TitleMain *plugin);
469 int set(const char *txt);
472 class TitleCurUnder : public TitleStack<int> {
474 TitleCurUnder(TitleParser *parser, TitleMain *plugin);
477 class TitleCurBlink : public TitleStack<float> {
479 TitleCurBlink(TitleParser *parser, TitleMain *plugin);
480 int set(const char *txt);
483 class TitleCurFixed : public TitleStack<int> {
485 TitleCurFixed(TitleParser *parser, TitleMain *plugin);
486 int set(const char *txt);
489 class TitleCurAlias : public TitleStack<int> {
491 TitleCurAlias(TitleParser *parser, TitleMain *plugin);
492 int set(const char *txt);
495 class TitleCurSuper : public TitleStack<int> {
497 TitleCurSuper(TitleParser *parser, TitleMain *plugin);
498 int set(const char *txt);
504 const wchar_t *bfr, *out, *lmt;
508 long tell() { return out - bfr; }
509 void seek(long pos) { out = bfr + pos; }
510 bool eof() { return out >= lmt; }
511 int wcur() { return eof() ? -1 : *out; }
512 int wnext() { return eof() ? -1 : *out++; }
513 int wget(wchar_t &wch);
514 int tget(wchar_t &wch);
515 wchar_t wid[BCSTRLEN], wtxt[BCTEXTLEN];
516 char id[BCSTRLEN], text[BCTEXTLEN];
517 int set_attributes(int ret);
519 TitleCurNudge cur_nudge;
520 TitleCurColor cur_color;
521 TitleCurAlpha cur_alpha;
522 TitleCurSize cur_size;
523 TitleCurBold cur_bold;
524 TitleCurItalic cur_italic;
525 TitleCurFont cur_font;
526 TitleCurCaps cur_caps;
527 TitleCurUnder cur_under;
528 TitleCurBlink cur_blink;
529 TitleCurFixed cur_fixed;
530 TitleCurAlias cur_alias;
531 TitleCurSuper cur_super;
533 TitleParser(TitleMain *main);
537 // Overlay text mask with fractional translation
538 // We don't use OverlayFrame to enable alpha blending on non alpha
540 class TitleTranslatePackage : public LoadPackage
543 TitleTranslatePackage();
547 class TitleTranslateUnit : public LoadClient
550 TitleTranslateUnit(TitleMain *plugin, TitleTranslate *server);
552 void process_package(LoadPackage *package);
556 class TitleTranslate : public LoadServer
559 TitleTranslate(TitleMain *plugin, int cpus);
564 float in_w, in_h, out_w, out_h;
565 float ix1, iy1, ix2, iy2;
566 float ox1, oy1, ox2, oy2;
568 void copy(VFrame *input);
569 LoadClient* new_client();
570 LoadPackage* new_package();
571 void init_packages();
575 class TitleMain : public PluginVClient
578 TitleMain(PluginServer *server);
581 // required for all realtime plugins
582 PLUGIN_CLASS_MEMBERS(TitleConfig)
583 int process_realtime(VFrame *input_ptr, VFrame *output_ptr);
587 void save_data(KeyFrame *keyframe);
588 void read_data(KeyFrame *keyframe);
589 void insert_text(const wchar_t *wtxt, int pos);
591 void build_previews(TitleWindow *gui);
594 int set_font(BC_FontEntry*&font, const char *txt);
595 int set_font(BC_FontEntry*&font, const char *txt, int style);
596 int set_size(int &size, const char *txt);
597 int set_color(int &color, const char *txt);
598 int set_bold(int &bold, const char *txt);
599 int set_italic(int &italic, const char *txt);
600 int set_caps(int &caps, const char *txt);
601 int set_under(int &under, const char *txt);
603 int draw_text(int need_redraw);
604 int draw_underline(VFrame *mask, int alpha);
608 int get_visible_text();
609 int check_char_code_path(FT_Library &freetype_library,
610 char *path_old, FT_ULong &char_code, char *path_new);
611 int load_freetype_face(FT_Library &freetype_library,
612 FT_Face &freetype_face, const char *path);
613 int load_font(BC_FontEntry *font);
614 Indexable *open_background(const char *filename);
615 int read_background(VFrame *frame, int64_t position, int color_model);
616 void draw_background();
617 static BC_FontEntry* get_font(const char *font_name, int style);
618 BC_FontEntry* config_font();
619 TitleGlyph *get_glyph(FT_ULong char_code, BC_FontEntry *font, int size, int style);
620 int get_width(TitleGlyph *cur, TitleGlyph *nxt);
622 VFrame *add_image(const char *path);
623 VFrame *get_image(const char *path);
625 // backward compatibility
626 void convert_encoding();
627 static const char* motion_to_text(int motion);
628 static int text_to_motion(const char *text);
632 GlyphEngine *glyph_engine;
633 TitleEngine *title_engine;
634 VFrame *outline_mask;
635 TitleOutlineEngine *outline_engine;
636 TitleTranslate *translate;
638 TitleChars title_chars;
639 TitleRows title_rows;
640 TitleGlyphs title_glyphs;
641 TitleImages title_images;
643 FT_Library freetype_library;
644 FT_Face freetype_face;
645 char text_font[BCTEXTLEN];
647 int window_w, window_h;
648 int fuzz, fuzz1, fuzz2;
649 float title_x, title_y;
650 int title_w, title_h;
652 float text_x, text_y, text_w, text_h;
653 float text_x1, text_y1, text_x2, text_y2;
655 int mask_x, mask_y; int mask_w, mask_h;
656 int mask_x1, mask_y1, mask_x2, mask_y2;
659 int visible_row1, visible_char1;
660 int visible_row2, visible_char2;
663 VFrame *input, *output;
664 int output_model, text_model, mask_model;
666 Indexable *background;
669 RenderEngine *render_engine;
670 CICache *video_cache;
671 OverlayFrame *overlay_frame;
673 int64_t last_position;
674 int need_reconfigure;