descratch again reworked + icons, add agingtv plugin params, add alias chkbox in...
[goodguy/history.git] / cinelerra-5.1 / plugins / titler / titler.C
index a3f2411bd98594b36bcf5d4ab5061a2a821f0270..9056bc19a9ec8fa333392729ba3f389d883b0ef2 100644 (file)
@@ -82,7 +82,7 @@ TitleConfig::TitleConfig()
 {
        strcpy(font, "fixed");
        strcpy(encoding, DEFAULT_ENCODING);
-       style = 0;
+       style = FONT_ALIAS;
        size = 24;
        color = BLACK;
        alpha = 0xff;
@@ -289,6 +289,17 @@ GlyphUnit::~GlyphUnit()
                FT_Done_FreeType(freetype_library);
 }
 
+static inline void to_mono(VFrame *data)
+{
+       if( !data ) return;
+       int w = data->get_w(), h = data->get_h();
+       uint8_t **rows = data->get_rows();
+       for( int y=0; y<h; ++y ) {
+               uint8_t *dp = rows[y];
+               for( int x=0; x<w; ++x,++dp ) *dp = *dp >= 0x80 ? 0xff : 0;
+       }
+}
+
 void GlyphUnit::process_package(LoadPackage *package)
 {
        GlyphPackage *pkg = (GlyphPackage*)package;
@@ -491,6 +502,11 @@ printf("GlyphUnit::process_package 1 glyph not found (%s) %04x, '%c'\n",
 
 //printf("GlyphUnit::process_package 2\n");
                }
+
+               if( !(glyph->style & FONT_ALIAS) ) {
+                       to_mono(glyph->data);
+                       to_mono(glyph->data_stroke);
+               }
        }
 }
 
@@ -841,6 +857,10 @@ TitleCurFixed::TitleCurFixed(TitleParser *parser, TitleMain *plugin)
  : TitleStack<int>(parser, 0)
 {
 }
+TitleCurAlias::TitleCurAlias(TitleParser *parser, TitleMain *plugin)
+ : TitleStack<int>(parser, (plugin->config.style & FONT_ALIAS) ? 1 : 0)
+{
+}
 TitleCurSuper::TitleCurSuper(TitleParser *parser, TitleMain *plugin)
  : TitleStack<int>(parser, 0)
 {
@@ -859,6 +879,7 @@ TitleParser::TitleParser(TitleMain *plugin)
    cur_under(this, plugin),
    cur_blink(this, plugin),
    cur_fixed(this, plugin),
+   cur_alias(this, plugin),
    cur_super(this, plugin)
 {
        bfr = out = plugin->config.wtext;
@@ -1578,6 +1599,14 @@ int TitleCurFixed::set(const char *txt)
        return 0;
 }
 
+int TitleCurAlias::set(const char *txt)
+{
+       int alias = !*txt ? 1 : strtol(txt,(char **)&txt,0);
+       if( *txt ) return 1;
+       push(alias);
+       return 0;
+}
+
 int TitleCurSuper::set(const char *txt)
 {
        int super = !*txt ? 1 : strtol(txt,(char **)&txt,0);
@@ -1611,6 +1640,7 @@ int TitleParser::set_attributes(int ret)
         if( !strcmp(id,KW_UL) )     return ret>1 ? cur_under.unset(text)  : cur_under.set(text);
         if( !strcmp(id,KW_BLINK) )  return ret>1 ? cur_blink.unset(text)  : cur_blink.set(text);
         if( !strcmp(id,KW_FIXED) )  return ret>1 ? cur_fixed.unset(text)  : cur_fixed.set(text);
+        if( !strcmp(id,KW_ALIAS) )  return ret>1 ? cur_alias.unset(text)  : cur_alias.set(text);
         if( !strcmp(id,KW_SUP) )    return ret>1 ? cur_super.unset(text)  : cur_super.set(text);
        return 1;
 }
@@ -1644,6 +1674,8 @@ void TitleMain::load_glyphs()
                if( cur_bold ) cur_style |= BC_FONT_BOLD;
                int cur_italic  = wchrs.cur_italic;
                if( cur_italic ) cur_style |= BC_FONT_ITALIC;
+               int cur_alias  = wchrs.cur_alias;
+               if( cur_alias ) cur_style |= FONT_ALIAS;
                int cur_super = wchrs.cur_super;
                if( cur_super ) cur_size /= 2;
                int exists = 0;
@@ -1758,6 +1790,8 @@ int TitleMain::get_text()
                int cur_style = 0;
                int cur_bold  = wchrs.cur_bold;
                if( cur_bold ) cur_style |= BC_FONT_BOLD;
+               int cur_alias   = wchrs.cur_alias;
+               if( cur_alias ) cur_style |= FONT_ALIAS;
                int cur_italic  = wchrs.cur_italic;
                if( cur_italic ) cur_style |= BC_FONT_ITALIC;
                short nx = cur_nudge >> 16, ny = cur_nudge;
@@ -2188,7 +2222,7 @@ TitleTranslateUnit::TitleTranslateUnit(TitleMain *plugin, TitleTranslate *server
 
 #define TRANSLATE(type, max, comps, ofs) { \
        type **out_rows = (type**)output->get_rows(); \
-       float fs = 1./(256.-max); \
+       float fr = 1./(256.-max), fs = max/255.; \
        float r = max > 1 ? 0.5 : 0; \
        for( int y=y1; y<y2; ++y ) { \
                float fy = y+yofs;  int iy = fy; \
@@ -2205,8 +2239,8 @@ TitleTranslateUnit::TitleTranslateUnit(TitleMain *plugin, TitleTranslate *server
                        uint8_t *cp10 = in_row1 + i0, *cp11 = in_row1 + i1; \
                        float a00 = yf0 * xf0 * cp00[3], a01 = yf0 * xf1 * cp01[3]; \
                        float a10 = yf1 * xf0 * cp10[3], a11 = yf1 * xf1 * cp11[3]; \
-                       float fa = a00 + a01 + a10 + a11;  if( !fa ) continue;  fa *= fs; \
-                       type in_a = fa + r;  float s = 1./fa; \
+                       float fa = a00 + a01 + a10 + a11;  if( !fa ) continue;  \
+                       type in_a = fa*fr + r;  float s = fs/fa; \
                        type in_r = (cp00[0]*a00 + cp01[0]*a01 + cp10[0]*a10 + cp11[0]*a11)*s + r; \
                        type in_g = (cp00[1]*a00 + cp01[1]*a01 + cp10[1]*a10 + cp11[1]*a11)*s + r; \
                        type in_b = (cp00[2]*a00 + cp01[2]*a01 + cp10[2]*a10 + cp11[2]*a11)*s + r; \