Changeset 223ebac60de34e1d82cee9a08e9aa041bf3e694c
- 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
| r869578a |
r223ebac |
|
| 83 | 83 | "If set to something different than 0 this option will override the " \ |
|---|
| 84 | 84 | "relative font size " ) |
|---|
| 85 | | #define OPACITY_TEXT N_("Opacity, 0..100%") |
|---|
| | 85 | #define OPACITY_TEXT N_("Opacity, 0..255") |
|---|
| 86 | 86 | #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]" ) |
|---|
| 88 | 91 | #define FONTSIZER_TEXT N_("Font size") |
|---|
| 89 | 92 | #define FONTSIZER_LONGTEXT N_("The size of the fonts used by the osd module" ) |
|---|
| … | … | |
| 102 | 105 | add_integer( "freetype-fontsize", 0, NULL, FONTSIZE_TEXT, |
|---|
| 103 | 106 | FONTSIZE_LONGTEXT, VLC_TRUE ); |
|---|
| 104 | | add_integer( "freetype-opacity", 100, NULL, OPACITY_TEXT, |
|---|
| | 107 | add_integer( "freetype-opacity", 255, NULL, OPACITY_TEXT, |
|---|
| 105 | 108 | OPACITY_LONGTEXT, VLC_TRUE ); |
|---|
| | 109 | add_integer( "freetype-color", 0xFFFFFF, NULL, COLOR_TEXT, |
|---|
| | 110 | COLOR_LONGTEXT, VLC_TRUE ); |
|---|
| 106 | 111 | add_integer( "freetype-rel-fontsize", 16, NULL, FONTSIZER_TEXT, |
|---|
| 107 | 112 | FONTSIZER_LONGTEXT, VLC_FALSE ); |
|---|
| … | … | |
| 137 | 142 | }; |
|---|
| 138 | 143 | |
|---|
| 139 | | static void Render ( filter_t *, subpicture_t *, subpicture_data_t * ); |
|---|
| | 144 | static void Render ( filter_t *, subpicture_t *, subpicture_data_t *, uint8_t, |
|---|
| | 145 | uint8_t, uint8_t, uint8_t ); |
|---|
| 140 | 146 | static void FreeString( subpicture_data_t * ); |
|---|
| 141 | 147 | static void FreeLine( line_desc_t * ); |
|---|
| … | … | |
| 152 | 158 | FT_Face p_face; /* handle to face object */ |
|---|
| 153 | 159 | 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 */ |
|---|
| 155 | 162 | uint8_t pi_gamma[256]; |
|---|
| 156 | 163 | }; |
|---|
| … | … | |
| 179 | 186 | p_sys->p_face = 0; |
|---|
| 180 | 187 | 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; |
|---|
| 182 | 193 | |
|---|
| 183 | 194 | for( i = 0; i < 256; i++ ) |
|---|
| … | … | |
| 193 | 204 | VLC_VAR_INTEGER | VLC_VAR_DOINHERIT ); |
|---|
| 194 | 205 | var_Create( p_filter, "freetype-opacity", |
|---|
| | 206 | VLC_VAR_INTEGER | VLC_VAR_DOINHERIT ); |
|---|
| | 207 | var_Create( p_filter, "freetype-color", |
|---|
| 195 | 208 | VLC_VAR_INTEGER | VLC_VAR_DOINHERIT ); |
|---|
| 196 | 209 | |
|---|
| … | … | |
| 245 | 258 | if( val.i_int ) |
|---|
| 246 | 259 | { |
|---|
| 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 */ |
|---|
| 248 | 261 | { |
|---|
| 249 | 262 | p_sys->i_opacity = val.i_int; |
|---|
| 250 | 263 | } |
|---|
| 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 | |
|---|
| 253 | 278 | var_Get( p_filter, "freetype-fontsize", &val ); |
|---|
| 254 | 279 | if( val.i_int ) |
|---|
| … | … | |
| 308 | 333 | *****************************************************************************/ |
|---|
| 309 | 334 | static 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 ) |
|---|
| 311 | 337 | { |
|---|
| 312 | 338 | filter_sys_t *p_sys = p_filter->p_sys; |
|---|
| … | … | |
| 315 | 341 | video_format_t fmt; |
|---|
| 316 | 342 | 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; |
|---|
| 317 | 349 | |
|---|
| 318 | 350 | /* Create a new subpicture region */ |
|---|
| … | … | |
| 344 | 376 | |
|---|
| 345 | 377 | #define pi_gamma p_sys->pi_gamma |
|---|
| 346 | | #define opacity p_sys->i_opacity |
|---|
| | 378 | /* #define opacity p_sys->i_opacity */ |
|---|
| 347 | 379 | |
|---|
| 348 | 380 | for( p_line = p_string->p_lines; p_line != NULL; p_line = p_line->p_next ) |
|---|
| … | … | |
| 373 | 405 | i_offset -= i_pitch; |
|---|
| 374 | 406 | 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; |
|---|
| 376 | 408 | i_offset += i_pitch; x--; |
|---|
| 377 | 409 | 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; |
|---|
| 379 | 411 | x += 2; |
|---|
| 380 | 412 | 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; |
|---|
| 382 | 414 | i_offset += i_pitch; x--; |
|---|
| 383 | 415 | 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; |
|---|
| 385 | 417 | i_offset -= i_pitch; |
|---|
| 386 | 418 | } |
|---|
| … | … | |
| 397 | 429 | { |
|---|
| 398 | 430 | 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; |
|---|
| 400 | 433 | } |
|---|
| 401 | 434 | i_offset += i_pitch; |
|---|
| … | … | |
| 660 | 693 | #undef glyph |
|---|
| 661 | 694 | |
|---|
| 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 ); |
|---|
| 663 | 697 | FreeString( p_string ); |
|---|
| 664 | 698 | block_Release( p_block ); |
|---|