Changeset 2479a41d194aa04f855a14ad79d66d94878b591f

Show
Ignore:
Timestamp:
10/03/05 14:37:29 (4 years ago)
Author:
Gildas Bazin <gbazin@videolan.org>
git-committer:
Gildas Bazin <gbazin@videolan.org> 1110461849 +0000
git-parent:

[2e3847698a715d877bf4506f4d100ba927ca0696]

git-author:
Gildas Bazin <gbazin@videolan.org> 1110461849 +0000
Message:

* modules/misc/freetype.c: better outlining algorithm + generate 16 colors (instead of 256) palettized YUV.

Files:

Legend:

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

    ref235f2 r2479a41  
    304304                   line_desc_t *p_line, int i_width, int i_height ) 
    305305{ 
     306    static uint8_t pi_gamma[16] = 
     307        {0x00, 0x41, 0x52, 0x63, 0x84, 0x85, 0x96, 0xa7, 0xb8, 0xc9, 
     308         0xca, 0xdb, 0xdc, 0xed, 0xee, 0xff}; 
     309 
    306310    uint8_t *p_dst; 
    307311    video_format_t fmt; 
     
    315319    fmt.i_chroma = VLC_FOURCC('Y','U','V','P'); 
    316320    fmt.i_aspect = VOUT_ASPECT_FACTOR; 
    317     fmt.i_width = fmt.i_visible_width = i_width + 2
    318     fmt.i_height = fmt.i_visible_height = i_height + 2
     321    fmt.i_width = fmt.i_visible_width = i_width + 4
     322    fmt.i_height = fmt.i_visible_height = i_height + 4
    319323    fmt.i_x_offset = fmt.i_y_offset = 0; 
    320324    p_region_tmp = spu_CreateRegion( p_filter, &fmt ); 
     
    338342 
    339343    /* Build palette */ 
    340     fmt.p_palette->i_entries = 256; 
     344    fmt.p_palette->i_entries = 16; 
    341345    for( i = 0; i < fmt.p_palette->i_entries; i++ ) 
    342346    { 
    343         fmt.p_palette->palette[i][0] = i * i_y / 256; 
     347        fmt.p_palette->palette[i][0] = i * 16 * i_y / 256; 
    344348        fmt.p_palette->palette[i][1] = i_u; 
    345349        fmt.p_palette->palette[i][2] = i_v; 
    346         fmt.p_palette->palette[i][3] = i + (255 - i) / 16
     350        fmt.p_palette->palette[i][3] = pi_gamma[i]
    347351        fmt.p_palette->palette[i][3] = 
    348352            (int)fmt.p_palette->palette[i][3] * (255 - p_line->i_alpha) / 255; 
    349353    } 
    350     fmt.p_palette->palette[0][3] = 0; 
    351354 
    352355    p_dst = p_region->picture.Y_PIXELS; 
     
    377380            } 
    378381        } 
     382 
    379383        for( i = 0; p_line->pp_glyphs[i] != NULL; i++ ) 
    380384        { 
     
    382386 
    383387            i_offset = ( p_line->p_glyph_pos[ i ].y + 
    384                 i_glyph_tmax - p_glyph->top + 1 ) * 
    385                 i_pitch + p_line->p_glyph_pos[ i ].x + p_glyph->left + 1
     388                i_glyph_tmax - p_glyph->top + 2 ) * 
     389                i_pitch + p_line->p_glyph_pos[ i ].x + p_glyph->left + 2
    386390                i_align_offset; 
    387391 
     
    390394                for( x = 0; x < p_glyph->bitmap.width; x++, i_bitmap_offset++ ) 
    391395                { 
    392                     if( !p_glyph->bitmap.buffer[i_bitmap_offset] ) 
    393                         continue; 
    394  
    395                     i_offset -= i_pitch; 
    396                     p_dst[i_offset + x] = ((uint16_t)p_dst[i_offset + x]*2 + 
    397                       p_glyph->bitmap.buffer[i_bitmap_offset])/3; 
    398                     i_offset += i_pitch; x--; 
    399                     p_dst[i_offset + x] = ((uint16_t)p_dst[i_offset + x]*2 + 
    400                       p_glyph->bitmap.buffer[i_bitmap_offset])/3; 
    401                     x += 2; 
    402                     p_dst[i_offset + x] = ((uint16_t)p_dst[i_offset + x]*2 + 
    403                       p_glyph->bitmap.buffer[i_bitmap_offset])/3; 
    404                     i_offset += i_pitch; x--; 
    405                     p_dst[i_offset + x] = ((uint16_t)p_dst[i_offset + x]*2 + 
    406                       p_glyph->bitmap.buffer[i_bitmap_offset])/3; 
    407                     i_offset -= i_pitch; 
     396                    if( p_glyph->bitmap.buffer[i_bitmap_offset] ) 
     397                        p_dst[i_offset+x] = 
     398                         ((int)p_glyph->bitmap.buffer[i_bitmap_offset] + 8)/16; 
    408399                } 
    409400                i_offset += i_pitch; 
    410401            } 
    411  
    412             i_offset = ( p_line->p_glyph_pos[ i ].y + 
    413                 i_glyph_tmax - p_glyph->top + 1 ) * 
    414                 i_pitch + p_line->p_glyph_pos[ i ].x + p_glyph->left + 1 + 
    415                 i_align_offset; 
    416  
    417             for( y = 0, i_bitmap_offset = 0; y < p_glyph->bitmap.rows; y++ ) 
     402        } 
     403    } 
     404 
     405    /* Outlining (find something better than nearest neighbour filtering ?) */ 
     406    if( 1 ) 
     407    { 
     408        uint8_t *p_dst = p_region->picture.Y_PIXELS; 
     409        uint8_t *p_top = p_dst; /* Use 1st line as a cache */ 
     410        uint8_t left, current; 
     411 
     412        for( y = 1; y < (int)fmt.i_height - 1; y++ ) 
     413        { 
     414            memcpy( p_top, p_dst, fmt.i_width ); 
     415            p_dst += p_region->picture.Y_PITCH; 
     416            left = 0; 
     417 
     418            for( x = 1; x < (int)fmt.i_width - 1; x++ ) 
    418419            { 
    419                for( x = 0; x < p_glyph->bitmap.width; x++, i_bitmap_offset++ ) 
    420                { 
    421                  if( p_glyph->bitmap.buffer[i_bitmap_offset] > 16 ) 
    422                    p_dst[i_offset+x] = p_glyph->bitmap.buffer[i_bitmap_offset]; 
    423                } 
    424                i_offset += i_pitch; 
     420                current = p_dst[x]; 
     421                p_dst[x] = ( 4 * (int)p_dst[x] + left + p_top[x] + p_dst[x+1] + 
     422                             p_dst[x + p_region->picture.Y_PITCH]) / 8; 
     423                left = current; 
    425424            } 
    426425        } 
     426        memset( p_top, 0, fmt.i_width ); 
    427427    } 
    428428