| OLD | NEW | 
|---|
| 1 /* | 1 /* | 
| 2  *  Copyright (c) 2010 The WebM project authors. All Rights Reserved. | 2  *  Copyright (c) 2010 The WebM project authors. All Rights Reserved. | 
| 3  * | 3  * | 
| 4  *  Use of this source code is governed by a BSD-style license | 4  *  Use of this source code is governed by a BSD-style license | 
| 5  *  that can be found in the LICENSE file in the root of the source | 5  *  that can be found in the LICENSE file in the root of the source | 
| 6  *  tree. An additional intellectual property rights grant can be found | 6  *  tree. An additional intellectual property rights grant can be found | 
| 7  *  in the file PATENTS.  All contributing project authors may | 7  *  in the file PATENTS.  All contributing project authors may | 
| 8  *  be found in the AUTHORS file in the root of the source tree. | 8  *  be found in the AUTHORS file in the root of the source tree. | 
| 9  */ | 9  */ | 
| 10 | 10 | 
| 11 | 11 | 
| 12 #include "mcomp.h" | 12 #include "mcomp.h" | 
| 13 #include "vpx_mem/vpx_mem.h" | 13 #include "vpx_mem/vpx_mem.h" | 
| 14 | 14 #include "vpx_ports/config.h" | 
| 15 #include <stdio.h> | 15 #include <stdio.h> | 
| 16 #include <limits.h> | 16 #include <limits.h> | 
| 17 #include <math.h> | 17 #include <math.h> | 
|  | 18 #include "vp8/common/findnearmv.h" | 
| 18 | 19 | 
| 19 #ifdef ENTROPY_STATS | 20 #ifdef ENTROPY_STATS | 
| 20 static int mv_ref_ct [31] [4] [2]; | 21 static int mv_ref_ct [31] [4] [2]; | 
| 21 static int mv_mode_cts [4] [2]; | 22 static int mv_mode_cts [4] [2]; | 
| 22 #endif | 23 #endif | 
| 23 | 24 | 
| 24 static int mv_bits_sadcost[256]; | 25 int vp8_mv_bit_cost(int_mv *mv, int_mv *ref, int *mvcost[2], int Weight) | 
| 25 |  | 
| 26 void vp8cx_init_mv_bits_sadcost() |  | 
| 27 { |  | 
| 28     int i; |  | 
| 29 |  | 
| 30     for (i = 0; i < 256; i++) |  | 
| 31     { |  | 
| 32         mv_bits_sadcost[i] = (int)sqrt(i * 16); |  | 
| 33     } |  | 
| 34 } |  | 
| 35 |  | 
| 36 |  | 
| 37 int vp8_mv_bit_cost(MV *mv, MV *ref, int *mvcost[2], int Weight) |  | 
| 38 { | 26 { | 
| 39     // MV costing is based on the distribution of vectors in the previous frame 
      and as such will tend to | 27     // MV costing is based on the distribution of vectors in the previous frame 
      and as such will tend to | 
| 40     // over state the cost of vectors. In addition coding a new vector can have 
      a knock on effect on the | 28     // over state the cost of vectors. In addition coding a new vector can have 
      a knock on effect on the | 
| 41     // cost of subsequent vectors and the quality of prediction from NEAR and NE
      AREST for subsequent blocks. | 29     // cost of subsequent vectors and the quality of prediction from NEAR and NE
      AREST for subsequent blocks. | 
| 42     // The "Weight" parameter allows, to a limited extent, for some account to b
      e taken of these factors. | 30     // The "Weight" parameter allows, to a limited extent, for some account to b
      e taken of these factors. | 
| 43     return ((mvcost[0][(mv->row - ref->row) >> 1] + mvcost[1][(mv->col - ref->co
      l) >> 1]) * Weight) >> 7; | 31     return ((mvcost[0][(mv->as_mv.row - ref->as_mv.row) >> 1] + mvcost[1][(mv->a
      s_mv.col - ref->as_mv.col) >> 1]) * Weight) >> 7; | 
| 44 } | 32 } | 
| 45 | 33 | 
| 46 static int mv_err_cost(MV *mv, MV *ref, int *mvcost[2], int error_per_bit) | 34 static int mv_err_cost(int_mv *mv, int_mv *ref, int *mvcost[2], int error_per_bi
      t) | 
| 47 { | 35 { | 
| 48     //int i; | 36     return ((mvcost[0][(mv->as_mv.row - ref->as_mv.row) >> 1] + | 
| 49     //return ((mvcost[0][(mv->row - ref->row)>>1] + mvcost[1][(mv->col - ref->co
      l)>>1] + 128) * error_per_bit) >> 8; | 37         mvcost[1][(mv->as_mv.col - ref->as_mv.col) >> 1]) | 
| 50     //return ( (vp8_mv_bit_cost(mv,  ref, mvcost, 100) + 128) * error_per_bit) >
      > 8; | 38         * error_per_bit + 128) >> 8; | 
| 51 |  | 
| 52     //i = (vp8_mv_bit_cost(mv,  ref, mvcost, 100) * error_per_bit + 128) >> 8; |  | 
| 53     return ((mvcost[0][(mv->row - ref->row) >> 1] + mvcost[1][(mv->col - ref->co
      l) >> 1]) * error_per_bit + 128) >> 8; |  | 
| 54     //return (vp8_mv_bit_cost(mv,  ref, mvcost, 128) * error_per_bit + 128) >> 8
      ; |  | 
| 55 } | 39 } | 
| 56 | 40 | 
| 57 | 41 static int mvsad_err_cost(int_mv *mv, int_mv *ref, int *mvsadcost[2], int error_
      per_bit) | 
| 58 static int mv_bits(MV *mv, MV *ref, int *mvcost[2]) |  | 
| 59 { | 42 { | 
| 60     // get the estimated number of bits for a motion vector, to be used for cost
      ing in SAD based | 43     /* Calculate sad error cost on full pixel basis. */ | 
| 61     // motion estimation | 44     return ((mvsadcost[0][(mv->as_mv.row - ref->as_mv.row)] + | 
| 62     return ((mvcost[0][(mv->row - ref->row) >> 1]  +  mvcost[1][(mv->col - ref->
      col)>> 1]) + 128) >> 8; | 45         mvsadcost[1][(mv->as_mv.col - ref->as_mv.col)]) | 
|  | 46         * error_per_bit + 128) >> 8; | 
| 63 } | 47 } | 
| 64 | 48 | 
| 65 void vp8_init_dsmotion_compensation(MACROBLOCK *x, int stride) | 49 void vp8_init_dsmotion_compensation(MACROBLOCK *x, int stride) | 
| 66 { | 50 { | 
| 67     int Len; | 51     int Len; | 
| 68     int search_site_count = 0; | 52     int search_site_count = 0; | 
| 69 | 53 | 
| 70 | 54 | 
| 71     // Generate offsets for 4 search sites per step. | 55     // Generate offsets for 4 search sites per step. | 
| 72     Len = MAX_FIRST_STEP; | 56     Len = MAX_FIRST_STEP; | 
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 175 | 159 | 
| 176 | 160 | 
| 177         // Contract. | 161         // Contract. | 
| 178         Len /= 2; | 162         Len /= 2; | 
| 179     } | 163     } | 
| 180 | 164 | 
| 181     x->ss_count = search_site_count; | 165     x->ss_count = search_site_count; | 
| 182     x->searches_per_step = 8; | 166     x->searches_per_step = 8; | 
| 183 } | 167 } | 
| 184 | 168 | 
| 185 | 169 /* | 
|  | 170  * To avoid the penalty for crossing cache-line read, preload the reference | 
|  | 171  * area in a small buffer, which is aligned to make sure there won't be crossing | 
|  | 172  * cache-line read while reading from this buffer. This reduced the cpu | 
|  | 173  * cycles spent on reading ref data in sub-pixel filter functions. | 
|  | 174  * TODO: Currently, since sub-pixel search range here is -3 ~ 3, copy 22 rows x | 
|  | 175  * 32 cols area that is enough for 16x16 macroblock. Later, for SPLITMV, we | 
|  | 176  * could reduce the area. | 
|  | 177  */ | 
| 186 #define MVC(r,c) (((mvcost[0][(r)-rr] + mvcost[1][(c) - rc]) * error_per_bit + 1
      28 )>>8 ) // estimated cost of a motion vector (r,c) | 178 #define MVC(r,c) (((mvcost[0][(r)-rr] + mvcost[1][(c) - rc]) * error_per_bit + 1
      28 )>>8 ) // estimated cost of a motion vector (r,c) | 
| 187 #define PRE(r,c) (*(d->base_pre) + d->pre + ((r)>>2) * d->pre_stride + ((c)>>2))
       // pointer to predictor base of a motionvector | 179 #define PRE(r,c) (y + (((r)>>2) * y_stride + ((c)>>2) -(offset))) // pointer to 
      predictor base of a motionvector | 
| 188 #define SP(x) (((x)&3)<<1) // convert motion vector component to offset for svf 
      calc | 180 #define SP(x) (((x)&3)<<1) // convert motion vector component to offset for svf 
      calc | 
| 189 #define DIST(r,c) vfp->svf( PRE(r,c), d->pre_stride, SP(c),SP(r), z,b->src_strid
      e,&sse) // returns subpixel variance error function. | 181 #define DIST(r,c) vfp->svf( PRE(r,c), y_stride, SP(c),SP(r), z,b->src_stride,&ss
      e) // returns subpixel variance error function. | 
| 190 #define IFMVCV(r,c,s,e) if ( c >= minc && c <= maxc && r >= minr && r <= maxr) s
       else e; | 182 #define IFMVCV(r,c,s,e) if ( c >= minc && c <= maxc && r >= minr && r <= maxr) s
       else e; | 
| 191 #define ERR(r,c) (MVC(r,c)+DIST(r,c)) // returns distortion + motion vector cost | 183 #define ERR(r,c) (MVC(r,c)+DIST(r,c)) // returns distortion + motion vector cost | 
| 192 #define CHECK_BETTER(v,r,c) IFMVCV(r,c,{if((v = ERR(r,c)) < besterr) { besterr =
       v; br=r; bc=c; }}, v=INT_MAX;)// checks if (r,c) has better score than previous
       best | 184 #define CHECK_BETTER(v,r,c) IFMVCV(r,c,{thismse = DIST(r,c); if((v = (MVC(r,c)+t
      hismse)) < besterr) { besterr = v; br=r; bc=c; *distortion = thismse; *sse1 = ss
      e; }}, v=INT_MAX;)// checks if (r,c) has better score than previous best | 
