]> git.sesse.net Git - vlc/blobdiff - src/video_decoder/vdec_motion.c
Bon, puisque �a semble commiter sous BeOS, je commite.
[vlc] / src / video_decoder / vdec_motion.c
index 99a2ec380d431dfaa9bf0646e1d66af228467141..2d859f25200065d25ed0e47e73e85969c1b49a00 100644 (file)
@@ -1,28 +1,42 @@
 /*****************************************************************************
  * vdec_motion.c : motion compensation routines
- * (c)1999 VideoLAN
+ *****************************************************************************
+ * Copyright (C) 1999, 2000 VideoLAN
+ *
+ * Authors:
+ *
+ * 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
+ * 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
+ * GNU General Public License for more details.
+ *
+ * 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.
  *****************************************************************************/
 
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include <errno.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <string.h>
-#include <sys/uio.h>
+#include "defs.h"
+
+#include <sys/types.h>                        /* on BSD, uio.h needs types.h */
+#include <sys/uio.h>                                          /* for input.h */
 
 #include "config.h"
 #include "common.h"
+#include "threads.h"
 #include "mtime.h"
-#include "vlc_thread.h"
+#include "plugins.h"
 
 #include "intf_msg.h"
-#include "debug.h"                    /* ?? temporaire, requis par netlist.h */
 
 #include "input.h"
-#include "input_netlist.h"
 #include "decoder_fifo.h"
 #include "video.h"
 #include "video_output.h"
 #include "video_parser.h"
 #include "video_fifo.h"
 
+#define __MotionComponents(width,height)               \
+void MotionComponent_x_y_copy_##width##_##height ();   \
+void MotionComponent_X_y_copy_##width##_##height ();   \
+void MotionComponent_x_Y_copy_##width##_##height ();   \
+void MotionComponent_X_Y_copy_##width##_##height ();   \
+void MotionComponent_x_y_avg_##width##_##height ();    \
+void MotionComponent_X_y_avg_##width##_##height ();    \
+void MotionComponent_x_Y_avg_##width##_##height ();    \
+void MotionComponent_X_Y_avg_##width##_##height ();
+
+__MotionComponents (16,16)     /* 444, 422, 420 */
+__MotionComponents (16,8)      /* 444, 422, 420 */
+__MotionComponents (8,8)       /* 422, 420 */
+__MotionComponents (8,4)       /* 420 */
+#if 0
+__MotionComponents (8,16)      /* 422 */
+#endif
+
+#define ___callTheRightOne(width,height)                                    \
+    if ((i_width == width) && (i_height == height))                         \
+    {                                                                       \
+       if (!b_average)                                                      \
+       {                                                                    \
+           switch (i_select)                                                \
+           {                                                                \
+           case 0:                                                          \
+               MotionComponent_x_y_copy_##width##_##height (p_src, p_dest,  \
+                                                            i_stride);      \
+               break;                                                       \
+           case 1:                                                          \
+               MotionComponent_X_y_copy_##width##_##height (p_src, p_dest,  \
+                                                            i_stride);      \
+               break;                                                       \
+           case 2:                                                          \
+               MotionComponent_x_Y_copy_##width##_##height (p_src, p_dest,  \
+                                                            i_stride,       \
+                                                            i_step);        \
+               break;                                                       \
+           case 3:                                                          \
+               MotionComponent_X_Y_copy_##width##_##height (p_src, p_dest,  \
+                                                            i_stride,       \
+                                                            i_step);        \
+               break;                                                       \
+           }                                                                \
+       }                                                                    \
+       else                                                                 \
+       {                                                                    \
+           switch (i_select)                                                \
+           {                                                                \
+           case 0:                                                          \
+               MotionComponent_x_y_avg_##width##_##height (p_src, p_dest,   \
+                                                           i_stride);       \
+               break;                                                       \
+           case 1:                                                          \
+               MotionComponent_X_y_avg_##width##_##height (p_src, p_dest,   \
+                                                           i_stride);       \
+               break;                                                       \
+           case 2:                                                          \
+               MotionComponent_x_Y_avg_##width##_##height (p_src, p_dest,   \
+                                                           i_stride,        \
+                                                           i_step);         \
+               break;                                                       \
+           case 3:                                                          \
+               MotionComponent_X_Y_avg_##width##_##height (p_src, p_dest,   \
+                                                           i_stride,        \
+                                                           i_step);         \
+               break;                                                       \
+           }                                                                \
+       }                                                                    \
+    }
+
 /*****************************************************************************
  * vdec_MotionComponent : last stage of motion compensation
  *****************************************************************************/
