]> git.sesse.net Git - vlc/blobdiff - modules/video_chroma/i420_rgb.c
video chromas: finalize SSE2 improvements
[vlc] / modules / video_chroma / i420_rgb.c
index 5522a2022bdbce9df2e66567cbf0385b9f8051b5..e92035040913fa7531a1f4b4363e431fe8fb70ad 100644 (file)
@@ -1,10 +1,11 @@
 /*****************************************************************************
  * i420_rgb.c : YUV to bitmap RGB conversion module for vlc
  *****************************************************************************
- * Copyright (C) 2000, 2001 VideoLAN
- * $Id: i420_rgb.c,v 1.6 2003/12/22 14:32:56 sam Exp $
+ * Copyright (C) 2000, 2001, 2004 the VideoLAN team
+ * $Id$
  *
- * Author: Sam Hocevar <sam@zoy.org>
+ * Authors: Sam Hocevar <sam@zoy.org>
+ *          Damien Fouilleul <damienf@videolan.org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -18,7 +19,7 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 /*****************************************************************************
@@ -29,7 +30,7 @@
 #include <stdlib.h>                                      /* malloc(), free() */
 
 #include <vlc/vlc.h>
-#include <vlc/vout.h>
+#include <vlc_vout.h>
 
 #include "i420_rgb.h"
 #if defined (MODULE_NAME_IS_i420_rgb)
@@ -72,6 +73,11 @@ vlc_module_begin();
                         "RV15,RV16,RV24,RV32 conversions") );
     set_capability( "chroma", 100 );
     add_requirement( MMX );
+#elif defined (MODULE_NAME_IS_i420_rgb_sse2)
+    set_description( _( "SSE2 I420,IYUV,YV12 to "
+                        "RV15,RV16,RV24,RV32 conversions") );
+    set_capability( "chroma", 120 );
+    add_requirement( SSE2 );
 #endif
     set_callbacks( Activate, Deactivate );
 vlc_module_end();
@@ -107,35 +113,78 @@ static int Activate( vlc_object_t *p_this )
 #endif
                 case VLC_FOURCC('R','V','1','5'):
                 case VLC_FOURCC('R','V','1','6'):
-#if defined (MODULE_NAME_IS_i420_rgb_mmx)
+#if ! defined (MODULE_NAME_IS_i420_rgb)
                     /* If we don't have support for the bitmasks, bail out */
-                    if( ( p_vout->output.i_rmask != 0x7c00
-                           || p_vout->output.i_gmask != 0x03e0
-                           || p_vout->output.i_bmask != 0x001f )
-                     && ( p_vout->output.i_rmask != 0xf800
-                           || p_vout->output.i_gmask != 0x07e0
-                           || p_vout->output.i_bmask != 0x001f ) )
+                    if( ( p_vout->output.i_rmask == 0x7c00
+                       && p_vout->output.i_gmask == 0x03e0
+                       && p_vout->output.i_bmask == 0x001f ) )
                     {
-                        return -1;
+                        /* R5G5B6 pixel format */
+                        msg_Dbg(p_this, "RGB pixel format is R5G5B5");
+                        p_vout->chroma.pf_convert = E_(I420_R5G5B5);
                     }
-#endif
+                    else if( ( p_vout->output.i_rmask == 0xf800
+                            && p_vout->output.i_gmask == 0x07e0
+                            && p_vout->output.i_bmask == 0x001f ) )
+                    {
+                        /* R5G6B5 pixel format */
+                        msg_Dbg(p_this, "RGB pixel format is R5G6B5");
+                        p_vout->chroma.pf_convert = E_(I420_R5G6B5);
+                    }
+                    else
+                        return -1;
+#else
+                    // generic C chroma converter */
                     p_vout->chroma.pf_convert = E_(I420_RGB16);
+#endif
                     break;
 
-#ifndef WIN32 /* Hmmm, is there only X11 using 32bits per pixel for RV24 ? */
+#if 0
+                /* Hmmm, is there only X11 using 32bits per pixel for RV24 ? */
                 case VLC_FOURCC('R','V','2','4'):
 #endif
+
                 case VLC_FOURCC('R','V','3','2'):
-#if defined (MODULE_NAME_IS_i420_rgb_mmx)
+#if ! defined (MODULE_NAME_IS_i420_rgb)
                     /* If we don't have support for the bitmasks, bail out */