| 193 #define MIN(x,y) (((x)<(y))?(x):(y)) | 185 #define MIN(x,y) (((x)<(y))?(x):(y)) | 
| 194 #define MAX(x,y) (((x)>(y))?(x):(y)) | 186 #define MAX(x,y) (((x)>(y))?(x):(y)) | 
| 195 | 187 | 
| 196 //#define CHECK_BETTER(v,r,c) if((v = ERR(r,c)) < besterr) { besterr = v; br=r; 
      bc=c; } | 188 int vp8_find_best_sub_pixel_step_iteratively(MACROBLOCK *x, BLOCK *b, BLOCKD *d, | 
| 197 | 189                                              int_mv *bestmv, int_mv *ref_mv, | 
| 198 int vp8_find_best_sub_pixel_step_iteratively(MACROBLOCK *x, BLOCK *b, BLOCKD *d,
       MV *bestmv, MV *ref_mv, int error_per_bit, const vp8_variance_fn_ptr_t *vfp, in
      t *mvcost[2]) | 190                                              int error_per_bit, | 
|  | 191                                              const vp8_variance_fn_ptr_t *vfp, | 
|  | 192                                              int *mvcost[2], int *distortion, | 
|  | 193                                              unsigned int *sse1) | 
| 199 { | 194 { | 
| 200     unsigned char *y = *(d->base_pre) + d->pre + (bestmv->row) * d->pre_stride +
       bestmv->col; |  | 
| 201     unsigned char *z = (*(b->base_src) + b->src); | 195     unsigned char *z = (*(b->base_src) + b->src); | 
| 202 | 196 | 
| 203     int rr = ref_mv->row >> 1, rc = ref_mv->col >> 1; | 197     int rr = ref_mv->as_mv.row >> 1, rc = ref_mv->as_mv.col >> 1; | 
| 204     int br = bestmv->row << 2, bc = bestmv->col << 2; | 198     int br = bestmv->as_mv.row << 2, bc = bestmv->as_mv.col << 2; | 
| 205     int tr = br, tc = bc; | 199     int tr = br, tc = bc; | 
| 206     unsigned int besterr = INT_MAX; | 200     unsigned int besterr = INT_MAX; | 
| 207     unsigned int left, right, up, down, diag; | 201     unsigned int left, right, up, down, diag; | 
| 208     unsigned int sse; | 202     unsigned int sse; | 
| 209     unsigned int whichdir; | 203     unsigned int whichdir; | 
| 210     unsigned int halfiters = 4; | 204     unsigned int halfiters = 4; | 
| 211     unsigned int quarteriters = 4; | 205     unsigned int quarteriters = 4; | 
|  | 206     int thismse; | 
| 212 | 207 | 
| 213     int minc = MAX(x->mv_col_min << 2, (ref_mv->col >> 1) - ((1 << mvlong_width)
       - 1)); | 208     int minc = MAX(x->mv_col_min << 2, (ref_mv->as_mv.col >> 1) - ((1 << mvlong_
      width) - 1)); | 
| 214     int maxc = MIN(x->mv_col_max << 2, (ref_mv->col >> 1) + ((1 << mvlong_width)
       - 1)); | 209     int maxc = MIN(x->mv_col_max << 2, (ref_mv->as_mv.col >> 1) + ((1 << mvlong_
      width) - 1)); | 
| 215     int minr = MAX(x->mv_row_min << 2, (ref_mv->row >> 1) - ((1 << mvlong_width)
       - 1)); | 210     int minr = MAX(x->mv_row_min << 2, (ref_mv->as_mv.row >> 1) - ((1 << mvlong_
      width) - 1)); | 
| 216     int maxr = MIN(x->mv_row_max << 2, (ref_mv->row >> 1) + ((1 << mvlong_width)
       - 1)); | 211     int maxr = MIN(x->mv_row_max << 2, (ref_mv->as_mv.row >> 1) + ((1 << mvlong_
      width) - 1)); | 
|  | 212 | 
|  | 213     int y_stride; | 
|  | 214     int offset; | 
|  | 215 | 
|  | 216 #if ARCH_X86 || ARCH_X86_64 | 
|  | 217     MACROBLOCKD *xd = &x->e_mbd; | 
|  | 218     unsigned char *y0 = *(d->base_pre) + d->pre + (bestmv->as_mv.row) * d->pre_s
      tride + bestmv->as_mv.col; | 
|  | 219     unsigned char *y; | 
|  | 220     int buf_r1, buf_r2, buf_c1, buf_c2; | 
|  | 221 | 
|  | 222     // Clamping to avoid out-of-range data access | 
|  | 223     buf_r1 = ((bestmv->as_mv.row - 3) < x->mv_row_min)?(bestmv->as_mv.row - x->m
      v_row_min):3; | 
|  | 224     buf_r2 = ((bestmv->as_mv.row + 3) > x->mv_row_max)?(x->mv_row_max - bestmv->
      as_mv.row):3; | 
|  | 225     buf_c1 = ((bestmv->as_mv.col - 3) < x->mv_col_min)?(bestmv->as_mv.col - x->m
      v_col_min):3; | 
|  | 226     buf_c2 = ((bestmv->as_mv.col + 3) > x->mv_col_max)?(x->mv_col_max - bestmv->
      as_mv.col):3; | 
|  | 227     y_stride = 32; | 
|  | 228 | 
|  | 229     /* Copy to intermediate buffer before searching. */ | 
|  | 230     vfp->copymem(y0 - buf_c1 - d->pre_stride*buf_r1, d->pre_stride, xd->y_buf, y
      _stride, 16+buf_r1+buf_r2); | 
|  | 231     y = xd->y_buf + y_stride*buf_r1 +buf_c1; | 
|  | 232 #else | 
|  | 233     unsigned char *y = *(d->base_pre) + d->pre + (bestmv->as_mv.row) * d->pre_st
      ride + bestmv->as_mv.col; | 
|  | 234     y_stride = d->pre_stride; | 
|  | 235 #endif | 
|  | 236 | 
|  | 237     offset = (bestmv->as_mv.row) * y_stride + bestmv->as_mv.col; | 
| 217 | 238 | 
| 218     // central mv | 239     // central mv | 
| 219     bestmv->row <<= 3; | 240     bestmv->as_mv.row <<= 3; | 
| 220     bestmv->col <<= 3; | 241     bestmv->as_mv.col <<= 3; | 
| 221 | 242 | 
| 222     // calculate central point error | 243     // calculate central point error | 
| 223     besterr = vfp->vf(y, d->pre_stride, z, b->src_stride, &sse); | 244     besterr = vfp->vf(y, y_stride, z, b->src_stride, sse1); | 
|  | 245     *distortion = besterr; | 
| 224     besterr += mv_err_cost(bestmv, ref_mv, mvcost, error_per_bit); | 246     besterr += mv_err_cost(bestmv, ref_mv, mvcost, error_per_bit); | 
| 225 | 247 | 
| 226     // TODO: Each subsequent iteration checks at least one point in common with 
      the last iteration could be 2 ( if diag selected) | 248     // TODO: Each subsequent iteration checks at least one point in common with 
      the last iteration could be 2 ( if diag selected) | 
| 227     while (--halfiters) | 249     while (--halfiters) | 
| 228     { | 250     { | 
| 229         // 1/2 pel | 251         // 1/2 pel | 
| 230         CHECK_BETTER(left, tr, tc - 2); | 252         CHECK_BETTER(left, tr, tc - 2); | 
| 231         CHECK_BETTER(right, tr, tc + 2); | 253         CHECK_BETTER(right, tr, tc + 2); | 
| 232         CHECK_BETTER(up, tr - 2, tc); | 254         CHECK_BETTER(up, tr - 2, tc); | 
| 233         CHECK_BETTER(down, tr + 2, tc); | 255         CHECK_BETTER(down, tr + 2, tc); | 
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 286         } | 308         } | 
| 287 | 309 | 
| 288         // no reason to check the same one again. | 310         // no reason to check the same one again. | 
| 289         if (tr == br && tc == bc) | 311         if (tr == br && tc == bc) | 
| 290             break; | 312             break; | 
| 291 | 313 | 
| 292         tr = br; | 314         tr = br; | 
| 293         tc = bc; | 315         tc = bc; | 
| 294     } | 316     } | 
| 295 | 317 | 
| 296     bestmv->row = br << 1; | 318     bestmv->as_mv.row = br << 1; | 
| 297     bestmv->col = bc << 1; | 319     bestmv->as_mv.col = bc << 1; | 
| 298 | 320 | 
| 299     if ((abs(bestmv->col - ref_mv->col) > MAX_FULL_PEL_VAL) || (abs(bestmv->row 
      - ref_mv->row) > MAX_FULL_PEL_VAL)) | 321     if ((abs(bestmv->as_mv.col - ref_mv->as_mv.col) > (MAX_FULL_PEL_VAL<<3)) || | 
|  | 322         (abs(bestmv->as_mv.row - ref_mv->as_mv.row) > (MAX_FULL_PEL_VAL<<3))) | 
| 300         return INT_MAX; | 323         return INT_MAX; | 
| 301 | 324 | 
| 302     return besterr; | 325     return besterr; | 
| 303 } | 326 } | 
| 304 #undef MVC | 327 #undef MVC | 
| 305 #undef PRE | 328 #undef PRE | 
| 306 #undef SP | 329 #undef SP | 
| 307 #undef DIST | 330 #undef DIST | 
|  | 331 #undef IFMVCV | 
| 308 #undef ERR | 332 #undef ERR | 
| 309 #undef CHECK_BETTER | 333 #undef CHECK_BETTER | 
| 310 #undef MIN | 334 #undef MIN | 
| 311 #undef MAX | 335 #undef MAX | 
| 312 int vp8_find_best_sub_pixel_step(MACROBLOCK *x, BLOCK *b, BLOCKD *d, MV *bestmv,
       MV *ref_mv, int error_per_bit, const vp8_variance_fn_ptr_t *vfp, int *mvcost[2]
      ) | 336 int vp8_find_best_sub_pixel_step(MACROBLOCK *x, BLOCK *b, BLOCKD *d, | 
|  | 337                                  int_mv *bestmv, int_mv *ref_mv, | 
|  | 338                                  int error_per_bit, | 
|  | 339                                  const vp8_variance_fn_ptr_t *vfp, | 
|  | 340                                  int *mvcost[2], int *distortion, | 
|  | 341                                  unsigned int *sse1) | 
| 313 { | 342 { | 
| 314     int bestmse = INT_MAX; | 343     int bestmse = INT_MAX; | 
| 315     MV startmv; | 344     int_mv startmv; | 
| 316     //MV this_mv; | 345     int_mv this_mv; | 
| 317     MV this_mv; |  | 
| 318     unsigned char *y = *(d->base_pre) + d->pre + (bestmv->row) * d->pre_stride +
       bestmv->col; |  | 
| 319     unsigned char *z = (*(b->base_src) + b->src); | 346     unsigned char *z = (*(b->base_src) + b->src); | 
| 320     int left, right, up, down, diag; | 347     int left, right, up, down, diag; | 
| 321     unsigned int sse; | 348     unsigned int sse; | 
| 322     int whichdir ; | 349     int whichdir ; | 
|  | 350     int thismse; | 
|  | 351     int y_stride; | 
| 323 | 352 | 
|  | 353 #if ARCH_X86 || ARCH_X86_64 | 
|  | 354     MACROBLOCKD *xd = &x->e_mbd; | 
|  | 355     unsigned char *y0 = *(d->base_pre) + d->pre + (bestmv->as_mv.row) * d->pre_s
      tride + bestmv->as_mv.col; | 
|  | 356     unsigned char *y; | 
| 324 | 357 | 
| 325     // Trap uncodable vectors | 358     y_stride = 32; | 
| 326     if ((abs((bestmv->col << 3) - ref_mv->col) > MAX_FULL_PEL_VAL) || (abs((best
      mv->row << 3) - ref_mv->row) > MAX_FULL_PEL_VAL)) | 359     /* Copy 18 rows x 32 cols area to intermediate buffer before searching. */ | 
| 327     { | 360      vfp->copymem(y0 - 1 - d->pre_stride, d->pre_stride, xd->y_buf, y_stride, 18
      ); | 
| 328         bestmv->row <<= 3; | 361      y = xd->y_buf + y_stride + 1; | 
| 329         bestmv->col <<= 3; | 362 #else | 
| 330         return INT_MAX; | 363      unsigned char *y = *(d->base_pre) + d->pre + (bestmv->as_mv.row) * d->pre_s
      tride + bestmv->as_mv.col; | 
| 331     } | 364      y_stride = d->pre_stride; | 
|  | 365 #endif | 
| 332 | 366 | 
| 333     // central mv | 367     // central mv | 
| 334     bestmv->row <<= 3; | 368     bestmv->as_mv.row <<= 3; | 
| 335     bestmv->col <<= 3; | 369     bestmv->as_mv.col <<= 3; | 
| 336     startmv = *bestmv; | 370     startmv = *bestmv; | 
| 337 | 371 | 
| 338     // calculate central point error | 372     // calculate central point error | 
| 339     bestmse = vfp->vf(y, d->pre_stride, z, b->src_stride, &sse); | 373     bestmse = vfp->vf(y, y_stride, z, b->src_stride, sse1); | 
|  | 374     *distortion = bestmse; | 
| 340     bestmse += mv_err_cost(bestmv, ref_mv, mvcost, error_per_bit); | 375     bestmse += mv_err_cost(bestmv, ref_mv, mvcost, error_per_bit); | 
| 341 | 376 | 
| 342     // go left then right and check error | 377     // go left then right and check error | 
| 343     this_mv.row = startmv.row; | 378     this_mv.as_mv.row = startmv.as_mv.row; | 
| 344     this_mv.col = ((startmv.col - 8) | 4); | 379     this_mv.as_mv.col = ((startmv.as_mv.col - 8) | 4); | 
| 345     left = vfp->svf_halfpix_h(y - 1, d->pre_stride, z, b->src_stride, &sse); | 380     thismse = vfp->svf_halfpix_h(y - 1, y_stride, z, b->src_stride, &sse); | 
| 346     left += mv_err_cost(&this_mv, ref_mv, mvcost, error_per_bit); | 381     left = thismse + mv_err_cost(&this_mv, ref_mv, mvcost, error_per_bit); | 
| 347 | 382 | 
| 348     if (left < bestmse) | 383     if (left < bestmse) | 
| 349     { | 384     { | 
| 350         *bestmv = this_mv; | 385         *bestmv = this_mv; | 
| 351         bestmse = left; | 386         bestmse = left; | 
|  | 387         *distortion = thismse; | 
|  | 388         *sse1 = sse; | 
| 352     } | 389     } | 
| 353 | 390 | 
| 354     this_mv.col += 8; | 391     this_mv.as_mv.col += 8; | 
| 355     right = vfp->svf_halfpix_h(y, d->pre_stride, z, b->src_stride, &sse); | 392     thismse = vfp->svf_halfpix_h(y, y_stride, z, b->src_stride, &sse); | 
| 356     right += mv_err_cost(&this_mv, ref_mv, mvcost, error_per_bit); | 393     right = thismse + mv_err_cost(&this_mv, ref_mv, mvcost, error_per_bit); | 
| 357 | 394 | 
| 358     if (right < bestmse) | 395     if (right < bestmse) | 
| 359     { | 396     { | 
| 360         *bestmv = this_mv; | 397         *bestmv = this_mv; | 
| 361         bestmse = right; | 398         bestmse = right; | 
|  | 399         *distortion = thismse; | 
|  | 400         *sse1 = sse; | 
| 362     } | 401     } | 
| 363 | 402 | 
| 364     // go up then down and check error | 403     // go up then down and check error | 
| 365     this_mv.col = startmv.col; | 404     this_mv.as_mv.col = startmv.as_mv.col; | 
| 366     this_mv.row = ((startmv.row - 8) | 4); | 405     this_mv.as_mv.row = ((startmv.as_mv.row - 8) | 4); | 
| 367     up = vfp->svf_halfpix_v(y - d->pre_stride, d->pre_stride, z, b->src_stride, 
      &sse); | 406     thismse =  vfp->svf_halfpix_v(y - y_stride, y_stride, z, b->src_stride, &sse
      ); | 
| 368     up += mv_err_cost(&this_mv, ref_mv, mvcost, error_per_bit); | 407     up = thismse + mv_err_cost(&this_mv, ref_mv, mvcost, error_per_bit); | 
| 369 | 408 | 
| 370     if (up < bestmse) | 409     if (up < bestmse) | 
| 371     { | 410     { | 
| 372         *bestmv = this_mv; | 411         *bestmv = this_mv; | 
| 373         bestmse = up; | 412         bestmse = up; | 
|  | 413         *distortion = thismse; | 
|  | 414         *sse1 = sse; | 
| 374     } | 415     } | 
| 375 | 416 | 
| 376     this_mv.row += 8; | 417     this_mv.as_mv.row += 8; | 
| 377     down = vfp->svf_halfpix_v(y, d->pre_stride, z, b->src_stride, &sse); | 418     thismse = vfp->svf_halfpix_v(y, y_stride, z, b->src_stride, &sse); | 
| 378     down += mv_err_cost(&this_mv, ref_mv, mvcost, error_per_bit); | 419     down = thismse + mv_err_cost(&this_mv, ref_mv, mvcost, error_per_bit); | 
| 379 | 420 | 
| 380     if (down < bestmse) | 421     if (down < bestmse) | 
| 381     { | 422     { | 
| 382         *bestmv = this_mv; | 423         *bestmv = this_mv; | 
| 383         bestmse = down; | 424         bestmse = down; | 
|  | 425         *distortion = thismse; | 
|  | 426         *sse1 = sse; | 
| 384     } | 427     } | 
| 385 | 428 | 
| 386 | 429 | 
| 387     // now check 1 more diagonal | 430     // now check 1 more diagonal | 
| 388     whichdir = (left < right ? 0 : 1) + (up < down ? 0 : 2); | 431     whichdir = (left < right ? 0 : 1) + (up < down ? 0 : 2); | 
| 389     //for(whichdir =0;whichdir<4;whichdir++) | 432     //for(whichdir =0;whichdir<4;whichdir++) | 
| 390     //{ | 433     //{ | 
| 391     this_mv = startmv; | 434     this_mv = startmv; | 
| 392 | 435 | 
| 393     switch (whichdir) | 436     switch (whichdir) | 
| 394     { | 437     { | 
| 395     case 0: | 438     case 0: | 
| 396         this_mv.col = (this_mv.col - 8) | 4; | 439         this_mv.as_mv.col = (this_mv.as_mv.col - 8) | 4; | 
| 397         this_mv.row = (this_mv.row - 8) | 4; | 440         this_mv.as_mv.row = (this_mv.as_mv.row - 8) | 4; | 
| 398         diag = vfp->svf_halfpix_hv(y - 1 - d->pre_stride, d->pre_stride, z, b->s
      rc_stride, &sse); | 441         thismse = vfp->svf_halfpix_hv(y - 1 - y_stride, y_stride, z, b->src_stri
      de, &sse); | 
| 399         break; | 442         break; | 
| 400     case 1: | 443     case 1: | 
| 401         this_mv.col += 4; | 444         this_mv.as_mv.col += 4; | 
| 402         this_mv.row = (this_mv.row - 8) | 4; | 445         this_mv.as_mv.row = (this_mv.as_mv.row - 8) | 4; | 
| 403         diag = vfp->svf_halfpix_hv(y - d->pre_stride, d->pre_stride, z, b->src_s
      tride, &sse); | 446         thismse = vfp->svf_halfpix_hv(y - y_stride, y_stride, z, b->src_stride, 
      &sse); | 
| 404         break; | 447         break; | 
| 405     case 2: | 448     case 2: | 
| 406         this_mv.col = (this_mv.col - 8) | 4; | 449         this_mv.as_mv.col = (this_mv.as_mv.col - 8) | 4; | 
| 407         this_mv.row += 4; | 450         this_mv.as_mv.row += 4; | 
| 408         diag = vfp->svf_halfpix_hv(y - 1, d->pre_stride, z, b->src_stride, &sse)
      ; | 451         thismse = vfp->svf_halfpix_hv(y - 1, y_stride, z, b->src_stride, &sse); | 
| 409         break; | 452         break; | 
| 410     case 3: | 453     case 3: | 
| 411     default: | 454     default: | 
| 412         this_mv.col += 4; | 455         this_mv.as_mv.col += 4; | 
| 413         this_mv.row += 4; | 456         this_mv.as_mv.row += 4; | 
| 414         diag = vfp->svf_halfpix_hv(y, d->pre_stride, z, b->src_stride, &sse); | 457         thismse = vfp->svf_halfpix_hv(y, y_stride, z, b->src_stride, &sse); | 
| 415         break; | 458         break; | 
| 416     } | 459     } | 
| 417 | 460 | 
| 418     diag += mv_err_cost(&this_mv, ref_mv, mvcost, error_per_bit); | 461     diag = thismse + mv_err_cost(&this_mv, ref_mv, mvcost, error_per_bit); | 
| 419 | 462 | 
| 420     if (diag < bestmse) | 463     if (diag < bestmse) | 
| 421     { | 464     { | 
| 422         *bestmv = this_mv; | 465         *bestmv = this_mv; | 
| 423         bestmse = diag; | 466         bestmse = diag; | 
|  | 467         *distortion = thismse; | 
|  | 468         *sse1 = sse; | 
| 424     } | 469     } | 
| 425 | 470 | 
| 426 //  } | 471 //  } | 
| 427 | 472 | 
| 428 | 473 | 
| 429     // time to check quarter pels. | 474     // time to check quarter pels. | 
| 430     if (bestmv->row < startmv.row) | 475     if (bestmv->as_mv.row < startmv.as_mv.row) | 
| 431         y -= d->pre_stride; | 476         y -= y_stride; | 
| 432 | 477 | 
| 433     if (bestmv->col < startmv.col) | 478     if (bestmv->as_mv.col < startmv.as_mv.col) | 
| 434         y--; | 479         y--; | 
| 435 | 480 | 
| 436     startmv = *bestmv; | 481     startmv = *bestmv; | 
| 437 | 482 | 
| 438 | 483 | 
| 439 | 484 | 
| 440     // go left then right and check error | 485     // go left then right and check error | 
| 441     this_mv.row = startmv.row; | 486     this_mv.as_mv.row = startmv.as_mv.row; | 
| 442 | 487 | 
| 443     if (startmv.col & 7) | 488     if (startmv.as_mv.col & 7) | 
| 444     { | 489     { | 
| 445         this_mv.col = startmv.col - 2; | 490         this_mv.as_mv.col = startmv.as_mv.col - 2; | 
| 446         left = vfp->svf(y, d->pre_stride, this_mv.col & 7, this_mv.row & 7, z, b
      ->src_stride, &sse); | 491         thismse = vfp->svf(y, y_stride, this_mv.as_mv.col & 7, this_mv.as_mv.row
       & 7, z, b->src_stride, &sse); | 
| 447     } | 492     } | 
| 448     else | 493     else | 
| 449     { | 494     { | 
| 450         this_mv.col = (startmv.col - 8) | 6; | 495         this_mv.as_mv.col = (startmv.as_mv.col - 8) | 6; | 
| 451         left = vfp->svf(y - 1, d->pre_stride, 6, this_mv.row & 7, z, b->src_stri
      de, &sse); | 496         thismse = vfp->svf(y - 1, y_stride, 6, this_mv.as_mv.row & 7, z, b->src_
      stride, &sse); | 
| 452     } | 497     } | 
| 453 | 498 | 
| 454     left += mv_err_cost(&this_mv, ref_mv, mvcost, error_per_bit); | 499     left = thismse + mv_err_cost(&this_mv, ref_mv, mvcost, error_per_bit); | 
| 455 | 500 | 
| 456     if (left < bestmse) | 501     if (left < bestmse) | 
| 457     { | 502     { | 
| 458         *bestmv = this_mv; | 503         *bestmv = this_mv; | 
| 459         bestmse = left; | 504         bestmse = left; | 
|  | 505         *distortion = thismse; | 
|  | 506         *sse1 = sse; | 
| 460     } | 507     } | 
| 461 | 508 | 
| 462     this_mv.col += 4; | 509     this_mv.as_mv.col += 4; | 
| 463     right = vfp->svf(y, d->pre_stride, this_mv.col & 7, this_mv.row & 7, z, b->s
      rc_stride, &sse); | 510     thismse = vfp->svf(y, y_stride, this_mv.as_mv.col & 7, this_mv.as_mv.row & 7
      , z, b->src_stride, &sse); | 
| 464     right += mv_err_cost(&this_mv, ref_mv, mvcost, error_per_bit); | 511     right = thismse + mv_err_cost(&this_mv, ref_mv, mvcost, error_per_bit); | 
| 465 | 512 | 
| 466     if (right < bestmse) | 513     if (right < bestmse) | 
| 467     { | 514     { | 
| 468         *bestmv = this_mv; | 515         *bestmv = this_mv; | 
| 469         bestmse = right; | 516         bestmse = right; | 
|  | 517         *distortion = thismse; | 
|  | 518         *sse1 = sse; | 
| 470     } | 519     } | 
| 471 | 520 | 
| 472     // go up then down and check error | 521     // go up then down and check error | 
| 473     this_mv.col = startmv.col; | 522     this_mv.as_mv.col = startmv.as_mv.col; | 
| 474 | 523 | 
| 475     if (startmv.row & 7) | 524     if (startmv.as_mv.row & 7) | 
| 476     { | 525     { | 
| 477         this_mv.row = startmv.row - 2; | 526         this_mv.as_mv.row = startmv.as_mv.row - 2; | 
| 478         up = vfp->svf(y, d->pre_stride, this_mv.col & 7, this_mv.row & 7, z, b->
      src_stride, &sse); | 527         thismse = vfp->svf(y, y_stride, this_mv.as_mv.col & 7, this_mv.as_mv.row
       & 7, z, b->src_stride, &sse); | 
| 479     } | 528     } | 
| 480     else | 529     else | 
| 481     { | 530     { | 
| 482         this_mv.row = (startmv.row - 8) | 6; | 531         this_mv.as_mv.row = (startmv.as_mv.row - 8) | 6; | 
| 483         up = vfp->svf(y - d->pre_stride, d->pre_stride, this_mv.col & 7, 6, z, b
      ->src_stride, &sse); | 532         thismse = vfp->svf(y - y_stride, y_stride, this_mv.as_mv.col & 7, 6, z, 
      b->src_stride, &sse); | 
| 484     } | 533     } | 
| 485 | 534 | 
| 486     up += mv_err_cost(&this_mv, ref_mv, mvcost, error_per_bit); | 535     up = thismse + mv_err_cost(&this_mv, ref_mv, mvcost, error_per_bit); | 
| 487 | 536 | 
| 488     if (up < bestmse) | 537     if (up < bestmse) | 
| 489     { | 538     { | 
| 490         *bestmv = this_mv; | 539         *bestmv = this_mv; | 
| 491         bestmse = up; | 540         bestmse = up; | 
|  | 541         *distortion = thismse; | 
|  | 542         *sse1 = sse; | 
| 492     } | 543     } | 
| 493 | 544 | 
| 494     this_mv.row += 4; | 545     this_mv.as_mv.row += 4; | 
| 495     down = vfp->svf(y, d->pre_stride, this_mv.col & 7, this_mv.row & 7, z, b->sr
      c_stride, &sse); | 546     thismse = vfp->svf(y, y_stride, this_mv.as_mv.col & 7, this_mv.as_mv.row & 7
      , z, b->src_stride, &sse); | 
| 496     down += mv_err_cost(&this_mv, ref_mv, mvcost, error_per_bit); | 547     down = thismse + mv_err_cost(&this_mv, ref_mv, mvcost, error_per_bit); | 
| 497 | 548 | 
| 498     if (down < bestmse) | 549     if (down < bestmse) | 
| 499     { | 550     { | 
| 500         *bestmv = this_mv; | 551         *bestmv = this_mv; | 
| 501         bestmse = down; | 552         bestmse = down; | 
|  | 553         *distortion = thismse; | 
|  | 554         *sse1 = sse; | 
| 502     } | 555     } | 
| 503 | 556 | 
| 504 | 557 | 
| 505     // now check 1 more diagonal | 558     // now check 1 more diagonal | 
| 506     whichdir = (left < right ? 0 : 1) + (up < down ? 0 : 2); | 559     whichdir = (left < right ? 0 : 1) + (up < down ? 0 : 2); | 
| 507 | 560 | 
| 508 //  for(whichdir=0;whichdir<4;whichdir++) | 561 //  for(whichdir=0;whichdir<4;whichdir++) | 
| 509 //  { | 562 //  { | 
| 510     this_mv = startmv; | 563     this_mv = startmv; | 
| 511 | 564 | 
| 512     switch (whichdir) | 565     switch (whichdir) | 
| 513     { | 566     { | 
| 514     case 0: | 567     case 0: | 
| 515 | 568 | 
| 516         if (startmv.row & 7) | 569         if (startmv.as_mv.row & 7) | 
| 517         { | 570         { | 
| 518             this_mv.row -= 2; | 571             this_mv.as_mv.row -= 2; | 
| 519 | 572 | 
| 520             if (startmv.col & 7) | 573             if (startmv.as_mv.col & 7) | 
| 521             { | 574             { | 
| 522                 this_mv.col -= 2; | 575                 this_mv.as_mv.col -= 2; | 
| 523                 diag = vfp->svf(y, d->pre_stride, this_mv.col & 7, this_mv.row &
       7, z, b->src_stride, &sse); | 576                 thismse = vfp->svf(y, y_stride, this_mv.as_mv.col & 7, this_mv.a
      s_mv.row & 7, z, b->src_stride, &sse); | 
| 524             } | 577             } | 
| 525             else | 578             else | 
| 526             { | 579             { | 
| 527                 this_mv.col = (startmv.col - 8) | 6; | 580                 this_mv.as_mv.col = (startmv.as_mv.col - 8) | 6; | 
| 528                 diag = vfp->svf(y - 1, d->pre_stride, 6, this_mv.row & 7, z, b->
      src_stride, &sse);; | 581                 thismse = vfp->svf(y - 1, y_stride, 6, this_mv.as_mv.row & 7, z,
       b->src_stride, &sse);; | 
| 529             } | 582             } | 
| 530         } | 583         } | 
| 531         else | 584         else | 
| 532         { | 585         { | 
| 533             this_mv.row = (startmv.row - 8) | 6; | 586             this_mv.as_mv.row = (startmv.as_mv.row - 8) | 6; | 
| 534 | 587 | 
| 535             if (startmv.col & 7) | 588             if (startmv.as_mv.col & 7) | 
| 536             { | 589             { | 
| 537                 this_mv.col -= 2; | 590                 this_mv.as_mv.col -= 2; | 
| 538                 diag = vfp->svf(y - d->pre_stride, d->pre_stride, this_mv.col & 
      7, 6, z, b->src_stride, &sse); | 591                 thismse = vfp->svf(y - y_stride, y_stride, this_mv.as_mv.col & 7
      , 6, z, b->src_stride, &sse); | 
| 539             } | 592             } | 
| 540             else | 593             else | 
| 541             { | 594             { | 
| 542                 this_mv.col = (startmv.col - 8) | 6; | 595                 this_mv.as_mv.col = (startmv.as_mv.col - 8) | 6; | 
| 543                 diag = vfp->svf(y - d->pre_stride - 1, d->pre_stride, 6, 6, z, b
      ->src_stride, &sse); | 596                 thismse = vfp->svf(y - y_stride - 1, y_stride, 6, 6, z, b->src_s
      tride, &sse); | 
| 544             } | 597             } | 
| 545         } | 598         } | 
| 546 | 599 | 
| 547         break; | 600         break; | 
| 548     case 1: | 601     case 1: | 
| 549         this_mv.col += 2; | 602         this_mv.as_mv.col += 2; | 
| 550 | 603 | 
| 551         if (startmv.row & 7) | 604         if (startmv.as_mv.row & 7) | 
| 552         { | 605         { | 
| 553             this_mv.row -= 2; | 606             this_mv.as_mv.row -= 2; | 
| 554             diag = vfp->svf(y, d->pre_stride, this_mv.col & 7, this_mv.row & 7, 
      z, b->src_stride, &sse); | 607             thismse = vfp->svf(y, y_stride, this_mv.as_mv.col & 7, this_mv.as_mv
      .row & 7, z, b->src_stride, &sse); | 
| 555         } | 608         } | 
| 556         else | 609         else | 
| 557         { | 610         { | 
| 558             this_mv.row = (startmv.row - 8) | 6; | 611             this_mv.as_mv.row = (startmv.as_mv.row - 8) | 6; | 
| 559             diag = vfp->svf(y - d->pre_stride, d->pre_stride, this_mv.col & 7, 6
      , z, b->src_stride, &sse); | 612             thismse = vfp->svf(y - y_stride, y_stride, this_mv.as_mv.col & 7, 6,
       z, b->src_stride, &sse); | 
| 560         } | 613         } | 
| 561 | 614 | 
| 562         break; | 615         break; | 
| 563     case 2: | 616     case 2: | 
| 564         this_mv.row += 2; | 617         this_mv.as_mv.row += 2; | 
| 565 | 618 | 
| 566         if (startmv.col & 7) | 619         if (startmv.as_mv.col & 7) | 
| 567         { | 620         { | 
| 568             this_mv.col -= 2; | 621             this_mv.as_mv.col -= 2; | 
| 569             diag = vfp->svf(y, d->pre_stride, this_mv.col & 7, this_mv.row & 7, 
      z, b->src_stride, &sse); | 622             thismse = vfp->svf(y, y_stride, this_mv.as_mv.col & 7, this_mv.as_mv
      .row & 7, z, b->src_stride, &sse); | 
| 570         } | 623         } | 
| 571         else | 624         else | 
| 572         { | 625         { | 
| 573             this_mv.col = (startmv.col - 8) | 6; | 626             this_mv.as_mv.col = (startmv.as_mv.col - 8) | 6; | 
| 574             diag = vfp->svf(y - 1, d->pre_stride, 6, this_mv.row & 7, z, b->src_
      stride, &sse);; | 627             thismse = vfp->svf(y - 1, y_stride, 6, this_mv.as_mv.row & 7, z, b->
      src_stride, &sse); | 
| 575         } | 628         } | 
| 576 | 629 | 
| 577         break; | 630         break; | 
| 578     case 3: | 631     case 3: | 
| 579         this_mv.col += 2; | 632         this_mv.as_mv.col += 2; | 
| 580         this_mv.row += 2; | 633         this_mv.as_mv.row += 2; | 
| 581         diag = vfp->svf(y, d->pre_stride,  this_mv.col & 7, this_mv.row & 7, z, 
      b->src_stride, &sse); | 634         thismse = vfp->svf(y, y_stride,  this_mv.as_mv.col & 7, this_mv.as_mv.ro
      w & 7, z, b->src_stride, &sse); | 
| 582         break; | 635         break; | 
| 583     } | 636     } | 
| 584 | 637 | 
| 585     diag += mv_err_cost(&this_mv, ref_mv, mvcost, error_per_bit); | 638     diag = thismse + mv_err_cost(&this_mv, ref_mv, mvcost, error_per_bit); | 
| 586 | 639 | 
| 587     if (diag < bestmse) | 640     if (diag < bestmse) | 
| 588     { | 641     { | 
| 589         *bestmv = this_mv; | 642         *bestmv = this_mv; | 
| 590         bestmse = diag; | 643         bestmse = diag; | 
|  | 644         *distortion = thismse; | 
|  | 645         *sse1 = sse; | 
| 591     } | 646     } | 
| 592 | 647 | 
| 593 //  } |  | 
| 594 |  | 
| 595     return bestmse; | 648     return bestmse; | 
| 596 } | 649 } | 
| 597 | 650 | 
| 598 int vp8_find_best_half_pixel_step(MACROBLOCK *mb, BLOCK *b, BLOCKD *d, MV *bestm
      v, MV *ref_mv, int error_per_bit, const vp8_variance_fn_ptr_t *vfp, int *mvcost[
      2]) | 651 int vp8_find_best_half_pixel_step(MACROBLOCK *x, BLOCK *b, BLOCKD *d, | 
|  | 652                                   int_mv *bestmv, int_mv *ref_mv, | 
|  | 653                                   int error_per_bit, | 
|  | 654                                   const vp8_variance_fn_ptr_t *vfp, | 
|  | 655                                   int *mvcost[2], int *distortion, | 
|  | 656                                   unsigned int *sse1) | 
| 599 { | 657 { | 
| 600     int bestmse = INT_MAX; | 658     int bestmse = INT_MAX; | 
| 601     MV startmv; | 659     int_mv startmv; | 
| 602     //MV this_mv; | 660     int_mv this_mv; | 
| 603     MV this_mv; |  | 
| 604     unsigned char *y = *(d->base_pre) + d->pre + (bestmv->row) * d->pre_stride +
       bestmv->col; |  | 
| 605     unsigned char *z = (*(b->base_src) + b->src); | 661     unsigned char *z = (*(b->base_src) + b->src); | 
| 606     int left, right, up, down, diag; | 662     int left, right, up, down, diag; | 
| 607     unsigned int sse; | 663     unsigned int sse; | 
|  | 664     int thismse; | 
|  | 665     int y_stride; | 
| 608 | 666 | 
| 609     // Trap uncodable vectors | 667 #if ARCH_X86 || ARCH_X86_64 | 
| 610     if ((abs((bestmv->col << 3) - ref_mv->col) > MAX_FULL_PEL_VAL) || (abs((best
      mv->row << 3) - ref_mv->row) > MAX_FULL_PEL_VAL)) | 668     MACROBLOCKD *xd = &x->e_mbd; | 
| 611     { | 669     unsigned char *y0 = *(d->base_pre) + d->pre + (bestmv->as_mv.row) * d->pre_s
      tride + bestmv->as_mv.col; | 
| 612         bestmv->row <<= 3; | 670     unsigned char *y; | 
| 613         bestmv->col <<= 3; | 671 | 
| 614         return INT_MAX; | 672     y_stride = 32; | 
| 615     } | 673     /* Copy 18 rows x 32 cols area to intermediate buffer before searching. */ | 
|  | 674     vfp->copymem(y0 - 1 - d->pre_stride, d->pre_stride, xd->y_buf, y_stride, 18)
      ; | 
|  | 675     y = xd->y_buf + y_stride + 1; | 
|  | 676 #else | 
|  | 677     unsigned char *y = *(d->base_pre) + d->pre + (bestmv->as_mv.row) * d->pre_st
      ride + bestmv->as_mv.col; | 
|  | 678     y_stride = d->pre_stride; | 
|  | 679 #endif | 
| 616 | 680 | 
| 617     // central mv | 681     // central mv | 
| 618     bestmv->row <<= 3; | 682     bestmv->as_mv.row <<= 3; | 
| 619     bestmv->col <<= 3; | 683     bestmv->as_mv.col <<= 3; | 
| 620     startmv = *bestmv; | 684     startmv = *bestmv; | 
| 621 | 685 | 
| 622     // calculate central point error | 686     // calculate central point error | 
| 623     bestmse = vfp->vf(y, d->pre_stride, z, b->src_stride, &sse); | 687     bestmse = vfp->vf(y, y_stride, z, b->src_stride, sse1); | 
|  | 688     *distortion = bestmse; | 
| 624     bestmse += mv_err_cost(bestmv, ref_mv, mvcost, error_per_bit); | 689     bestmse += mv_err_cost(bestmv, ref_mv, mvcost, error_per_bit); | 
| 625 | 690 | 
| 626     // go left then right and check error | 691     // go left then right and check error | 
| 627     this_mv.row = startmv.row; | 692     this_mv.as_mv.row = startmv.as_mv.row; | 
| 628     this_mv.col = ((startmv.col - 8) | 4); | 693     this_mv.as_mv.col = ((startmv.as_mv.col - 8) | 4); | 
| 629     left = vfp->svf_halfpix_h(y - 1, d->pre_stride, z, b->src_stride, &sse); | 694     thismse = vfp->svf_halfpix_h(y - 1, y_stride, z, b->src_stride, &sse); | 
| 630     left += mv_err_cost(&this_mv, ref_mv, mvcost, error_per_bit); | 695     left = thismse + mv_err_cost(&this_mv, ref_mv, mvcost, error_per_bit); | 
| 631 | 696 | 
| 632     if (left < bestmse) | 697     if (left < bestmse) | 
| 633     { | 698     { | 
| 634         *bestmv = this_mv; | 699         *bestmv = this_mv; | 
| 635         bestmse = left; | 700         bestmse = left; | 
|  | 701         *distortion = thismse; | 
|  | 702         *sse1 = sse; | 
| 636     } | 703     } | 
| 637 | 704 | 
| 638     this_mv.col += 8; | 705     this_mv.as_mv.col += 8; | 
| 639     right = vfp->svf_halfpix_h(y, d->pre_stride, z, b->src_stride, &sse); | 706     thismse = vfp->svf_halfpix_h(y, y_stride, z, b->src_stride, &sse); | 
| 640     right += mv_err_cost(&this_mv, ref_mv, mvcost, error_per_bit); | 707     right = thismse + mv_err_cost(&this_mv, ref_mv, mvcost, error_per_bit); | 
| 641 | 708 | 
| 642     if (right < bestmse) | 709     if (right < bestmse) | 
| 643     { | 710     { | 
| 644         *bestmv = this_mv; | 711         *bestmv = this_mv; | 
| 645         bestmse = right; | 712         bestmse = right; | 
|  | 713         *distortion = thismse; | 
|  | 714         *sse1 = sse; | 
| 646     } | 715     } | 
| 647 | 716 | 
| 648     // go up then down and check error | 717     // go up then down and check error | 
| 649     this_mv.col = startmv.col; | 718     this_mv.as_mv.col = startmv.as_mv.col; | 
| 650     this_mv.row = ((startmv.row - 8) | 4); | 719     this_mv.as_mv.row = ((startmv.as_mv.row - 8) | 4); | 
| 651     up = vfp->svf_halfpix_v(y - d->pre_stride, d->pre_stride, z, b->src_stride, 
      &sse); | 720     thismse = vfp->svf_halfpix_v(y - y_stride, y_stride, z, b->src_stride, &sse)
      ; | 
| 652     up += mv_err_cost(&this_mv, ref_mv, mvcost, error_per_bit); | 721     up = thismse + mv_err_cost(&this_mv, ref_mv, mvcost, error_per_bit); | 
| 653 | 722 | 
| 654     if (up < bestmse) | 723     if (up < bestmse) | 
| 655     { | 724     { | 
| 656         *bestmv = this_mv; | 725         *bestmv = this_mv; | 
| 657         bestmse = up; | 726         bestmse = up; | 
|  | 727         *distortion = thismse; | 
|  | 728         *sse1 = sse; | 
| 658     } | 729     } | 
| 659 | 730 | 
| 660     this_mv.row += 8; | 731     this_mv.as_mv.row += 8; | 
| 661     down = vfp->svf_halfpix_v(y, d->pre_stride, z, b->src_stride, &sse); | 732     thismse = vfp->svf_halfpix_v(y, y_stride, z, b->src_stride, &sse); | 
| 662     down += mv_err_cost(&this_mv, ref_mv, mvcost, error_per_bit); | 733     down = thismse + mv_err_cost(&this_mv, ref_mv, mvcost, error_per_bit); | 
| 663 | 734 | 
| 664     if (down < bestmse) | 735     if (down < bestmse) | 
| 665     { | 736     { | 
| 666         *bestmv = this_mv; | 737         *bestmv = this_mv; | 
| 667         bestmse = down; | 738         bestmse = down; | 
|  | 739         *distortion = thismse; | 
|  | 740         *sse1 = sse; | 
| 668     } | 741     } | 
| 669 | 742 | 
| 670     // somewhat strangely not doing all the diagonals for half pel is slower tha
      n doing them. | 743     // somewhat strangely not doing all the diagonals for half pel is slower tha
      n doing them. | 
| 671 #if 0 | 744 #if 0 | 
| 672     // now check 1 more diagonal - | 745     // now check 1 more diagonal - | 
| 673     whichdir = (left < right ? 0 : 1) + (up < down ? 0 : 2); | 746     whichdir = (left < right ? 0 : 1) + (up < down ? 0 : 2); | 
| 674     this_mv = startmv; | 747     this_mv = startmv; | 
| 675 | 748 | 
| 676     switch (whichdir) | 749     switch (whichdir) | 
| 677     { | 750     { | 
| 678     case 0: | 751     case 0: | 
| 679         this_mv.col = (this_mv.col - 8) | 4; | 752         this_mv.col = (this_mv.col - 8) | 4; | 
| 680         this_mv.row = (this_mv.row - 8) | 4; | 753         this_mv.row = (this_mv.row - 8) | 4; | 
| 681         diag = vfp->svf(y - 1 - d->pre_stride, d->pre_stride, 4, 4, z, b->src_st
      ride, &sse); | 754         diag = vfp->svf(y - 1 - y_stride, y_stride, 4, 4, z, b->src_stride, &sse
      ); | 
| 682         break; | 755         break; | 
| 683     case 1: | 756     case 1: | 
| 684         this_mv.col += 4; | 757         this_mv.col += 4; | 
| 685         this_mv.row = (this_mv.row - 8) | 4; | 758         this_mv.row = (this_mv.row - 8) | 4; | 
| 686         diag = vfp->svf(y - d->pre_stride, d->pre_stride, 4, 4, z, b->src_stride
      , &sse); | 759         diag = vfp->svf(y - y_stride, y_stride, 4, 4, z, b->src_stride, &sse); | 
| 687         break; | 760         break; | 
| 688     case 2: | 761     case 2: | 
| 689         this_mv.col = (this_mv.col - 8) | 4; | 762         this_mv.col = (this_mv.col - 8) | 4; | 
| 690         this_mv.row += 4; | 763         this_mv.row += 4; | 
| 691         diag = vfp->svf(y - 1, d->pre_stride, 4, 4, z, b->src_stride, &sse); | 764         diag = vfp->svf(y - 1, y_stride, 4, 4, z, b->src_stride, &sse); | 
| 692         break; | 765         break; | 
| 693     case 3: | 766     case 3: | 
| 694         this_mv.col += 4; | 767         this_mv.col += 4; | 
| 695         this_mv.row += 4; | 768         this_mv.row += 4; | 
| 696         diag = vfp->svf(y, d->pre_stride, 4, 4, z, b->src_stride, &sse); | 769         diag = vfp->svf(y, y_stride, 4, 4, z, b->src_stride, &sse); | 
| 697         break; | 770         break; | 
| 698     } | 771     } | 
| 699 | 772 | 
| 700     diag += mv_err_cost(&this_mv, ref_mv, mvcost, error_per_bit); | 773     diag += mv_err_cost(&this_mv, ref_mv, mvcost, error_per_bit); | 
| 701 | 774 | 
| 702     if (diag < bestmse) | 775     if (diag < bestmse) | 
| 703     { | 776     { | 
| 704         *bestmv = this_mv; | 777         *bestmv = this_mv; | 
| 705         bestmse = diag; | 778         bestmse = diag; | 
| 706     } | 779     } | 
| 707 | 780 | 
| 708 #else | 781 #else | 
| 709     this_mv.col = (this_mv.col - 8) | 4; | 782     this_mv.as_mv.col = (this_mv.as_mv.col - 8) | 4; | 
| 710     this_mv.row = (this_mv.row - 8) | 4; | 783     this_mv.as_mv.row = (this_mv.as_mv.row - 8) | 4; | 
| 711     diag = vfp->svf_halfpix_hv(y - 1 - d->pre_stride, d->pre_stride, z, b->src_s
      tride, &sse); | 784     thismse = vfp->svf_halfpix_hv(y - 1 - y_stride, y_stride, z, b->src_stride, 
      &sse); | 
| 712     diag += mv_err_cost(&this_mv, ref_mv, mvcost, error_per_bit); | 785     diag = thismse + mv_err_cost(&this_mv, ref_mv, mvcost, error_per_bit); | 
| 713 | 786 | 
| 714     if (diag < bestmse) | 787     if (diag < bestmse) | 
| 715     { | 788     { | 
| 716         *bestmv = this_mv; | 789         *bestmv = this_mv; | 
| 717         bestmse = diag; | 790         bestmse = diag; | 
|  | 791         *distortion = thismse; | 
|  | 792         *sse1 = sse; | 
| 718     } | 793     } | 
| 719 | 794 | 
| 720     this_mv.col += 8; | 795     this_mv.as_mv.col += 8; | 
| 721     diag = vfp->svf_halfpix_hv(y - d->pre_stride, d->pre_stride, z, b->src_strid
      e, &sse); | 796     thismse = vfp->svf_halfpix_hv(y - y_stride, y_stride, z, b->src_stride, &sse
      ); | 
| 722     diag += mv_err_cost(&this_mv, ref_mv, mvcost, error_per_bit); | 797     diag = thismse + mv_err_cost(&this_mv, ref_mv, mvcost, error_per_bit); | 
| 723 | 798 | 
| 724     if (diag < bestmse) | 799     if (diag < bestmse) | 
| 725     { | 800     { | 
| 726         *bestmv = this_mv; | 801         *bestmv = this_mv; | 
| 727         bestmse = diag; | 802         bestmse = diag; | 
|  | 803         *distortion = thismse; | 
|  | 804         *sse1 = sse; | 
| 728     } | 805     } | 
| 729 | 806 | 
| 730     this_mv.col = (this_mv.col - 8) | 4; | 807     this_mv.as_mv.col = (this_mv.as_mv.col - 8) | 4; | 
| 731     this_mv.row = startmv.row + 4; | 808     this_mv.as_mv.row = startmv.as_mv.row + 4; | 
| 732     diag = vfp->svf_halfpix_hv(y - 1, d->pre_stride, z, b->src_stride, &sse); | 809     thismse = vfp->svf_halfpix_hv(y - 1, y_stride, z, b->src_stride, &sse); | 
| 733     diag += mv_err_cost(&this_mv, ref_mv, mvcost, error_per_bit); | 810     diag = thismse + mv_err_cost(&this_mv, ref_mv, mvcost, error_per_bit); | 
| 734 | 811 | 
| 735     if (diag < bestmse) | 812     if (diag < bestmse) | 
| 736     { | 813     { | 
| 737         *bestmv = this_mv; | 814         *bestmv = this_mv; | 
| 738         bestmse = diag; | 815         bestmse = diag; | 
|  | 816         *distortion = thismse; | 
|  | 817         *sse1 = sse; | 
| 739     } | 818     } | 
| 740 | 819 | 
| 741     this_mv.col += 8; | 820     this_mv.as_mv.col += 8; | 
| 742     diag = vfp->svf_halfpix_hv(y, d->pre_stride, z, b->src_stride, &sse); | 821     thismse = vfp->svf_halfpix_hv(y, y_stride, z, b->src_stride, &sse); | 
| 743     diag += mv_err_cost(&this_mv, ref_mv, mvcost, error_per_bit); | 822     diag = thismse + mv_err_cost(&this_mv, ref_mv, mvcost, error_per_bit); | 
| 744 | 823 | 
| 745     if (diag < bestmse) | 824     if (diag < bestmse) | 
| 746     { | 825     { | 
| 747         *bestmv = this_mv; | 826         *bestmv = this_mv; | 
| 748         bestmse = diag; | 827         bestmse = diag; | 
|  | 828         *distortion = thismse; | 
|  | 829         *sse1 = sse; | 
| 749     } | 830     } | 
| 750 | 831 | 
| 751 #endif | 832 #endif | 
| 752     return bestmse; | 833     return bestmse; | 
| 753 } | 834 } | 
| 754 | 835 | 
|  | 836 #define CHECK_BOUNDS(range) \ | 
|  | 837 {\ | 
|  | 838     all_in = 1;\ | 
|  | 839     all_in &= ((br-range) >= x->mv_row_min);\ | 
|  | 840     all_in &= ((br+range) <= x->mv_row_max);\ | 
|  | 841     all_in &= ((bc-range) >= x->mv_col_min);\ | 
|  | 842     all_in &= ((bc+range) <= x->mv_col_max);\ | 
|  | 843 } | 
| 755 | 844 | 
| 756 #define MVC(r,c) (((mvsadcost[0][((r)<<2)-rr] + mvsadcost[1][((c)<<2) - rc]) * e
      rror_per_bit + 128 )>>8 ) // estimated cost of a motion vector (r,c) | 845 #define CHECK_POINT \ | 
