-
-TitleTranslatePackage::TitleTranslatePackage()
- : LoadPackage()
-{
- y1 = y2 = 0;
-}
-
-
-TitleTranslateUnit::TitleTranslateUnit(TitleMain *plugin, TitleTranslate *server)
- : LoadClient(server)
-{
- this->plugin = plugin;
-}
-
-void TitleTranslate::run_packages()
-{
-// Generate scaling tables
- delete [] x_table; x_table = 0;
- delete [] y_table; y_table = 0;
-
- float in_w = xlat_mask->get_w();
- float in_h = xlat_mask->get_h();
- float ix1 = 0, ix2 = ix1 + in_w;
- float iy1 = 0, iy2 = iy1 + in_h;
-
- float out_w = plugin->output->get_w();
- float out_h = plugin->output->get_h();
- float x1 = plugin->title_x, x2 = x1 + plugin->title_w;
- float y1 = plugin->title_y, y2 = y1 + plugin->title_h;
- bclamp(x1, 0, out_w); bclamp(y1, 0, out_h);
- bclamp(x2, 0, out_w); bclamp(y2, 0, out_h);
-
- float ox1 = plugin->title_x + plugin->text_x - plugin->text_x1 + plugin->mask_x1, ox2 = ox1 + in_w;
- float oy1 = plugin->title_y + plugin->text_y - plugin->text_y1 + plugin->mask_y1, oy2 = oy1 + in_h;
- if( ox1 < x1 ) { ix1 -= (ox1-x1); ox1 = x1; }
- if( oy1 < y1 ) { iy1 -= (oy1-y1); oy1 = y1; }
- if( ox2 > x2 ) { ix2 -= (ox2-x2); ox2 = x2; }
- if( oy2 > y2 ) { iy2 -= (oy2-x2); oy2 = y2; }
-#if 0
-printf("TitleTranslate text txy=%7.2f,%-7.2f\n"
- " mxy1=%7d,%-7d mxy2=%7d,%-7d\n"
- " xy1=%7.2f,%-7.2f xy2=%7.2f,%-7.2f\n"
- " ixy1=%7.2f,%-7.2f ixy2=%7.2f,%-7.2f\n"
- " oxy1=%7.2f,%-7.2f oxy2=%7.2f,%-7.2f\n",
- plugin->text_x, plugin->text_y,
- plugin->mask_x1, plugin->mask_y1, plugin->mask_x2, plugin->mask_y2,
- x1,y1, x2,y2, ix1,iy1, ix2,iy2, ox1,oy1, ox2,oy2);
-#endif
- out_x1 = out_x2 = out_y1 = out_y2 = 0;
- TitleTranslateUnit::translation_array_f(x_table,
- ix1, ix2, in_w, ox1, ox2, out_w, out_x1, out_x2);
- TitleTranslateUnit::translation_array_f(y_table,
- iy1, iy2, in_h, oy1, oy2, out_h, out_y1, out_y2);
-
- process_packages();
-}
-
-
-
-#define TRANSLATE(type, max, components, ofs) { \
- unsigned char **in_rows = server->xlat_mask->get_rows(); \
- type **out_rows = (type**)plugin->output->get_rows(); \
- \
- for( int y=pkg->y1; y<pkg->y2; ++y ) { \
- int in_y1 = server->y_table[y].in_x1; \
- int in_y2 = server->y_table[y].in_x2; \
- float y_f1 = server->y_table[y].in_fraction1; \
- float y_f2 = server->y_table[y].in_fraction2; \
- unsigned char *in_row1 = in_rows[in_y1]; \
- unsigned char *in_row2 = in_rows[in_y2]; \
- type *out_row = out_rows[y + server->out_y1]; \
- for( int i=0,x=server->out_x1; x<server->out_x2; ++i,++x ) { \
- int in_x1 = 4*server->x_table[i].in_x1; \
- int in_x2 = 4*server->x_table[i].in_x2; \
- float x_f1 = server->x_table[i].in_fraction1; \
- float x_f2 = server->x_table[i].in_fraction2; \
- float f11 = x_f1 * y_f1 / (256.f-max); \
- float f12 = x_f2 * y_f1 / (256.f-max); \
- float f21 = x_f1 * y_f2 / (256.f-max); \
- float f22 = x_f2 * y_f2 / (256.f-max); \
- type input_r = (type)( \
- in_row1[in_x1 + 0] * f11 + in_row1[in_x2 + 0] * f12 + \
- in_row2[in_x1 + 0] * f21 + in_row2[in_x2 + 0] * f22 ); \
- type input_g = (type)( \
- in_row1[in_x1 + 1] * f11 + in_row1[in_x2 + 1] * f12 + \
- in_row2[in_x1 + 1] * f21 + in_row2[in_x2 + 1] * f22 ); \
- type input_b = (type)( \
- in_row1[in_x1 + 2] * f11 + in_row1[in_x2 + 2] * f12 + \
- in_row2[in_x1 + 2] * f21 + in_row2[in_x2 + 2] * f22 ); \
- type input_a = (type)( \
- in_row1[in_x1 + 3] * f11 + in_row1[in_x2 + 3] * f12 + \
- in_row2[in_x1 + 3] * f21 + in_row2[in_x2 + 3] * f22 ); \
- input_a = input_a * plugin->fade; \
- if( components == 4 ) { \
- type transparency = out_row[x * components + 3] * (max - input_a) / max; \
- out_row[x * components + 0] = (input_r * input_a + \
- out_row[x * components + 0] * transparency) / max; \
- out_row[x * components + 1] = ((input_g-ofs) * input_a + \
- (out_row[x * components + 1]-ofs) * transparency) / max + ofs; \
- out_row[x * components + 2] = ((input_b-ofs) * input_a + \
- (out_row[x * components + 2]-ofs) * transparency) / max + ofs; \
- out_row[x * components + 3] = MAX(input_a, out_row[x * components + 3]); \
- } \
- else { \
- type transparency = max - input_a; \
- out_row[x * components + 0] = (input_r * input_a + \
- out_row[x * components + 0] * transparency) / max; \
- out_row[x * components + 1] = ((input_g-ofs) * input_a + \
- (out_row[x * components + 1]-ofs) * transparency) / max + ofs; \
- out_row[x * components + 2] = ((input_b-ofs) * input_a + \
- (out_row[x * components + 2]-ofs) * transparency) / max + ofs; \
- } \
- } \
- } \
-}
-
-
-void TitleTranslateUnit::process_package(LoadPackage *package)
-{
- TitleTranslatePackage *pkg = (TitleTranslatePackage*)package;
- TitleTranslate *server = (TitleTranslate*)this->server;
-
- switch( plugin->output->get_color_model() ) {
- case BC_RGB888: TRANSLATE(unsigned char, 0xff, 3, 0); break;
- case BC_RGB_FLOAT: TRANSLATE(float, 1.0, 3, 0); break;
- case BC_YUV888: TRANSLATE(unsigned char, 0xff, 3, 0x80); break;
- case BC_RGBA_FLOAT: TRANSLATE(float, 1.0, 4, 0); break;
- case BC_RGBA8888: TRANSLATE(unsigned char, 0xff, 4, 0); break;
- case BC_YUVA8888: TRANSLATE(unsigned char, 0xff, 4, 0x80); break;
- }
-//printf("TitleTranslateUnit::process_package 5\n");
-}
-
-
-TitleTranslate::TitleTranslate(TitleMain *plugin, int cpus)
- : LoadServer(cpus, cpus)
-{
- this->plugin = plugin;
- x_table = 0;
- y_table = 0;
- out_x1 = out_x2 = 0;
- out_y1 = out_y2 = 0;
-}
-
-TitleTranslate::~TitleTranslate()
-{
- delete [] x_table;
- delete [] y_table;
-}
-
-void TitleTranslate::init_packages()
-{
- int out_h = out_y2 - out_y1;
- int py1 = 0, py2 = 0;
- int pkgs = get_total_packages();
- for( int i=0; i<pkgs; py1=py2 ) {
- TitleTranslatePackage *pkg = (TitleTranslatePackage*)get_package(i);
- py2 = (++i*out_h) / pkgs;
- pkg->y1 = py1; pkg->y2 = py2;
- }
-//printf("TitleTranslate::init_packages 2\n");
-}
-
-LoadClient* TitleTranslate::new_client()
-{
- return new TitleTranslateUnit(plugin, this);
-}
-
-LoadPackage* TitleTranslate::new_package()
-{
- return new TitleTranslatePackage;
-}
-