| @@ -21,8 +21,6 @@ static int mv_ref_ct [31] [4] [2]; · 20 unmodified lines |
| 21 | static int mv_mode_cts [4] [2]; | 21 | static int mv_mode_cts [4] [2]; |
| 22 | #endif | 22 | #endif |
| 23 | | 23 | |
| 24 | static int mv_bits_sadcost[256]; | | |
| 25 | | | |
| 26 | extern unsigned int vp8_sub_pixel_variance16x16s_neon | 24 | extern unsigned int vp8_sub_pixel_variance16x16s_neon |
| 27 | ( | 25 | ( |
| 28 | unsigned char *src_ptr, | 26 | unsigned char *src_ptr, |
| @@ -58,292 +56,7 @@ extern unsigned int vp8_sub_pixel_variance16x16s_4_4_neon · 29 unmodified lines |
| 58 | unsigned int *sse | 56 | unsigned int *sse |
| 59 | ); | 57 | ); |
| 60 | | 58 | |
| 61 | void vp8cx_init_mv_bits_sadcost() | | |
| 62 | { | | |
| 63 | int i; | | |
| 64 | | | |
| 65 | for (i = 0; i < 256; i++) | | |
| 66 | { | | |
| 67 | mv_bits_sadcost[i] = (int)sqrt(i * 16); | | |
| 68 | } | | |
| 69 | } | | |
| 70 | | | |
| 71 | | | |
| 72 | int vp8_mv_bit_cost(MV *mv, MV *ref, int *mvcost[2], int Weight) | | |
| 73 | { | | |
| 74 | // MV costing is based on the distribution of vectors in the previous frame and as such will tend to | | |
| 75 | // over state the cost of vectors. In addition coding a new vector can have a knock on effect on the | | |
| 76 | // cost of subsequent vectors and the quality of prediction from NEAR and NEAREST for subsequent blocks. | | |
| 77 | // The "Weight" parameter allows, to a limited extent, for some account to be taken of these factors. | | |
| 78 | return ((mvcost[0][(mv->row - ref->row) >> 1] + mvcost[1][(mv->col - ref->col) >> 1]) * Weight) >> 7; | | |
| 79 | } | | |
| 80 | | | |
| 81 | int vp8_mv_err_cost(MV *mv, MV *ref, int *mvcost[2], int error_per_bit) | | |
| 82 | { | | |
| 83 | //int i; | | |
| 84 | //return ((mvcost[0][(mv->row - ref->row)>>1] + mvcost[1][(mv->col - ref->col)>>1] + 128) * error_per_bit) >> 8; | | |
| 85 | //return ( (vp8_mv_bit_cost(mv, ref, mvcost, 100) + 128) * error_per_bit) >> 8; | | |
| 86 | | | |
| 87 | //i = (vp8_mv_bit_cost(mv, ref, mvcost, 100) * error_per_bit + 128) >> 8; | | |
| 88 | return ((mvcost[0][(mv->row - ref->row) >> 1] + mvcost[1][(mv->col - ref->col) >> 1]) * error_per_bit + 128) >> 8; | | |
| 89 | //return (vp8_mv_bit_cost(mv, ref, mvcost, 128) * error_per_bit + 128) >> 8; | | |
| 90 | } | | |
| 91 | | | |
| 92 | | | |
| 93 | static int mv_bits(MV *mv, MV *ref, int *mvcost[2]) | | |
| 94 | { | | |
| 95 | // get the estimated number of bits for a motion vector, to be used for costing in SAD based | | |
| 96 | // motion estimation | | |
| 97 | return ((mvcost[0][(mv->row - ref->row) >> 1] + mvcost[1][(mv->col - ref->col)>> 1]) + 128) >> 8; | | |
| 98 | } | | |
| 99 | | | |
| 100 | void vp8_init_dsmotion_compensation(MACROBLOCK *x, int stride) | | |
| 101 | { | | |
| 102 | int Len; | | |
| 103 | int search_site_count = 0; | | |
| 104 | | | |
| 105 | | | |
| 106 | // Generate offsets for 4 search sites per step. | | |
| 107 | Len = MAX_FIRST_STEP; | | |
| 108 | x->ss[search_site_count].mv.col = 0; | | |
| 109 | x->ss[search_site_count].mv.row = 0; | | |
| 110 | x->ss[search_site_count].offset = 0; | | |
| 111 | search_site_count++; | | |
| 112 | | | |
| 113 | while (Len > 0) | | |
| 114 | { | | |
| 115 | | | |
| 116 | // Compute offsets for search sites. | | |
| 117 | x->ss[search_site_count].mv.col = 0; | | |
| 118 | x->ss[search_site_count].mv.row = -Len; | | |
| 119 | x->ss[search_site_count].offset = -Len * stride; | | |
| 120 | search_site_count++; | | |
| 121 | | | |
| 122 | // Compute offsets for search sites. | | |
| 123 | x->ss[search_site_count].mv.col = 0; | | |
| 124 | x->ss[search_site_count].mv.row = Len; | | |
| 125 | x->ss[search_site_count].offset = Len * stride; | | |
| 126 | search_site_count++; | | |
| 127 | | | |
| 128 | // Compute offsets for search sites. | | |
| 129 | x->ss[search_site_count].mv.col = -Len; | | |
| 130 | x->ss[search_site_count].mv.row = 0; | | |
| 131 | x->ss[search_site_count].offset = -Len; | | |
| 132 | search_site_count++; | | |
| 133 | | | |
| 134 | // Compute offsets for search sites. | | |
| 135 | x->ss[search_site_count].mv.col = Len; | | |
| 136 | x->ss[search_site_count].mv.row = 0; | | |
| 137 | x->ss[search_site_count].offset = Len; | | |
| 138 | search_site_count++; | | |
| 139 | | | |
| 140 | // Contract. | | |
| 141 | Len /= 2; | | |
| 142 | } | | |
| 143 | | | |
| 144 | x->ss_count = search_site_count; | | |
| 145 | x->searches_per_step = 4; | | |
| 146 | } | | |
| 147 | | | |
| 148 | void vp8_init3smotion_compensation(MACROBLOCK *x, int stride) | | |
| 149 | { | | |
| 150 | int Len; | | |
| 151 | int search_site_count = 0; | | |
| 152 | | | |
| 153 | // Generate offsets for 8 search sites per step. | | |
| 154 | Len = MAX_FIRST_STEP; | | |
| 155 | x->ss[search_site_count].mv.col = 0; | | |
| 156 | x->ss[search_site_count].mv.row = 0; | | |
| 157 | x->ss[search_site_count].offset = 0; | | |
| 158 | search_site_count++; | | |
| 159 | | | |
| 160 | while (Len > 0) | | |
| 161 | { | | |
| 162 | | | |
| 163 | // Compute offsets for search sites. | | |
| 164 | x->ss[search_site_count].mv.col = 0; | | |
| 165 | x->ss[search_site_count].mv.row = -Len; | | |
| 166 | x->ss[search_site_count].offset = -Len * stride; | | |
| 167 | search_site_count++; | | |
| 168 | | | |
| 169 | // Compute offsets for search sites. | | |
| 170 | x->ss[search_site_count].mv.col = 0; | | |
| 171 | x->ss[search_site_count].mv.row = Len; | | |
| 172 | x->ss[search_site_count].offset = Len * stride; | | |
| 173 | search_site_count++; | | |
| 174 | | | |
| 175 | // Compute offsets for search sites. | | |
| 176 | x->ss[search_site_count].mv.col = -Len; | | |
| 177 | x->ss[search_site_count].mv.row = 0; | | |
| 178 | x->ss[search_site_count].offset = -Len; | | |
| 179 | search_site_count++; | | |
| 180 | | | |
| 181 | // Compute offsets for search sites. | | |
| 182 | x->ss[search_site_count].mv.col = Len; | | |
| 183 | x->ss[search_site_count].mv.row = 0; | | |
| 184 | x->ss[search_site_count].offset = Len; | | |
| 185 | search_site_count++; | | |
| 186 | | | |
| 187 | // Compute offsets for search sites. | | |
| 188 | x->ss[search_site_count].mv.col = -Len; | | |
| 189 | x->ss[search_site_count].mv.row = -Len; | | |
| 190 | x->ss[search_site_count].offset = -Len * stride - Len; | | |
| 191 | search_site_count++; | | |
| 192 | | | |
| 193 | // Compute offsets for search sites. | | |
| 194 | x->ss[search_site_count].mv.col = Len; | | |
| 195 | x->ss[search_site_count].mv.row = -Len; | | |
| 196 | x->ss[search_site_count].offset = -Len * stride + Len; | | |
| 197 | search_site_count++; | | |
| 198 | | | |
| 199 | // Compute offsets for search sites. | | |
| 200 | x->ss[search_site_count].mv.col = -Len; | | |
| 201 | x->ss[search_site_count].mv.row = Len; | | |
| 202 | x->ss[search_site_count].offset = Len * stride - Len; | | |
| 203 | search_site_count++; | | |
| 204 | | | |
| 205 | // Compute offsets for search sites. | | |
| 206 | x->ss[search_site_count].mv.col = Len; | | |
| 207 | x->ss[search_site_count].mv.row = Len; | | |
| 208 | x->ss[search_site_count].offset = Len * stride + Len; | | |
| 209 | search_site_count++; | | |
| 210 | | | |
| 211 | | | |
| 212 | // Contract. | | |
| 213 | Len /= 2; | | |
| 214 | } | | |
| 215 | | | |
| 216 | x->ss_count = search_site_count; | | |
| 217 | x->searches_per_step = 8; | | |
| 218 | } | | |
| 219 | | | |
| 220 | | | |
| 221 | #define MVC(r,c) (((mvcost[0][(r)-rr] + mvcost[1][(c) - rc]) * error_per_bit + 128 )>>8 ) // estimated cost of a motion vector (r,c) | | |
| 222 | #define PRE(r,c) (*(d->base_pre) + d->pre + ((r)>>2) * d->pre_stride + ((c)>>2)) // pointer to predictor base of a motionvector | | |
| 223 | #define SP(x) (((x)&3)<<1) // convert motion vector component to offset for svf calc | | |
| 224 | #define DIST(r,c) svf( PRE(r,c), d->pre_stride, SP(c),SP(r), z,b->src_stride,&sse) // returns subpixel variance error function. | | |
| 225 | #define IFMVCV(r,c,s,e) if ( c >= minc && c <= maxc && r >= minr && r <= maxr) s else e; | | |
| 226 | #define ERR(r,c) (MVC(r,c)+DIST(r,c)) // returns distortion + motion vector cost | | |
| 227 | #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 | | |
| 228 | #define MIN(x,y) (((x)<(y))?(x):(y)) | | |
| 229 | #define MAX(x,y) (((x)>(y))?(x):(y)) | | |
| 230 | | | |
| 231 | //#define CHECK_BETTER(v,r,c) if((v = ERR(r,c)) < besterr) { besterr = v; br=r; bc=c; } | | |
| 232 | | | |
| 233 | int vp8_find_best_sub_pixel_step_iteratively(MACROBLOCK *x, BLOCK *b, BLOCKD *d, MV *bestmv, MV *ref_mv, int error_per_bit, vp8_subpixvariance_fn_t svf, vp8_variance_fn_t vf, int *mvcost[2]) | | |
| 234 | { | | |
| 235 | unsigned char *y = *(d->base_pre) + d->pre + (bestmv->row) * d->pre_stride + bestmv->col; | | |
| 236 | unsigned char *z = (*(b->base_src) + b->src); | | |
| 237 | | | |
| 238 | int rr = ref_mv->row >> 1, rc = ref_mv->col >> 1; | | |
| 239 | int br = bestmv->row << 2, bc = bestmv->col << 2; | | |
| 240 | int tr = br, tc = bc; | | |
| 241 | unsigned int besterr = INT_MAX; | | |
| 242 | unsigned int left, right, up, down, diag; | | |
| 243 | unsigned int sse; | | |
| 244 | unsigned int whichdir; | | |
| 245 | unsigned int halfiters = 4; | | |
| 246 | unsigned int quarteriters = 4; | | |
| 247 | | | |
| 248 | int minc = MAX(x->mv_col_min << 2, (ref_mv->col >> 1) - ((1 << mvlong_width) - 1)); | | |
| 249 | int maxc = MIN(x->mv_col_max << 2, (ref_mv->col >> 1) + ((1 << mvlong_width) - 1)); | | |
| 250 | int minr = MAX(x->mv_row_min << 2, (ref_mv->row >> 1) - ((1 << mvlong_width) - 1)); | | |
| 251 | int maxr = MIN(x->mv_row_max << 2, (ref_mv->row >> 1) + ((1 << mvlong_width) - 1)); | | |
| 252 | | | |
| 253 | // central mv | | |
| 254 | bestmv->row <<= 3; | | |
| 255 | bestmv->col <<= 3; | | |
| 256 | | | |
| 257 | // calculate central point error | | |
| 258 | besterr = vf(y, d->pre_stride, z, b->src_stride, &sse); | | |
| 259 | besterr += vp8_mv_err_cost(bestmv, ref_mv, mvcost, error_per_bit); | | |
| 260 | | | |
| 261 | // TODO: Each subsequent iteration checks at least one point in common with the last iteration could be 2 ( if diag selected) | | |
| 262 | while (--halfiters) | | |
| 263 | { | | |
| 264 | // 1/2 pel | | |
| 265 | CHECK_BETTER(left, tr, tc - 2); | | |
| 266 | CHECK_BETTER(right, tr, tc + 2); | | |
| 267 | CHECK_BETTER(up, tr - 2, tc); | | |
| 268 | CHECK_BETTER(down, tr + 2, tc); | | |
| 269 | | | |
| 270 | whichdir = (left < right ? 0 : 1) + (up < down ? 0 : 2); | | |
| 271 | | 59 | |
| 272 | switch (whichdir) | | |
| 273 | { | | |
| 274 | case 0: | | |
| 275 | CHECK_BETTER(diag, tr - 2, tc - 2); | | |
| 276 | break; | | |
| 277 | case 1: | | |
| 278 | CHECK_BETTER(diag, tr - 2, tc + 2); | | |
| 279 | break; | | |
| 280 | case 2: | | |
| 281 | CHECK_BETTER(diag, tr + 2, tc - 2); | | |
| 282 | break; | | |
| 283 | case 3: | | |
| 284 | CHECK_BETTER(diag, tr + 2, tc + 2); | | |
| 285 | break; | | |
| 286 | } | | |
| 287 | | | |
| 288 | // no reason to check the same one again. | | |
| 289 | if (tr == br && tc == bc) | | |
| 290 | break; | | |
| 291 | | | |
| 292 | tr = br; | | |
| 293 | tc = bc; | | |
| 294 | } | | |
| 295 | | | |
| 296 | // TODO: Each subsequent iteration checks at least one point in common with the last iteration could be 2 ( if diag selected) | | |
| 297 | // 1/4 pel | | |
| 298 | while (--quarteriters) | | |
| 299 | { | | |
| 300 | CHECK_BETTER(left, tr, tc - 1); | | |
| 301 | CHECK_BETTER(right, tr, tc + 1); | | |
| 302 | CHECK_BETTER(up, tr - 1, tc); | | |
| 303 | CHECK_BETTER(down, tr + 1, tc); | | |
| 304 | | | |
| 305 | whichdir = (left < right ? 0 : 1) + (up < down ? 0 : 2); | | |
| 306 | | | |
| 307 | switch (whichdir) | | |
| 308 | { | | |
| 309 | case 0: | | |
| 310 | CHECK_BETTER(diag, tr - 1, tc - 1); | | |
| 311 | break; | | |
| 312 | case 1: | | |
| 313 | CHECK_BETTER(diag, tr - 1, tc + 1); | | |
| 314 | break; | | |
| 315 | case 2: | | |
| 316 | CHECK_BETTER(diag, tr + 1, tc - 1); | | |
| 317 | break; | | |
| 318 | case 3: | | |
| 319 | CHECK_BETTER(diag, tr + 1, tc + 1); | | |
| 320 | break; | | |
| 321 | } | | |
| 322 | | | |
| 323 | // no reason to check the same one again. | | |
| 324 | if (tr == br && tc == bc) | | |
| 325 | break; | | |
| 326 | | | |
| 327 | tr = br; | | |
| 328 | tc = bc; | | |
| 329 | } | | |
| 330 | | | |
| 331 | bestmv->row = br << 1; | | |
| 332 | bestmv->col = bc << 1; | | |
| 333 | | | |
| 334 | if ((abs(bestmv->col - ref_mv->col) > MAX_FULL_PEL_VAL) || (abs(bestmv->row - ref_mv->row) > MAX_FULL_PEL_VAL)) | | |
| 335 | return INT_MAX; | | |
| 336 | | | |
| 337 | return besterr; | | |
| 338 | } | | |
| 339 | #undef MVC | | |
| 340 | #undef PRE | | |
| 341 | #undef SP | | |
| 342 | #undef DIST | | |
| 343 | #undef ERR | | |
| 344 | #undef CHECK_BETTER | | |
| 345 | #undef MIN | | |
| 346 | #undef MAX | | |
| 347 | int vp8_find_best_sub_pixel_step(MACROBLOCK *x, BLOCK *b, BLOCKD *d, MV *bestmv, MV *ref_mv, int error_per_bit, vp8_subpixvariance_fn_t svf, vp8_variance_fn_t vf, int *mvcost[2]) | 60 | int vp8_find_best_sub_pixel_step(MACROBLOCK *x, BLOCK *b, BLOCKD *d, MV *bestmv, MV *ref_mv, int error_per_bit, vp8_subpixvariance_fn_t svf, vp8_variance_fn_t vf, int *mvcost[2]) |
| 348 | { | 61 | { |
| 349 | int bestmse = INT_MAX; | 62 | int bestmse = INT_MAX; |
| @@ -935,335 +648,6 @@ cal_neighbors: · 585 unmodified lines |
| 935 | #undef ERR | 648 | #undef ERR |
| 936 | #undef CHECK_BETTER | 649 | #undef CHECK_BETTER |
| 937 | | 650 | |
| 938 | int vp8_diamond_search_sad | | |
| 939 | ( | | |
| 940 | MACROBLOCK *x, | | |
| 941 | BLOCK *b, | | |
| 942 | BLOCKD *d, | | |
| 943 | MV *ref_mv, | | |
| 944 | MV *best_mv, | | |
| 945 | int search_param, | | |
| 946 | int error_per_bit, | | |
| 947 | int *num00, | | |
| 948 | vp8_variance_fn_ptr_t *fn_ptr, | | |
| 949 | int *mvsadcost[2], | | |
| 950 | int *mvcost[2] | | |
| 951 | ) | | |
| 952 | { | | |
| 953 | int i, j, step; | | |
| 954 | | | |
| 955 | unsigned char *what = (*(b->base_src) + b->src); | | |
| 956 | int what_stride = b->src_stride; | | |
| 957 | unsigned char *in_what; | | |
| 958 | int in_what_stride = d->pre_stride; | | |
| 959 | unsigned char *best_address; | | |
| 960 | | | |
| 961 | int tot_steps; | | |
| 962 | MV this_mv; | | |
| 963 | | | |
| 964 | int bestsad = INT_MAX; | | |
| 965 | int best_site = 0; | | |
| 966 | int last_site = 0; | | |
| 967 | | | |
| 968 | int ref_row = ref_mv->row >> 3; | | |
| 969 | int ref_col = ref_mv->col >> 3; | | |
| 970 | int this_row_offset; | | |
| 971 | int this_col_offset; | | |
| 972 | search_site *ss; | | |
| 973 | | | |
| 974 | unsigned char *check_here; | | |
| 975 | int thissad; | | |
| 976 | | | |
| 977 | // Work out the start point for the search | | |
| 978 | in_what = (unsigned char *)(*(d->base_pre) + d->pre + (ref_row * (d->pre_stride)) + ref_col); | | |
| 979 | best_address = in_what; | | |
| 980 | | | |
| 981 | // We need to check that the starting point for the search (as indicated by ref_mv) is within the buffer limits | | |
| 982 | if ((ref_col > x->mv_col_min) && (ref_col < x->mv_col_max) && | | |
| 983 | (ref_row > x->mv_row_min) && (ref_row < x->mv_row_max)) | | |
| 984 | { | | |
| 985 | // Check the starting position | | |
| 986 | bestsad = fn_ptr->sdf(what, what_stride, in_what, in_what_stride, 0x7fffffff) + vp8_mv_err_cost(ref_mv, ref_mv, mvsadcost, error_per_bit); | | |
| 987 | } | | |
| 988 | | | |
| 989 | // search_param determines the length of the initial step and hence the number of iterations | | |
| 990 | // 0 = initial step (MAX_FIRST_STEP) pel : 1 = (MAX_FIRST_STEP/2) pel, 2 = (MAX_FIRST_STEP/4) pel... etc. | | |
| 991 | ss = &x->ss[search_param * x->searches_per_step]; | | |
| 992 | tot_steps = (x->ss_count / x->searches_per_step) - search_param; | | |
| 993 | | | |
| 994 | i = 1; | | |
| 995 | best_mv->row = ref_row; | | |
| 996 | best_mv->col = ref_col; | | |
| 997 | | | |
| 998 | *num00 = 0; | | |
| 999 | | | |
| 1000 | for (step = 0; step < tot_steps ; step++) | | |
| 1001 | { | | |
| 1002 | for (j = 0 ; j < x->searches_per_step ; j++) | | |
| 1003 | { | | |
| 1004 | // Trap illegal vectors | | |
| 1005 | this_row_offset = best_mv->row + ss[i].mv.row; | | |
| 1006 | this_col_offset = best_mv->col + ss[i].mv.col; | | |
| 1007 | | | |
| 1008 | if ((this_col_offset > x->mv_col_min) && (this_col_offset < x->mv_col_max) && | | |
| 1009 | (this_row_offset > x->mv_row_min) && (this_row_offset < x->mv_row_max)) | | |
| 1010 | | | |
| 1011 | { | | |
| 1012 | check_here = ss[i].offset + best_address; | | |
| 1013 | thissad = fn_ptr->sdf(what, what_stride, check_here , in_what_stride, bestsad); | | |
| 1014 | | | |
| 1015 | if (thissad < bestsad) | | |
| 1016 | { | | |
| 1017 | this_mv.row = this_row_offset << 3; | | |
| 1018 | this_mv.col = this_col_offset << 3; | | |
| 1019 | thissad += vp8_mv_err_cost(&this_mv, ref_mv, mvsadcost, error_per_bit); | | |
| 1020 | | | |
| 1021 | if (thissad < bestsad) | | |
| 1022 | { | | |
| 1023 | bestsad = thissad; | | |
| 1024 | best_site = i; | | |
| 1025 | } | | |
| 1026 | } | | |
| 1027 | } | | |
| 1028 | | | |
| 1029 | i++; | | |
| 1030 | } | | |
| 1031 | | | |
| 1032 | if (best_site != last_site) | | |
| 1033 | { | | |
| 1034 | best_mv->row += ss[best_site].mv.row; | | |
| 1035 | best_mv->col += ss[best_site].mv.col; | | |
| 1036 | best_address += ss[best_site].offset; | | |
| 1037 | last_site = best_site; | | |
| 1038 | } | | |
| 1039 | else if (best_address == in_what) | | |
| 1040 | (*num00)++; | | |
| 1041 | } | | |
| 1042 | | | |
| 1043 | this_mv.row = best_mv->row << 3; | | |
| 1044 | this_mv.col = best_mv->col << 3; | | |
| 1045 | | | |
| 1046 | if (bestsad == INT_MAX) | | |
| 1047 | return INT_MAX; | | |
| 1048 | | | |
| 1049 | return fn_ptr->vf(what, what_stride, best_address, in_what_stride, (unsigned int *)(&thissad)) | | |
| 1050 | + vp8_mv_err_cost(&this_mv, ref_mv, mvcost, error_per_bit); | | |
| 1051 | } | | |
| 1052 | | | |
| 1053 | #if !(CONFIG_REALTIME_ONLY) | | |
| 1054 | int vp8_full_search_sad(MACROBLOCK *x, BLOCK *b, BLOCKD *d, MV *ref_mv, int error_per_bit, int distance, vp8_variance_fn_ptr_t *fn_ptr, int *mvcost[2], int *mvsadcost[2]) | | |
| 1055 | { | | |
| 1056 | unsigned char *what = (*(b->base_src) + b->src); | | |
| 1057 | int what_stride = b->src_stride; | | |
| 1058 | unsigned char *in_what; | | |
| 1059 | int in_what_stride = d->pre_stride; | | |
| 1060 | int mv_stride = d->pre_stride; | | |
| 1061 | unsigned char *bestaddress; | | |
| 1062 | MV *best_mv = &d->bmi.mv.as_mv; | | |
| 1063 | MV this_mv; | | |
| 1064 | int bestsad = INT_MAX; | | |
| 1065 | int r, c; | | |
| 1066 | | | |
| 1067 | unsigned char *check_here; | | |
| 1068 | int thissad; | | |
| 1069 | | | |
| 1070 | int ref_row = ref_mv->row >> 3; | | |
| 1071 | int ref_col = ref_mv->col >> 3; | | |
| 1072 | | | |
| 1073 | int row_min = ref_row - distance; | | |
| 1074 | int row_max = ref_row + distance; | | |
| 1075 | int col_min = ref_col - distance; | | |
| 1076 | int col_max = ref_col + distance; | | |
| 1077 | | | |
| 1078 | // Work out the mid point for the search | | |
| 1079 | in_what = *(d->base_pre) + d->pre; | | |
| 1080 | bestaddress = in_what + (ref_row * d->pre_stride) + ref_col; | | |
| 1081 | | | |
| 1082 | best_mv->row = ref_row; | | |
| 1083 | best_mv->col = ref_col; | | |
| 1084 | | | |
| 1085 | // We need to check that the starting point for the search (as indicated by ref_mv) is within the buffer limits | | |
| 1086 | if ((ref_col > x->mv_col_min) && (ref_col < x->mv_col_max) && | | |
| 1087 | (ref_row > x->mv_row_min) && (ref_row < x->mv_row_max)) | | |
| 1088 | { | | |
| 1089 | // Baseline value at the centre | | |
| 1090 | | | |
| 1091 | //bestsad = fn_ptr->sf( what,what_stride,bestaddress,in_what_stride) + (int)sqrt(vp8_mv_err_cost(ref_mv,ref_mv, mvcost,error_per_bit*14)); | | |
| 1092 | bestsad = fn_ptr->sdf(what, what_stride, bestaddress, in_what_stride, 0x7fffffff) + vp8_mv_err_cost(ref_mv, ref_mv, mvsadcost, error_per_bit); | | |
| 1093 | } | | |
| 1094 | | | |
| 1095 | // Apply further limits to prevent us looking using vectors that stretch beyiond the UMV border | | |
| 1096 | if (col_min < x->mv_col_min) | | |
| 1097 | col_min = x->mv_col_min; | | |
| 1098 | | | |
| 1099 | if (col_max > x->mv_col_max) | | |
| 1100 | col_max = x->mv_col_max; | | |
| 1101 | | | |
| 1102 | if (row_min < x->mv_row_min) | | |
| 1103 | row_min = x->mv_row_min; | | |
| 1104 | | | |
| 1105 | if (row_max > x->mv_row_max) | | |
| 1106 | row_max = x->mv_row_max; | | |
| 1107 | | | |
| 1108 | for (r = row_min; r < row_max ; r++) | | |
| 1109 | { | | |
| 1110 | this_mv.row = r << 3; | | |
| 1111 | check_here = r * mv_stride + in_what + col_min; | | |
| 1112 | | | |
| 1113 | for (c = col_min; c < col_max; c++) | | |
| 1114 | { | | |
| 1115 | thissad = fn_ptr->sdf(what, what_stride, check_here , in_what_stride, bestsad); | | |
| 1116 | | | |
| 1117 | this_mv.col = c << 3; | | |
| 1118 | //thissad += (int)sqrt(vp8_mv_err_cost(&this_mv,ref_mv, mvcost,error_per_bit*14)); | | |
| 1119 | //thissad += error_per_bit * mv_bits_sadcost[mv_bits(&this_mv, ref_mv, mvcost)]; | | |
| 1120 | thissad += vp8_mv_err_cost(&this_mv, ref_mv, mvsadcost, error_per_bit); //mv_bits(error_per_bit, &this_mv, ref_mv, mvsadcost); | | |
| 1121 | | | |
| 1122 | if (thissad < bestsad) | | |
| 1123 | { | | |
| 1124 | bestsad = thissad; | | |
| 1125 | best_mv->row = r; | | |
| 1126 | best_mv->col = c; | | |
| 1127 | bestaddress = check_here; | | |
| 1128 | } | | |
| 1129 | | | |
| 1130 | check_here++; | | |
| 1131 | } | | |
| 1132 | } | | |
| 1133 | | | |
| 1134 | this_mv.row = best_mv->row << 3; | | |
| 1135 | this_mv.col = best_mv->col << 3; | | |
| 1136 | | | |
| 1137 | if (bestsad < INT_MAX) | | |
| 1138 | return fn_ptr->vf(what, what_stride, bestaddress, in_what_stride, (unsigned int *)(&thissad)) | | |
| 1139 | + vp8_mv_err_cost(&this_mv, ref_mv, mvcost, error_per_bit); | | |
| 1140 | else | | |
| 1141 | return INT_MAX; | | |
| 1142 | } | | |
| 1143 | | | |
| 1144 | int vp8_full_search_sadx3(MACROBLOCK *x, BLOCK *b, BLOCKD *d, MV *ref_mv, int error_per_bit, int distance, vp8_variance_fn_ptr_t *fn_ptr, int *mvcost[2], int *mvsadcost[2]) | | |
| 1145 | { | | |
| 1146 | unsigned char *what = (*(b->base_src) + b->src); | | |
| 1147 | int what_stride = b->src_stride; | | |
| 1148 | unsigned char *in_what; | | |
| 1149 | int in_what_stride = d->pre_stride; | | |
| 1150 | int mv_stride = d->pre_stride; | | |
| 1151 | unsigned char *bestaddress; | | |
| 1152 | MV *best_mv = &d->bmi.mv.as_mv; | | |
| 1153 | MV this_mv; | | |
| 1154 | int bestsad = INT_MAX; | | |
| 1155 | int r, c; | | |
| 1156 | | | |
| 1157 | unsigned char *check_here; | | |
| 1158 | unsigned int thissad; | | |
| 1159 | | | |
| 1160 | int ref_row = ref_mv->row >> 3; | | |
| 1161 | int ref_col = ref_mv->col >> 3; | | |
| 1162 | | | |
| 1163 | int row_min = ref_row - distance; | | |
| 1164 | int row_max = ref_row + distance; | | |
| 1165 | int col_min = ref_col - distance; | | |
| 1166 | int col_max = ref_col + distance; | | |
| 1167 | | | |
| 1168 | unsigned int sad_array[3]; | | |
| 1169 | | | |
| 1170 | // Work out the mid point for the search | | |
| 1171 | in_what = *(d->base_pre) + d->pre; | | |
| 1172 | bestaddress = in_what + (ref_row * d->pre_stride) + ref_col; | | |
| 1173 | | | |
| 1174 | best_mv->row = ref_row; | | |
| 1175 | best_mv->col = ref_col; | | |
| 1176 | | | |
| 1177 | // We need to check that the starting point for the search (as indicated by ref_mv) is within the buffer limits | | |
| 1178 | if ((ref_col > x->mv_col_min) && (ref_col < x->mv_col_max) && | | |
| 1179 | (ref_row > x->mv_row_min) && (ref_row < x->mv_row_max)) | | |
| 1180 | { | | |
| 1181 | // Baseline value at the centre | | |
| 1182 | bestsad = fn_ptr->sdf(what, what_stride, bestaddress, in_what_stride, 0x7fffffff) + vp8_mv_err_cost(ref_mv, ref_mv, mvsadcost, error_per_bit); | | |
| 1183 | } | | |
| 1184 | | | |
| 1185 | // Apply further limits to prevent us looking using vectors that stretch beyiond the UMV border | | |
| 1186 | if (col_min < x->mv_col_min) | | |
| 1187 | col_min = x->mv_col_min; | | |
| 1188 | | | |
| 1189 | if (col_max > x->mv_col_max) | | |
| 1190 | col_max = x->mv_col_max; | | |
| 1191 | | | |
| 1192 | if (row_min < x->mv_row_min) | | |
| 1193 | row_min = x->mv_row_min; | | |
| 1194 | | | |
| 1195 | if (row_max > x->mv_row_max) | | |
| 1196 | row_max = x->mv_row_max; | | |
| 1197 | | | |
| 1198 | for (r = row_min; r < row_max ; r++) | | |
| 1199 | { | | |
| 1200 | this_mv.row = r << 3; | | |
| 1201 | check_here = r * mv_stride + in_what + col_min; | | |
| 1202 | c = col_min; | | |
| 1203 | | | |
| 1204 | while ((c + 3) < col_max) | | |
| 1205 | { | | |
| 1206 | int i; | | |
| 1207 | | | |
| 1208 | fn_ptr->sdx3f(what, what_stride, check_here , in_what_stride, sad_array); | | |
| 1209 | | | |
| 1210 | for (i = 0; i < 3; i++) | | |
| 1211 | { | | |
| 1212 | thissad = sad_array[i]; | | |
| 1213 | | | |
| 1214 | if (thissad < bestsad) | | |
| 1215 | { | | |
| 1216 | this_mv.col = c << 3; | | |
| 1217 | thissad += vp8_mv_err_cost(&this_mv, ref_mv, mvsadcost, error_per_bit); | | |
| 1218 | | | |
| 1219 | if (thissad < bestsad) | | |
| 1220 | { | | |
| 1221 | bestsad = thissad; | | |
| 1222 | best_mv->row = r; | | |
| 1223 | best_mv->col = c; | | |
| 1224 | bestaddress = check_here; | | |
| 1225 | } | | |
| 1226 | } | | |
| 1227 | | | |
| 1228 | check_here++; | | |
| 1229 | c++; | | |
| 1230 | } | | |
| 1231 | } | | |
| 1232 | | | |
| 1233 | while (c < col_max) | | |
| 1234 | { | | |
| 1235 | thissad = fn_ptr->sdf(what, what_stride, check_here , in_what_stride, bestsad); | | |
| 1236 | | | |
| 1237 | if (thissad < bestsad) | | |
| 1238 | { | | |
| 1239 | this_mv.col = c << 3; | | |
| 1240 | thissad += vp8_mv_err_cost(&this_mv, ref_mv, mvsadcost, error_per_bit); | | |
| 1241 | | | |
| 1242 | if (thissad < bestsad) | | |
| 1243 | { | | |
| 1244 | bestsad = thissad; | | |
| 1245 | best_mv->row = r; | | |
| 1246 | best_mv->col = c; | | |
| 1247 | bestaddress = check_here; | | |
| 1248 | } | | |
| 1249 | } | | |
| 1250 | | | |
| 1251 | check_here ++; | | |
| 1252 | c ++; | | |
| 1253 | } | | |
| 1254 | | | |
| 1255 | } | | |
| 1256 | | | |
| 1257 | this_mv.row = best_mv->row << 3; | | |
| 1258 | this_mv.col = best_mv->col << 3; | | |
| 1259 | | | |
| 1260 | if (bestsad < INT_MAX) | | |
| 1261 | return fn_ptr->vf(what, what_stride, bestaddress, in_what_stride, (unsigned int *)(&thissad)) | | |
| 1262 | + vp8_mv_err_cost(&this_mv, ref_mv, mvcost, error_per_bit); | | |
| 1263 | else | | |
| 1264 | return INT_MAX; | | |
| 1265 | } | | |
| 1266 | #endif | | |
| 1267 | | 651 | |
| 1268 | #ifdef ENTROPY_STATS | 652 | #ifdef ENTROPY_STATS |
| 1269 | void print_mode_context(void) | 653 | void print_mode_context(void) |