| 757 #define PRE(r,c) (*(d->base_pre) + d->pre + (r) * d->pre_stride + (c)) // pointe
      r to predictor base of a motionvector | 846 {\ | 
| 758 #define DIST(r,c,v) vfp->sdf( src,src_stride,PRE(r,c),d->pre_stride, v) // retur
      ns sad error score. | 847     if (this_mv.as_mv.col < x->mv_col_min) continue;\ | 
| 759 #define ERR(r,c,v) (MVC(r,c)+DIST(r,c,v)) // returns distortion + motion vector 
      cost | 848     if (this_mv.as_mv.col > x->mv_col_max) continue;\ | 
| 760 #define CHECK_BETTER(v,r,c) if ((v = ERR(r,c,besterr)) < besterr) { besterr = v;
       br=r; bc=c; } // checks if (r,c) has better score than previous best | 849     if (this_mv.as_mv.row < x->mv_row_min) continue;\ | 
|  | 850     if (this_mv.as_mv.row > x->mv_row_max) continue;\ | 
|  | 851 } | 
|  | 852 | 
|  | 853 #define CHECK_BETTER \ | 
|  | 854 {\ | 
|  | 855     if (thissad < bestsad)\ | 
|  | 856     {\ | 
|  | 857         thissad += mvsad_err_cost(&this_mv, &fcenter_mv, mvsadcost, sad_per_bit)
      ;\ | 
|  | 858         if (thissad < bestsad)\ | 
|  | 859         {\ | 
|  | 860             bestsad = thissad;\ | 
|  | 861             best_site = i;\ | 
|  | 862         }\ | 
|  | 863     }\ | 
|  | 864 } | 
|  | 865 | 
| 761 static const MV next_chkpts[6][3] = | 866 static const MV next_chkpts[6][3] = | 
| 762 { | 867 { | 
| 763     {{ -2, 0}, { -1, -2}, {1, -2}}, | 868     {{ -2, 0}, { -1, -2}, {1, -2}}, | 
| 764     {{ -1, -2}, {1, -2}, {2, 0}}, | 869     {{ -1, -2}, {1, -2}, {2, 0}}, | 
| 765     {{1, -2}, {2, 0}, {1, 2}}, | 870     {{1, -2}, {2, 0}, {1, 2}}, | 
| 766     {{2, 0}, {1, 2}, { -1, 2}}, | 871     {{2, 0}, {1, 2}, { -1, 2}}, | 
| 767     {{1, 2}, { -1, 2}, { -2, 0}}, | 872     {{1, 2}, { -1, 2}, { -2, 0}}, | 
| 768     {{ -1, 2}, { -2, 0}, { -1, -2}} | 873     {{ -1, 2}, { -2, 0}, { -1, -2}} | 
| 769 }; | 874 }; | 
|  | 875 | 
| 770 int vp8_hex_search | 876 int vp8_hex_search | 
| 771 ( | 877 ( | 
| 772     MACROBLOCK *x, | 878     MACROBLOCK *x, | 
| 773     BLOCK *b, | 879     BLOCK *b, | 
| 774     BLOCKD *d, | 880     BLOCKD *d, | 
| 775     MV *ref_mv, | 881     int_mv *ref_mv, | 
| 776     MV *best_mv, | 882     int_mv *best_mv, | 
| 777     int search_param, | 883     int search_param, | 
| 778     int error_per_bit, | 884     int sad_per_bit, | 
| 779     int *num00, |  | 
| 780     const vp8_variance_fn_ptr_t *vfp, | 885     const vp8_variance_fn_ptr_t *vfp, | 
| 781     int *mvsadcost[2], | 886     int *mvsadcost[2], | 
| 782     int *mvcost[2], | 887     int *mvcost[2], | 
| 783     MV *center_mv | 888     int_mv *center_mv | 
| 784 ) | 889 ) | 
| 785 { | 890 { | 
| 786     MV hex[6] = { { -1, -2}, {1, -2}, {2, 0}, {1, 2}, { -1, 2}, { -2, 0} } ; | 891     MV hex[6] = { { -1, -2}, {1, -2}, {2, 0}, {1, 2}, { -1, 2}, { -2, 0} } ; | 
| 787     MV neighbors[8] = { { -1, -1}, {0, -1}, {1, -1}, { -1, 0}, {1, 0}, { -1, 1},
       {0, 1}, {1, 1} } ; | 892     MV neighbors[4] = {{0, -1}, { -1, 0}, {1, 0}, {0, 1}} ; | 
| 788     int i, j; | 893     int i, j; | 
| 789     unsigned char *src = (*(b->base_src) + b->src); |  | 
| 790     int src_stride = b->src_stride; |  | 
| 791     int rr = center_mv->row, rc = center_mv->col; |  | 
| 792     int br = ref_mv->row >> 3, bc = ref_mv->col >> 3, tr, tc; |  | 
| 793     unsigned int besterr, thiserr = 0x7fffffff; |  | 
| 794     int k = -1, tk; |  | 
| 795 | 894 | 
| 796     if (bc < x->mv_col_min) bc = x->mv_col_min; | 895     unsigned char *what = (*(b->base_src) + b->src); | 
|  | 896     int what_stride = b->src_stride; | 
|  | 897     int in_what_stride = d->pre_stride; | 
|  | 898     int br, bc; | 
|  | 899     int_mv this_mv; | 
|  | 900     unsigned int bestsad = 0x7fffffff; | 
|  | 901     unsigned int thissad; | 
|  | 902     unsigned char *base_offset; | 
|  | 903     unsigned char *this_offset; | 
|  | 904     int k = -1; | 
|  | 905     int all_in; | 
|  | 906     int best_site = -1; | 
| 797 | 907 | 
| 798     if (bc > x->mv_col_max) bc = x->mv_col_max; | 908     int_mv fcenter_mv; | 
|  | 909     fcenter_mv.as_mv.row = center_mv->as_mv.row >> 3; | 
|  | 910     fcenter_mv.as_mv.col = center_mv->as_mv.col >> 3; | 
| 799 | 911 | 
| 800     if (br < x->mv_row_min) br = x->mv_row_min; | 912     // adjust ref_mv to make sure it is within MV range | 
|  | 913     vp8_clamp_mv(ref_mv, x->mv_col_min, x->mv_col_max, x->mv_row_min, x->mv_row_
      max); | 
|  | 914     br = ref_mv->as_mv.row; | 
|  | 915     bc = ref_mv->as_mv.col; | 
| 801 | 916 | 
| 802     if (br > x->mv_row_max) br = x->mv_row_max; | 917     // Work out the start point for the search | 
| 803 | 918     base_offset = (unsigned char *)(*(d->base_pre) + d->pre); | 
| 804     rr >>= 1; | 919     this_offset = base_offset + (br * (d->pre_stride)) + bc; | 
| 805     rc >>= 1; | 920     this_mv.as_mv.row = br; | 
| 806 | 921     this_mv.as_mv.col = bc; | 
| 807     besterr = ERR(br, bc, thiserr); | 922     bestsad = vfp->sdf( what, what_stride, this_offset, | 
|  | 923                         in_what_stride, 0x7fffffff) | 
|  | 924             + mvsad_err_cost(&this_mv, &fcenter_mv, mvsadcost, sad_per_bit); | 
| 808 | 925 | 
| 809     // hex search | 926     // hex search | 
| 810     //j=0 | 927     //j=0 | 
| 811     tr = br; | 928     CHECK_BOUNDS(2) | 
| 812     tc = bc; |  | 
| 813 | 929 | 
| 814     for (i = 0; i < 6; i++) | 930     if(all_in) | 
| 815     { | 931     { | 
| 816         int nr = tr + hex[i].row, nc = tc + hex[i].col; | 932         for (i = 0; i < 6; i++) | 
| 817 |  | 
| 818         if (nc < x->mv_col_min) continue; |  | 
| 819 |  | 
| 820         if (nc > x->mv_col_max) continue; |  | 
| 821 |  | 
| 822         if (nr < x->mv_row_min) continue; |  | 
| 823 |  | 
| 824         if (nr > x->mv_row_max) continue; |  | 
| 825 |  | 
| 826         //CHECK_BETTER(thiserr,nr,nc); |  | 
| 827         if ((thiserr = ERR(nr, nc, besterr)) < besterr) |  | 
| 828         { | 933         { | 
| 829             besterr = thiserr; | 934             this_mv.as_mv.row = br + hex[i].row; | 
| 830             br = nr; | 935             this_mv.as_mv.col = bc + hex[i].col; | 
| 831             bc = nc; | 936             this_offset = base_offset + (this_mv.as_mv.row * in_what_stride) + t
      his_mv.as_mv.col; | 
| 832             k = i; | 937             thissad=vfp->sdf( what, what_stride, this_offset, in_what_stride, be
      stsad); | 
|  | 938             CHECK_BETTER | 
|  | 939         } | 
|  | 940     }else | 
|  | 941     { | 
|  | 942         for (i = 0; i < 6; i++) | 
|  | 943         { | 
|  | 944             this_mv.as_mv.row = br + hex[i].row; | 
|  | 945             this_mv.as_mv.col = bc + hex[i].col; | 
|  | 946             CHECK_POINT | 
|  | 947             this_offset = base_offset + (this_mv.as_mv.row * in_what_stride) + t
      his_mv.as_mv.col; | 
|  | 948             thissad=vfp->sdf( what, what_stride, this_offset, in_what_stride, be
      stsad); | 
|  | 949             CHECK_BETTER | 
| 833         } | 950         } | 
| 834     } | 951     } | 
| 835 | 952 | 
| 836     if (tr == br && tc == bc) | 953     if (best_site == -1) | 
| 837         goto cal_neighbors; | 954         goto cal_neighbors; | 
|  | 955     else | 
|  | 956     { | 
|  | 957         br += hex[best_site].row; | 
|  | 958         bc += hex[best_site].col; | 
|  | 959         k = best_site; | 
|  | 960     } | 
| 838 | 961 | 
| 839     for (j = 1; j < 127; j++) | 962     for (j = 1; j < 127; j++) | 
| 840     { | 963     { | 
| 841         tr = br; | 964         best_site = -1; | 
| 842         tc = bc; | 965         CHECK_BOUNDS(2) | 
| 843         tk = k; |  | 
| 844 | 966 | 
| 845         for (i = 0; i < 3; i++) | 967         if(all_in) | 
| 846         { | 968         { | 
| 847             int nr = tr + next_chkpts[tk][i].row, nc = tc + next_chkpts[tk][i].c
      ol; | 969             for (i = 0; i < 3; i++) | 
| 848 |  | 
| 849             if (nc < x->mv_col_min) continue; |  | 
| 850 |  | 
| 851             if (nc > x->mv_col_max) continue; |  | 
| 852 |  | 
| 853             if (nr < x->mv_row_min) continue; |  | 
| 854 |  | 
| 855             if (nr > x->mv_row_max) continue; |  | 
| 856 |  | 
| 857             //CHECK_BETTER(thiserr,nr,nc); |  | 
| 858             if ((thiserr = ERR(nr, nc, besterr)) < besterr) |  | 
| 859             { | 970             { | 
| 860                 besterr = thiserr; | 971                 this_mv.as_mv.row = br + next_chkpts[k][i].row; | 
| 861                 br = nr; | 972                 this_mv.as_mv.col = bc + next_chkpts[k][i].col; | 
| 862                 bc = nc; //k=(tk+5+i)%6;} | 973                 this_offset = base_offset + (this_mv.as_mv.row * (in_what_stride
      )) + this_mv.as_mv.col; | 
| 863                 k = tk + 5 + i; | 974                 thissad = vfp->sdf( what, what_stride, this_offset, in_what_stri
      de, bestsad); | 
| 864 | 975                 CHECK_BETTER | 
| 865                 if (k >= 12) k -= 12; | 976             } | 
| 866                 else if (k >= 6) k -= 6; | 977         }else | 
|  | 978         { | 
|  | 979             for (i = 0; i < 3; i++) | 
|  | 980             { | 
|  | 981                 this_mv.as_mv.row = br + next_chkpts[k][i].row; | 
|  | 982                 this_mv.as_mv.col = bc + next_chkpts[k][i].col; | 
|  | 983                 CHECK_POINT | 
|  | 984                 this_offset = base_offset + (this_mv.as_mv.row * (in_what_stride
      )) + this_mv.as_mv.col; | 
|  | 985                 thissad = vfp->sdf( what, what_stride, this_offset, in_what_stri
      de, bestsad); | 
|  | 986                 CHECK_BETTER | 
| 867             } | 987             } | 
| 868         } | 988         } | 
| 869 | 989 | 
| 870         if (tr == br && tc == bc) | 990         if (best_site == -1) | 
| 871             break; | 991             break; | 
|  | 992         else | 
|  | 993         { | 
|  | 994             br += next_chkpts[k][best_site].row; | 
|  | 995             bc += next_chkpts[k][best_site].col; | 
|  | 996             k += 5 + best_site; | 
|  | 997             if (k >= 12) k -= 12; | 
|  | 998             else if (k >= 6) k -= 6; | 
|  | 999         } | 
| 872     } | 1000     } | 
| 873 | 1001 | 
| 874     // check 8 1 away neighbors | 1002     // check 4 1-away neighbors | 
| 875 cal_neighbors: | 1003 cal_neighbors: | 
| 876     tr = br; | 1004     for (j = 0; j < 32; j++) | 
| 877     tc = bc; | 1005     { | 
|  | 1006         best_site = -1; | 
|  | 1007         CHECK_BOUNDS(1) | 
| 878 | 1008 | 
| 879     for (i = 0; i < 8; i++) | 1009         if(all_in) | 
| 880     { | 1010         { | 
| 881         int nr = tr + neighbors[i].row, nc = tc + neighbors[i].col; | 1011             for (i = 0; i < 4; i++) | 
|  | 1012             { | 
|  | 1013                 this_mv.as_mv.row = br + neighbors[i].row; | 
|  | 1014                 this_mv.as_mv.col = bc + neighbors[i].col; | 
|  | 1015                 this_offset = base_offset + (this_mv.as_mv.row * (in_what_stride
      )) + this_mv.as_mv.col; | 
|  | 1016                 thissad = vfp->sdf( what, what_stride, this_offset, in_what_stri
      de, bestsad); | 
|  | 1017                 CHECK_BETTER | 
|  | 1018             } | 
|  | 1019         }else | 
|  | 1020         { | 
|  | 1021             for (i = 0; i < 4; i++) | 
|  | 1022             { | 
|  | 1023                 this_mv.as_mv.row = br + neighbors[i].row; | 
|  | 1024                 this_mv.as_mv.col = bc + neighbors[i].col; | 
|  | 1025                 CHECK_POINT | 
|  | 1026                 this_offset = base_offset + (this_mv.as_mv.row * (in_what_stride
      )) + this_mv.as_mv.col; | 
|  | 1027                 thissad = vfp->sdf( what, what_stride, this_offset, in_what_stri
      de, bestsad); | 
|  | 1028                 CHECK_BETTER | 
|  | 1029             } | 
|  | 1030         } | 
| 882 | 1031 | 
| 883         if (nc < x->mv_col_min) continue; | 1032         if (best_site == -1) | 
| 884 | 1033             break; | 
| 885         if (nc > x->mv_col_max) continue; | 1034         else | 
| 886 | 1035         { | 
| 887         if (nr < x->mv_row_min) continue; | 1036             br += neighbors[best_site].row; | 
| 888 | 1037             bc += neighbors[best_site].col; | 
| 889         if (nr > x->mv_row_max) continue; | 1038         } | 
| 890 |  | 
| 891         CHECK_BETTER(thiserr, nr, nc); |  | 
| 892     } | 1039     } | 
| 893 | 1040 | 
| 894     best_mv->row = br; | 1041     best_mv->as_mv.row = br; | 
| 895     best_mv->col = bc; | 1042     best_mv->as_mv.col = bc; | 
| 896 | 1043 | 
| 897     return vfp->vf(src, src_stride, PRE(br, bc), d->pre_stride, &thiserr) + mv_e
      rr_cost(best_mv, center_mv, mvcost, error_per_bit) ; | 1044     return bestsad; | 
