Changeset 223ebac60de34e1d82cee9a08e9aa041bf3e694c

Show
Ignore:
Timestamp:
20/02/05 17:05:39 (4 years ago)
Author:
Mark Moriarty <markfm@videolan.org>
git-committer:
Mark Moriarty <markfm@videolan.org> 1108915539 +0000
git-parent:

[20f007d0e630028cc15b949454515cf74d89363c]

git-author:
Mark Moriarty <markfm@videolan.org> 1108915539 +0000
Message:

freetype.c Change opacity to 0...255, add --freetype-color hex_RGB shortcut

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/misc/freetype.c

    r869578a r223ebac  
    8383    "If set to something different than 0 this option will override the " \ 
    8484    "relative font size " ) 
    85 #define OPACITY_TEXT N_("Opacity, 0..100%") 
     85#define OPACITY_TEXT N_("Opacity, 0..255") 
    8686#define OPACITY_LONGTEXT N_("The opacity (inverse of transparency) of overlay text. " \ 
    87     "0 = totally transparent, 100 = totally opaque. " ) 
     87    "0 = totally transparent, 255 = totally opaque. " ) 
     88#define COLOR_TEXT N_("Color, RGB, 0x000000 - 0xFFFFFF") 
     89#define COLOR_LONGTEXT N_("The color of overlay text. 1 byte for each color, hexadecimal." \ 
     90    "#000000 = all colors off, 0xFF0000 = just Red, 0xFFFFFF = all color on [White]" ) 
    8891#define FONTSIZER_TEXT N_("Font size") 
    8992#define FONTSIZER_LONGTEXT N_("The size of the fonts used by the osd module" ) 
     
    102105    add_integer( "freetype-fontsize", 0, NULL, FONTSIZE_TEXT, 
    103106                 FONTSIZE_LONGTEXT, VLC_TRUE ); 
    104     add_integer( "freetype-opacity", 100, NULL, OPACITY_TEXT, 
     107    add_integer( "freetype-opacity", 255, NULL, OPACITY_TEXT, 
    105108                 OPACITY_LONGTEXT, VLC_TRUE ); 
     109    add_integer( "freetype-color", 0xFFFFFF, NULL, COLOR_TEXT, 
     110                 COLOR_LONGTEXT, VLC_TRUE ); 
    106111    add_integer( "freetype-rel-fontsize", 16, NULL, FONTSIZER_TEXT, 
    107112                 FONTSIZER_LONGTEXT, VLC_FALSE ); 
     
    137142}; 
    138143 
    139 static void Render    ( filter_t *, subpicture_t *, subpicture_data_t * ); 
     144static void Render    ( filter_t *, subpicture_t *, subpicture_data_t *, uint8_t, 
     145                        uint8_t, uint8_t, uint8_t ); 
    140146static void FreeString( subpicture_data_t * ); 
    141147static void FreeLine( line_desc_t * ); 
     
    152158    FT_Face        p_face;      /* handle to face object */ 
    153159    vlc_bool_t     i_use_kerning; 
    154     int            i_opacity;   /* default is opaque */ 
     160    uint8_t        i_opacity;    
     161    uint8_t        i_red, i_green, i_blue; /* color components */ 
    155162    uint8_t        pi_gamma[256]; 
    156163}; 
     
    179186    p_sys->p_face = 0; 
    180187    p_sys->p_library = 0; 
    181     p_sys->i_opacity = 100; /* default to fully opaque */ 
     188    /* default to opaque letters, white (all colors set to 255): */ 
     189    p_sys->i_opacity = 255; 
     190    p_sys->i_red = 255; 
     191    p_sys->i_green = 255; 
     192    p_sys->i_blue = 255; 
    182193 
    183194    for( i = 0; i < 256; i++ ) 
     
    193204                VLC_VAR_INTEGER | VLC_VAR_DOINHERIT ); 
    194205    var_Create( p_filter, "freetype-opacity", 
     206                VLC_VAR_INTEGER | VLC_VAR_DOINHERIT ); 
     207    var_Create( p_filter, "freetype-color", 
    195208                VLC_VAR_INTEGER | VLC_VAR_DOINHERIT ); 
    196209 
     
    245258    if( val.i_int ) 
    246259    { 
    247         if ( ( val.i_int > -1 ) && ( val.i_int < 101 ) )  /* valid range 0 to 100% */ 
     260        if ( ( val.i_int > -1 ) && ( val.i_int < 256 ) )  /* valid range 0 to 255 */ 
    248261        { 
    249262           p_sys->i_opacity = val.i_int; 
    250263        } 
    251         else msg_Warn(p_filter, "Invalid freetype opacity specified, using 100%");         
    252     } 
     264        else msg_Warn(p_filter, "Invalid freetype opacity specified, using 255");         
     265    } 
     266    var_Get( p_filter, "freetype-color", &val ); 
     267    if( val.i_int ) 
     268    { 
     269        if ( ( val.i_int > -1 ) && ( val.i_int < 0xFFFFFF ) )  /* valid range */ 
     270        { 
     271           p_sys->i_blue = val.i_int & 0x000000FF; 
     272           p_sys->i_green = (val.i_int & 0x0000FF00)/256; 
     273           p_sys->i_red = (val.i_int & 0x00FF0000)/(256*256); 
     274        } 
     275        else msg_Warn(p_filter, "Invalid freetype color specified, using white [0xFFFFFF]");         
     276    } 
     277     
    253278    var_Get( p_filter, "freetype-fontsize", &val ); 
    254279    if( val.i_int ) 
     
    308333 *****************************************************************************/ 
    309334static void Render( filter_t *p_filter, subpicture_t *p_spu, 
    310                     subpicture_data_t *p_string ) 
     335                    subpicture_data_t *p_string, uint8_t opacity,  
     336                    uint8_t red, uint8_t green, uint8_t blue ) 
    311337{ 
    312338    filter_sys_t *p_sys = p_filter->p_sys; 
     
    315341    video_format_t fmt; 
    316342    int i, x, y, i_pitch; 
     343    uint8_t i_y, i_u, i_v;  /* YUV values, derived from incoming RGB */ 
     344     
     345    /* calculate text color components: */ 
     346    i_y = (uint8_t) (0.257 * red) + (0.504 * green) + (0.098 * blue) + 16; 
     347    i_u = (uint8_t) -(0.148 * red) - (0.291 * green) + (0.439 * blue) + 128; 
     348    i_v = (uint8_t) (0.439 * red) - (0.368 * green) - (0.071 * blue) + 128; 
    317349 
    318350    /* Create a new subpicture region */ 
     
    344376 
    345377#define pi_gamma p_sys->pi_gamma 
    346 #define opacity  p_sys->i_opacity 
     378/* #define opacity  p_sys->i_opacity */ 
    347379 
    348380    for( p_line = p_string->p_lines; p_line != NULL; p_line = p_line->p_next ) 
     
    373405                    i_offset -= i_pitch; 
    374406                    p_a[i_offset + x] = ((uint16_t)p_a[i_offset + x] + 
    375                       pi_gamma[p_glyph->bitmap.buffer[i_bitmap_offset]])*opacity/200
     407                      pi_gamma[p_glyph->bitmap.buffer[i_bitmap_offset]])*opacity/512
    376408                    i_offset += i_pitch; x--; 
    377409                    p_a[i_offset + x] = ((uint16_t)p_a[i_offset + x] + 
    378                       pi_gamma[p_glyph->bitmap.buffer[i_bitmap_offset]])*opacity/200
     410                      pi_gamma[p_glyph->bitmap.buffer[i_bitmap_offset]])*opacity/512
    379411                    x += 2; 
    380412                    p_a[i_offset + x] = ((uint16_t)p_a[i_offset + x] + 
    381                       pi_gamma[p_glyph->bitmap.buffer[i_bitmap_offset]])*opacity/200
     413                      pi_gamma[p_glyph->bitmap.buffer[i_bitmap_offset]])*opacity/512
    382414                    i_offset += i_pitch; x--; 
    383415                    p_a[i_offset + x] = ((uint16_t)p_a[i_offset + x] + 
    384                       pi_gamma[p_glyph->bitmap.buffer[i_bitmap_offset]])*opacity/200
     416                      pi_gamma[p_glyph->bitmap.buffer[i_bitmap_offset]])*opacity/512
    385417                    i_offset -= i_pitch; 
    386418                } 
     
    397429               { 
    398430                   p_y[i_offset + x] = 
    399                        pi_gamma[p_glyph->bitmap.buffer[i_bitmap_offset]]*opacity/100; 
     431                       pi_gamma[p_glyph->bitmap.buffer[i_bitmap_offset]]*opacity/256; 
     432                   p_u[i_offset + x] = i_u; p_v[i_offset + x] = i_v; 
    400433               } 
    401434               i_offset += i_pitch; 
     
    660693#undef glyph 
    661694 
    662     Render( p_filter, p_subpic, p_string ); 
     695    Render( p_filter, p_subpic, p_string, p_sys->i_opacity,  
     696                 p_sys->i_red, p_sys->i_green, p_sys->i_blue ); 
    663697    FreeString( p_string ); 
    664698    block_Release( p_block );