X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Fmotion_est.c;h=047fbd669797d111101d5a93b104a2b0cd6d4a68;hb=7cd7d19e86f98a0806429a623bb0b010a24ce93a;hp=b97b4413051b32a7d92d95ae0266532e285f8339;hpb=540c5220ffafce9038b1f0c96cb02382d0ab126e;p=ffmpeg diff --git a/libavcodec/motion_est.c b/libavcodec/motion_est.c index b97b4413051..047fbd66979 100644 --- a/libavcodec/motion_est.c +++ b/libavcodec/motion_est.c @@ -1,6 +1,6 @@ /* * Motion estimation - * Copyright (c) 2000,2001 Fabrice Bellard. + * Copyright (c) 2000,2001 Fabrice Bellard * Copyright (c) 2002-2004 Michael Niedermayer * * new motion estimation (X1/EPZS) by Michael Niedermayer @@ -23,7 +23,7 @@ */ /** - * @file motion_est.c + * @file libavcodec/motion_est.c * Motion estimation. */ @@ -32,6 +32,7 @@ #include #include "avcodec.h" #include "dsputil.h" +#include "mathops.h" #include "mpegvideo.h" #undef NDEBUG @@ -231,7 +232,7 @@ static int zero_cmp(void *s, uint8_t *a, uint8_t *b, int stride, int h){ static void zero_hpel(uint8_t *a, const uint8_t *b, int stride, int h){ } -void ff_init_me(MpegEncContext *s){ +int ff_init_me(MpegEncContext *s){ MotionEstContext * const c= &s->me; int cache_size= FFMIN(ME_MAP_SIZE>>ME_MAP_SHIFT, 1<avctx->dia_size)&255, FFABS(s->avctx->pre_dia_size)&255); @@ -240,6 +241,11 @@ void ff_init_me(MpegEncContext *s){ av_log(s->avctx, AV_LOG_ERROR, "ME_MAP size is too small for SAB diamond\n"); return -1; } + //special case of snow is needed because snow uses its own iterative ME code + if(s->me_method!=ME_ZERO && s->me_method!=ME_EPZS && s->me_method!=ME_X1 && s->avctx->codec_id != CODEC_ID_SNOW){ + av_log(s->avctx, AV_LOG_ERROR, "me_method is only allowed to be set to zero and epzs; for hex,umh,full and others see dia_size\n"); + return -1; + } c->avctx= s->avctx; @@ -302,7 +308,7 @@ void ff_init_me(MpegEncContext *s){ c->sub_motion_search= no_sub_motion_search; } - c->temp= c->scratchpad; + return 0; } #if 0 @@ -336,229 +342,6 @@ static inline void no_motion_search(MpegEncContext * s, *my_ptr = 16 * s->mb_y; } -#if 0 /* the use of these functions is inside #if 0 */ -static int full_motion_search(MpegEncContext * s, - int *mx_ptr, int *my_ptr, int range, - int xmin, int ymin, int xmax, int ymax, uint8_t *ref_picture) -{ - int x1, y1, x2, y2, xx, yy, x, y; - int mx, my, dmin, d; - uint8_t *pix; - - xx = 16 * s->mb_x; - yy = 16 * s->mb_y; - x1 = xx - range + 1; /* we loose one pixel to avoid boundary pb with half pixel pred */ - if (x1 < xmin) - x1 = xmin; - x2 = xx + range - 1; - if (x2 > xmax) - x2 = xmax; - y1 = yy - range + 1; - if (y1 < ymin) - y1 = ymin; - y2 = yy + range - 1; - if (y2 > ymax) - y2 = ymax; - pix = s->new_picture.data[0] + (yy * s->linesize) + xx; - dmin = 0x7fffffff; - mx = 0; - my = 0; - for (y = y1; y <= y2; y++) { - for (x = x1; x <= x2; x++) { - d = s->dsp.pix_abs[0][0](NULL, pix, ref_picture + (y * s->linesize) + x, - s->linesize, 16); - if (d < dmin || - (d == dmin && - (abs(x - xx) + abs(y - yy)) < - (abs(mx - xx) + abs(my - yy)))) { - dmin = d; - mx = x; - my = y; - } - } - } - - *mx_ptr = mx; - *my_ptr = my; - -#if 0 - if (*mx_ptr < -(2 * range) || *mx_ptr >= (2 * range) || - *my_ptr < -(2 * range) || *my_ptr >= (2 * range)) { - av_log(NULL, AV_LOG_ERROR, "error %d %d\n", *mx_ptr, *my_ptr); - } -#endif - return dmin; -} - - -static int log_motion_search(MpegEncContext * s, - int *mx_ptr, int *my_ptr, int range, - int xmin, int ymin, int xmax, int ymax, uint8_t *ref_picture) -{ - int x1, y1, x2, y2, xx, yy, x, y; - int mx, my, dmin, d; - uint8_t *pix; - - xx = s->mb_x << 4; - yy = s->mb_y << 4; - - /* Left limit */ - x1 = xx - range; - if (x1 < xmin) - x1 = xmin; - - /* Right limit */ - x2 = xx + range; - if (x2 > xmax) - x2 = xmax; - - /* Upper limit */ - y1 = yy - range; - if (y1 < ymin) - y1 = ymin; - - /* Lower limit */ - y2 = yy + range; - if (y2 > ymax) - y2 = ymax; - - pix = s->new_picture.data[0] + (yy * s->linesize) + xx; - dmin = 0x7fffffff; - mx = 0; - my = 0; - - do { - for (y = y1; y <= y2; y += range) { - for (x = x1; x <= x2; x += range) { - d = s->dsp.pix_abs[0][0](NULL, pix, ref_picture + (y * s->linesize) + x, s->linesize, 16); - if (d < dmin || (d == dmin && (abs(x - xx) + abs(y - yy)) < (abs(mx - xx) + abs(my - yy)))) { - dmin = d; - mx = x; - my = y; - } - } - } - - range = range >> 1; - - x1 = mx - range; - if (x1 < xmin) - x1 = xmin; - - x2 = mx + range; - if (x2 > xmax) - x2 = xmax; - - y1 = my - range; - if (y1 < ymin) - y1 = ymin; - - y2 = my + range; - if (y2 > ymax) - y2 = ymax; - - } while (range >= 1); - -#ifdef DEBUG - av_log(s->avctx, AV_LOG_DEBUG, "log - MX: %d\tMY: %d\n", mx, my); -#endif - *mx_ptr = mx; - *my_ptr = my; - return dmin; -} - -static int phods_motion_search(MpegEncContext * s, - int *mx_ptr, int *my_ptr, int range, - int xmin, int ymin, int xmax, int ymax, uint8_t *ref_picture) -{ - int x1, y1, x2, y2, xx, yy, x, y, lastx, d; - int mx, my, dminx, dminy; - uint8_t *pix; - - xx = s->mb_x << 4; - yy = s->mb_y << 4; - - /* Left limit */ - x1 = xx - range; - if (x1 < xmin) - x1 = xmin; - - /* Right limit */ - x2 = xx + range; - if (x2 > xmax) - x2 = xmax; - - /* Upper limit */ - y1 = yy - range; - if (y1 < ymin) - y1 = ymin; - - /* Lower limit */ - y2 = yy + range; - if (y2 > ymax) - y2 = ymax; - - pix = s->new_picture.data[0] + (yy * s->linesize) + xx; - mx = 0; - my = 0; - - x = xx; - y = yy; - do { - dminx = 0x7fffffff; - dminy = 0x7fffffff; - - lastx = x; - for (x = x1; x <= x2; x += range) { - d = s->dsp.pix_abs[0][0](NULL, pix, ref_picture + (y * s->linesize) + x, s->linesize, 16); - if (d < dminx || (d == dminx && (abs(x - xx) + abs(y - yy)) < (abs(mx - xx) + abs(my - yy)))) { - dminx = d; - mx = x; - } - } - - x = lastx; - for (y = y1; y <= y2; y += range) { - d = s->dsp.pix_abs[0][0](NULL, pix, ref_picture + (y * s->linesize) + x, s->linesize, 16); - if (d < dminy || (d == dminy && (abs(x - xx) + abs(y - yy)) < (abs(mx - xx) + abs(my - yy)))) { - dminy = d; - my = y; - } - } - - range = range >> 1; - - x = mx; - y = my; - x1 = mx - range; - if (x1 < xmin) - x1 = xmin; - - x2 = mx + range; - if (x2 > xmax) - x2 = xmax; - - y1 = my - range; - if (y1 < ymin) - y1 = ymin; - - y2 = my + range; - if (y2 > ymax) - y2 = ymax; - - } while (range >= 1); - -#ifdef DEBUG - av_log(s->avctx, AV_LOG_DEBUG, "phods - MX: %d\tMY: %d\n", mx, my); -#endif - - /* half pixel search */ - *mx_ptr = mx; - *my_ptr = my; - return dminy; -} -#endif /* 0 */ - #define Z_THRESHOLD 256 #define CHECK_SAD_HALF_MV(suffix, x, y) \ @@ -1223,23 +1006,6 @@ void ff_estimate_p_frame_motion(MpegEncContext * s, my-= mb_y*16; dmin = 0; break; -#if 0 - case ME_FULL: - dmin = full_motion_search(s, &mx, &my, range, ref_picture); - mx-= mb_x*16; - my-= mb_y*16; - break; - case ME_LOG: - dmin = log_motion_search(s, &mx, &my, range / 2, ref_picture); - mx-= mb_x*16; - my-= mb_y*16; - break; - case ME_PHODS: - dmin = phods_motion_search(s, &mx, &my, range / 2, ref_picture); - mx-= mb_x*16; - my-= mb_y*16; - break; -#endif case ME_X1: case ME_EPZS: { @@ -1511,23 +1277,6 @@ static int ff_estimate_motion_b(MpegEncContext * s, mx-= mb_x*16; my-= mb_y*16; break; -#if 0 - case ME_FULL: - dmin = full_motion_search(s, &mx, &my, range, ref_picture); - mx-= mb_x*16; - my-= mb_y*16; - break; - case ME_LOG: - dmin = log_motion_search(s, &mx, &my, range / 2, ref_picture); - mx-= mb_x*16; - my-= mb_y*16; - break; - case ME_PHODS: - dmin = phods_motion_search(s, &mx, &my, range / 2, ref_picture); - mx-= mb_x*16; - my-= mb_y*16; - break; -#endif case ME_X1: case ME_EPZS: {