| 898 } | 1045 } | 
| 899 #undef MVC | 1046 #undef CHECK_BOUNDS | 
| 900 #undef PRE | 1047 #undef CHECK_POINT | 
| 901 #undef SP |  | 
| 902 #undef DIST |  | 
| 903 #undef ERR |  | 
| 904 #undef CHECK_BETTER | 1048 #undef CHECK_BETTER | 
| 905 | 1049 | 
| 906 |  | 
| 907 int vp8_diamond_search_sad | 1050 int vp8_diamond_search_sad | 
| 908 ( | 1051 ( | 
| 909     MACROBLOCK *x, | 1052     MACROBLOCK *x, | 
| 910     BLOCK *b, | 1053     BLOCK *b, | 
| 911     BLOCKD *d, | 1054     BLOCKD *d, | 
| 912     MV *ref_mv, | 1055     int_mv *ref_mv, | 
| 913     MV *best_mv, | 1056     int_mv *best_mv, | 
| 914     int search_param, | 1057     int search_param, | 
| 915     int error_per_bit, | 1058     int sad_per_bit, | 
| 916     int *num00, | 1059     int *num00, | 
| 917     vp8_variance_fn_ptr_t *fn_ptr, | 1060     vp8_variance_fn_ptr_t *fn_ptr, | 
| 918     int *mvsadcost[2], |  | 
| 919     int *mvcost[2], | 1061     int *mvcost[2], | 
| 920     MV *center_mv | 1062     int_mv *center_mv | 
| 921 ) | 1063 ) | 
| 922 { | 1064 { | 
| 923     int i, j, step; | 1065     int i, j, step; | 
| 924 | 1066 | 
| 925     unsigned char *what = (*(b->base_src) + b->src); | 1067     unsigned char *what = (*(b->base_src) + b->src); | 
| 926     int what_stride = b->src_stride; | 1068     int what_stride = b->src_stride; | 
| 927     unsigned char *in_what; | 1069     unsigned char *in_what; | 
| 928     int in_what_stride = d->pre_stride; | 1070     int in_what_stride = d->pre_stride; | 
| 929     unsigned char *best_address; | 1071     unsigned char *best_address; | 
| 930 | 1072 | 
| 931     int tot_steps; | 1073     int tot_steps; | 
| 932     MV this_mv; | 1074     int_mv this_mv; | 
| 933 | 1075 | 
| 934     int bestsad = INT_MAX; | 1076     int bestsad = INT_MAX; | 
| 935     int best_site = 0; | 1077     int best_site = 0; | 
| 936     int last_site = 0; | 1078     int last_site = 0; | 
| 937 | 1079 | 
| 938     int ref_row = ref_mv->row >> 3; | 1080     int ref_row; | 
| 939     int ref_col = ref_mv->col >> 3; | 1081     int ref_col; | 
| 940     int this_row_offset; | 1082     int this_row_offset; | 
| 941     int this_col_offset; | 1083     int this_col_offset; | 
| 942     search_site *ss; | 1084     search_site *ss; | 
| 943 | 1085 | 
| 944     unsigned char *check_here; | 1086     unsigned char *check_here; | 
| 945     int thissad; | 1087     int thissad; | 
| 946 | 1088 | 
|  | 1089     int *mvsadcost[2] = {x->mvsadcost[0], x->mvsadcost[1]}; | 
|  | 1090     int_mv fcenter_mv; | 
|  | 1091     fcenter_mv.as_mv.row = center_mv->as_mv.row >> 3; | 
|  | 1092     fcenter_mv.as_mv.col = center_mv->as_mv.col >> 3; | 
|  | 1093 | 
|  | 1094     vp8_clamp_mv(ref_mv, x->mv_col_min, x->mv_col_max, x->mv_row_min, x->mv_row_
      max); | 
|  | 1095     ref_row = ref_mv->as_mv.row; | 
|  | 1096     ref_col = ref_mv->as_mv.col; | 
| 947     *num00 = 0; | 1097     *num00 = 0; | 
|  | 1098     best_mv->as_mv.row = ref_row; | 
|  | 1099     best_mv->as_mv.col = ref_col; | 
| 948 | 1100 | 
| 949     // Work out the start point for the search | 1101     // Work out the start point for the search | 
| 950     in_what = (unsigned char *)(*(d->base_pre) + d->pre + (ref_row * (d->pre_str
      ide)) + ref_col); | 1102     in_what = (unsigned char *)(*(d->base_pre) + d->pre + (ref_row * (d->pre_str
      ide)) + ref_col); | 
| 951     best_address = in_what; | 1103     best_address = in_what; | 
| 952 | 1104 | 
| 953     // We need to check that the starting point for the search (as indicated by 
      ref_mv) is within the buffer limits | 1105     // Check the starting position | 
| 954     if ((ref_col > x->mv_col_min) && (ref_col < x->mv_col_max) && | 1106     bestsad = fn_ptr->sdf(what, what_stride, in_what, | 
| 955     (ref_row > x->mv_row_min) && (ref_row < x->mv_row_max)) | 1107                           in_what_stride, 0x7fffffff) | 
| 956     { | 1108               + mvsad_err_cost(best_mv, &fcenter_mv, mvsadcost, sad_per_bit); | 
| 957         // Check the starting position |  | 
| 958         bestsad = fn_ptr->sdf(what, what_stride, in_what, in_what_stride, 0x7fff
      ffff) + mv_err_cost(ref_mv, center_mv, mvsadcost, error_per_bit); |  | 
| 959     } |  | 
| 960 | 1109 | 
| 961     // search_param determines the length of the initial step and hence the numb
      er of iterations | 1110     // search_param determines the length of the initial step and hence the numb
      er of iterations | 
| 962     // 0 = initial step (MAX_FIRST_STEP) pel : 1 = (MAX_FIRST_STEP/2) pel, 2 = (
      MAX_FIRST_STEP/4) pel... etc. | 1111     // 0 = initial step (MAX_FIRST_STEP) pel : 1 = (MAX_FIRST_STEP/2) pel, 2 = (
      MAX_FIRST_STEP/4) pel... etc. | 
