]> git.sesse.net Git - vlc/blobdiff - plugins/chroma/i420_yuy2.c
* ALL: new module API. Makes a few things a lot simpler, and we gain
[vlc] / plugins / chroma / i420_yuy2.c
index 38ce9f8d8a9f89f0c63c80844d30eba20cfe0e8c..34c3fbb37dc96c41ce2fcda1e3cf0fe4c6e90044 100644 (file)
@@ -2,7 +2,7 @@
  * i420_yuy2.c : YUV to YUV conversion module for vlc
  *****************************************************************************
  * Copyright (C) 2000, 2001 VideoLAN
- * $Id: i420_yuy2.c,v 1.3 2002/03/16 23:03:19 sam Exp $
+ * $Id: i420_yuy2.c,v 1.11 2002/07/31 20:56:51 sam Exp $
  *
  * Authors: Samuel Hocevar <sam@zoy.org>
  *
@@ -10,7 +10,7 @@
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version.
- * 
+ *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include <math.h>                                            /* exp(), pow() */
 #include <errno.h>                                                 /* ENOMEM */
 #include <string.h>                                            /* strerror() */
 #include <stdlib.h>                                      /* malloc(), free() */
 
-#include <videolan/vlc.h>
-
-#include "video.h"
-#include "video_output.h"
+#include <vlc/vlc.h>
+#include <vlc/vout.h>
 
 #include "i420_yuy2.h"
 
 /*****************************************************************************
  * Local and extern prototypes.
  *****************************************************************************/
-static void chroma_getfunctions ( function_list_t * p_function_list );
-
-static int  chroma_Init         ( vout_thread_t *p_vout );
-static void chroma_End          ( vout_thread_t *p_vout );
+static int  Activate ( vlc_object_t * );
 
 static void I420_YUY2           ( vout_thread_t *, picture_t *, picture_t * );
 static void I420_YVYU           ( vout_thread_t *, picture_t *, picture_t * );
@@ -61,47 +55,38 @@ static void I420_cyuv           ( vout_thread_t *, picture_t *, picture_t * );
 static void I420_Y211           ( vout_thread_t *, picture_t *, picture_t * );
 #endif
 
+#ifdef MODULE_NAME_IS_chroma_i420_yuy2_mmx
+static unsigned long long i_00ffw;
+static unsigned long long i_80w;
+#endif
+
 /*****************************************************************************
- * Build configuration tree.
+ * Module descriptor.
  *****************************************************************************/
-MODULE_CONFIG_START
-MODULE_CONFIG_STOP
-
-MODULE_INIT_START
+vlc_module_begin();
 #if defined (MODULE_NAME_IS_chroma_i420_yuy2)
-    SET_DESCRIPTION( "conversions from " SRC_FOURCC " to " DEST_FOURCC )
-    ADD_CAPABILITY( CHROMA, 80 )
+    set_description( _("conversions from " SRC_FOURCC " to " DEST_FOURCC) );
+    set_capability( "chroma", 80 );
 #elif defined (MODULE_NAME_IS_chroma_i420_yuy2_mmx)
-    SET_DESCRIPTION( "MMX conversions from " SRC_FOURCC " to " DEST_FOURCC )
-    ADD_CAPABILITY( CHROMA, 100 )
-    ADD_REQUIREMENT( MMX )
+    set_description( _("MMX conversions from " SRC_FOURCC " to " DEST_FOURCC) );
+    set_capability( "chroma", 100 );
+    add_requirement( MMX );
+    /* Initialize MMX-specific constants */
+    i_00ffw = 0x00ff00ff00ff00ff;
+    i_80w   = 0x0000000080808080;
 #endif
-MODULE_INIT_STOP
-
-MODULE_ACTIVATE_START
-    chroma_getfunctions( &p_module->p_functions->chroma );
-MODULE_ACTIVATE_STOP
-
-MODULE_DEACTIVATE_START
-MODULE_DEACTIVATE_STOP
+    set_callbacks( Activate, NULL );
+vlc_module_end();
 
 /*****************************************************************************
- * Functions exported as capabilities. They are declared as static so that
- * we don't pollute the namespace too much.
- *****************************************************************************/
-static void chroma_getfunctions( function_list_t * p_function_list )
-{
-    p_function_list->functions.chroma.pf_init = chroma_Init;
-    p_function_list->functions.chroma.pf_end  = chroma_End;
-}
-
-/*****************************************************************************
- * chroma_Init: allocate a chroma function
+ * Activate: allocate a chroma function
  *****************************************************************************
  * This function allocates and initializes a chroma function
  *****************************************************************************/
