1 // Originally developed by Heroine Virtual Ltd.
2 // Support for multiple encodings, outline (stroke) by
3 // Andraz Tori <Andraz.tori1@guest.arnes.si>
10 #include "filesystem.h"
11 #include "freetype/ftbbox.h"
12 #include "freetype/ftglyph.h"
13 #include "freetype/ftoutln.h"
14 #include "freetype/ftstroker.h"
16 #include "plugincolors.h"
18 #include "titlewindow.h"
31 #define ZERO (1.0 / 64.0)
33 #define FONT_SEARCHPATH "fonts"
34 //#define FONT_SEARCHPATH "/usr/X11R6/lib/X11/fonts"
37 REGISTER_PLUGIN(TitleMain)
40 TitleConfig::TitleConfig()
44 color_stroke = 0xff0000;
46 motion_strategy = NO_MOTION;
48 hjustification = JUSTIFY_CENTER;
49 vjustification = JUSTIFY_MID;
55 sprintf(font, "fixed");
56 sprintf(text, _("hello world"));
57 #define DEFAULT_ENCODING "ISO8859-1"
58 sprintf(encoding, DEFAULT_ENCODING);
59 pixels_per_second = 1.0;
64 // Does not test equivalency but determines if redrawing text is necessary.
65 int TitleConfig::equivalent(TitleConfig &that)
67 return dropshadow == that.dropshadow &&
68 style == that.style &&
70 color == that.color &&
71 color_stroke == that.color_stroke &&
72 stroke_width == that.stroke_width &&
73 timecode == that.timecode &&
74 hjustification == that.hjustification &&
75 vjustification == that.vjustification &&
76 EQUIV(pixels_per_second, that.pixels_per_second) &&
77 !strcasecmp(font, that.font) &&
78 !strcasecmp(encoding, that.encoding) &&
79 !strcmp(text, that.text);
82 void TitleConfig::copy_from(TitleConfig &that)
84 strcpy(font, that.font);
88 color_stroke = that.color_stroke;
89 stroke_width = that.stroke_width;
90 pixels_per_second = that.pixels_per_second;
91 motion_strategy = that.motion_strategy;
93 hjustification = that.hjustification;
94 vjustification = that.vjustification;
95 fade_in = that.fade_in;
96 fade_out = that.fade_out;
99 dropshadow = that.dropshadow;
100 timecode = that.timecode;
101 strcpy(text, that.text);
102 strcpy(encoding, that.encoding);
105 void TitleConfig::interpolate(TitleConfig &prev,
109 int64_t current_frame)
111 strcpy(font, prev.font);
112 strcpy(encoding, prev.encoding);
116 color_stroke = prev.color_stroke;
117 stroke_width = prev.stroke_width;
118 motion_strategy = prev.motion_strategy;
120 hjustification = prev.hjustification;
121 vjustification = prev.vjustification;
122 fade_in = prev.fade_in;
123 fade_out = prev.fade_out;
124 pixels_per_second = prev.pixels_per_second;
125 strcpy(text, prev.text);
127 double next_scale = (double)(current_frame - prev_frame) / (next_frame - prev_frame);
128 double prev_scale = (double)(next_frame - current_frame) / (next_frame - prev_frame);
131 // this->x = prev.x * prev_scale + next.x * next_scale;
132 // this->y = prev.y * prev_scale + next.y * next_scale;
135 timecode = prev.timecode;
136 // this->dropshadow = (int)(prev.dropshadow * prev_scale + next.dropshadow * next_scale);
137 this->dropshadow = prev.dropshadow;
156 FontEntry::FontEntry()
172 FontEntry::~FontEntry()
174 if(path) delete [] path;
175 if(foundary) delete [] foundary;
176 if(family) delete [] family;
177 if(weight) delete [] weight;
178 if(slant) delete [] slant;
179 if(swidth) delete [] swidth;
180 if(adstyle) delete [] adstyle;
181 if(spacing) delete [] spacing;
182 if(registry) delete [] registry;
183 if(encoding) delete [] encoding;
184 if(fixed_title) delete [] fixed_title;
187 void FontEntry::dump()
189 printf("%s: %s %s %s %s %s %s %d %d %d %d %s %d %s %s\n",
207 TitleGlyph::TitleGlyph()
216 TitleGlyph::~TitleGlyph()
218 //printf("TitleGlyph::~TitleGlyph 1\n");
219 if(data) delete data;
220 if(data_stroke) delete data_stroke;
233 GlyphPackage::GlyphPackage() : LoadPackage()
237 GlyphUnit::GlyphUnit(TitleMain *plugin, GlyphEngine *server)
240 this->plugin = plugin;
242 freetype_library = 0;
246 GlyphUnit::~GlyphUnit()
248 if(freetype_library) FT_Done_FreeType(freetype_library);
251 void GlyphUnit::process_package(LoadPackage *package)
253 GlyphPackage *pkg = (GlyphPackage*)package;
254 TitleGlyph *glyph = pkg->glyph;
257 if(!freetype_library)
259 current_font = plugin->get_font();
261 if(plugin->load_freetype_face(freetype_library,
265 printf(_("GlyphUnit::process_package FT_New_Face failed.\n"));
270 FT_Set_Pixel_Sizes(freetype_face, plugin->config.size, 0);
276 int gindex = FT_Get_Char_Index(freetype_face, glyph->char_code);
278 //printf("GlyphUnit::process_package 1 %c\n", glyph->char_code);
283 if (glyph->char_code != 10)
284 printf(_("GlyphUnit::process_package FT_Load_Char failed - char: %i.\n"),
286 // Prevent a crash here
292 glyph->freetype_index = 0;
293 glyph->advance_w = 8;
294 glyph->data = new VFrame(0,
299 glyph->data->clear_frame();
300 glyph->data_stroke = 0;
304 // create outline glyph
305 if (plugin->config.stroke_width >= ZERO &&
306 (plugin->config.style & FONT_OUTLINE))
308 glyph->data_stroke = new VFrame(0,
313 glyph->data_stroke->clear_frame();
320 // char found and no outline desired
321 if (plugin->config.stroke_width < ZERO ||
322 !(plugin->config.style & FONT_OUTLINE))
324 FT_Glyph glyph_image;
327 FT_Load_Glyph(freetype_face, gindex, FT_LOAD_DEFAULT);
328 FT_Get_Glyph(freetype_face->glyph, &glyph_image);
329 FT_Outline_Get_BBox(&((FT_OutlineGlyph) glyph_image)->outline, &bbox);
330 // printf("Stroke: Xmin: %ld, Xmax: %ld, Ymin: %ld, yMax: %ld\n",
331 // bbox.xMin,bbox.xMax, bbox.yMin, bbox.yMax);
333 FT_Outline_Translate(&((FT_OutlineGlyph) glyph_image)->outline,
336 glyph->width = bm.width = ((bbox.xMax - bbox.xMin + 63) >> 6);
337 glyph->height = bm.rows = ((bbox.yMax - bbox.yMin + 63) >> 6);
338 glyph->pitch = bm.pitch = bm.width;
339 bm.pixel_mode = FT_PIXEL_MODE_GRAY;
341 glyph->left = (bbox.xMin + 31) >> 6;
342 if (glyph->left < 0) glyph->left = 0;
343 glyph->top = (bbox.yMax + 31) >> 6;
344 glyph->freetype_index = gindex;
345 glyph->advance_w = ((freetype_face->glyph->advance.x + 31) >> 6);
346 //printf("GlyphUnit::process_package 1 width=%d height=%d pitch=%d left=%d top=%d advance_w=%d freetype_index=%d\n",
347 //glyph->width, glyph->height, glyph->pitch, glyph->left, glyph->top, glyph->advance_w, glyph->freetype_index);
349 glyph->data = new VFrame(0,
354 glyph->data->clear_frame();
355 bm.buffer = glyph->data->get_data();
356 FT_Outline_Get_Bitmap( freetype_library,
357 &((FT_OutlineGlyph) glyph_image)->outline,
359 FT_Done_Glyph(glyph_image);
362 // Outline desired and glyph found
364 FT_Glyph glyph_image;
370 FT_UInt npoints, ncontours;
372 typedef struct FT_LibraryRec_
377 FT_Load_Glyph(freetype_face, gindex, FT_LOAD_DEFAULT);
378 FT_Get_Glyph(freetype_face->glyph, &glyph_image);
380 // check if the outline is ok (non-empty);
381 FT_Outline_Get_BBox(&((FT_OutlineGlyph) glyph_image)->outline, &bbox);
382 if (bbox.xMin == 0 && bbox.xMax == 0 && bbox.yMin ==0 && bbox.yMax == 0)
384 FT_Done_Glyph(glyph_image);
385 glyph->data = new VFrame(0, 0, BC_A8,0);
386 glyph->data_stroke = new VFrame(0, 0, BC_A8,0);;
391 glyph->advance_w =((int)(freetype_face->glyph->advance.x +
392 plugin->config.stroke_width * 64)) >> 6;
395 FT_Stroker_New(((FT_LibraryRec *)freetype_library)->memory, &stroker);
396 FT_Stroker_Set(stroker, (int)(plugin->config.stroke_width * 64), FT_STROKER_LINECAP_ROUND, FT_STROKER_LINEJOIN_ROUND, 0);
397 FT_Stroker_ParseOutline(stroker, &((FT_OutlineGlyph) glyph_image)->outline,1);
398 FT_Stroker_GetCounts(stroker,&npoints, &ncontours);
399 if (npoints ==0 && ncontours == 0)
401 // this never happens, but FreeType has a bug regarding Linotype's Palatino font
402 FT_Stroker_Done(stroker);
403 FT_Done_Glyph(glyph_image);
404 glyph->data = new VFrame(0, 0, BC_A8,0);
405 glyph->data_stroke = new VFrame(0, 0, BC_A8,0);;
410 glyph->advance_w =((int)(freetype_face->glyph->advance.x +
411 plugin->config.stroke_width * 64)) >> 6;
415 FT_Outline_New(freetype_library, npoints, ncontours, &outline);
417 outline.n_contours=0;
418 FT_Stroker_Export (stroker, &outline);
419 FT_Outline_Get_BBox(&outline, &bbox);
421 FT_Outline_Translate(&outline,
425 FT_Outline_Translate(&((FT_OutlineGlyph) glyph_image)->outline,
427 - bbox.yMin + (int)(plugin->config.stroke_width*32));
428 // printf("Stroke: Xmin: %ld, Xmax: %ld, Ymin: %ld, yMax: %ld\nFill Xmin: %ld, Xmax: %ld, Ymin: %ld, yMax: %ld\n",
429 // bbox.xMin,bbox.xMax, bbox.yMin, bbox.yMax,
430 // bbox_fill.xMin,bbox_fill.xMax, bbox_fill.yMin, bbox_fill.yMax);
432 glyph->width = bm.width = ((bbox.xMax - bbox.xMin) >> 6)+1;
433 glyph->height = bm.rows = ((bbox.yMax - bbox.yMin) >> 6) +1;
434 glyph->pitch = bm.pitch = bm.width;
435 bm.pixel_mode = FT_PIXEL_MODE_GRAY;
437 glyph->left = (bbox.xMin + 31) >> 6;
438 if (glyph->left < 0) glyph->left = 0;
439 glyph->top = (bbox.yMax + 31) >> 6;
440 glyph->freetype_index = gindex;
441 int real_advance = ((int)ceil((float)freetype_face->glyph->advance.x +
442 plugin->config.stroke_width * 64) >> 6);
443 glyph->advance_w = glyph->width + glyph->left;
444 if (real_advance > glyph->advance_w)
445 glyph->advance_w = real_advance;
446 //printf("GlyphUnit::process_package 1 width=%d height=%d pitch=%d left=%d top=%d advance_w=%d freetype_index=%d\n",
447 //glyph->width, glyph->height, glyph->pitch, glyph->left, glyph->top, glyph->advance_w, glyph->freetype_index);
450 //printf("GlyphUnit::process_package 1\n");
451 glyph->data = new VFrame(0,
456 glyph->data_stroke = new VFrame(0,
461 glyph->data->clear_frame();
462 glyph->data_stroke->clear_frame();
463 // for debugging memset( glyph->data_stroke->get_data(), 60, glyph->pitch * glyph->height);
464 bm.buffer=glyph->data->get_data();
465 FT_Outline_Get_Bitmap( freetype_library,
466 &((FT_OutlineGlyph) glyph_image)->outline,
468 bm.buffer=glyph->data_stroke->get_data();
469 FT_Outline_Get_Bitmap( freetype_library,
472 FT_Outline_Done(freetype_library,&outline);
473 FT_Stroker_Done(stroker);
474 FT_Done_Glyph(glyph_image);
476 //printf("GlyphUnit::process_package 2\n");
481 GlyphEngine::GlyphEngine(TitleMain *plugin, int cpus)
482 : LoadServer(cpus, cpus)
484 this->plugin = plugin;
486 void GlyphEngine::init_packages()
488 int current_package = 0;
489 for(int i = 0; i < plugin->glyphs.total; i++)
491 if(!plugin->glyphs.values[i]->data)
493 GlyphPackage *pkg = (GlyphPackage*)packages[current_package++];
494 pkg->glyph = plugin->glyphs.values[i];
498 LoadClient* GlyphEngine::new_client()
500 return new GlyphUnit(plugin, this);
502 LoadPackage* GlyphEngine::new_package()
504 return new GlyphPackage;
519 // Copy a single character to the text mask
520 TitlePackage::TitlePackage()
526 TitleUnit::TitleUnit(TitleMain *plugin, TitleEngine *server)
529 this->plugin = plugin;
532 void TitleUnit::draw_glyph(VFrame *output, TitleGlyph *glyph, int x, int y)
534 int glyph_w = glyph->data->get_w();
535 int glyph_h = glyph->data->get_h();
536 int output_w = output->get_w();
537 int output_h = output->get_h();
538 unsigned char **in_rows = glyph->data->get_rows();
539 unsigned char **out_rows = output->get_rows();
541 //printf("TitleUnit::draw_glyph 1 %c %d %d\n", glyph->c, x, y);
542 for(int in_y = 0; in_y < glyph_h; in_y++)
544 // int y_out = y + plugin->ascent + in_y - glyph->top;
545 int y_out = y + plugin->get_char_height() + in_y - glyph->top;
547 //printf("TitleUnit::draw_glyph 1 %d\n", y_out);
548 if(y_out >= 0 && y_out < output_h)
550 unsigned char *out_row = out_rows[y_out];
551 unsigned char *in_row = in_rows[in_y];
552 for(int in_x = 0; in_x < glyph_w; in_x++)
554 int x_out = x + glyph->left + in_x;
555 if(x_out >= 0 && x_out < output_w)
558 out_row[x_out] = in_row[in_x];
559 //out_row[x_out] = 0xff;
567 void TitleUnit::process_package(LoadPackage *package)
569 TitlePackage *pkg = (TitlePackage*)package;
573 for(int i = 0; i < plugin->glyphs.total; i++)
575 TitleGlyph *glyph = plugin->glyphs.values[i];
576 if(glyph->c == pkg->c)
578 draw_glyph(plugin->text_mask, glyph, pkg->x, pkg->y);
579 if(plugin->config.stroke_width >= ZERO &&
580 (plugin->config.style & FONT_OUTLINE))
582 VFrame *tmp = glyph->data;
583 glyph->data = glyph->data_stroke;
584 draw_glyph(plugin->text_mask_stroke, glyph, pkg->x, pkg->y);
593 TitleEngine::TitleEngine(TitleMain *plugin, int cpus)
594 : LoadServer(cpus, cpus)
596 this->plugin = plugin;
599 void TitleEngine::init_packages()
601 int visible_y1 = plugin->visible_row1 * plugin->get_char_height();
602 int current_package = 0;
603 for(int i = plugin->visible_char1; i < plugin->visible_char2; i++)
605 title_char_position_t *char_position = plugin->char_positions + i;
606 TitlePackage *pkg = (TitlePackage*)get_package(current_package);
607 pkg->x = char_position->x;
608 pkg->y = char_position->y - visible_y1;
609 pkg->c = plugin->config.text[i];
614 LoadClient* TitleEngine::new_client()
616 return new TitleUnit(plugin, this);
619 LoadPackage* TitleEngine::new_package()
621 return new TitlePackage;
634 TitleTranslatePackage::TitleTranslatePackage()
640 TitleTranslateUnit::TitleTranslateUnit(TitleMain *plugin, TitleTranslate *server)
643 this->plugin = plugin;
648 #define TRANSLATE(type, max, components, r, g, b) \
650 unsigned char **in_rows = plugin->text_mask->get_rows(); \
651 type **out_rows = (type**)plugin->output->get_rows(); \
653 for(int i = pkg->y1; i < pkg->y2; i++) \
655 if(i + server->out_y1_int >= 0 && \
656 i + server->out_y1_int < server->output_h) \
659 float y_fraction1, y_fraction2; \
660 float y_output_fraction; \
661 in_y1 = server->y_table[i].in_x1; \
662 in_y2 = server->y_table[i].in_x2; \
663 y_fraction1 = server->y_table[i].in_fraction1; \
664 y_fraction2 = server->y_table[i].in_fraction2; \
665 y_output_fraction = server->y_table[i].output_fraction; \
666 unsigned char *in_row1 = in_rows[in_y1]; \
667 unsigned char *in_row2 = in_rows[in_y2]; \
668 type *out_row = out_rows[i + server->out_y1_int]; \
670 for(int j = server->out_x1_int; j < server->out_x2_int; j++) \
672 if(j >= 0 && j < server->output_w) \
678 float x_output_fraction; \
680 server->x_table[j - server->out_x1_int].in_x1; \
682 server->x_table[j - server->out_x1_int].in_x2; \
684 server->x_table[j - server->out_x1_int].in_fraction1; \
686 server->x_table[j - server->out_x1_int].in_fraction2; \
687 x_output_fraction = \
688 server->x_table[j - server->out_x1_int].output_fraction; \
690 float fraction1 = x_fraction1 * y_fraction1; \
691 float fraction2 = x_fraction2 * y_fraction1; \
692 float fraction3 = x_fraction1 * y_fraction2; \
693 float fraction4 = x_fraction2 * y_fraction2; \
694 int input = (int)(in_row1[in_x1] * fraction1 + \
695 in_row1[in_x2] * fraction2 + \
696 in_row2[in_x1] * fraction3 + \
697 in_row2[in_x2] * fraction4 + 0.5); \
698 input *= plugin->alpha; \
699 /* Alpha is 0 - 256 */ \
702 int anti_input = 0xff - input; \
703 if(components == 4) \
705 out_row[j * components + 0] = \
706 (r * input + out_row[j * components + 0] * anti_input) / 0xff; \
707 out_row[j * components + 1] = \
708 (g * input + out_row[j * components + 1] * anti_input) / 0xff; \
709 out_row[j * components + 2] = \
710 (b * input + out_row[j * components + 2] * anti_input) / 0xff; \
712 out_row[j * components + 3] = \
713 MAX((input << 8) | input, out_row[j * components + 3]); \
715 out_row[j * components + 3] = \
716 MAX(input, out_row[j * components + 3]); \
720 out_row[j * components + 0] = \
721 (r * input + out_row[j * components + 0] * anti_input) / 0xff; \
722 out_row[j * components + 1] = \
723 (g * input + out_row[j * components + 1] * anti_input) / 0xff; \
724 out_row[j * components + 2] = \
725 (b * input + out_row[j * components + 2] * anti_input) / 0xff; \
734 #define TRANSLATEA(type, max, components, r, g, b) \
736 unsigned char **in_rows = plugin->text_mask->get_rows(); \
737 type **out_rows = (type**)plugin->output->get_rows(); \
739 for(int i = pkg->y1; i < pkg->y2; i++) \
741 if(i + server->out_y1_int >= 0 && \
742 i + server->out_y1_int < server->output_h) \
744 unsigned char *in_row = in_rows[i]; \
745 type *out_row = out_rows[i + server->out_y1_int]; \
747 for(int j = server->out_x1; j < server->out_x2_int; j++) \
750 j < server->output_w) \
752 int input = (int)(in_row[j - server->out_x1]); \
754 input *= plugin->alpha; \
755 /* Alpha is 0 - 256 */ \
758 int anti_input = 0xff - input; \
759 if(components == 4) \
761 out_row[j * components + 0] = \
762 (r * input + out_row[j * components + 0] * anti_input) / 0xff; \
763 out_row[j * components + 1] = \
764 (g * input + out_row[j * components + 1] * anti_input) / 0xff; \
765 out_row[j * components + 2] = \
766 (b * input + out_row[j * components + 2] * anti_input) / 0xff; \
768 out_row[j * components + 3] = \
769 MAX((input << 8) | input, out_row[j * components + 3]); \
771 out_row[j * components + 3] = \
772 MAX(input, out_row[j * components + 3]); \
776 out_row[j * components + 0] = \
777 (r * input + out_row[j * components + 0] * anti_input) / 0xff; \
778 out_row[j * components + 1] = \
779 (g * input + out_row[j * components + 1] * anti_input) / 0xff; \
780 out_row[j * components + 2] = \
781 (b * input + out_row[j * components + 2] * anti_input) / 0xff; \
791 void TitleTranslateUnit::process_package(LoadPackage *package)
793 TitleTranslatePackage *pkg = (TitleTranslatePackage*)package;
794 TitleTranslate *server = (TitleTranslate*)this->server;
795 int r_in, g_in, b_in;
797 //printf("TitleTranslateUnit::process_package 1 %d %d\n", pkg->y1, pkg->y2);
799 r_in = (plugin->config.color & 0xff0000) >> 16;
800 g_in = (plugin->config.color & 0xff00) >> 8;
801 b_in = plugin->config.color & 0xff;
803 switch(plugin->output->get_color_model())
807 TRANSLATE(unsigned char, 0xff, 3, r_in, g_in, b_in);
812 unsigned char y, u, v;
813 yuv.rgb_to_yuv_8(r_in, g_in, b_in, y, u, v);
814 TRANSLATE(unsigned char, 0xff, 3, y, u, v);
820 r = (r_in << 8) | r_in;
821 g = (g_in << 8) | g_in;
822 b = (b_in << 8) | b_in;
823 TRANSLATE(uint16_t, 0xffff, 3, r, g, b);
836 TRANSLATE(uint16_t, 0xffff, 3, y, u, v);
841 TRANSLATE(unsigned char, 0xff, 4, r_in, g_in, b_in);
846 unsigned char y, u, v;
847 yuv.rgb_to_yuv_8(r_in, g_in, b_in, y, u, v);
848 TRANSLATE(unsigned char, 0xff, 4, y, u, v);
851 case BC_RGBA16161616:
854 r = (r_in << 8) | r_in;
855 g = (g_in << 8) | g_in;
856 b = (b_in << 8) | b_in;
857 TRANSLATE(uint16_t, 0xffff, 4, r, g, b);
860 case BC_YUVA16161616:
870 TRANSLATE(uint16_t, 0xffff, 4, y, u, v);
875 //printf("TitleTranslateUnit::process_package 5\n");
881 TitleTranslate::TitleTranslate(TitleMain *plugin, int cpus)
884 this->plugin = plugin;
885 x_table = y_table = 0;
888 TitleTranslate::~TitleTranslate()
890 if(x_table) delete [] x_table;
891 if(y_table) delete [] y_table;
894 void TitleTranslate::init_packages()
896 //printf("TitleTranslate::init_packages 1\n");
897 // Generate scaling tables
898 if(x_table) delete [] x_table;
899 if(y_table) delete [] y_table;
900 //printf("TitleTranslate::init_packages 1\n");
902 output_w = plugin->output->get_w();
903 output_h = plugin->output->get_h();
904 //printf("TitleTranslate::init_packages 1 %f %d\n", plugin->text_x1, plugin->text_w);
907 TranslateUnit::translation_array_f(x_table,
909 plugin->text_x1 + plugin->text_w,
916 //printf("TitleTranslate::init_packages 1 %f %f\n", plugin->mask_y1, plugin->mask_y2);
918 TranslateUnit::translation_array_f(y_table,
920 plugin->mask_y1 + plugin->text_mask->get_h(),
922 plugin->text_mask->get_h(),
923 plugin->text_mask->get_h(),
928 //printf("TitleTranslate::init_packages 1\n");
935 int increment = (out_y2 - out_y1) / get_total_packages() + 1;
937 //printf("TitleTranslate::init_packages 1 %d %d %d %d\n",
938 // out_y1, out_y2, out_y1_int, out_y2_int);
939 for(int i = 0; i < get_total_packages(); i++)
941 TitleTranslatePackage *pkg = (TitleTranslatePackage*)get_package(i);
942 pkg->y1 = i * increment;
943 pkg->y2 = i * increment + increment;
944 if(pkg->y1 > out_y2 - out_y1)
945 pkg->y1 = out_y2 - out_y1;
946 if(pkg->y2 > out_y2 - out_y1)
947 pkg->y2 = out_y2 - out_y1;
949 //printf("TitleTranslate::init_packages 2\n");
952 LoadClient* TitleTranslate::new_client()
954 return new TitleTranslateUnit(plugin, this);
957 LoadPackage* TitleTranslate::new_package()
959 return new TitleTranslatePackage;
976 ArrayList<FontEntry*>* TitleMain::fonts = 0;
980 TitleMain::TitleMain(PluginServer *server)
981 : PluginVClient(server)
983 PLUGIN_CONSTRUCTOR_MACRO
985 // Build font database
988 text_mask_stroke = 0;
991 freetype_library = 0;
996 need_reconfigure = 1;
999 TitleMain::~TitleMain()
1001 PLUGIN_DESTRUCTOR_MACRO
1002 if(text_mask) delete text_mask;
1003 if(text_mask_stroke) delete text_mask_stroke;
1004 if(char_positions) delete [] char_positions;
1005 if(rows_bottom) delete [] rows_bottom;
1007 if(glyph_engine) delete glyph_engine;
1008 if(title_engine) delete title_engine;
1009 if(freetype_library) FT_Done_FreeType(freetype_library);
1010 if(translate) delete translate;
1013 char* TitleMain::plugin_title() { return _("Title"); }
1014 int TitleMain::is_realtime() { return 1; }
1015 int TitleMain::is_synthesis() { return 1; }
1017 void TitleMain::build_fonts()
1021 fonts = new ArrayList<FontEntry*>;
1022 // Construct path from location of the plugin
1023 char search_path[BCTEXTLEN];
1024 strcpy(search_path, PluginClient::get_path());
1025 char *ptr = strrchr(search_path, '/');
1026 strcpy(ptr + 1, FONT_SEARCHPATH);
1027 char command_line[BCTEXTLEN];
1029 sprintf(command_line,
1030 "find %s -name 'fonts.dir' -print -exec cat {} \\;",
1032 //printf("TitleMain::build_fonts %s\n", command_line);
1034 FILE *in = popen(command_line, "r");
1037 char current_dir[BCTEXTLEN];
1038 FT_Library freetype_library = 0; // Freetype library
1039 FT_Face freetype_face = 0;
1041 // FT_Init_FreeType(&freetype_library);
1046 char string[BCTEXTLEN], string2[BCTEXTLEN];
1047 fgets(string, BCTEXTLEN, in);
1048 if(!strlen(string)) break;
1050 char *in_ptr = string;
1053 // Get current directory
1055 if(string[0] == '/')
1057 out_ptr = current_dir;
1058 while(*in_ptr != 0 && *in_ptr != 0xa)
1059 *out_ptr++ = *in_ptr++;
1061 while(*out_ptr != '/')
1068 //printf("TitleMain::build_fonts %s\n", string);
1069 FontEntry *entry = new FontEntry;
1074 while(*in_ptr != 0 && *in_ptr != ' ' && *in_ptr != 0xa)
1076 *out_ptr++ = *in_ptr++;
1079 if(string2[0] == '/')
1081 entry->path = new char[strlen(string2) + 1];
1082 sprintf(entry->path, "%s", string2);
1086 entry->path = new char[strlen(current_dir) + strlen(string2) + 1];
1087 sprintf(entry->path, "%s%s", current_dir, string2);
1091 // Test path existence
1092 struct stat test_stat;
1093 if(stat(entry->path, &test_stat))
1097 //printf("TitleMain::build_fonts 1 %s\n", entry->path);
1100 while(*in_ptr != 0 && *in_ptr != 0xa && (*in_ptr == ' ' || *in_ptr == '-'))
1104 while(*in_ptr != 0 && *in_ptr != ' ' && *in_ptr != 0xa && *in_ptr != '-')
1106 *out_ptr++ = *in_ptr++;
1109 entry->foundary = new char[strlen(string2) + 1];
1110 strcpy(entry->foundary, string2);
1111 if(*in_ptr == '-') in_ptr++;
1116 while(*in_ptr != 0 && *in_ptr != 0xa && *in_ptr != '-')
1118 *out_ptr++ = *in_ptr++;
1121 entry->family = new char[strlen(string2) + 1];
1122 strcpy(entry->family, string2);
1123 if(*in_ptr == '-') in_ptr++;
1127 while(*in_ptr != 0 && *in_ptr != 0xa && *in_ptr != '-')
1129 *out_ptr++ = *in_ptr++;
1132 entry->weight = new char[strlen(string2) + 1];
1133 strcpy(entry->weight, string2);
1134 if(*in_ptr == '-') in_ptr++;
1138 while(*in_ptr != 0 && *in_ptr != 0xa && *in_ptr != '-')
1140 *out_ptr++ = *in_ptr++;
1143 entry->slant = new char[strlen(string2) + 1];
1144 strcpy(entry->slant, string2);
1145 if(*in_ptr == '-') in_ptr++;
1149 while(*in_ptr != 0 && *in_ptr != 0xa && *in_ptr != '-')
1151 *out_ptr++ = *in_ptr++;
1154 entry->swidth = new char[strlen(string2) + 1];
1155 strcpy(entry->swidth, string2);
1156 if(*in_ptr == '-') in_ptr++;
1160 while(*in_ptr != 0 && *in_ptr != 0xa && *in_ptr != '-')
1162 *out_ptr++ = *in_ptr++;
1165 entry->adstyle = new char[strlen(string2) + 1];
1166 strcpy(entry->adstyle, string2);
1167 if(*in_ptr == '-') in_ptr++;
1171 while(*in_ptr != 0 && *in_ptr != 0xa && *in_ptr != '-')
1173 *out_ptr++ = *in_ptr++;
1176 entry->pixelsize = atol(string2);
1177 if(*in_ptr == '-') in_ptr++;
1181 while(*in_ptr != 0 && *in_ptr != 0xa && *in_ptr != '-')
1183 *out_ptr++ = *in_ptr++;
1186 entry->pointsize = atol(string2);
1187 if(*in_ptr == '-') in_ptr++;
1191 while(*in_ptr != 0 && *in_ptr != 0xa && *in_ptr != '-')
1193 *out_ptr++ = *in_ptr++;
1196 entry->xres = atol(string2);
1197 if(*in_ptr == '-') in_ptr++;
1201 while(*in_ptr != 0 && *in_ptr != 0xa && *in_ptr != '-')
1203 *out_ptr++ = *in_ptr++;
1206 entry->yres = atol(string2);
1207 if(*in_ptr == '-') in_ptr++;
1211 while(*in_ptr != 0 && *in_ptr != 0xa && *in_ptr != '-')
1213 *out_ptr++ = *in_ptr++;
1216 entry->spacing = new char[strlen(string2) + 1];
1217 strcpy(entry->spacing, string2);
1218 if(*in_ptr == '-') in_ptr++;
1222 while(*in_ptr != 0 && *in_ptr != 0xa && *in_ptr != '-')
1224 *out_ptr++ = *in_ptr++;
1227 entry->avg_width = atol(string2);
1228 if(*in_ptr == '-') in_ptr++;
1232 while(*in_ptr != 0 && *in_ptr != 0xa && *in_ptr != '-')
1234 *out_ptr++ = *in_ptr++;
1237 entry->registry = new char[strlen(string2) + 1];
1238 strcpy(entry->registry, string2);
1239 if(*in_ptr == '-') in_ptr++;
1243 while(*in_ptr != 0 && *in_ptr != 0xa)
1245 *out_ptr++ = *in_ptr++;
1248 entry->encoding = new char[strlen(string2) + 1];
1249 strcpy(entry->encoding, string2);
1254 if(strlen(entry->foundary) && !result)
1256 //printf("TitleMain::build_fonts 1 %s\n", entry->path);
1257 // This takes a real long time to do. Instead just take all fonts
1258 // if(!load_freetype_face(freetype_library,
1262 if(entry->family[0])
1265 sprintf(string, "%s (%s)", entry->family, entry->foundary);
1266 entry->fixed_title = new char[strlen(string) + 1];
1267 strcpy(entry->fixed_title, string);
1269 if(!strcasecmp(entry->weight, "demibold") ||
1270 !strcasecmp(entry->weight, "bold"))
1271 entry->fixed_style |= FONT_BOLD;
1272 if(!strcasecmp(entry->slant, "i") ||
1273 !strcasecmp(entry->slant, "o"))
1274 entry->fixed_style |= FONT_ITALIC;
1275 fonts->append(entry);
1276 // printf("TitleMain::build_fonts %s: success\n",
1278 //printf("TitleMain::build_fonts 2\n");
1282 // printf("TitleMain::build_fonts %s: FT_New_Face failed\n",
1284 //printf("TitleMain::build_fonts 3\n");
1296 if(freetype_library) FT_Done_FreeType(freetype_library);
1300 // for(int i = 0; i < fonts->total; i++)
1301 // fonts->values[i]->dump();
1306 int TitleMain::load_freetype_face(FT_Library &freetype_library,
1307 FT_Face &freetype_face,
1310 //printf("TitleMain::load_freetype_face 1\n");
1311 if(!freetype_library) FT_Init_FreeType(&freetype_library);
1312 if(freetype_face) FT_Done_Face(freetype_face);
1314 //printf("TitleMain::load_freetype_face 2\n");
1316 // Use freetype's internal function for loading font
1317 if(FT_New_Face(freetype_library,
1322 fprintf(stderr, _("TitleMain::load_freetype_face %s failed.\n"));
1323 FT_Done_FreeType(freetype_library);
1325 freetype_library = 0;
1332 //printf("TitleMain::load_freetype_face 4\n");
1335 FontEntry* TitleMain::get_font_entry(char *title,
1339 //printf("TitleMain::get_font_entry %s %d %d\n", title, style, size);
1340 FontEntry *result = 0;
1343 for(int i = 0; i < fonts->total; i++)
1345 FontEntry *entry = fonts->values[i];
1347 if(!result) result = entry;
1349 if(!strcmp(title, entry->fixed_title))
1351 if(!got_title) result = entry;
1354 // Not every font has a size but every font has a style
1355 if(entry->fixed_style == style)
1358 if(entry->fixed_style == style && entry->pointsize == size)
1368 FontEntry* TitleMain::get_font()
1370 return get_font_entry(config.font,
1380 int TitleMain::get_char_height()
1382 // this is height above the zero line, but does not include characters that go below
1383 int result = config.size;
1384 if((config.style & FONT_OUTLINE)) result += (int)ceil(config.stroke_width * 2);
1388 int TitleMain::get_char_advance(int current, int next)
1392 TitleGlyph *current_glyph = 0;
1393 TitleGlyph *next_glyph = 0;
1395 if(current == 0xa) return 0;
1397 for(int i = 0; i < glyphs.total; i++)
1399 if(glyphs.values[i]->c == current)
1401 current_glyph = glyphs.values[i];
1406 for(int i = 0; i < glyphs.total; i++)
1408 if(glyphs.values[i]->c == next)
1410 next_glyph = glyphs.values[i];
1416 result = current_glyph->advance_w;
1418 //printf("TitleMain::get_char_advance 1 %c %c %p %p\n", current, next, current_glyph, next_glyph);
1420 FT_Get_Kerning(freetype_face,
1421 current_glyph->freetype_index,
1422 next_glyph->freetype_index,
1427 //printf("TitleMain::get_char_advance 2 %d %d\n", result, kerning.x);
1429 return result + (kerning.x >> 6);
1433 void TitleMain::draw_glyphs()
1435 // Build table of all glyphs needed
1436 int text_len = strlen(config.text);
1437 int total_packages = 0;
1439 cd = iconv_open ("UCS-4", config.encoding);
1442 if (cd == (iconv_t) -1)
1444 /* Something went wrong. */
1445 fprintf (stderr, _("Iconv conversion from %s to Unicode UCS-4 not available\n"),config.encoding);
1448 for(int i = 0; i < text_len; i++)
1451 int c = config.text[i];
1454 /* if iconv is working ok for current encoding */
1455 if (cd != (iconv_t) -1)
1458 size_t inbytes,outbytes;
1460 char *inp = (char*)&inbuf, *outp = (char *)&char_code;
1466 iconv (cd, &inp, &inbytes, &outp, &outbytes);
1467 #if __BYTE_ORDER == __LITTLE_ENDIAN
1468 char_code = bswap_32(char_code);
1469 #endif /* Big endian. */
1477 for(int j = 0; j < glyphs.total; j++)
1479 if(glyphs.values[j]->char_code == char_code)
1489 //printf("TitleMain::draw_glyphs 1\n");
1490 TitleGlyph *glyph = new TitleGlyph;
1491 //printf("TitleMain::draw_glyphs 2\n");
1492 glyphs.append(glyph);
1494 glyph->char_code = char_code;
1500 glyph_engine = new GlyphEngine(this, PluginClient::smp + 1);
1502 glyph_engine->set_package_count(total_packages);
1503 //printf("TitleMain::draw_glyphs 3 %d\n", glyphs.total);
1504 glyph_engine->process_packages();
1505 //printf("TitleMain::draw_glyphs 4\n");
1508 void TitleMain::get_total_extents()
1510 // Determine extents of total text
1513 text_len = strlen(config.text);
1514 if(!char_positions) char_positions = new title_char_position_t[text_len];
1520 for(int i = 0; i < glyphs.total; i++)
1521 if(glyphs.values[i]->top > ascent) ascent = glyphs.values[i]->top;
1522 //printf("TitleMain::get_total_extents %d\n", ascent);
1524 // get the number of rows first
1525 for(int i = 0; i < text_len; i++)
1527 if(config.text[i] == 0xa || i == text_len - 1)
1532 if (!rows_bottom) rows_bottom = new int[text_rows+1];
1536 for(int i = 0; i < text_len; i++)
1538 char_positions[i].x = current_w;
1539 char_positions[i].y = text_rows * get_char_height();
1540 char_positions[i].w = get_char_advance(config.text[i], config.text[i + 1]);
1541 TitleGlyph *current_glyph = 0;
1542 for(int j = 0; j < glyphs.total; j++)
1544 if(glyphs.values[j]->c == config.text[i])
1546 current_glyph = glyphs.values[j];
1550 int current_bottom = current_glyph->top - current_glyph->height;
1551 if (current_bottom < rows_bottom[text_rows])
1552 rows_bottom[text_rows] = current_bottom ;
1554 // printf("TitleMain::get_total_extents 1 %c %d %d %d\n",
1556 // char_positions[i].x,
1557 // char_positions[i].y,
1558 // char_positions[i].w);
1559 current_w += char_positions[i].w;
1561 if(config.text[i] == 0xa || i == text_len - 1)
1564 rows_bottom[text_rows] = 0;
1565 if(current_w > text_w) text_w = current_w;
1569 text_w += config.dropshadow;
1570 text_h = text_rows * get_char_height();
1571 text_h += config.dropshadow;
1573 // Now that text_w is known
1574 // Justify rows based on configuration
1576 for(int i = 0; i < text_len; i++)
1578 if(config.text[i] == 0xa || i == text_len - 1)
1580 for(int j = row_start; j <= i; j++)
1582 switch(config.hjustification)
1588 char_positions[j].x += (text_w -
1589 char_positions[i].x -
1590 char_positions[i].w) /
1595 char_positions[j].x += (text_w -
1596 char_positions[i].x -
1597 char_positions[i].w);
1606 //printf("TitleMain::get_total_extents 2 %d %d\n", text_w, text_h);
1609 int TitleMain::draw_mask()
1611 int old_visible_row1 = visible_row1;
1612 int old_visible_row2 = visible_row2;
1615 // Determine y of visible text
1616 if(config.motion_strategy == BOTTOM_TO_TOP)
1618 // printf("TitleMain::draw_mask 1 %d %d %d %d\n",
1619 // config.motion_strategy,
1620 // get_source_position(),
1621 // get_source_start(),
1622 // config.prev_keyframe_position);
1623 float magnitude = config.pixels_per_second *
1624 ((get_source_position() - get_source_start()) -
1625 (config.prev_keyframe_position - get_source_start())) /
1626 PluginVClient::project_frame_rate;
1629 int loop_size = text_h + input->get_h();
1630 magnitude -= (int)(magnitude / loop_size) * loop_size;
1632 text_y1 = config.y + input->get_h() - magnitude;
1635 if(config.motion_strategy == TOP_TO_BOTTOM)
1637 float magnitude = config.pixels_per_second *
1638 (get_source_position() -
1639 get_source_start() -
1640 config.prev_keyframe_position) /
1641 PluginVClient::project_frame_rate;
1644 int loop_size = text_h + input->get_h();
1645 magnitude -= (int)(magnitude / loop_size) * loop_size;
1647 text_y1 = config.y + magnitude;
1651 if(config.vjustification == JUSTIFY_TOP)
1656 if(config.vjustification == JUSTIFY_MID)
1658 text_y1 = config.y + input->get_h() / 2 - text_h / 2;
1661 if(config.vjustification == JUSTIFY_BOTTOM)
1663 text_y1 = config.y + input->get_h() - text_h;
1666 text_y2 = text_y1 + text_h + 0.5;
1668 // Determine x of visible text
1669 if(config.motion_strategy == RIGHT_TO_LEFT)
1671 float magnitude = config.pixels_per_second *
1672 (get_source_position() -
1673 get_source_start() -
1674 config.prev_keyframe_position) /
1675 PluginVClient::project_frame_rate;
1678 int loop_size = text_w + input->get_w();
1679 magnitude -= (int)(magnitude / loop_size) * loop_size;
1681 text_x1 = config.x + (float)input->get_w() - magnitude;
1684 if(config.motion_strategy == LEFT_TO_RIGHT)
1686 float magnitude = config.pixels_per_second *
1687 (get_source_position() -
1688 get_source_start() -
1689 config.prev_keyframe_position) /
1690 PluginVClient::project_frame_rate;
1693 int loop_size = text_w + input->get_w();
1694 magnitude -= (int)(magnitude / loop_size) * loop_size;
1696 text_x1 = config.x + -(float)text_w + magnitude;
1699 if(config.hjustification == JUSTIFY_LEFT)
1704 if(config.hjustification == JUSTIFY_MID)
1706 text_x1 = config.x + input->get_w() / 2 - text_w / 2;
1709 if(config.hjustification == JUSTIFY_RIGHT)
1711 text_x1 = config.x + input->get_w() - text_w;
1718 // Determine y extents just of visible text
1719 visible_row1 = (int)(-text_y1 / get_char_height());
1720 if(visible_row1 < 0) visible_row1 = 0;
1722 visible_row2 = (int)((float)text_rows - (text_y2 - input->get_h()) / get_char_height() + 1);
1723 if(visible_row2 > text_rows) visible_row2 = text_rows;
1726 if(visible_row2 <= visible_row1) return 1;
1729 mask_y1 = text_y1 + visible_row1 * get_char_height();
1730 mask_y2 = text_y1 + visible_row2 * get_char_height();
1731 text_x1 += config.x;
1734 visible_char1 = visible_char2 = 0;
1736 for(int i = 0; i < text_len; i++)
1738 title_char_position_t *char_position = char_positions + i;
1739 int char_row = char_position->y / get_char_height();
1740 if(char_row >= visible_row1 &&
1741 char_row < visible_row2)
1756 int visible_rows = visible_row2 - visible_row1;
1757 int need_redraw = 0;
1759 (text_mask->get_w() != text_w ||
1760 text_mask->get_h() != visible_rows * get_char_height() - rows_bottom[visible_row2 - 1]))
1763 delete text_mask_stroke;
1765 text_mask_stroke = 0;
1770 text_mask = new VFrame(0,
1772 visible_rows * get_char_height() - rows_bottom[visible_row2-1],
1774 text_mask_stroke = new VFrame(0,
1776 visible_rows * get_char_height() - rows_bottom[visible_row2-1],
1784 // Draw on text mask if different
1785 if(old_visible_row1 != visible_row1 ||
1786 old_visible_row2 != visible_row2 ||
1789 text_mask->clear_frame();
1790 text_mask_stroke->clear_frame();
1794 title_engine = new TitleEngine(this, PluginClient::smp + 1);
1796 title_engine->set_package_count(visible_char2 - visible_char1);
1797 title_engine->process_packages();
1804 void TitleMain::overlay_mask()
1808 // printf("TitleMain::overlay_mask %lld %lld %lld\n",
1809 // get_source_position(),
1810 // config.prev_keyframe_position,
1811 // config.next_keyframe_position);
1812 if(!EQUIV(config.fade_in, 0))
1814 int fade_len = (int)(config.fade_in * PluginVClient::project_frame_rate);
1815 int fade_position = get_source_position() -
1816 /* get_source_start() - */
1817 config.prev_keyframe_position;
1820 if(fade_position >= 0 && fade_position < fade_len)
1822 alpha = (int)((float)0x100 *
1828 if(!EQUIV(config.fade_out, 0))
1830 int fade_len = (int)(config.fade_out *
1831 PluginVClient::project_frame_rate);
1832 int fade_position = config.next_keyframe_position -
1833 get_source_position();
1836 if(fade_position >= 0 && fade_position < fade_len)
1838 alpha = (int)((float)0x100 *
1844 if(config.dropshadow)
1846 text_x1 += config.dropshadow;
1847 text_x2 += config.dropshadow;
1848 mask_y1 += config.dropshadow;
1849 mask_y2 += config.dropshadow;
1850 if(text_x1 < input->get_w() && text_x1 + text_w > 0 &&
1851 mask_y1 < input->get_h() && mask_y2 > 0)
1853 if(!translate) translate = new TitleTranslate(this, PluginClient::smp + 1);
1854 // Do 2 passes if dropshadow.
1855 int temp_color = config.color;
1857 translate->process_packages();
1858 config.color = temp_color;
1860 text_x1 -= config.dropshadow;
1861 text_x2 -= config.dropshadow;
1862 mask_y1 -= config.dropshadow;
1863 mask_y2 -= config.dropshadow;
1866 if(text_x1 < input->get_w() && text_x1 + text_w > 0 &&
1867 mask_y1 < input->get_h() && mask_y2 > 0)
1869 if(!translate) translate = new TitleTranslate(this, PluginClient::smp + 1);
1870 translate->process_packages();
1871 if (config.stroke_width >= ZERO &&
1872 (config.style & FONT_OUTLINE))
1874 int temp_color = config.color;
1875 VFrame *tmp_text_mask = this->text_mask;
1876 config.color = config.color_stroke;
1877 this->text_mask = this->text_mask_stroke;
1879 translate->process_packages();
1880 config.color = temp_color;
1881 this->text_mask = tmp_text_mask;
1886 void TitleMain::clear_glyphs()
1888 //printf("TitleMain::clear_glyphs 1\n");
1889 glyphs.remove_all_objects();
1892 char* TitleMain::motion_to_text(int motion)
1896 case NO_MOTION: return _("No motion"); break;
1897 case BOTTOM_TO_TOP: return _("Bottom to top"); break;
1898 case TOP_TO_BOTTOM: return _("Top to bottom"); break;
1899 case RIGHT_TO_LEFT: return _("Right to left"); break;
1900 case LEFT_TO_RIGHT: return _("Left to right"); break;
1904 int TitleMain::text_to_motion(char *text)
1906 for(int i = 0; i < TOTAL_PATHS; i++)
1908 if(!strcasecmp(motion_to_text(i), text)) return i;
1919 int TitleMain::process_realtime(VFrame *input_ptr, VFrame *output_ptr)
1923 output = output_ptr;
1926 need_reconfigure |= load_configuration();
1929 // Always synthesize text and redraw it for timecode
1932 Units::totext(config.text,
1933 (double)get_source_position() / PluginVClient::project_frame_rate,
1936 PluginVClient::project_frame_rate,
1938 need_reconfigure = 1;
1942 if(config.size <= 0 || config.size >= 2048) config.size = 72;
1943 if(config.stroke_width < 0 ||
1944 config.stroke_width >= 512) config.stroke_width = 0.0;
1945 if(!strlen(config.text)) return 0;
1946 if(!strlen(config.encoding)) strcpy(config.encoding, DEFAULT_ENCODING);
1948 //printf("TitleMain::process_realtime 4\n");
1950 // Handle reconfiguration
1951 if(need_reconfigure)
1953 //printf("TitleMain::process_realtime 2\n");
1954 if(text_mask) delete text_mask;
1955 if(text_mask_stroke) delete text_mask_stroke;
1957 text_mask_stroke = 0;
1958 //printf("TitleMain::process_realtime 2\n");
1959 if(freetype_face) FT_Done_Face(freetype_face);
1961 //printf("TitleMain::process_realtime 2\n");
1962 if(glyph_engine) delete glyph_engine;
1964 //printf("TitleMain::process_realtime 2\n");
1965 if(char_positions) delete [] char_positions;
1967 if(rows_bottom) delete [] rows_bottom;
1969 //printf("TitleMain::process_realtime 2\n");
1971 //printf("TitleMain::process_realtime 2\n");
1976 if(!freetype_library)
1977 FT_Init_FreeType(&freetype_library);
1979 //printf("TitleMain::process_realtime 2\n");
1982 FontEntry *font = get_font();
1983 //printf("TitleMain::process_realtime 2.1 %s\n", font->path);
1984 if(load_freetype_face(freetype_library,
1988 printf("TitleMain::process_realtime %s: FT_New_Face failed.\n",
1992 //printf("TitleMain::process_realtime 2.2\n");
1994 if(!result) FT_Set_Pixel_Sizes(freetype_face, config.size, 0);
1995 //printf("TitleMain::process_realtime 2.3\n");
1998 //printf("TitleMain::process_realtime 3\n");
2003 //printf("TitleMain::process_realtime 4\n");
2004 get_total_extents();
2005 //printf("TitleMain::process_realtime 5\n");
2006 need_reconfigure = 0;
2012 //printf("TitleMain::process_realtime 4\n");
2013 // Determine region of text visible on the output and draw mask
2014 result = draw_mask();
2016 //printf("TitleMain::process_realtime 50\n");
2019 // Overlay mask on output
2024 //printf("TitleMain::process_realtime 60 %d\n", glyphs.total);
2029 int TitleMain::show_gui()
2031 load_configuration();
2032 thread = new TitleThread(this);
2037 int TitleMain::set_string()
2039 if(thread) thread->window->set_title(gui_string);
2043 void TitleMain::raise_window()
2047 thread->window->raise_window();
2048 thread->window->flush();
2052 void TitleMain::update_gui()
2056 int reconfigure = load_configuration();
2059 thread->window->lock_window();
2060 thread->window->update();
2061 thread->window->unlock_window();
2067 int TitleMain::load_defaults()
2069 char directory[1024], text_path[1024];
2070 // set the default directory
2071 sprintf(directory, "%s/title.rc", File::get_config_path());
2073 // load the defaults
2074 defaults = new Defaults(directory);
2077 defaults->get("FONT", config.font);
2078 defaults->get("ENCODING", config.encoding);
2079 config.style = defaults->get("STYLE", (int64_t)config.style);
2080 config.size = defaults->get("SIZE", config.size);
2081 config.color = defaults->get("COLOR", config.color);
2082 config.color_stroke = defaults->get("COLOR_STROKE", config.color_stroke);
2083 config.stroke_width = defaults->get("STROKE_WIDTH", config.stroke_width);
2084 config.motion_strategy = defaults->get("MOTION_STRATEGY", config.motion_strategy);
2085 config.loop = defaults->get("LOOP", config.loop);
2086 config.pixels_per_second = defaults->get("PIXELS_PER_SECOND", config.pixels_per_second);
2087 config.hjustification = defaults->get("HJUSTIFICATION", config.hjustification);
2088 config.vjustification = defaults->get("VJUSTIFICATION", config.vjustification);
2089 config.fade_in = defaults->get("FADE_IN", config.fade_in);
2090 config.fade_out = defaults->get("FADE_OUT", config.fade_out);
2091 config.x = defaults->get("TITLE_X", config.x);
2092 config.y = defaults->get("TITLE_Y", config.y);
2093 config.dropshadow = defaults->get("DROPSHADOW", config.dropshadow);
2094 config.timecode = defaults->get("TIMECODE", config.timecode);
2095 window_w = defaults->get("WINDOW_W", 660);
2096 window_h = defaults->get("WINDOW_H", 480);
2098 // Store text in separate path to isolate special characters
2100 sprintf(text_path, "%s/title_text.rc", File::get_config_path());
2101 fs.complete_path(text_path);
2102 FILE *fd = fopen(text_path, "rb");
2105 fseek(fd, 0, SEEK_END);
2106 int64_t len = ftell(fd);
2107 fseek(fd, 0, SEEK_SET);
2108 fread(config.text, len, 1, fd);
2109 config.text[len] = 0;
2110 //printf("TitleMain::load_defaults %s\n", config.text);
2118 int TitleMain::save_defaults()
2120 char text_path[1024];
2122 defaults->update("FONT", config.font);
2123 defaults->update("ENCODING", config.encoding);
2124 defaults->update("STYLE", (int64_t)config.style);
2125 defaults->update("SIZE", config.size);
2126 defaults->update("COLOR", config.color);
2127 defaults->update("COLOR_STROKE", config.color_stroke);
2128 defaults->update("STROKE_WIDTH", config.stroke_width);
2129 defaults->update("MOTION_STRATEGY", config.motion_strategy);
2130 defaults->update("LOOP", config.loop);
2131 defaults->update("PIXELS_PER_SECOND", config.pixels_per_second);
2132 defaults->update("HJUSTIFICATION", config.hjustification);
2133 defaults->update("VJUSTIFICATION", config.vjustification);
2134 defaults->update("FADE_IN", config.fade_in);
2135 defaults->update("FADE_OUT", config.fade_out);
2136 defaults->update("TITLE_X", config.x);
2137 defaults->update("TITLE_Y", config.y);
2138 defaults->update("DROPSHADOW", config.dropshadow);
2139 defaults->update("TIMECODE", config.timecode);
2140 defaults->update("WINDOW_W", window_w);
2141 defaults->update("WINDOW_H", window_h);
2144 // Store text in separate path to isolate special characters
2146 sprintf(text_path, "%s/title_text.rc", File::get_config_path());
2147 fs.complete_path(text_path);
2148 FILE *fd = fopen(text_path, "wb");
2151 fwrite(config.text, strlen(config.text), 1, fd);
2155 // perror("TitleMain::save_defaults");
2162 int TitleMain::load_configuration()
2164 KeyFrame *prev_keyframe, *next_keyframe;
2165 prev_keyframe = get_prev_keyframe(get_source_position());
2166 next_keyframe = get_next_keyframe(get_source_position());
2167 int64_t prev_position = edl_to_local(prev_keyframe->position);
2168 int64_t next_position = edl_to_local(next_keyframe->position);
2170 TitleConfig old_config, prev_config, next_config;
2171 old_config.copy_from(config);
2172 read_data(prev_keyframe);
2173 prev_config.copy_from(config);
2174 read_data(next_keyframe);
2175 next_config.copy_from(config);
2177 config.prev_keyframe_position = prev_position;
2178 config.next_keyframe_position = next_position;
2179 if(config.next_keyframe_position == config.prev_keyframe_position)
2180 config.next_keyframe_position = get_source_start() + get_total_len();
2181 if(config.prev_keyframe_position == 0)
2182 config.prev_keyframe_position = get_source_start();
2186 config.interpolate(prev_config,
2188 (next_position == prev_position) ?
2189 get_source_position() :
2191 (next_position == prev_position) ?
2192 get_source_position() + 1 :
2194 get_source_position());
2196 if(!config.equivalent(old_config))
2213 void TitleMain::save_data(KeyFrame *keyframe)
2217 // cause data to be stored directly in text
2218 output.set_shared_string(keyframe->get_data(), -MESSAGESIZE);
2219 output.tag.set_title("TITLE");
2220 output.tag.set_property("FONT", config.font);
2221 output.tag.set_property("ENCODING", config.encoding);
2222 output.tag.set_property("STYLE", (int64_t)config.style);
2223 output.tag.set_property("SIZE", config.size);
2224 output.tag.set_property("COLOR", config.color);
2225 output.tag.set_property("COLOR_STROKE", config.color_stroke);
2226 output.tag.set_property("STROKE_WIDTH", config.stroke_width);
2227 output.tag.set_property("MOTION_STRATEGY", config.motion_strategy);
2228 output.tag.set_property("LOOP", config.loop);
2229 output.tag.set_property("PIXELS_PER_SECOND", config.pixels_per_second);
2230 output.tag.set_property("HJUSTIFICATION", config.hjustification);
2231 output.tag.set_property("VJUSTIFICATION", config.vjustification);
2232 output.tag.set_property("FADE_IN", config.fade_in);
2233 output.tag.set_property("FADE_OUT", config.fade_out);
2234 output.tag.set_property("TITLE_X", config.x);
2235 output.tag.set_property("TITLE_Y", config.y);
2236 output.tag.set_property("DROPSHADOW", config.dropshadow);
2237 output.tag.set_property("TIMECODE", config.timecode);
2238 output.append_tag();
2239 output.append_newline();
2241 output.append_text(config.text);
2243 output.tag.set_title("/TITLE");
2244 output.append_tag();
2245 output.append_newline();
2246 output.terminate_string();
2247 //printf("TitleMain::save_data 1\n%s\n", output.string);
2248 //printf("TitleMain::save_data 2\n%s\n", config.text);
2251 void TitleMain::read_data(KeyFrame *keyframe)
2255 input.set_shared_string(keyframe->get_data(), strlen(keyframe->get_data()));
2258 int new_interlace = 0;
2259 int new_horizontal = 0;
2260 int new_luminance = 0;
2262 config.prev_keyframe_position = edl_to_local(keyframe->position);
2265 result = input.read_tag();
2269 if(input.tag.title_is("TITLE"))
2271 input.tag.get_property("FONT", config.font);
2272 input.tag.get_property("ENCODING", config.encoding);
2273 config.style = input.tag.get_property("STYLE", (int64_t)config.style);
2274 config.size = input.tag.get_property("SIZE", config.size);
2275 config.color = input.tag.get_property("COLOR", config.color);
2276 config.color_stroke = input.tag.get_property("COLOR_STROKE", config.color_stroke);
2277 config.stroke_width = input.tag.get_property("STROKE_WIDTH", config.stroke_width);
2278 config.motion_strategy = input.tag.get_property("MOTION_STRATEGY", config.motion_strategy);
2279 config.loop = input.tag.get_property("LOOP", config.loop);
2280 config.pixels_per_second = input.tag.get_property("PIXELS_PER_SECOND", config.pixels_per_second);
2281 config.hjustification = input.tag.get_property("HJUSTIFICATION", config.hjustification);
2282 config.vjustification = input.tag.get_property("VJUSTIFICATION", config.vjustification);
2283 config.fade_in = input.tag.get_property("FADE_IN", config.fade_in);
2284 config.fade_out = input.tag.get_property("FADE_OUT", config.fade_out);
2285 config.x = input.tag.get_property("TITLE_X", config.x);
2286 config.y = input.tag.get_property("TITLE_Y", config.y);
2287 config.dropshadow = input.tag.get_property("DROPSHADOW", config.dropshadow);
2288 config.timecode = input.tag.get_property("TIMECODE", config.timecode);
2289 strcpy(config.text, input.read_text());
2290 //printf("TitleMain::read_data 1\n%s\n", input.string);
2291 //printf("TitleMain::read_data 2\n%s\n", config.text);
2294 if(input.tag.title_is("/TITLE"))