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 N_("nudge")
27 #define KW_COLOR N_("color")
28 #define KW_ALPHA N_("alpha")
29 #define KW_FONT N_("font")
30 #define KW_SIZE N_("size")
31 #define KW_BOLD N_("bold")
32 #define KW_ITALIC N_("italic")
33 #define KW_CAPS N_("caps")
34 #define KW_UL N_("ul")
35 #define KW_BLINK N_("blink")
36 #define KW_FIXED N_("fixed")
37 #define KW_ALIAS N_("smooth")
38 #define KW_SUP N_("sup")
39 #define KW_PNG N_("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
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];
187 // loop background playback
200 int width, height, style;
203 int left, top, right, bottom;
204 VFrame *data, *data_stroke;
206 class TitleGlyphs : public ArrayList<TitleGlyph *> {
208 void clear() { remove_all_objects(); }
209 int count() { return size(); }
212 ~TitleGlyphs() { clear(); }
220 TitleImage(const char *path, VFrame *vfrm);
223 class TitleImages : public ArrayList<TitleImage *> {
225 void clear() { remove_all_objects(); }
226 int count() { return size(); }
229 ~TitleImages() { clear(); }
233 // Position of each image box in a row
245 TitleChar *init(int typ, void *vp);
247 class TitleChars : public ArrayList<TitleChar *> {
250 void reset() { next = 0; }
251 void clear() { remove_all_objects(); reset(); }
252 int count() { return next; }
253 TitleChar *add(int typ, void *vp) {
254 TitleChar *ret = next < size() ? get(next++) : 0;
255 if( !ret ) { append(ret = new TitleChar()); next = size(); }
256 return ret->init(typ, vp);
258 TitleChars() { reset(); }
259 ~TitleChars() { clear(); }
264 float x0, y0, x1, y1, x2, y2;
266 void bound(float lt, float tp, float rt, float bt) {
267 if( x1 > lt ) x1 = lt;
268 if( y1 < tp ) y1 = tp;
269 if( x2 < rt ) x2 = rt;
270 if( y2 > bt ) y2 = bt;
273 class TitleRows : public ArrayList<TitleRow *> {
276 void reset() { next = 0; }
277 void clear() { remove_all_objects(); reset(); }
278 int count() { return next; }
280 TitleRow *ret = next < size() ? get(next++) : 0;
281 if( !ret ) { append(ret = new TitleRow()); next = size(); }
284 TitleRows() { reset(); }
285 ~TitleRows() { clear(); }
288 // Draw a single character into the glyph cache
290 class GlyphPackage : public LoadPackage
298 class GlyphUnit : public LoadClient
301 GlyphUnit(TitleMain *plugin, GlyphEngine *server);
303 void process_package(LoadPackage *package);
306 FT_Library freetype_library; // Freetype library
307 FT_Face freetype_face;
310 class GlyphEngine : public LoadServer
313 GlyphEngine(TitleMain *plugin, int cpus);
314 void init_packages();
315 LoadClient* new_client();
316 LoadPackage* new_package();
321 // Copy a single character to the text mask
322 class TitlePackage : public LoadPackage
335 class TitleUnit : public LoadClient
338 TitleUnit(TitleMain *plugin, TitleEngine *server);
339 void process_package(LoadPackage *package);
340 void draw_frame(int mode, VFrame *dst, VFrame *src, int x, int y);
347 class TitleEngine : public LoadServer
350 TitleEngine(TitleMain *plugin, int cpus);
351 void init_packages();
352 LoadClient* new_client();
353 LoadPackage* new_package();
360 class TitleOutlinePackage : public LoadPackage
363 TitleOutlinePackage();
368 class TitleOutlineUnit : public LoadClient
371 TitleOutlineUnit(TitleMain *plugin, TitleOutlineEngine *server);
372 void process_package(LoadPackage *package);
374 TitleOutlineEngine *engine;
377 class TitleOutlineEngine : public LoadServer
380 TitleOutlineEngine(TitleMain *plugin, int cpus);
381 void init_packages();
383 LoadClient* new_client();
384 LoadPackage* new_package();
389 template<class typ> class TitleStack : public ArrayList<typ>
391 typ &last() { return ArrayList<typ>::last(); }
392 int size() { return ArrayList<typ>::size(); }
393 typ &append(typ &v) { return ArrayList<typ>::append(v); }
394 void remove() { return ArrayList<typ>::remove(); }
397 TitleStack(TitleParser *p, typ v) : parser(p) { append(v); }
398 operator typ&() { return last(); }
399 typ &push(typ &v) { return append(v); }
400 int pop() { return size()>1 ? (remove(),0) : 1; }
401 int set(const char *txt);
402 int unset(const char *txt);
405 template<class typ> int TitleStack<typ>::set(const char *txt)
407 typ v = !*txt ? 1 : strtol(txt,(char **)&txt,0);
408 if( *txt || v < 0 || v > 1 ) return 1;
412 template<class typ> int TitleStack<typ>::unset(const char *txt)
417 class TitleCurNudge : public TitleStack<int> {
419 TitleCurNudge(TitleParser *parser, TitleMain *plugin);
420 int set(const char *txt);
423 class TitleCurColor : public TitleStack<int> {
425 TitleCurColor(TitleParser *parser, TitleMain *plugin);
426 int set(const char *txt);
429 class TitleCurAlpha : public TitleStack<int> {
431 TitleCurAlpha(TitleParser *parser, TitleMain *plugin);
432 int set(const char *txt);
435 class TitleCurSize : public TitleStack<float> {
437 TitleCurSize(TitleParser *parser, TitleMain *plugin);
438 int set(const char *txt);
439 int unset(const char *txt);
442 class TitleCurBold : public TitleStack<int> {
444 TitleCurBold(TitleParser *parser, TitleMain *plugin);
445 int set(const char *txt);
446 int unset(const char *txt);
449 class TitleCurItalic : public TitleStack<int> {
451 TitleCurItalic(TitleParser *parser, TitleMain *plugin);
452 int set(const char *txt);
453 int unset(const char *txt);
456 class TitleCurFont : public TitleStack<BC_FontEntry*>
459 BC_FontEntry *get(const char *txt, int style);
460 BC_FontEntry *set(const char *txt, int style);
462 virtual int set(const char *txt=0);
463 virtual int unset(const char *txt);
464 TitleCurFont(TitleParser *parser, TitleMain *plugin);
467 class TitleCurCaps : public TitleStack<int> {
469 TitleCurCaps(TitleParser *parser, TitleMain *plugin);
470 int set(const char *txt);
473 class TitleCurUnder : public TitleStack<int> {
475 TitleCurUnder(TitleParser *parser, TitleMain *plugin);
478 class TitleCurBlink : public TitleStack<float> {
480 TitleCurBlink(TitleParser *parser, TitleMain *plugin);
481 int set(const char *txt);
484 class TitleCurFixed : public TitleStack<int> {
486 TitleCurFixed(TitleParser *parser, TitleMain *plugin);
487 int set(const char *txt);
490 class TitleCurAlias : public TitleStack<int> {
492 TitleCurAlias(TitleParser *parser, TitleMain *plugin);
493 int set(const char *txt);
496 class TitleCurSuper : public TitleStack<int> {
498 TitleCurSuper(TitleParser *parser, TitleMain *plugin);
499 int set(const char *txt);
505 const wchar_t *bfr, *out, *lmt;
509 long tell() { return out - bfr; }
510 void seek(long pos) { out = bfr + pos; }
511 bool eof() { return out >= lmt; }
512 int wcur() { return eof() ? -1 : *out; }
513 int wnext() { return eof() ? -1 : *out++; }
514 int wget(wchar_t &wch);
515 int tget(wchar_t &wch);
516 wchar_t wid[BCSTRLEN], wtxt[BCTEXTLEN];
517 char id[BCSTRLEN], text[BCTEXTLEN];
518 int set_attributes(int ret);
520 TitleCurNudge cur_nudge;
521 TitleCurColor cur_color;
522 TitleCurAlpha cur_alpha;
523 TitleCurSize cur_size;
524 TitleCurBold cur_bold;
525 TitleCurItalic cur_italic;
526 TitleCurFont cur_font;
527 TitleCurCaps cur_caps;
528 TitleCurUnder cur_under;
529 TitleCurBlink cur_blink;
530 TitleCurFixed cur_fixed;
531 TitleCurAlias cur_alias;
532 TitleCurSuper cur_super;
534 TitleParser(TitleMain *main);
538 // Overlay text mask with fractional translation
539 // We don't use OverlayFrame to enable alpha blending on non alpha
541 class TitleTranslatePackage : public LoadPackage
544 TitleTranslatePackage();
548 class TitleTranslateUnit : public LoadClient
551 TitleTranslateUnit(TitleMain *plugin, TitleTranslate *server);
553 void process_package(LoadPackage *package);
557 class TitleTranslate : public LoadServer
560 TitleTranslate(TitleMain *plugin, int cpus);
565 float in_w, in_h, out_w, out_h;
566 float ix1, iy1, ix2, iy2;
567 float ox1, oy1, ox2, oy2;
569 void copy(VFrame *input);
570 LoadClient* new_client();
571 LoadPackage* new_package();
572 void init_packages();
576 class TitleMain : public PluginVClient
579 TitleMain(PluginServer *server);
582 // required for all realtime plugins
583 PLUGIN_CLASS_MEMBERS(TitleConfig)
584 int process_realtime(VFrame *input_ptr, VFrame *output_ptr);
588 void save_data(KeyFrame *keyframe);
589 void read_data(KeyFrame *keyframe);
590 void insert_text(const wchar_t *wtxt, int pos);
592 void build_previews(TitleWindow *gui);
595 int set_font(BC_FontEntry*&font, const char *txt);
596 int set_font(BC_FontEntry*&font, const char *txt, int style);
597 int set_size(int &size, const char *txt);
598 int set_color(int &color, const char *txt);
599 int set_bold(int &bold, const char *txt);
600 int set_italic(int &italic, const char *txt);
601 int set_caps(int &caps, const char *txt);
602 int set_under(int &under, const char *txt);
604 int draw_text(int need_redraw);
605 int draw_underline(VFrame *mask, int alpha);
609 int get_visible_text();
610 int check_char_code_path(FT_Library &freetype_library,
611 char *path_old, FT_ULong &char_code, char *path_new);
612 int load_freetype_face(FT_Library &freetype_library,
613 FT_Face &freetype_face, const char *path);
614 int load_font(BC_FontEntry *font);
615 Indexable *open_background(const char *filename);
616 int read_background(VFrame *frame, int64_t position, int color_model);
617 void draw_background();
618 static BC_FontEntry* get_font(const char *font_name, int style);
619 BC_FontEntry* config_font();
620 TitleGlyph *get_glyph(FT_ULong char_code, BC_FontEntry *font, int size, int style);
621 int get_width(TitleGlyph *cur, TitleGlyph *nxt);
623 VFrame *add_image(const char *path);
624 VFrame *get_image(const char *path);
626 // backward compatibility
627 void convert_encoding();
628 static const char* motion_to_text(int motion);
629 static int text_to_motion(const char *text);
633 GlyphEngine *glyph_engine;
634 TitleEngine *title_engine;
635 VFrame *outline_mask;
636 TitleOutlineEngine *outline_engine;
637 TitleTranslate *translate;
639 TitleChars title_chars;
640 TitleRows title_rows;
641 TitleGlyphs title_glyphs;
642 TitleImages title_images;
644 FT_Library freetype_library;
645 FT_Face freetype_face;
646 char text_font[BCTEXTLEN];
648 int window_w, window_h;
649 int fuzz, fuzz1, fuzz2;
650 float title_x, title_y;
651 int title_w, title_h;
653 float text_x, text_y, text_w, text_h;
654 float text_x1, text_y1, text_x2, text_y2;
656 int mask_x, mask_y; int mask_w, mask_h;
657 int mask_x1, mask_y1, mask_x2, mask_y2;
660 int visible_row1, visible_char1;
661 int visible_row2, visible_char2;
664 VFrame *input, *output;
665 int output_model, text_model, mask_model;
667 Indexable *background;
670 RenderEngine *render_engine;
671 CICache *video_cache;
672 OverlayFrame *overlay_frame;
674 int64_t last_position;
675 int need_reconfigure;