@@ -54,175 +139,13 @@ static __inline__ void MotionComponent(
                     boolean_t b_average     /* (explicit) averaging of several
                                              * predictions */ )
 {
-    int i_x, i_y, i_x1;
-    unsigned int i_dummy;
-
-    if( !b_average )
-    {
-        /* Please note that b_average will be expanded at compile time */
-
-        switch( i_select )
-        {
-        case 0:
-            /* !xh, !yh, !average */
-            for( i_y = 0; i_y < i_height; i_y ++ )
-            {
-                    for( i_x = 0; i_x < i_width; i_x += 8 )
-                    {
-                         for( i_x1 = 0; i_x1 < 8; i_x1++ )
-                         {
-                             p_dest[i_x+i_x1] = p_src[i_x+i_x1];
-                         }
-                    }
-                    p_dest += i_stride;
-                    p_src += i_stride;
-            }
-            break;
-
-        case 1:
-            /* xh, !yh, !average */
-            for( i_y = 0; i_y < i_height; i_y ++ )
-            {
-                    for( i_x = 0; i_x < i_width; i_x += 8 )
-                    {
-                         for( i_x1 = 0; i_x1 < 8; i_x1++ )
-                         {
-                             p_dest[i_x+i_x1] = (unsigned int)(p_src[i_x+i_x1]
-                                                      + p_src[i_x+i_x1 + 1] + 1)
-                                                    >> 1;
-                         }
-                    }
-                    p_dest += i_stride;
-                    p_src += i_stride;
-            }
-            break;
-
-        case 2:
-            /* !xh, yh, !average */
-            for( i_y = 0; i_y < i_height; i_y ++ )
-            {
-                    for( i_x = 0; i_x < i_width; i_x += 8 )
-                    {
-                         for( i_x1 = 0; i_x1 < 8; i_x1++ )
-                         {
-                             p_dest[i_x+i_x1] = (unsigned int)(p_src[i_x+i_x1] + 1
-                                                + p_src[i_x+i_x1 + i_step])
-                                              >> 1;
-                         }
-                    }
-                    p_dest += i_stride;
-                    p_src += i_stride;
-            }
-            break;
-
-        case 3:
-            /* xh, yh, !average (3) */
-            for( i_y = 0; i_y < i_height; i_y ++ )
-            {
-                    for( i_x = 0; i_x < i_width; i_x += 8 )
-                    {
-                         for( i_x1 = 0; i_x1 < 8; i_x1++ )
-                         {
-                             p_dest[i_x+i_x1]
-                                = ((unsigned int)(
-                                      p_src[i_x+i_x1]
-                                    + p_src[i_x+i_x1 + 1]
-                                    + p_src[i_x+i_x1 + i_step]
-                                    + p_src[i_x+i_x1 + i_step + 1]
-                                    + 2) >> 2);
-                         }
-                    }
-                    p_dest += i_stride;
-                    p_src += i_stride;
-            }
-            break;
-        }
-
-    }
-    else
-    {
-        /* b_average */
-        switch( i_select )
-        {
-        case 0:
-            /* !xh, !yh, average */
-            for( i_y = 0; i_y < i_height; i_y ++ )
-            {
-                    for( i_x = 0; i_x < i_width; i_x += 8 )
-                    {
-                         for( i_x1 = 0; i_x1 < 8; i_x1++ )
-                         {
-                             i_dummy = p_dest[i_x + i_x1] + p_src[i_x + i_x1];
-                             p_dest[i_x + i_x1] = (i_dummy + 1) >> 1;
-                         }
-                    }
-                    p_dest += i_stride;
-                    p_src += i_stride;
-            }
-            break;
-
-        case 1:
-            /* xh, !yh, average */
-            for( i_y = 0; i_y < i_height; i_y ++ )
-            {
-                    for( i_x = 0; i_x < i_width; i_x += 8 )
-                    {
-                         for( i_x1 = 0; i_x1 < 8; i_x1++ )
-                         {
-                             i_dummy = p_dest[i_x+i_x1]
-                                + ((unsigned int)(p_src[i_x+i_x1]
-                                                  + p_src[i_x+i_x1 + 1] + 1) >> 1);
-                             p_dest[i_x + i_x1] = (i_dummy + 1) >> 1;
-                         }
-                    }
-                    p_dest += i_stride;
-                    p_src += i_stride;
-            }
-            break;
-
-        case 2:
-            /* !xh, yh, average */
-            for( i_y = 0; i_y < i_height; i_y ++ )
-            {
-                    for( i_x = 0; i_x < i_width; i_x += 8 )
-                    {
-                         for( i_x1 = 0; i_x1 < 8; i_x1++ )
-                         {
-                             i_dummy = p_dest[i_x+i_x1]
-                                + ((unsigned int)(p_src[i_x+i_x1] + 1
-                                         + p_src[i_x+i_x1 + i_step]) >> 1);
-                             p_dest[i_x + i_x1] = (i_dummy + 1) >> 1;
-                         }
-                    }
-                    p_dest += i_stride;
-                    p_src += i_stride;
-            }
-            break;
-
-        case 3:
-            /* xh, yh, average */
-            for( i_y = 0; i_y < i_height; i_y ++ )
-            {
-                    for( i_x = 0; i_x < i_width; i_x += 8 )
-                    {
-                         for( i_x1 = 0; i_x1 < 8; i_x1++ )
-                         {
-                             i_dummy = p_dest[i_x+i_x1]
-                                + ((unsigned int)(
-                                      p_src[i_x+i_x1]
-                                    + p_src[i_x+i_x1 + 1]
-                                    + p_src[i_x+i_x1 + i_step]
-                                    + p_src[i_x+i_x1 + i_step + 1]
-                                    + 2) >> 2);
-                             p_dest[i_x + i_x1] = (i_dummy + 1) >> 1;
-                         }
-                    }
-                    p_dest += i_stride;
-                    p_src += i_stride;
-            }
-            break;
-        }
-    }
+___callTheRightOne (16,16)
+___callTheRightOne (16,8)
+___callTheRightOne (8,8)
+___callTheRightOne (8,4)
+#if 0
+___callTheRightOne (8,16)
+#endif
 }
 
 /*****************************************************************************
@@ -257,7 +180,7 @@ static __inline__ void Motion420(
                          * p_mb->p_picture->i_width;
     if( i_source_offset >= p_source->i_width * p_source->i_height )
     {
-        fprintf( stderr, "vdec error: bad motion vector\n" );
+        intf_ErrMsg( "vdec error: bad motion vector\n" );
         return;
     }
 
@@ -284,7 +207,7 @@ static __inline__ void Motion420(
                           * p_mb->p_picture->i_chroma_width;
     if( i_source_offset >= (p_source->i_width * p_source->i_height) / 4 )
     {
-        fprintf( stderr, "vdec error: bad motion vector\n" );
+        intf_ErrMsg( "vdec error: bad motion vector\n" );
         return;
     }
 
@@ -503,7 +426,7 @@ void vdec_MotionFieldField444( macroblock_t * p_mb )
 }
 
 /*****************************************************************************
- * vdec_MotionField16x8XXX : motion compensation for 16x8 motion type (field)
+ * vdec_MotionField16x8XXX: motion compensation for 16x8 motion type (field)
  *****************************************************************************/
 #define FIELD16X8( MOTION )                                             \
 {                                                                       \
@@ -585,7 +508,7 @@ void vdec_MotionField16x8444( macroblock_t * p_mb )
 }
 
 /*****************************************************************************
- * vdec_MotionFieldDMVXXX : motion compensation for dmv motion type (field)
+ * vdec_MotionFieldDMVXXX?? : motion compensation for dmv motion type (field)
  *****************************************************************************/
 #define FIELDDMV( MOTION )                                              \
 {                                                                       \
@@ -627,7 +550,7 @@ void vdec_MotionFieldDMV444( macroblock_t * p_mb )
 }
 
 /*****************************************************************************
- * vdec_MotionFrameFrameXXX : motion compensation for frame motion type (frame)
+ * vdec_MotionFrameFrameXXX?? : motion compensation for frame motion type (frame)
  *****************************************************************************/
 #define FRAMEFRAME( MOTION )                                            \
 {                                                                       \
@@ -672,7 +595,7 @@ void vdec_MotionFrameFrame444( macroblock_t * p_mb )
 }
 
 /*****************************************************************************
- * vdec_MotionFrameFieldXXX : motion compensation for field motion type (frame)
+ * vdec_MotionFrameFieldXXX?? : motion compensation for field motion type (frame)
  *****************************************************************************/
 #define FRAMEFIELD( MOTION )                                            \
 {                                                                       \
@@ -737,7 +660,7 @@ void vdec_MotionFrameField444( macroblock_t * p_mb )
 }
 
 /*****************************************************************************
- * vdec_MotionFrameDMVXXX : motion compensation for dmv motion type (frame)
+ * vdec_MotionFrameDMVXXX?? : motion compensation for dmv motion type (frame)
  *****************************************************************************/
 #define FRAMEDMV( MOTION )                                              \
 {                                                                       \
@@ -748,7 +671,7 @@ void vdec_MotionFrameField444( macroblock_t * p_mb )
     MOTION( p_mb, p_mb->p_forward, 0, 0,                                \
             p_mb->pppi_motion_vectors[0][0][0],                         \
             p_mb->pppi_motion_vectors[0][0][1],                         \
-            /* ????? >> 1 ? */                                          \
+            /* XXX?? XXX?? >> 1 ? */                                        \
             p_mb->i_l_stride << 1, p_mb->i_c_stride << 1, 8, 0, 0 );    \
                                                                         \
     /* predict and add to top field from bottom field */                \
@@ -760,7 +683,7 @@ void vdec_MotionFrameField444( macroblock_t * p_mb )
     MOTION( p_mb, p_mb->p_forward, 1, 1,                                \
             p_mb->pppi_motion_vectors[0][0][0],                         \
             p_mb->pppi_motion_vectors[0][0][1],                         \
-            /* ????? >> 1 ? */                                          \
+            /* XXX?? XXX?? >> 1 ? */                                        \
             p_mb->i_l_stride << 1, p_mb->i_c_stride << 1, 8, 0, 0 );    \
                                                                         \
     /* predict and add to bottom field from top field */                \