]> git.sesse.net Git - vlc/blobdiff - modules/misc/freetype.c
ALL: backport of 13001,13004,13005,13011,13012,13019,13020,13025 from trunk.
[vlc] / modules / misc / freetype.c
index 7b2a35cb0f60593166e382e75ed68241e3c3b1b0..98fd7abba941ead2298a8e4e340b79ee2942ed06 100644 (file)
@@ -1,10 +1,10 @@
 /*****************************************************************************
  * freetype.c : Put text on the video, using freetype2
  *****************************************************************************
- * Copyright (C) 2002 - 2005 VideoLAN
+ * Copyright (C) 2002 - 2005 the VideoLAN team
  * $Id$
  *
- * Authors: Sigmund Augdal <sigmunau@idi.ntnu.no>
+ * Authors: Sigmund Augdal Helberg <dnumgis@videolan.org>
  *          Gildas Bazin <gbazin@videolan.org>
  *
  * This program is free software; you can redistribute it and/or modify
@@ -34,7 +34,7 @@
 
 #include <vlc/vlc.h>
 #include <vlc/vout.h>
-#include "osd.h"
+#include "vlc_osd.h"
 #include "vlc_block.h"
 #include "vlc_filter.h"
 
@@ -304,8 +304,8 @@ static int Render( filter_t *p_filter, subpicture_region_t *p_region,
                    line_desc_t *p_line, int i_width, int i_height )
 {
     static uint8_t pi_gamma[16] =
-        {0x00, 0x41, 0x52, 0x63, 0x84, 0x85, 0x96, 0xa7, 0xb8, 0xc9,
-         0xca, 0xdb, 0xdc, 0xed, 0xee, 0xff};
+        {0x00, 0x52, 0x84, 0x96, 0xb8, 0xca, 0xdc, 0xee, 0xff,
+          0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
 
     uint8_t *p_dst;
     video_format_t fmt;
@@ -342,7 +342,16 @@ static int Render( filter_t *p_filter, subpicture_region_t *p_region,
 
     /* Build palette */
     fmt.p_palette->i_entries = 16;
-    for( i = 0; i < fmt.p_palette->i_entries; i++ )
+    for( i = 0; i < 8; i++ )
+    {
+        fmt.p_palette->palette[i][0] = 0;
+        fmt.p_palette->palette[i][1] = 0x80;
+        fmt.p_palette->palette[i][2] = 0x80;
+        fmt.p_palette->palette[i][3] = pi_gamma[i];
+        fmt.p_palette->palette[i][3] =
+            (int)fmt.p_palette->palette[i][3] * (255 - p_line->i_alpha) / 255;
+    }
+    for( i = 8; i < fmt.p_palette->i_entries; i++ )
     {
         fmt.p_palette->palette[i][0] = i * 16 * i_y / 256;
         fmt.p_palette->palette[i][1] = i_u;
@@ -411,15 +420,15 @@ static int Render( filter_t *p_filter, subpicture_region_t *p_region,
 
         for( y = 1; y < (int)fmt.i_height - 1; y++ )
         {
-            memcpy( p_top, p_dst, fmt.i_width );
+            if( y > 1 ) memcpy( p_top, p_dst, fmt.i_width );
             p_dst += p_region->picture.Y_PITCH;
             left = 0;
 
             for( x = 1; x < (int)fmt.i_width - 1; x++ )
             {
                 current = p_dst[x];
-                p_dst[x] = ( 4 * (int)p_dst[x] + left + p_top[x] + p_dst[x+1] +
-                             p_dst[x + p_region->picture.Y_PITCH]) / 8;
+                p_dst[x] = ( 8 * (int)p_dst[x] + left + p_dst[x+1] + p_top[x -1]+ p_top[x] + p_top[x+1] +
+                             p_dst[x -1 + p_region->picture.Y_PITCH ] + p_dst[x + p_region->picture.Y_PITCH] + p_dst[x + 1 + p_region->picture.Y_PITCH]) / 16;
                 left = current;
             }
         }
@@ -606,7 +615,11 @@ static int RenderText( filter_t *p_filter, subpicture_region_t *p_region_out,
         }
         FT_Glyph_Get_CBox( tmp_glyph, ft_glyph_bbox_pixels, &glyph_size );
         i_error = FT_Glyph_To_Bitmap( &tmp_glyph, ft_render_mode_normal, 0, 1);
-        if( i_error ) continue;
+        if( i_error )
+        {
+            FT_Done_Glyph( tmp_glyph );
+            continue;
+        }
         p_line->pp_glyphs[ i ] = (FT_BitmapGlyph)tmp_glyph;
 
         /* Do rest */