| 963     ss = &x->ss[search_param * x->searches_per_step]; | 1112     ss = &x->ss[search_param * x->searches_per_step]; | 
| 964     tot_steps = (x->ss_count / x->searches_per_step) - search_param; | 1113     tot_steps = (x->ss_count / x->searches_per_step) - search_param; | 
| 965 | 1114 | 
| 966     i = 1; | 1115     i = 1; | 
| 967     best_mv->row = ref_row; |  | 
| 968     best_mv->col = ref_col; |  | 
| 969 | 1116 | 
| 970     for (step = 0; step < tot_steps ; step++) | 1117     for (step = 0; step < tot_steps ; step++) | 
| 971     { | 1118     { | 
| 972         for (j = 0 ; j < x->searches_per_step ; j++) | 1119         for (j = 0 ; j < x->searches_per_step ; j++) | 
| 973         { | 1120         { | 
| 974             // Trap illegal vectors | 1121             // Trap illegal vectors | 
| 975             this_row_offset = best_mv->row + ss[i].mv.row; | 1122             this_row_offset = best_mv->as_mv.row + ss[i].mv.row; | 
| 976             this_col_offset = best_mv->col + ss[i].mv.col; | 1123             this_col_offset = best_mv->as_mv.col + ss[i].mv.col; | 
| 977 | 1124 | 
| 978             if ((this_col_offset > x->mv_col_min) && (this_col_offset < x->mv_co
      l_max) && | 1125             if ((this_col_offset > x->mv_col_min) && (this_col_offset < x->mv_co
      l_max) && | 
| 979             (this_row_offset > x->mv_row_min) && (this_row_offset < x->mv_row_ma
      x)) | 1126             (this_row_offset > x->mv_row_min) && (this_row_offset < x->mv_row_ma
      x)) | 
| 980 | 1127 | 
| 981             { | 1128             { | 
| 982                 check_here = ss[i].offset + best_address; | 1129                 check_here = ss[i].offset + best_address; | 
| 983                 thissad = fn_ptr->sdf(what, what_stride, check_here , in_what_st
      ride, bestsad); | 1130                 thissad = fn_ptr->sdf(what, what_stride, check_here , in_what_st
      ride, bestsad); | 
| 984 | 1131 | 
| 985                 if (thissad < bestsad) | 1132                 if (thissad < bestsad) | 
| 986                 { | 1133                 { | 
| 987                     this_mv.row = this_row_offset << 3; | 1134                     this_mv.as_mv.row = this_row_offset; | 
| 988                     this_mv.col = this_col_offset << 3; | 1135                     this_mv.as_mv.col = this_col_offset; | 
| 989                     thissad += mv_err_cost(&this_mv, center_mv, mvsadcost, error
      _per_bit); | 1136                     thissad += mvsad_err_cost(&this_mv, &fcenter_mv, | 
|  | 1137                                                 mvsadcost, sad_per_bit); | 
| 990 | 1138 | 
| 991                     if (thissad < bestsad) | 1139                     if (thissad < bestsad) | 
| 992                     { | 1140                     { | 
| 993                         bestsad = thissad; | 1141                         bestsad = thissad; | 
| 994                         best_site = i; | 1142                         best_site = i; | 
| 995                     } | 1143                     } | 
| 996                 } | 1144                 } | 
| 997             } | 1145             } | 
| 998 | 1146 | 
| 999             i++; | 1147             i++; | 
| 1000         } | 1148         } | 
| 1001 | 1149 | 
| 1002         if (best_site != last_site) | 1150         if (best_site != last_site) | 
| 1003         { | 1151         { | 
| 1004             best_mv->row += ss[best_site].mv.row; | 1152             best_mv->as_mv.row += ss[best_site].mv.row; | 
| 1005             best_mv->col += ss[best_site].mv.col; | 1153             best_mv->as_mv.col += ss[best_site].mv.col; | 
| 1006             best_address += ss[best_site].offset; | 1154             best_address += ss[best_site].offset; | 
| 1007             last_site = best_site; | 1155             last_site = best_site; | 
| 1008         } | 1156         } | 
| 1009         else if (best_address == in_what) | 1157         else if (best_address == in_what) | 
| 1010             (*num00)++; | 1158             (*num00)++; | 
| 1011     } | 1159     } | 
| 1012 | 1160 | 
| 1013     this_mv.row = best_mv->row << 3; | 1161     this_mv.as_mv.row = best_mv->as_mv.row << 3; | 
| 1014     this_mv.col = best_mv->col << 3; | 1162     this_mv.as_mv.col = best_mv->as_mv.col << 3; | 
| 1015 | 1163 | 
| 1016     if (bestsad == INT_MAX) | 1164     if (bestsad == INT_MAX) | 
| 1017         return INT_MAX; | 1165         return INT_MAX; | 
| 1018 | 1166 | 
| 1019     return fn_ptr->vf(what, what_stride, best_address, in_what_stride, (unsigned
       int *)(&thissad)) | 1167     return fn_ptr->vf(what, what_stride, best_address, in_what_stride, (unsigned
       int *)(&thissad)) | 
| 1020     + mv_err_cost(&this_mv, center_mv, mvcost, error_per_bit); | 1168         + mv_err_cost(&this_mv, center_mv, mvcost, x->errorperbit); | 
| 1021 } | 1169 } | 
| 1022 | 1170 | 
| 1023 int vp8_diamond_search_sadx4 | 1171 int vp8_diamond_search_sadx4 | 
| 1024 ( | 1172 ( | 
| 1025     MACROBLOCK *x, | 1173     MACROBLOCK *x, | 
| 1026     BLOCK *b, | 1174     BLOCK *b, | 
| 1027     BLOCKD *d, | 1175     BLOCKD *d, | 
| 1028     MV *ref_mv, | 1176     int_mv *ref_mv, | 
| 1029     MV *best_mv, | 1177     int_mv *best_mv, | 
| 1030     int search_param, | 1178     int search_param, | 
| 1031     int error_per_bit, | 1179     int sad_per_bit, | 
| 1032     int *num00, | 1180     int *num00, | 
| 1033     vp8_variance_fn_ptr_t *fn_ptr, | 1181     vp8_variance_fn_ptr_t *fn_ptr, | 
| 1034     int *mvsadcost[2], |  | 
| 1035     int *mvcost[2], | 1182     int *mvcost[2], | 
| 1036     MV *center_mv | 1183     int_mv *center_mv | 
| 1037 ) | 1184 ) | 
| 1038 { | 1185 { | 
| 1039     int i, j, step; | 1186     int i, j, step; | 
| 1040 | 1187 | 
| 1041     unsigned char *what = (*(b->base_src) + b->src); | 1188     unsigned char *what = (*(b->base_src) + b->src); | 
| 1042     int what_stride = b->src_stride; | 1189     int what_stride = b->src_stride; | 
| 1043     unsigned char *in_what; | 1190     unsigned char *in_what; | 
| 1044     int in_what_stride = d->pre_stride; | 1191     int in_what_stride = d->pre_stride; | 
| 1045     unsigned char *best_address; | 1192     unsigned char *best_address; | 
| 1046 | 1193 | 
| 1047     int tot_steps; | 1194     int tot_steps; | 
| 1048     MV this_mv; | 1195     int_mv this_mv; | 
| 1049 | 1196 | 
| 1050     int bestsad = INT_MAX; | 1197     int bestsad = INT_MAX; | 
| 1051     int best_site = 0; | 1198     int best_site = 0; | 
| 1052     int last_site = 0; | 1199     int last_site = 0; | 
| 1053 | 1200 | 
| 1054     int ref_row = ref_mv->row >> 3; | 1201     int ref_row; | 
| 1055     int ref_col = ref_mv->col >> 3; | 1202     int ref_col; | 
| 1056     int this_row_offset; | 1203     int this_row_offset; | 
| 1057     int this_col_offset; | 1204     int this_col_offset; | 
| 1058     search_site *ss; | 1205     search_site *ss; | 
| 1059 | 1206 | 
| 1060     unsigned char *check_here; | 1207     unsigned char *check_here; | 
| 1061     unsigned int thissad; | 1208     unsigned int thissad; | 
| 1062 | 1209 | 
|  | 1210     int *mvsadcost[2] = {x->mvsadcost[0], x->mvsadcost[1]}; | 
|  | 1211     int_mv fcenter_mv; | 
|  | 1212     fcenter_mv.as_mv.row = center_mv->as_mv.row >> 3; | 
|  | 1213     fcenter_mv.as_mv.col = center_mv->as_mv.col >> 3; | 
|  | 1214 | 
|  | 1215     vp8_clamp_mv(ref_mv, x->mv_col_min, x->mv_col_max, x->mv_row_min, x->mv_row_
      max); | 
|  | 1216     ref_row = ref_mv->as_mv.row; | 
|  | 1217     ref_col = ref_mv->as_mv.col; | 
| 1063     *num00 = 0; | 1218     *num00 = 0; | 
|  | 1219     best_mv->as_mv.row = ref_row; | 
|  | 1220     best_mv->as_mv.col = ref_col; | 
| 1064 | 1221 | 
| 1065     // Work out the start point for the search | 1222     // Work out the start point for the search | 
| 1066     in_what = (unsigned char *)(*(d->base_pre) + d->pre + (ref_row * (d->pre_str
      ide)) + ref_col); | 1223     in_what = (unsigned char *)(*(d->base_pre) + d->pre + (ref_row * (d->pre_str
      ide)) + ref_col); | 
| 1067     best_address = in_what; | 1224     best_address = in_what; | 
| 1068 | 1225 | 
| 1069     // We need to check that the starting point for the search (as indicated by 
      ref_mv) is within the buffer limits | 1226     // Check the starting position | 
| 1070     if ((ref_col > x->mv_col_min) && (ref_col < x->mv_col_max) && | 1227     bestsad = fn_ptr->sdf(what, what_stride, | 
| 1071     (ref_row > x->mv_row_min) && (ref_row < x->mv_row_max)) | 1228                           in_what, in_what_stride, 0x7fffffff) | 
| 1072     { | 1229               + mvsad_err_cost(best_mv, &fcenter_mv, mvsadcost, sad_per_bit); | 
| 1073         // Check the starting position |  | 
| 1074         bestsad = fn_ptr->sdf(what, what_stride, in_what, in_what_stride, 0x7fff
      ffff) + mv_err_cost(ref_mv, center_mv, mvsadcost, error_per_bit); |  | 
| 1075     } |  | 
| 1076 | 1230 | 
| 1077     // search_param determines the length of the initial step and hence the numb
      er of iterations | 1231     // search_param determines the length of the initial step and hence the numb
      er of iterations | 
| 1078     // 0 = initial step (MAX_FIRST_STEP) pel : 1 = (MAX_FIRST_STEP/2) pel, 2 = (
      MAX_FIRST_STEP/4) pel... etc. | 1232     // 0 = initial step (MAX_FIRST_STEP) pel : 1 = (MAX_FIRST_STEP/2) pel, 2 = (
      MAX_FIRST_STEP/4) pel... etc. | 
