Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(510)

Side by Side Diff: source/libvpx/vp9/encoder/vp9_mcomp.c

Issue 54923004: libvpx: Pull from upstream (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/libvpx/
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_mcomp.h ('k') | source/libvpx/vp9/encoder/vp9_modecosts.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 sr++; 52 sr++;
53 53
54 if (sr) 54 if (sr)
55 sr--; 55 sr--;
56 56
57 sr += cpi->sf.reduce_first_step_size; 57 sr += cpi->sf.reduce_first_step_size;
58 sr = MIN(sr, (cpi->sf.max_step_search_steps - 2)); 58 sr = MIN(sr, (cpi->sf.max_step_search_steps - 2));
59 return sr; 59 return sr;
60 } 60 }
61 61
62 int vp9_mv_bit_cost(int_mv *mv, int_mv *ref, int *mvjcost, int *mvcost[2], 62 static INLINE int mv_cost(const MV *mv,
63 int weight) { 63 const int *joint_cost, int *comp_cost[2]) {
64 MV v; 64 return joint_cost[vp9_get_mv_joint(mv)] +
65 v.row = mv->as_mv.row - ref->as_mv.row; 65 comp_cost[0][mv->row] + comp_cost[1][mv->col];
66 v.col = mv->as_mv.col - ref->as_mv.col;
67 return ROUND_POWER_OF_TWO((mvjcost[vp9_get_mv_joint(&v)] +
68 mvcost[0][v.row] +
69 mvcost[1][v.col]) * weight, 7);
70 } 66 }
71 67
72 static int mv_err_cost(int_mv *mv, int_mv *ref, int *mvjcost, int *mvcost[2], 68 int vp9_mv_bit_cost(const MV *mv, const MV *ref,
69 const int *mvjcost, int *mvcost[2], int weight) {
70 const MV diff = { mv->row - ref->row,
71 mv->col - ref->col };
72 return ROUND_POWER_OF_TWO(mv_cost(&diff, mvjcost, mvcost) * weight, 7);
73 }
74
75 static int mv_err_cost(const MV *mv, const MV *ref,
76 const int *mvjcost, int *mvcost[2],
73 int error_per_bit) { 77 int error_per_bit) {
74 if (mvcost) { 78 if (mvcost) {
75 MV v; 79 const MV diff = { mv->row - ref->row,
76 v.row = mv->as_mv.row - ref->as_mv.row; 80 mv->col - ref->col };
77 v.col = mv->as_mv.col - ref->as_mv.col; 81 return ROUND_POWER_OF_TWO(mv_cost(&diff, mvjcost, mvcost) *
78 return ROUND_POWER_OF_TWO((mvjcost[vp9_get_mv_joint(&v)] + 82 error_per_bit, 13);
79 mvcost[0][v.row] +
80 mvcost[1][v.col]) * error_per_bit, 13);
81 } 83 }
82 return 0; 84 return 0;
83 } 85 }
84 86
85 static int mvsad_err_cost(int_mv *mv, int_mv *ref, int *mvjsadcost, 87 static int mvsad_err_cost(const MV *mv, const MV *ref,
86 int *mvsadcost[2], int error_per_bit) { 88 const int *mvjsadcost, int *mvsadcost[2],
89 int error_per_bit) {
87 if (mvsadcost) { 90 if (mvsadcost) {
88 MV v; 91 const MV diff = { mv->row - ref->row,
89 v.row = mv->as_mv.row - ref->as_mv.row; 92 mv->col - ref->col };
90 v.col = mv->as_mv.col - ref->as_mv.col; 93 return ROUND_POWER_OF_TWO(mv_cost(&diff, mvjsadcost, mvsadcost) *
91 return ROUND_POWER_OF_TWO((mvjsadcost[vp9_get_mv_joint(&v)] + 94 error_per_bit, 8);
92 mvsadcost[0][v.row] +
93 mvsadcost[1][v.col]) * error_per_bit, 8);
94 } 95 }
95 return 0; 96 return 0;
96 } 97 }
97 98
98 void vp9_init_dsmotion_compensation(MACROBLOCK *x, int stride) { 99 void vp9_init_dsmotion_compensation(MACROBLOCK *x, int stride) {
99 int len; 100 int len;
100 int search_site_count = 0; 101 int search_site_count = 0;
101 102
102 // Generate offsets for 4 search sites per step. 103 // Generate offsets for 4 search sites per step.
103 x->ss[search_site_count].mv.col = 0; 104 x->ss[search_site_count].mv.col = 0;
(...skipping 25 matching lines...) Expand all
129 x->ss[search_site_count].mv.row = 0; 130 x->ss[search_site_count].mv.row = 0;
130 x->ss[search_site_count].offset = len; 131 x->ss[search_site_count].offset = len;
131 search_site_count++; 132 search_site_count++;
132 } 133 }
133 134
134 x->ss_count = search_site_count; 135 x->ss_count = search_site_count;
135 x->searches_per_step = 4; 136 x->searches_per_step = 4;
136 } 137 }
137 138
138 void vp9_init3smotion_compensation(MACROBLOCK *x, int stride) { 139 void vp9_init3smotion_compensation(MACROBLOCK *x, int stride) {
139 int len; 140 int len, ss_count = 1;
140 int search_site_count = 0;
141 141
142 // Generate offsets for 8 search sites per step. 142 x->ss[0].mv.col = x->ss[0].mv.row = 0;
143 x->ss[search_site_count].mv.col = 0; 143 x->ss[0].offset = 0;
144 x->ss[search_site_count].mv.row = 0;
145 x->ss[search_site_count].offset = 0;
146 search_site_count++;
147 144
148 for (len = MAX_FIRST_STEP; len > 0; len /= 2) { 145 for (len = MAX_FIRST_STEP; len > 0; len /= 2) {
149 // Compute offsets for search sites. 146 // Generate offsets for 8 search sites per step.
150 x->ss[search_site_count].mv.col = 0; 147 const MV ss_mvs[8] = {
151 x->ss[search_site_count].mv.row = -len; 148 {-len, 0 }, {len, 0 }, { 0, -len}, {0, len},
152 x->ss[search_site_count].offset = -len * stride; 149 {-len, -len}, {-len, len}, {len, -len}, {len, len}
153 search_site_count++; 150 };
154 151 int i;
155 // Compute offsets for search sites. 152 for (i = 0; i < 8; ++i) {
156 x->ss[search_site_count].mv.col = 0; 153 search_site *const ss = &x->ss[ss_count++];
157 x->ss[search_site_count].mv.row = len; 154 ss->mv = ss_mvs[i];
158 x->ss[search_site_count].offset = len * stride; 155 ss->offset = ss->mv.row * stride + ss->mv.col;
159 search_site_count++; 156 }
160
161 // Compute offsets for search sites.
162 x->ss[search_site_count].mv.col = -len;
163 x->ss[search_site_count].mv.row = 0;
164 x->ss[search_site_count].offset = -len;
165 search_site_count++;
166
167 // Compute offsets for search sites.
168 x->ss[search_site_count].mv.col = len;
169 x->ss[search_site_count].mv.row = 0;
170 x->ss[search_site_count].offset = len;
171 search_site_count++;
172
173 // Compute offsets for search sites.
174 x->ss[search_site_count].mv.col = -len;
175 x->ss[search_site_count].mv.row = -len;
176 x->ss[search_site_count].offset = -len * stride - len;
177 search_site_count++;
178
179 // Compute offsets for search sites.
180 x->ss[search_site_count].mv.col = len;
181 x->ss[search_site_count].mv.row = -len;
182 x->ss[search_site_count].offset = -len * stride + len;
183 search_site_count++;
184
185 // Compute offsets for search sites.
186 x->ss[search_site_count].mv.col = -len;
187 x->ss[search_site_count].mv.row = len;
188 x->ss[search_site_count].offset = len * stride - len;
189 search_site_count++;
190
191 // Compute offsets for search sites.
192 x->ss[search_site_count].mv.col = len;
193 x->ss[search_site_count].mv.row = len;
194 x->ss[search_site_count].offset = len * stride + len;
195 search_site_count++;
196 } 157 }
197 158
198 x->ss_count = search_site_count; 159 x->ss_count = ss_count;
199 x->searches_per_step = 8; 160 x->searches_per_step = 8;
200 } 161 }
201 162
202 /* 163 /*
203 * To avoid the penalty for crossing cache-line read, preload the reference 164 * To avoid the penalty for crossing cache-line read, preload the reference
204 * area in a small buffer, which is aligned to make sure there won't be crossing 165 * area in a small buffer, which is aligned to make sure there won't be crossing
205 * cache-line read while reading from this buffer. This reduced the cpu 166 * cache-line read while reading from this buffer. This reduced the cpu
206 * cycles spent on reading ref data in sub-pixel filter functions. 167 * cycles spent on reading ref data in sub-pixel filter functions.
207 * TODO: Currently, since sub-pixel search range here is -3 ~ 3, copy 22 rows x 168 * TODO: Currently, since sub-pixel search range here is -3 ~ 3, copy 22 rows x
208 * 32 cols area that is enough for 16x16 macroblock. Later, for SPLITMV, we 169 * 32 cols area that is enough for 16x16 macroblock. Later, for SPLITMV, we
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 break; \ 267 break; \
307 case 1: \ 268 case 1: \
308 case 3: \ 269 case 3: \
309 CHECK_BETTER(second, tr + kr, tc - hstep); \ 270 CHECK_BETTER(second, tr + kr, tc - hstep); \
310 break; \ 271 break; \
311 } \ 272 } \
312 } \ 273 } \
313 } 274 }
314 275
315 int vp9_find_best_sub_pixel_iterative(MACROBLOCK *x, 276 int vp9_find_best_sub_pixel_iterative(MACROBLOCK *x,
316 int_mv *bestmv, int_mv *ref_mv, 277 MV *bestmv, const MV *ref_mv,
278 int allow_hp,
317 int error_per_bit, 279 int error_per_bit,
318 const vp9_variance_fn_ptr_t *vfp, 280 const vp9_variance_fn_ptr_t *vfp,
319 int forced_stop, 281 int forced_stop,
320 int iters_per_step, 282 int iters_per_step,
321 int *mvjcost, int *mvcost[2], 283 int *mvjcost, int *mvcost[2],
322 int *distortion, 284 int *distortion,
323 unsigned int *sse1) { 285 unsigned int *sse1) {
324 uint8_t *z = x->plane[0].src.buf; 286 uint8_t *z = x->plane[0].src.buf;
325 int src_stride = x->plane[0].src.stride; 287 int src_stride = x->plane[0].src.stride;
326 MACROBLOCKD *xd = &x->e_mbd; 288 MACROBLOCKD *xd = &x->e_mbd;
327 289
328 unsigned int besterr = INT_MAX; 290 unsigned int besterr = INT_MAX;
329 unsigned int sse; 291 unsigned int sse;
330 unsigned int whichdir; 292 unsigned int whichdir;
331 unsigned int halfiters = iters_per_step; 293 unsigned int halfiters = iters_per_step;
332 unsigned int quarteriters = iters_per_step; 294 unsigned int quarteriters = iters_per_step;
333 unsigned int eighthiters = iters_per_step; 295 unsigned int eighthiters = iters_per_step;
334 int thismse; 296 int thismse;
335 297
336 uint8_t *y = xd->plane[0].pre[0].buf + 298 const int y_stride = xd->plane[0].pre[0].stride;
337 (bestmv->as_mv.row) * xd->plane[0].pre[0].stride + 299 const int offset = bestmv->row * y_stride + bestmv->col;
338 bestmv->as_mv.col; 300 uint8_t *y = xd->plane[0].pre[0].buf + offset;
339 301
340 const int y_stride = xd->plane[0].pre[0].stride; 302 int rr = ref_mv->row;
341 303 int rc = ref_mv->col;
342 int rr = ref_mv->as_mv.row; 304 int br = bestmv->row * 8;
343 int rc = ref_mv->as_mv.col; 305 int bc = bestmv->col * 8;
344 int br = bestmv->as_mv.row << 3;
345 int bc = bestmv->as_mv.col << 3;
346 int hstep = 4; 306 int hstep = 4;
347 const int minc = MAX(x->mv_col_min << 3, ref_mv->as_mv.col - MV_MAX); 307 const int minc = MAX(x->mv_col_min * 8, ref_mv->col - MV_MAX);
348 const int maxc = MIN(x->mv_col_max << 3, ref_mv->as_mv.col + MV_MAX); 308 const int maxc = MIN(x->mv_col_max * 8, ref_mv->col + MV_MAX);
349 const int minr = MAX(x->mv_row_min << 3, ref_mv->as_mv.row - MV_MAX); 309 const int minr = MAX(x->mv_row_min * 8, ref_mv->row - MV_MAX);
350 const int maxr = MIN(x->mv_row_max << 3, ref_mv->as_mv.row + MV_MAX); 310 const int maxr = MIN(x->mv_row_max * 8, ref_mv->row + MV_MAX);
351 311
352 int tr = br; 312 int tr = br;
353 int tc = bc; 313 int tc = bc;
354 314
355 const int offset = (bestmv->as_mv.row) * y_stride + bestmv->as_mv.col;
356
357 // central mv 315 // central mv
358 bestmv->as_mv.row <<= 3; 316 bestmv->row <<= 3;
359 bestmv->as_mv.col <<= 3; 317 bestmv->col <<= 3;
360 318
361 // calculate central point error 319 // calculate central point error
362 besterr = vfp->vf(y, y_stride, z, src_stride, sse1); 320 besterr = vfp->vf(y, y_stride, z, src_stride, sse1);
363 *distortion = besterr; 321 *distortion = besterr;
364 besterr += mv_err_cost(bestmv, ref_mv, mvjcost, mvcost, error_per_bit); 322 besterr += mv_err_cost(bestmv, ref_mv, mvjcost, mvcost, error_per_bit);
365 323
366 // TODO: Each subsequent iteration checks at least one point in 324 // TODO(jbb): Each subsequent iteration checks at least one point in
367 // common with the last iteration could be 2 ( if diag selected) 325 // common with the last iteration could be 2 if diagonal is selected.
368 while (halfiters--) { 326 while (halfiters--) {
369 // 1/2 pel 327 // 1/2 pel
370 FIRST_LEVEL_CHECKS; 328 FIRST_LEVEL_CHECKS;
371 // no reason to check the same one again. 329 // no reason to check the same one again.
372 if (tr == br && tc == bc) 330 if (tr == br && tc == bc)
373 break; 331 break;
374 tr = br; 332 tr = br;
375 tc = bc; 333 tc = bc;
376 } 334 }
377 335
378 // TODO: Each subsequent iteration checks at least one point in common with 336 // TODO(yaowu): Each subsequent iteration checks at least one point in common
379 // the last iteration could be 2 ( if diag selected) 1/4 pel 337 // with the last iteration could be 2 if diagonal is selected.
380 338
381 // Note forced_stop: 0 - full, 1 - qtr only, 2 - half only 339 // Note forced_stop: 0 - full, 1 - qtr only, 2 - half only
382 if (forced_stop != 2) { 340 if (forced_stop != 2) {
383 hstep >>= 1; 341 hstep >>= 1;
384 while (quarteriters--) { 342 while (quarteriters--) {
385 FIRST_LEVEL_CHECKS; 343 FIRST_LEVEL_CHECKS;
386 // no reason to check the same one again. 344 // no reason to check the same one again.
387 if (tr == br && tc == bc) 345 if (tr == br && tc == bc)
388 break; 346 break;
389 tr = br; 347 tr = br;
390 tc = bc; 348 tc = bc;
391 } 349 }
392 } 350 }
393 351
394 if (xd->allow_high_precision_mv && vp9_use_mv_hp(&ref_mv->as_mv) && 352 if (allow_hp && vp9_use_mv_hp(ref_mv) && forced_stop == 0) {
395 forced_stop == 0) {
396 hstep >>= 1; 353 hstep >>= 1;
397 while (eighthiters--) { 354 while (eighthiters--) {
398 FIRST_LEVEL_CHECKS; 355 FIRST_LEVEL_CHECKS;
399 // no reason to check the same one again. 356 // no reason to check the same one again.
400 if (tr == br && tc == bc) 357 if (tr == br && tc == bc)
401 break; 358 break;
402 tr = br; 359 tr = br;
403 tc = bc; 360 tc = bc;
404 } 361 }
405 } 362 }
406 363
407 bestmv->as_mv.row = br; 364 bestmv->row = br;
408 bestmv->as_mv.col = bc; 365 bestmv->col = bc;
409 366
410 if ((abs(bestmv->as_mv.col - ref_mv->as_mv.col) > (MAX_FULL_PEL_VAL << 3)) || 367 if ((abs(bestmv->col - ref_mv->col) > (MAX_FULL_PEL_VAL << 3)) ||
411 (abs(bestmv->as_mv.row - ref_mv->as_mv.row) > (MAX_FULL_PEL_VAL << 3))) 368 (abs(bestmv->row - ref_mv->row) > (MAX_FULL_PEL_VAL << 3)))
412 return INT_MAX; 369 return INT_MAX;
413 370
414 return besterr; 371 return besterr;
415 } 372 }
416 373
417 int vp9_find_best_sub_pixel_tree(MACROBLOCK *x, 374 int vp9_find_best_sub_pixel_tree(MACROBLOCK *x,
418 int_mv *bestmv, int_mv *ref_mv, 375 MV *bestmv, const MV *ref_mv,
376 int allow_hp,
419 int error_per_bit, 377 int error_per_bit,
420 const vp9_variance_fn_ptr_t *vfp, 378 const vp9_variance_fn_ptr_t *vfp,
421 int forced_stop, 379 int forced_stop,
422 int iters_per_step, 380 int iters_per_step,
423 int *mvjcost, int *mvcost[2], 381 int *mvjcost, int *mvcost[2],
424 int *distortion, 382 int *distortion,
425 unsigned int *sse1) { 383 unsigned int *sse1) {
426 uint8_t *z = x->plane[0].src.buf; 384 uint8_t *z = x->plane[0].src.buf;
427 int src_stride = x->plane[0].src.stride; 385 const int src_stride = x->plane[0].src.stride;
428 MACROBLOCKD *xd = &x->e_mbd; 386 MACROBLOCKD *xd = &x->e_mbd;
429 int rr, rc, br, bc, hstep;
430 int tr, tc;
431 unsigned int besterr = INT_MAX; 387 unsigned int besterr = INT_MAX;
432 unsigned int sse; 388 unsigned int sse;
433 unsigned int whichdir; 389 unsigned int whichdir;
434 int thismse; 390 int thismse;
435 int maxc, minc, maxr, minr;
436 int y_stride;
437 int offset;
438 unsigned int halfiters = iters_per_step; 391 unsigned int halfiters = iters_per_step;
439 unsigned int quarteriters = iters_per_step; 392 unsigned int quarteriters = iters_per_step;
440 unsigned int eighthiters = iters_per_step; 393 unsigned int eighthiters = iters_per_step;
441 394
442 uint8_t *y = xd->plane[0].pre[0].buf + 395 const int y_stride = xd->plane[0].pre[0].stride;
443 (bestmv->as_mv.row) * xd->plane[0].pre[0].stride + 396 const int offset = bestmv->row * y_stride + bestmv->col;
444 bestmv->as_mv.col; 397 uint8_t *y = xd->plane[0].pre[0].buf + offset;
445 398
446 y_stride = xd->plane[0].pre[0].stride; 399 int rr = ref_mv->row;
400 int rc = ref_mv->col;
401 int br = bestmv->row * 8;
402 int bc = bestmv->col * 8;
403 int hstep = 4;
404 const int minc = MAX(x->mv_col_min * 8, ref_mv->col - MV_MAX);
405 const int maxc = MIN(x->mv_col_max * 8, ref_mv->col + MV_MAX);
406 const int minr = MAX(x->mv_row_min * 8, ref_mv->row - MV_MAX);
407 const int maxr = MIN(x->mv_row_max * 8, ref_mv->row + MV_MAX);
447 408
448 rr = ref_mv->as_mv.row; 409 int tr = br;
449 rc = ref_mv->as_mv.col; 410 int tc = bc;
450 br = bestmv->as_mv.row << 3;
451 bc = bestmv->as_mv.col << 3;
452 hstep = 4;
453 minc = MAX(x->mv_col_min << 3,
454 (ref_mv->as_mv.col) - ((1 << MV_MAX_BITS) - 1));
455 maxc = MIN(x->mv_col_max << 3,
456 (ref_mv->as_mv.col) + ((1 << MV_MAX_BITS) - 1));
457 minr = MAX(x->mv_row_min << 3,
458 (ref_mv->as_mv.row) - ((1 << MV_MAX_BITS) - 1));
459 maxr = MIN(x->mv_row_max << 3,
460 (ref_mv->as_mv.row) + ((1 << MV_MAX_BITS) - 1));
461
462 tr = br;
463 tc = bc;
464
465 offset = (bestmv->as_mv.row) * y_stride + bestmv->as_mv.col;
466 411
467 // central mv 412 // central mv
468 bestmv->as_mv.row <<= 3; 413 bestmv->row *= 8;
469 bestmv->as_mv.col <<= 3; 414 bestmv->col *= 8;
470 415
471 // calculate central point error 416 // calculate central point error
472 besterr = vfp->vf(y, y_stride, z, src_stride, sse1); 417 besterr = vfp->vf(y, y_stride, z, src_stride, sse1);
473 *distortion = besterr; 418 *distortion = besterr;
474 besterr += mv_err_cost(bestmv, ref_mv, mvjcost, mvcost, error_per_bit); 419 besterr += mv_err_cost(bestmv, ref_mv, mvjcost, mvcost, error_per_bit);
475 420
476 // 1/2 pel 421 // 1/2 pel
477 FIRST_LEVEL_CHECKS; 422 FIRST_LEVEL_CHECKS;
478 if (halfiters > 1) { 423 if (halfiters > 1) {
479 SECOND_LEVEL_CHECKS; 424 SECOND_LEVEL_CHECKS;
480 } 425 }
481 tr = br; 426 tr = br;
482 tc = bc; 427 tc = bc;
483 428
484 // Note forced_stop: 0 - full, 1 - qtr only, 2 - half only 429 // Note forced_stop: 0 - full, 1 - qtr only, 2 - half only
485 if (forced_stop != 2) { 430 if (forced_stop != 2) {
486 hstep >>= 1; 431 hstep >>= 1;
487 FIRST_LEVEL_CHECKS; 432 FIRST_LEVEL_CHECKS;
488 if (quarteriters > 1) { 433 if (quarteriters > 1) {
489 SECOND_LEVEL_CHECKS; 434 SECOND_LEVEL_CHECKS;
490 } 435 }
491 tr = br; 436 tr = br;
492 tc = bc; 437 tc = bc;
493 } 438 }
494 439
495 if (xd->allow_high_precision_mv && vp9_use_mv_hp(&ref_mv->as_mv) && 440 if (allow_hp && vp9_use_mv_hp(ref_mv) && forced_stop == 0) {
496 forced_stop == 0) {
497 hstep >>= 1; 441 hstep >>= 1;
498 FIRST_LEVEL_CHECKS; 442 FIRST_LEVEL_CHECKS;
499 if (eighthiters > 1) { 443 if (eighthiters > 1) {
500 SECOND_LEVEL_CHECKS; 444 SECOND_LEVEL_CHECKS;
501 } 445 }
502 tr = br; 446 tr = br;
503 tc = bc; 447 tc = bc;
504 } 448 }
505 449
506 bestmv->as_mv.row = br; 450 bestmv->row = br;
507 bestmv->as_mv.col = bc; 451 bestmv->col = bc;
508 452
509 if ((abs(bestmv->as_mv.col - ref_mv->as_mv.col) > (MAX_FULL_PEL_VAL << 3)) || 453 if ((abs(bestmv->col - ref_mv->col) > (MAX_FULL_PEL_VAL << 3)) ||
510 (abs(bestmv->as_mv.row - ref_mv->as_mv.row) > (MAX_FULL_PEL_VAL << 3))) 454 (abs(bestmv->row - ref_mv->row) > (MAX_FULL_PEL_VAL << 3)))
511 return INT_MAX; 455 return INT_MAX;
512 456
513 return besterr; 457 return besterr;
514 } 458 }
515 459
516 #undef DIST 460 #undef DIST
517 /* returns subpixel variance error function */ 461 /* returns subpixel variance error function */
518 #define DIST(r, c) \ 462 #define DIST(r, c) \
519 vfp->svaf(PRE(r, c), y_stride, SP(c), SP(r), \ 463 vfp->svaf(PRE(r, c), y_stride, SP(c), SP(r), \
520 z, src_stride, &sse, second_pred) 464 z, src_stride, &sse, second_pred)
521 465
522 int vp9_find_best_sub_pixel_comp_iterative(MACROBLOCK *x, 466 int vp9_find_best_sub_pixel_comp_iterative(MACROBLOCK *x,
523 int_mv *bestmv, int_mv *ref_mv, 467 MV *bestmv, const MV *ref_mv,
468 int allow_hp,
524 int error_per_bit, 469 int error_per_bit,
525 const vp9_variance_fn_ptr_t *vfp, 470 const vp9_variance_fn_ptr_t *vfp,
526 int forced_stop, 471 int forced_stop,
527 int iters_per_step, 472 int iters_per_step,
528 int *mvjcost, int *mvcost[2], 473 int *mvjcost, int *mvcost[2],
529 int *distortion, 474 int *distortion,
530 unsigned int *sse1, 475 unsigned int *sse1,
531 const uint8_t *second_pred, 476 const uint8_t *second_pred,
532 int w, int h) { 477 int w, int h) {
533 uint8_t *const z = x->plane[0].src.buf; 478 uint8_t *const z = x->plane[0].src.buf;
534 const int src_stride = x->plane[0].src.stride; 479 const int src_stride = x->plane[0].src.stride;
535 MACROBLOCKD *const xd = &x->e_mbd; 480 MACROBLOCKD *const xd = &x->e_mbd;
536 481
537 unsigned int besterr = INT_MAX; 482 unsigned int besterr = INT_MAX;
538 unsigned int sse; 483 unsigned int sse;
539 unsigned int whichdir; 484 unsigned int whichdir;
540 unsigned int halfiters = iters_per_step; 485 unsigned int halfiters = iters_per_step;
541 unsigned int quarteriters = iters_per_step; 486 unsigned int quarteriters = iters_per_step;
542 unsigned int eighthiters = iters_per_step; 487 unsigned int eighthiters = iters_per_step;
543 int thismse; 488 int thismse;
544 489
545 DECLARE_ALIGNED_ARRAY(16, uint8_t, comp_pred, 64 * 64); 490 DECLARE_ALIGNED_ARRAY(16, uint8_t, comp_pred, 64 * 64);
546 uint8_t *const y = xd->plane[0].pre[0].buf + 491 const int y_stride = xd->plane[0].pre[0].stride;
547 (bestmv->as_mv.row) * xd->plane[0].pre[0].stride + 492 const int offset = bestmv->row * y_stride + bestmv->col;
548 bestmv->as_mv.col; 493 uint8_t *const y = xd->plane[0].pre[0].buf + offset;
549 494
550 const int y_stride = xd->plane[0].pre[0].stride; 495 int rr = ref_mv->row;
551 496 int rc = ref_mv->col;
552 int rr = ref_mv->as_mv.row; 497 int br = bestmv->row * 8;
553 int rc = ref_mv->as_mv.col; 498 int bc = bestmv->col * 8;
554 int br = bestmv->as_mv.row << 3;
555 int bc = bestmv->as_mv.col << 3;
556 int hstep = 4; 499 int hstep = 4;
557 const int minc = MAX(x->mv_col_min << 3, ref_mv->as_mv.col - MV_MAX); 500 const int minc = MAX(x->mv_col_min * 8, ref_mv->col - MV_MAX);
558 const int maxc = MIN(x->mv_col_max << 3, ref_mv->as_mv.col + MV_MAX); 501 const int maxc = MIN(x->mv_col_max * 8, ref_mv->col + MV_MAX);
559 const int minr = MAX(x->mv_row_min << 3, ref_mv->as_mv.row - MV_MAX); 502 const int minr = MAX(x->mv_row_min * 8, ref_mv->row - MV_MAX);
560 const int maxr = MIN(x->mv_row_max << 3, ref_mv->as_mv.row + MV_MAX); 503 const int maxr = MIN(x->mv_row_max * 8, ref_mv->row + MV_MAX);
561 504
562 int tr = br; 505 int tr = br;
563 int tc = bc; 506 int tc = bc;
564 507
565 const int offset = (bestmv->as_mv.row) * y_stride + bestmv->as_mv.col;
566
567 // central mv 508 // central mv
568 bestmv->as_mv.row <<= 3; 509 bestmv->row *= 8;
569 bestmv->as_mv.col <<= 3; 510 bestmv->col *= 8;
570 511
571 // calculate central point error 512 // calculate central point error
572 // TODO(yunqingwang): central pointer error was already calculated in full- 513 // TODO(yunqingwang): central pointer error was already calculated in full-
573 // pixel search, and can be passed in this function. 514 // pixel search, and can be passed in this function.
574 comp_avg_pred(comp_pred, second_pred, w, h, y, y_stride); 515 comp_avg_pred(comp_pred, second_pred, w, h, y, y_stride);
575 besterr = vfp->vf(comp_pred, w, z, src_stride, sse1); 516 besterr = vfp->vf(comp_pred, w, z, src_stride, sse1);
576 *distortion = besterr; 517 *distortion = besterr;
577 besterr += mv_err_cost(bestmv, ref_mv, mvjcost, mvcost, error_per_bit); 518 besterr += mv_err_cost(bestmv, ref_mv, mvjcost, mvcost, error_per_bit);
578 519
579 // Each subsequent iteration checks at least one point in 520 // Each subsequent iteration checks at least one point in
(...skipping 17 matching lines...) Expand all
597 while (quarteriters--) { 538 while (quarteriters--) {
598 FIRST_LEVEL_CHECKS; 539 FIRST_LEVEL_CHECKS;
599 // no reason to check the same one again. 540 // no reason to check the same one again.
600 if (tr == br && tc == bc) 541 if (tr == br && tc == bc)
601 break; 542 break;
602 tr = br; 543 tr = br;
603 tc = bc; 544 tc = bc;
604 } 545 }
605 } 546 }
606 547
607 if (xd->allow_high_precision_mv && vp9_use_mv_hp(&ref_mv->as_mv) && 548 if (allow_hp && vp9_use_mv_hp(ref_mv) && forced_stop == 0) {
608 forced_stop == 0) {
609 hstep >>= 1; 549 hstep >>= 1;
610 while (eighthiters--) { 550 while (eighthiters--) {
611 FIRST_LEVEL_CHECKS; 551 FIRST_LEVEL_CHECKS;
612 // no reason to check the same one again. 552 // no reason to check the same one again.
613 if (tr == br && tc == bc) 553 if (tr == br && tc == bc)
614 break; 554 break;
615 tr = br; 555 tr = br;
616 tc = bc; 556 tc = bc;
617 } 557 }
618 } 558 }
619 bestmv->as_mv.row = br; 559 bestmv->row = br;
620 bestmv->as_mv.col = bc; 560 bestmv->col = bc;
621 561
622 if ((abs(bestmv->as_mv.col - ref_mv->as_mv.col) > (MAX_FULL_PEL_VAL << 3)) || 562 if ((abs(bestmv->col - ref_mv->col) > (MAX_FULL_PEL_VAL << 3)) ||
623 (abs(bestmv->as_mv.row - ref_mv->as_mv.row) > (MAX_FULL_PEL_VAL << 3))) 563 (abs(bestmv->row - ref_mv->row) > (MAX_FULL_PEL_VAL << 3)))
624 return INT_MAX; 564 return INT_MAX;
625 565
626 return besterr; 566 return besterr;
627 } 567 }
628 568
629 int vp9_find_best_sub_pixel_comp_tree(MACROBLOCK *x, 569 int vp9_find_best_sub_pixel_comp_tree(MACROBLOCK *x,
630 int_mv *bestmv, int_mv *ref_mv, 570 MV *bestmv, const MV *ref_mv,
571 int allow_hp,
631 int error_per_bit, 572 int error_per_bit,
632 const vp9_variance_fn_ptr_t *vfp, 573 const vp9_variance_fn_ptr_t *vfp,
633 int forced_stop, 574 int forced_stop,
634 int iters_per_step, 575 int iters_per_step,
635 int *mvjcost, int *mvcost[2], 576 int *mvjcost, int *mvcost[2],
636 int *distortion, 577 int *distortion,
637 unsigned int *sse1, 578 unsigned int *sse1,
638 const uint8_t *second_pred, 579 const uint8_t *second_pred,
639 int w, int h) { 580 int w, int h) {
640 uint8_t *z = x->plane[0].src.buf; 581 uint8_t *z = x->plane[0].src.buf;
641 int src_stride = x->plane[0].src.stride; 582 const int src_stride = x->plane[0].src.stride;
642 MACROBLOCKD *xd = &x->e_mbd; 583 MACROBLOCKD *xd = &x->e_mbd;
643 int rr, rc, br, bc, hstep;
644 int tr, tc;
645 unsigned int besterr = INT_MAX; 584 unsigned int besterr = INT_MAX;
646 unsigned int sse; 585 unsigned int sse;
647 unsigned int whichdir; 586 unsigned int whichdir;
648 int thismse; 587 int thismse;
649 int maxc, minc, maxr, minr;
650 int y_stride;
651 int offset;
652 unsigned int halfiters = iters_per_step; 588 unsigned int halfiters = iters_per_step;
653 unsigned int quarteriters = iters_per_step; 589 unsigned int quarteriters = iters_per_step;
654 unsigned int eighthiters = iters_per_step; 590 unsigned int eighthiters = iters_per_step;
655 591
656 DECLARE_ALIGNED_ARRAY(16, uint8_t, comp_pred, 64 * 64); 592 DECLARE_ALIGNED_ARRAY(16, uint8_t, comp_pred, 64 * 64);
657 uint8_t *y = xd->plane[0].pre[0].buf + 593 const int y_stride = xd->plane[0].pre[0].stride;
658 (bestmv->as_mv.row) * xd->plane[0].pre[0].stride + 594 const int offset = bestmv->row * y_stride + bestmv->col;
659 bestmv->as_mv.col; 595 uint8_t *y = xd->plane[0].pre[0].buf + offset;
660 596
661 y_stride = xd->plane[0].pre[0].stride; 597 int rr = ref_mv->row;
598 int rc = ref_mv->col;
599 int br = bestmv->row * 8;
600 int bc = bestmv->col * 8;
601 int hstep = 4;
602 const int minc = MAX(x->mv_col_min * 8, ref_mv->col - MV_MAX);
603 const int maxc = MIN(x->mv_col_max * 8, ref_mv->col + MV_MAX);
604 const int minr = MAX(x->mv_row_min * 8, ref_mv->row - MV_MAX);
605 const int maxr = MIN(x->mv_row_max * 8, ref_mv->row + MV_MAX);
662 606
663 rr = ref_mv->as_mv.row; 607 int tr = br;
664 rc = ref_mv->as_mv.col; 608 int tc = bc;
665 br = bestmv->as_mv.row << 3;
666 bc = bestmv->as_mv.col << 3;
667 hstep = 4;
668 minc = MAX(x->mv_col_min << 3, (ref_mv->as_mv.col) -
669 ((1 << MV_MAX_BITS) - 1));
670 maxc = MIN(x->mv_col_max << 3, (ref_mv->as_mv.col) +
671 ((1 << MV_MAX_BITS) - 1));
672 minr = MAX(x->mv_row_min << 3, (ref_mv->as_mv.row) -
673 ((1 << MV_MAX_BITS) - 1));
674 maxr = MIN(x->mv_row_max << 3, (ref_mv->as_mv.row) +
675 ((1 << MV_MAX_BITS) - 1));
676
677 tr = br;
678 tc = bc;
679
680
681 offset = (bestmv->as_mv.row) * y_stride + bestmv->as_mv.col;
682 609
683 // central mv 610 // central mv
684 bestmv->as_mv.row <<= 3; 611 bestmv->row *= 8;
685 bestmv->as_mv.col <<= 3; 612 bestmv->col *= 8;
686 613
687 // calculate central point error 614 // calculate central point error
688 // TODO(yunqingwang): central pointer error was already calculated in full- 615 // TODO(yunqingwang): central pointer error was already calculated in full-
689 // pixel search, and can be passed in this function. 616 // pixel search, and can be passed in this function.
690 comp_avg_pred(comp_pred, second_pred, w, h, y, y_stride); 617 comp_avg_pred(comp_pred, second_pred, w, h, y, y_stride);
691 besterr = vfp->vf(comp_pred, w, z, src_stride, sse1); 618 besterr = vfp->vf(comp_pred, w, z, src_stride, sse1);
692 *distortion = besterr; 619 *distortion = besterr;
693 besterr += mv_err_cost(bestmv, ref_mv, mvjcost, mvcost, error_per_bit); 620 besterr += mv_err_cost(bestmv, ref_mv, mvjcost, mvcost, error_per_bit);
694 621
695 // Each subsequent iteration checks at least one point in 622 // Each subsequent iteration checks at least one point in
(...skipping 13 matching lines...) Expand all
709 if (forced_stop != 2) { 636 if (forced_stop != 2) {
710 hstep >>= 1; 637 hstep >>= 1;
711 FIRST_LEVEL_CHECKS; 638 FIRST_LEVEL_CHECKS;
712 if (quarteriters > 1) { 639 if (quarteriters > 1) {
713 SECOND_LEVEL_CHECKS; 640 SECOND_LEVEL_CHECKS;
714 } 641 }
715 tr = br; 642 tr = br;
716 tc = bc; 643 tc = bc;
717 } 644 }
718 645
719 if (xd->allow_high_precision_mv && vp9_use_mv_hp(&ref_mv->as_mv) && 646 if (allow_hp && vp9_use_mv_hp(ref_mv) && forced_stop == 0) {
720 forced_stop == 0) {
721 hstep >>= 1; 647 hstep >>= 1;
722 FIRST_LEVEL_CHECKS; 648 FIRST_LEVEL_CHECKS;
723 if (eighthiters > 1) { 649 if (eighthiters > 1) {
724 SECOND_LEVEL_CHECKS; 650 SECOND_LEVEL_CHECKS;
725 } 651 }
726 tr = br; 652 tr = br;
727 tc = bc; 653 tc = bc;
728 } 654 }
729 bestmv->as_mv.row = br; 655 bestmv->row = br;
730 bestmv->as_mv.col = bc; 656 bestmv->col = bc;
731 657
732 if ((abs(bestmv->as_mv.col - ref_mv->as_mv.col) > (MAX_FULL_PEL_VAL << 3)) || 658 if ((abs(bestmv->col - ref_mv->col) > (MAX_FULL_PEL_VAL << 3)) ||
733 (abs(bestmv->as_mv.row - ref_mv->as_mv.row) > (MAX_FULL_PEL_VAL << 3))) 659 (abs(bestmv->row - ref_mv->row) > (MAX_FULL_PEL_VAL << 3)))
734 return INT_MAX; 660 return INT_MAX;
735 661
736 return besterr; 662 return besterr;
737 } 663 }
738 664
739 #undef MVC 665 #undef MVC
740 #undef PRE 666 #undef PRE
741 #undef DIST 667 #undef DIST
742 #undef IFMVCV 668 #undef IFMVCV
743 #undef CHECK_BETTER 669 #undef CHECK_BETTER
744 #undef SP 670 #undef SP
745 671
746 #define CHECK_BOUNDS(range) \ 672 #define CHECK_BOUNDS(range) \
747 {\ 673 {\
748 all_in = 1;\ 674 all_in = 1;\
749 all_in &= ((br-range) >= x->mv_row_min);\ 675 all_in &= ((br-range) >= x->mv_row_min);\
750 all_in &= ((br+range) <= x->mv_row_max);\ 676 all_in &= ((br+range) <= x->mv_row_max);\
751 all_in &= ((bc-range) >= x->mv_col_min);\ 677 all_in &= ((bc-range) >= x->mv_col_min);\
752 all_in &= ((bc+range) <= x->mv_col_max);\ 678 all_in &= ((bc+range) <= x->mv_col_max);\
753 } 679 }
754 680
755 #define CHECK_POINT \ 681 #define CHECK_POINT \
756 {\ 682 {\
757 if (this_mv.as_mv.col < x->mv_col_min) continue;\ 683 if (this_mv.col < x->mv_col_min) continue;\
758 if (this_mv.as_mv.col > x->mv_col_max) continue;\ 684 if (this_mv.col > x->mv_col_max) continue;\
759 if (this_mv.as_mv.row < x->mv_row_min) continue;\ 685 if (this_mv.row < x->mv_row_min) continue;\
760 if (this_mv.as_mv.row > x->mv_row_max) continue;\ 686 if (this_mv.row > x->mv_row_max) continue;\
761 } 687 }
762 688
763 #define CHECK_BETTER \ 689 #define CHECK_BETTER \
764 {\ 690 {\
765 if (thissad < bestsad)\ 691 if (thissad < bestsad)\
766 {\ 692 {\
767 if (use_mvcost) \ 693 if (use_mvcost) \
768 thissad += mvsad_err_cost(&this_mv, &fcenter_mv, \ 694 thissad += mvsad_err_cost(&this_mv, &fcenter_mv.as_mv, \
769 mvjsadcost, mvsadcost, \ 695 mvjsadcost, mvsadcost, \
770 sad_per_bit);\ 696 sad_per_bit);\
771 if (thissad < bestsad)\ 697 if (thissad < bestsad)\
772 {\ 698 {\
773 bestsad = thissad;\ 699 bestsad = thissad;\
774 best_site = i;\ 700 best_site = i;\
775 }\ 701 }\
776 }\ 702 }\
777 } 703 }
778 704
779 #define get_next_chkpts(list, i, n) \ 705 #define get_next_chkpts(list, i, n) \
780 list[0] = ((i) == 0 ? (n) - 1 : (i) - 1); \ 706 list[0] = ((i) == 0 ? (n) - 1 : (i) - 1); \
781 list[1] = (i); \ 707 list[1] = (i); \
782 list[2] = ((i) == (n) - 1 ? 0 : (i) + 1); 708 list[2] = ((i) == (n) - 1 ? 0 : (i) + 1);
783 709
784 #define MAX_PATTERN_SCALES 11 710 #define MAX_PATTERN_SCALES 11
785 #define MAX_PATTERN_CANDIDATES 8 // max number of canddiates per scale 711 #define MAX_PATTERN_CANDIDATES 8 // max number of canddiates per scale
786 #define PATTERN_CANDIDATES_REF 3 // number of refinement candidates 712 #define PATTERN_CANDIDATES_REF 3 // number of refinement candidates
787 713
788 // Generic pattern search function that searches over multiple scales. 714 // Generic pattern search function that searches over multiple scales.
789 // Each scale can have a different number of candidates and shape of 715 // Each scale can have a different number of candidates and shape of
790 // candidates as indicated in the num_candidates and candidates arrays 716 // candidates as indicated in the num_candidates and candidates arrays
791 // passed into this function 717 // passed into this function
792 static int vp9_pattern_search(MACROBLOCK *x, 718 static int vp9_pattern_search(MACROBLOCK *x,
793 int_mv *ref_mv, 719 MV *ref_mv,
794 int search_param, 720 int search_param,
795 int sad_per_bit, 721 int sad_per_bit,
796 int do_init_search, 722 int do_init_search,
797 int do_refine, 723 int do_refine,
798 const vp9_variance_fn_ptr_t *vfp, 724 const vp9_variance_fn_ptr_t *vfp,
799 int use_mvcost, 725 int use_mvcost,
800 int_mv *center_mv, int_mv *best_mv, 726 const MV *center_mv, MV *best_mv,
801 const int num_candidates[MAX_PATTERN_SCALES], 727 const int num_candidates[MAX_PATTERN_SCALES],
802 const MV candidates[MAX_PATTERN_SCALES] 728 const MV candidates[MAX_PATTERN_SCALES]
803 [MAX_PATTERN_CANDIDATES]) { 729 [MAX_PATTERN_CANDIDATES]) {
804 const MACROBLOCKD* const xd = &x->e_mbd; 730 const MACROBLOCKD* const xd = &x->e_mbd;
805 static const int search_param_to_steps[MAX_MVSEARCH_STEPS] = { 731 static const int search_param_to_steps[MAX_MVSEARCH_STEPS] = {
806 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 732 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0,
807 }; 733 };
808 int i, j, s, t; 734 int i, j, s, t;
809 uint8_t *what = x->plane[0].src.buf; 735 uint8_t *what = x->plane[0].src.buf;
810 int what_stride = x->plane[0].src.stride; 736 int what_stride = x->plane[0].src.stride;
811 int in_what_stride = xd->plane[0].pre[0].stride; 737 int in_what_stride = xd->plane[0].pre[0].stride;
812 int br, bc; 738 int br, bc;
813 int_mv this_mv; 739 MV this_mv;
814 int bestsad = INT_MAX; 740 int bestsad = INT_MAX;
815 int thissad; 741 int thissad;
816 uint8_t *base_offset; 742 uint8_t *base_offset;
817 uint8_t *this_offset; 743 uint8_t *this_offset;
818 int k = -1; 744 int k = -1;
819 int all_in; 745 int all_in;
820 int best_site = -1; 746 int best_site = -1;
821 int_mv fcenter_mv; 747 int_mv fcenter_mv;
822 int best_init_s = search_param_to_steps[search_param]; 748 int best_init_s = search_param_to_steps[search_param];
823 int *mvjsadcost = x->nmvjointsadcost; 749 int *mvjsadcost = x->nmvjointsadcost;
824 int *mvsadcost[2] = {x->nmvsadcost[0], x->nmvsadcost[1]}; 750 int *mvsadcost[2] = {x->nmvsadcost[0], x->nmvsadcost[1]};
825 751
826 fcenter_mv.as_mv.row = center_mv->as_mv.row >> 3; 752 fcenter_mv.as_mv.row = center_mv->row >> 3;
827 fcenter_mv.as_mv.col = center_mv->as_mv.col >> 3; 753 fcenter_mv.as_mv.col = center_mv->col >> 3;
828 754
829 // adjust ref_mv to make sure it is within MV range 755 // adjust ref_mv to make sure it is within MV range
830 clamp_mv(&ref_mv->as_mv, 756 clamp_mv(ref_mv, x->mv_col_min, x->mv_col_max, x->mv_row_min, x->mv_row_max);
831 x->mv_col_min, x->mv_col_max, x->mv_row_min, x->mv_row_max); 757 br = ref_mv->row;
832 br = ref_mv->as_mv.row; 758 bc = ref_mv->col;
833 bc = ref_mv->as_mv.col;
834 759
835 // Work out the start point for the search 760 // Work out the start point for the search
836 base_offset = (uint8_t *)(xd->plane[0].pre[0].buf); 761 base_offset = (uint8_t *)(xd->plane[0].pre[0].buf);
837 this_offset = base_offset + (br * in_what_stride) + bc; 762 this_offset = base_offset + (br * in_what_stride) + bc;
838 this_mv.as_mv.row = br; 763 this_mv.row = br;
839 this_mv.as_mv.col = bc; 764 this_mv.col = bc;
840 bestsad = vfp->sdf(what, what_stride, this_offset, 765 bestsad = vfp->sdf(what, what_stride, this_offset, in_what_stride, 0x7fffffff)
841 in_what_stride, 0x7fffffff) 766 + mvsad_err_cost(&this_mv, &fcenter_mv.as_mv,
842 + mvsad_err_cost(&this_mv, &fcenter_mv, mvjsadcost, mvsadcost, 767 mvjsadcost, mvsadcost, sad_per_bit);
843 sad_per_bit);
844 768
845 // Search all possible scales upto the search param around the center point 769 // Search all possible scales upto the search param around the center point
846 // pick the scale of the point that is best as the starting scale of 770 // pick the scale of the point that is best as the starting scale of
847 // further steps around it. 771 // further steps around it.
848 if (do_init_search) { 772 if (do_init_search) {
849 s = best_init_s; 773 s = best_init_s;
850 best_init_s = -1; 774 best_init_s = -1;
851 for (t = 0; t <= s; ++t) { 775 for (t = 0; t <= s; ++t) {
852 best_site = -1; 776 best_site = -1;
853 CHECK_BOUNDS((1 << t)) 777 CHECK_BOUNDS((1 << t))
854 if (all_in) { 778 if (all_in) {
855 for (i = 0; i < num_candidates[t]; i++) { 779 for (i = 0; i < num_candidates[t]; i++) {
856 this_mv.as_mv.row = br + candidates[t][i].row; 780 this_mv.row = br + candidates[t][i].row;
857 this_mv.as_mv.col = bc + candidates[t][i].col; 781 this_mv.col = bc + candidates[t][i].col;
858 this_offset = base_offset + (this_mv.as_mv.row * in_what_stride) + 782 this_offset = base_offset + (this_mv.row * in_what_stride) +
859 this_mv.as_mv.col; 783 this_mv.col;
860 thissad = vfp->sdf(what, what_stride, this_offset, in_what_stride, 784 thissad = vfp->sdf(what, what_stride, this_offset, in_what_stride,
861 bestsad); 785 bestsad);
862 CHECK_BETTER 786 CHECK_BETTER
863 } 787 }
864 } else { 788 } else {
865 for (i = 0; i < num_candidates[t]; i++) { 789 for (i = 0; i < num_candidates[t]; i++) {
866 this_mv.as_mv.row = br + candidates[t][i].row; 790 this_mv.row = br + candidates[t][i].row;
867 this_mv.as_mv.col = bc + candidates[t][i].col; 791 this_mv.col = bc + candidates[t][i].col;
868 CHECK_POINT 792 CHECK_POINT
869 this_offset = base_offset + (this_mv.as_mv.row * in_what_stride) + 793 this_offset = base_offset + (this_mv.row * in_what_stride) +
870 this_mv.as_mv.col; 794 this_mv.col;
871 thissad = vfp->sdf(what, what_stride, this_offset, in_what_stride, 795 thissad = vfp->sdf(what, what_stride, this_offset, in_what_stride,
872 bestsad); 796 bestsad);
873 CHECK_BETTER 797 CHECK_BETTER
874 } 798 }
875 } 799 }
876 if (best_site == -1) { 800 if (best_site == -1) {
877 continue; 801 continue;
878 } else { 802 } else {
879 best_init_s = t; 803 best_init_s = t;
880 k = best_site; 804 k = best_site;
881 } 805 }
882 } 806 }
883 if (best_init_s != -1) { 807 if (best_init_s != -1) {
884 br += candidates[best_init_s][k].row; 808 br += candidates[best_init_s][k].row;
885 bc += candidates[best_init_s][k].col; 809 bc += candidates[best_init_s][k].col;
886 } 810 }
887 } 811 }
888 812
889 // If the center point is still the best, just skip this and move to 813 // If the center point is still the best, just skip this and move to
890 // the refinement step. 814 // the refinement step.
891 if (best_init_s != -1) { 815 if (best_init_s != -1) {
892 s = best_init_s; 816 s = best_init_s;
893 best_site = -1; 817 best_site = -1;
894 do { 818 do {
895 // No need to search all 6 points the 1st time if initial search was used 819 // No need to search all 6 points the 1st time if initial search was used
896 if (!do_init_search || s != best_init_s) { 820 if (!do_init_search || s != best_init_s) {
897 CHECK_BOUNDS((1 << s)) 821 CHECK_BOUNDS((1 << s))
898 if (all_in) { 822 if (all_in) {
899 for (i = 0; i < num_candidates[s]; i++) { 823 for (i = 0; i < num_candidates[s]; i++) {
900 this_mv.as_mv.row = br + candidates[s][i].row; 824 this_mv.row = br + candidates[s][i].row;
901 this_mv.as_mv.col = bc + candidates[s][i].col; 825 this_mv.col = bc + candidates[s][i].col;
902 this_offset = base_offset + (this_mv.as_mv.row * in_what_stride) + 826 this_offset = base_offset + (this_mv.row * in_what_stride) +
903 this_mv.as_mv.col; 827 this_mv.col;
904 thissad = vfp->sdf(what, what_stride, this_offset, in_what_stride, 828 thissad = vfp->sdf(what, what_stride, this_offset, in_what_stride,
905 bestsad); 829 bestsad);
906 CHECK_BETTER 830 CHECK_BETTER
907 } 831 }
908 } else { 832 } else {
909 for (i = 0; i < num_candidates[s]; i++) { 833 for (i = 0; i < num_candidates[s]; i++) {
910 this_mv.as_mv.row = br + candidates[s][i].row; 834 this_mv.row = br + candidates[s][i].row;
911 this_mv.as_mv.col = bc + candidates[s][i].col; 835 this_mv.col = bc + candidates[s][i].col;
912 CHECK_POINT 836 CHECK_POINT
913 this_offset = base_offset + (this_mv.as_mv.row * in_what_stride) + 837 this_offset = base_offset + (this_mv.row * in_what_stride) +
914 this_mv.as_mv.col; 838 this_mv.col;
915 thissad = vfp->sdf(what, what_stride, this_offset, in_what_stride, 839 thissad = vfp->sdf(what, what_stride, this_offset, in_what_stride,
916 bestsad); 840 bestsad);
917 CHECK_BETTER 841 CHECK_BETTER
918 } 842 }
919 } 843 }
920 844
921 if (best_site == -1) { 845 if (best_site == -1) {
922 continue; 846 continue;
923 } else { 847 } else {
924 br += candidates[s][best_site].row; 848 br += candidates[s][best_site].row;
925 bc += candidates[s][best_site].col; 849 bc += candidates[s][best_site].col;
926 k = best_site; 850 k = best_site;
927 } 851 }
928 } 852 }
929 853
930 do { 854 do {
931 int next_chkpts_indices[PATTERN_CANDIDATES_REF]; 855 int next_chkpts_indices[PATTERN_CANDIDATES_REF];
932 best_site = -1; 856 best_site = -1;
933 CHECK_BOUNDS((1 << s)) 857 CHECK_BOUNDS((1 << s))
934 858
935 get_next_chkpts(next_chkpts_indices, k, num_candidates[s]); 859 get_next_chkpts(next_chkpts_indices, k, num_candidates[s]);
936 if (all_in) { 860 if (all_in) {
937 for (i = 0; i < PATTERN_CANDIDATES_REF; i++) { 861 for (i = 0; i < PATTERN_CANDIDATES_REF; i++) {
938 this_mv.as_mv.row = br + 862 this_mv.row = br + candidates[s][next_chkpts_indices[i]].row;
939 candidates[s][next_chkpts_indices[i]].row; 863 this_mv.col = bc + candidates[s][next_chkpts_indices[i]].col;
940 this_mv.as_mv.col = bc + 864 this_offset = base_offset + (this_mv.row * (in_what_stride)) +
941 candidates[s][next_chkpts_indices[i]].col; 865 this_mv.col;
942 this_offset = base_offset + (this_mv.as_mv.row * (in_what_stride)) +
943 this_mv.as_mv.col;
944 thissad = vfp->sdf(what, what_stride, this_offset, in_what_stride, 866 thissad = vfp->sdf(what, what_stride, this_offset, in_what_stride,
945 bestsad); 867 bestsad);
946 CHECK_BETTER 868 CHECK_BETTER
947 } 869 }
948 } else { 870 } else {
949 for (i = 0; i < PATTERN_CANDIDATES_REF; i++) { 871 for (i = 0; i < PATTERN_CANDIDATES_REF; i++) {
950 this_mv.as_mv.row = br + 872 this_mv.row = br + candidates[s][next_chkpts_indices[i]].row;
951 candidates[s][next_chkpts_indices[i]].row; 873 this_mv.col = bc + candidates[s][next_chkpts_indices[i]].col;
952 this_mv.as_mv.col = bc +
953 candidates[s][next_chkpts_indices[i]].col;
954 CHECK_POINT 874 CHECK_POINT
955 this_offset = base_offset + (this_mv.as_mv.row * (in_what_stride)) + 875 this_offset = base_offset + (this_mv.row * (in_what_stride)) +
956 this_mv.as_mv.col; 876 this_mv.col;
957 thissad = vfp->sdf(what, what_stride, this_offset, in_what_stride, 877 thissad = vfp->sdf(what, what_stride, this_offset, in_what_stride,
958 bestsad); 878 bestsad);
959 CHECK_BETTER 879 CHECK_BETTER
960 } 880 }
961 } 881 }
962 882
963 if (best_site != -1) { 883 if (best_site != -1) {
964 k = next_chkpts_indices[best_site]; 884 k = next_chkpts_indices[best_site];
965 br += candidates[s][k].row; 885 br += candidates[s][k].row;
966 bc += candidates[s][k].col; 886 bc += candidates[s][k].col;
967 } 887 }
968 } while (best_site != -1); 888 } while (best_site != -1);
969 } while (s--); 889 } while (s--);
970 } 890 }
971 891
972 // Check 4 1-away neighbors if do_refine is true. 892 // Check 4 1-away neighbors if do_refine is true.
973 // For most well-designed schemes do_refine will not be necessary. 893 // For most well-designed schemes do_refine will not be necessary.
974 if (do_refine) { 894 if (do_refine) {
975 static const MV neighbors[4] = { 895 static const MV neighbors[4] = {
976 {0, -1}, { -1, 0}, {1, 0}, {0, 1}, 896 {0, -1}, { -1, 0}, {1, 0}, {0, 1},
977 }; 897 };
978 for (j = 0; j < 16; j++) { 898 for (j = 0; j < 16; j++) {
979 best_site = -1; 899 best_site = -1;
980 CHECK_BOUNDS(1) 900 CHECK_BOUNDS(1)
981 if (all_in) { 901 if (all_in) {
982 for (i = 0; i < 4; i++) { 902 for (i = 0; i < 4; i++) {
983 this_mv.as_mv.row = br + neighbors[i].row; 903 this_mv.row = br + neighbors[i].row;
984 this_mv.as_mv.col = bc + neighbors[i].col; 904 this_mv.col = bc + neighbors[i].col;
985 this_offset = base_offset + (this_mv.as_mv.row * (in_what_stride)) + 905 this_offset = base_offset + (this_mv.row * (in_what_stride)) +
986 this_mv.as_mv.col; 906 this_mv.col;
987 thissad = vfp->sdf(what, what_stride, this_offset, in_what_stride, 907 thissad = vfp->sdf(what, what_stride, this_offset, in_what_stride,
988 bestsad); 908 bestsad);
989 CHECK_BETTER 909 CHECK_BETTER
990 } 910 }
991 } else { 911 } else {
992 for (i = 0; i < 4; i++) { 912 for (i = 0; i < 4; i++) {
993 this_mv.as_mv.row = br + neighbors[i].row; 913 this_mv.row = br + neighbors[i].row;
994 this_mv.as_mv.col = bc + neighbors[i].col; 914 this_mv.col = bc + neighbors[i].col;
995 CHECK_POINT 915 CHECK_POINT
996 this_offset = base_offset + (this_mv.as_mv.row * (in_what_stride)) + 916 this_offset = base_offset + (this_mv.row * (in_what_stride)) +
997 this_mv.as_mv.col; 917 this_mv.col;
998 thissad = vfp->sdf(what, what_stride, this_offset, in_what_stride, 918 thissad = vfp->sdf(what, what_stride, this_offset, in_what_stride,
999 bestsad); 919 bestsad);
1000 CHECK_BETTER 920 CHECK_BETTER
1001 } 921 }
1002 } 922 }
1003 923
1004 if (best_site == -1) { 924 if (best_site == -1) {
1005 break; 925 break;
1006 } else { 926 } else {
1007 br += neighbors[best_site].row; 927 br += neighbors[best_site].row;
1008 bc += neighbors[best_site].col; 928 bc += neighbors[best_site].col;
1009 } 929 }
1010 } 930 }
1011 } 931 }
1012 932
1013 best_mv->as_mv.row = br; 933 best_mv->row = br;
1014 best_mv->as_mv.col = bc; 934 best_mv->col = bc;
1015 935
1016 this_offset = base_offset + (best_mv->as_mv.row * (in_what_stride)) + 936 this_offset = base_offset + (best_mv->row * in_what_stride) +
1017 best_mv->as_mv.col; 937 best_mv->col;
1018 this_mv.as_mv.row = best_mv->as_mv.row << 3; 938 this_mv.row = best_mv->row * 8;
1019 this_mv.as_mv.col = best_mv->as_mv.col << 3; 939 this_mv.col = best_mv->col * 8;
1020 if (bestsad == INT_MAX) 940 if (bestsad == INT_MAX)
1021 return INT_MAX; 941 return INT_MAX;
1022 return 942
1023 vfp->vf(what, what_stride, this_offset, in_what_stride, 943 return vfp->vf(what, what_stride, this_offset, in_what_stride,
1024 (unsigned int *)(&bestsad)) + 944 (unsigned int *)&bestsad) +
1025 use_mvcost ? mv_err_cost(&this_mv, center_mv, x->nmvjointcost, x->mvcost, 945 use_mvcost ? mv_err_cost(&this_mv, center_mv,
1026 x->errorperbit) : 0; 946 x->nmvjointcost, x->mvcost, x->errorperbit)
947 : 0;
1027 } 948 }
1028 949
1029 950
1030 int vp9_hex_search(MACROBLOCK *x, 951 int vp9_hex_search(MACROBLOCK *x,
1031 int_mv *ref_mv, 952 MV *ref_mv,
1032 int search_param, 953 int search_param,
1033 int sad_per_bit, 954 int sad_per_bit,
1034 int do_init_search, 955 int do_init_search,
1035 const vp9_variance_fn_ptr_t *vfp, 956 const vp9_variance_fn_ptr_t *vfp,
1036 int use_mvcost, 957 int use_mvcost,
1037 int_mv *center_mv, int_mv *best_mv) { 958 const MV *center_mv, MV *best_mv) {
1038 // First scale has 8-closest points, the rest have 6 points in hex shape 959 // First scale has 8-closest points, the rest have 6 points in hex shape
1039 // at increasing scales 960 // at increasing scales
1040 static const int hex_num_candidates[MAX_PATTERN_SCALES] = { 961 static const int hex_num_candidates[MAX_PATTERN_SCALES] = {
1041 8, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6 962 8, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6
1042 }; 963 };
1043 // Note that the largest candidate step at each scale is 2^scale 964 // Note that the largest candidate step at each scale is 2^scale
1044 static const MV hex_candidates[MAX_PATTERN_SCALES][MAX_PATTERN_CANDIDATES] = { 965 static const MV hex_candidates[MAX_PATTERN_SCALES][MAX_PATTERN_CANDIDATES] = {
1045 {{-1, -1}, {0, -1}, {1, -1}, {1, 0}, {1, 1}, { 0, 1}, { -1, 1}, {-1, 0}}, 966 {{-1, -1}, {0, -1}, {1, -1}, {1, 0}, {1, 1}, { 0, 1}, { -1, 1}, {-1, 0}},
1046 {{-1, -2}, {1, -2}, {2, 0}, {1, 2}, { -1, 2}, { -2, 0}}, 967 {{-1, -2}, {1, -2}, {2, 0}, {1, 2}, { -1, 2}, { -2, 0}},
1047 {{-2, -4}, {2, -4}, {4, 0}, {2, 4}, { -2, 4}, { -4, 0}}, 968 {{-2, -4}, {2, -4}, {4, 0}, {2, 4}, { -2, 4}, { -4, 0}},
1048 {{-4, -8}, {4, -8}, {8, 0}, {4, 8}, { -4, 8}, { -8, 0}}, 969 {{-4, -8}, {4, -8}, {8, 0}, {4, 8}, { -4, 8}, { -8, 0}},
1049 {{-8, -16}, {8, -16}, {16, 0}, {8, 16}, { -8, 16}, { -16, 0}}, 970 {{-8, -16}, {8, -16}, {16, 0}, {8, 16}, { -8, 16}, { -16, 0}},
1050 {{-16, -32}, {16, -32}, {32, 0}, {16, 32}, { -16, 32}, { -32, 0}}, 971 {{-16, -32}, {16, -32}, {32, 0}, {16, 32}, { -16, 32}, { -32, 0}},
1051 {{-32, -64}, {32, -64}, {64, 0}, {32, 64}, { -32, 64}, { -64, 0}}, 972 {{-32, -64}, {32, -64}, {64, 0}, {32, 64}, { -32, 64}, { -64, 0}},
1052 {{-64, -128}, {64, -128}, {128, 0}, {64, 128}, { -64, 128}, { -128, 0}}, 973 {{-64, -128}, {64, -128}, {128, 0}, {64, 128}, { -64, 128}, { -128, 0}},
1053 {{-128, -256}, {128, -256}, {256, 0}, {128, 256}, { -128, 256}, { -256, 0}}, 974 {{-128, -256}, {128, -256}, {256, 0}, {128, 256}, { -128, 256}, { -256, 0}},
1054 {{-256, -512}, {256, -512}, {512, 0}, {256, 512}, { -256, 512}, { -512, 0}}, 975 {{-256, -512}, {256, -512}, {512, 0}, {256, 512}, { -256, 512}, { -512, 0}},
1055 {{-512, -1024}, {512, -1024}, {1024, 0}, {512, 1024}, { -512, 1024}, 976 {{-512, -1024}, {512, -1024}, {1024, 0}, {512, 1024}, { -512, 1024},
1056 { -1024, 0}}, 977 { -1024, 0}},
1057 }; 978 };
1058 return 979 return
1059 vp9_pattern_search(x, ref_mv, search_param, sad_per_bit, 980 vp9_pattern_search(x, ref_mv, search_param, sad_per_bit,
1060 do_init_search, 0, vfp, use_mvcost, 981 do_init_search, 0, vfp, use_mvcost,
1061 center_mv, best_mv, 982 center_mv, best_mv,
1062 hex_num_candidates, hex_candidates); 983 hex_num_candidates, hex_candidates);
1063 } 984 }
1064 985
1065 int vp9_bigdia_search(MACROBLOCK *x, 986 int vp9_bigdia_search(MACROBLOCK *x,
1066 int_mv *ref_mv, 987 MV *ref_mv,
1067 int search_param, 988 int search_param,
1068 int sad_per_bit, 989 int sad_per_bit,
1069 int do_init_search, 990 int do_init_search,
1070 const vp9_variance_fn_ptr_t *vfp, 991 const vp9_variance_fn_ptr_t *vfp,
1071 int use_mvcost, 992 int use_mvcost,
1072 int_mv *center_mv, 993 const MV *center_mv,
1073 int_mv *best_mv) { 994 MV *best_mv) {
1074 // First scale has 4-closest points, the rest have 8 points in diamond 995 // First scale has 4-closest points, the rest have 8 points in diamond
1075 // shape at increasing scales 996 // shape at increasing scales
1076 static const int bigdia_num_candidates[MAX_PATTERN_SCALES] = { 997 static const int bigdia_num_candidates[MAX_PATTERN_SCALES] = {
1077 4, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 998 4, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
1078 }; 999 };
1079 // Note that the largest candidate step at each scale is 2^scale 1000 // Note that the largest candidate step at each scale is 2^scale
1080 static const MV bigdia_candidates[MAX_PATTERN_SCALES] 1001 static const MV bigdia_candidates[MAX_PATTERN_SCALES]
1081 [MAX_PATTERN_CANDIDATES] = { 1002 [MAX_PATTERN_CANDIDATES] = {
1082 {{0, -1}, {1, 0}, { 0, 1}, {-1, 0}}, 1003 {{0, -1}, {1, 0}, { 0, 1}, {-1, 0}},
1083 {{-1, -1}, {0, -2}, {1, -1}, {2, 0}, {1, 1}, {0, 2}, {-1, 1}, {-2, 0}}, 1004 {{-1, -1}, {0, -2}, {1, -1}, {2, 0}, {1, 1}, {0, 2}, {-1, 1}, {-2, 0}},
1084 {{-2, -2}, {0, -4}, {2, -2}, {4, 0}, {2, 2}, {0, 4}, {-2, 2}, {-4, 0}}, 1005 {{-2, -2}, {0, -4}, {2, -2}, {4, 0}, {2, 2}, {0, 4}, {-2, 2}, {-4, 0}},
1085 {{-4, -4}, {0, -8}, {4, -4}, {8, 0}, {4, 4}, {0, 8}, {-4, 4}, {-8, 0}}, 1006 {{-4, -4}, {0, -8}, {4, -4}, {8, 0}, {4, 4}, {0, 8}, {-4, 4}, {-8, 0}},
1086 {{-8, -8}, {0, -16}, {8, -8}, {16, 0}, {8, 8}, {0, 16}, {-8, 8}, {-16, 0}}, 1007 {{-8, -8}, {0, -16}, {8, -8}, {16, 0}, {8, 8}, {0, 16}, {-8, 8}, {-16, 0}},
1087 {{-16, -16}, {0, -32}, {16, -16}, {32, 0}, {16, 16}, {0, 32}, 1008 {{-16, -16}, {0, -32}, {16, -16}, {32, 0}, {16, 16}, {0, 32},
1088 {-16, 16}, {-32, 0}}, 1009 {-16, 16}, {-32, 0}},
1089 {{-32, -32}, {0, -64}, {32, -32}, {64, 0}, {32, 32}, {0, 64}, 1010 {{-32, -32}, {0, -64}, {32, -32}, {64, 0}, {32, 32}, {0, 64},
1090 {-32, 32}, {-64, 0}}, 1011 {-32, 32}, {-64, 0}},
1091 {{-64, -64}, {0, -128}, {64, -64}, {128, 0}, {64, 64}, {0, 128}, 1012 {{-64, -64}, {0, -128}, {64, -64}, {128, 0}, {64, 64}, {0, 128},
1092 {-64, 64}, {-128, 0}}, 1013 {-64, 64}, {-128, 0}},
1093 {{-128, -128}, {0, -256}, {128, -128}, {256, 0}, {128, 128}, {0, 256}, 1014 {{-128, -128}, {0, -256}, {128, -128}, {256, 0}, {128, 128}, {0, 256},
1094 {-128, 128}, {-256, 0}}, 1015 {-128, 128}, {-256, 0}},
1095 {{-256, -256}, {0, -512}, {256, -256}, {512, 0}, {256, 256}, {0, 512}, 1016 {{-256, -256}, {0, -512}, {256, -256}, {512, 0}, {256, 256}, {0, 512},
1096 {-256, 256}, {-512, 0}}, 1017 {-256, 256}, {-512, 0}},
1097 {{-512, -512}, {0, -1024}, {512, -512}, {1024, 0}, {512, 512}, {0, 1024}, 1018 {{-512, -512}, {0, -1024}, {512, -512}, {1024, 0}, {512, 512}, {0, 1024},
1098 {-512, 512}, {-1024, 0}}, 1019 {-512, 512}, {-1024, 0}},
1099 }; 1020 };
1100 return 1021 return vp9_pattern_search(x, ref_mv, search_param, sad_per_bit,
1101 vp9_pattern_search(x, ref_mv, search_param, sad_per_bit, 1022 do_init_search, 0, vfp, use_mvcost,
1102 do_init_search, 0, vfp, use_mvcost, 1023 center_mv, best_mv,
1103 center_mv, best_mv, 1024 bigdia_num_candidates, bigdia_candidates);
1104 bigdia_num_candidates, bigdia_candidates);
1105 } 1025 }
1106 1026
1107 int vp9_square_search(MACROBLOCK *x, 1027 int vp9_square_search(MACROBLOCK *x,
1108 int_mv *ref_mv, 1028 MV *ref_mv,
1109 int search_param, 1029 int search_param,
1110 int sad_per_bit, 1030 int sad_per_bit,
1111 int do_init_search, 1031 int do_init_search,
1112 const vp9_variance_fn_ptr_t *vfp, 1032 const vp9_variance_fn_ptr_t *vfp,
1113 int use_mvcost, 1033 int use_mvcost,
1114 int_mv *center_mv, 1034 const MV *center_mv,
1115 int_mv *best_mv) { 1035 MV *best_mv) {
1116 // All scales have 8 closest points in square shape 1036 // All scales have 8 closest points in square shape
1117 static const int square_num_candidates[MAX_PATTERN_SCALES] = { 1037 static const int square_num_candidates[MAX_PATTERN_SCALES] = {
1118 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 1038 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
1119 }; 1039 };
1120 // Note that the largest candidate step at each scale is 2^scale 1040 // Note that the largest candidate step at each scale is 2^scale
1121 static const MV square_candidates[MAX_PATTERN_SCALES] 1041 static const MV square_candidates[MAX_PATTERN_SCALES]
1122 [MAX_PATTERN_CANDIDATES] = { 1042 [MAX_PATTERN_CANDIDATES] = {
1123 {{-1, -1}, {0, -1}, {1, -1}, {1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}}, 1043 {{-1, -1}, {0, -1}, {1, -1}, {1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}},
1124 {{-2, -2}, {0, -2}, {2, -2}, {2, 0}, {2, 2}, {0, 2}, {-2, 2}, {-2, 0}}, 1044 {{-2, -2}, {0, -2}, {2, -2}, {2, 0}, {2, 2}, {0, 2}, {-2, 2}, {-2, 0}},
1125 {{-4, -4}, {0, -4}, {4, -4}, {4, 0}, {4, 4}, {0, 4}, {-4, 4}, {-4, 0}}, 1045 {{-4, -4}, {0, -4}, {4, -4}, {4, 0}, {4, 4}, {0, 4}, {-4, 4}, {-4, 0}},
1126 {{-8, -8}, {0, -8}, {8, -8}, {8, 0}, {8, 8}, {0, 8}, {-8, 8}, {-8, 0}}, 1046 {{-8, -8}, {0, -8}, {8, -8}, {8, 0}, {8, 8}, {0, 8}, {-8, 8}, {-8, 0}},
1127 {{-16, -16}, {0, -16}, {16, -16}, {16, 0}, {16, 16}, {0, 16}, 1047 {{-16, -16}, {0, -16}, {16, -16}, {16, 0}, {16, 16}, {0, 16},
1128 {-16, 16}, {-16, 0}}, 1048 {-16, 16}, {-16, 0}},
1129 {{-32, -32}, {0, -32}, {32, -32}, {32, 0}, {32, 32}, {0, 32}, 1049 {{-32, -32}, {0, -32}, {32, -32}, {32, 0}, {32, 32}, {0, 32},
1130 {-32, 32}, {-32, 0}}, 1050 {-32, 32}, {-32, 0}},
1131 {{-64, -64}, {0, -64}, {64, -64}, {64, 0}, {64, 64}, {0, 64}, 1051 {{-64, -64}, {0, -64}, {64, -64}, {64, 0}, {64, 64}, {0, 64},
1132 {-64, 64}, {-64, 0}}, 1052 {-64, 64}, {-64, 0}},
1133 {{-128, -128}, {0, -128}, {128, -128}, {128, 0}, {128, 128}, {0, 128}, 1053 {{-128, -128}, {0, -128}, {128, -128}, {128, 0}, {128, 128}, {0, 128},
1134 {-128, 128}, {-128, 0}}, 1054 {-128, 128}, {-128, 0}},
1135 {{-256, -256}, {0, -256}, {256, -256}, {256, 0}, {256, 256}, {0, 256}, 1055 {{-256, -256}, {0, -256}, {256, -256}, {256, 0}, {256, 256}, {0, 256},
1136 {-256, 256}, {-256, 0}}, 1056 {-256, 256}, {-256, 0}},
1137 {{-512, -512}, {0, -512}, {512, -512}, {512, 0}, {512, 512}, {0, 512}, 1057 {{-512, -512}, {0, -512}, {512, -512}, {512, 0}, {512, 512}, {0, 512},
1138 {-512, 512}, {-512, 0}}, 1058 {-512, 512}, {-512, 0}},
1139 {{-1024, -1024}, {0, -1024}, {1024, -1024}, {1024, 0}, {1024, 1024}, 1059 {{-1024, -1024}, {0, -1024}, {1024, -1024}, {1024, 0}, {1024, 1024},
1140 {0, 1024}, {-1024, 1024}, {-1024, 0}}, 1060 {0, 1024}, {-1024, 1024}, {-1024, 0}},
1141 }; 1061 };
1142 return 1062 return vp9_pattern_search(x, ref_mv, search_param, sad_per_bit,
1143 vp9_pattern_search(x, ref_mv, search_param, sad_per_bit, 1063 do_init_search, 0, vfp, use_mvcost,
1144 do_init_search, 0, vfp, use_mvcost, 1064 center_mv, best_mv,
1145 center_mv, best_mv, 1065 square_num_candidates, square_candidates);
1146 square_num_candidates, square_candidates);
1147 }; 1066 };
1148 1067
1149 #undef CHECK_BOUNDS 1068 #undef CHECK_BOUNDS
1150 #undef CHECK_POINT 1069 #undef CHECK_POINT
1151 #undef CHECK_BETTER 1070 #undef CHECK_BETTER
1152 1071
1153 int vp9_diamond_search_sad_c(MACROBLOCK *x, 1072 int vp9_diamond_search_sad_c(MACROBLOCK *x,
1154 int_mv *ref_mv, int_mv *best_mv, 1073 int_mv *ref_mv, int_mv *best_mv,
1155 int search_param, int sad_per_bit, int *num00, 1074 int search_param, int sad_per_bit, int *num00,
1156 vp9_variance_fn_ptr_t *fn_ptr, int *mvjcost, 1075 vp9_variance_fn_ptr_t *fn_ptr, int *mvjcost,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1192 *num00 = 0; 1111 *num00 = 0;
1193 best_mv->as_mv.row = ref_row; 1112 best_mv->as_mv.row = ref_row;
1194 best_mv->as_mv.col = ref_col; 1113 best_mv->as_mv.col = ref_col;
1195 1114
1196 // Work out the start point for the search 1115 // Work out the start point for the search
1197 in_what = (uint8_t *)(xd->plane[0].pre[0].buf + 1116 in_what = (uint8_t *)(xd->plane[0].pre[0].buf +
1198 (ref_row * (xd->plane[0].pre[0].stride)) + ref_col); 1117 (ref_row * (xd->plane[0].pre[0].stride)) + ref_col);
1199 best_address = in_what; 1118 best_address = in_what;
1200 1119
1201 // Check the starting position 1120 // Check the starting position
1202 bestsad = fn_ptr->sdf(what, what_stride, in_what, 1121 bestsad = fn_ptr->sdf(what, what_stride, in_what, in_what_stride, 0x7fffffff)
1203 in_what_stride, 0x7fffffff) 1122 + mvsad_err_cost(&best_mv->as_mv, &fcenter_mv.as_mv,
1204 + mvsad_err_cost(best_mv, &fcenter_mv, mvjsadcost, mvsadcost, 1123 mvjsadcost, mvsadcost, sad_per_bit);
1205 sad_per_bit);
1206 1124
1207 // search_param determines the length of the initial step and hence the number of iterations 1125 // search_param determines the length of the initial step and hence the number
1208 // 0 = initial step (MAX_FIRST_STEP) pel : 1 = (MAX_FIRST_STEP/2) pel, 2 = (MA X_FIRST_STEP/4) pel... etc. 1126 // of iterations
1127 // 0 = initial step (MAX_FIRST_STEP) pel : 1 = (MAX_FIRST_STEP/2) pel, 2 =
1128 // (MAX_FIRST_STEP/4) pel... etc.
1209 ss = &x->ss[search_param * x->searches_per_step]; 1129 ss = &x->ss[search_param * x->searches_per_step];
1210 tot_steps = (x->ss_count / x->searches_per_step) - search_param; 1130 tot_steps = (x->ss_count / x->searches_per_step) - search_param;
1211 1131
1212 i = 1; 1132 i = 1;
1213 1133
1214 for (step = 0; step < tot_steps; step++) { 1134 for (step = 0; step < tot_steps; step++) {
1215 for (j = 0; j < x->searches_per_step; j++) { 1135 for (j = 0; j < x->searches_per_step; j++) {
1216 // Trap illegal vectors 1136 // Trap illegal vectors
1217 this_row_offset = best_mv->as_mv.row + ss[i].mv.row; 1137 this_row_offset = best_mv->as_mv.row + ss[i].mv.row;
1218 this_col_offset = best_mv->as_mv.col + ss[i].mv.col; 1138 this_col_offset = best_mv->as_mv.col + ss[i].mv.col;
1219 1139
1220 if ((this_col_offset > x->mv_col_min) && 1140 if ((this_col_offset > x->mv_col_min) &&
1221 (this_col_offset < x->mv_col_max) && 1141 (this_col_offset < x->mv_col_max) &&
1222 (this_row_offset > x->mv_row_min) && 1142 (this_row_offset > x->mv_row_min) &&
1223 (this_row_offset < x->mv_row_max)) { 1143 (this_row_offset < x->mv_row_max)) {
1224 check_here = ss[i].offset + best_address; 1144 check_here = ss[i].offset + best_address;
1225 thissad = fn_ptr->sdf(what, what_stride, check_here, in_what_stride, 1145 thissad = fn_ptr->sdf(what, what_stride, check_here, in_what_stride,
1226 bestsad); 1146 bestsad);
1227 1147
1228 if (thissad < bestsad) { 1148 if (thissad < bestsad) {
1229 this_mv.as_mv.row = this_row_offset; 1149 this_mv.as_mv.row = this_row_offset;
1230 this_mv.as_mv.col = this_col_offset; 1150 this_mv.as_mv.col = this_col_offset;
1231 thissad += mvsad_err_cost(&this_mv, &fcenter_mv, 1151 thissad += mvsad_err_cost(&this_mv.as_mv, &fcenter_mv.as_mv,
1232 mvjsadcost, mvsadcost, sad_per_bit); 1152 mvjsadcost, mvsadcost, sad_per_bit);
1233 1153
1234 if (thissad < bestsad) { 1154 if (thissad < bestsad) {
1235 bestsad = thissad; 1155 bestsad = thissad;
1236 best_site = i; 1156 best_site = i;
1237 } 1157 }
1238 } 1158 }
1239 } 1159 }
1240 1160
1241 i++; 1161 i++;
(...skipping 11 matching lines...) Expand all
1253 if ((this_col_offset > x->mv_col_min) && 1173 if ((this_col_offset > x->mv_col_min) &&
1254 (this_col_offset < x->mv_col_max) && 1174 (this_col_offset < x->mv_col_max) &&
1255 (this_row_offset > x->mv_row_min) && 1175 (this_row_offset > x->mv_row_min) &&
1256 (this_row_offset < x->mv_row_max)) { 1176 (this_row_offset < x->mv_row_max)) {
1257 check_here = ss[best_site].offset + best_address; 1177 check_here = ss[best_site].offset + best_address;
1258 thissad = fn_ptr->sdf(what, what_stride, check_here, in_what_stride, 1178 thissad = fn_ptr->sdf(what, what_stride, check_here, in_what_stride,
1259 bestsad); 1179 bestsad);
1260 if (thissad < bestsad) { 1180 if (thissad < bestsad) {
1261 this_mv.as_mv.row = this_row_offset; 1181 this_mv.as_mv.row = this_row_offset;
1262 this_mv.as_mv.col = this_col_offset; 1182 this_mv.as_mv.col = this_col_offset;
1263 thissad += mvsad_err_cost(&this_mv, &fcenter_mv, 1183 thissad += mvsad_err_cost(&this_mv.as_mv, &fcenter_mv.as_mv,
1264 mvjsadcost, mvsadcost, sad_per_bit); 1184 mvjsadcost, mvsadcost, sad_per_bit);
1265 if (thissad < bestsad) { 1185 if (thissad < bestsad) {
1266 bestsad = thissad; 1186 bestsad = thissad;
1267 best_mv->as_mv.row += ss[best_site].mv.row; 1187 best_mv->as_mv.row += ss[best_site].mv.row;
1268 best_mv->as_mv.col += ss[best_site].mv.col; 1188 best_mv->as_mv.col += ss[best_site].mv.col;
1269 best_address += ss[best_site].offset; 1189 best_address += ss[best_site].offset;
1270 continue; 1190 continue;
1271 } 1191 }
1272 } 1192 }
1273 } 1193 }
1274 break; 1194 break;
1275 }; 1195 };
1276 #endif 1196 #endif
1277 } else if (best_address == in_what) 1197 } else if (best_address == in_what) {
1278 (*num00)++; 1198 (*num00)++;
1199 }
1279 } 1200 }
1280 1201
1281 this_mv.as_mv.row = best_mv->as_mv.row << 3; 1202 this_mv.as_mv.row = best_mv->as_mv.row * 8;
1282 this_mv.as_mv.col = best_mv->as_mv.col << 3; 1203 this_mv.as_mv.col = best_mv->as_mv.col * 8;
1283 1204
1284 if (bestsad == INT_MAX) 1205 if (bestsad == INT_MAX)
1285 return INT_MAX; 1206 return INT_MAX;
1286 1207
1287 return fn_ptr->vf(what, what_stride, best_address, in_what_stride, 1208 return fn_ptr->vf(what, what_stride, best_address, in_what_stride,
1288 (unsigned int *)(&thissad)) + mv_err_cost(&this_mv, center_mv, mvjcost, 1209 (unsigned int *)(&thissad)) +
1289 mvcost, x->errorperbit); 1210 mv_err_cost(&this_mv.as_mv, &center_mv->as_mv,
1211 mvjcost, mvcost, x->errorperbit);
1290 } 1212 }
1291 1213
1292 int vp9_diamond_search_sadx4(MACROBLOCK *x, 1214 int vp9_diamond_search_sadx4(MACROBLOCK *x,
1293 int_mv *ref_mv, int_mv *best_mv, int search_param, 1215 int_mv *ref_mv, int_mv *best_mv, int search_param,
1294 int sad_per_bit, int *num00, 1216 int sad_per_bit, int *num00,
1295 vp9_variance_fn_ptr_t *fn_ptr, 1217 vp9_variance_fn_ptr_t *fn_ptr,
1296 int *mvjcost, int *mvcost[2], int_mv *center_mv) { 1218 int *mvjcost, int *mvcost[2], int_mv *center_mv) {
1297 int i, j, step; 1219 int i, j, step;
1298 1220
1299 const MACROBLOCKD* const xd = &x->e_mbd; 1221 const MACROBLOCKD* const xd = &x->e_mbd;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1333 *num00 = 0; 1255 *num00 = 0;
1334 best_mv->as_mv.row = ref_row; 1256 best_mv->as_mv.row = ref_row;
1335 best_mv->as_mv.col = ref_col; 1257 best_mv->as_mv.col = ref_col;
1336 1258
1337 // Work out the start point for the search 1259 // Work out the start point for the search
1338 in_what = (uint8_t *)(xd->plane[0].pre[0].buf + 1260 in_what = (uint8_t *)(xd->plane[0].pre[0].buf +
1339 (ref_row * (xd->plane[0].pre[0].stride)) + ref_col); 1261 (ref_row * (xd->plane[0].pre[0].stride)) + ref_col);
1340 best_address = in_what; 1262 best_address = in_what;
1341 1263
1342 // Check the starting position 1264 // Check the starting position
1343 bestsad = fn_ptr->sdf(what, what_stride, 1265 bestsad = fn_ptr->sdf(what, what_stride, in_what, in_what_stride, 0x7fffffff)
1344 in_what, in_what_stride, 0x7fffffff) 1266 + mvsad_err_cost(&best_mv->as_mv, &fcenter_mv.as_mv,
1345 + mvsad_err_cost(best_mv, &fcenter_mv, mvjsadcost, mvsadcost, 1267 mvjsadcost, mvsadcost, sad_per_bit);
1346 sad_per_bit);
1347 1268
1348 // search_param determines the length of the initial step and hence the number of iterations 1269 // search_param determines the length of the initial step and hence the number
1349 // 0 = initial step (MAX_FIRST_STEP) pel : 1 = (MAX_FIRST_STEP/2) pel, 2 = (MA X_FIRST_STEP/4) pel... etc. 1270 // of iterations.
1271 // 0 = initial step (MAX_FIRST_STEP) pel
1272 // 1 = (MAX_FIRST_STEP/2) pel,
1273 // 2 = (MAX_FIRST_STEP/4) pel...
1350 ss = &x->ss[search_param * x->searches_per_step]; 1274 ss = &x->ss[search_param * x->searches_per_step];
1351 tot_steps = (x->ss_count / x->searches_per_step) - search_param; 1275 tot_steps = (x->ss_count / x->searches_per_step) - search_param;
1352 1276
1353 i = 1; 1277 i = 1;
1354 1278
1355 for (step = 0; step < tot_steps; step++) { 1279 for (step = 0; step < tot_steps; step++) {
1356 int all_in = 1, t; 1280 int all_in = 1, t;
1357 1281
1358 // To know if all neighbor points are within the bounds, 4 bounds checking a re enough instead of 1282 // All_in is true if every one of the points we are checking are within
1359 // checking 4 bounds for each points. 1283 // the bounds of the image.
1360 all_in &= ((best_mv->as_mv.row + ss[i].mv.row) > x->mv_row_min); 1284 all_in &= ((best_mv->as_mv.row + ss[i].mv.row) > x->mv_row_min);
1361 all_in &= ((best_mv->as_mv.row + ss[i + 1].mv.row) < x->mv_row_max); 1285 all_in &= ((best_mv->as_mv.row + ss[i + 1].mv.row) < x->mv_row_max);
1362 all_in &= ((best_mv->as_mv.col + ss[i + 2].mv.col) > x->mv_col_min); 1286 all_in &= ((best_mv->as_mv.col + ss[i + 2].mv.col) > x->mv_col_min);
1363 all_in &= ((best_mv->as_mv.col + ss[i + 3].mv.col) < x->mv_col_max); 1287 all_in &= ((best_mv->as_mv.col + ss[i + 3].mv.col) < x->mv_col_max);
1364 1288
1289 // If all the pixels are within the bounds we don't check whether the
1290 // search point is valid in this loop, otherwise we check each point
1291 // for validity..
1365 if (all_in) { 1292 if (all_in) {
1366 unsigned int sad_array[4]; 1293 unsigned int sad_array[4];
1367 1294
1368 for (j = 0; j < x->searches_per_step; j += 4) { 1295 for (j = 0; j < x->searches_per_step; j += 4) {
1369 unsigned char const *block_offset[4]; 1296 unsigned char const *block_offset[4];
1370 1297
1371 for (t = 0; t < 4; t++) 1298 for (t = 0; t < 4; t++)
1372 block_offset[t] = ss[i + t].offset + best_address; 1299 block_offset[t] = ss[i + t].offset + best_address;
1373 1300
1374 fn_ptr->sdx4df(what, what_stride, block_offset, in_what_stride, 1301 fn_ptr->sdx4df(what, what_stride, block_offset, in_what_stride,
1375 sad_array); 1302 sad_array);
1376 1303
1377 for (t = 0; t < 4; t++, i++) { 1304 for (t = 0; t < 4; t++, i++) {
1378 if (sad_array[t] < bestsad) { 1305 if (sad_array[t] < bestsad) {
1379 this_mv.as_mv.row = best_mv->as_mv.row + ss[i].mv.row; 1306 this_mv.as_mv.row = best_mv->as_mv.row + ss[i].mv.row;
1380 this_mv.as_mv.col = best_mv->as_mv.col + ss[i].mv.col; 1307 this_mv.as_mv.col = best_mv->as_mv.col + ss[i].mv.col;
1381 sad_array[t] += mvsad_err_cost(&this_mv, &fcenter_mv, 1308 sad_array[t] += mvsad_err_cost(&this_mv.as_mv, &fcenter_mv.as_mv,
1382 mvjsadcost, mvsadcost, sad_per_bit); 1309 mvjsadcost, mvsadcost, sad_per_bit);
1383 1310
1384 if (sad_array[t] < bestsad) { 1311 if (sad_array[t] < bestsad) {
1385 bestsad = sad_array[t]; 1312 bestsad = sad_array[t];
1386 best_site = i; 1313 best_site = i;
1387 } 1314 }
1388 } 1315 }
1389 } 1316 }
1390 } 1317 }
1391 } else { 1318 } else {
1392 for (j = 0; j < x->searches_per_step; j++) { 1319 for (j = 0; j < x->searches_per_step; j++) {
1393 // Trap illegal vectors 1320 // Trap illegal vectors
1394 this_row_offset = best_mv->as_mv.row + ss[i].mv.row; 1321 this_row_offset = best_mv->as_mv.row + ss[i].mv.row;
1395 this_col_offset = best_mv->as_mv.col + ss[i].mv.col; 1322 this_col_offset = best_mv->as_mv.col + ss[i].mv.col;
1396 1323
1397 if ((this_col_offset > x->mv_col_min) && (this_col_offset < x->mv_col_ma x) && 1324 if ((this_col_offset > x->mv_col_min) &&
1398 (this_row_offset > x->mv_row_min) && (this_row_offset < x->mv_row_ma x)) { 1325 (this_col_offset < x->mv_col_max) &&
1326 (this_row_offset > x->mv_row_min) &&
1327 (this_row_offset < x->mv_row_max)) {
1399 check_here = ss[i].offset + best_address; 1328 check_here = ss[i].offset + best_address;
1400 thissad = fn_ptr->sdf(what, what_stride, check_here, in_what_stride, b estsad); 1329 thissad = fn_ptr->sdf(what, what_stride, check_here, in_what_stride,
1330 bestsad);
1401 1331
1402 if (thissad < bestsad) { 1332 if (thissad < bestsad) {
1403 this_mv.as_mv.row = this_row_offset; 1333 this_mv.as_mv.row = this_row_offset;
1404 this_mv.as_mv.col = this_col_offset; 1334 this_mv.as_mv.col = this_col_offset;
1405 thissad += mvsad_err_cost(&this_mv, &fcenter_mv, 1335 thissad += mvsad_err_cost(&this_mv.as_mv, &fcenter_mv.as_mv,
1406 mvjsadcost, mvsadcost, sad_per_bit); 1336 mvjsadcost, mvsadcost, sad_per_bit);
1407 1337
1408 if (thissad < bestsad) { 1338 if (thissad < bestsad) {
1409 bestsad = thissad; 1339 bestsad = thissad;
1410 best_site = i; 1340 best_site = i;
1411 } 1341 }
1412 } 1342 }
1413 } 1343 }
1414 i++; 1344 i++;
1415 } 1345 }
(...skipping 10 matching lines...) Expand all
1426 if ((this_col_offset > x->mv_col_min) && 1356 if ((this_col_offset > x->mv_col_min) &&
1427 (this_col_offset < x->mv_col_max) && 1357 (this_col_offset < x->mv_col_max) &&
1428 (this_row_offset > x->mv_row_min) && 1358 (this_row_offset > x->mv_row_min) &&
1429 (this_row_offset < x->mv_row_max)) { 1359 (this_row_offset < x->mv_row_max)) {
1430 check_here = ss[best_site].offset + best_address; 1360 check_here = ss[best_site].offset + best_address;
1431 thissad = fn_ptr->sdf(what, what_stride, check_here, in_what_stride, 1361 thissad = fn_ptr->sdf(what, what_stride, check_here, in_what_stride,
1432 bestsad); 1362 bestsad);
1433 if (thissad < bestsad) { 1363 if (thissad < bestsad) {
1434 this_mv.as_mv.row = this_row_offset; 1364 this_mv.as_mv.row = this_row_offset;
1435 this_mv.as_mv.col = this_col_offset; 1365 this_mv.as_mv.col = this_col_offset;
1436 thissad += mvsad_err_cost(&this_mv, &fcenter_mv, 1366 thissad += mvsad_err_cost(&this_mv.as_mv, &fcenter_mv.as_mv,
1437 mvjsadcost, mvsadcost, sad_per_bit); 1367 mvjsadcost, mvsadcost, sad_per_bit);
1438 if (thissad < bestsad) { 1368 if (thissad < bestsad) {
1439 bestsad = thissad; 1369 bestsad = thissad;
1440 best_mv->as_mv.row += ss[best_site].mv.row; 1370 best_mv->as_mv.row += ss[best_site].mv.row;
1441 best_mv->as_mv.col += ss[best_site].mv.col; 1371 best_mv->as_mv.col += ss[best_site].mv.col;
1442 best_address += ss[best_site].offset; 1372 best_address += ss[best_site].offset;
1443 continue; 1373 continue;
1444 } 1374 }
1445 } 1375 }
1446 } 1376 }
1447 break; 1377 break;
1448 }; 1378 };
1449 #endif 1379 #endif
1450 } else if (best_address == in_what) 1380 } else if (best_address == in_what) {
1451 (*num00)++; 1381 (*num00)++;
1382 }
1452 } 1383 }
1453 1384
1454 this_mv.as_mv.row = best_mv->as_mv.row << 3; 1385 this_mv.as_mv.row = best_mv->as_mv.row * 8;
1455 this_mv.as_mv.col = best_mv->as_mv.col << 3; 1386 this_mv.as_mv.col = best_mv->as_mv.col * 8;
1456 1387
1457 if (bestsad == INT_MAX) 1388 if (bestsad == INT_MAX)
1458 return INT_MAX; 1389 return INT_MAX;
1459 1390
1460 return fn_ptr->vf(what, what_stride, best_address, in_what_stride, 1391 return fn_ptr->vf(what, what_stride, best_address, in_what_stride,
1461 (unsigned int *)(&thissad)) + mv_err_cost(&this_mv, 1392 (unsigned int *)(&thissad)) +
1462 center_mv, mvjcost, mvcost, x->errorperbit); 1393 mv_err_cost(&this_mv.as_mv, &center_mv->as_mv,
1394 mvjcost, mvcost, x->errorperbit);
1463 } 1395 }
1464 1396
1465 /* do_refine: If last step (1-away) of n-step search doesn't pick the center 1397 /* do_refine: If last step (1-away) of n-step search doesn't pick the center
1466 point as the best match, we will do a final 1-away diamond 1398 point as the best match, we will do a final 1-away diamond
1467 refining search */ 1399 refining search */
1468 1400
1469 int vp9_full_pixel_diamond(VP9_COMP *cpi, MACROBLOCK *x, 1401 int vp9_full_pixel_diamond(VP9_COMP *cpi, MACROBLOCK *x,
1470 int_mv *mvp_full, int step_param, 1402 int_mv *mvp_full, int step_param,
1471 int sadpb, int further_steps, 1403 int sadpb, int further_steps,
1472 int do_refine, vp9_variance_fn_ptr_t *fn_ptr, 1404 int do_refine, vp9_variance_fn_ptr_t *fn_ptr,
1473 int_mv *ref_mv, int_mv *dst_mv) { 1405 int_mv *ref_mv, int_mv *dst_mv) {
1474 int_mv temp_mv; 1406 int_mv temp_mv;
1475 int thissme, n, num00; 1407 int thissme, n, num00;
1476 int bestsme = cpi->diamond_search_sad(x, mvp_full, &temp_mv, 1408 int bestsme = cpi->diamond_search_sad(x, mvp_full, &temp_mv,
1477 step_param, sadpb, &num00, 1409 step_param, sadpb, &num00,
1478 fn_ptr, x->nmvjointcost, 1410 fn_ptr, x->nmvjointcost,
1479 x->mvcost, ref_mv); 1411 x->mvcost, ref_mv);
1480 dst_mv->as_int = temp_mv.as_int; 1412 dst_mv->as_int = temp_mv.as_int;
1481 1413
1482 n = num00; 1414 n = num00;
1483 num00 = 0; 1415 num00 = 0;
1484 1416
1485 /* If there won't be more n-step search, check to see if refining search is ne eded. */ 1417 /* If there won't be more n-step search, check to see if refining search is
1418 * needed. */
1486 if (n > further_steps) 1419 if (n > further_steps)
1487 do_refine = 0; 1420 do_refine = 0;
1488 1421
1489 while (n < further_steps) { 1422 while (n < further_steps) {
1490 n++; 1423 n++;
1491 1424
1492 if (num00) 1425 if (num00) {
1493 num00--; 1426 num00--;
1494 else { 1427 } else {
1495 thissme = cpi->diamond_search_sad(x, mvp_full, &temp_mv, 1428 thissme = cpi->diamond_search_sad(x, mvp_full, &temp_mv,
1496 step_param + n, sadpb, &num00, 1429 step_param + n, sadpb, &num00,
1497 fn_ptr, x->nmvjointcost, x->mvcost, 1430 fn_ptr, x->nmvjointcost, x->mvcost,
1498 ref_mv); 1431 ref_mv);
1499 1432
1500 /* check to see if refining search is needed. */ 1433 /* check to see if refining search is needed. */
1501 if (num00 > (further_steps - n)) 1434 if (num00 > (further_steps - n))
1502 do_refine = 0; 1435 do_refine = 0;
1503 1436
1504 if (thissme < bestsme) { 1437 if (thissme < bestsme) {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1563 // Work out the mid point for the search 1496 // Work out the mid point for the search
1564 in_what = xd->plane[0].pre[0].buf; 1497 in_what = xd->plane[0].pre[0].buf;
1565 bestaddress = in_what + (ref_row * xd->plane[0].pre[0].stride) + ref_col; 1498 bestaddress = in_what + (ref_row * xd->plane[0].pre[0].stride) + ref_col;
1566 1499
1567 best_mv->as_mv.row = ref_row; 1500 best_mv->as_mv.row = ref_row;
1568 best_mv->as_mv.col = ref_col; 1501 best_mv->as_mv.col = ref_col;
1569 1502
1570 // Baseline value at the centre 1503 // Baseline value at the centre
1571 bestsad = fn_ptr->sdf(what, what_stride, bestaddress, 1504 bestsad = fn_ptr->sdf(what, what_stride, bestaddress,
1572 in_what_stride, 0x7fffffff) 1505 in_what_stride, 0x7fffffff)
1573 + mvsad_err_cost(best_mv, &fcenter_mv, mvjsadcost, mvsadcost, 1506 + mvsad_err_cost(&best_mv->as_mv, &fcenter_mv.as_mv,
1574 sad_per_bit); 1507 mvjsadcost, mvsadcost, sad_per_bit);
1575 1508
1576 // Apply further limits to prevent us looking using vectors that stretch 1509 // Apply further limits to prevent us looking using vectors that stretch
1577 // beyond the UMV border 1510 // beyond the UMV border
1578 col_min = MAX(col_min, x->mv_col_min); 1511 col_min = MAX(col_min, x->mv_col_min);
1579 col_max = MIN(col_max, x->mv_col_max); 1512 col_max = MIN(col_max, x->mv_col_max);
1580 row_min = MAX(row_min, x->mv_row_min); 1513 row_min = MAX(row_min, x->mv_row_min);
1581 row_max = MIN(row_max, x->mv_row_max); 1514 row_max = MIN(row_max, x->mv_row_max);
1582 1515
1583 for (r = row_min; r < row_max; r++) { 1516 for (r = row_min; r < row_max; r++) {
1584 this_mv.as_mv.row = r; 1517 this_mv.as_mv.row = r;
1585 check_here = r * mv_stride + in_what + col_min; 1518 check_here = r * mv_stride + in_what + col_min;
1586 1519
1587 for (c = col_min; c < col_max; c++) { 1520 for (c = col_min; c < col_max; c++) {
1588 thissad = fn_ptr->sdf(what, what_stride, check_here, in_what_stride, bests ad); 1521 thissad = fn_ptr->sdf(what, what_stride, check_here, in_what_stride,
1522 bestsad);
1589 1523
1590 this_mv.as_mv.col = c; 1524 this_mv.as_mv.col = c;
1591 thissad += mvsad_err_cost(&this_mv, &fcenter_mv, 1525 thissad += mvsad_err_cost(&this_mv.as_mv, &fcenter_mv.as_mv,
1592 mvjsadcost, mvsadcost, sad_per_bit); 1526 mvjsadcost, mvsadcost, sad_per_bit);
1593 1527
1594 if (thissad < bestsad) { 1528 if (thissad < bestsad) {
1595 bestsad = thissad; 1529 bestsad = thissad;
1596 best_mv->as_mv.row = r; 1530 best_mv->as_mv.row = r;
1597 best_mv->as_mv.col = c; 1531 best_mv->as_mv.col = c;
1598 bestaddress = check_here; 1532 bestaddress = check_here;
1599 } 1533 }
1600 1534
1601 check_here++; 1535 check_here++;
1602 } 1536 }
1603 } 1537 }
1604 1538
1605 this_mv.as_mv.row = best_mv->as_mv.row << 3; 1539 this_mv.as_mv.row = best_mv->as_mv.row * 8;
1606 this_mv.as_mv.col = best_mv->as_mv.col << 3; 1540 this_mv.as_mv.col = best_mv->as_mv.col * 8;
1607 1541
1608 if (bestsad < INT_MAX) 1542 if (bestsad < INT_MAX)
1609 return 1543 return fn_ptr->vf(what, what_stride, bestaddress, in_what_stride,
1610 fn_ptr->vf(what, what_stride, bestaddress, in_what_stride, 1544 (unsigned int *)(&thissad)) +
1611 (unsigned int *)(&thissad)) + 1545 mv_err_cost(&this_mv.as_mv, &center_mv->as_mv,
1612 mv_err_cost(&this_mv, center_mv, mvjcost, mvcost, x->errorperbit); 1546 mvjcost, mvcost, x->errorperbit);
1613 else 1547 else
1614 return INT_MAX; 1548 return INT_MAX;
1615 } 1549 }
1616 1550
1617 int vp9_full_search_sadx3(MACROBLOCK *x, int_mv *ref_mv, 1551 int vp9_full_search_sadx3(MACROBLOCK *x, int_mv *ref_mv,
1618 int sad_per_bit, int distance, 1552 int sad_per_bit, int distance,
1619 vp9_variance_fn_ptr_t *fn_ptr, int *mvjcost, 1553 vp9_variance_fn_ptr_t *fn_ptr, int *mvjcost,
1620 int *mvcost[2], int_mv *center_mv, int n) { 1554 int *mvcost[2], int_mv *center_mv, int n) {
1621 const MACROBLOCKD* const xd = &x->e_mbd; 1555 const MACROBLOCKD* const xd = &x->e_mbd;
1622 uint8_t *what = x->plane[0].src.buf; 1556 uint8_t *what = x->plane[0].src.buf;
(...skipping 30 matching lines...) Expand all
1653 // Work out the mid point for the search 1587 // Work out the mid point for the search
1654 in_what = xd->plane[0].pre[0].buf; 1588 in_what = xd->plane[0].pre[0].buf;
1655 bestaddress = in_what + (ref_row * xd->plane[0].pre[0].stride) + ref_col; 1589 bestaddress = in_what + (ref_row * xd->plane[0].pre[0].stride) + ref_col;
1656 1590
1657 best_mv->as_mv.row = ref_row; 1591 best_mv->as_mv.row = ref_row;
1658 best_mv->as_mv.col = ref_col; 1592 best_mv->as_mv.col = ref_col;
1659 1593
1660 // Baseline value at the centre 1594 // Baseline value at the centre
1661 bestsad = fn_ptr->sdf(what, what_stride, 1595 bestsad = fn_ptr->sdf(what, what_stride,
1662 bestaddress, in_what_stride, 0x7fffffff) 1596 bestaddress, in_what_stride, 0x7fffffff)
1663 + mvsad_err_cost(best_mv, &fcenter_mv, mvjsadcost, mvsadcost, 1597 + mvsad_err_cost(&best_mv->as_mv, &fcenter_mv.as_mv,
1664 sad_per_bit); 1598 mvjsadcost, mvsadcost, sad_per_bit);
1665 1599
1666 // Apply further limits to prevent us looking using vectors that stretch 1600 // Apply further limits to prevent us looking using vectors that stretch
1667 // beyond the UMV border 1601 // beyond the UMV border
1668 col_min = MAX(col_min, x->mv_col_min); 1602 col_min = MAX(col_min, x->mv_col_min);
1669 col_max = MIN(col_max, x->mv_col_max); 1603 col_max = MIN(col_max, x->mv_col_max);
1670 row_min = MAX(row_min, x->mv_row_min); 1604 row_min = MAX(row_min, x->mv_row_min);
1671 row_max = MIN(row_max, x->mv_row_max); 1605 row_max = MIN(row_max, x->mv_row_max);
1672 1606
1673 for (r = row_min; r < row_max; r++) { 1607 for (r = row_min; r < row_max; r++) {
1674 this_mv.as_mv.row = r; 1608 this_mv.as_mv.row = r;
1675 check_here = r * mv_stride + in_what + col_min; 1609 check_here = r * mv_stride + in_what + col_min;
1676 c = col_min; 1610 c = col_min;
1677 1611
1678 while ((c + 2) < col_max) { 1612 while ((c + 2) < col_max) {
1679 int i; 1613 int i;
1680 1614
1681 fn_ptr->sdx3f(what, what_stride, check_here, in_what_stride, sad_array); 1615 fn_ptr->sdx3f(what, what_stride, check_here, in_what_stride, sad_array);
1682 1616
1683 for (i = 0; i < 3; i++) { 1617 for (i = 0; i < 3; i++) {
1684 thissad = sad_array[i]; 1618 thissad = sad_array[i];
1685 1619
1686 if (thissad < bestsad) { 1620 if (thissad < bestsad) {
1687 this_mv.as_mv.col = c; 1621 this_mv.as_mv.col = c;
1688 thissad += mvsad_err_cost(&this_mv, &fcenter_mv, 1622 thissad += mvsad_err_cost(&this_mv.as_mv, &fcenter_mv.as_mv,
1689 mvjsadcost, mvsadcost, sad_per_bit); 1623 mvjsadcost, mvsadcost, sad_per_bit);
1690 1624
1691 if (thissad < bestsad) { 1625 if (thissad < bestsad) {
1692 bestsad = thissad; 1626 bestsad = thissad;
1693 best_mv->as_mv.row = r; 1627 best_mv->as_mv.row = r;
1694 best_mv->as_mv.col = c; 1628 best_mv->as_mv.col = c;
1695 bestaddress = check_here; 1629 bestaddress = check_here;
1696 } 1630 }
1697 } 1631 }
1698 1632
1699 check_here++; 1633 check_here++;
1700 c++; 1634 c++;
1701 } 1635 }
1702 } 1636 }
1703 1637
1704 while (c < col_max) { 1638 while (c < col_max) {
1705 thissad = fn_ptr->sdf(what, what_stride, check_here, in_what_stride, bests ad); 1639 thissad = fn_ptr->sdf(what, what_stride, check_here, in_what_stride,
1640 bestsad);
1706 1641
1707 if (thissad < bestsad) { 1642 if (thissad < bestsad) {
1708 this_mv.as_mv.col = c; 1643 this_mv.as_mv.col = c;
1709 thissad += mvsad_err_cost(&this_mv, &fcenter_mv, 1644 thissad += mvsad_err_cost(&this_mv.as_mv, &fcenter_mv.as_mv,
1710 mvjsadcost, mvsadcost, sad_per_bit); 1645 mvjsadcost, mvsadcost, sad_per_bit);
1711 1646
1712 if (thissad < bestsad) { 1647 if (thissad < bestsad) {
1713 bestsad = thissad; 1648 bestsad = thissad;
1714 best_mv->as_mv.row = r; 1649 best_mv->as_mv.row = r;
1715 best_mv->as_mv.col = c; 1650 best_mv->as_mv.col = c;
1716 bestaddress = check_here; 1651 bestaddress = check_here;
1717 } 1652 }
1718 } 1653 }
1719 1654
1720 check_here++; 1655 check_here++;
1721 c++; 1656 c++;
1722 } 1657 }
1723
1724 } 1658 }
1725 1659
1726 this_mv.as_mv.row = best_mv->as_mv.row << 3; 1660 this_mv.as_mv.row = best_mv->as_mv.row * 8;
1727 this_mv.as_mv.col = best_mv->as_mv.col << 3; 1661 this_mv.as_mv.col = best_mv->as_mv.col * 8;
1728 1662
1729 if (bestsad < INT_MAX) 1663 if (bestsad < INT_MAX)
1730 return 1664 return fn_ptr->vf(what, what_stride, bestaddress, in_what_stride,
1731 fn_ptr->vf(what, what_stride, bestaddress, in_what_stride, 1665 (unsigned int *)(&thissad)) +
1732 (unsigned int *)(&thissad)) + 1666 mv_err_cost(&this_mv.as_mv, &center_mv->as_mv,
1733 mv_err_cost(&this_mv, center_mv, mvjcost, mvcost, x->errorperbit); 1667 mvjcost, mvcost, x->errorperbit);
1734 else 1668 else
1735 return INT_MAX; 1669 return INT_MAX;
1736 } 1670 }
1737 1671
1738 int vp9_full_search_sadx8(MACROBLOCK *x, int_mv *ref_mv, 1672 int vp9_full_search_sadx8(MACROBLOCK *x, int_mv *ref_mv,
1739 int sad_per_bit, int distance, 1673 int sad_per_bit, int distance,
1740 vp9_variance_fn_ptr_t *fn_ptr, 1674 vp9_variance_fn_ptr_t *fn_ptr,
1741 int *mvjcost, int *mvcost[2], 1675 int *mvjcost, int *mvcost[2],
1742 int_mv *center_mv, int n) { 1676 int_mv *center_mv, int n) {
1743 const MACROBLOCKD* const xd = &x->e_mbd; 1677 const MACROBLOCKD* const xd = &x->e_mbd;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1776 // Work out the mid point for the search 1710 // Work out the mid point for the search
1777 in_what = xd->plane[0].pre[0].buf; 1711 in_what = xd->plane[0].pre[0].buf;
1778 bestaddress = in_what + (ref_row * xd->plane[0].pre[0].stride) + ref_col; 1712 bestaddress = in_what + (ref_row * xd->plane[0].pre[0].stride) + ref_col;
1779 1713
1780 best_mv->as_mv.row = ref_row; 1714 best_mv->as_mv.row = ref_row;
1781 best_mv->as_mv.col = ref_col; 1715 best_mv->as_mv.col = ref_col;
1782 1716
1783 // Baseline value at the centre 1717 // Baseline value at the centre
1784 bestsad = fn_ptr->sdf(what, what_stride, 1718 bestsad = fn_ptr->sdf(what, what_stride,
1785 bestaddress, in_what_stride, 0x7fffffff) 1719 bestaddress, in_what_stride, 0x7fffffff)
1786 + mvsad_err_cost(best_mv, &fcenter_mv, mvjsadcost, mvsadcost, 1720 + mvsad_err_cost(&best_mv->as_mv, &fcenter_mv.as_mv,
1787 sad_per_bit); 1721 mvjsadcost, mvsadcost, sad_per_bit);
1788 1722
1789 // Apply further limits to prevent us looking using vectors that stretch 1723 // Apply further limits to prevent us looking using vectors that stretch
1790 // beyond the UMV border 1724 // beyond the UMV border
1791 col_min = MAX(col_min, x->mv_col_min); 1725 col_min = MAX(col_min, x->mv_col_min);
1792 col_max = MIN(col_max, x->mv_col_max); 1726 col_max = MIN(col_max, x->mv_col_max);
1793 row_min = MAX(row_min, x->mv_row_min); 1727 row_min = MAX(row_min, x->mv_row_min);
1794 row_max = MIN(row_max, x->mv_row_max); 1728 row_max = MIN(row_max, x->mv_row_max);
1795 1729
1796 for (r = row_min; r < row_max; r++) { 1730 for (r = row_min; r < row_max; r++) {
1797 this_mv.as_mv.row = r; 1731 this_mv.as_mv.row = r;
1798 check_here = r * mv_stride + in_what + col_min; 1732 check_here = r * mv_stride + in_what + col_min;
1799 c = col_min; 1733 c = col_min;
1800 1734
1801 while ((c + 7) < col_max) { 1735 while ((c + 7) < col_max) {
1802 int i; 1736 int i;
1803 1737
1804 fn_ptr->sdx8f(what, what_stride, check_here, in_what_stride, sad_array8); 1738 fn_ptr->sdx8f(what, what_stride, check_here, in_what_stride, sad_array8);
1805 1739
1806 for (i = 0; i < 8; i++) { 1740 for (i = 0; i < 8; i++) {
1807 thissad = (unsigned int)sad_array8[i]; 1741 thissad = (unsigned int)sad_array8[i];
1808 1742
1809 if (thissad < bestsad) { 1743 if (thissad < bestsad) {
1810 this_mv.as_mv.col = c; 1744 this_mv.as_mv.col = c;
1811 thissad += mvsad_err_cost(&this_mv, &fcenter_mv, 1745 thissad += mvsad_err_cost(&this_mv.as_mv, &fcenter_mv.as_mv,
1812 mvjsadcost, mvsadcost, sad_per_bit); 1746 mvjsadcost, mvsadcost, sad_per_bit);
1813 1747
1814 if (thissad < bestsad) { 1748 if (thissad < bestsad) {
1815 bestsad = thissad; 1749 bestsad = thissad;
1816 best_mv->as_mv.row = r; 1750 best_mv->as_mv.row = r;
1817 best_mv->as_mv.col = c; 1751 best_mv->as_mv.col = c;
1818 bestaddress = check_here; 1752 bestaddress = check_here;
1819 } 1753 }
1820 } 1754 }
1821 1755
1822 check_here++; 1756 check_here++;
1823 c++; 1757 c++;
1824 } 1758 }
1825 } 1759 }
1826 1760
1827 while ((c + 2) < col_max && fn_ptr->sdx3f != NULL) { 1761 while ((c + 2) < col_max && fn_ptr->sdx3f != NULL) {
1828 int i; 1762 int i;
1829 1763
1830 fn_ptr->sdx3f(what, what_stride, check_here, in_what_stride, sad_array); 1764 fn_ptr->sdx3f(what, what_stride, check_here, in_what_stride, sad_array);
1831 1765
1832 for (i = 0; i < 3; i++) { 1766 for (i = 0; i < 3; i++) {
1833 thissad = sad_array[i]; 1767 thissad = sad_array[i];
1834 1768
1835 if (thissad < bestsad) { 1769 if (thissad < bestsad) {
1836 this_mv.as_mv.col = c; 1770 this_mv.as_mv.col = c;
1837 thissad += mvsad_err_cost(&this_mv, &fcenter_mv, 1771 thissad += mvsad_err_cost(&this_mv.as_mv, &fcenter_mv.as_mv,
1838 mvjsadcost, mvsadcost, sad_per_bit); 1772 mvjsadcost, mvsadcost, sad_per_bit);
1839 1773
1840 if (thissad < bestsad) { 1774 if (thissad < bestsad) {
1841 bestsad = thissad; 1775 bestsad = thissad;
1842 best_mv->as_mv.row = r; 1776 best_mv->as_mv.row = r;
1843 best_mv->as_mv.col = c; 1777 best_mv->as_mv.col = c;
1844 bestaddress = check_here; 1778 bestaddress = check_here;
1845 } 1779 }
1846 } 1780 }
1847 1781
1848 check_here++; 1782 check_here++;
1849 c++; 1783 c++;
1850 } 1784 }
1851 } 1785 }
1852 1786
1853 while (c < col_max) { 1787 while (c < col_max) {
1854 thissad = fn_ptr->sdf(what, what_stride, check_here, in_what_stride, bests ad); 1788 thissad = fn_ptr->sdf(what, what_stride, check_here, in_what_stride,
1789 bestsad);
1855 1790
1856 if (thissad < bestsad) { 1791 if (thissad < bestsad) {
1857 this_mv.as_mv.col = c; 1792 this_mv.as_mv.col = c;
1858 thissad += mvsad_err_cost(&this_mv, &fcenter_mv, 1793 thissad += mvsad_err_cost(&this_mv.as_mv, &fcenter_mv.as_mv,
1859 mvjsadcost, mvsadcost, sad_per_bit); 1794 mvjsadcost, mvsadcost, sad_per_bit);
1860 1795
1861 if (thissad < bestsad) { 1796 if (thissad < bestsad) {
1862 bestsad = thissad; 1797 bestsad = thissad;
1863 best_mv->as_mv.row = r; 1798 best_mv->as_mv.row = r;
1864 best_mv->as_mv.col = c; 1799 best_mv->as_mv.col = c;
1865 bestaddress = check_here; 1800 bestaddress = check_here;
1866 } 1801 }
1867 } 1802 }
1868 1803
1869 check_here++; 1804 check_here++;
1870 c++; 1805 c++;
1871 } 1806 }
1872 } 1807 }
1873 1808
1874 this_mv.as_mv.row = best_mv->as_mv.row << 3; 1809 this_mv.as_mv.row = best_mv->as_mv.row * 8;
1875 this_mv.as_mv.col = best_mv->as_mv.col << 3; 1810 this_mv.as_mv.col = best_mv->as_mv.col * 8;
1876 1811
1877 if (bestsad < INT_MAX) 1812 if (bestsad < INT_MAX)
1878 return 1813 return fn_ptr->vf(what, what_stride, bestaddress, in_what_stride,
1879 fn_ptr->vf(what, what_stride, bestaddress, in_what_stride, 1814 (unsigned int *)(&thissad)) +
1880 (unsigned int *)(&thissad)) + 1815 mv_err_cost(&this_mv.as_mv, &center_mv->as_mv,
1881 mv_err_cost(&this_mv, center_mv, mvjcost, mvcost, x->errorperbit); 1816 mvjcost, mvcost, x->errorperbit);
1882 else 1817 else
1883 return INT_MAX; 1818 return INT_MAX;
1884 } 1819 }
1885 int vp9_refining_search_sad_c(MACROBLOCK *x, 1820 int vp9_refining_search_sad_c(MACROBLOCK *x,
1886 int_mv *ref_mv, int error_per_bit, 1821 int_mv *ref_mv, int error_per_bit,
1887 int search_range, vp9_variance_fn_ptr_t *fn_ptr, 1822 int search_range, vp9_variance_fn_ptr_t *fn_ptr,
1888 int *mvjcost, int *mvcost[2], int_mv *center_mv) { 1823 int *mvjcost, int *mvcost[2], int_mv *center_mv) {
1889 const MACROBLOCKD* const xd = &x->e_mbd; 1824 const MACROBLOCKD* const xd = &x->e_mbd;
1890 MV neighbors[4] = {{ -1, 0}, {0, -1}, {0, 1}, {1, 0}}; 1825 MV neighbors[4] = {{ -1, 0}, {0, -1}, {0, 1}, {1, 0}};
1891 int i, j; 1826 int i, j;
(...skipping 10 matching lines...) Expand all
1902 int_mv this_mv; 1837 int_mv this_mv;
1903 unsigned int bestsad = INT_MAX; 1838 unsigned int bestsad = INT_MAX;
1904 int_mv fcenter_mv; 1839 int_mv fcenter_mv;
1905 1840
1906 int *mvjsadcost = x->nmvjointsadcost; 1841 int *mvjsadcost = x->nmvjointsadcost;
1907 int *mvsadcost[2] = {x->nmvsadcost[0], x->nmvsadcost[1]}; 1842 int *mvsadcost[2] = {x->nmvsadcost[0], x->nmvsadcost[1]};
1908 1843
1909 fcenter_mv.as_mv.row = center_mv->as_mv.row >> 3; 1844 fcenter_mv.as_mv.row = center_mv->as_mv.row >> 3;
1910 fcenter_mv.as_mv.col = center_mv->as_mv.col >> 3; 1845 fcenter_mv.as_mv.col = center_mv->as_mv.col >> 3;
1911 1846
1912 bestsad = fn_ptr->sdf(what, what_stride, best_address, in_what_stride, 0x7ffff fff) + 1847 bestsad = fn_ptr->sdf(what, what_stride, best_address,
1913 mvsad_err_cost(ref_mv, &fcenter_mv, mvjsadcost, mvsadcost, error_per_bit); 1848 in_what_stride, 0x7fffffff) +
1849 mvsad_err_cost(&ref_mv->as_mv, &fcenter_mv.as_mv,
1850 mvjsadcost, mvsadcost, error_per_bit);
1914 1851
1915 for (i = 0; i < search_range; i++) { 1852 for (i = 0; i < search_range; i++) {
1916 int best_site = -1; 1853 int best_site = -1;
1917 1854
1918 for (j = 0; j < 4; j++) { 1855 for (j = 0; j < 4; j++) {
1919 this_row_offset = ref_mv->as_mv.row + neighbors[j].row; 1856 this_row_offset = ref_mv->as_mv.row + neighbors[j].row;
1920 this_col_offset = ref_mv->as_mv.col + neighbors[j].col; 1857 this_col_offset = ref_mv->as_mv.col + neighbors[j].col;
1921 1858
1922 if ((this_col_offset > x->mv_col_min) && (this_col_offset < x->mv_col_max) && 1859 if ((this_col_offset > x->mv_col_min) &&
1923 (this_row_offset > x->mv_row_min) && (this_row_offset < x->mv_row_max) ) { 1860 (this_col_offset < x->mv_col_max) &&
1924 check_here = (neighbors[j].row) * in_what_stride + neighbors[j].col + be st_address; 1861 (this_row_offset > x->mv_row_min) &&
1925 thissad = fn_ptr->sdf(what, what_stride, check_here, in_what_stride, bes tsad); 1862 (this_row_offset < x->mv_row_max)) {
1863 check_here = (neighbors[j].row) * in_what_stride + neighbors[j].col +
1864 best_address;
1865 thissad = fn_ptr->sdf(what, what_stride, check_here, in_what_stride,
1866 bestsad);
1926 1867
1927 if (thissad < bestsad) { 1868 if (thissad < bestsad) {
1928 this_mv.as_mv.row = this_row_offset; 1869 this_mv.as_mv.row = this_row_offset;
1929 this_mv.as_mv.col = this_col_offset; 1870 this_mv.as_mv.col = this_col_offset;
1930 thissad += mvsad_err_cost(&this_mv, &fcenter_mv, mvjsadcost, 1871 thissad += mvsad_err_cost(&this_mv.as_mv, &fcenter_mv.as_mv,
1931 mvsadcost, error_per_bit); 1872 mvjsadcost, mvsadcost, error_per_bit);
1932 1873
1933 if (thissad < bestsad) { 1874 if (thissad < bestsad) {
1934 bestsad = thissad; 1875 bestsad = thissad;
1935 best_site = j; 1876 best_site = j;
1936 } 1877 }
1937 } 1878 }
1938 } 1879 }
1939 } 1880 }
1940 1881
1941 if (best_site == -1) 1882 if (best_site == -1) {
1942 break; 1883 break;
1943 else { 1884 } else {
1944 ref_mv->as_mv.row += neighbors[best_site].row; 1885 ref_mv->as_mv.row += neighbors[best_site].row;
1945 ref_mv->as_mv.col += neighbors[best_site].col; 1886 ref_mv->as_mv.col += neighbors[best_site].col;
1946 best_address += (neighbors[best_site].row) * in_what_stride + neighbors[be st_site].col; 1887 best_address += (neighbors[best_site].row) * in_what_stride +
1888 neighbors[best_site].col;
1947 } 1889 }
1948 } 1890 }
1949 1891
1950 this_mv.as_mv.row = ref_mv->as_mv.row << 3; 1892 this_mv.as_mv.row = ref_mv->as_mv.row * 8;
1951 this_mv.as_mv.col = ref_mv->as_mv.col << 3; 1893 this_mv.as_mv.col = ref_mv->as_mv.col * 8;
1952 1894
1953 if (bestsad < INT_MAX) 1895 if (bestsad < INT_MAX)
1954 return 1896 return fn_ptr->vf(what, what_stride, best_address, in_what_stride,
1955 fn_ptr->vf(what, what_stride, best_address, in_what_stride, 1897 (unsigned int *)(&thissad)) +
1956 (unsigned int *)(&thissad)) + 1898 mv_err_cost(&this_mv.as_mv, &center_mv->as_mv,
1957 mv_err_cost(&this_mv, center_mv, mvjcost, mvcost, x->errorperbit); 1899 mvjcost, mvcost, x->errorperbit);
1958 else 1900 else
1959 return INT_MAX; 1901 return INT_MAX;
1960 } 1902 }
1961 1903
1962 int vp9_refining_search_sadx4(MACROBLOCK *x, 1904 int vp9_refining_search_sadx4(MACROBLOCK *x,
1963 int_mv *ref_mv, int error_per_bit, 1905 int_mv *ref_mv, int error_per_bit,
1964 int search_range, vp9_variance_fn_ptr_t *fn_ptr, 1906 int search_range, vp9_variance_fn_ptr_t *fn_ptr,
1965 int *mvjcost, int *mvcost[2], int_mv *center_mv) { 1907 int *mvjcost, int *mvcost[2], int_mv *center_mv) {
1966 const MACROBLOCKD* const xd = &x->e_mbd; 1908 const MACROBLOCKD* const xd = &x->e_mbd;
1967 MV neighbors[4] = {{ -1, 0}, {0, -1}, {0, 1}, {1, 0}}; 1909 MV neighbors[4] = {{ -1, 0}, {0, -1}, {0, 1}, {1, 0}};
(...skipping 11 matching lines...) Expand all
1979 int_mv this_mv; 1921 int_mv this_mv;
1980 unsigned int bestsad = INT_MAX; 1922 unsigned int bestsad = INT_MAX;
1981 int_mv fcenter_mv; 1923 int_mv fcenter_mv;
1982 1924
1983 int *mvjsadcost = x->nmvjointsadcost; 1925 int *mvjsadcost = x->nmvjointsadcost;
1984 int *mvsadcost[2] = {x->nmvsadcost[0], x->nmvsadcost[1]}; 1926 int *mvsadcost[2] = {x->nmvsadcost[0], x->nmvsadcost[1]};
1985 1927
1986 fcenter_mv.as_mv.row = center_mv->as_mv.row >> 3; 1928 fcenter_mv.as_mv.row = center_mv->as_mv.row >> 3;
1987 fcenter_mv.as_mv.col = center_mv->as_mv.col >> 3; 1929 fcenter_mv.as_mv.col = center_mv->as_mv.col >> 3;
1988 1930
1989 bestsad = fn_ptr->sdf(what, what_stride, best_address, in_what_stride, 0x7ffff fff) + 1931 bestsad = fn_ptr->sdf(what, what_stride, best_address,
1990 mvsad_err_cost(ref_mv, &fcenter_mv, mvjsadcost, mvsadcost, error_per_bit); 1932 in_what_stride, 0x7fffffff) +
1933 mvsad_err_cost(&ref_mv->as_mv, &fcenter_mv.as_mv,
1934 mvjsadcost, mvsadcost, error_per_bit);
1991 1935
1992 for (i = 0; i < search_range; i++) { 1936 for (i = 0; i < search_range; i++) {
1993 int best_site = -1; 1937 int best_site = -1;
1994 int all_in = ((ref_mv->as_mv.row - 1) > x->mv_row_min) & 1938 int all_in = ((ref_mv->as_mv.row - 1) > x->mv_row_min) &
1995 ((ref_mv->as_mv.row + 1) < x->mv_row_max) & 1939 ((ref_mv->as_mv.row + 1) < x->mv_row_max) &
1996 ((ref_mv->as_mv.col - 1) > x->mv_col_min) & 1940 ((ref_mv->as_mv.col - 1) > x->mv_col_min) &
1997 ((ref_mv->as_mv.col + 1) < x->mv_col_max); 1941 ((ref_mv->as_mv.col + 1) < x->mv_col_max);
1998 1942
1999 if (all_in) { 1943 if (all_in) {
2000 unsigned int sad_array[4]; 1944 unsigned int sad_array[4];
2001 unsigned char const *block_offset[4]; 1945 unsigned char const *block_offset[4];
2002 block_offset[0] = best_address - in_what_stride; 1946 block_offset[0] = best_address - in_what_stride;
2003 block_offset[1] = best_address - 1; 1947 block_offset[1] = best_address - 1;
2004 block_offset[2] = best_address + 1; 1948 block_offset[2] = best_address + 1;
2005 block_offset[3] = best_address + in_what_stride; 1949 block_offset[3] = best_address + in_what_stride;
2006 1950
2007 fn_ptr->sdx4df(what, what_stride, block_offset, in_what_stride, sad_array) ; 1951 fn_ptr->sdx4df(what, what_stride, block_offset, in_what_stride,
1952 sad_array);
2008 1953
2009 for (j = 0; j < 4; j++) { 1954 for (j = 0; j < 4; j++) {
2010 if (sad_array[j] < bestsad) { 1955 if (sad_array[j] < bestsad) {
2011 this_mv.as_mv.row = ref_mv->as_mv.row + neighbors[j].row; 1956 this_mv.as_mv.row = ref_mv->as_mv.row + neighbors[j].row;
2012 this_mv.as_mv.col = ref_mv->as_mv.col + neighbors[j].col; 1957 this_mv.as_mv.col = ref_mv->as_mv.col + neighbors[j].col;
2013 sad_array[j] += mvsad_err_cost(&this_mv, &fcenter_mv, mvjsadcost, 1958 sad_array[j] += mvsad_err_cost(&this_mv.as_mv, &fcenter_mv.as_mv,
2014 mvsadcost, error_per_bit); 1959 mvjsadcost, mvsadcost, error_per_bit);
2015 1960
2016 if (sad_array[j] < bestsad) { 1961 if (sad_array[j] < bestsad) {
2017 bestsad = sad_array[j]; 1962 bestsad = sad_array[j];
2018 best_site = j; 1963 best_site = j;
2019 } 1964 }
2020 } 1965 }
2021 } 1966 }
2022 } else { 1967 } else {
2023 for (j = 0; j < 4; j++) { 1968 for (j = 0; j < 4; j++) {
2024 this_row_offset = ref_mv->as_mv.row + neighbors[j].row; 1969 this_row_offset = ref_mv->as_mv.row + neighbors[j].row;
2025 this_col_offset = ref_mv->as_mv.col + neighbors[j].col; 1970 this_col_offset = ref_mv->as_mv.col + neighbors[j].col;
2026 1971
2027 if ((this_col_offset > x->mv_col_min) && (this_col_offset < x->mv_col_ma x) && 1972 if ((this_col_offset > x->mv_col_min) &&
2028 (this_row_offset > x->mv_row_min) && (this_row_offset < x->mv_row_ma x)) { 1973 (this_col_offset < x->mv_col_max) &&
2029 check_here = (neighbors[j].row) * in_what_stride + neighbors[j].col + best_address; 1974 (this_row_offset > x->mv_row_min) &&
2030 thissad = fn_ptr->sdf(what, what_stride, check_here, in_what_stride, b estsad); 1975 (this_row_offset < x->mv_row_max)) {
1976 check_here = (neighbors[j].row) * in_what_stride + neighbors[j].col +
1977 best_address;
1978 thissad = fn_ptr->sdf(what, what_stride, check_here, in_what_stride,
1979 bestsad);
2031 1980
2032 if (thissad < bestsad) { 1981 if (thissad < bestsad) {
2033 this_mv.as_mv.row = this_row_offset; 1982 this_mv.as_mv.row = this_row_offset;
2034 this_mv.as_mv.col = this_col_offset; 1983 this_mv.as_mv.col = this_col_offset;
2035 thissad += mvsad_err_cost(&this_mv, &fcenter_mv, mvjsadcost, 1984 thissad += mvsad_err_cost(&this_mv.as_mv, &fcenter_mv.as_mv,
2036 mvsadcost, error_per_bit); 1985 mvjsadcost, mvsadcost, error_per_bit);
2037 1986
2038 if (thissad < bestsad) { 1987 if (thissad < bestsad) {
2039 bestsad = thissad; 1988 bestsad = thissad;
2040 best_site = j; 1989 best_site = j;
2041 } 1990 }
2042 } 1991 }
2043 } 1992 }
2044 } 1993 }
2045 } 1994 }
2046 1995
2047 if (best_site == -1) 1996 if (best_site == -1) {
2048 break; 1997 break;
2049 else { 1998 } else {
2050 ref_mv->as_mv.row += neighbors[best_site].row; 1999 ref_mv->as_mv.row += neighbors[best_site].row;
2051 ref_mv->as_mv.col += neighbors[best_site].col; 2000 ref_mv->as_mv.col += neighbors[best_site].col;
2052 best_address += (neighbors[best_site].row) * in_what_stride + neighbors[be st_site].col; 2001 best_address += (neighbors[best_site].row) * in_what_stride +
2002 neighbors[best_site].col;
2053 } 2003 }
2054 } 2004 }
2055 2005
2056 this_mv.as_mv.row = ref_mv->as_mv.row << 3; 2006 this_mv.as_mv.row = ref_mv->as_mv.row * 8;
2057 this_mv.as_mv.col = ref_mv->as_mv.col << 3; 2007 this_mv.as_mv.col = ref_mv->as_mv.col * 8;
2058 2008
2059 if (bestsad < INT_MAX) 2009 if (bestsad < INT_MAX)
2060 return 2010 return fn_ptr->vf(what, what_stride, best_address, in_what_stride,
2061 fn_ptr->vf(what, what_stride, best_address, in_what_stride, 2011 (unsigned int *)(&thissad)) +
2062 (unsigned int *)(&thissad)) + 2012 mv_err_cost(&this_mv.as_mv, &center_mv->as_mv,
2063 mv_err_cost(&this_mv, center_mv, mvjcost, mvcost, x->errorperbit); 2013 mvjcost, mvcost, x->errorperbit);
2064 else 2014 else
2065 return INT_MAX; 2015 return INT_MAX;
2066 } 2016 }
2067 2017
2068 /* This function is called when we do joint motion search in comp_inter_inter 2018 /* This function is called when we do joint motion search in comp_inter_inter
2069 * mode. 2019 * mode.
2070 */ 2020 */
2071 int vp9_refining_search_8p_c(MACROBLOCK *x, 2021 int vp9_refining_search_8p_c(MACROBLOCK *x,
2072 int_mv *ref_mv, int error_per_bit, 2022 int_mv *ref_mv, int error_per_bit,
2073 int search_range, vp9_variance_fn_ptr_t *fn_ptr, 2023 int search_range, vp9_variance_fn_ptr_t *fn_ptr,
(...skipping 19 matching lines...) Expand all
2093 2043
2094 int *mvjsadcost = x->nmvjointsadcost; 2044 int *mvjsadcost = x->nmvjointsadcost;
2095 int *mvsadcost[2] = {x->nmvsadcost[0], x->nmvsadcost[1]}; 2045 int *mvsadcost[2] = {x->nmvsadcost[0], x->nmvsadcost[1]};
2096 2046
2097 fcenter_mv.as_mv.row = center_mv->as_mv.row >> 3; 2047 fcenter_mv.as_mv.row = center_mv->as_mv.row >> 3;
2098 fcenter_mv.as_mv.col = center_mv->as_mv.col >> 3; 2048 fcenter_mv.as_mv.col = center_mv->as_mv.col >> 3;
2099 2049
2100 /* Get compound pred by averaging two pred blocks. */ 2050 /* Get compound pred by averaging two pred blocks. */
2101 bestsad = fn_ptr->sdaf(what, what_stride, best_address, in_what_stride, 2051 bestsad = fn_ptr->sdaf(what, what_stride, best_address, in_what_stride,
2102 second_pred, 0x7fffffff) + 2052 second_pred, 0x7fffffff) +
2103 mvsad_err_cost(ref_mv, &fcenter_mv, mvjsadcost, mvsadcost, error_per_bit); 2053 mvsad_err_cost(&ref_mv->as_mv, &fcenter_mv.as_mv,
2054 mvjsadcost, mvsadcost, error_per_bit);
2104 2055
2105 for (i = 0; i < search_range; i++) { 2056 for (i = 0; i < search_range; i++) {
2106 int best_site = -1; 2057 int best_site = -1;
2107 2058
2108 for (j = 0; j < 8; j++) { 2059 for (j = 0; j < 8; j++) {
2109 this_row_offset = ref_mv->as_mv.row + neighbors[j].row; 2060 this_row_offset = ref_mv->as_mv.row + neighbors[j].row;
2110 this_col_offset = ref_mv->as_mv.col + neighbors[j].col; 2061 this_col_offset = ref_mv->as_mv.col + neighbors[j].col;
2111 2062
2112 if ((this_col_offset > x->mv_col_min) && 2063 if ((this_col_offset > x->mv_col_min) &&
2113 (this_col_offset < x->mv_col_max) && 2064 (this_col_offset < x->mv_col_max) &&
2114 (this_row_offset > x->mv_row_min) && 2065 (this_row_offset > x->mv_row_min) &&
2115 (this_row_offset < x->mv_row_max)) { 2066 (this_row_offset < x->mv_row_max)) {
2116 check_here = (neighbors[j].row) * in_what_stride + neighbors[j].col + 2067 check_here = (neighbors[j].row) * in_what_stride + neighbors[j].col +
2117 best_address; 2068 best_address;
2118 2069
2119 /* Get compound block and use it to calculate SAD. */ 2070 /* Get compound block and use it to calculate SAD. */
2120 thissad = fn_ptr->sdaf(what, what_stride, check_here, in_what_stride, 2071 thissad = fn_ptr->sdaf(what, what_stride, check_here, in_what_stride,
2121 second_pred, bestsad); 2072 second_pred, bestsad);
2122 2073
2123 if (thissad < bestsad) { 2074 if (thissad < bestsad) {
2124 this_mv.as_mv.row = this_row_offset; 2075 this_mv.as_mv.row = this_row_offset;
2125 this_mv.as_mv.col = this_col_offset; 2076 this_mv.as_mv.col = this_col_offset;
2126 thissad += mvsad_err_cost(&this_mv, &fcenter_mv, mvjsadcost, 2077 thissad += mvsad_err_cost(&this_mv.as_mv, &fcenter_mv.as_mv,
2127 mvsadcost, error_per_bit); 2078 mvjsadcost, mvsadcost, error_per_bit);
2128
2129 if (thissad < bestsad) { 2079 if (thissad < bestsad) {
2130 bestsad = thissad; 2080 bestsad = thissad;
2131 best_site = j; 2081 best_site = j;
2132 } 2082 }
2133 } 2083 }
2134 } 2084 }
2135 } 2085 }
2136 2086
2137 if (best_site == -1) { 2087 if (best_site == -1) {
2138 break; 2088 break;
2139 } else { 2089 } else {
2140 ref_mv->as_mv.row += neighbors[best_site].row; 2090 ref_mv->as_mv.row += neighbors[best_site].row;
2141 ref_mv->as_mv.col += neighbors[best_site].col; 2091 ref_mv->as_mv.col += neighbors[best_site].col;
2142 best_address += (neighbors[best_site].row) * in_what_stride + 2092 best_address += (neighbors[best_site].row) * in_what_stride +
2143 neighbors[best_site].col; 2093 neighbors[best_site].col;
2144 } 2094 }
2145 } 2095 }
2146 2096
2147 this_mv.as_mv.row = ref_mv->as_mv.row << 3; 2097 this_mv.as_mv.row = ref_mv->as_mv.row * 8;
2148 this_mv.as_mv.col = ref_mv->as_mv.col << 3; 2098 this_mv.as_mv.col = ref_mv->as_mv.col * 8;
2149 2099
2150 if (bestsad < INT_MAX) { 2100 if (bestsad < INT_MAX) {
2151 // FIXME(rbultje, yunqing): add full-pixel averaging variance functions 2101 // FIXME(rbultje, yunqing): add full-pixel averaging variance functions
2152 // so we don't have to use the subpixel with xoff=0,yoff=0 here. 2102 // so we don't have to use the subpixel with xoff=0,yoff=0 here.
2153 return fn_ptr->svaf(best_address, in_what_stride, 0, 0, 2103 return fn_ptr->svaf(best_address, in_what_stride, 0, 0, what, what_stride,
2154 what, what_stride, (unsigned int *)(&thissad), 2104 (unsigned int *)(&thissad), second_pred) +
2155 second_pred) + 2105 mv_err_cost(&this_mv.as_mv, &center_mv->as_mv,
2156 mv_err_cost(&this_mv, center_mv, mvjcost, mvcost, x->errorperbit); 2106 mvjcost, mvcost, x->errorperbit);
2157 } else { 2107 } else {
2158 return INT_MAX; 2108 return INT_MAX;
2159 } 2109 }
2160 } 2110 }
OLDNEW
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_mcomp.h ('k') | source/libvpx/vp9/encoder/vp9_modecosts.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698