Zypher's amd64 patch.
[melted] / src / modules / motion_est / filter_motion_est.c
index 1b0058d..734f048 100644 (file)
@@ -3,7 +3,7 @@
  *     /author Zachary Drew, Copyright 2005
  *
  *     Currently only uses Gamma data for comparisonon (bug or feature?)
- *     Vector optimization coming soon. 
+ *     SSE optimized where available.
  *
  *     Vector orientation: The vector data that is generated for the current frame specifies
  *     the motion from the previous frame to the current frame. To know how a macroblock
@@ -34,7 +34,9 @@
 #include <sys/time.h>
 #include <unistd.h>
 
+#ifndef __DARWIN__
 #include "sad_sse.h"
+#endif
 
 #define NDEBUG
 #include <assert.h>
@@ -51,8 +53,6 @@
 #define ABS(a) ((a) >= 0 ? (a) : (-(a)))
 
 
-typedef struct motion_vector_s motion_vector;
-
 struct motion_est_context_s
 {
        int initialized;                                // true if filter has been initialized
@@ -160,7 +160,7 @@ inline static int constrain(        int *x, int *y, int *w, int *h,
 /** /brief Reference Sum of Absolute Differences comparison function
 *
 */
-inline static int sad_reference( uint8_t *block1, uint8_t *block2, const int xstride, const int ystride, const int w, const int h )
+static int sad_reference( uint8_t *block1, uint8_t *block2, const int xstride, const int ystride, const int w, const int h )
 {
        int i, j, score = 0;
        for ( j = 0; j < h; j++ ){
@@ -290,6 +290,8 @@ static inline void diamond_search(
 
        // Keep track of best and former best candidates
        motion_vector best, former;
+       former.dx = 0;
+       former.dy = 0;
 
        // The direction of the refinement needs to be known
        motion_vector current;
@@ -610,7 +612,9 @@ static void motion_search( uint8_t *from,                   //<! Image data.
         } /* End column loop */
        } /* End row loop */
 
+#ifndef __DARWIN__
        asm volatile ( "emms" );
+#endif
 
 #ifdef COUNT_COMPARES
        fprintf(stderr, "%d comparisons per block were made", compares/count);
@@ -652,6 +656,7 @@ void collect_post_statistics( struct motion_est_context_s *c ) {
 static void init_optimizations( struct motion_est_context_s *c )
 {
        switch(c->mb_w){
+#ifndef __DARWIN__
                case 4:  if(c->mb_h == 4)       c->compare_optimized = sad_sse_422_luma_4x4;
                         else                           c->compare_optimized = sad_sse_422_luma_4w;
                         break;
@@ -666,6 +671,7 @@ static void init_optimizations( struct motion_est_context_s *c )
                         break;
                case 64: c->compare_optimized = sad_sse_422_luma_64w;
                         break;
+#endif
                default: c->compare_optimized = sad_reference;
                         break;
        }
@@ -1033,6 +1039,10 @@ static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format
 
        mlt_properties_set_int( MLT_FRAME_PROPERTIES( frame ), "motion_est.macroblock_width", c->mb_w );
        mlt_properties_set_int( MLT_FRAME_PROPERTIES( frame ), "motion_est.macroblock_height", c->mb_h );
+       mlt_properties_set_int( MLT_FRAME_PROPERTIES( frame ), "motion_est.left_mb", c->left_mb );
+       mlt_properties_set_int( MLT_FRAME_PROPERTIES( frame ), "motion_est.right_mb", c->right_mb );
+       mlt_properties_set_int( MLT_FRAME_PROPERTIES( frame ), "motion_est.top_mb", c->top_mb );
+       mlt_properties_set_int( MLT_FRAME_PROPERTIES( frame ), "motion_est.bottom_mb", c->bottom_mb );
 
        #ifdef BENCHMARK
        struct timeval finish; gettimeofday(&finish, NULL ); int difference = (finish.tv_sec - start.tv_sec) * 1000000 + (finish.tv_usec - start.tv_usec);