-static int chroma_Init( vout_thread_t *p_vout )
+static int Activate( vlc_object_t *p_this )
 {
+    vout_thread_t *p_vout = (vout_thread_t *)p_this;
+
     if( p_vout->render.i_width & 1 || p_vout->render.i_height & 1 )
     {
         return -1;
@@ -109,36 +94,36 @@ static int chroma_Init( vout_thread_t *p_vout )
 
     switch( p_vout->render.i_chroma )
     {
-        case FOURCC_YV12:
-        case FOURCC_I420:
-        case FOURCC_IYUV:
+        case VLC_FOURCC('Y','V','1','2'):
+        case VLC_FOURCC('I','4','2','0'):
+        case VLC_FOURCC('I','Y','U','V'):
             switch( p_vout->output.i_chroma )
             {
-                case FOURCC_YUY2:
-                case FOURCC_YUNV:
+                case VLC_FOURCC('Y','U','Y','2'):
+                case VLC_FOURCC('Y','U','N','V'):
                     p_vout->chroma.pf_convert = I420_YUY2;
                     break;
 
-                case FOURCC_YVYU:
+                case VLC_FOURCC('Y','V','Y','U'):
                     p_vout->chroma.pf_convert = I420_YVYU;
                     break;
 
-                case FOURCC_UYVY:
-                case FOURCC_UYNV:
-                case FOURCC_Y422:
+                case VLC_FOURCC('U','Y','V','Y'):
+                case VLC_FOURCC('U','Y','N','V'):
+                case VLC_FOURCC('Y','4','2','2'):
                     p_vout->chroma.pf_convert = I420_UYVY;
                     break;
 
-                case FOURCC_IUYV:
+                case VLC_FOURCC('I','U','Y','V'):
                     p_vout->chroma.pf_convert = I420_IUYV;
                     break;
 
-                case FOURCC_cyuv:
+                case VLC_FOURCC('c','y','u','v'):
                     p_vout->chroma.pf_convert = I420_cyuv;
                     break;
 
 #if defined (MODULE_NAME_IS_chroma_i420_yuy2)
-                case FOURCC_Y211:
+                case VLC_FOURCC('Y','2','1','1'):
                     p_vout->chroma.pf_convert = I420_Y211;
                     break;
 #endif
@@ -151,18 +136,8 @@ static int chroma_Init( vout_thread_t *p_vout )
         default:
             return -1;
     }
-    
-    return 0; 
-}
 
-/*****************************************************************************
- * chroma_End: free the chroma function
- *****************************************************************************
- * This function frees the previously allocated chroma function
- *****************************************************************************/
-static void chroma_End( vout_thread_t *p_vout )
-{
-    ;
+    return 0;
 }
 
 /* Following functions are local */
@@ -180,6 +155,11 @@ static void I420_YUY2( vout_thread_t *p_vout, picture_t *p_source,
 
     int i_x, i_y;
 
+    const int i_source_margin = p_source->p->i_pitch
+                                 - p_source->p->i_visible_pitch;
+    const int i_dest_margin = p_dest->p->i_pitch
+                               - p_dest->p->i_visible_pitch;
+
     for( i_y = p_vout->render.i_height / 2 ; i_y-- ; )
     {
         p_line1 = p_line2;
@@ -191,26 +171,19 @@ static void I420_YUY2( vout_thread_t *p_vout, picture_t *p_source,
         for( i_x = p_vout->render.i_width / 8 ; i_x-- ; )
         {
 #if defined (MODULE_NAME_IS_chroma_i420_yuy2)
-            C_YUV420_YUYV( p_line1, p_line2, p_y1, p_y2, p_u, p_v );
-            C_YUV420_YUYV( p_line1, p_line2, p_y1, p_y2, p_u, p_v );
-            C_YUV420_YUYV( p_line1, p_line2, p_y1, p_y2, p_u, p_v );
-            C_YUV420_YUYV( p_line1, p_line2, p_y1, p_y2, p_u, p_v );
+            C_YUV420_YUYV( );
+            C_YUV420_YUYV( );
+            C_YUV420_YUYV( );
+            C_YUV420_YUYV( );
 #else
-            __asm__( ".align 8" MMX_YUV420_YUYV
-                     : : "r" (p_line1), "r" (p_line2),
-                         "r" (p_y1), "r" (p_y2), "r" (p_u), "r" (p_v) ); 
-
-            p_line1 += 8; p_line2 += 8;
-            p_y1 += 4; p_y2 += 4; p_u += 2; p_v += 2;
-
-            __asm__( ".align 8" MMX_YUV420_YUYV
-                     : : "r" (p_line1), "r" (p_line2),
-                         "r" (p_y1), "r" (p_y2), "r" (p_u), "r" (p_v) ); 
-
-            p_line1 += 8; p_line2 += 8;
-            p_y1 += 4; p_y2 += 4; p_u += 2; p_v += 2;
+            MMX_CALL( MMX_YUV420_YUYV );
 #endif
         }
+
+        p_y1 += i_source_margin;
+        p_y2 += i_source_margin;
+        p_line1 += i_dest_margin;
+        p_line2 += i_dest_margin;
     }
 }
 
@@ -227,6 +200,11 @@ static void I420_YVYU( vout_thread_t *p_vout, picture_t *p_source,
 
     int i_x, i_y;
 
+    const int i_source_margin = p_source->p->i_pitch
+                                 - p_source->p->i_visible_pitch;
+    const int i_dest_margin = p_dest->p->i_pitch
+                               - p_dest->p->i_visible_pitch;
+
     for( i_y = p_vout->render.i_height / 2 ; i_y-- ; )
     {
         p_line1 = p_line2;
@@ -238,26 +216,19 @@ static void I420_YVYU( vout_thread_t *p_vout, picture_t *p_source,
         for( i_x = p_vout->render.i_width / 8 ; i_x-- ; )
         {
 #if defined (MODULE_NAME_IS_chroma_i420_yuy2)
-            C_YUV420_YVYU( p_line1, p_line2, p_y1, p_y2, p_u, p_v );
-            C_YUV420_YVYU( p_line1, p_line2, p_y1, p_y2, p_u, p_v );
-            C_YUV420_YVYU( p_line1, p_line2, p_y1, p_y2, p_u, p_v );
-            C_YUV420_YVYU( p_line1, p_line2, p_y1, p_y2, p_u, p_v );
+            C_YUV420_YVYU( );
+            C_YUV420_YVYU( );
+            C_YUV420_YVYU( );
+            C_YUV420_YVYU( );
 #else
-            __asm__( ".align 8" MMX_YUV420_YVYU
-                     : : "r" (p_line1), "r" (p_line2),
-                         "r" (p_y1), "r" (p_y2), "r" (p_u), "r" (p_v) ); 
-
-            p_line1 += 8; p_line2 += 8;
-            p_y1 += 4; p_y2 += 4; p_u += 2; p_v += 2;
-
-            __asm__( ".align 8" MMX_YUV420_YVYU
-                     : : "r" (p_line1), "r" (p_line2),
-                         "r" (p_y1), "r" (p_y2), "r" (p_u), "r" (p_v) ); 
-
-            p_line1 += 8; p_line2 += 8;
-            p_y1 += 4; p_y2 += 4; p_u += 2; p_v += 2;
+            MMX_CALL( MMX_YUV420_YVYU );
 #endif
         }
+
+        p_y1 += i_source_margin;
+        p_y2 += i_source_margin;
+        p_line1 += i_dest_margin;
+        p_line2 += i_dest_margin;
     }
 }
 
@@ -274,6 +245,11 @@ static void I420_UYVY( vout_thread_t *p_vout, picture_t *p_source,
 
     int i_x, i_y;
 
+    const int i_source_margin = p_source->p->i_pitch
+                                 - p_source->p->i_visible_pitch;
+    const int i_dest_margin = p_dest->p->i_pitch
+                               - p_dest->p->i_visible_pitch;
+
     for( i_y = p_vout->render.i_height / 2 ; i_y-- ; )
     {
         p_line1 = p_line2;
@@ -285,26 +261,19 @@ static void I420_UYVY( vout_thread_t *p_vout, picture_t *p_source,
         for( i_x = p_vout->render.i_width / 8 ; i_x-- ; )
         {
 #if defined (MODULE_NAME_IS_chroma_i420_yuy2)
-            C_YUV420_UYVY( p_line1, p_line2, p_y1, p_y2, p_u, p_v );
-            C_YUV420_UYVY( p_line1, p_line2, p_y1, p_y2, p_u, p_v );
-            C_YUV420_UYVY( p_line1, p_line2, p_y1, p_y2, p_u, p_v );
-            C_YUV420_UYVY( p_line1, p_line2, p_y1, p_y2, p_u, p_v );
+            C_YUV420_UYVY( );
+            C_YUV420_UYVY( );
+            C_YUV420_UYVY( );
+            C_YUV420_UYVY( );
 #else
-            __asm__( ".align 8" MMX_YUV420_UYVY
-                     : : "r" (p_line1), "r" (p_line2),
-                         "r" (p_y1), "r" (p_y2), "r" (p_u), "r" (p_v) ); 
-
-            p_line1 += 8; p_line2 += 8;
-            p_y1 += 4; p_y2 += 4; p_u += 2; p_v += 2;
-
-            __asm__( ".align 8" MMX_YUV420_UYVY
-                     : : "r" (p_line1), "r" (p_line2),
-                         "r" (p_y1), "r" (p_y2), "r" (p_u), "r" (p_v) ); 
-
-            p_line1 += 8; p_line2 += 8;
-            p_y1 += 4; p_y2 += 4; p_u += 2; p_v += 2;
+            MMX_CALL( MMX_YUV420_UYVY );
 #endif
         }
+
+        p_y1 += i_source_margin;
+        p_y2 += i_source_margin;
+        p_line1 += i_dest_margin;
+        p_line2 += i_dest_margin;
     }
 }
 
@@ -315,8 +284,7 @@ static void I420_IUYV( vout_thread_t *p_vout, picture_t *p_source,
                                               picture_t *p_dest )
 {
     /* FIXME: TODO ! */
-    intf_ErrMsg( "chroma error: I420_IUYV unimplemented, "
-                 "please harass <sam@zoy.org>" );
+    msg_Err( p_vout, "I420_IUYV unimplemented, please harass <sam@zoy.org>" );
 }
 
 /*****************************************************************************
@@ -334,6 +302,11 @@ static void I420_cyuv( vout_thread_t *p_vout, picture_t *p_source,
 
     int i_x, i_y;
 
+    const int i_source_margin = p_source->p->i_pitch
+                                 - p_source->p->i_visible_pitch;
+    const int i_dest_margin = p_dest->p->i_pitch
+                               - p_dest->p->i_visible_pitch;
+
     for( i_y = p_vout->render.i_height / 2 ; i_y-- ; )
     {
         p_line1 -= 3 * p_dest->p->i_pitch;
@@ -345,26 +318,19 @@ static void I420_cyuv( vout_thread_t *p_vout, picture_t *p_source,
         for( i_x = p_vout->render.i_width / 8 ; i_x-- ; )
         {
 #if defined (MODULE_NAME_IS_chroma_i420_yuy2)
-            C_YUV420_UYVY( p_line1, p_line2, p_y1, p_y2, p_u, p_v );
-            C_YUV420_UYVY( p_line1, p_line2, p_y1, p_y2, p_u, p_v );
-            C_YUV420_UYVY( p_line1, p_line2, p_y1, p_y2, p_u, p_v );
-            C_YUV420_UYVY( p_line1, p_line2, p_y1, p_y2, p_u, p_v );
+            C_YUV420_UYVY( );
+            C_YUV420_UYVY( );
+            C_YUV420_UYVY( );
+            C_YUV420_UYVY( );
 #else
-            __asm__( ".align 8" MMX_YUV420_UYVY
-                     : : "r" (p_line1), "r" (p_line2),
-                         "r" (p_y1), "r" (p_y2), "r" (p_u), "r" (p_v) ); 
-
-            p_line1 += 8; p_line2 += 8;
-            p_y1 += 4; p_y2 += 4; p_u += 2; p_v += 2;
-
-            __asm__( ".align 8" MMX_YUV420_UYVY
-                     : : "r" (p_line1), "r" (p_line2),
-                         "r" (p_y1), "r" (p_y2), "r" (p_u), "r" (p_v) ); 
-
-            p_line1 += 8; p_line2 += 8;
-            p_y1 += 4; p_y2 += 4; p_u += 2; p_v += 2;
+            MMX_CALL( MMX_YUV420_UYVY );
 #endif
         }
+
+        p_y1 += i_source_margin;
+        p_y2 += i_source_margin;
+        p_line1 += i_dest_margin;
+        p_line2 += i_dest_margin;
     }
 }
 
@@ -382,6 +348,11 @@ static void I420_Y211( vout_thread_t *p_vout, picture_t *p_source,
 
     int i_x, i_y;
 
+    const int i_source_margin = p_source->p->i_pitch
+                                 - p_source->p->i_visible_pitch;
+    const int i_dest_margin = p_dest->p->i_pitch
+                               - p_dest->p->i_visible_pitch;
+
     for( i_y = p_vout->render.i_height / 2 ; i_y-- ; )
     {
         p_line1 = p_line2;
@@ -392,9 +363,14 @@ static void I420_Y211( vout_thread_t *p_vout, picture_t *p_source,
 
         for( i_x = p_vout->render.i_width / 8 ; i_x-- ; )
         {
-            C_YUV420_Y211( p_line1, p_line2, p_y1, p_y2, p_u, p_v );
-            C_YUV420_Y211( p_line1, p_line2, p_y1, p_y2, p_u, p_v );
+            C_YUV420_Y211( );
+            C_YUV420_Y211( );
         }
+
+        p_y1 += i_source_margin;
+        p_y2 += i_source_margin;
+        p_line1 += i_dest_margin;
+        p_line2 += i_dest_margin;
     }
 }
 #endif