freetype.c: basic YUY2 rendering (Y only)
authorEric Petit <titer@videolan.org>
Sat, 26 Jul 2003 18:54:20 +0000 (18:54 +0000)
committerEric Petit <titer@videolan.org>
Sat, 26 Jul 2003 18:54:20 +0000 (18:54 +0000)
modules/misc/freetype.c

index 3b74715..3b9fb54 100644 (file)
@@ -2,7 +2,7 @@
  * freetype.c : Put text on the video, using freetype2
  *****************************************************************************
  * Copyright (C) 2002, 2003 VideoLAN
- * $Id: freetype.c,v 1.13 2003/07/24 21:50:28 gbazin Exp $
+ * $Id: freetype.c,v 1.14 2003/07/26 18:54:20 titer Exp $
  *
  * Authors: Sigmund Augdal <sigmunau@idi.ntnu.no>
  *
@@ -54,6 +54,8 @@ static void Render    ( vout_thread_t *, picture_t *,
                         const subpicture_t * );
 static void RenderI420( vout_thread_t *, picture_t *,
                         const subpicture_t * );
+static void RenderYUY2( vout_thread_t *, picture_t *,
+                        const subpicture_t * );
 static int  AddText   ( vout_thread_t *, byte_t *, text_style_t *, int,
                         int, int, mtime_t, mtime_t );
 static int  GetUnicodeCharFromUTF8( byte_t ** );
@@ -248,20 +250,20 @@ static void Render( vout_thread_t *p_vout, picture_t *p_pic,
 #if 0
         /* RV16 target, scaling */
         case VLC_FOURCC('R','V','1','6'):
-            RenderRV16( p_vout, p_pic, p_spu, p_spu->p_sys->b_crop );
+            RenderRV16( p_vout, p_pic, p_subpic );
             break;
 
         /* RV32 target, scaling */
         case VLC_FOURCC('R','V','2','4'):
         case VLC_FOURCC('R','V','3','2'):
-            RenderRV32( p_vout, p_pic, p_spu, p_spu->p_sys->b_crop );
+            RenderRV32( p_vout, p_pic, p_subpic );
             break;
-
-        /* NVidia overlay, no scaling */
+#endif
+        /* NVidia or BeOS overlay, no scaling */
         case VLC_FOURCC('Y','U','Y','2'):
-            RenderYUY2( p_vout, p_pic, p_spu, p_spu->p_sys->b_crop );
+            RenderYUY2( p_vout, p_pic, p_subpic );
             break;
-#endif
+
         default:
             msg_Err( p_vout, "unknown chroma, can't render SPU" );
             break;
@@ -372,6 +374,63 @@ static void RenderI420( vout_thread_t *p_vout, picture_t *p_pic,
     }
 }
 
+/**
+ * Draw a string on a YUY2 picture
+ */
+static void RenderYUY2( vout_thread_t *p_vout, picture_t *p_pic,
+                        const subpicture_t *p_subpic )
+{
+    subpicture_sys_t *p_string = p_subpic->p_sys;
+    int x, y, pen_x, pen_y;
+    unsigned int i;
+
+    uint8_t *p_in;
+    int i_pitch = p_pic->p[0].i_pitch;
+
+    p_in = p_pic->p->p_pixels;
+
+    if ( p_string->i_flags & OSD_ALIGN_BOTTOM )
+    {
+        pen_y = p_pic->p->i_lines - p_string->i_height -
+                p_string->i_y_margin;
+    }
+    else
+    {
+        pen_y = p_string->i_y_margin;
+    }
+    pen_y += p_vout->p_text_renderer_data->p_face->size->metrics.height / 100;
+    if ( p_string->i_flags & OSD_ALIGN_RIGHT )
+    {
+        pen_x = i_pitch - p_string->i_width - p_string->i_x_margin;
+    }
+    else
+    {
+        pen_x = p_string->i_x_margin;
+    }
+
+    /* TODO : set U & V bytes */
+    for( i = 0; p_string->pp_glyphs[i] != NULL; i++ )
+    {
+        if( p_string->pp_glyphs[i] )
+        {
+            FT_BitmapGlyph p_glyph = p_string->pp_glyphs[ i ];
+#define alpha p_vout->p_text_renderer_data->pi_gamma[ p_glyph->bitmap.buffer[ x + y * p_glyph->bitmap.width ] ]
+#define pixel p_in[ ( p_string->p_glyph_pos[ i ].y + pen_y + y - p_glyph->top ) * i_pitch + 2 * ( x + pen_x + p_string->p_glyph_pos[ i ].x + p_glyph->left ) ]
+            for( y = 0; y < p_glyph->bitmap.rows; y++ )
+            {
+                for( x = 0; x < p_glyph->bitmap.width; x++ )
+                {
+                    pixel = ( ( pixel * ( 255 - alpha ) ) >> 8 ) +
+                            ( 255 * alpha >> 8 );
+#undef alpha
+#undef pixel
+                }
+            }
+        }
+    }
+}
+
+
 /**
  * This function receives a string and creates a subpicture for it. It
  * also calculates the size needed for this string, and renders the