-                    if( p_vout->output.i_rmask != 0x00ff0000
-                         || p_vout->output.i_gmask != 0x0000ff00
-                         || p_vout->output.i_bmask != 0x000000ff )
+                    if( p_vout->output.i_rmask == 0x00ff0000
+                     && p_vout->output.i_gmask == 0x0000ff00
+                     && p_vout->output.i_bmask == 0x000000ff )
                     {
-                        return -1;
+                        /* A8R8G8B8 pixel format */
+                        msg_Dbg(p_this, "RGB pixel format is A8R8G8B8");
+                        p_vout->chroma.pf_convert = E_(I420_A8R8G8B8);
                     }
-#endif
+                    else if( p_vout->output.i_rmask == 0xff000000
+                          && p_vout->output.i_gmask == 0x00ff0000
+                          && p_vout->output.i_bmask == 0x0000ff00 )
+                    {
+                        /* R8G8B8A8 pixel format */
+                        msg_Dbg(p_this, "RGB pixel format is R8G8B8A8");
+                        p_vout->chroma.pf_convert = E_(I420_R8G8B8A8);
+                    }
+                    else if( p_vout->output.i_rmask == 0x0000ff00
+                          && p_vout->output.i_gmask == 0x00ff0000
+                          && p_vout->output.i_bmask == 0xff000000 )
+                    {
+                        /* B8G8R8A8 pixel format */
+                        msg_Dbg(p_this, "RGB pixel format is B8G8R8A8");
+                        p_vout->chroma.pf_convert = E_(I420_B8G8R8A8);
+                    }
+                    else if( p_vout->output.i_rmask == 0x000000ff
+                          && p_vout->output.i_gmask == 0x0000ff00
+                          && p_vout->output.i_bmask == 0x00ff0000 )
+                    {
+                        /* A8B8G8R8 pixel format */
+                        msg_Dbg(p_this, "RGB pixel format is A8B8G8R8");
+                        p_vout->chroma.pf_convert = E_(I420_A8B8G8R8);
+                    }
+                    else
+                        return -1;
+#else
+                    /* generic C chroma converter */
                     p_vout->chroma.pf_convert = E_(I420_RGB32);
+#endif
                     break;
 
                 default:
@@ -265,8 +314,10 @@ static void SetGammaTable( int *pi_table, double f_gamma )
  *****************************************************************************/
 static void SetYUV( vout_thread_t *p_vout )
 {
-    int         pi_gamma[256];                                /* gamma table */
-    int         i_index;                                  /* index in tables */
+    int          pi_gamma[256];                               /* gamma table */
+    volatile int i_index;                                 /* index in tables */
+                   /* We use volatile here to work around a strange gcc-3.3.4
+                    * optimization bug */
 
     /* Build gamma table */
     SetGammaTable( pi_gamma, p_vout->f_gamma );
@@ -344,7 +395,10 @@ static void Set8bppPalette( vout_thread_t *p_vout, uint8_t *p_rgb8 )
     int y,u,v;
     int r,g,b;
     int i = 0, j = 0;
-    uint16_t red[ 256 ], green[ 256 ], blue[ 256 ];
+    uint16_t *p_cmap_r=p_vout->chroma.p_sys->p_rgb_r;
+    uint16_t *p_cmap_g=p_vout->chroma.p_sys->p_rgb_g;
+    uint16_t *p_cmap_b=p_vout->chroma.p_sys->p_rgb_b;
+
     unsigned char p_lookup[PALETTE_TABLE_SIZE];
 
     /* This loop calculates the intersection of an YUV box and the RGB cube. */
@@ -371,9 +425,15 @@ static void Set8bppPalette( vout_thread_t *p_vout, uint8_t *p_rgb8 )
                     }
 
                     /* Clip the colors */
-                    red[ j ] = CLIP( r );
-                    green[ j ] = CLIP( g );
-                    blue[ j ] = CLIP( b );
+                    p_cmap_r[ j ] = CLIP( r );
+                    p_cmap_g[ j ] = CLIP( g );
+                    p_cmap_b[ j ] = CLIP( b );
+
+#if 0
+                   printf("+++Alloc RGB cmap %d (%d, %d, %d)\n", j,
+                          p_cmap_r[ j ] >>8, p_cmap_g[ j ] >>8, 
+                          p_cmap_b[ j ] >>8);
+#endif
 
                     /* Allocate color */
                     p_lookup[ i ] = 1;
@@ -390,7 +450,7 @@ static void Set8bppPalette( vout_thread_t *p_vout, uint8_t *p_rgb8 )
     }
 
     /* The colors have been allocated, we can set the palette */
-    p_vout->output.pf_setpalette( p_vout, red, green, blue );
+    p_vout->output.pf_setpalette( p_vout, p_cmap_r, p_cmap_g, p_cmap_b );
 
 #if 0
     /* There will eventually be a way to know which colors