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
22 // Originally developed by Heroine Virtual Ltd.
23 // Support for multiple encodings, outline (stroke) by
24 // Andraz Tori <Andraz.tori1@guest.arnes.si>
25 // Additional support for UTF-8 by
26 // Paolo Rampino aka Akirad <info at tuttoainternet.it>
29 #include "bccmodels.h"
30 #include "bcsignals.h"
35 #include "edlsession.h"
38 #include "filesystem.h"
39 #include "indexable.h"
46 #include "mwindow.inc"
47 #include "overlayframe.h"
49 #include "renderengine.h"
51 #include "titlerwindow.h"
52 #include "transportque.h"
64 #include <fontconfig/fontconfig.h>
66 #define FIXED_FONT "bitstream vera sans mono (bitstream)"
67 #define SMALL (1.0 / 64.0)
69 #define MAX_FLT 3.40282347e+38
70 #define MIN_FLT -3.40282347e+38
72 REGISTER_PLUGIN(TitleMain)
74 #ifdef X_HAVE_UTF8_STRING
75 #define DEFAULT_ENCODING "UTF-8"
77 #define DEFAULT_ENCODING "ISO8859-1"
79 #define DEFAULT_TIMECODEFORMAT TIME_HMS
81 TitleConfig::TitleConfig()
83 strcpy(font, "fixed");
84 strcpy(encoding, DEFAULT_ENCODING);
90 outline_color = WHITE;
92 color_stroke = 0xff0000;
94 motion_strategy = NO_MOTION;
97 hjustification = JUSTIFY_CENTER;
98 vjustification = JUSTIFY_MID;
99 fade_in = 0.0; fade_out = 0.0;
100 pixels_per_second = 100.0;
101 wtext[0] = 0; wlen = 0;
102 title_x = title_y = 0.0;
103 title_w = title_h = 0;
106 next_keyframe_position = 0;
107 prev_keyframe_position = 0;
111 strcpy(background_path, "");
112 timecode_format = DEFAULT_TIMECODEFORMAT;
117 TitleConfig::~TitleConfig()
121 int TitleConfig::equivalent(TitleConfig &that)
123 return !strcasecmp(font, that.font) &&
124 !strcasecmp(encoding, that.encoding) &&
125 style == that.style &&
127 color == that.color &&
128 alpha == that.alpha &&
129 outline_size == that.outline_size &&
130 outline_color == that.outline_color &&
131 outline_alpha == that.outline_alpha &&
132 color_stroke == that.color_stroke &&
133 stroke_width == that.stroke_width &&
134 // dont require redraw for these
135 // motion_strategy == that.motion_strategy &&
136 line_pitch == that.line_pitch &&
137 // loop == that.loop &&
138 hjustification == that.hjustification &&
139 vjustification == that.vjustification &&
140 // fade_in == that.fade_in && fade_out == that.fade_out &&
141 // EQUIV(pixels_per_second, that.pixels_per_second) &&
143 !memcmp(wtext, that.wtext, wlen * sizeof(wchar_t)) &&
144 // title_x == that.title_x && title_y == that.title_y &&
145 title_w == that.title_w && title_h == that.title_h &&
146 // window_w == that.window_w && window_h == that.window_h &&
147 timecode == that.timecode &&
148 dropshadow == that.dropshadow &&
149 background == that.background &&
150 !strcmp(background_path, that.background_path) &&
151 timecode_format == that.timecode_format &&
152 // drag == that.drag &&
153 loop_playback == that.loop_playback;
156 void TitleConfig::copy_from(TitleConfig &that)
158 strcpy(font, that.font);
159 strcpy(encoding, that.encoding);
164 outline_size = that.outline_size;
165 outline_color = that.outline_color;
166 outline_alpha = that.outline_alpha;
167 color_stroke = that.color_stroke;
168 stroke_width = that.stroke_width;
169 motion_strategy = that.motion_strategy;
170 line_pitch = that.line_pitch;
172 hjustification = that.hjustification;
173 vjustification = that.vjustification;
174 fade_in = that.fade_in;
175 fade_out = that.fade_out;
176 pixels_per_second = that.pixels_per_second;
178 memcpy(wtext, that.wtext, that.wlen * sizeof(wchar_t));
179 title_x = that.title_x; title_y = that.title_y;
180 title_w = that.title_w; title_h = that.title_h;
181 window_w = that.window_w; window_h = that.window_h;
182 timecode = that.timecode;
183 dropshadow = that.dropshadow;
184 background = that.background;
185 strcpy(background_path, that.background_path);
186 timecode_format = that.timecode_format;
188 loop_playback = that.loop_playback;
191 void TitleConfig::interpolate(TitleConfig &prev, TitleConfig &next,
192 int64_t prev_frame, int64_t next_frame, int64_t current_frame)
194 double next_scale = (double)(current_frame - prev_frame) / (next_frame - prev_frame);
195 double prev_scale = (double)(next_frame - current_frame) / (next_frame - prev_frame);
196 strcpy(font, prev.font);
197 strcpy(encoding, prev.encoding);
202 outline_size = prev.outline_size;
203 outline_color = prev.outline_color;
204 outline_alpha = prev.outline_alpha;
205 color_stroke = prev.color_stroke;
206 stroke_width = prev.stroke_width;
207 motion_strategy = prev.motion_strategy;
208 line_pitch = prev.line_pitch;
210 hjustification = prev.hjustification;
211 vjustification = prev.vjustification;
212 fade_in = prev.fade_in;
213 fade_out = prev.fade_out;
214 pixels_per_second = prev.pixels_per_second;
216 memcpy(wtext, prev.wtext, prev.wlen * sizeof(wchar_t));
218 this->title_x = prev.title_x == next.title_x ? prev.title_x :
219 prev.title_x * prev_scale + next.title_x * next_scale;
220 this->title_y = prev.title_y == next.title_y ? prev.title_y :
221 prev.title_y * prev_scale + next.title_y * next_scale;
222 this->title_w = prev.title_w == next.title_w ? prev.title_w :
223 prev.title_w * prev_scale + next.title_w * next_scale;
224 this->title_h = prev.title_h == next.title_h ? prev.title_h :
225 prev.title_h * prev_scale + next.title_h * next_scale;
226 window_w = prev.window_w;
227 window_h = prev.window_h;
228 timecode = prev.timecode;
229 this->dropshadow = prev.dropshadow == next.dropshadow ? prev.dropshadow :
230 prev.dropshadow * prev_scale + next.dropshadow * next_scale;
231 background = prev.background;
232 strcpy(background_path, prev.background_path);
233 timecode_format = prev.timecode_format;
235 loop_playback = prev.loop_playback;
238 void TitleConfig::to_wtext(const char *from_enc, const char *text, int tlen)
240 wlen = BC_Resources::encode(from_enc, BC_Resources::wide_encoding,
241 (char*)text,tlen, (char *)wtext,sizeof(wtext)) / sizeof(wchar_t);
242 while( wlen > 0 && !wtext[wlen-1] ) --wlen;
246 TitleGlyph::TitleGlyph()
265 TitleGlyph::~TitleGlyph()
267 //printf("TitleGlyph::~TitleGlyph 1\n");
268 if( data ) delete data;
269 if( data_stroke ) delete data_stroke;
273 GlyphPackage::GlyphPackage() : LoadPackage()
278 GlyphUnit::GlyphUnit(TitleMain *plugin, GlyphEngine *server)
281 this->plugin = plugin;
282 freetype_library = 0;
286 GlyphUnit::~GlyphUnit()
288 if( freetype_library )
289 FT_Done_FreeType(freetype_library);
292 void GlyphUnit::process_package(LoadPackage *package)
294 GlyphPackage *pkg = (GlyphPackage*)package;
295 TitleGlyph *glyph = pkg->glyph;
296 BC_Resources *resources = BC_WindowBase::get_resources();
297 if( resources->font_debug )
298 printf("GlyphUnit load glyph (%s) %04x, '%c'\n", glyph->font->displayname,
299 (unsigned)glyph->char_code, (unsigned)glyph->char_code);
301 char new_path[BCTEXTLEN];
302 if( plugin->load_freetype_face(freetype_library, freetype_face, glyph->font->path) ) {
303 printf(_("GlyphUnit::process_package FT_New_Face failed, path=%s\n"),
308 int gindex = FT_Get_Char_Index(freetype_face, glyph->char_code);
309 if( !gindex && !freetype_face->charmap && // if no default charmap
310 freetype_face->charmaps && freetype_face->charmaps[0] &&
311 !FT_Select_Charmap(freetype_face, freetype_face->charmaps[0]->encoding) ) {
312 gindex = FT_Get_Char_Index(freetype_face, glyph->char_code);
315 printf("GlyphUnit::process_package 1 glyph not found (%s) %04x, '%c'\n",
316 glyph->font->displayname, (unsigned)glyph->char_code, (unsigned)glyph->char_code);
317 // Search replacement font
318 if( resources->find_font_by_char(glyph->char_code, new_path, freetype_face) ) {
319 plugin->load_freetype_face(freetype_library,
320 freetype_face, new_path);
321 gindex = FT_Get_Char_Index(freetype_face, glyph->char_code);
324 FT_Set_Pixel_Sizes(freetype_face, glyph->size, 0);
328 if( glyph->char_code != 10 )
329 printf(_("GlyphUnit::process_package FT_Load_Char failed - char: %li.\n"),
331 // Prevent a crash here
332 glyph->width = 8; glyph->height = 8;
333 glyph->pitch = 8; glyph->advance_x = 8;
334 glyph->left = 9; glyph->top = 9;
335 glyph->right = 0; glyph->bottom = 0;
336 glyph->freetype_index = 0;
337 glyph->data = new VFrame(glyph->width, glyph->height, BC_A8, glyph->pitch);
338 glyph->data->clear_frame();
339 glyph->data_stroke = 0;
341 // create outline glyph
342 if( plugin->config.stroke_width >= SMALL &&
343 (plugin->config.style & BC_FONT_OUTLINE) ) {
344 glyph->data_stroke = new VFrame(glyph->width, glyph->height, BC_A8, glyph->pitch);
345 glyph->data_stroke->clear_frame();
348 // char found and no outline desired
349 else if( plugin->config.stroke_width < SMALL ||
350 !(plugin->config.style & BC_FONT_OUTLINE) ) {
351 FT_Glyph glyph_image;
354 FT_Load_Glyph(freetype_face, gindex, FT_LOAD_DEFAULT);
355 FT_Get_Glyph(freetype_face->glyph, &glyph_image);
356 FT_Outline_Get_BBox(&((FT_OutlineGlyph) glyph_image)->outline, &bbox);
357 // printf("Stroke: Xmin: %ld, Xmax: %ld, Ymin: %ld, yMax: %ld\n",
358 // bbox.xMin,bbox.xMax, bbox.yMin, bbox.yMax);
360 glyph->width = bm.width = ((bbox.xMax - bbox.xMin + 63) >> 6);
361 glyph->height = bm.rows = ((bbox.yMax - bbox.yMin + 63) >> 6);
362 glyph->pitch = bm.pitch = bm.width;
363 bm.pixel_mode = FT_PIXEL_MODE_GRAY;
365 glyph->left = (bbox.xMin + 31) >> 6;
366 glyph->top = (bbox.yMax + 31) >> 6;
367 glyph->right = (bbox.xMax + 31) >> 6;
368 glyph->bottom = (bbox.yMin + 31) >> 6;
369 glyph->freetype_index = gindex;
370 glyph->advance_x = ((freetype_face->glyph->advance.x + 31) >> 6);
371 //printf("GlyphUnit::process_package 1 width=%d height=%d pitch=%d left=%d top=%d advance_x=%d freetype_index=%d\n",
372 //glyph->width, glyph->height, glyph->pitch, glyph->left, glyph->top, glyph->advance_x, glyph->freetype_index);
374 glyph->data = new VFrame(glyph->width, glyph->height, BC_A8, glyph->pitch);
375 glyph->data->clear_frame();
376 bm.buffer = glyph->data->get_data();
377 FT_Outline_Translate(&((FT_OutlineGlyph) glyph_image)->outline,
378 - bbox.xMin, - bbox.yMin);
379 FT_Outline_Get_Bitmap( freetype_library,
380 &((FT_OutlineGlyph) glyph_image)->outline,
382 FT_Done_Glyph(glyph_image);
385 // Outline desired and glyph found
386 FT_Glyph glyph_image;
391 FT_UInt npoints, ncontours;
393 FT_Load_Glyph(freetype_face, gindex, FT_LOAD_DEFAULT);
394 FT_Get_Glyph(freetype_face->glyph, &glyph_image);
396 // check if the outline is ok (non-empty);
397 FT_Outline_Get_BBox(&((FT_OutlineGlyph) glyph_image)->outline, &bbox);
398 if( bbox.xMin == 0 && bbox.xMax == 0 &&
399 bbox.yMin == 0 && bbox.yMax == 0 ) {
400 FT_Done_Glyph(glyph_image);
401 glyph->width = 0; glyph->height = 0;
402 glyph->left = 0; glyph->top = 0;
403 glyph->right = 0; glyph->bottom = 0;
406 new VFrame(glyph->width, glyph->height, BC_A8, glyph->pitch);
408 new VFrame(glyph->width, glyph->height, BC_A8, glyph->pitch);
409 glyph->advance_x =((int)(freetype_face->glyph->advance.x +
410 plugin->config.stroke_width * 64)) >> 6;
413 #if FREETYPE_MAJOR > 2 || (FREETYPE_MAJOR == 2 && FREETYPE_MINOR >= 2)
414 FT_Stroker_New(freetype_library, &stroker);
416 FT_Stroker_New(((FT_LibraryRec *)freetype_library)->memory, &stroker);
418 FT_Stroker_Set(stroker, (int)(plugin->config.stroke_width * 64),
419 FT_STROKER_LINECAP_ROUND, FT_STROKER_LINEJOIN_ROUND, 0);
420 FT_Stroker_ParseOutline(stroker, &((FT_OutlineGlyph) glyph_image)->outline,1);
421 FT_Stroker_GetCounts(stroker,&npoints, &ncontours);
422 if( npoints == 0 && ncontours == 0 ) {
423 // this never happens, but FreeType has a bug regarding Linotype's Palatino font
424 FT_Stroker_Done(stroker);
425 FT_Done_Glyph(glyph_image);
426 glyph->width = 0; glyph->height = 0;
427 glyph->left = 0; glyph->top = 0;
428 glyph->right = 0; glyph->bottom = 0;
431 new VFrame(glyph->width, glyph->height, BC_A8, glyph->pitch);
433 new VFrame(glyph->width, glyph->height, BC_A8, glyph->pitch);
434 glyph->advance_x =((int)(freetype_face->glyph->advance.x +
435 plugin->config.stroke_width * 64)) >> 6;
439 FT_Outline_New(freetype_library, npoints, ncontours, &outline);
441 outline.n_contours=0;
442 FT_Stroker_Export (stroker, &outline);
443 FT_Outline_Get_BBox(&outline, &bbox);
444 FT_Outline_Translate(&outline, - bbox.xMin, - bbox.yMin);
445 FT_Outline_Translate(&((FT_OutlineGlyph) glyph_image)->outline,
447 - bbox.yMin + (int)(plugin->config.stroke_width*32));
448 // printf("Stroke: Xmin: %ld, Xmax: %ld, Ymin: %ld, yMax: %ld\n"
449 // "Fill Xmin: %ld, Xmax: %ld, Ymin: %ld, yMax: %ld\n",
450 // bbox.xMin,bbox.xMax, bbox.yMin, bbox.yMax,
451 // bbox_fill.xMin,bbox_fill.xMax, bbox_fill.yMin, bbox_fill.yMax);
453 glyph->width = bm.width = ((bbox.xMax - bbox.xMin) >> 6)+1;
454 glyph->height = bm.rows = ((bbox.yMax - bbox.yMin) >> 6) +1;
455 glyph->pitch = bm.pitch = bm.width;
456 bm.pixel_mode = FT_PIXEL_MODE_GRAY;
458 glyph->left = (bbox.xMin + 31) >> 6;
459 glyph->top = (bbox.yMax + 31) >> 6;
460 glyph->right = (bbox.xMax + 31) >> 6;
461 glyph->bottom = (bbox.yMin + 31) >> 6;
462 glyph->freetype_index = gindex;
463 int real_advance = ((int)ceil((float)freetype_face->glyph->advance.x +
464 plugin->config.stroke_width * 64) >> 6);
465 glyph->advance_x = glyph->width + glyph->left;
466 if( real_advance > glyph->advance_x )
467 glyph->advance_x = real_advance;
468 //printf("GlyphUnit::process_package 1 width=%d height=%d "
469 // "pitch=%d left=%d top=%d advance_x=%d freetype_index=%d\n",
470 // glyph->width, glyph->height, glyph->pitch, glyph->left,
471 // glyph->top, glyph->advance_x, glyph->freetype_index);
474 //printf("GlyphUnit::process_package 1\n");
475 glyph->data = new VFrame(glyph->width, glyph->height, BC_A8, glyph->pitch);
476 glyph->data->clear_frame();
477 glyph->data_stroke = new VFrame(glyph->width, glyph->height, BC_A8, glyph->pitch);
478 glyph->data_stroke->clear_frame();
479 // for debugging memset( glyph->data_stroke->get_data(), 60, glyph->pitch * glyph->height);
480 bm.buffer=glyph->data->get_data();
481 FT_Outline_Get_Bitmap( freetype_library,
482 &((FT_OutlineGlyph) glyph_image)->outline,
484 bm.buffer=glyph->data_stroke->get_data();
485 FT_Outline_Get_Bitmap( freetype_library,
488 FT_Outline_Done(freetype_library,&outline);
489 FT_Stroker_Done(stroker);
490 FT_Done_Glyph(glyph_image);
492 //printf("GlyphUnit::process_package 2\n");
498 GlyphEngine::GlyphEngine(TitleMain *plugin, int cpus)
499 : LoadServer(cpus, cpus)
501 this->plugin = plugin;
504 void GlyphEngine::init_packages()
506 int current_package = 0;
507 for( int i=0; i<plugin->title_glyphs.count(); ++i ) {
508 if( !plugin->title_glyphs[i]->data ) {
509 GlyphPackage *pkg = (GlyphPackage*)get_package(current_package++);
510 pkg->glyph = plugin->title_glyphs[i];
515 LoadClient* GlyphEngine::new_client()
517 return new GlyphUnit(plugin, this);
520 LoadPackage* GlyphEngine::new_package()
522 return new GlyphPackage;
526 // Copy a single character to the text mask
527 TitlePackage::TitlePackage()
535 TitleUnit::TitleUnit(TitleMain *plugin, TitleEngine *server)
538 this->plugin = plugin;
539 this->engine = server;
543 static void get_mask_colors(int rgb, int color_model, int &rr, int &gg, int &bb)
545 int r = 0xff & (rgb>>16), g = 0xff & (rgb>>8), b = 0xff & (rgb>>0);
546 if( BC_CModels::is_yuv(color_model) ) bc_rgb2yuv(r,g,b, r,g,b);
547 rr = r; gg = g; bb = b;
550 void TitleUnit::draw_frame(int mode, VFrame *dst, VFrame *src, int x, int y)
552 int inp_w = src->get_w(), inp_h = src->get_h();
553 int out_w = dst->get_w(), out_h = dst->get_h();
554 unsigned char **inp_rows = src->get_rows();
555 unsigned char **out_rows = dst->get_rows();
557 int x_inp = 0, y_inp = 0;
559 if( x_out < 0 ) { x_inp = -x_out; x_out = 0; }
560 if( x_out+inp_w > out_w ) inp_w = out_w-x_out;
561 if( x_inp >= inp_w || x_out >= out_w ) return;
563 if( y_out < 0 ) { y_inp = -y_out; y_out = 0; }
564 if( y_out+inp_h > out_h ) inp_h = out_h-y_out;
565 if( y_inp >= inp_h || y_out >= out_h ) return;
566 int color = chr->color, max = 0xff;
567 int alpha = chr->alpha * chr->fade;
568 int ofs = BC_CModels::is_yuv(dst->get_color_model()) ? 0x80 : 0x00;
572 while( y_inp < inp_h && y_out < out_h ) {
573 uint8_t *inp = inp_rows[y_inp], *out = out_rows[y_out];
574 for( int xin=x_inp,xout=x_out*4+3; xin<inp_w; ++xin,xout+=4 ) {
575 out[xout] = inp[xin];
581 int r = 0, g = 0, b = 0;
582 get_mask_colors(color, plugin->text_model, r, g, b);
583 while( y_inp < inp_h && y_out < out_h ) {
584 uint8_t *inp = inp_rows[y_inp], *out = out_rows[y_out];
585 for( int xin=x_inp,xout=x_out*4+0; xin<inp_w; ++xin,xout+=4 ) {
586 int in_a = inp[xin], out_a = out[xout+3];
587 if( in_a + out_a == 0 ) continue;
588 int opacity = (in_a * alpha)/max, transp = out_a * (max - opacity)/max;
589 out[xout+0] = (opacity * r + transp * out[xout+0]) / max;
590 out[xout+1] = (opacity * (g-ofs) + transp * (out[xout+1]-ofs)) / max + ofs;
591 out[xout+2] = (opacity * (b-ofs) + transp * (out[xout+2]-ofs)) / max + ofs;
592 out[xout+3] = opacity + transp - (opacity * transp) / max;
598 while( y_inp < inp_h && y_out < out_h ) {
599 uint8_t *inp = inp_rows[y_inp], *out = out_rows[y_out];
600 for( int xin=x_inp,xout=x_out*4+0; xin<inp_w; ++xin,xout+=4 ) {
601 int xinp = xin*4, in_a = inp[xinp+3], out_a = out[xout+3];
602 if( in_a + out_a == 0 ) continue;
603 int opacity = (in_a * alpha)/max, transp = out_a * (max - opacity)/max;
604 out[xout+0] = (opacity * inp[xinp+0] + transp * out[xout+0]) / max;
605 out[xout+1] = (opacity * (inp[xinp+1]-ofs) + transp * (out[xout+1]-ofs)) / max + ofs;
606 out[xout+2] = (opacity * (inp[xinp+2]-ofs) + transp * (out[xout+2]-ofs)) / max + ofs;
607 out[xout+3] = opacity + transp - (opacity * transp) / max;
616 void TitleUnit::process_package(LoadPackage *package)
618 TitlePackage *pkg = (TitlePackage*)package;
619 int x = pkg->x, y = pkg->y;
623 VFrame *vframe = (VFrame *)chr->vp;
624 if( !vframe ) return;
625 draw_frame(DRAW_IMAGE, plugin->text_mask, vframe, x, y);
628 if( chr->wch == 0 || chr->wch == '\n') return;
629 TitleGlyph *glyph = (TitleGlyph *)chr->vp;
631 if( engine->do_dropshadow ) {
632 x += plugin->config.dropshadow;
633 y += plugin->config.dropshadow;
635 else if( plugin->config.dropshadow < 0 ) {
636 x -= plugin->config.dropshadow;
637 y -= plugin->config.dropshadow;
639 int mode = engine->do_dropshadow ? DRAW_ALPHA : DRAW_COLOR;
640 draw_frame(mode, plugin->text_mask, glyph->data, x, y);
641 if( plugin->config.stroke_width >= SMALL && (plugin->config.style & BC_FONT_OUTLINE) )
642 draw_frame(mode, plugin->stroke_mask, glyph->data_stroke, x, y);
647 TitleEngine::TitleEngine(TitleMain *plugin, int cpus)
648 : LoadServer(cpus, cpus)
650 this->plugin = plugin;
653 void TitleEngine::init_packages()
655 int current_package = 0;
656 for( int i=plugin->visible_char1; i<plugin->visible_char2; ++i ) {
657 TitlePackage *pkg = (TitlePackage*)get_package(current_package++);
658 TitleChar *chr = plugin->title_chars[i];
659 TitleRow *row = plugin->title_rows[chr->row];
661 pkg->x = row->x0 + chr->x - plugin->mask_x1;
662 pkg->y = row->y0 - chr->y - plugin->mask_y1;
663 //printf("draw '%c' at %d,%d\n",(int)pkg->chr->wch, pkg->x, pkg->y);
667 LoadClient* TitleEngine::new_client()
669 return new TitleUnit(plugin, this);
672 LoadPackage* TitleEngine::new_package()
674 return new TitlePackage;
677 void TitleTranslateUnit::translation_array_f(transfer_table_f* &table,
678 float in_x1, float in_x2, int in_total,
679 float out_x1, float out_x2, int out_total,
680 int &x1_out, int &x2_out)
683 //float offset = out_x1 - in_x1;
685 x1_out = (int)out_x1;
686 x2_out = MIN((int)ceil(out_x2), out_total);
687 if( x1_out >= x2_out ) return;
689 out_w = x2_out - x1_out;
690 table = new transfer_table_f[out_w];
691 bzero(table, sizeof(transfer_table_f) * out_w);
694 for( int out_x=x1_out; out_x<x2_out; ++out_x ) {
695 transfer_table_f *entry = &table[out_x - x1_out];
697 entry->in_x1 = (int)in_x;
698 entry->in_x2 = (int)in_x + 1;
700 // Get fraction of output pixel to fill
701 entry->output_fraction = 1;
703 if( out_x1 > out_x ) {
704 entry->output_fraction -= out_x1 - out_x;
707 if( out_x2 < out_x + 1 ) {
708 entry->output_fraction = (out_x2 - out_x);
711 // Advance in_x until out_x_fraction is filled
712 float out_x_fraction = entry->output_fraction;
713 float in_x_fraction = floor(in_x + 1) - in_x;
715 if( out_x_fraction <= in_x_fraction ) {
716 entry->in_fraction1 = out_x_fraction;
717 entry->in_fraction2 = 0.0;
718 in_x += out_x_fraction;
721 entry->in_fraction1 = in_x_fraction;
722 in_x += out_x_fraction;
723 entry->in_fraction2 = in_x - floor(in_x);
726 // Clip in_x and zero out fraction. This doesn't work for YUV.
727 if( entry->in_x2 >= in_total ) {
728 entry->in_x2 = in_total - 1;
729 entry->in_fraction2 = 0.0;
732 if( entry->in_x1 >= in_total ) {
733 entry->in_x1 = in_total - 1;
734 entry->in_fraction1 = 0.0;
741 // Copy a single character to the text mask
742 TitleOutlinePackage::TitleOutlinePackage()
748 TitleOutlineUnit::TitleOutlineUnit(TitleMain *plugin, TitleOutlineEngine *server)
751 this->plugin = plugin;
752 this->engine = server;
755 void TitleOutlineUnit::process_package(LoadPackage *package)
757 TitleOutlinePackage *pkg = (TitleOutlinePackage*)package;
758 int r = 0, g = 0, b = 0, outline_a = plugin->config.outline_alpha;
759 get_mask_colors(plugin->config.outline_color, plugin->mask_model, r, g, b);
761 unsigned char **outline_rows = plugin->outline_mask->get_rows();
762 unsigned char **text_rows = plugin->text_mask->get_rows();
763 int mask_w1 = plugin->text_mask->get_w()-1;
764 int mask_h1 = plugin->text_mask->get_h()-1;
765 int ofs = plugin->config.outline_size;
767 if( engine->pass == 0 ) {
768 // get max alpha under outline size macropixel
769 for( int y=pkg->y1, my=pkg->y2; y<my; ++y ) {
770 unsigned char *out_row = outline_rows[y];
771 int y1 = y - ofs, y2 = y + ofs;
772 CLAMP(y1, 0, mask_h1); CLAMP(y2, 0, mask_h1);
773 for( int x=0, mx=plugin->text_mask->get_w(); x<mx; ++x ) {
774 int x1 = x - ofs, x2 = x + ofs;
775 CLAMP(x1, 0, mask_w1); CLAMP(x2, 0, mask_w1);
777 for( int yy=y1; yy<=y2; ++yy ) {
778 unsigned char *text_row = text_rows[yy];
779 for( int xx = x1; xx <= x2; ++xx ) {
780 unsigned char *pixel = text_row + xx*4;
781 if( pixel[3] > max_a ) max_a = pixel[3];
784 unsigned char *out = out_row + x*4;
785 out[0] = r; out[1] = g; out[2] = b;
786 out[3] = (max_a * outline_a) / 0xff;
792 // Overlay text mask on top of outline mask
793 int ofs = BC_CModels::is_yuv(plugin->output->get_color_model()) ? 0x80 : 0;
794 for( int y=pkg->y1, my=pkg->y2; y<my; ++y ) {
795 unsigned char *outline_row = outline_rows[y];
796 unsigned char *text_row = text_rows[y];
797 for( int x=0, mx=plugin->text_mask->get_w(); x<mx; ++x ) {
798 unsigned char *out = text_row + x * 4;
799 unsigned char *inp = outline_row + x * 4;
800 int out_a = out[3], in_a = inp[3];
801 int transparency = in_a * (0xff - out_a) / 0xff;
802 out[0] = (out[0] * out_a + inp[0] * transparency) / 0xff;
803 out[1] = ((out[1]-ofs) * out_a + (inp[1]-ofs) * transparency) / 0xff + ofs;
804 out[2] = ((out[2]-ofs) * out_a + (inp[2]-ofs) * transparency) / 0xff + ofs;
805 out[3] = in_a + out_a - in_a*out_a / 0xff;
811 TitleOutlineEngine::TitleOutlineEngine(TitleMain *plugin, int cpus)
812 : LoadServer(cpus, cpus)
814 this->plugin = plugin;
817 void TitleOutlineEngine::init_packages()
819 int mask_h = plugin->text_mask->get_h();
820 if( !mask_h ) return;
821 int py1 = 0, py2 = 0;
822 int pkgs = get_total_packages();
823 for( int i=0; i<pkgs; py1=py2 ) {
824 TitleOutlinePackage *pkg = (TitleOutlinePackage*)get_package(i);
825 py2 = (++i * mask_h)/ pkgs;
826 pkg->y1 = py1; pkg->y2 = py2;
830 void TitleOutlineEngine::do_outline()
832 pass = 0; process_packages();
833 pass = 1; process_packages();
836 LoadClient* TitleOutlineEngine::new_client()
838 return new TitleOutlineUnit(plugin, this);
841 LoadPackage* TitleOutlineEngine::new_package()
843 return new TitleOutlinePackage;
848 TitleTranslatePackage::TitleTranslatePackage()
855 TitleTranslateUnit::TitleTranslateUnit(TitleMain *plugin, TitleTranslate *server)
858 this->plugin = plugin;
861 void TitleTranslate::run_packages()
863 // Generate scaling tables
864 delete [] x_table; x_table = 0;
865 delete [] y_table; y_table = 0;
867 float in_w = xlat_mask->get_w();
868 float in_h = xlat_mask->get_h();
869 float ix1 = 0, ix2 = ix1 + in_w;
870 float iy1 = 0, iy2 = iy1 + in_h;
872 float out_w = plugin->output->get_w();
873 float out_h = plugin->output->get_h();
874 float x1 = plugin->title_x, x2 = x1 + plugin->title_w;
875 float y1 = plugin->title_y, y2 = y1 + plugin->title_h;
876 bclamp(x1, 0, out_w); bclamp(y1, 0, out_h);
877 bclamp(x2, 0, out_w); bclamp(y2, 0, out_h);
879 float ox1 = plugin->title_x + plugin->text_x - plugin->text_x1 + plugin->mask_x1, ox2 = ox1 + in_w;
880 float oy1 = plugin->title_y + plugin->text_y - plugin->text_y1 + plugin->mask_y1, oy2 = oy1 + in_h;
881 if( ox1 < x1 ) { ix1 -= (ox1-x1); ox1 = x1; }
882 if( oy1 < y1 ) { iy1 -= (oy1-y1); oy1 = y1; }
883 if( ox2 > x2 ) { ix2 -= (ox2-x2); ox2 = x2; }
884 if( oy2 > y2 ) { iy2 -= (oy2-x2); oy2 = y2; }
886 printf("TitleTranslate text txy=%7.2f,%-7.2f\n"
887 " mxy1=%7d,%-7d mxy2=%7d,%-7d\n"
888 " xy1=%7.2f,%-7.2f xy2=%7.2f,%-7.2f\n"
889 " ixy1=%7.2f,%-7.2f ixy2=%7.2f,%-7.2f\n"
890 " oxy1=%7.2f,%-7.2f oxy2=%7.2f,%-7.2f\n",
891 plugin->text_x, plugin->text_y,
892 plugin->mask_x1, plugin->mask_y1, plugin->mask_x2, plugin->mask_y2,
893 x1,y1, x2,y2, ix1,iy1, ix2,iy2, ox1,oy1, ox2,oy2);
895 out_x1 = out_x2 = out_y1 = out_y2 = 0;
896 TitleTranslateUnit::translation_array_f(x_table,
897 ix1, ix2, in_w, ox1, ox2, out_w, out_x1, out_x2);
898 TitleTranslateUnit::translation_array_f(y_table,
899 iy1, iy2, in_h, oy1, oy2, out_h, out_y1, out_y2);
906 #define TRANSLATE(type, max, components, ofs) { \
907 unsigned char **in_rows = server->xlat_mask->get_rows(); \
908 type **out_rows = (type**)plugin->output->get_rows(); \
910 for( int y=pkg->y1; y<pkg->y2; ++y ) { \
911 int in_y1 = server->y_table[y].in_x1; \
912 int in_y2 = server->y_table[y].in_x2; \
913 float y_f1 = server->y_table[y].in_fraction1; \
914 float y_f2 = server->y_table[y].in_fraction2; \
915 unsigned char *in_row1 = in_rows[in_y1]; \
916 unsigned char *in_row2 = in_rows[in_y2]; \
917 type *out_row = out_rows[y + server->out_y1]; \
918 for( int i=0,x=server->out_x1; x<server->out_x2; ++i,++x ) { \
919 int in_x1 = 4*server->x_table[i].in_x1; \
920 int in_x2 = 4*server->x_table[i].in_x2; \
921 float x_f1 = server->x_table[i].in_fraction1; \
922 float x_f2 = server->x_table[i].in_fraction2; \
923 float f11 = x_f1 * y_f1 / (256.f-max); \
924 float f12 = x_f2 * y_f1 / (256.f-max); \
925 float f21 = x_f1 * y_f2 / (256.f-max); \
926 float f22 = x_f2 * y_f2 / (256.f-max); \
927 type input_r = (type)( \
928 in_row1[in_x1 + 0] * f11 + in_row1[in_x2 + 0] * f12 + \
929 in_row2[in_x1 + 0] * f21 + in_row2[in_x2 + 0] * f22 ); \
930 type input_g = (type)( \
931 in_row1[in_x1 + 1] * f11 + in_row1[in_x2 + 1] * f12 + \
932 in_row2[in_x1 + 1] * f21 + in_row2[in_x2 + 1] * f22 ); \
933 type input_b = (type)( \
934 in_row1[in_x1 + 2] * f11 + in_row1[in_x2 + 2] * f12 + \
935 in_row2[in_x1 + 2] * f21 + in_row2[in_x2 + 2] * f22 ); \
936 type input_a = (type)( \
937 in_row1[in_x1 + 3] * f11 + in_row1[in_x2 + 3] * f12 + \
938 in_row2[in_x1 + 3] * f21 + in_row2[in_x2 + 3] * f22 ); \
939 input_a = input_a * plugin->fade; \
940 if( components == 4 ) { \
941 type transparency = out_row[x * components + 3] * (max - input_a) / max; \
942 out_row[x * components + 0] = (input_r * input_a + \
943 out_row[x * components + 0] * transparency) / max; \
944 out_row[x * components + 1] = ((input_g-ofs) * input_a + \
945 (out_row[x * components + 1]-ofs) * transparency) / max + ofs; \
946 out_row[x * components + 2] = ((input_b-ofs) * input_a + \
947 (out_row[x * components + 2]-ofs) * transparency) / max + ofs; \
948 out_row[x * components + 3] = MAX(input_a, out_row[x * components + 3]); \
951 type transparency = max - input_a; \
952 out_row[x * components + 0] = (input_r * input_a + \
953 out_row[x * components + 0] * transparency) / max; \
954 out_row[x * components + 1] = ((input_g-ofs) * input_a + \
955 (out_row[x * components + 1]-ofs) * transparency) / max + ofs; \
956 out_row[x * components + 2] = ((input_b-ofs) * input_a + \
957 (out_row[x * components + 2]-ofs) * transparency) / max + ofs; \
964 void TitleTranslateUnit::process_package(LoadPackage *package)
966 TitleTranslatePackage *pkg = (TitleTranslatePackage*)package;
967 TitleTranslate *server = (TitleTranslate*)this->server;
969 switch( plugin->output->get_color_model() ) {
970 case BC_RGB888: TRANSLATE(unsigned char, 0xff, 3, 0); break;
971 case BC_RGB_FLOAT: TRANSLATE(float, 1.0, 3, 0); break;
972 case BC_YUV888: TRANSLATE(unsigned char, 0xff, 3, 0x80); break;
973 case BC_RGBA_FLOAT: TRANSLATE(float, 1.0, 4, 0); break;
974 case BC_RGBA8888: TRANSLATE(unsigned char, 0xff, 4, 0); break;
975 case BC_YUVA8888: TRANSLATE(unsigned char, 0xff, 4, 0x80); break;
977 //printf("TitleTranslateUnit::process_package 5\n");
981 TitleTranslate::TitleTranslate(TitleMain *plugin, int cpus)
982 : LoadServer(cpus, cpus)
984 this->plugin = plugin;
991 TitleTranslate::~TitleTranslate()
997 void TitleTranslate::init_packages()
999 int out_h = out_y2 - out_y1;
1000 int py1 = 0, py2 = 0;
1001 int pkgs = get_total_packages();
1002 for( int i=0; i<pkgs; py1=py2 ) {
1003 TitleTranslatePackage *pkg = (TitleTranslatePackage*)get_package(i);
1004 py2 = (++i*out_h) / pkgs;
1005 pkg->y1 = py1; pkg->y2 = py2;
1007 //printf("TitleTranslate::init_packages 2\n");
1010 LoadClient* TitleTranslate::new_client()
1012 return new TitleTranslateUnit(plugin, this);
1015 LoadPackage* TitleTranslate::new_package()
1017 return new TitleTranslatePackage;
1020 TitleCurNudge::TitleCurNudge(TitleParser *parser, TitleMain *plugin)
1021 : TitleStack<int>(parser, 0)
1024 TitleCurColor::TitleCurColor(TitleParser *parser, TitleMain *plugin)
1025 : TitleStack<int>(parser, plugin->config.color)
1028 TitleCurAlpha::TitleCurAlpha(TitleParser *parser, TitleMain *plugin)
1029 : TitleStack<int>(parser, plugin->config.alpha)
1032 TitleCurSize::TitleCurSize(TitleParser *parser, TitleMain *plugin)
1033 : TitleStack<float>(parser, plugin->config.size)
1036 TitleCurBold::TitleCurBold(TitleParser *parser, TitleMain *plugin)
1037 : TitleStack<int>(parser, (plugin->config.style & BC_FONT_BOLD) ? 1 : 0)
1040 TitleCurItalic::TitleCurItalic(TitleParser *parser, TitleMain *plugin)
1041 : TitleStack<int>(parser, (plugin->config.style & BC_FONT_ITALIC) ? 1 : 0)
1044 TitleCurFont::TitleCurFont(TitleParser *parser, TitleMain *plugin)
1045 : TitleStack<BC_FontEntry*>(parser, plugin->config_font())
1048 TitleCurCaps::TitleCurCaps(TitleParser *parser, TitleMain *plugin)
1049 : TitleStack<int>(parser, 0)
1052 TitleCurUnder::TitleCurUnder(TitleParser *parser, TitleMain *plugin)
1053 : TitleStack<int>(parser, 0)
1056 TitleCurBlink::TitleCurBlink(TitleParser *parser, TitleMain *plugin)
1057 : TitleStack<float>(parser, 0)
1060 TitleCurFixed::TitleCurFixed(TitleParser *parser, TitleMain *plugin)
1061 : TitleStack<int>(parser, 0)
1064 TitleCurSuper::TitleCurSuper(TitleParser *parser, TitleMain *plugin)
1065 : TitleStack<int>(parser, 0)
1069 TitleParser::TitleParser(TitleMain *plugin)
1071 cur_nudge(this, plugin),
1072 cur_color(this, plugin),
1073 cur_alpha(this, plugin),
1074 cur_size(this, plugin),
1075 cur_bold(this, plugin),
1076 cur_italic(this, plugin),
1077 cur_font(this, plugin),
1078 cur_caps(this, plugin),
1079 cur_under(this, plugin),
1080 cur_blink(this, plugin),
1081 cur_fixed(this, plugin),
1082 cur_super(this, plugin)
1084 bfr = out = plugin->config.wtext;
1085 lmt = bfr + plugin->config.wlen;
1088 TitleMain::TitleMain(PluginServer *server)
1089 : PluginVClient(server)
1098 freetype_library = 0;
1101 window_w = window_h = 0;
1102 title_x = title_y = 0;
1103 title_w = title_h = 0;
1104 text_w = text_h = 0;
1105 text_x = text_y = 0; mask_w = mask_h = 0;
1106 mask_x1 = mask_y1 = mask_x2 = mask_y2 = 0;
1108 visible_row1 = visible_char1 = 0;
1109 visible_row2 = visible_char2 = 0;
1111 input = 0; output = 0;
1112 output_model = BC_RGBA8888;
1113 mask_model = BC_RGBA8888;
1114 background = 0; bg_file = 0; bg_frame = 0;
1115 render_engine = 0; video_cache = 0;
1117 cpus = PluginClient::smp + 1;
1118 if( cpus > 8 ) cpus = 8;
1120 need_reconfigure = 1;
1123 TitleMain::~TitleMain()
1126 background->Garbage::remove_user();
1129 delete render_engine;
1131 delete overlay_frame;
1135 delete outline_mask;
1137 delete glyph_engine;
1138 delete title_engine;
1140 FT_Done_Face(freetype_face);
1141 if( freetype_library )
1142 FT_Done_FreeType(freetype_library);
1144 delete outline_engine;
1147 const char* TitleMain::plugin_title() { return C_("Title"); }
1148 int TitleMain::is_realtime() { return 1; }
1149 int TitleMain::is_synthesis() { return 1; }
1151 NEW_WINDOW_MACRO(TitleMain, TitleWindow);
1154 void TitleMain::build_previews(TitleWindow *gui)
1156 BC_Resources *resources = BC_WindowBase::get_resources();
1157 ArrayList<BC_FontEntry*>&fonts = *resources->fontlist;
1159 for( int font_number=0; font_number<fonts.size(); ++font_number ) {
1160 BC_FontEntry *font = fonts.get(font_number);
1161 // already have examples
1162 if( font->image ) return;
1165 // create example bitmaps
1166 FT_Library freetype_library = 0; // Freetype library
1167 FT_Face freetype_face = 0;
1168 const char *test_string = "Aa";
1169 char new_path[BCTEXTLEN];
1170 int text_height = gui->get_text_height(LARGEFONT);
1171 int max_height = 3*text_height/2, max_width = 2 * max_height;
1172 int text_color = resources->default_text_color;
1173 int r = (text_color >> 16) & 0xff;
1174 int g = (text_color >> 8) & 0xff;
1175 int b = text_color & 0xff;
1176 // dimensions for each line
1177 int height[fonts.size()];
1178 int ascent[fonts.size()];
1180 // pass 1 gets the extents for all the fonts
1181 // pass 2 draws the image
1184 for( int pass=0; pass<2; ++pass ) {
1185 if( resources->font_debug )
1186 printf("Titler: build previews pass %d\n",pass);
1187 //printf("TitleMain::build_previews %d %d %d\n",
1188 //__LINE__, text_height, total_h);
1189 for( int font_number=0; font_number<fonts.size(); ++font_number ) {
1190 BC_FontEntry *font = fonts[font_number];
1191 // test if font of same name has been processed
1193 for( int i=0; i<font_number; ++i ) {
1194 if( !strcasecmp(fonts[i]->displayname, font->displayname) ) {
1196 font->image = new VFrame(*fonts[i]->image);
1203 if( skip ) continue;
1204 if( resources->font_debug )
1205 printf("Titler: preview %s = %s\n",font->displayname, font->path);
1207 font->image = new VFrame;
1208 font->image->set_use_shm(0);
1209 font->image->reallocate(0, -1, 0, 0, 0,
1210 total_w, total_h, BC_RGBA8888, -1);
1211 font->image->clear_frame();
1214 int current_w = 1, current_h = 1;
1215 int current_x = 0, current_ascent = 0;
1216 int len = strlen(test_string);
1218 for( int j=0; j<len; ++j ) {
1219 FT_ULong c = test_string[j];
1220 // memory leaks here are fatal
1221 // check_char_code_path(freetype_library,
1224 // (char *)new_path);
1225 strcpy(new_path, font->path);
1226 if( load_freetype_face(freetype_library, freetype_face, new_path)) continue;
1227 FT_Set_Pixel_Sizes(freetype_face, text_height, 0);
1228 if( FT_Load_Char(freetype_face, c, FT_LOAD_RENDER) ) continue;
1229 int glyph_w = freetype_face->glyph->bitmap.width;
1230 int glyph_h = freetype_face->glyph->bitmap.rows;
1231 if( glyph_h > max_height ) glyph_h = max_height;
1232 int glyph_a = freetype_face->glyph->advance.x >> 6;
1233 int glyph_t = freetype_face->glyph->bitmap_top;
1235 current_w = current_x + glyph_w;
1236 if( current_w > max_width ) current_w = max_width;
1237 if( total_w < current_w ) total_w = current_w;
1238 if( current_ascent < glyph_t ) current_ascent = glyph_t;
1239 if( current_h < glyph_h ) current_h = glyph_h;
1240 if( total_h < glyph_h ) total_h = glyph_h;
1243 // copy 1 row at a time, center vertically
1244 int out_y = (total_h-height[font_number])/2 + ascent[font_number]-glyph_t;
1245 if( out_y < 0 ) out_y = 0;
1246 for( int in_y = 0; in_y < glyph_h && out_y < total_h; ++in_y, ++out_y ) {
1247 unsigned char *in_row = freetype_face->glyph->bitmap.buffer +
1248 freetype_face->glyph->bitmap.pitch * in_y;
1249 int out_x = current_x;
1250 unsigned char *out_row = font->image->get_rows()[out_y] +
1253 for( int in_x = 0; in_x < glyph_w && out_x < total_w; ++in_x, ++out_x ) {
1254 *out_row = (*in_row * r +
1255 (0xff - *in_row) * *out_row) / 0xff; ++out_row;
1256 *out_row = (*in_row * g +
1257 (0xff - *in_row) * *out_row) / 0xff; ++out_row;
1258 *out_row = (*in_row * b +
1259 (0xff - *in_row) * *out_row) / 0xff; ++out_row;
1260 *out_row = MAX(*in_row, *out_row); ++out_row;
1265 current_x += glyph_a;
1267 height[font_number] = current_h;
1268 ascent[font_number] = current_ascent;
1272 if( freetype_library ) FT_Done_FreeType(freetype_library);
1276 //This checks if char_code is on the selected font, else it changes font to the first compatible //Akirad
1277 int TitleMain::check_char_code_path(FT_Library &freetype_library,
1278 char *path_old, FT_ULong &char_code, char *path_new)
1280 FT_Face temp_freetype_face;
1284 FcChar8 *file, *format;
1289 config = FcConfigGetCurrent();
1290 FcConfigSetRescanInterval(config, 0);
1292 pat = FcPatternCreate();
1293 os = FcObjectSetBuild ( FC_FILE, FC_FONTFORMAT, (char *) 0);
1294 fs = FcFontList(config, pat, os);
1296 char tmpstring[BCTEXTLEN];
1297 int limit_to_truetype = 0; //if you want to limit search to truetype put 1
1298 if( !freetype_library ) FT_Init_FreeType(&freetype_library);
1299 if( !FT_New_Face(freetype_library, path_old, 0, &temp_freetype_face) ) {
1300 FT_Set_Pixel_Sizes(temp_freetype_face, 128, 0);
1301 int gindex = FT_Get_Char_Index(temp_freetype_face, char_code);
1302 if( gindex != 0 && char_code == 10 ) {
1303 strcpy(path_new, path_old);
1309 for( int i=0; fs && i<fs->nfont; ++i ) {
1310 font = fs->fonts[i];
1311 FcPatternGetString(font, FC_FONTFORMAT, 0, &format);
1312 if( strcmp((char *)format, "TrueType") && !limit_to_truetype ) continue;
1313 if( FcPatternGetString(font, FC_FILE, 0, &file) != FcResultMatch ) continue;
1314 sprintf(tmpstring, "%s", file);
1315 if( !FT_New_Face(freetype_library, tmpstring, 0, &temp_freetype_face) ) continue;
1316 FT_Set_Pixel_Sizes(temp_freetype_face, 128, 0);
1317 int gindex = FT_Get_Char_Index(temp_freetype_face, char_code);
1318 if( gindex != 0 && char_code == 10 ) {
1319 sprintf(path_new, "%s", tmpstring);
1327 if( fs ) FcFontSetDestroy(fs);
1328 if( temp_freetype_face ) FT_Done_Face(temp_freetype_face);
1329 temp_freetype_face = 0;
1332 strcpy(path_new, path_old);
1340 int TitleMain::load_freetype_face(FT_Library &freetype_library,
1341 FT_Face &freetype_face, const char *path)
1343 //printf("TitleMain::load_freetype_face 1\n");
1344 if( !freetype_library )
1345 FT_Init_FreeType(&freetype_library);
1347 FT_Done_Face(freetype_face);
1349 //printf("TitleMain::load_freetype_face 2\n");
1351 // Use freetype's internal function for loading font
1352 if( FT_New_Face(freetype_library, path, 0, &freetype_face) ) {
1353 fprintf(stderr, _("TitleMain::load_freetype_face %s failed.\n"), path);
1355 freetype_library = 0;
1361 int TitleMain::load_font(BC_FontEntry *font)
1363 if( !font || load_freetype_face(freetype_library,freetype_face, font->path) ) return 1;
1364 strcpy(text_font, font->displayname);
1369 Indexable *TitleMain::open_background(const char *filename)
1371 delete render_engine; render_engine = 0;
1372 delete video_cache; video_cache = 0;
1373 delete bg_file; bg_file = new File;
1375 Asset *asset = new Asset(filename);
1376 int result = bg_file->open_file(server->preferences, asset, 1, 0);
1377 if( result == FILE_OK ) return (Indexable *)asset;
1379 asset->Garbage::remove_user();
1380 delete bg_file; bg_file = 0;
1381 if( result != FILE_IS_XML ) return 0;
1384 if( xml_file.read_from_file(filename) ) return 0;
1385 EDL *nested_edl = new EDL;
1386 nested_edl->create_objects();
1387 nested_edl->set_path(filename);
1388 nested_edl->load_xml(&xml_file, LOAD_ALL);
1389 TransportCommand command;
1390 //command.command = audio_tracks ? NORMAL_FWD : CURRENT_FRAME;
1391 command.command = CURRENT_FRAME;
1392 command.get_edl()->copy_all(nested_edl);
1393 command.change_type = CHANGE_ALL;
1394 command.realtime = 0;
1395 render_engine = new RenderEngine(0, server->preferences, 0, 0);
1396 render_engine->set_vcache(video_cache = new CICache(server->preferences));
1397 render_engine->arm_command(&command);
1398 return (Indexable *)nested_edl;
1401 int TitleMain::read_background(VFrame *frame, int64_t position, int color_model)
1404 VFrame *iframe = frame;
1405 int bw = background->get_w(), bh = background->get_h();
1406 if( background->is_asset ) {
1407 Asset *asset = (Asset *)background;
1408 if( bw != asset->width || bh != asset->height )
1409 iframe = new_temp(asset->width, asset->height, color_model);
1410 int64_t source_position = (int64_t)(position *
1411 asset->frame_rate / project_frame_rate);
1412 if( config.loop_playback ) {
1413 int64_t loop_size = asset->get_video_frames();
1414 source_position -= (int64_t)(source_position / loop_size) * loop_size;
1417 bg_file->set_video_position(source_position, 0);
1418 result = bg_file->read_frame(iframe);
1422 EDL *nested_edl = (EDL *)background;
1423 if( color_model != nested_edl->session->color_model ||
1424 bw != nested_edl->session->output_w ||
1425 bh != nested_edl->session->output_h )
1427 nested_edl->session->output_w,
1428 nested_edl->session->output_h,
1429 nested_edl->session->color_model);
1430 int64_t source_position = (int64_t)(position *
1431 nested_edl->session->frame_rate / project_frame_rate);
1432 if( config.loop_playback ) {
1433 int64_t loop_size = nested_edl->get_video_frames();
1434 source_position -= (int64_t)(source_position / loop_size) * loop_size;
1436 if( render_engine->vrender )
1437 result = render_engine->vrender->process_buffer(iframe, source_position, 0);
1439 if( !result && iframe != frame )
1440 frame->transfer_from(iframe);
1444 void TitleMain::draw_background()
1447 if( strcmp(background->path, config.background_path) ) {
1449 background->Garbage::remove_user();
1458 if( !background && config.background_path[0] && !access(config.background_path,R_OK) )
1459 background = open_background(config.background_path);
1461 int bw = background->get_w(), bh = background->get_h();
1462 if( bg_frame && (bg_frame->get_w() != bw || bg_frame->get_h() != bh ||
1463 bg_frame->get_color_model() != output_model) ) {
1464 delete bg_frame; bg_frame = 0;
1467 bg_frame = new VFrame(0, -1, bw, bh, output_model, -1);
1468 int64_t position = get_source_position() - get_source_start();
1469 if( !read_background(bg_frame, position, output_model) ) {
1470 if( !overlay_frame )
1471 overlay_frame = new OverlayFrame(cpus);
1472 float in_x1 = 0, in_x2 = bg_frame->get_w();
1473 float in_y1 = 0, in_y2 = bg_frame->get_h();
1474 float out_x1 = config.title_x, out_x2 = out_x1 + title_w;
1475 float out_y1 = config.title_y, out_y2 = out_y1 + title_h;
1476 overlay_frame->overlay(output, bg_frame,
1477 in_x1,in_y1, in_x2,in_y2,
1478 out_x1,out_y1, out_x2,out_y2,
1479 1, TRANSFER_NORMAL, CUBIC_LINEAR);
1484 BC_FontEntry* TitleMain::get_font(const char *font_name, int style)
1486 if( !strcmp("fixed", font_name) )
1487 font_name = FIXED_FONT;
1488 int flavor = FL_WIDTH_MASK |
1489 ((style & BC_FONT_ITALIC) != 0 ? FL_SLANT_ITALIC | FL_SLANT_OBLIQUE : FL_SLANT_ROMAN) |
1490 ((style & BC_FONT_BOLD) != 0 ? FL_WEIGHT_BOLD | FL_WEIGHT_DEMIBOLD |
1491 FL_WEIGHT_EXTRABOLD| FL_WEIGHT_BLACK | FL_WEIGHT_EXTRABLACK :
1492 FL_WEIGHT_BOOK | FL_WEIGHT_NORMAL | FL_WEIGHT_MEDIUM |
1493 FL_WEIGHT_LIGHT | FL_WEIGHT_EXTRALIGHT | FL_WEIGHT_THIN);
1495 int mask = FL_WEIGHT_MASK | FL_SLANT_MASK | FL_WIDTH_MASK;
1497 BC_Resources *resources = BC_WindowBase::get_resources();
1498 BC_FontEntry *font = resources->find_fontentry(font_name, flavor, mask, style);
1499 if( font && strcmp(font_name, font->displayname) ) font = 0;
1502 BC_FontEntry* TitleMain::config_font()
1504 BC_FontEntry *font = get_font(config.font, config.style);
1505 if( !font || load_font(font) )
1506 load_font(font = get_font(FIXED_FONT,0));
1511 static inline bool is_ltr(wchar_t wch) { return iswalpha(wch); }
1512 static inline bool is_nbr(wchar_t wch) { return iswdigit(wch); }
1513 static inline bool is_ws(wchar_t wch) { return wch==' ' || wch=='\t'; }
1514 static inline bool is_idch(wchar_t wch) { return is_ltr(wch) || is_nbr(wch) || wch=='_'; }
1516 // return eof=-1, chr=0, opener=1, closer=2
1517 int TitleParser::wget(wchar_t &wch)
1519 wchar_t *wip = wid, *wtp = wtxt; *wip = 0; *wtp = 0;
1520 int ilen = sizeof(wid)/sizeof(wid[0]);
1521 int tlen = sizeof(wtxt)/sizeof(wtxt[0]);
1523 while( (ich=wnext()) >= 0 ) {
1525 if( (ich=wnext()) == '\n' ) continue;
1529 if( ich == '<' ) break;
1530 if( ich != '#' ) { wch = ich; return 0; }
1531 while( (ich=wnext()) >= 0 && ich != '\n' );
1532 if( ich < 0 ) break;
1534 if( ich < 0 ) return -1;
1535 int ret = 1; long pos = tell();
1536 if( (ich=wnext()) == '/' ) { ret = 2; ich = wnext(); }
1539 while( is_idch(ich=wnext()) )
1540 if( --ilen > 0 ) *wip++ = ich;
1543 while( is_ws(ich) ) ich = wnext();
1544 while( ich >= 0 && ich != '>' ) {
1545 if( ich == '\n' || ich == '<' ) { ich = -1; break; }
1546 if( ich == '\\' && (ich=wnext()) < 0 ) break;
1547 if( --tlen > 0 ) *wtp++ = ich;
1551 if( ich < 0 ) { ich = '<'; seek(pos); ret = 0; }
1555 int TitleParser::tget(wchar_t &wch)
1557 int ret = wget(wch);
1559 int wid_len = wcslen(wid)+1;
1560 BC_Resources::encode(
1561 BC_Resources::wide_encoding, plugin->config.encoding,
1562 (char*)wid,wid_len*sizeof(wid[0]), (char *)id,sizeof(id));
1563 int wtxt_len = wcslen(wtxt)+1;
1564 BC_Resources::encode(
1565 BC_Resources::wide_encoding, plugin->config.encoding,
1566 (char*)wtxt,wtxt_len*sizeof(wtxt[0]), (char *)text,sizeof(text));
1571 TitleGlyph *TitleMain::get_glyph(FT_ULong char_code, BC_FontEntry *font, int size, int style)
1573 for( int i=0, n=title_glyphs.count(); i<n; ++i ) {
1574 TitleGlyph *glyph = title_glyphs[i];
1575 if( glyph->char_code == char_code && glyph->font == font &&
1576 glyph->size == size && glyph->style == style )
1582 int TitleMain::get_width(TitleGlyph *cur, TitleGlyph *nxt)
1584 if( !cur || cur->char_code == '\n' ) return 0;
1585 int result = cur->advance_x;
1586 if( !nxt ) return result;
1588 if( !FT_Get_Kerning(freetype_face,
1589 cur->freetype_index, nxt->freetype_index,
1590 ft_kerning_default, &kerning) )
1591 result += (kerning.x >> 6);
1596 VFrame *TitleMain::get_image(const char *path)
1598 for( int i=0; i<title_images.count(); ++i ) {
1599 if( !strcmp(path, title_images[i]->path) )
1600 return title_images[i]->vframe;
1605 VFrame *TitleMain::add_image(const char *path)
1607 VFrame *vframe = get_image(path);
1608 if( !vframe && (vframe=VFramePng::vframe_png(path)) != 0 ) {
1609 if( vframe->get_color_model() != text_model ) {
1610 VFrame *frame = new VFrame(vframe->get_w(), vframe->get_h(), text_model);
1611 frame->transfer_from(vframe); delete vframe;
1614 title_images.append(new TitleImage(path, vframe));
1619 int TitleCurColor::set(const char *txt)
1621 #define BCOLOR(NM) { #NM, NM }
1622 static const struct { const char *name; int color; } colors[] = {
1623 BCOLOR(MNBLUE), BCOLOR(ORANGE), BCOLOR(BLOND),
1624 BCOLOR(MNGREY), BCOLOR(FGGREY), BCOLOR(FTGREY), BCOLOR(DKGREY),
1625 BCOLOR(LTGREY), BCOLOR(MEGREY), BCOLOR(DMGREY), BCOLOR(MDGREY),
1626 BCOLOR(LTPURPLE),BCOLOR(MEPURPLE),BCOLOR(MDPURPLE), BCOLOR(DKPURPLE),
1627 BCOLOR(LTCYAN), BCOLOR(MECYAN), BCOLOR(MDCYAN), BCOLOR(DKCYAN),
1628 BCOLOR(YELLOW), BCOLOR(LTYELLOW),BCOLOR(MEYELLOW), BCOLOR(MDYELLOW),
1629 BCOLOR(LTGREEN), BCOLOR(DKGREEN), BCOLOR(DKYELLOW), BCOLOR(LTPINK),
1630 BCOLOR(PINK), BCOLOR(LTBLUE), BCOLOR(DKBLUE),
1631 BCOLOR(RED), BCOLOR(GREEN), BCOLOR(BLUE),
1632 BCOLOR(BLACK), BCOLOR(WHITE),
1636 if( txt[0] == '#' ) {
1637 if( sscanf(&txt[1], "%x", &color) != 1 ) return 1;
1640 int i = sizeof(colors)/sizeof(colors[0]);
1641 while( --i >= 0 && strcasecmp(txt, colors[i].name) );
1642 if( i < 0 ) return 1;
1643 color = colors[i].color;
1647 color = parser->plugin->config.color;
1652 int TitleCurAlpha::set(const char *txt)
1655 parser->plugin->config.alpha :
1656 strtof(txt,(char**)&txt) * 255;
1658 if( *txt || alpha < 0 || alpha > 255 ) return 1;
1663 int TitleCurSize::set(const char *txt)
1667 size = parser->plugin->config.size;
1669 else if( *txt == '+' || *txt == '-' ) {
1671 for( int ch; (ch=*txt)!=0; ++txt ) {
1672 if( ch == '+' ) { size *= 5./4.; continue; }
1673 if( ch == '-' ) { size *= 4./5.; continue; }
1678 size = strtof(txt,(char**)&txt);
1680 if( *txt || size <= 0 || size > 2048 ) return 1;
1681 int style = parser->cur_font.style();
1682 if( !parser->cur_font.set(0,style) ) return 1;
1686 int TitleCurSize::unset(const char *txt)
1688 if( pop() ) return 1;
1689 int style = parser->cur_font.style();
1690 parser->cur_font.set(0,style);
1695 int TitleCurBold::set(const char *txt)
1697 int bold = !*txt ? 1 :
1698 strtol(txt,(char**)&txt,0);
1699 if( *txt || bold < 0 || bold > 1 ) return 1;
1700 int style = parser->cur_font.style();
1701 if( bold ) style |= BC_FONT_BOLD;
1702 else style &= ~BC_FONT_BOLD;
1703 if( !parser->cur_font.set(0,style) ) return 1;
1707 int TitleCurBold::unset(const char *txt)
1709 if( pop() ) return 1;
1710 int style = parser->cur_font.style();
1711 parser->cur_font.set(0,style);
1715 int TitleCurItalic::set(const char *txt)
1717 int italic = !*txt ? 1 :
1718 strtol(txt,(char**)&txt,0);
1719 if( *txt || italic < 0 || italic > 1 ) return 1;
1720 int style = parser->cur_font.style();
1721 if( italic ) style |= BC_FONT_ITALIC;
1722 else style &= ~BC_FONT_ITALIC;
1723 if( !parser->cur_font.set(0,style) ) return 1;
1727 int TitleCurItalic::unset(const char *txt)
1729 if( pop() ) return 1;
1730 int style = parser->cur_font.style();
1731 parser->cur_font.set(0,style);
1736 int TitleCurFont::style()
1739 if( parser->cur_bold ) style |= BC_FONT_BOLD;
1740 if( parser->cur_italic ) style |= BC_FONT_ITALIC;
1743 BC_FontEntry* TitleCurFont::get(const char *txt, int style)
1745 if( !txt ) txt = parser->plugin->text_font;
1746 else if( !*txt ) txt = parser->plugin->config.font;
1747 return parser->plugin->get_font(txt, style);
1749 BC_FontEntry *TitleCurFont::set(const char *txt, int style)
1751 BC_FontEntry *font = get(txt, style);
1752 if( !font || parser->plugin->load_font(font) ) return 0;
1753 if( !txt ) (BC_FontEntry*&)*this = font;
1756 int TitleCurFont::set(const char *txt)
1758 BC_FontEntry *font = set(txt, style());
1759 if( !font ) return 1;
1763 int TitleCurFont::unset(const char *txt)
1765 if( *txt || pop() ) return 1;
1766 BC_FontEntry *font = *this;
1767 if( !font ) return 1;
1768 font = get(font->displayname, style());
1769 if( !font ) return 1;
1770 (BC_FontEntry*&)*this = font;
1774 int TitleCurCaps::set(const char *txt)
1776 int caps = !*txt ? 1 : strtol(txt,(char **)&txt,0);
1777 if( *txt || caps < -1 || caps > 1 ) return 1;
1782 int TitleCurBlink::set(const char *txt)
1784 float blink = !*txt ? 1 : strtof(txt,(char **)&txt);
1785 if( *txt ) return 1;
1790 int TitleCurFixed::set(const char *txt)
1793 parser->cur_size*3/4 :
1794 strtol(txt,(char **)&txt,0);
1795 if( *txt || fixed < 0 ) return 1;
1800 int TitleCurSuper::set(const char *txt)
1802 int super = !*txt ? 1 : strtol(txt,(char **)&txt,0);
1803 if( *txt || super < -1 || super > 1 ) return 1;
1808 int TitleCurNudge::set(const char *txt)
1810 if( !*txt ) return 1;
1811 short nx = strtol(txt,(char **)&txt,0);
1812 if( *txt++ != ',' ) return 1;
1813 short ny = strtol(txt,(char **)&txt,0);
1814 if( *txt ) return 1;
1815 int nudge = (nx << 16) | (ny & 0xffff);
1820 int TitleParser::set_attributes(int ret)
1822 if( !strcmp(id,KW_NUDGE) ) return ret>1 ? cur_nudge.unset(text) : cur_nudge.set(text);
1823 if( !strcmp(id,KW_COLOR) ) return ret>1 ? cur_color.unset(text) : cur_color.set(text);
1824 if( !strcmp(id,KW_ALPHA) ) return ret>1 ? cur_alpha.unset(text) : cur_alpha.set(text);
1825 if( !strcmp(id,KW_FONT) ) return ret>1 ? cur_font.unset(text) : cur_font.set(text);
1826 if( !strcmp(id,KW_SIZE) ) return ret>1 ? cur_size.unset(text) : cur_size.set(text);
1827 if( !strcmp(id,KW_BOLD) ) return ret>1 ? cur_bold.unset(text) : cur_bold.set(text);
1828 if( !strcmp(id,KW_ITALIC) ) return ret>1 ? cur_italic.unset(text) : cur_italic.set(text);
1829 if( !strcmp(id,KW_CAPS) ) return ret>1 ? cur_caps.unset(text) : cur_caps.set(text);
1830 if( !strcmp(id,KW_UL) ) return ret>1 ? cur_under.unset(text) : cur_under.set(text);
1831 if( !strcmp(id,KW_BLINK) ) return ret>1 ? cur_blink.unset(text) : cur_blink.set(text);
1832 if( !strcmp(id,KW_FIXED) ) return ret>1 ? cur_fixed.unset(text) : cur_fixed.set(text);
1833 if( !strcmp(id,KW_SUP) ) return ret>1 ? cur_super.unset(text) : cur_super.set(text);
1838 void TitleMain::load_glyphs()
1840 // Build table of all glyphs needed
1841 TitleParser wchrs(this);
1842 int total_packages = 0;
1844 while( !wchrs.eof() ) {
1845 wchar_t wch1 = wchrs.wcur(), wch;
1846 long ipos = wchrs.tell();
1847 int ret = wchrs.tget(wch);
1849 if( !wchrs.set_attributes(ret) ) continue;
1850 if( !strcmp(wchrs.id,KW_PNG) && add_image(wchrs.text) ) continue;
1851 wch = wch1; wchrs.seek(ipos+1);
1854 if( ret || wch == '\n' ) continue;
1856 int cur_caps = wchrs.cur_caps;
1857 if( cur_caps > 0 ) wch = towupper(wch);
1858 else if( cur_caps < 0 ) wch = towlower(wch);
1859 BC_FontEntry *cur_font = wchrs.cur_font;
1860 int cur_size = wchrs.cur_size;
1862 int cur_bold = wchrs.cur_bold;
1863 if( cur_bold ) cur_style |= BC_FONT_BOLD;
1864 int cur_italic = wchrs.cur_italic;
1865 if( cur_italic ) cur_style |= BC_FONT_ITALIC;
1866 int cur_super = wchrs.cur_super;
1867 if( cur_super ) cur_size /= 2;
1869 for( int j=0; j<title_glyphs.count(); ++j ) {
1870 TitleGlyph *glyph = title_glyphs[j];
1871 if( glyph->char_code == (FT_ULong)wch && glyph->font == cur_font &&
1872 glyph->size == cur_size && glyph->style == cur_style ) {
1877 if( !exists && cur_font ) {
1879 TitleGlyph *glyph = new TitleGlyph;
1880 glyph->char_code = (FT_ULong)wch;
1881 glyph->font = cur_font;
1882 glyph->size = cur_size;
1883 glyph->style = cur_style;
1884 title_glyphs.append(glyph);
1889 glyph_engine = new GlyphEngine(this, cpus);
1891 glyph_engine->set_package_count(total_packages);
1892 glyph_engine->process_packages();
1896 TitleImage::TitleImage(const char *path, VFrame *vfrm)
1898 this->path = cstrdup(path);
1899 this->vframe = vfrm;
1901 TitleImage::~TitleImage()
1907 TitleChar *TitleChar::init(int typ, void *vp)
1923 TitleRow *TitleRow::init()
1926 x1 = y2 = 0; //MAX_FLT;
1927 y1 = x2 = 0; //MIN_FLT;
1931 int TitleMain::get_text()
1933 // Determine extents of total text
1934 title_chars.reset();
1936 int pitch = config.line_pitch;
1937 float font_h = config.size;
1940 TitleParser wchrs(this);
1943 float row_w = 0, row_h = 0;
1944 float row_x = 0, row_y = 0;
1948 if( !row ) row = title_rows.add();
1950 long ipos = wchrs.tell();
1951 wchar_t wch1 = wchrs.wcur(), wch;
1952 int ret = wchrs.tget(wch);
1953 if( ret < 0 || wch == '\n' ) {
1954 if( row->x1 > row->x2 ) row->x1 = row->x2 = 0;
1955 if( row->y2 > row->y1 ) row->y1 = row->y2 = 0;
1956 int dy = row->y1 - descent;
1957 row_y += pitch ? pitch : dy > font_h ? dy : font_h;
1960 if( row_x > row_w ) row_w = row_x;
1961 if( row_y > row_h ) row_h = row_y;
1962 text_rows = title_rows.count();
1964 if( ret < 0 ) break;
1967 BC_FontEntry *cur_font = wchrs.cur_font;
1968 int cur_color = wchrs.cur_color;
1969 int cur_alpha = wchrs.cur_alpha;
1970 float cur_size = wchrs.cur_size;
1971 int cur_caps = wchrs.cur_caps;
1972 int cur_under = wchrs.cur_under;
1973 float cur_blink = wchrs.cur_blink;
1974 int cur_fixed = wchrs.cur_fixed;
1975 int cur_super = wchrs.cur_super;
1976 int cur_nudge = wchrs.cur_nudge;
1978 int cur_bold = wchrs.cur_bold;
1979 if( cur_bold ) cur_style |= BC_FONT_BOLD;
1980 int cur_italic = wchrs.cur_italic;
1981 if( cur_italic ) cur_style |= BC_FONT_ITALIC;
1982 short nx = cur_nudge >> 16, ny = cur_nudge;
1983 int cx = nx, cy = ny, cw = 0, ch = 0, dx = 0;
1985 if( !wchrs.set_attributes(ret) ) continue;
1987 if( !strcmp(wchrs.id,KW_PNG) ) {
1988 VFrame *png_image = get_image(wchrs.text);
1990 chr = title_chars.add(CHAR_IMAGE, png_image);
1991 cy += ch = png_image->get_h();
1992 cw = dx = png_image->get_w();
1997 wch = wch1; wchrs.seek(ipos+1);
2001 if( cur_caps > 0 ) wch = towupper(wch);
2002 else if( cur_caps < 0 ) wch = towlower(wch);
2003 int size = !cur_super ? cur_size : cur_size/2;
2004 TitleGlyph *gp = get_glyph(wch, cur_font, size, cur_style);
2007 if( cur_super > 0 ) cy += cur_size-4*size/3;
2008 else if( cur_super < 0 ) cy -= size/3;
2014 else if( !wchrs.eof() ) {
2015 TitleGlyph *np = get_glyph(wchrs.wcur(), cur_font, cur_size, cur_style);
2016 dx = get_width(gp, np);
2019 chr = title_chars.add(CHAR_GLYPH, gp);
2022 cw = gp->right - gp->left;
2023 ch = gp->top - gp->bottom;
2026 if( !chr ) continue;
2028 chr->size = cur_size;
2029 chr->blink = cur_blink;
2030 chr->color = cur_color;
2031 chr->alpha = cur_alpha;
2033 if( cur_fixed ) chr->flags |= FLAG_FIXED;
2034 if( cur_super > 0 ) chr->flags |= FLAG_SUPER;
2035 if( cur_super < 0 ) chr->flags |= FLAG_SUBER;
2036 if( cur_under ) chr->flags |= FLAG_UNDER;
2037 if( cur_blink ) chr->flags |= FLAG_BLINK;
2038 chr->x = (cx += row_x);
2041 row->bound(cx,cy, cx+cw,cy-ch);
2042 chr->row = text_rows;
2046 if( !row_w || !row_h ) return 1;
2048 // rows boundary, note: row->xy is y up (FT), row_xy is y down (X)
2049 text_x1 = text_y1 = MAX_FLT;
2050 text_x2 = text_y2 = MIN_FLT;
2051 for( int i=0; i<text_rows; ++i ) {
2052 row = title_rows[i];
2053 switch( config.hjustification ) {
2054 case JUSTIFY_LEFT: row->x0 = 0; break;
2055 case JUSTIFY_CENTER: row->x0 = (row_w - (row->x2-row->x1)) / 2; break;
2056 case JUSTIFY_RIGHT: row->x0 = row_w - (row->x2-row->x1); break;
2059 if( text_x1 > (v=row->x0+row->x1) ) text_x1 = v;
2060 if( text_y1 > (v=row->y0-row->y1) ) text_y1 = v;
2061 if( text_x2 < (v=row->x0+row->x2) ) text_x2 = v;
2062 if( text_y2 < (v=row->y0-row->y2) ) text_y2 = v;
2064 if( text_x1 > text_x2 || text_y1 > text_y2 ) return 1;
2065 text_x1 += fuzz1; text_y1 += fuzz1;
2066 text_x2 += fuzz2; text_y2 += fuzz2;
2067 text_w = text_x2 - text_x1;
2068 text_h = text_y2 - text_y1;
2072 int TitleMain::get_visible_text()
2074 // Determine y of visible text
2075 switch( config.motion_strategy ) {
2077 case TOP_TO_BOTTOM: {
2078 float magnitude = config.pixels_per_second *
2079 (get_source_position() - config.prev_keyframe_position) /
2080 PluginVClient::project_frame_rate;
2082 int loop_size = text_h + title_h;
2083 magnitude -= (int)(magnitude / loop_size) * loop_size;
2085 text_y = config.motion_strategy == BOTTOM_TO_TOP ?
2086 title_h - magnitude :
2089 default: switch( config.vjustification ) {
2090 case JUSTIFY_TOP: text_y = 0; break;
2091 case JUSTIFY_MID: text_y = (title_h - text_h) / 2; break;
2092 case JUSTIFY_BOTTOM: text_y = title_h - text_h; break;
2096 // Determine x of visible text
2097 switch( config.motion_strategy ) {
2099 case LEFT_TO_RIGHT: {
2100 float magnitude = config.pixels_per_second *
2101 (get_source_position() - get_source_start()) /
2102 PluginVClient::project_frame_rate;
2104 int loop_size = text_w + title_w;
2105 magnitude -= (int)(magnitude / loop_size) * loop_size;
2107 text_x = config.motion_strategy == RIGHT_TO_LEFT ?
2108 title_w - magnitude :
2111 default: switch ( config.hjustification ) {
2112 case JUSTIFY_LEFT: text_x = 0; break;
2113 case JUSTIFY_CENTER: text_x = (title_w - text_w) / 2; break;
2114 case JUSTIFY_RIGHT: text_x = title_w - text_w; break;
2119 // until bottom of this row is visible
2121 int y0 = text_y - text_y1;
2122 while( row1 < text_rows ) {
2123 TitleRow *row = title_rows[row1];
2124 if( y0 + row->y0-row->y2 > 0 ) break;
2127 if( row1 >= text_rows ) return 0;
2129 // until top of next row is not visible
2132 while( row2 < text_rows ) {
2133 TitleRow *row = title_rows[row2];
2134 if( y0 + row->y0-row->y1 >= 0 ) break;
2137 if( row1 >= row2 ) return 0;
2139 //printf("get_visible_rows: visible_row1/2 = %d to %d\n",visible_row1,visible_row2);
2140 // Only draw visible chars
2141 double frame_rate = PluginVClient::get_project_framerate();
2142 int64_t units = get_source_position() - get_source_start();
2143 double position = units / frame_rate;
2145 int char1 = -1, char2 = -1, nchars = title_chars.count();
2146 for( int i=0; i<nchars; ++i ) {
2147 TitleChar *chr = title_chars[i];
2148 if( chr->row < row1 ) continue;
2149 if( chr->row >= row2 ) break;
2150 if( char1 < 0 ) char1 = i;
2152 if( (chr->flags & FLAG_BLINK) != 0 ) {
2154 double rate = 1 / fabs(chr->blink), rate2 = 2 * rate;
2155 double pos = position - ((int64_t)(position / rate2)) * rate2;
2156 chr->fade = chr->blink > 0 ?
2157 (pos > rate ? 0 : 1) : fabs(rate+pos) / rate;
2160 if( char1 < 0 ) char1 = 0;
2162 if( !blinking && visible_row1 == row1 && visible_row2 == row2 ) return 0;
2164 visible_row1 = row1; visible_row2 = row2;
2165 visible_char1 = char1; visible_char2 = char2;
2170 int TitleMain::draw_text(int need_redraw)
2172 // until top of next row is not visible
2173 mask_x1 = mask_y1 = INT_MAX;
2174 mask_x2 = mask_y2 = INT_MIN;
2175 for( int i=visible_row1; i<visible_row2; ++i ) {
2176 int v; TitleRow *row = title_rows[i];
2177 if( mask_x1 > (v=row->x0+row->x1) ) mask_x1 = v;
2178 if( mask_y1 > (v=row->y0-row->y1) ) mask_y1 = v;
2179 if( mask_x2 < (v=row->x0+row->x2) ) mask_x2 = v;
2180 if( mask_y2 < (v=row->y0-row->y2) ) mask_y2 = v;
2182 if( mask_x1 >= mask_x2 || mask_y1 >= mask_y2 ) return 1;
2184 mask_x1 += fuzz1; mask_y1 += fuzz1;
2185 mask_x2 += fuzz2; mask_y2 += fuzz2;
2186 mask_w = mask_x2 - mask_x1;
2187 mask_h = mask_y2 - mask_y1;
2189 //printf("TitleMain::draw_text %d-%d frame %dx%d\n",
2190 // visible_row1, visible_row2, mask_w,mask_h);
2191 if( text_mask && (text_mask->get_color_model() != text_model ||
2192 text_mask->get_w() != mask_w || text_mask->get_h() != mask_h) ) {
2193 delete text_mask; text_mask = 0;
2194 delete stroke_mask; stroke_mask = 0;
2198 // Always use 8 bit because the glyphs are 8 bit
2199 // Need to set YUV to get clear_frame to set the right chroma.
2200 mask_model = text_model;
2201 text_mask = new VFrame;
2202 text_mask->set_use_shm(0);
2203 text_mask->reallocate(0, -1, 0, 0, 0, mask_w, mask_h, mask_model, -1);
2204 int drop = abs(config.dropshadow);
2205 int drop_w = mask_w + drop;
2206 int drop_h = mask_h + drop;
2207 stroke_mask = new VFrame;
2208 stroke_mask->set_use_shm(0);
2209 stroke_mask->reallocate(0, -1, 0, 0, 0, drop_w, drop_h, mask_model, -1);
2213 // Draw on text mask if it has changed
2215 //printf("redraw %d to %d %d,%d %d,%d - %d,%d\n", visible_char1,visible_char2,
2216 // ext_x0, ext_y0, ext_x1,ext_y1, ext_x2,ext_y2);
2218 text_mask->clear_frame();
2219 stroke_mask->clear_frame();
2221 unsigned char *data = text_mask->get_data(); // draw bbox on text
2222 for( int x=0; x<mask_w; ++x ) data[4*x+3] = 0xff;
2223 for( int x=0; x<mask_w; ++x ) data[4*((mask_h-1)*mask_w+x)+3] = 0xff;
2224 for( int y=0; y<mask_h; ++y ) data[4*mask_w*y+3] = 0xff;
2225 for( int y=0; y<mask_h; ++y ) data[4*(mask_w*y + mask_w-1)+3] = 0xff;
2228 title_engine = new TitleEngine(this, cpus);
2230 // Draw dropshadow first
2231 if( config.dropshadow ) {
2232 title_engine->do_dropshadow = 1;
2233 title_engine->set_package_count(visible_char2 - visible_char1);
2234 title_engine->process_packages();
2237 // Then draw foreground
2238 title_engine->do_dropshadow = 0;
2239 title_engine->set_package_count(visible_char2 - visible_char1);
2240 title_engine->process_packages();
2242 draw_underline(text_mask, config.alpha);
2244 // Convert to text outlines
2245 if( config.outline_size > 0 ) {
2247 (text_mask->get_w() != outline_mask->get_w() ||
2248 text_mask->get_h() != outline_mask->get_h()) ) {
2249 delete outline_mask; outline_mask = 0;
2252 if( !outline_mask ) {
2253 outline_mask = new VFrame;
2254 outline_mask->set_use_shm(0);
2255 outline_mask->reallocate(0, -1, 0, 0, 0,
2256 text_mask->get_w(), text_mask->get_h(),
2257 text_mask->get_color_model(), -1);
2259 if( !outline_engine ) outline_engine =
2260 new TitleOutlineEngine(this, cpus);
2261 outline_engine->do_outline();
2269 int TitleMain::draw_underline(VFrame *mask, int alpha)
2271 int row = -1, sz = -1, color = -1, rgb = -1;
2272 int bpp = mask->get_bytes_per_pixel(), bpp1 = bpp-1;
2273 int x1 = 0, x2 = 0, y0 = 0;
2274 for( int i=visible_char1; i<visible_char2; ) {
2275 TitleChar *chr = title_chars[i];
2276 if( (chr->flags & FLAG_UNDER) && row < 0 ) {
2278 rgb = chr->color; int rr, gg, bb;
2279 get_mask_colors(rgb, mask_model, rr, gg, bb);
2280 color = (rr<<16) | (gg<<8) | (bb<<0);
2282 TitleRow *rp = title_rows[row];
2283 x1 = rp->x0 + chr->x;
2286 if( (chr->flags & FLAG_UNDER) && row == chr->row && chr->color == rgb ) {
2287 TitleRow *rp = title_rows[row];
2288 x2 = rp->x0 + chr->x + chr->dx;
2289 if( sz < chr->size ) sz = chr->size;
2290 if( ++i < visible_char2 ) continue;
2292 if( row < 0 ) { ++i; continue; }
2293 x1 -= mask_x1; x2 -= mask_x1; y0 -= mask_y1;
2294 if( x1 < 0 ) x1 = 0;
2295 if( x2 > mask_w ) x2 = mask_w;
2296 int sz1 = sz / 32 + 1, sz2 = sz1/2;
2297 int y1 = y0 - sz2, y2 = y1 + sz1;
2298 if( y1 < 0 ) y1 = 0;
2299 if( y2 > mask_h ) y2 = mask_h;
2300 unsigned char **rows = mask->get_rows();
2301 for( int y=y1; y<y2; ++y ) {
2302 unsigned char *rp = rows[y];
2303 for( int x=x1; x<x2; ++x ) {
2304 unsigned char *bp = rp + bpp * x;
2305 for( int i=bpp1; --i>=0; ) *bp++ = color>>(8*i);
2314 void TitleMain::draw_overlay()
2316 //printf("TitleMain::draw_overlay 1\n");
2318 if( !EQUIV(config.fade_in, 0) ) {
2319 int64_t plugin_start = server->plugin->startproject;
2320 int64_t fade_len = lroundf(config.fade_in * PluginVClient::project_frame_rate);
2321 int64_t fade_position = get_source_position() - plugin_start;
2323 if( fade_position >= 0 && fade_position < fade_len ) {
2324 fade = (float)fade_position / fade_len;
2327 if( !EQUIV(config.fade_out, 0) ) {
2328 int64_t plugin_end = server->plugin->startproject + server->plugin->length;
2329 int64_t fade_len = lroundf(config.fade_out * PluginVClient::project_frame_rate);
2330 int64_t fade_position = plugin_end - get_source_position();
2332 if( fade_position >= 0 && fade_position < fade_len ) {
2333 fade = (float)fade_position / fade_len;
2338 translate = new TitleTranslate(this, cpus);
2339 int tx = text_x - text_x1 + mask_x1;
2340 if( tx < title_w && tx+mask_w > 0 ) {
2341 translate->xlat_mask = text_mask;
2342 translate->run_packages();
2343 if( config.stroke_width >= SMALL && (config.style & BC_FONT_OUTLINE) ) {
2344 translate->xlat_mask = stroke_mask;
2345 translate->run_packages();
2350 const char* TitleMain::motion_to_text(int motion)
2353 case NO_MOTION: return _("No motion");
2354 case BOTTOM_TO_TOP: return _("Bottom to top");
2355 case TOP_TO_BOTTOM: return _("Top to bottom");
2356 case RIGHT_TO_LEFT: return _("Right to left");
2357 case LEFT_TO_RIGHT: return _("Left to right");
2359 return _("Unknown");
2362 int TitleMain::text_to_motion(const char *text)
2364 for( int i=0; i<TOTAL_PATHS; ++i ) {
2365 if( !strcasecmp(motion_to_text(i), text) ) return i;
2370 void TitleMain::reset_render()
2372 delete text_mask; text_mask = 0;
2373 delete stroke_mask; stroke_mask = 0;
2374 delete glyph_engine; glyph_engine = 0;
2375 visible_row1 = 0; visible_row2 = 0;
2376 visible_char1 = 0; visible_char2 = 0;
2378 title_glyphs.clear();
2379 title_images.clear();
2380 if( freetype_face ) {
2381 FT_Done_Face(freetype_face);
2386 int TitleMain::init_freetype()
2388 if( !freetype_library )
2389 FT_Init_FreeType(&freetype_library);
2393 void TitleMain::draw_boundry()
2395 VFrame &out = *output;
2396 int iw = output->get_w(), ih = output->get_h();
2397 int mr = MIN(iw, ih)/200 + 2, rr = 2*mr;
2398 int x = title_x, y = title_y, w = title_w, h = title_h;
2400 int x0 = x-r2, x1 = x+(w+1)/2, x2 = x+w+r2;
2401 int y0 = y-r2, y1 = y+(h+1)/2, y2 = y+h+r2;
2403 for( int r=2; r<mr; r<<=1 ) st = r;
2406 for( int r=mr/2; --r>=0; ) { // bbox
2407 int lft = x+r, rgt = x+w-1-r;
2408 int top = y+r, bot = y+h-1-r;
2409 out.draw_line(lft,top, rgt,top);
2410 out.draw_line(rgt,top, rgt,bot);
2411 out.draw_line(rgt,bot, lft,bot);
2412 out.draw_line(lft,bot, lft,top);
2415 for( int r=mr; r<rr; ++r ) { // center
2416 out.draw_smooth(x1-r,y1, x1-r,y1+r, x1,y1+r);
2417 out.draw_smooth(x1,y1+r, x1+r,y1+r, x1+r,y1);
2418 out.draw_smooth(x1+r,y1, x1+r,y1-r, x1,y1-r);
2419 out.draw_smooth(x1,y1-r, x1-r,y1-r, x1-r,y1);
2422 for( int r=rr; --r>=0; ) { // edge arrows
2423 out.draw_line(x1-r,y0+r, x1+r,y0+r);
2424 out.draw_line(x2-r,y1-r, x2-r,y1+r);
2425 out.draw_line(x1-r,y2-r, x1+r,y2-r);
2426 out.draw_line(x0+r,y1+r, x0+r,y1-r);
2428 x0 += r2; y0 += r2; x2 -= r2; y2 -= r2;
2429 for( int r=2*mr; --r>=0; ) { // corner arrows
2430 out.draw_line(x0,y0+r, x0+r,y0);
2431 out.draw_line(x2,y0+r, x2-r,y0);
2432 out.draw_line(x2,y2-r, x2-r,y2);
2433 out.draw_line(x0,y2-r, x0+r,y2);
2438 int TitleMain::process_realtime(VFrame *input_ptr, VFrame *output_ptr)
2442 output = output_ptr;
2443 output_model = output->get_color_model();
2444 text_model = BC_CModels::is_yuv(output_model) ? BC_YUVA8888 : BC_RGBA8888;
2446 if( text_model != mask_model ) need_reconfigure = 1;
2447 need_reconfigure |= load_configuration();
2448 int64_t cur_position = get_source_position();
2449 if( last_position < 0 || last_position+1 != cur_position )
2450 need_reconfigure = 1;
2451 last_position = cur_position;
2453 title_x = config.title_x; title_y = config.title_y;
2454 title_w = config.title_w ? config.title_w : input->get_w();
2455 title_h = config.title_h ? config.title_h : input->get_h();
2457 fuzz1 = -config.outline_size;
2458 fuzz2 = config.outline_size;
2459 if( config.dropshadow < 0 )
2460 fuzz1 += config.dropshadow;
2462 fuzz2 += config.dropshadow;
2463 fuzz = fuzz2 - fuzz1;
2466 if( config.size <= 0 || config.size >= 2048 )
2468 if( config.stroke_width < 0 || config.stroke_width >= 512 )
2469 config.stroke_width = 0.0;
2470 if( !config.wlen && !config.timecode )
2472 if( !strlen(config.encoding) )
2473 strcpy(config.encoding, DEFAULT_ENCODING);
2475 // Always synthesize text and redraw it for timecode
2476 if( config.timecode ) {
2477 int64_t rendered_frame = get_source_position();
2478 if( get_direction() == PLAY_REVERSE )
2479 rendered_frame -= 1;
2481 char text[BCTEXTLEN];
2483 (double)rendered_frame / PluginVClient::project_frame_rate,
2484 config.timecode_format,
2485 PluginVClient::get_project_samplerate(),
2486 PluginVClient::get_project_framerate(),
2488 config.to_wtext(config.encoding, text, strlen(text)+1);
2489 need_reconfigure = 1;
2492 if( config.background )
2495 // Handle reconfiguration
2496 if( need_reconfigure ) {
2497 need_reconfigure = 0;
2499 result = init_freetype();
2502 result = get_text();
2507 result = draw_text(get_visible_text());
2510 // Overlay mask on output
2520 void TitleMain::update_gui()
2523 int reconfigure = load_configuration();
2525 TitleWindow *window = (TitleWindow*)thread->window;
2526 window->lock_window("TitleMain::update_gui");
2528 window->unlock_window();
2529 window->color_thread->update_gui(config.color, 0);
2534 int TitleMain::load_configuration()
2536 KeyFrame *prev_keyframe, *next_keyframe;
2537 prev_keyframe = get_prev_keyframe(get_source_position());
2538 next_keyframe = get_next_keyframe(get_source_position());
2540 TitleConfig old_config, prev_config, next_config;
2541 old_config.copy_from(config);
2542 read_data(prev_keyframe);
2543 prev_config.copy_from(config);
2544 read_data(next_keyframe);
2545 next_config.copy_from(config);
2547 config.prev_keyframe_position = prev_keyframe->position;
2548 config.next_keyframe_position = next_keyframe->position;
2550 // if no previous keyframe exists, it should be start of the plugin, not start of the track
2551 if( config.next_keyframe_position == config.prev_keyframe_position )
2552 config.next_keyframe_position = get_source_start() + get_total_len();
2553 if( config.prev_keyframe_position == 0 )
2554 config.prev_keyframe_position = get_source_start();
2555 // printf("TitleMain::load_configuration 10 %d %d\n",
2556 // config.prev_keyframe_position,
2557 // config.next_keyframe_position);
2559 config.interpolate(prev_config,
2561 (next_keyframe->position == prev_keyframe->position) ?
2562 get_source_position() :
2563 prev_keyframe->position,
2564 (next_keyframe->position == prev_keyframe->position) ?
2565 get_source_position() + 1 :
2566 next_keyframe->position,
2567 get_source_position());
2569 if( !config.equivalent(old_config) )
2575 void TitleMain::save_data(KeyFrame *keyframe)
2579 output.set_shared_output(keyframe->get_data(), MESSAGESIZE);
2580 output.tag.set_title("TITLE");
2581 output.tag.set_property("FONT", config.font);
2582 output.tag.set_property("ENCODING", config.encoding);
2583 output.tag.set_property("STYLE", (int64_t)config.style);
2584 output.tag.set_property("SIZE", config.size);
2585 output.tag.set_property("COLOR", config.color);
2586 output.tag.set_property("ALPHA", config.alpha);
2587 output.tag.set_property("OUTLINE_SIZE", config.outline_size);
2588 output.tag.set_property("OUTLINE_COLOR", config.outline_color);
2589 output.tag.set_property("OUTLINE_ALPHA", config.outline_alpha);
2590 output.tag.set_property("COLOR_STROKE", config.color_stroke);
2591 output.tag.set_property("STROKE_WIDTH", config.stroke_width);
2592 output.tag.set_property("MOTION_STRATEGY", config.motion_strategy);
2593 output.tag.set_property("LOOP", config.loop);
2594 output.tag.set_property("LINE_PITCH", config.line_pitch);
2595 output.tag.set_property("PIXELS_PER_SECOND", config.pixels_per_second);
2596 output.tag.set_property("HJUSTIFICATION", config.hjustification);
2597 output.tag.set_property("VJUSTIFICATION", config.vjustification);
2598 output.tag.set_property("FADE_IN", config.fade_in);
2599 output.tag.set_property("FADE_OUT", config.fade_out);
2600 output.tag.set_property("TITLE_X", config.title_x);
2601 output.tag.set_property("TITLE_Y", config.title_y);
2602 output.tag.set_property("TITLE_W", config.title_w);
2603 output.tag.set_property("TITLE_H", config.title_h);
2604 output.tag.set_property("DROPSHADOW", config.dropshadow);
2605 output.tag.set_property("TIMECODE", config.timecode);
2606 output.tag.set_property("TIMECODEFORMAT", config.timecode_format);
2607 output.tag.set_property("WINDOW_W", config.window_w);
2608 output.tag.set_property("WINDOW_H", config.window_h);
2609 output.tag.set_property("DRAG", config.drag);
2610 output.tag.set_property("BACKGROUND", config.background);
2611 output.tag.set_property("BACKGROUND_PATH", config.background_path);
2612 output.tag.set_property("LOOP_PLAYBACK", config.loop_playback);
2613 output.append_tag();
2614 output.append_newline();
2615 char text[2*sizeof(config.wtext)];
2616 int text_len = BC_Resources::encode(
2617 BC_Resources::wide_encoding, DEFAULT_ENCODING,
2618 (char*)config.wtext, config.wlen*sizeof(wchar_t),
2619 text, sizeof(text));
2620 int len = output.length(), avail = MESSAGESIZE-16 - len;
2621 if( text_len >= avail ) { // back off last utf8 char
2623 while( text_len > 0 && (text[text_len-1] & 0xc0) == 0x80 )
2624 text[--text_len] = 0;
2626 text[--text_len] = 0;
2628 output.append_text(text, text_len);
2629 output.tag.set_title("/TITLE");
2630 output.append_tag();
2631 output.append_newline();
2632 output.terminate_string();
2633 //printf("TitleMain::save_data 1\n%s\n", output.string);
2634 //printf("TitleMain::save_data 2\n%s\n", config.text);
2637 void TitleMain::read_data(KeyFrame *keyframe)
2641 input.set_shared_input(keyframe->get_data(), strlen(keyframe->get_data()));
2645 config.prev_keyframe_position = keyframe->position;
2648 result = input.read_tag();
2651 if( input.tag.title_is("TITLE") ) {
2652 input.tag.get_property("FONT", config.font);
2653 input.tag.get_property("ENCODING", config.encoding);
2654 config.style = input.tag.get_property("STYLE", (int64_t)config.style);
2655 config.size = input.tag.get_property("SIZE", config.size);
2656 config.color = input.tag.get_property("COLOR", config.color);
2657 config.alpha = input.tag.get_property("ALPHA", config.alpha);
2658 config.outline_size = input.tag.get_property("OUTLINE_SIZE", config.outline_size);
2659 config.outline_color = input.tag.get_property("OUTLINE_COLOR", config.outline_color);
2660 config.outline_alpha = input.tag.get_property("OUTLINE_ALPHA", config.outline_alpha);
2661 config.color_stroke = input.tag.get_property("COLOR_STROKE", config.color_stroke);
2662 config.stroke_width = input.tag.get_property("STROKE_WIDTH", config.stroke_width);
2663 config.motion_strategy = input.tag.get_property("MOTION_STRATEGY", config.motion_strategy);
2664 config.loop = input.tag.get_property("LOOP", config.loop);
2665 config.line_pitch = input.tag.get_property("LINE_PITCH", config.line_pitch);
2666 config.pixels_per_second = input.tag.get_property("PIXELS_PER_SECOND", config.pixels_per_second);
2667 config.hjustification = input.tag.get_property("HJUSTIFICATION", config.hjustification);
2668 config.vjustification = input.tag.get_property("VJUSTIFICATION", config.vjustification);
2669 config.fade_in = input.tag.get_property("FADE_IN", config.fade_in);
2670 config.fade_out = input.tag.get_property("FADE_OUT", config.fade_out);
2671 config.title_x = input.tag.get_property("TITLE_X", config.title_x);
2672 config.title_y = input.tag.get_property("TITLE_Y", config.title_y);
2673 config.title_w = input.tag.get_property("TITLE_W", config.title_w);
2674 config.title_h = input.tag.get_property("TITLE_H", config.title_h);
2675 config.dropshadow = input.tag.get_property("DROPSHADOW", config.dropshadow);
2676 config.timecode = input.tag.get_property("TIMECODE", config.timecode);
2677 config.timecode_format = input.tag.get_property("TIMECODEFORMAT", config.timecode_format);
2678 config.window_w = input.tag.get_property("WINDOW_W", config.window_w);
2679 config.window_h = input.tag.get_property("WINDOW_H", config.window_h);
2680 config.drag = input.tag.get_property("DRAG", config.drag);
2681 config.background = input.tag.get_property("BACKGROUND", config.background);
2682 input.tag.get_property("BACKGROUND_PATH", config.background_path);
2683 config.loop_playback = input.tag.get_property("LOOP_PLAYBACK", config.loop_playback);
2684 const char *text = input.read_text();
2685 config.to_wtext(config.encoding, text, strlen(text)+1);
2687 else if( input.tag.title_is("/TITLE") ) {
2693 void TitleMain::insert_text(const wchar_t *wtxt, int pos)
2695 int len = wcslen(wtxt);
2696 wchar_t *wtext = config.wtext;
2697 int wsize = sizeof(config.wtext)-1;
2698 int wlen = config.wlen;
2699 if( pos < 0 ) pos = 0;
2700 if( pos > wlen ) pos = wlen;
2702 for( int i=wlen-1, j=wlen+len-1; i>=pos; --i,--j ) {
2703 if( j >= wsize ) continue;
2704 wtext[j] = wtext[i];
2706 for( int i=pos, j=0; j<len; ++i,++j ) {
2707 if( i >= wsize ) break;
2711 if( (wlen+=len) > wsize ) wlen = wsize;