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
40 class TitleOutlinePackage;
41 class TitleOutlineUnit;
42 class TitleOutlineEngine;
43 class TitleTranslatePackage;
44 class TitleTranslateUnit;
62 #include "bcfontentry.h"
64 #include "indexable.inc"
65 #include "loadbalance.h"
67 #include "overlayframe.inc"
68 #include "pluginvclient.h"
69 #include "renderengine.inc"
70 #include "titlerwindow.h"
73 #include FT_FREETYPE_H
74 #include <sys/types.h>
79 #define BOTTOM_TO_TOP 0x1
80 #define TOP_TO_BOTTOM 0x2
81 #define RIGHT_TO_LEFT 0x3
82 #define LEFT_TO_RIGHT 0x4
84 // Horizontal justification
85 #define JUSTIFY_LEFT 0x0
86 #define JUSTIFY_CENTER 0x1
87 #define JUSTIFY_RIGHT 0x2
89 // Vertical justification
90 #define JUSTIFY_TOP 0x0
91 #define JUSTIFY_MID 0x1
92 #define JUSTIFY_BOTTOM 0x2
98 #define FLAG_UNDER 0x0001
99 #define FLAG_FIXED 0x0002
100 #define FLAG_SUPER 0x0004
101 #define FLAG_SUBER 0x0008
102 #define FLAG_BLINK 0x0010
110 void to_wtext(const char *from_enc, const char *text, int tlen);
111 // Only used to clear glyphs
112 int equivalent(TitleConfig &that);
113 void copy_from(TitleConfig &that);
114 void interpolate(TitleConfig &prev,
118 int64_t current_frame);
121 char font[BCTEXTLEN];
122 // Encoding to convert from
123 char encoding[BCTEXTLEN];
133 int motion_strategy; // Motion of title across frame
135 int loop; // Loop motion path
138 // Number of seconds the fade in and fade out of the title take
139 double fade_in, fade_out;
140 float pixels_per_second; // Speed of motion
142 wchar_t wtext[BCTEXTLEN];
144 // Position in frame relative to top left
145 float title_x, title_y;
146 int title_w, title_h;
148 int window_w, window_h;
149 // Calculated during every frame for motion strategy
150 int64_t prev_keyframe_position;
151 int64_t next_keyframe_position;
156 char background_path[BCTEXTLEN];
164 // loop background playback
177 int width, height, style;
180 int left, top, right, bottom;
181 VFrame *data, *data_stroke;
183 class TitleGlyphs : public ArrayList<TitleGlyph *> {
185 void clear() { remove_all_objects(); }
186 int count() { return size(); }
189 ~TitleGlyphs() { clear(); }
197 TitleImage(const char *path, VFrame *vfrm);
200 class TitleImages : public ArrayList<TitleImage *> {
202 void clear() { remove_all_objects(); }
203 int count() { return size(); }
206 ~TitleImages() { clear(); }
210 // Position of each image box in a row
222 TitleChar *init(int typ, void *vp);
224 class TitleChars : public ArrayList<TitleChar *> {
227 void reset() { next = 0; }
228 void clear() { remove_all_objects(); reset(); }
229 int count() { return next; }
230 TitleChar *add(int typ, void *vp) {
231 TitleChar *ret = next < size() ? get(next++) : 0;
232 if( !ret ) { append(ret = new TitleChar()); next = size(); }
233 return ret->init(typ, vp);
235 TitleChars() { reset(); }
236 ~TitleChars() { clear(); }
241 float x0, y0, x1, y1, x2, y2;
243 void bound(float lt, float tp, float rt, float bt) {
244 if( x1 > lt ) x1 = lt;
245 if( y1 < tp ) y1 = tp;
246 if( x2 < rt ) x2 = rt;
247 if( y2 > bt ) y2 = bt;
250 class TitleRows : public ArrayList<TitleRow *> {
253 void reset() { next = 0; }
254 void clear() { remove_all_objects(); reset(); }
255 int count() { return next; }
257 TitleRow *ret = next < size() ? get(next++) : 0;
258 if( !ret ) { append(ret = new TitleRow()); next = size(); }
261 TitleRows() { reset(); }
262 ~TitleRows() { clear(); }
265 // Draw a single character into the glyph cache
267 class GlyphPackage : public LoadPackage
275 class GlyphUnit : public LoadClient
278 GlyphUnit(TitleMain *plugin, GlyphEngine *server);
280 void process_package(LoadPackage *package);
283 FT_Library freetype_library; // Freetype library
284 FT_Face freetype_face;
287 class GlyphEngine : public LoadServer
290 GlyphEngine(TitleMain *plugin, int cpus);
291 void init_packages();
292 LoadClient* new_client();
293 LoadPackage* new_package();
298 // Copy a single character to the text mask
299 class TitlePackage : public LoadPackage
312 class TitleUnit : public LoadClient
315 TitleUnit(TitleMain *plugin, TitleEngine *server);
316 void process_package(LoadPackage *package);
317 void draw_frame(int mode, VFrame *dst, VFrame *src, int x, int y);
324 class TitleEngine : public LoadServer
327 TitleEngine(TitleMain *plugin, int cpus);
328 void init_packages();
329 LoadClient* new_client();
330 LoadPackage* new_package();
337 class TitleOutlinePackage : public LoadPackage
340 TitleOutlinePackage();
345 class TitleOutlineUnit : public LoadClient
348 TitleOutlineUnit(TitleMain *plugin, TitleOutlineEngine *server);
349 void process_package(LoadPackage *package);
351 TitleOutlineEngine *engine;
354 class TitleOutlineEngine : public LoadServer
357 TitleOutlineEngine(TitleMain *plugin, int cpus);
358 void init_packages();
360 LoadClient* new_client();
361 LoadPackage* new_package();
367 // Overlay text mask with fractional translation
368 // We don't use OverlayFrame to enable alpha blending on non alpha
370 class TitleTranslatePackage : public LoadPackage
373 TitleTranslatePackage();
380 int in_x2; // Might be same as in_x1 for boundary
382 float output_fraction;
385 class TitleTranslateUnit : public LoadClient
388 TitleTranslateUnit(TitleMain *plugin, TitleTranslate *server);
390 static void translation_array_f(transfer_table_f* &table,
391 float out_x1, float out_x2, int out_total,
392 float in_x1, float in_x2, int in_total,
393 int &x1_out, int &x2_out);
394 void process_package(LoadPackage *package);
398 class TitleTranslate : public LoadServer
401 TitleTranslate(TitleMain *plugin, int cpus);
403 void init_packages();
405 LoadClient* new_client();
406 LoadPackage* new_package();
408 transfer_table_f *y_table;
409 transfer_table_f *x_table;
415 template<class typ> class TitleStack : public ArrayList<typ>
417 typ &last() { return ArrayList<typ>::last(); }
418 int size() { return ArrayList<typ>::size(); }
419 typ &append(typ &v) { return ArrayList<typ>::append(v); }
420 void remove() { return ArrayList<typ>::remove(); }
423 TitleStack(TitleParser *p, typ v) : parser(p) { append(v); }
424 operator typ&() { return last(); }
425 typ &push(typ &v) { return append(v); }
426 int pop() { return size()>1 ? (remove(),0) : 1; }
427 int set(const char *txt);
428 int unset(const char *txt);
431 template<class typ> int TitleStack<typ>::set(const char *txt)
433 typ v = !*txt ? 1 : strtol(txt,(char **)&txt,0);
434 if( *txt || v < 0 || v > 1 ) return 1;
438 template<class typ> int TitleStack<typ>::unset(const char *txt)
443 class TitleCurNudge : public TitleStack<int> {
445 TitleCurNudge(TitleParser *parser, TitleMain *plugin);
446 int set(const char *txt);
449 class TitleCurColor : public TitleStack<int> {
451 TitleCurColor(TitleParser *parser, TitleMain *plugin);
452 int set(const char *txt);
455 class TitleCurAlpha : public TitleStack<int> {
457 TitleCurAlpha(TitleParser *parser, TitleMain *plugin);
458 int set(const char *txt);
461 class TitleCurSize : public TitleStack<float> {
463 TitleCurSize(TitleParser *parser, TitleMain *plugin);
464 int set(const char *txt);
465 int unset(const char *txt);
468 class TitleCurBold : public TitleStack<int> {
470 TitleCurBold(TitleParser *parser, TitleMain *plugin);
471 int set(const char *txt);
472 int unset(const char *txt);
475 class TitleCurItalic : public TitleStack<int> {
477 TitleCurItalic(TitleParser *parser, TitleMain *plugin);
478 int set(const char *txt);
479 int unset(const char *txt);
482 class TitleCurFont : public TitleStack<BC_FontEntry*>
485 BC_FontEntry* get(const char *txt, int style);
486 int set(const char *txt, int style);
488 virtual int set(const char *txt=0);
489 virtual int unset(const char *txt);
490 TitleCurFont(TitleParser *parser, TitleMain *plugin);
493 class TitleCurCaps : public TitleStack<int> {
495 TitleCurCaps(TitleParser *parser, TitleMain *plugin);
496 int set(const char *txt);
499 class TitleCurUnder : public TitleStack<int> {
501 TitleCurUnder(TitleParser *parser, TitleMain *plugin);
504 class TitleCurBlink : public TitleStack<float> {
506 TitleCurBlink(TitleParser *parser, TitleMain *plugin);
507 int set(const char *txt);
510 class TitleCurFixed : public TitleStack<int> {
512 TitleCurFixed(TitleParser *parser, TitleMain *plugin);
513 int set(const char *txt);
516 class TitleCurSuper : public TitleStack<int> {
518 TitleCurSuper(TitleParser *parser, TitleMain *plugin);
519 int set(const char *txt);
525 const wchar_t *bfr, *out, *lmt;
529 long tell() { return out - bfr; }
530 void seek(long pos) { out = bfr + pos; }
531 bool eof() { return out >= lmt; }
532 int wcur() { return eof() ? -1 : *out; }
533 int wnext() { return eof() ? -1 : *out++; }
534 int wget(wchar_t &wch);
535 char id[BCSTRLEN], text[BCTEXTLEN];
536 int set_attributes(int ret);
538 TitleCurNudge cur_nudge;
539 TitleCurColor cur_color;
540 TitleCurAlpha cur_alpha;
541 TitleCurSize cur_size;
542 TitleCurBold cur_bold;
543 TitleCurItalic cur_italic;
544 TitleCurFont cur_font;
545 TitleCurCaps cur_caps;
546 TitleCurUnder cur_under;
547 TitleCurBlink cur_blink;
548 TitleCurFixed cur_fixed;
549 TitleCurSuper cur_super;
551 TitleParser(TitleMain *main);
555 class TitleMain : public PluginVClient
558 TitleMain(PluginServer *server);
561 // required for all realtime plugins
562 PLUGIN_CLASS_MEMBERS(TitleConfig)
563 int process_realtime(VFrame *input_ptr, VFrame *output_ptr);
567 void save_data(KeyFrame *keyframe);
568 void read_data(KeyFrame *keyframe);
570 void build_previews(TitleWindow *gui);
573 int set_font(BC_FontEntry*&font, const char *txt);
574 int set_font(BC_FontEntry*&font, const char *txt, int style);
575 int set_size(int &size, const char *txt);
576 int set_color(int &color, const char *txt);
577 int set_bold(int &bold, const char *txt);
578 int set_italic(int &italic, const char *txt);
579 int set_caps(int &caps, const char *txt);
580 int set_under(int &under, const char *txt);
582 int draw_text(int need_redraw);
583 int draw_underline(VFrame *mask, int alpha);
587 int get_visible_text();
588 int check_char_code_path(FT_Library &freetype_library,
589 char *path_old, FT_ULong &char_code, char *path_new);
590 int load_freetype_face(FT_Library &freetype_library,
591 FT_Face &freetype_face, const char *path);
592 int load_font(BC_FontEntry *font);
593 Indexable *open_background(const char *filename);
594 int read_background(VFrame *frame, int64_t position, int color_model);
595 void draw_background();
596 BC_FontEntry* get_font(const char *font_name, int style);
597 BC_FontEntry* config_font();
598 TitleGlyph *get_glyph(FT_ULong char_code, BC_FontEntry *font, int size, int style);
599 int get_width(TitleGlyph *cur, TitleGlyph *nxt);
601 VFrame *add_image(const char *path);
602 VFrame *get_image(const char *path);
604 // backward compatibility
605 void convert_encoding();
606 static const char* motion_to_text(int motion);
607 static int text_to_motion(const char *text);
611 GlyphEngine *glyph_engine;
612 TitleEngine *title_engine;
613 VFrame *outline_mask;
614 TitleOutlineEngine *outline_engine;
615 TitleTranslate *translate;
617 TitleChars title_chars;
618 TitleRows title_rows;
619 TitleGlyphs title_glyphs;
620 TitleImages title_images;
622 FT_Library freetype_library;
623 FT_Face freetype_face;
624 char text_font[BCTEXTLEN];
626 int window_w, window_h;
627 int fuzz, fuzz1, fuzz2;
628 int title_x, title_y, title_w, title_h;
630 float text_x, text_y, text_w, text_h;
631 float text_x1, text_y1, text_x2, text_y2;
633 int mask_x, mask_y; int mask_w, mask_h;
634 int mask_x1, mask_y1, mask_x2, mask_y2;
637 int visible_row1, visible_char1;
638 int visible_row2, visible_char2;
641 VFrame *input, *output;
642 int output_model, text_model, mask_model;
644 Indexable *background;
647 RenderEngine *render_engine;
648 CICache *video_cache;
649 OverlayFrame *overlay_frame;
651 int64_t last_position;
652 int need_reconfigure;