| 1079     ss = &x->ss[search_param * x->searches_per_step]; | 1233     ss = &x->ss[search_param * x->searches_per_step]; | 
| 1080     tot_steps = (x->ss_count / x->searches_per_step) - search_param; | 1234     tot_steps = (x->ss_count / x->searches_per_step) - search_param; | 
| 1081 | 1235 | 
| 1082     i = 1; | 1236     i = 1; | 
| 1083     best_mv->row = ref_row; |  | 
| 1084     best_mv->col = ref_col; |  | 
| 1085 | 1237 | 
| 1086     for (step = 0; step < tot_steps ; step++) | 1238     for (step = 0; step < tot_steps ; step++) | 
| 1087     { | 1239     { | 
| 1088         int all_in = 1, t; | 1240         int all_in = 1, t; | 
| 1089 | 1241 | 
| 1090         // To know if all neighbor points are within the bounds, 4 bounds checki
      ng are enough instead of | 1242         // To know if all neighbor points are within the bounds, 4 bounds checki
      ng are enough instead of | 
| 1091         // checking 4 bounds for each points. | 1243         // checking 4 bounds for each points. | 
| 1092         all_in &= ((best_mv->row + ss[i].mv.row)> x->mv_row_min); | 1244         all_in &= ((best_mv->as_mv.row + ss[i].mv.row)> x->mv_row_min); | 
| 1093         all_in &= ((best_mv->row + ss[i+1].mv.row) < x->mv_row_max); | 1245         all_in &= ((best_mv->as_mv.row + ss[i+1].mv.row) < x->mv_row_max); | 
| 1094         all_in &= ((best_mv->col + ss[i+2].mv.col) > x->mv_col_min); | 1246         all_in &= ((best_mv->as_mv.col + ss[i+2].mv.col) > x->mv_col_min); | 
| 1095         all_in &= ((best_mv->col + ss[i+3].mv.col) < x->mv_col_max); | 1247         all_in &= ((best_mv->as_mv.col + ss[i+3].mv.col) < x->mv_col_max); | 
| 1096 | 1248 | 
| 1097         if (all_in) | 1249         if (all_in) | 
| 1098         { | 1250         { | 
| 1099             unsigned int sad_array[4]; | 1251             unsigned int sad_array[4]; | 
| 1100 | 1252 | 
| 1101             for (j = 0 ; j < x->searches_per_step ; j += 4) | 1253             for (j = 0 ; j < x->searches_per_step ; j += 4) | 
| 1102             { | 1254             { | 
| 1103                 unsigned char *block_offset[4]; | 1255                 unsigned char *block_offset[4]; | 
| 1104 | 1256 | 
| 1105                 for (t = 0; t < 4; t++) | 1257                 for (t = 0; t < 4; t++) | 
| 1106                     block_offset[t] = ss[i+t].offset + best_address; | 1258                     block_offset[t] = ss[i+t].offset + best_address; | 
| 1107 | 1259 | 
| 1108                 fn_ptr->sdx4df(what, what_stride, block_offset, in_what_stride, 
      sad_array); | 1260                 fn_ptr->sdx4df(what, what_stride, block_offset, in_what_stride, 
      sad_array); | 
| 1109 | 1261 | 
| 1110                 for (t = 0; t < 4; t++, i++) | 1262                 for (t = 0; t < 4; t++, i++) | 
| 1111                 { | 1263                 { | 
| 1112                     if (sad_array[t] < bestsad) | 1264                     if (sad_array[t] < bestsad) | 
| 1113                     { | 1265                     { | 
| 1114                         this_mv.row = (best_mv->row + ss[i].mv.row) << 3; | 1266                         this_mv.as_mv.row = best_mv->as_mv.row + ss[i].mv.row; | 
| 1115                         this_mv.col = (best_mv->col + ss[i].mv.col) << 3; | 1267                         this_mv.as_mv.col = best_mv->as_mv.col + ss[i].mv.col; | 
| 1116                         sad_array[t] += mv_err_cost(&this_mv, center_mv, mvsadco
      st, error_per_bit); | 1268                         sad_array[t] += mvsad_err_cost(&this_mv, &fcenter_mv, | 
|  | 1269                                                        mvsadcost, sad_per_bit); | 
| 1117 | 1270 | 
| 1118                         if (sad_array[t] < bestsad) | 1271                         if (sad_array[t] < bestsad) | 
| 1119                         { | 1272                         { | 
| 1120                             bestsad = sad_array[t]; | 1273                             bestsad = sad_array[t]; | 
| 1121                             best_site = i; | 1274                             best_site = i; | 
| 1122                         } | 1275                         } | 
| 1123                     } | 1276                     } | 
| 1124                 } | 1277                 } | 
| 1125             } | 1278             } | 
| 1126         } | 1279         } | 
| 1127         else | 1280         else | 
| 1128         { | 1281         { | 
| 1129             for (j = 0 ; j < x->searches_per_step ; j++) | 1282             for (j = 0 ; j < x->searches_per_step ; j++) | 
| 1130             { | 1283             { | 
| 1131                 // Trap illegal vectors | 1284                 // Trap illegal vectors | 
| 1132                 this_row_offset = best_mv->row + ss[i].mv.row; | 1285                 this_row_offset = best_mv->as_mv.row + ss[i].mv.row; | 
| 1133                 this_col_offset = best_mv->col + ss[i].mv.col; | 1286                 this_col_offset = best_mv->as_mv.col + ss[i].mv.col; | 
| 1134 | 1287 | 
| 1135                 if ((this_col_offset > x->mv_col_min) && (this_col_offset < x->m
      v_col_max) && | 1288                 if ((this_col_offset > x->mv_col_min) && (this_col_offset < x->m
      v_col_max) && | 
| 1136                 (this_row_offset > x->mv_row_min) && (this_row_offset < x->mv_ro
      w_max)) | 1289                 (this_row_offset > x->mv_row_min) && (this_row_offset < x->mv_ro
      w_max)) | 
| 1137                 { | 1290                 { | 
| 1138                     check_here = ss[i].offset + best_address; | 1291                     check_here = ss[i].offset + best_address; | 
| 1139                     thissad = fn_ptr->sdf(what, what_stride, check_here , in_wha
      t_stride, bestsad); | 1292                     thissad = fn_ptr->sdf(what, what_stride, check_here , in_wha
      t_stride, bestsad); | 
| 1140 | 1293 | 
| 1141                     if (thissad < bestsad) | 1294                     if (thissad < bestsad) | 
| 1142                     { | 1295                     { | 
| 1143                         this_mv.row = this_row_offset << 3; | 1296                         this_mv.as_mv.row = this_row_offset; | 
| 1144                         this_mv.col = this_col_offset << 3; | 1297                         this_mv.as_mv.col = this_col_offset; | 
| 1145                         thissad += mv_err_cost(&this_mv, center_mv, mvsadcost, e
      rror_per_bit); | 1298                         thissad += mvsad_err_cost(&this_mv, &fcenter_mv, | 
|  | 1299                                                    mvsadcost, sad_per_bit); | 
| 1146 | 1300 | 
| 1147                         if (thissad < bestsad) | 1301                         if (thissad < bestsad) | 
| 1148                         { | 1302                         { | 
| 1149                             bestsad = thissad; | 1303                             bestsad = thissad; | 
| 1150                             best_site = i; | 1304                             best_site = i; | 
| 1151                         } | 1305                         } | 
| 1152                     } | 1306                     } | 
| 1153                 } | 1307                 } | 
| 1154                 i++; | 1308                 i++; | 
| 1155             } | 1309             } | 
| 1156         } | 1310         } | 
| 1157 | 1311 | 
| 1158         if (best_site != last_site) | 1312         if (best_site != last_site) | 
| 1159         { | 1313         { | 
| 1160             best_mv->row += ss[best_site].mv.row; | 1314             best_mv->as_mv.row += ss[best_site].mv.row; | 
| 1161             best_mv->col += ss[best_site].mv.col; | 1315             best_mv->as_mv.col += ss[best_site].mv.col; | 
| 1162             best_address += ss[best_site].offset; | 1316             best_address += ss[best_site].offset; | 
| 1163             last_site = best_site; | 1317             last_site = best_site; | 
| 1164         } | 1318         } | 
| 1165         else if (best_address == in_what) | 1319         else if (best_address == in_what) | 
| 1166             (*num00)++; | 1320             (*num00)++; | 
| 1167     } | 1321     } | 
| 1168 | 1322 | 
| 1169     this_mv.row = best_mv->row << 3; | 1323     this_mv.as_mv.row = best_mv->as_mv.row << 3; | 
| 1170     this_mv.col = best_mv->col << 3; | 1324     this_mv.as_mv.col = best_mv->as_mv.col << 3; | 
| 1171 | 1325 | 
| 1172     if (bestsad == INT_MAX) | 1326     if (bestsad == INT_MAX) | 
| 1173         return INT_MAX; | 1327         return INT_MAX; | 
| 1174 | 1328 | 
| 1175     return fn_ptr->vf(what, what_stride, best_address, in_what_stride, (unsigned
       int *)(&thissad)) | 1329     return fn_ptr->vf(what, what_stride, best_address, in_what_stride, (unsigned
       int *)(&thissad)) | 
| 1176     + mv_err_cost(&this_mv, center_mv, mvcost, error_per_bit); | 1330         + mv_err_cost(&this_mv, center_mv, mvcost, x->errorperbit); | 
| 1177 } | 1331 } | 
| 1178 | 1332 | 
| 1179 | 1333 int vp8_full_search_sad(MACROBLOCK *x, BLOCK *b, BLOCKD *d, int_mv *ref_mv, | 
| 1180 #if !(CONFIG_REALTIME_ONLY) | 1334                         int sad_per_bit, int distance, | 
| 1181 int vp8_full_search_sad(MACROBLOCK *x, BLOCK *b, BLOCKD *d, MV *ref_mv, int erro
      r_per_bit, int distance, vp8_variance_fn_ptr_t *fn_ptr, int *mvcost[2], int *mvs
      adcost[2], MV *center_mv) | 1335                         vp8_variance_fn_ptr_t *fn_ptr, int *mvcost[2], | 
|  | 1336                         int_mv *center_mv) | 
| 1182 { | 1337 { | 
| 1183     unsigned char *what = (*(b->base_src) + b->src); | 1338     unsigned char *what = (*(b->base_src) + b->src); | 
| 1184     int what_stride = b->src_stride; | 1339     int what_stride = b->src_stride; | 
| 1185     unsigned char *in_what; | 1340     unsigned char *in_what; | 
| 1186     int in_what_stride = d->pre_stride; | 1341     int in_what_stride = d->pre_stride; | 
| 1187     int mv_stride = d->pre_stride; | 1342     int mv_stride = d->pre_stride; | 
| 1188     unsigned char *bestaddress; | 1343     unsigned char *bestaddress; | 
| 1189     MV *best_mv = &d->bmi.mv.as_mv; | 1344     int_mv *best_mv = &d->bmi.mv; | 
| 1190     MV this_mv; | 1345     int_mv this_mv; | 
| 1191     int bestsad = INT_MAX; | 1346     int bestsad = INT_MAX; | 
| 1192     int r, c; | 1347     int r, c; | 
| 1193 | 1348 | 
| 1194     unsigned char *check_here; | 1349     unsigned char *check_here; | 
| 1195     int thissad; | 1350     int thissad; | 
| 1196 | 1351 | 
| 1197     int ref_row = ref_mv->row >> 3; | 1352     int ref_row = ref_mv->as_mv.row; | 
| 1198     int ref_col = ref_mv->col >> 3; | 1353     int ref_col = ref_mv->as_mv.col; | 
| 1199 | 1354 | 
| 1200     int row_min = ref_row - distance; | 1355     int row_min = ref_row - distance; | 
| 1201     int row_max = ref_row + distance; | 1356     int row_max = ref_row + distance; | 
| 1202     int col_min = ref_col - distance; | 1357     int col_min = ref_col - distance; | 
| 1203     int col_max = ref_col + distance; | 1358     int col_max = ref_col + distance; | 
| 1204 | 1359 | 
|  | 1360     int *mvsadcost[2] = {x->mvsadcost[0], x->mvsadcost[1]}; | 
|  | 1361     int_mv fcenter_mv; | 
|  | 1362     fcenter_mv.as_mv.row = center_mv->as_mv.row >> 3; | 
|  | 1363     fcenter_mv.as_mv.col = center_mv->as_mv.col >> 3; | 
|  | 1364 | 
| 1205     // Work out the mid point for the search | 1365     // Work out the mid point for the search | 
| 1206     in_what = *(d->base_pre) + d->pre; | 1366     in_what = *(d->base_pre) + d->pre; | 
| 1207     bestaddress = in_what + (ref_row * d->pre_stride) + ref_col; | 1367     bestaddress = in_what + (ref_row * d->pre_stride) + ref_col; | 
| 1208 | 1368 | 
| 1209     best_mv->row = ref_row; | 1369     best_mv->as_mv.row = ref_row; | 
| 1210     best_mv->col = ref_col; | 1370     best_mv->as_mv.col = ref_col; | 
| 1211 | 1371 | 
| 1212     // We need to check that the starting point for the search (as indicated by 
      ref_mv) is within the buffer limits | 1372     // Baseline value at the centre | 
| 1213     if ((ref_col > x->mv_col_min) && (ref_col < x->mv_col_max) && | 1373     bestsad = fn_ptr->sdf(what, what_stride, bestaddress, | 
| 1214     (ref_row > x->mv_row_min) && (ref_row < x->mv_row_max)) | 1374                           in_what_stride, 0x7fffffff) | 
| 1215     { | 1375               + mvsad_err_cost(best_mv, &fcenter_mv, mvsadcost, sad_per_bit); | 
| 1216         // Baseline value at the centre |  | 
| 1217 |  | 
| 1218         //bestsad = fn_ptr->sf( what,what_stride,bestaddress,in_what_stride) + (
      int)sqrt(mv_err_cost(ref_mv,ref_mv, mvcost,error_per_bit*14)); |  | 
| 1219         bestsad = fn_ptr->sdf(what, what_stride, bestaddress, in_what_stride, 0x
      7fffffff) + mv_err_cost(ref_mv, center_mv, mvsadcost, error_per_bit); |  | 
| 1220     } |  | 
| 1221 | 1376 | 
| 1222     // Apply further limits to prevent us looking using vectors that stretch bey
      iond the UMV border | 1377     // Apply further limits to prevent us looking using vectors that stretch bey
      iond the UMV border | 
| 1223     if (col_min < x->mv_col_min) | 1378     if (col_min < x->mv_col_min) | 
| 1224         col_min = x->mv_col_min; | 1379         col_min = x->mv_col_min; | 
| 1225 | 1380 | 
| 1226     if (col_max > x->mv_col_max) | 1381     if (col_max > x->mv_col_max) | 
| 1227         col_max = x->mv_col_max; | 1382         col_max = x->mv_col_max; | 
| 1228 | 1383 | 
| 1229     if (row_min < x->mv_row_min) | 1384     if (row_min < x->mv_row_min) | 
| 1230         row_min = x->mv_row_min; | 1385         row_min = x->mv_row_min; | 
| 1231 | 1386 | 
| 1232     if (row_max > x->mv_row_max) | 1387     if (row_max > x->mv_row_max) | 
| 1233         row_max = x->mv_row_max; | 1388         row_max = x->mv_row_max; | 
| 1234 | 1389 | 
| 1235     for (r = row_min; r < row_max ; r++) | 1390     for (r = row_min; r < row_max ; r++) | 
| 1236     { | 1391     { | 
| 1237         this_mv.row = r << 3; | 1392         this_mv.as_mv.row = r; | 
| 1238         check_here = r * mv_stride + in_what + col_min; | 1393         check_here = r * mv_stride + in_what + col_min; | 
| 1239 | 1394 | 
| 1240         for (c = col_min; c < col_max; c++) | 1395         for (c = col_min; c < col_max; c++) | 
| 1241         { | 1396         { | 
| 1242             thissad = fn_ptr->sdf(what, what_stride, check_here , in_what_stride
      , bestsad); | 1397             thissad = fn_ptr->sdf(what, what_stride, check_here , in_what_stride
      , bestsad); | 
| 1243 | 1398 | 
| 1244             this_mv.col = c << 3; | 1399             this_mv.as_mv.col = c; | 
| 1245             //thissad += (int)sqrt(mv_err_cost(&this_mv,ref_mv, mvcost,error_per
      _bit*14)); | 1400             thissad  += mvsad_err_cost(&this_mv, &fcenter_mv, | 
| 1246             //thissad  += error_per_bit * mv_bits_sadcost[mv_bits(&this_mv, ref_
      mv, mvcost)]; | 1401                         mvsadcost, sad_per_bit); | 
| 1247             thissad  += mv_err_cost(&this_mv, center_mv, mvsadcost, error_per_bi
      t); //mv_bits(error_per_bit, &this_mv, ref_mv, mvsadcost); |  | 
| 1248 | 1402 | 
| 1249             if (thissad < bestsad) | 1403             if (thissad < bestsad) | 
| 1250             { | 1404             { | 
| 1251                 bestsad = thissad; | 1405                 bestsad = thissad; | 
| 1252                 best_mv->row = r; | 1406                 best_mv->as_mv.row = r; | 
| 1253                 best_mv->col = c; | 1407                 best_mv->as_mv.col = c; | 
| 1254                 bestaddress = check_here; | 1408                 bestaddress = check_here; | 
| 1255             } | 1409             } | 
| 1256 | 1410 | 
| 1257             check_here++; | 1411             check_here++; | 
| 1258         } | 1412         } | 
| 1259     } | 1413     } | 
| 1260 | 1414 | 
| 1261     this_mv.row = best_mv->row << 3; | 1415     this_mv.as_mv.row = best_mv->as_mv.row << 3; | 
| 1262     this_mv.col = best_mv->col << 3; | 1416     this_mv.as_mv.col = best_mv->as_mv.col << 3; | 
| 1263 | 1417 | 
| 1264     if (bestsad < INT_MAX) | 1418     if (bestsad < INT_MAX) | 
| 1265         return fn_ptr->vf(what, what_stride, bestaddress, in_what_stride, (unsig
      ned int *)(&thissad)) | 1419         return fn_ptr->vf(what, what_stride, bestaddress, in_what_stride, (unsig
      ned int *)(&thissad)) | 
