00001
00002
00003
00004
00005
00006 #include "clip.h"
00007 #include "colormodels.h"
00008 #include "filexml.h"
00009 #include "filesystem.h"
00010 #include "transportque.inc"
00011 #include "ft2build.h"
00012 #include FT_GLYPH_H
00013 #include FT_BBOX_H
00014 #include FT_OUTLINE_H
00015 #include FT_STROKER_H
00016
00017 #include "language.h"
00018 #include "mwindow.inc"
00019 #include "picon_png.h"
00020 #include "plugincolors.h"
00021 #include "title.h"
00022 #include "titlewindow.h"
00023 #include "transportque.inc"
00024
00025
00026 #include <errno.h>
00027 #include <stdint.h>
00028 #include <stdio.h>
00029 #include <string.h>
00030 #include <endian.h>
00031 #include <byteswap.h>
00032 #include <iconv.h>
00033 #include <sys/stat.h>
00034
00035 #define ZERO (1.0 / 64.0)
00036
00037 #define FONT_SEARCHPATH "fonts"
00038
00039
00040
00041 REGISTER_PLUGIN(TitleMain)
00042
00043
00044 TitleConfig::TitleConfig()
00045 {
00046 style = 0;
00047 color = BLACK;
00048 color_stroke = 0xff0000;
00049 size = 24;
00050 motion_strategy = NO_MOTION;
00051 loop = 0;
00052 hjustification = JUSTIFY_CENTER;
00053 vjustification = JUSTIFY_MID;
00054 fade_in = 0.0;
00055 fade_out = 0.0;
00056 x = 0.0;
00057 y = 0.0;
00058 dropshadow = 10;
00059 sprintf(font, "fixed");
00060 sprintf(text, _("hello world"));
00061 #define DEFAULT_ENCODING "ISO8859-1"
00062 sprintf(encoding, DEFAULT_ENCODING);
00063 #define DEFAULT_TIMECODEFORMAT "h:mm:ss:ff"
00064 sprintf(timecodeformat, DEFAULT_TIMECODEFORMAT);
00065 pixels_per_second = 1.0;
00066 timecode = 0;
00067 stroke_width = 1.0;
00068 }
00069
00070
00071 int TitleConfig::equivalent(TitleConfig &that)
00072 {
00073 return dropshadow == that.dropshadow &&
00074 style == that.style &&
00075 size == that.size &&
00076 color == that.color &&
00077 color_stroke == that.color_stroke &&
00078 stroke_width == that.stroke_width &&
00079 timecode == that.timecode &&
00080 !strcasecmp(timecodeformat, that.timecodeformat) &&
00081 hjustification == that.hjustification &&
00082 vjustification == that.vjustification &&
00083 EQUIV(pixels_per_second, that.pixels_per_second) &&
00084 !strcasecmp(font, that.font) &&
00085 !strcasecmp(encoding, that.encoding) &&
00086 !strcmp(text, that.text);
00087 }
00088
00089 void TitleConfig::copy_from(TitleConfig &that)
00090 {
00091 strcpy(font, that.font);
00092 style = that.style;
00093 size = that.size;
00094 color = that.color;
00095 color_stroke = that.color_stroke;
00096 stroke_width = that.stroke_width;
00097 pixels_per_second = that.pixels_per_second;
00098 motion_strategy = that.motion_strategy;
00099 loop = that.loop;
00100 hjustification = that.hjustification;
00101 vjustification = that.vjustification;
00102 fade_in = that.fade_in;
00103 fade_out = that.fade_out;
00104 x = that.x;
00105 y = that.y;
00106 dropshadow = that.dropshadow;
00107 timecode = that.timecode;
00108 strcpy(timecodeformat, that.timecodeformat);
00109 strcpy(text, that.text);
00110 strcpy(encoding, that.encoding);
00111 }
00112
00113 void TitleConfig::interpolate(TitleConfig &prev,
00114 TitleConfig &next,
00115 int64_t prev_frame,
00116 int64_t next_frame,
00117 int64_t current_frame)
00118 {
00119 strcpy(font, prev.font);
00120 strcpy(encoding, prev.encoding);
00121 style = prev.style;
00122 size = prev.size;
00123 color = prev.color;
00124 color_stroke = prev.color_stroke;
00125 stroke_width = prev.stroke_width;
00126 motion_strategy = prev.motion_strategy;
00127 loop = prev.loop;
00128 hjustification = prev.hjustification;
00129 vjustification = prev.vjustification;
00130 fade_in = prev.fade_in;
00131 fade_out = prev.fade_out;
00132 pixels_per_second = prev.pixels_per_second;
00133 strcpy(text, prev.text);
00134
00135 double next_scale = (double)(current_frame - prev_frame) / (next_frame - prev_frame);
00136 double prev_scale = (double)(next_frame - current_frame) / (next_frame - prev_frame);
00137
00138
00139
00140
00141 this->x = prev.x;
00142 this->y = prev.y;
00143 timecode = prev.timecode;
00144 strcpy(timecodeformat, prev.timecodeformat);
00145
00146 this->dropshadow = prev.dropshadow;
00147 }
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165 FontEntry::FontEntry()
00166 {
00167 path = 0;
00168 foundary = 0;
00169 family = 0;
00170 weight = 0;
00171 slant = 0;
00172 swidth = 0;
00173 adstyle = 0;
00174 spacing = 0;
00175 registry = 0;
00176 encoding = 0;
00177 fixed_title = 0;
00178 fixed_style = 0;
00179 }
00180
00181 FontEntry::~FontEntry()
00182 {
00183 if(path) delete [] path;
00184 if(foundary) delete [] foundary;
00185 if(family) delete [] family;
00186 if(weight) delete [] weight;
00187 if(slant) delete [] slant;
00188 if(swidth) delete [] swidth;
00189 if(adstyle) delete [] adstyle;
00190 if(spacing) delete [] spacing;
00191 if(registry) delete [] registry;
00192 if(encoding) delete [] encoding;
00193 if(fixed_title) delete [] fixed_title;
00194 }
00195
00196 void FontEntry::dump()
00197 {
00198 printf("%s: %s %s %s %s %s %s %d %d %d %d %s %d %s %s\n",
00199 path,
00200 foundary,
00201 family,
00202 weight,
00203 slant,
00204 swidth,
00205 adstyle,
00206 pixelsize,
00207 pointsize,
00208 xres,
00209 yres,
00210 spacing,
00211 avg_width,
00212 registry,
00213 encoding);
00214 }
00215
00216 TitleGlyph::TitleGlyph()
00217 {
00218 char_code = 0;
00219 c=0;
00220 data = 0;
00221 data_stroke = 0;
00222 }
00223
00224
00225 TitleGlyph::~TitleGlyph()
00226 {
00227
00228 if(data) delete data;
00229 if(data_stroke) delete data_stroke;
00230 }
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242 GlyphPackage::GlyphPackage() : LoadPackage()
00243 {
00244 }
00245
00246 GlyphUnit::GlyphUnit(TitleMain *plugin, GlyphEngine *server)
00247 : LoadClient(server)
00248 {
00249 this->plugin = plugin;
00250 current_font = 0;
00251 freetype_library = 0;
00252 freetype_face = 0;
00253 }
00254
00255 GlyphUnit::~GlyphUnit()
00256 {
00257 if(freetype_library) FT_Done_FreeType(freetype_library);
00258 }
00259
00260 void GlyphUnit::process_package(LoadPackage *package)
00261 {
00262 GlyphPackage *pkg = (GlyphPackage*)package;
00263 TitleGlyph *glyph = pkg->glyph;
00264 int result = 0;
00265
00266 if(!freetype_library)
00267 {
00268 current_font = plugin->get_font();
00269
00270 if(plugin->load_freetype_face(freetype_library,
00271 freetype_face,
00272 current_font->path))
00273 {
00274 printf(_("GlyphUnit::process_package FT_New_Face failed.\n"));
00275 result = 1;
00276 }
00277 else
00278 {
00279 FT_Set_Pixel_Sizes(freetype_face, plugin->config.size, 0);
00280 }
00281 }
00282
00283 if(!result)
00284 {
00285 int gindex = FT_Get_Char_Index(freetype_face, glyph->char_code);
00286
00287
00288
00289 if (gindex == 0)
00290 {
00291
00292 if (glyph->char_code != 10)
00293 printf(_("GlyphUnit::process_package FT_Load_Char failed - char: %i.\n"),
00294 glyph->char_code);
00295
00296 glyph->width = 8;
00297 glyph->height = 8;
00298 glyph->pitch = 8;
00299 glyph->left = 9;
00300 glyph->top = 9;
00301 glyph->freetype_index = 0;
00302 glyph->advance_w = 8;
00303 glyph->data = new VFrame(0,
00304 8,
00305 8,
00306 BC_A8,
00307 8);
00308 glyph->data->clear_frame();
00309 glyph->data_stroke = 0;
00310
00311
00312
00313
00314 if (plugin->config.stroke_width >= ZERO &&
00315 (plugin->config.style & FONT_OUTLINE))
00316 {
00317 glyph->data_stroke = new VFrame(0,
00318 8,
00319 8,
00320 BC_A8,
00321 8);
00322 glyph->data_stroke->clear_frame();
00323 }
00324
00325
00326
00327 }
00328 else
00329
00330 if (plugin->config.stroke_width < ZERO ||
00331 !(plugin->config.style & FONT_OUTLINE))
00332 {
00333 FT_Glyph glyph_image;
00334 FT_BBox bbox;
00335 FT_Bitmap bm;
00336 FT_Load_Glyph(freetype_face, gindex, FT_LOAD_DEFAULT);
00337 FT_Get_Glyph(freetype_face->glyph, &glyph_image);
00338 FT_Outline_Get_BBox(&((FT_OutlineGlyph) glyph_image)->outline, &bbox);
00339
00340
00341
00342 FT_Outline_Translate(&((FT_OutlineGlyph) glyph_image)->outline,
00343 - bbox.xMin,
00344 - bbox.yMin);
00345 glyph->width = bm.width = ((bbox.xMax - bbox.xMin + 63) >> 6);
00346 glyph->height = bm.rows = ((bbox.yMax - bbox.yMin + 63) >> 6);
00347 glyph->pitch = bm.pitch = bm.width;
00348 bm.pixel_mode = FT_PIXEL_MODE_GRAY;
00349 bm.num_grays = 256;
00350 glyph->left = (bbox.xMin + 31) >> 6;
00351 if (glyph->left < 0) glyph->left = 0;
00352 glyph->top = (bbox.yMax + 31) >> 6;
00353 glyph->freetype_index = gindex;
00354 glyph->advance_w = ((freetype_face->glyph->advance.x + 31) >> 6);
00355
00356
00357
00358 glyph->data = new VFrame(0,
00359 glyph->width,
00360 glyph->height,
00361 BC_A8,
00362 glyph->pitch);
00363 glyph->data->clear_frame();
00364 bm.buffer = glyph->data->get_data();
00365 FT_Outline_Get_Bitmap( freetype_library,
00366 &((FT_OutlineGlyph) glyph_image)->outline,
00367 &bm);
00368 FT_Done_Glyph(glyph_image);
00369 }
00370 else
00371
00372 {
00373 FT_Glyph glyph_image;
00374 int no_outline = 0;
00375 FT_Stroker stroker;
00376 FT_Outline outline;
00377 FT_Bitmap bm;
00378 FT_BBox bbox;
00379 FT_UInt npoints, ncontours;
00380
00381 typedef struct FT_LibraryRec_
00382 {
00383 FT_Memory memory;
00384 } FT_LibraryRec;
00385
00386 FT_Load_Glyph(freetype_face, gindex, FT_LOAD_DEFAULT);
00387 FT_Get_Glyph(freetype_face->glyph, &glyph_image);
00388
00389
00390 FT_Outline_Get_BBox(&((FT_OutlineGlyph) glyph_image)->outline, &bbox);
00391 if (bbox.xMin == 0 && bbox.xMax == 0 && bbox.yMin ==0 && bbox.yMax == 0)
00392 {
00393 FT_Done_Glyph(glyph_image);
00394 glyph->data = new VFrame(0, 0, BC_A8,0);
00395 glyph->data_stroke = new VFrame(0, 0, BC_A8,0);;
00396 glyph->width=0;
00397 glyph->height=0;
00398 glyph->top=0;
00399 glyph->left=0;
00400 glyph->advance_w =((int)(freetype_face->glyph->advance.x +
00401 plugin->config.stroke_width * 64)) >> 6;
00402 return;
00403 }
00404 #if FREETYPE_MAJOR > 2 || (FREETYPE_MAJOR == 2 && FREETYPE_MINOR >= 2)
00405 FT_Stroker_New(freetype_library, &stroker);
00406 #else
00407 FT_Stroker_New(((FT_LibraryRec *)freetype_library)->memory, &stroker);
00408 #endif
00409 FT_Stroker_Set(stroker, (int)(plugin->config.stroke_width * 64), FT_STROKER_LINECAP_ROUND, FT_STROKER_LINEJOIN_ROUND, 0);
00410 FT_Stroker_ParseOutline(stroker, &((FT_OutlineGlyph) glyph_image)->outline,1);
00411 FT_Stroker_GetCounts(stroker,&npoints, &ncontours);
00412 if (npoints ==0 && ncontours == 0)
00413 {
00414
00415 FT_Stroker_Done(stroker);
00416 FT_Done_Glyph(glyph_image);
00417 glyph->data = new VFrame(0, 0, BC_A8,0);
00418 glyph->data_stroke = new VFrame(0, 0, BC_A8,0);;
00419 glyph->width=0;
00420 glyph->height=0;
00421 glyph->top=0;
00422 glyph->left=0;
00423 glyph->advance_w =((int)(freetype_face->glyph->advance.x +
00424 plugin->config.stroke_width * 64)) >> 6;
00425 return;
00426 };
00427
00428 FT_Outline_New(freetype_library, npoints, ncontours, &outline);
00429 outline.n_points=0;
00430 outline.n_contours=0;
00431 FT_Stroker_Export (stroker, &outline);
00432 FT_Outline_Get_BBox(&outline, &bbox);
00433
00434 FT_Outline_Translate(&outline,
00435 - bbox.xMin,
00436 - bbox.yMin);
00437
00438 FT_Outline_Translate(&((FT_OutlineGlyph) glyph_image)->outline,
00439 - bbox.xMin,
00440 - bbox.yMin + (int)(plugin->config.stroke_width*32));
00441
00442
00443
00444
00445 glyph->width = bm.width = ((bbox.xMax - bbox.xMin) >> 6)+1;
00446 glyph->height = bm.rows = ((bbox.yMax - bbox.yMin) >> 6) +1;
00447 glyph->pitch = bm.pitch = bm.width;
00448 bm.pixel_mode = FT_PIXEL_MODE_GRAY;
00449 bm.num_grays = 256;
00450 glyph->left = (bbox.xMin + 31) >> 6;
00451 if (glyph->left < 0) glyph->left = 0;
00452 glyph->top = (bbox.yMax + 31) >> 6;
00453 glyph->freetype_index = gindex;
00454 int real_advance = ((int)ceil((float)freetype_face->glyph->advance.x +
00455 plugin->config.stroke_width * 64) >> 6);
00456 glyph->advance_w = glyph->width + glyph->left;
00457 if (real_advance > glyph->advance_w)
00458 glyph->advance_w = real_advance;
00459
00460
00461
00462
00463
00464 glyph->data = new VFrame(0,
00465 glyph->width,
00466 glyph->height,
00467 BC_A8,
00468 glyph->pitch);
00469 glyph->data_stroke = new VFrame(0,
00470 glyph->width,
00471 glyph->height,
00472 BC_A8,
00473 glyph->pitch);
00474 glyph->data->clear_frame();
00475 glyph->data_stroke->clear_frame();
00476
00477 bm.buffer=glyph->data->get_data();
00478 FT_Outline_Get_Bitmap( freetype_library,
00479 &((FT_OutlineGlyph) glyph_image)->outline,
00480 &bm);
00481 bm.buffer=glyph->data_stroke->get_data();
00482 FT_Outline_Get_Bitmap( freetype_library,
00483 &outline,
00484 &bm);
00485 FT_Outline_Done(freetype_library,&outline);
00486 FT_Stroker_Done(stroker);
00487 FT_Done_Glyph(glyph_image);
00488
00489
00490 }
00491 }
00492 }
00493
00494 GlyphEngine::GlyphEngine(TitleMain *plugin, int cpus)
00495 : LoadServer(cpus, cpus)
00496 {
00497 this->plugin = plugin;
00498 }
00499 void GlyphEngine::init_packages()
00500 {
00501 int current_package = 0;
00502 for(int i = 0; i < plugin->glyphs.total; i++)
00503 {
00504 if(!plugin->glyphs.values[i]->data)
00505 {
00506 GlyphPackage *pkg = (GlyphPackage*)get_package(current_package++);
00507 pkg->glyph = plugin->glyphs.values[i];
00508 }
00509 }
00510 }
00511 LoadClient* GlyphEngine::new_client()
00512 {
00513 return new GlyphUnit(plugin, this);
00514 }
00515 LoadPackage* GlyphEngine::new_package()
00516 {
00517 return new GlyphPackage;
00518 }
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533 TitlePackage::TitlePackage()
00534 : LoadPackage()
00535 {
00536 }
00537
00538
00539 TitleUnit::TitleUnit(TitleMain *plugin, TitleEngine *server)
00540 : LoadClient(server)
00541 {
00542 this->plugin = plugin;
00543 }
00544
00545 void TitleUnit::draw_glyph(VFrame *output, TitleGlyph *glyph, int x, int y)
00546 {
00547 int glyph_w = glyph->data->get_w();
00548 int glyph_h = glyph->data->get_h();
00549 int output_w = output->get_w();
00550 int output_h = output->get_h();
00551 unsigned char **in_rows = glyph->data->get_rows();
00552 unsigned char **out_rows = output->get_rows();
00553
00554
00555 for(int in_y = 0; in_y < glyph_h; in_y++)
00556 {
00557
00558 int y_out = y + plugin->get_char_height() + in_y - glyph->top;
00559
00560
00561 if(y_out >= 0 && y_out < output_h)
00562 {
00563 unsigned char *out_row = out_rows[y_out];
00564 unsigned char *in_row = in_rows[in_y];
00565 for(int in_x = 0; in_x < glyph_w; in_x++)
00566 {
00567 int x_out = x + glyph->left + in_x;
00568 if(x_out >= 0 && x_out < output_w)
00569 {
00570 if(in_row[in_x] > 0)
00571 out_row[x_out] = in_row[in_x];
00572
00573 }
00574 }
00575 }
00576 }
00577 }
00578
00579
00580 void TitleUnit::process_package(LoadPackage *package)
00581 {
00582 TitlePackage *pkg = (TitlePackage*)package;
00583
00584 if(pkg->c != 0xa)
00585 {
00586 for(int i = 0; i < plugin->glyphs.total; i++)
00587 {
00588 TitleGlyph *glyph = plugin->glyphs.values[i];
00589 if(glyph->c == pkg->c)
00590 {
00591 draw_glyph(plugin->text_mask, glyph, pkg->x, pkg->y);
00592 if(plugin->config.stroke_width >= ZERO &&
00593 (plugin->config.style & FONT_OUTLINE))
00594 {
00595 VFrame *tmp = glyph->data;
00596 glyph->data = glyph->data_stroke;
00597 draw_glyph(plugin->text_mask_stroke, glyph, pkg->x, pkg->y);
00598 glyph->data = tmp;
00599 }
00600 break;
00601 }
00602 }
00603 }
00604 }
00605
00606 TitleEngine::TitleEngine(TitleMain *plugin, int cpus)
00607 : LoadServer(cpus, cpus)
00608 {
00609 this->plugin = plugin;
00610 }
00611
00612 void TitleEngine::init_packages()
00613 {
00614
00615 int visible_y1 = plugin->visible_row1 * plugin->get_char_height();
00616
00617 int current_package = 0;
00618 for(int i = plugin->visible_char1; i < plugin->visible_char2; i++)
00619 {
00620 title_char_position_t *char_position = plugin->char_positions + i;
00621 TitlePackage *pkg = (TitlePackage*)get_package(current_package);
00622
00623 pkg->x = char_position->x;
00624
00625 pkg->y = char_position->y - visible_y1;
00626
00627 pkg->c = plugin->config.text[i];
00628
00629 current_package++;
00630 }
00631 }
00632
00633 LoadClient* TitleEngine::new_client()
00634 {
00635 return new TitleUnit(plugin, this);
00636 }
00637
00638 LoadPackage* TitleEngine::new_package()
00639 {
00640 return new TitlePackage;
00641 }
00642
00643
00644
00645
00646
00647
00648
00649
00650
00651
00652
00653 TitleTranslatePackage::TitleTranslatePackage()
00654 : LoadPackage()
00655 {
00656 }
00657
00658
00659 TitleTranslateUnit::TitleTranslateUnit(TitleMain *plugin, TitleTranslate *server)
00660 : LoadClient(server)
00661 {
00662 this->plugin = plugin;
00663 }
00664
00665
00666
00667 #define TRANSLATE(type, max, components, r, g, b) \
00668 { \
00669 unsigned char **in_rows = plugin->text_mask->get_rows(); \
00670 type **out_rows = (type**)plugin->output->get_rows(); \
00671 \
00672 for(int i = pkg->y1; i < pkg->y2; i++) \
00673 { \
00674 if(i + server->out_y1_int >= 0 && \
00675 i + server->out_y1_int < server->output_h) \
00676 { \
00677 int in_y1, in_y2; \
00678 float y_fraction1, y_fraction2; \
00679 float y_output_fraction; \
00680 in_y1 = server->y_table[i].in_x1; \
00681 in_y2 = server->y_table[i].in_x2; \
00682 y_fraction1 = server->y_table[i].in_fraction1; \
00683 y_fraction2 = server->y_table[i].in_fraction2; \
00684 y_output_fraction = server->y_table[i].output_fraction; \
00685 unsigned char *in_row1 = in_rows[in_y1]; \
00686 unsigned char *in_row2 = in_rows[in_y2]; \
00687 type *out_row = out_rows[i + server->out_y1_int]; \
00688 \
00689 for(int j = server->out_x1_int; j < server->out_x2_int; j++) \
00690 { \
00691 if(j >= 0 && j < server->output_w) \
00692 { \
00693 int in_x1; \
00694 int in_x2; \
00695 float x_fraction1; \
00696 float x_fraction2; \
00697 float x_output_fraction; \
00698 in_x1 = \
00699 server->x_table[j - server->out_x1_int].in_x1; \
00700 in_x2 = \
00701 server->x_table[j - server->out_x1_int].in_x2; \
00702 x_fraction1 = \
00703 server->x_table[j - server->out_x1_int].in_fraction1; \
00704 x_fraction2 = \
00705 server->x_table[j - server->out_x1_int].in_fraction2; \
00706 x_output_fraction = \
00707 server->x_table[j - server->out_x1_int].output_fraction; \
00708 \
00709 float fraction1 = x_fraction1 * y_fraction1; \
00710 float fraction2 = x_fraction2 * y_fraction1; \
00711 float fraction3 = x_fraction1 * y_fraction2; \
00712 float fraction4 = x_fraction2 * y_fraction2; \
00713 int input = (int)(in_row1[in_x1] * fraction1 + \
00714 in_row1[in_x2] * fraction2 + \
00715 in_row2[in_x1] * fraction3 + \
00716 in_row2[in_x2] * fraction4 + 0.5); \
00717 input *= plugin->alpha; \
00718 \
00719 input >>= 8; \
00720 \
00721 int anti_input = 0xff - input; \
00722 if(components == 4) \
00723 { \
00724 out_row[j * components + 0] = \
00725 (r * input + out_row[j * components + 0] * anti_input) / 0xff; \
00726 out_row[j * components + 1] = \
00727 (g * input + out_row[j * components + 1] * anti_input) / 0xff; \
00728 out_row[j * components + 2] = \
00729 (b * input + out_row[j * components + 2] * anti_input) / 0xff; \
00730 if(max == 0xffff) \
00731 out_row[j * components + 3] = \
00732 MAX((input << 8) | input, out_row[j * components + 3]); \
00733 else \
00734 out_row[j * components + 3] = \
00735 MAX(input, out_row[j * components + 3]); \
00736 } \
00737 else \
00738 { \
00739 out_row[j * components + 0] = \
00740 (r * input + out_row[j * components + 0] * anti_input) / 0xff; \
00741 out_row[j * components + 1] = \
00742 (g * input + out_row[j * components + 1] * anti_input) / 0xff; \
00743 out_row[j * components + 2] = \
00744 (b * input + out_row[j * components + 2] * anti_input) / 0xff; \
00745 } \
00746 } \
00747 } \
00748 } \
00749 } \
00750 }
00751
00752
00753 #define TRANSLATEA(type, max, components, r, g, b) \
00754 { \
00755 unsigned char **in_rows = plugin->text_mask->get_rows(); \
00756 type **out_rows = (type**)plugin->output->get_rows(); \
00757 \
00758 for(int i = pkg->y1; i < pkg->y2; i++) \
00759 { \
00760 if(i + server->out_y1_int >= 0 && \
00761 i + server->out_y1_int < server->output_h) \
00762 { \
00763 unsigned char *in_row = in_rows[i]; \
00764 type *out_row = out_rows[i + server->out_y1_int]; \
00765 \
00766 for(int j = server->out_x1; j < server->out_x2_int; j++) \
00767 { \
00768 if(j >= 0 && \
00769 j < server->output_w) \
00770 { \
00771 int input = (int)(in_row[j - server->out_x1]); \
00772 \
00773 input *= plugin->alpha; \
00774 \
00775 input >>= 8; \
00776 \
00777 int anti_input = 0xff - input; \
00778 if(components == 4) \
00779 { \
00780 out_row[j * components + 0] = \
00781 (r * input + out_row[j * components + 0] * anti_input) / 0xff; \
00782 out_row[j * components + 1] = \
00783 (g * input + out_row[j * components + 1] * anti_input) / 0xff; \
00784 out_row[j * components + 2] = \
00785 (b * input + out_row[j * components + 2] * anti_input) / 0xff; \
00786 if(max == 0xffff) \
00787 out_row[j * components + 3] = \
00788 MAX((input << 8) | input, out_row[j * components + 3]); \
00789 else \
00790 out_row[j * components + 3] = \
00791 MAX(input, out_row[j * components + 3]); \
00792 } \
00793 else \
00794 { \
00795 out_row[j * components + 0] = \
00796 (r * input + out_row[j * components + 0] * anti_input) / 0xff; \
00797 out_row[j * components + 1] = \
00798 (g * input + out_row[j * components + 1] * anti_input) / 0xff; \
00799 out_row[j * components + 2] = \
00800 (b * input + out_row[j * components + 2] * anti_input) / 0xff; \
00801 } \
00802 } \
00803 } \
00804 } \
00805 } \
00806 }
00807
00808 static YUV yuv;
00809
00810 void TitleTranslateUnit::process_package(LoadPackage *package)
00811 {
00812 TitleTranslatePackage *pkg = (TitleTranslatePackage*)package;
00813 TitleTranslate *server = (TitleTranslate*)this->server;
00814 int r_in, g_in, b_in;
00815
00816
00817
00818 r_in = (plugin->config.color & 0xff0000) >> 16;
00819 g_in = (plugin->config.color & 0xff00) >> 8;
00820 b_in = plugin->config.color & 0xff;
00821 switch(plugin->output->get_color_model())
00822 {
00823 case BC_RGB888:
00824 {
00825 TRANSLATE(unsigned char, 0xff, 3, r_in, g_in, b_in);
00826 break;
00827 }
00828 case BC_RGB_FLOAT:
00829 {
00830 float r, g, b;
00831 r = (float)r_in / 0xff;
00832 g = (float)g_in / 0xff;
00833 b = (float)b_in / 0xff;
00834 TRANSLATE(float, 0xff, 3, r, g, b);
00835 break;
00836 }
00837 case BC_YUV888:
00838 {
00839 unsigned char y, u, v;
00840 yuv.rgb_to_yuv_8(r_in, g_in, b_in, y, u, v);
00841 TRANSLATE(unsigned char, 0xff, 3, y, u, v);
00842 break;
00843 }
00844 case BC_RGB161616:
00845 {
00846 uint16_t r, g, b;
00847 r = (r_in << 8) | r_in;
00848 g = (g_in << 8) | g_in;
00849 b = (b_in << 8) | b_in;
00850 TRANSLATE(uint16_t, 0xffff, 3, r, g, b);
00851 break;
00852 }
00853 case BC_YUV161616:
00854 {
00855 uint16_t y, u, v;
00856 yuv.rgb_to_yuv_16(
00857 (r_in << 8) | r_in,
00858 (g_in << 8) | g_in,
00859 (b_in << 8) | b_in,
00860 y,
00861 u,
00862 v);
00863 TRANSLATE(uint16_t, 0xffff, 3, y, u, v);
00864 break;
00865 }
00866 case BC_RGBA_FLOAT:
00867 {
00868 float r, g, b;
00869 r = (float)r_in / 0xff;
00870 g = (float)g_in / 0xff;
00871 b = (float)b_in / 0xff;
00872 TRANSLATE(float, 0xff, 4, r, g, b);
00873 break;
00874 }
00875 case BC_RGBA8888:
00876 {
00877 TRANSLATE(unsigned char, 0xff, 4, r_in, g_in, b_in);
00878 break;
00879 }
00880 case BC_YUVA8888:
00881 {
00882 unsigned char y, u, v;
00883 yuv.rgb_to_yuv_8(r_in, g_in, b_in, y, u, v);
00884 TRANSLATE(unsigned char, 0xff, 4, y, u, v);
00885 break;
00886 }
00887 case BC_RGBA16161616:
00888 {
00889 uint16_t r, g, b;
00890 r = (r_in << 8) | r_in;
00891 g = (g_in << 8) | g_in;
00892 b = (b_in << 8) | b_in;
00893 TRANSLATE(uint16_t, 0xffff, 4, r, g, b);
00894 break;
00895 }
00896 case BC_YUVA16161616:
00897 {
00898 uint16_t y, u, v;
00899 yuv.rgb_to_yuv_16(
00900 (r_in << 8) | r_in,
00901 (g_in << 8) | g_in,
00902 (b_in << 8) | b_in,
00903 y,
00904 u,
00905 v);
00906 TRANSLATE(uint16_t, 0xffff, 4, y, u, v);
00907 break;
00908 }
00909 }
00910
00911
00912 }
00913
00914
00915
00916
00917 TitleTranslate::TitleTranslate(TitleMain *plugin, int cpus)
00918 : LoadServer(1, 1)
00919 {
00920 this->plugin = plugin;
00921 x_table = y_table = 0;
00922 }
00923
00924 TitleTranslate::~TitleTranslate()
00925 {
00926 if(x_table) delete [] x_table;
00927 if(y_table) delete [] y_table;
00928 }
00929
00930 void TitleTranslate::init_packages()
00931 {
00932
00933
00934 if(x_table) delete [] x_table;
00935 if(y_table) delete [] y_table;
00936
00937
00938 output_w = plugin->output->get_w();
00939 output_h = plugin->output->get_h();
00940
00941
00942
00943 TranslateUnit::translation_array_f(x_table,
00944 plugin->text_x1,
00945 plugin->text_x1 + plugin->text_w,
00946 0,
00947 plugin->text_w,
00948 plugin->text_w,
00949 output_w,
00950 out_x1_int,
00951 out_x2_int);
00952
00953
00954 TranslateUnit::translation_array_f(y_table,
00955 plugin->mask_y1,
00956 plugin->mask_y1 + plugin->text_mask->get_h(),
00957 0,
00958 plugin->text_mask->get_h(),
00959 plugin->text_mask->get_h(),
00960 output_h,
00961 out_y1_int,
00962 out_y2_int);
00963
00964
00965
00966
00967 out_y1 = out_y1_int;
00968 out_y2 = out_y2_int;
00969 out_x1 = out_x1_int;
00970 out_x2 = out_x2_int;
00971 int increment = (out_y2 - out_y1) / get_total_packages() + 1;
00972
00973
00974
00975 for(int i = 0; i < get_total_packages(); i++)
00976 {
00977 TitleTranslatePackage *pkg = (TitleTranslatePackage*)get_package(i);
00978 pkg->y1 = i * increment;
00979 pkg->y2 = i * increment + increment;
00980 if(pkg->y1 > out_y2 - out_y1)
00981 pkg->y1 = out_y2 - out_y1;
00982 if(pkg->y2 > out_y2 - out_y1)
00983 pkg->y2 = out_y2 - out_y1;
00984 }
00985
00986 }
00987
00988 LoadClient* TitleTranslate::new_client()
00989 {
00990 return new TitleTranslateUnit(plugin, this);
00991 }
00992
00993 LoadPackage* TitleTranslate::new_package()