| 1266         + mv_err_cost(&this_mv, center_mv, mvcost, error_per_bit); | 1420         + mv_err_cost(&this_mv, center_mv, mvcost, x->errorperbit); | 
| 1267     else | 1421     else | 
| 1268         return INT_MAX; | 1422         return INT_MAX; | 
| 1269 } | 1423 } | 
| 1270 | 1424 | 
| 1271 int vp8_full_search_sadx3(MACROBLOCK *x, BLOCK *b, BLOCKD *d, MV *ref_mv, int er
      ror_per_bit, int distance, vp8_variance_fn_ptr_t *fn_ptr, int *mvcost[2], int *m
      vsadcost[2], MV *center_mv) | 1425 int vp8_full_search_sadx3(MACROBLOCK *x, BLOCK *b, BLOCKD *d, int_mv *ref_mv, | 
|  | 1426                           int sad_per_bit, int distance, | 
|  | 1427                           vp8_variance_fn_ptr_t *fn_ptr, int *mvcost[2], | 
|  | 1428                           int_mv *center_mv) | 
| 1272 { | 1429 { | 
| 1273     unsigned char *what = (*(b->base_src) + b->src); | 1430     unsigned char *what = (*(b->base_src) + b->src); | 
| 1274     int what_stride = b->src_stride; | 1431     int what_stride = b->src_stride; | 
| 1275     unsigned char *in_what; | 1432     unsigned char *in_what; | 
| 1276     int in_what_stride = d->pre_stride; | 1433     int in_what_stride = d->pre_stride; | 
| 1277     int mv_stride = d->pre_stride; | 1434     int mv_stride = d->pre_stride; | 
| 1278     unsigned char *bestaddress; | 1435     unsigned char *bestaddress; | 
| 1279     MV *best_mv = &d->bmi.mv.as_mv; | 1436     int_mv *best_mv = &d->bmi.mv; | 
| 1280     MV this_mv; | 1437     int_mv this_mv; | 
| 1281     int bestsad = INT_MAX; | 1438     int bestsad = INT_MAX; | 
| 1282     int r, c; | 1439     int r, c; | 
| 1283 | 1440 | 
| 1284     unsigned char *check_here; | 1441     unsigned char *check_here; | 
| 1285     unsigned int thissad; | 1442     unsigned int thissad; | 
| 1286 | 1443 | 
| 1287     int ref_row = ref_mv->row >> 3; | 1444     int ref_row = ref_mv->as_mv.row; | 
| 1288     int ref_col = ref_mv->col >> 3; | 1445     int ref_col = ref_mv->as_mv.col; | 
| 1289 | 1446 | 
| 1290     int row_min = ref_row - distance; | 1447     int row_min = ref_row - distance; | 
| 1291     int row_max = ref_row + distance; | 1448     int row_max = ref_row + distance; | 
| 1292     int col_min = ref_col - distance; | 1449     int col_min = ref_col - distance; | 
| 1293     int col_max = ref_col + distance; | 1450     int col_max = ref_col + distance; | 
| 1294 | 1451 | 
| 1295     unsigned int sad_array[3]; | 1452     unsigned int sad_array[3]; | 
| 1296 | 1453 | 
|  | 1454     int *mvsadcost[2] = {x->mvsadcost[0], x->mvsadcost[1]}; | 
|  | 1455     int_mv fcenter_mv; | 
|  | 1456     fcenter_mv.as_mv.row = center_mv->as_mv.row >> 3; | 
|  | 1457     fcenter_mv.as_mv.col = center_mv->as_mv.col >> 3; | 
|  | 1458 | 
| 1297     // Work out the mid point for the search | 1459     // Work out the mid point for the search | 
| 1298     in_what = *(d->base_pre) + d->pre; | 1460     in_what = *(d->base_pre) + d->pre; | 
| 1299     bestaddress = in_what + (ref_row * d->pre_stride) + ref_col; | 1461     bestaddress = in_what + (ref_row * d->pre_stride) + ref_col; | 
| 1300 | 1462 | 
| 1301     best_mv->row = ref_row; | 1463     best_mv->as_mv.row = ref_row; | 
| 1302     best_mv->col = ref_col; | 1464     best_mv->as_mv.col = ref_col; | 
| 1303 | 1465 | 
| 1304     // We need to check that the starting point for the search (as indicated by 
      ref_mv) is within the buffer limits | 1466     // Baseline value at the centre | 
| 1305     if ((ref_col > x->mv_col_min) && (ref_col < x->mv_col_max) && | 1467     bestsad = fn_ptr->sdf(what, what_stride, | 
| 1306     (ref_row > x->mv_row_min) && (ref_row < x->mv_row_max)) | 1468                           bestaddress, in_what_stride, 0x7fffffff) | 
| 1307     { | 1469               + mvsad_err_cost(best_mv, &fcenter_mv, mvsadcost, sad_per_bit); | 
| 1308         // Baseline value at the centre |  | 
| 1309         bestsad = fn_ptr->sdf(what, what_stride, bestaddress, in_what_stride, 0x
      7fffffff) + mv_err_cost(ref_mv, center_mv, mvsadcost, error_per_bit); |  | 
| 1310     } |  | 
| 1311 | 1470 | 
| 1312     // Apply further limits to prevent us looking using vectors that stretch bey
      iond the UMV border | 1471     // Apply further limits to prevent us looking using vectors that stretch bey
      iond the UMV border | 
| 1313     if (col_min < x->mv_col_min) | 1472     if (col_min < x->mv_col_min) | 
| 1314         col_min = x->mv_col_min; | 1473         col_min = x->mv_col_min; | 
| 1315 | 1474 | 
| 1316     if (col_max > x->mv_col_max) | 1475     if (col_max > x->mv_col_max) | 
| 1317         col_max = x->mv_col_max; | 1476         col_max = x->mv_col_max; | 
| 1318 | 1477 | 
| 1319     if (row_min < x->mv_row_min) | 1478     if (row_min < x->mv_row_min) | 
| 1320         row_min = x->mv_row_min; | 1479         row_min = x->mv_row_min; | 
| 1321 | 1480 | 
| 1322     if (row_max > x->mv_row_max) | 1481     if (row_max > x->mv_row_max) | 
| 1323         row_max = x->mv_row_max; | 1482         row_max = x->mv_row_max; | 
| 1324 | 1483 | 
| 1325     for (r = row_min; r < row_max ; r++) | 1484     for (r = row_min; r < row_max ; r++) | 
| 1326     { | 1485     { | 
| 1327         this_mv.row = r << 3; | 1486         this_mv.as_mv.row = r; | 
| 1328         check_here = r * mv_stride + in_what + col_min; | 1487         check_here = r * mv_stride + in_what + col_min; | 
| 1329         c = col_min; | 1488         c = col_min; | 
| 1330 | 1489 | 
| 1331         while ((c + 2) < col_max) | 1490         while ((c + 2) < col_max) | 
| 1332         { | 1491         { | 
| 1333             int i; | 1492             int i; | 
| 1334 | 1493 | 
| 1335             fn_ptr->sdx3f(what, what_stride, check_here , in_what_stride, sad_ar
      ray); | 1494             fn_ptr->sdx3f(what, what_stride, check_here , in_what_stride, sad_ar
      ray); | 
| 1336 | 1495 | 
| 1337             for (i = 0; i < 3; i++) | 1496             for (i = 0; i < 3; i++) | 
| 1338             { | 1497             { | 
| 1339                 thissad = sad_array[i]; | 1498                 thissad = sad_array[i]; | 
| 1340 | 1499 | 
| 1341                 if (thissad < bestsad) | 1500                 if (thissad < bestsad) | 
| 1342                 { | 1501                 { | 
| 1343                     this_mv.col = c << 3; | 1502                     this_mv.as_mv.col = c; | 
| 1344                     thissad  += mv_err_cost(&this_mv, center_mv, mvsadcost, erro
      r_per_bit); | 1503                     thissad  += mvsad_err_cost(&this_mv, &fcenter_mv, | 
|  | 1504                                                 mvsadcost, sad_per_bit); | 
| 1345 | 1505 | 
| 1346                     if (thissad < bestsad) | 1506                     if (thissad < bestsad) | 
| 1347                     { | 1507                     { | 
| 1348                         bestsad = thissad; | 1508                         bestsad = thissad; | 
| 1349                         best_mv->row = r; | 1509                         best_mv->as_mv.row = r; | 
| 1350                         best_mv->col = c; | 1510                         best_mv->as_mv.col = c; | 
| 1351                         bestaddress = check_here; | 1511                         bestaddress = check_here; | 
| 1352                     } | 1512                     } | 
| 1353                 } | 1513                 } | 
| 1354 | 1514 | 
| 1355                 check_here++; | 1515                 check_here++; | 
| 1356                 c++; | 1516                 c++; | 
| 1357             } | 1517             } | 
| 1358         } | 1518         } | 
| 1359 | 1519 | 
| 1360         while (c < col_max) | 1520         while (c < col_max) | 
| 1361         { | 1521         { | 
| 1362             thissad = fn_ptr->sdf(what, what_stride, check_here , in_what_stride
      , bestsad); | 1522             thissad = fn_ptr->sdf(what, what_stride, check_here , in_what_stride
      , bestsad); | 
| 1363 | 1523 | 
| 1364             if (thissad < bestsad) | 1524             if (thissad < bestsad) | 
| 1365             { | 1525             { | 
| 1366                 this_mv.col = c << 3; | 1526                 this_mv.as_mv.col = c; | 
| 1367                 thissad  += mv_err_cost(&this_mv, center_mv, mvsadcost, error_pe
      r_bit); | 1527                 thissad  += mvsad_err_cost(&this_mv, &fcenter_mv, | 
|  | 1528                                             mvsadcost, sad_per_bit); | 
| 1368 | 1529 | 
| 1369                 if (thissad < bestsad) | 1530                 if (thissad < bestsad) | 
| 1370                 { | 1531                 { | 
| 1371                     bestsad = thissad; | 1532                     bestsad = thissad; | 
| 1372                     best_mv->row = r; | 1533                     best_mv->as_mv.row = r; | 
| 1373                     best_mv->col = c; | 1534                     best_mv->as_mv.col = c; | 
| 1374                     bestaddress = check_here; | 1535                     bestaddress = check_here; | 
| 1375                 } | 1536                 } | 
| 1376             } | 1537             } | 
| 1377 | 1538 | 
| 1378             check_here ++; | 1539             check_here ++; | 
| 1379             c ++; | 1540             c ++; | 
| 1380         } | 1541         } | 
| 1381 | 1542 | 
| 1382     } | 1543     } | 
| 1383 | 1544 | 
| 1384     this_mv.row = best_mv->row << 3; | 1545     this_mv.as_mv.row = best_mv->as_mv.row << 3; | 
| 1385     this_mv.col = best_mv->col << 3; | 1546     this_mv.as_mv.col = best_mv->as_mv.col << 3; | 
| 1386 | 1547 | 
| 1387     if (bestsad < INT_MAX) | 1548     if (bestsad < INT_MAX) | 
| 1388         return fn_ptr->vf(what, what_stride, bestaddress, in_what_stride, (unsig
      ned int *)(&thissad)) | 1549         return fn_ptr->vf(what, what_stride, bestaddress, in_what_stride, (unsig
      ned int *)(&thissad)) | 
| 1389         + mv_err_cost(&this_mv, center_mv, mvcost, error_per_bit); | 1550         + mv_err_cost(&this_mv, center_mv, mvcost, x->errorperbit); | 
| 1390     else | 1551     else | 
| 1391         return INT_MAX; | 1552         return INT_MAX; | 
| 1392 } | 1553 } | 
| 1393 | 1554 | 
| 1394 int vp8_full_search_sadx8(MACROBLOCK *x, BLOCK *b, BLOCKD *d, MV *ref_mv, int er
      ror_per_bit, int distance, vp8_variance_fn_ptr_t *fn_ptr, int *mvcost[2], int *m
      vsadcost[2], MV *center_mv) | 1555 int vp8_full_search_sadx8(MACROBLOCK *x, BLOCK *b, BLOCKD *d, int_mv *ref_mv, | 
|  | 1556                           int sad_per_bit, int distance, | 
|  | 1557                           vp8_variance_fn_ptr_t *fn_ptr, int *mvcost[2], | 
|  | 1558                           int_mv *center_mv) | 
| 1395 { | 1559 { | 
| 1396     unsigned char *what = (*(b->base_src) + b->src); | 1560     unsigned char *what = (*(b->base_src) + b->src); | 
| 1397     int what_stride = b->src_stride; | 1561     int what_stride = b->src_stride; | 
| 1398     unsigned char *in_what; | 1562     unsigned char *in_what; | 
| 1399     int in_what_stride = d->pre_stride; | 1563     int in_what_stride = d->pre_stride; | 
| 1400     int mv_stride = d->pre_stride; | 1564     int mv_stride = d->pre_stride; | 
| 1401     unsigned char *bestaddress; | 1565     unsigned char *bestaddress; | 
| 1402     MV *best_mv = &d->bmi.mv.as_mv; | 1566     int_mv *best_mv = &d->bmi.mv; | 
| 1403     MV this_mv; | 1567     int_mv this_mv; | 
| 1404     int bestsad = INT_MAX; | 1568     int bestsad = INT_MAX; | 
| 1405     int r, c; | 1569     int r, c; | 
| 1406 | 1570 | 
| 1407     unsigned char *check_here; | 1571     unsigned char *check_here; | 
| 1408     unsigned int thissad; | 1572     unsigned int thissad; | 
| 1409 | 1573 | 
| 1410     int ref_row = ref_mv->row >> 3; | 1574     int ref_row = ref_mv->as_mv.row; | 
| 1411     int ref_col = ref_mv->col >> 3; | 1575     int ref_col = ref_mv->as_mv.col; | 
| 1412 | 1576 | 
| 1413     int row_min = ref_row - distance; | 1577     int row_min = ref_row - distance; | 
| 1414     int row_max = ref_row + distance; | 1578     int row_max = ref_row + distance; | 
| 1415     int col_min = ref_col - distance; | 1579     int col_min = ref_col - distance; | 
| 1416     int col_max = ref_col + distance; | 1580     int col_max = ref_col + distance; | 
| 1417 | 1581 | 
| 1418     DECLARE_ALIGNED_ARRAY(16, unsigned short, sad_array8, 8); | 1582     DECLARE_ALIGNED_ARRAY(16, unsigned short, sad_array8, 8); | 
| 1419     unsigned int sad_array[3]; | 1583     unsigned int sad_array[3]; | 
| 1420 | 1584 | 
|  | 1585     int *mvsadcost[2] = {x->mvsadcost[0], x->mvsadcost[1]}; | 
|  | 1586     int_mv fcenter_mv; | 
|  | 1587     fcenter_mv.as_mv.row = center_mv->as_mv.row >> 3; | 
|  | 1588     fcenter_mv.as_mv.col = center_mv->as_mv.col >> 3; | 
|  | 1589 | 
| 1421     // Work out the mid point for the search | 1590     // Work out the mid point for the search | 
| 1422     in_what = *(d->base_pre) + d->pre; | 1591     in_what = *(d->base_pre) + d->pre; | 
| 1423     bestaddress = in_what + (ref_row * d->pre_stride) + ref_col; | 1592     bestaddress = in_what + (ref_row * d->pre_stride) + ref_col; | 
| 1424 | 1593 | 
| 1425     best_mv->row = ref_row; | 1594     best_mv->as_mv.row = ref_row; | 
| 1426     best_mv->col = ref_col; | 1595     best_mv->as_mv.col = ref_col; | 
| 1427 | 1596 | 
| 1428     // We need to check that the starting point for the search (as indicated by 
      ref_mv) is within the buffer limits | 1597     // Baseline value at the centre | 
| 1429     if ((ref_col > x->mv_col_min) && (ref_col < x->mv_col_max) && | 1598     bestsad = fn_ptr->sdf(what, what_stride, | 
| 1430     (ref_row > x->mv_row_min) && (ref_row < x->mv_row_max)) | 1599                           bestaddress, in_what_stride, 0x7fffffff) | 
| 1431     { | 1600               + mvsad_err_cost(best_mv, &fcenter_mv, mvsadcost, sad_per_bit); | 
| 1432         // Baseline value at the centre |  | 
| 1433         bestsad = fn_ptr->sdf(what, what_stride, bestaddress, in_what_stride, 0x
      7fffffff) + mv_err_cost(ref_mv, center_mv, mvsadcost, error_per_bit); |  | 
| 1434     } |  | 
| 1435 | 1601 | 
| 1436     // Apply further limits to prevent us looking using vectors that stretch bey
      iond the UMV border | 1602     // Apply further limits to prevent us looking using vectors that stretch bey
      iond the UMV border | 
| 1437     if (col_min < x->mv_col_min) | 1603     if (col_min < x->mv_col_min) | 
| 1438         col_min = x->mv_col_min; | 1604         col_min = x->mv_col_min; | 
| 1439 | 1605 | 
| 1440     if (col_max > x->mv_col_max) | 1606     if (col_max > x->mv_col_max) | 
| 1441         col_max = x->mv_col_max; | 1607         col_max = x->mv_col_max; | 
| 1442 | 1608 | 
| 1443     if (row_min < x->mv_row_min) | 1609     if (row_min < x->mv_row_min) | 
| 1444         row_min = x->mv_row_min; | 1610         row_min = x->mv_row_min; | 
| 1445 | 1611 | 
| 1446     if (row_max > x->mv_row_max) | 1612     if (row_max > x->mv_row_max) | 
| 1447         row_max = x->mv_row_max; | 1613         row_max = x->mv_row_max; | 
| 1448 | 1614 | 
| 1449     for (r = row_min; r < row_max ; r++) | 1615     for (r = row_min; r < row_max ; r++) | 
| 1450     { | 1616     { | 
| 1451         this_mv.row = r << 3; | 1617         this_mv.as_mv.row = r; | 
| 1452         check_here = r * mv_stride + in_what + col_min; | 1618         check_here = r * mv_stride + in_what + col_min; | 
| 1453         c = col_min; | 1619         c = col_min; | 
| 1454 | 1620 | 
| 1455         while ((c + 7) < col_max) | 1621         while ((c + 7) < col_max) | 
| 1456         { | 1622         { | 
| 1457             int i; | 1623             int i; | 
| 1458 | 1624 | 
| 1459             fn_ptr->sdx8f(what, what_stride, check_here , in_what_stride, sad_ar
      ray8); | 1625             fn_ptr->sdx8f(what, what_stride, check_here , in_what_stride, sad_ar
      ray8); | 
| 1460 | 1626 | 
| 1461             for (i = 0; i < 8; i++) | 1627             for (i = 0; i < 8; i++) | 
| 1462             { | 1628             { | 
| 1463                 thissad = (unsigned int)sad_array8[i]; | 1629                 thissad = (unsigned int)sad_array8[i]; | 
| 1464 | 1630 | 
| 1465                 if (thissad < bestsad) | 1631                 if (thissad < bestsad) | 
| 1466                 { | 1632                 { | 
| 1467                     this_mv.col = c << 3; | 1633                     this_mv.as_mv.col = c; | 
| 1468                     thissad  += mv_err_cost(&this_mv, center_mv, mvsadcost, erro
      r_per_bit); | 1634                     thissad  += mvsad_err_cost(&this_mv, &fcenter_mv, | 
|  | 1635                                                 mvsadcost, sad_per_bit); | 
| 1469 | 1636 | 
| 1470                     if (thissad < bestsad) | 1637                     if (thissad < bestsad) | 
| 1471                     { | 1638                     { | 
| 1472                         bestsad = thissad; | 1639                         bestsad = thissad; | 
| 1473                         best_mv->row = r; | 1640                         best_mv->as_mv.row = r; | 
| 1474                         best_mv->col = c; | 1641                         best_mv->as_mv.col = c; | 
| 1475                         bestaddress = check_here; | 1642                         bestaddress = check_here; | 
| 1476                     } | 1643                     } | 
| 1477                 } | 1644                 } | 
| 1478 | 1645 | 
| 1479                 check_here++; | 1646                 check_here++; | 
| 1480                 c++; | 1647                 c++; | 
| 1481             } | 1648             } | 
| 1482         } | 1649         } | 
| 1483 | 1650 | 
| 1484         while ((c + 2) < col_max) | 1651         while ((c + 2) < col_max) | 
| 1485         { | 1652         { | 
| 1486             int i; | 1653             int i; | 
| 1487 | 1654 | 
| 1488             fn_ptr->sdx3f(what, what_stride, check_here , in_what_stride, sad_ar
      ray); | 1655             fn_ptr->sdx3f(what, what_stride, check_here , in_what_stride, sad_ar
      ray); | 
| 1489 | 1656 | 
| 1490             for (i = 0; i < 3; i++) | 1657             for (i = 0; i < 3; i++) | 
| 1491             { | 1658             { | 
| 1492                 thissad = sad_array[i]; | 1659                 thissad = sad_array[i]; | 
| 1493 | 1660 | 
| 1494                 if (thissad < bestsad) | 1661                 if (thissad < bestsad) | 
| 1495                 { | 1662                 { | 
| 1496                     this_mv.col = c << 3; | 1663                     this_mv.as_mv.col = c; | 
| 1497                     thissad  += mv_err_cost(&this_mv, center_mv, mvsadcost, erro
      r_per_bit); | 1664                     thissad  += mvsad_err_cost(&this_mv, &fcenter_mv, | 
|  | 1665                         mvsadcost, sad_per_bit); | 
| 1498 | 1666 | 
| 1499                     if (thissad < bestsad) | 1667                     if (thissad < bestsad) | 
| 1500                     { | 1668                     { | 
| 1501                         bestsad = thissad; | 1669                         bestsad = thissad; | 
| 1502                         best_mv->row = r; | 1670                         best_mv->as_mv.row = r; | 
| 1503                         best_mv->col = c; | 1671                         best_mv->as_mv.col = c; | 
| 1504                         bestaddress = check_here; | 1672                         bestaddress = check_here; | 
| 1505                     } | 1673                     } | 
| 1506                 } | 1674                 } | 
| 1507 | 1675 | 
| 1508                 check_here++; | 1676                 check_here++; | 
| 1509                 c++; | 1677                 c++; | 
| 1510             } | 1678             } | 
| 1511         } | 1679         } | 
| 1512 | 1680 | 
| 1513         while (c < col_max) | 1681         while (c < col_max) | 
| 1514         { | 1682         { | 
| 1515             thissad = fn_ptr->sdf(what, what_stride, check_here , in_what_stride
      , bestsad); | 1683             thissad = fn_ptr->sdf(what, what_stride, check_here , in_what_stride
      , bestsad); | 
| 1516 | 1684 | 
| 1517             if (thissad < bestsad) | 1685             if (thissad < bestsad) | 
| 1518             { | 1686             { | 
| 1519                 this_mv.col = c << 3; | 1687                 this_mv.as_mv.col = c; | 
| 1520                 thissad  += mv_err_cost(&this_mv, center_mv, mvsadcost, error_pe
      r_bit); | 1688                 thissad  += mvsad_err_cost(&this_mv, &fcenter_mv, | 
|  | 1689                     mvsadcost, sad_per_bit); | 
| 1521 | 1690 | 
| 1522                 if (thissad < bestsad) | 1691                 if (thissad < bestsad) | 
| 1523                 { | 1692                 { | 
| 1524                     bestsad = thissad; | 1693                     bestsad = thissad; | 
| 1525                     best_mv->row = r; | 1694                     best_mv->as_mv.row = r; | 
| 1526                     best_mv->col = c; | 1695                     best_mv->as_mv.col = c; | 
| 1527                     bestaddress = check_here; | 1696                     bestaddress = check_here; | 
| 1528                 } | 1697                 } | 
| 1529             } | 1698             } | 
| 1530 | 1699 | 
| 1531             check_here ++; | 1700             check_here ++; | 
| 1532             c ++; | 1701             c ++; | 
| 1533         } | 1702         } | 
| 1534     } | 1703     } | 
| 1535 | 1704 | 
| 1536     this_mv.row = best_mv->row << 3; | 1705     this_mv.as_mv.row = best_mv->as_mv.row << 3; | 
| 1537     this_mv.col = best_mv->col << 3; | 1706     this_mv.as_mv.col = best_mv->as_mv.col << 3; | 
| 1538 | 1707 | 
| 1539     if (bestsad < INT_MAX) | 1708     if (bestsad < INT_MAX) | 
| 1540         return fn_ptr->vf(what, what_stride, bestaddress, in_what_stride, (unsig
      ned int *)(&thissad)) | 1709         return fn_ptr->vf(what, what_stride, bestaddress, in_what_stride, (unsig
      ned int *)(&thissad)) | 
| 1541         + mv_err_cost(&this_mv, center_mv, mvcost, error_per_bit); | 1710         + mv_err_cost(&this_mv, center_mv, mvcost, x->errorperbit); | 
| 1542     else | 1711     else | 
| 1543         return INT_MAX; | 1712         return INT_MAX; | 
| 1544 } | 1713 } | 
| 1545 #endif /* !(CONFIG_REALTIME_ONLY) */ | 1714 | 
|  | 1715 int vp8_refining_search_sad(MACROBLOCK *x, BLOCK *b, BLOCKD *d, int_mv *ref_mv, | 
|  | 1716                             int error_per_bit, int search_range, | 
|  | 1717                             vp8_variance_fn_ptr_t *fn_ptr, int *mvcost[2], | 
|  | 1718                             int_mv *center_mv) | 
|  | 1719 { | 
|  | 1720     MV neighbors[4] = {{-1, 0}, {0, -1}, {0, 1}, {1, 0}}; | 
|  | 1721     int i, j; | 
|  | 1722     short this_row_offset, this_col_offset; | 
|  | 1723 | 
|  | 1724     int what_stride = b->src_stride; | 
|  | 1725     int in_what_stride = d->pre_stride; | 
|  | 1726     unsigned char *what = (*(b->base_src) + b->src); | 
|  | 1727     unsigned char *best_address = (unsigned char *)(*(d->base_pre) + d->pre + | 
|  | 1728         (ref_mv->as_mv.row * (d->pre_stride)) + ref_mv->as_mv.col); | 
|  | 1729     unsigned char *check_here; | 
|  | 1730     unsigned int thissad; | 
|  | 1731     int_mv this_mv; | 
|  | 1732     unsigned int bestsad = INT_MAX; | 
|  | 1733 | 
|  | 1734     int *mvsadcost[2] = {x->mvsadcost[0], x->mvsadcost[1]}; | 
|  | 1735     int_mv fcenter_mv; | 
|  | 1736 | 
|  | 1737     fcenter_mv.as_mv.row = center_mv->as_mv.row >> 3; | 
|  | 1738     fcenter_mv.as_mv.col = center_mv->as_mv.col >> 3; | 
|  | 1739 | 
|  | 1740     bestsad = fn_ptr->sdf(what, what_stride, best_address, in_what_stride, 0x7ff
      fffff) + mvsad_err_cost(ref_mv, &fcenter_mv, mvsadcost, error_per_bit); | 
|  | 1741 | 
|  | 1742     for (i=0; i<search_range; i++) | 
|  | 1743     { | 
|  | 1744         int best_site = -1; | 
|  | 1745 | 
|  | 1746         for (j = 0 ; j < 4 ; j++) | 
|  | 1747         { | 
|  | 1748             this_row_offset = ref_mv->as_mv.row + neighbors[j].row; | 
|  | 1749             this_col_offset = ref_mv->as_mv.col + neighbors[j].col; | 
|  | 1750 | 
|  | 1751             if ((this_col_offset > x->mv_col_min) && (this_col_offset < x->mv_co
      l_max) && | 
|  | 1752             (this_row_offset > x->mv_row_min) && (this_row_offset < x->mv_row_ma
      x)) | 
|  | 1753             { | 
|  | 1754                 check_here = (neighbors[j].row)*in_what_stride + neighbors[j].co
      l + best_address; | 
|  | 1755                 thissad = fn_ptr->sdf(what, what_stride, check_here , in_what_st
      ride, bestsad); | 
|  | 1756 | 
|  | 1757                 if (thissad < bestsad) | 
|  | 1758                 { | 
|  | 1759                     this_mv.as_mv.row = this_row_offset; | 
|  | 1760                     this_mv.as_mv.col = this_col_offset; | 
|  | 1761                     thissad += mvsad_err_cost(&this_mv, &fcenter_mv, mvsadcost, 
      error_per_bit); | 
|  | 1762 | 
|  | 1763                     if (thissad < bestsad) | 
|  | 1764                     { | 
|  | 1765                         bestsad = thissad; | 
|  | 1766                         best_site = j; | 
|  | 1767                     } | 
|  | 1768                 } | 
|  | 1769             } | 
|  | 1770         } | 
|  | 1771 | 
|  | 1772         if (best_site == -1) | 
|  | 1773             break; | 
|  | 1774         else | 
|  | 1775         { | 
|  | 1776             ref_mv->as_mv.row += neighbors[best_site].row; | 
|  | 1777             ref_mv->as_mv.col += neighbors[best_site].col; | 
|  | 1778             best_address += (neighbors[best_site].row)*in_what_stride + neighbor
      s[best_site].col; | 
|  | 1779         } | 
|  | 1780     } | 
|  | 1781 | 
|  | 1782     this_mv.as_mv.row = ref_mv->as_mv.row << 3; | 
|  | 1783     this_mv.as_mv.col = ref_mv->as_mv.col << 3; | 
|  | 1784 | 
|  | 1785     if (bestsad < INT_MAX) | 
|  | 1786         return fn_ptr->vf(what, what_stride, best_address, in_what_stride, (unsi
      gned int *)(&thissad)) | 
|  | 1787         + mv_err_cost(&this_mv, center_mv, mvcost, x->errorperbit); | 
|  | 1788     else | 
|  | 1789         return INT_MAX; | 
|  | 1790 } | 
|  | 1791 | 
|  | 1792 int vp8_refining_search_sadx4(MACROBLOCK *x, BLOCK *b, BLOCKD *d, | 
|  | 1793                               int_mv *ref_mv, int error_per_bit, | 
|  | 1794                               int search_range, vp8_variance_fn_ptr_t *fn_ptr, | 
|  | 1795                               int *mvcost[2], int_mv *center_mv) | 
|  | 1796 { | 
|  | 1797     MV neighbors[4] = {{-1, 0}, {0, -1}, {0, 1}, {1, 0}}; | 
|  | 1798     int i, j; | 
|  | 1799     short this_row_offset, this_col_offset; | 
|  | 1800 | 
|  | 1801     int what_stride = b->src_stride; | 
|  | 1802     int in_what_stride = d->pre_stride; | 
|  | 1803     unsigned char *what = (*(b->base_src) + b->src); | 
|  | 1804     unsigned char *best_address = (unsigned char *)(*(d->base_pre) + d->pre + | 
|  | 1805         (ref_mv->as_mv.row * (d->pre_stride)) + ref_mv->as_mv.col); | 
|  | 1806     unsigned char *check_here; | 
|  | 1807     unsigned int thissad; | 
|  | 1808     int_mv this_mv; | 
|  | 1809     unsigned int bestsad = INT_MAX; | 
|  | 1810 | 
|  | 1811     int *mvsadcost[2] = {x->mvsadcost[0], x->mvsadcost[1]}; | 
|  | 1812     int_mv fcenter_mv; | 
|  | 1813 | 
|  | 1814     fcenter_mv.as_mv.row = center_mv->as_mv.row >> 3; | 
|  | 1815     fcenter_mv.as_mv.col = center_mv->as_mv.col >> 3; | 
|  | 1816 | 
|  | 1817     bestsad = fn_ptr->sdf(what, what_stride, best_address, in_what_stride, 0x7ff
      fffff) + mvsad_err_cost(ref_mv, &fcenter_mv, mvsadcost, error_per_bit); | 
|  | 1818 | 
|  | 1819     for (i=0; i<search_range; i++) | 
|  | 1820     { | 
|  | 1821         int best_site = -1; | 
|  | 1822         int all_in = 1; | 
|  | 1823 | 
|  | 1824         all_in &= ((ref_mv->as_mv.row - 1) > x->mv_row_min); | 
|  | 1825         all_in &= ((ref_mv->as_mv.row + 1) < x->mv_row_max); | 
|  | 1826         all_in &= ((ref_mv->as_mv.col - 1) > x->mv_col_min); | 
|  | 1827         all_in &= ((ref_mv->as_mv.col + 1) < x->mv_col_max); | 
|  | 1828 | 
|  | 1829         if(all_in) | 
|  | 1830         { | 
|  | 1831             unsigned int sad_array[4]; | 
|  | 1832             unsigned char *block_offset[4]; | 
|  | 1833             block_offset[0] = best_address - in_what_stride; | 
|  | 1834             block_offset[1] = best_address - 1; | 
|  | 1835             block_offset[2] = best_address + 1; | 
|  | 1836             block_offset[3] = best_address + in_what_stride; | 
|  | 1837 | 
|  | 1838             fn_ptr->sdx4df(what, what_stride, block_offset, in_what_stride, sad_
      array); | 
|  | 1839 | 
|  | 1840             for (j = 0; j < 4; j++) | 
|  | 1841             { | 
|  | 1842                 if (sad_array[j] < bestsad) | 
|  | 1843                 { | 
|  | 1844                     this_mv.as_mv.row = ref_mv->as_mv.row + neighbors[j].row; | 
|  | 1845                     this_mv.as_mv.col = ref_mv->as_mv.col + neighbors[j].col; | 
|  | 1846                     sad_array[j] += mvsad_err_cost(&this_mv, &fcenter_mv, mvsadc
      ost, error_per_bit); | 
|  | 1847 | 
|  | 1848                     if (sad_array[j] < bestsad) | 
|  | 1849                     { | 
|  | 1850                         bestsad = sad_array[j]; | 
|  | 1851                         best_site = j; | 
|  | 1852                     } | 
|  | 1853                 } | 
|  | 1854             } | 
|  | 1855         } | 
|  | 1856         else | 
|  | 1857         { | 
|  | 1858             for (j = 0 ; j < 4 ; j++) | 
|  | 1859             { | 
|  | 1860                 this_row_offset = ref_mv->as_mv.row + neighbors[j].row; | 
|  | 1861                 this_col_offset = ref_mv->as_mv.col + neighbors[j].col; | 
|  | 1862 | 
|  | 1863                 if ((this_col_offset > x->mv_col_min) && (this_col_offset < x->m
      v_col_max) && | 
|  | 1864                 (this_row_offset > x->mv_row_min) && (this_row_offset < x->mv_ro
      w_max)) | 
|  | 1865                 { | 
|  | 1866                     check_here = (neighbors[j].row)*in_what_stride + neighbors[j
      ].col + best_address; | 
|  | 1867                     thissad = fn_ptr->sdf(what, what_stride, check_here , in_wha
      t_stride, bestsad); | 
|  | 1868 | 
|  | 1869                     if (thissad < bestsad) | 
|  | 1870                     { | 
|  | 1871                         this_mv.as_mv.row = this_row_offset; | 
|  | 1872                         this_mv.as_mv.col = this_col_offset; | 
|  | 1873                         thissad += mvsad_err_cost(&this_mv, &fcenter_mv, mvsadco
      st, error_per_bit); | 
|  | 1874 | 
|  | 1875                         if (thissad < bestsad) | 
|  | 1876                         { | 
|  | 1877                             bestsad = thissad; | 
|  | 1878                             best_site = j; | 
|  | 1879                         } | 
|  | 1880                     } | 
|  | 1881                 } | 
|  | 1882             } | 
|  | 1883         } | 
|  | 1884 | 
|  | 1885         if (best_site == -1) | 
|  | 1886             break; | 
|  | 1887         else | 
|  | 1888         { | 
|  | 1889             ref_mv->as_mv.row += neighbors[best_site].row; | 
|  | 1890             ref_mv->as_mv.col += neighbors[best_site].col; | 
|  | 1891             best_address += (neighbors[best_site].row)*in_what_stride + neighbor
      s[best_site].col; | 
|  | 1892         } | 
|  | 1893     } | 
|  | 1894 | 
|  | 1895     this_mv.as_mv.row = ref_mv->as_mv.row << 3; | 
|  | 1896     this_mv.as_mv.col = ref_mv->as_mv.col << 3; | 
|  | 1897 | 
|  | 1898     if (bestsad < INT_MAX) | 
|  | 1899         return fn_ptr->vf(what, what_stride, best_address, in_what_stride, (unsi
      gned int *)(&thissad)) | 
|  | 1900         + mv_err_cost(&this_mv, center_mv, mvcost, x->errorperbit); | 
|  | 1901     else | 
|  | 1902         return INT_MAX; | 
|  | 1903 } | 
| 1546 | 1904 | 
| 1547 #ifdef ENTROPY_STATS | 1905 #ifdef ENTROPY_STATS | 
| 1548 void print_mode_context(void) | 1906 void print_mode_context(void) | 
| 1549 { | 1907 { | 
| 1550     FILE *f = fopen("modecont.c", "w"); | 1908     FILE *f = fopen("modecont.c", "w"); | 
| 1551     int i, j; | 1909     int i, j; | 
| 1552 | 1910 | 
| 1553     fprintf(f, "#include \"entropy.h\"\n"); | 1911     fprintf(f, "#include \"entropy.h\"\n"); | 
| 1554     fprintf(f, "const int vp8_mode_contexts[6][4] =\n"); | 1912     fprintf(f, "const int vp8_mode_contexts[6][4] =\n"); | 
| 1555     fprintf(f, "{\n"); | 1913     fprintf(f, "{\n"); | 
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1650                     ++mv_mode_cts[3][1]; | 2008                     ++mv_mode_cts[3][1]; | 
| 1651                 } | 2009                 } | 
| 1652             } | 2010             } | 
| 1653         } | 2011         } | 
| 1654     } | 2012     } | 
| 1655 } | 2013 } | 
| 1656 | 2014 | 
| 1657 #endif/* END MV ref count ENTROPY_STATS stats code */ | 2015 #endif/* END MV ref count ENTROPY_STATS stats code */ | 
| 1658 | 2016 | 
| 1659 #endif | 2017 #endif | 
| OLD | NEW | 
|---|