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

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

Issue 11555023: libvpx: Add VP9 decoder. (Closed) Base URL: svn://chrome-svn/chrome/trunk/deps/third_party/libvpx/
Patch Set: Created 8 years 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
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11
12 #include "vp9/common/vp9_common.h"
13 #include "vp9/encoder/vp9_encodemv.h"
14 #include "vp9/common/vp9_entropymode.h"
15 #include "vp9/common/vp9_systemdependent.h"
16
17 #include <math.h>
18
19 #ifdef ENTROPY_STATS
20 extern unsigned int active_section;
21 #endif
22
23 #ifdef NMV_STATS
24 nmv_context_counts tnmvcounts;
25 #endif
26
27 static void encode_nmv_component(vp9_writer* const bc,
28 int v,
29 int r,
30 const nmv_component* const mvcomp) {
31 int s, z, c, o, d;
32 assert (v != 0); /* should not be zero */
33 s = v < 0;
34 vp9_write(bc, s, mvcomp->sign);
35 z = (s ? -v : v) - 1; /* magnitude - 1 */
36
37 c = vp9_get_mv_class(z, &o);
38
39 write_token(bc, vp9_mv_class_tree, mvcomp->classes,
40 vp9_mv_class_encodings + c);
41
42 d = (o >> 3); /* int mv data */
43
44 if (c == MV_CLASS_0) {
45 write_token(bc, vp9_mv_class0_tree, mvcomp->class0,
46 vp9_mv_class0_encodings + d);
47 } else {
48 int i, b;
49 b = c + CLASS0_BITS - 1; /* number of bits */
50 for (i = 0; i < b; ++i)
51 vp9_write(bc, ((d >> i) & 1), mvcomp->bits[i]);
52 }
53 }
54
55 static void encode_nmv_component_fp(vp9_writer *bc,
56 int v,
57 int r,
58 const nmv_component* const mvcomp,
59 int usehp) {
60 int s, z, c, o, d, f, e;
61 assert (v != 0); /* should not be zero */
62 s = v < 0;
63 z = (s ? -v : v) - 1; /* magnitude - 1 */
64
65 c = vp9_get_mv_class(z, &o);
66
67 d = (o >> 3); /* int mv data */
68 f = (o >> 1) & 3; /* fractional pel mv data */
69 e = (o & 1); /* high precision mv data */
70
71 /* Code the fractional pel bits */
72 if (c == MV_CLASS_0) {
73 write_token(bc, vp9_mv_fp_tree, mvcomp->class0_fp[d],
74 vp9_mv_fp_encodings + f);
75 } else {
76 write_token(bc, vp9_mv_fp_tree, mvcomp->fp,
77 vp9_mv_fp_encodings + f);
78 }
79 /* Code the high precision bit */
80 if (usehp) {
81 if (c == MV_CLASS_0) {
82 vp9_write(bc, e, mvcomp->class0_hp);
83 } else {
84 vp9_write(bc, e, mvcomp->hp);
85 }
86 }
87 }
88
89 static void build_nmv_component_cost_table(int *mvcost,
90 const nmv_component* const mvcomp,
91 int usehp) {
92 int i, v;
93 int sign_cost[2], class_cost[MV_CLASSES], class0_cost[CLASS0_SIZE];
94 int bits_cost[MV_OFFSET_BITS][2];
95 int class0_fp_cost[CLASS0_SIZE][4], fp_cost[4];
96 int class0_hp_cost[2], hp_cost[2];
97
98 sign_cost[0] = vp9_cost_zero(mvcomp->sign);
99 sign_cost[1] = vp9_cost_one(mvcomp->sign);
100 vp9_cost_tokens(class_cost, mvcomp->classes, vp9_mv_class_tree);
101 vp9_cost_tokens(class0_cost, mvcomp->class0, vp9_mv_class0_tree);
102 for (i = 0; i < MV_OFFSET_BITS; ++i) {
103 bits_cost[i][0] = vp9_cost_zero(mvcomp->bits[i]);
104 bits_cost[i][1] = vp9_cost_one(mvcomp->bits[i]);
105 }
106
107 for (i = 0; i < CLASS0_SIZE; ++i)
108 vp9_cost_tokens(class0_fp_cost[i], mvcomp->class0_fp[i], vp9_mv_fp_tree);
109 vp9_cost_tokens(fp_cost, mvcomp->fp, vp9_mv_fp_tree);
110
111 if (usehp) {
112 class0_hp_cost[0] = vp9_cost_zero(mvcomp->class0_hp);
113 class0_hp_cost[1] = vp9_cost_one(mvcomp->class0_hp);
114 hp_cost[0] = vp9_cost_zero(mvcomp->hp);
115 hp_cost[1] = vp9_cost_one(mvcomp->hp);
116 }
117 mvcost[0] = 0;
118 for (v = 1; v <= MV_MAX; ++v) {
119 int z, c, o, d, e, f, cost = 0;
120 z = v - 1;
121 c = vp9_get_mv_class(z, &o);
122 cost += class_cost[c];
123 d = (o >> 3); /* int mv data */
124 f = (o >> 1) & 3; /* fractional pel mv data */
125 e = (o & 1); /* high precision mv data */
126 if (c == MV_CLASS_0) {
127 cost += class0_cost[d];
128 } else {
129 int i, b;
130 b = c + CLASS0_BITS - 1; /* number of bits */
131 for (i = 0; i < b; ++i)
132 cost += bits_cost[i][((d >> i) & 1)];
133 }
134 if (c == MV_CLASS_0) {
135 cost += class0_fp_cost[d][f];
136 } else {
137 cost += fp_cost[f];
138 }
139 if (usehp) {
140 if (c == MV_CLASS_0) {
141 cost += class0_hp_cost[e];
142 } else {
143 cost += hp_cost[e];
144 }
145 }
146 mvcost[v] = cost + sign_cost[0];
147 mvcost[-v] = cost + sign_cost[1];
148 }
149 }
150
151 static int update_nmv_savings(const unsigned int ct[2],
152 const vp9_prob cur_p,
153 const vp9_prob new_p,
154 const vp9_prob upd_p) {
155
156 #ifdef LOW_PRECISION_MV_UPDATE
157 vp9_prob mod_p = new_p | 1;
158 #else
159 vp9_prob mod_p = new_p;
160 #endif
161 const int cur_b = cost_branch256(ct, cur_p);
162 const int mod_b = cost_branch256(ct, mod_p);
163 const int cost = 7 * 256 +
164 #ifndef LOW_PRECISION_MV_UPDATE
165 256 +
166 #endif
167 (vp9_cost_one(upd_p) - vp9_cost_zero(upd_p));
168 if (cur_b - mod_b - cost > 0) {
169 return cur_b - mod_b - cost;
170 } else {
171 return 0 - vp9_cost_zero(upd_p);
172 }
173 }
174
175 static int update_nmv(
176 vp9_writer *const bc,
177 const unsigned int ct[2],
178 vp9_prob *const cur_p,
179 const vp9_prob new_p,
180 const vp9_prob upd_p) {
181
182 #ifdef LOW_PRECISION_MV_UPDATE
183 vp9_prob mod_p = new_p | 1;
184 #else
185 vp9_prob mod_p = new_p;
186 #endif
187
188 const int cur_b = cost_branch256(ct, *cur_p);
189 const int mod_b = cost_branch256(ct, mod_p);
190 const int cost = 7 * 256 +
191 #ifndef LOW_PRECISION_MV_UPDATE
192 256 +
193 #endif
194 (vp9_cost_one(upd_p) - vp9_cost_zero(upd_p));
195
196 if (cur_b - mod_b > cost) {
197 *cur_p = mod_p;
198 vp9_write(bc, 1, upd_p);
199 #ifdef LOW_PRECISION_MV_UPDATE
200 vp9_write_literal(bc, mod_p >> 1, 7);
201 #else
202 vp9_write_literal(bc, mod_p, 8);
203 #endif
204 return 1;
205 } else {
206 vp9_write(bc, 0, upd_p);
207 return 0;
208 }
209 }
210
211 void print_nmvcounts(nmv_context_counts tnmvcounts) {
212 int i, j, k;
213 printf("\nCounts =\n { ");
214 for (j = 0; j < MV_JOINTS; ++j)
215 printf("%d, ", tnmvcounts.joints[j]);
216 printf("},\n");
217 for (i = 0; i < 2; ++i) {
218 printf(" {\n");
219 printf(" %d/%d,\n", tnmvcounts.comps[i].sign[0],
220 tnmvcounts.comps[i].sign[1]);
221 printf(" { ");
222 for (j = 0; j < MV_CLASSES; ++j)
223 printf("%d, ", tnmvcounts.comps[i].classes[j]);
224 printf("},\n");
225 printf(" { ");
226 for (j = 0; j < CLASS0_SIZE; ++j)
227 printf("%d, ", tnmvcounts.comps[i].class0[j]);
228 printf("},\n");
229 printf(" { ");
230 for (j = 0; j < MV_OFFSET_BITS; ++j)
231 printf("%d/%d, ", tnmvcounts.comps[i].bits[j][0],
232 tnmvcounts.comps[i].bits[j][1]);
233 printf("},\n");
234
235 printf(" {");
236 for (j = 0; j < CLASS0_SIZE; ++j) {
237 printf("{");
238 for (k = 0; k < 4; ++k)
239 printf("%d, ", tnmvcounts.comps[i].class0_fp[j][k]);
240 printf("}, ");
241 }
242 printf("},\n");
243
244 printf(" { ");
245 for (j = 0; j < 4; ++j)
246 printf("%d, ", tnmvcounts.comps[i].fp[j]);
247 printf("},\n");
248
249 printf(" %d/%d,\n",
250 tnmvcounts.comps[i].class0_hp[0],
251 tnmvcounts.comps[i].class0_hp[1]);
252 printf(" %d/%d,\n",
253 tnmvcounts.comps[i].hp[0],
254 tnmvcounts.comps[i].hp[1]);
255 printf(" },\n");
256 }
257 }
258
259 #ifdef NMV_STATS
260 void init_nmvstats() {
261 vp9_zero(tnmvcounts);
262 }
263
264 void print_nmvstats() {
265 nmv_context prob;
266 unsigned int branch_ct_joint[MV_JOINTS - 1][2];
267 unsigned int branch_ct_sign[2][2];
268 unsigned int branch_ct_classes[2][MV_CLASSES - 1][2];
269 unsigned int branch_ct_class0[2][CLASS0_SIZE - 1][2];
270 unsigned int branch_ct_bits[2][MV_OFFSET_BITS][2];
271 unsigned int branch_ct_class0_fp[2][CLASS0_SIZE][4 - 1][2];
272 unsigned int branch_ct_fp[2][4 - 1][2];
273 unsigned int branch_ct_class0_hp[2][2];
274 unsigned int branch_ct_hp[2][2];
275 int i, j, k;
276 vp9_counts_to_nmv_context(&tnmvcounts, &prob, 1,
277 branch_ct_joint, branch_ct_sign, branch_ct_classes,
278 branch_ct_class0, branch_ct_bits,
279 branch_ct_class0_fp, branch_ct_fp,
280 branch_ct_class0_hp, branch_ct_hp);
281
282 printf("\nCounts =\n { ");
283 for (j = 0; j < MV_JOINTS; ++j)
284 printf("%d, ", tnmvcounts.joints[j]);
285 printf("},\n");
286 for (i = 0; i < 2; ++i) {
287 printf(" {\n");
288 printf(" %d/%d,\n", tnmvcounts.comps[i].sign[0],
289 tnmvcounts.comps[i].sign[1]);
290 printf(" { ");
291 for (j = 0; j < MV_CLASSES; ++j)
292 printf("%d, ", tnmvcounts.comps[i].classes[j]);
293 printf("},\n");
294 printf(" { ");
295 for (j = 0; j < CLASS0_SIZE; ++j)
296 printf("%d, ", tnmvcounts.comps[i].class0[j]);
297 printf("},\n");
298 printf(" { ");
299 for (j = 0; j < MV_OFFSET_BITS; ++j)
300 printf("%d/%d, ", tnmvcounts.comps[i].bits[j][0],
301 tnmvcounts.comps[i].bits[j][1]);
302 printf("},\n");
303
304 printf(" {");
305 for (j = 0; j < CLASS0_SIZE; ++j) {
306 printf("{");
307 for (k = 0; k < 4; ++k)
308 printf("%d, ", tnmvcounts.comps[i].class0_fp[j][k]);
309 printf("}, ");
310 }
311 printf("},\n");
312
313 printf(" { ");
314 for (j = 0; j < 4; ++j)
315 printf("%d, ", tnmvcounts.comps[i].fp[j]);
316 printf("},\n");
317
318 printf(" %d/%d,\n",
319 tnmvcounts.comps[i].class0_hp[0],
320 tnmvcounts.comps[i].class0_hp[1]);
321 printf(" %d/%d,\n",
322 tnmvcounts.comps[i].hp[0],
323 tnmvcounts.comps[i].hp[1]);
324 printf(" },\n");
325 }
326
327 printf("\nProbs =\n { ");
328 for (j = 0; j < MV_JOINTS - 1; ++j)
329 printf("%d, ", prob.joints[j]);
330 printf("},\n");
331 for (i=0; i< 2; ++i) {
332 printf(" {\n");
333 printf(" %d,\n", prob.comps[i].sign);
334 printf(" { ");
335 for (j = 0; j < MV_CLASSES - 1; ++j)
336 printf("%d, ", prob.comps[i].classes[j]);
337 printf("},\n");
338 printf(" { ");
339 for (j = 0; j < CLASS0_SIZE - 1; ++j)
340 printf("%d, ", prob.comps[i].class0[j]);
341 printf("},\n");
342 printf(" { ");
343 for (j = 0; j < MV_OFFSET_BITS; ++j)
344 printf("%d, ", prob.comps[i].bits[j]);
345 printf("},\n");
346 printf(" { ");
347 for (j = 0; j < CLASS0_SIZE; ++j) {
348 printf("{");
349 for (k = 0; k < 3; ++k)
350 printf("%d, ", prob.comps[i].class0_fp[j][k]);
351 printf("}, ");
352 }
353 printf("},\n");
354 printf(" { ");
355 for (j = 0; j < 3; ++j)
356 printf("%d, ", prob.comps[i].fp[j]);
357 printf("},\n");
358
359 printf(" %d,\n", prob.comps[i].class0_hp);
360 printf(" %d,\n", prob.comps[i].hp);
361 printf(" },\n");
362 }
363 }
364
365 static void add_nmvcount(nmv_context_counts* const dst,
366 const nmv_context_counts* const src) {
367 int i, j, k;
368 for (j = 0; j < MV_JOINTS; ++j) {
369 dst->joints[j] += src->joints[j];
370 }
371 for (i = 0; i < 2; ++i) {
372 for (j = 0; j < MV_VALS; ++j) {
373 dst->comps[i].mvcount[j] += src->comps[i].mvcount[j];
374 }
375 dst->comps[i].sign[0] += src->comps[i].sign[0];
376 dst->comps[i].sign[1] += src->comps[i].sign[1];
377 for (j = 0; j < MV_CLASSES; ++j) {
378 dst->comps[i].classes[j] += src->comps[i].classes[j];
379 }
380 for (j = 0; j < CLASS0_SIZE; ++j) {
381 dst->comps[i].class0[j] += src->comps[i].class0[j];
382 }
383 for (j = 0; j < MV_OFFSET_BITS; ++j) {
384 dst->comps[i].bits[j][0] += src->comps[i].bits[j][0];
385 dst->comps[i].bits[j][1] += src->comps[i].bits[j][1];
386 }
387 }
388 for (i = 0; i < 2; ++i) {
389 for (j = 0; j < CLASS0_SIZE; ++j) {
390 for (k = 0; k < 4; ++k) {
391 dst->comps[i].class0_fp[j][k] += src->comps[i].class0_fp[j][k];
392 }
393 }
394 for (j = 0; j < 4; ++j) {
395 dst->comps[i].fp[j] += src->comps[i].fp[j];
396 }
397 dst->comps[i].class0_hp[0] += src->comps[i].class0_hp[0];
398 dst->comps[i].class0_hp[1] += src->comps[i].class0_hp[1];
399 dst->comps[i].hp[0] += src->comps[i].hp[0];
400 dst->comps[i].hp[1] += src->comps[i].hp[1];
401 }
402 }
403 #endif
404
405 void vp9_write_nmv_probs(VP9_COMP* const cpi, int usehp, vp9_writer* const bc) {
406 int i, j;
407 nmv_context prob;
408 unsigned int branch_ct_joint[MV_JOINTS - 1][2];
409 unsigned int branch_ct_sign[2][2];
410 unsigned int branch_ct_classes[2][MV_CLASSES - 1][2];
411 unsigned int branch_ct_class0[2][CLASS0_SIZE - 1][2];
412 unsigned int branch_ct_bits[2][MV_OFFSET_BITS][2];
413 unsigned int branch_ct_class0_fp[2][CLASS0_SIZE][4 - 1][2];
414 unsigned int branch_ct_fp[2][4 - 1][2];
415 unsigned int branch_ct_class0_hp[2][2];
416 unsigned int branch_ct_hp[2][2];
417 #ifdef MV_GROUP_UPDATE
418 int savings = 0;
419 #endif
420
421 #ifdef NMV_STATS
422 if (!cpi->dummy_packing)
423 add_nmvcount(&tnmvcounts, &cpi->NMVcount);
424 #endif
425 vp9_counts_to_nmv_context(&cpi->NMVcount, &prob, usehp,
426 branch_ct_joint, branch_ct_sign, branch_ct_classes,
427 branch_ct_class0, branch_ct_bits,
428 branch_ct_class0_fp, branch_ct_fp,
429 branch_ct_class0_hp, branch_ct_hp);
430 /* write updates if they help */
431 #ifdef MV_GROUP_UPDATE
432 for (j = 0; j < MV_JOINTS - 1; ++j) {
433 savings += update_nmv_savings(branch_ct_joint[j],
434 cpi->common.fc.nmvc.joints[j],
435 prob.joints[j],
436 VP9_NMV_UPDATE_PROB);
437 }
438 for (i = 0; i < 2; ++i) {
439 savings += update_nmv_savings(branch_ct_sign[i],
440 cpi->common.fc.nmvc.comps[i].sign,
441 prob.comps[i].sign,
442 VP9_NMV_UPDATE_PROB);
443 for (j = 0; j < MV_CLASSES - 1; ++j) {
444 savings += update_nmv_savings(branch_ct_classes[i][j],
445 cpi->common.fc.nmvc.comps[i].classes[j],
446 prob.comps[i].classes[j],
447 VP9_NMV_UPDATE_PROB);
448 }
449 for (j = 0; j < CLASS0_SIZE - 1; ++j) {
450 savings += update_nmv_savings(branch_ct_class0[i][j],
451 cpi->common.fc.nmvc.comps[i].class0[j],
452 prob.comps[i].class0[j],
453 VP9_NMV_UPDATE_PROB);
454 }
455 for (j = 0; j < MV_OFFSET_BITS; ++j) {
456 savings += update_nmv_savings(branch_ct_bits[i][j],
457 cpi->common.fc.nmvc.comps[i].bits[j],
458 prob.comps[i].bits[j],
459 VP9_NMV_UPDATE_PROB);
460 }
461 }
462 for (i = 0; i < 2; ++i) {
463 for (j = 0; j < CLASS0_SIZE; ++j) {
464 int k;
465 for (k = 0; k < 3; ++k) {
466 savings += update_nmv_savings(branch_ct_class0_fp[i][j][k],
467 cpi->common.fc.nmvc.comps[i].class0_fp[j][ k],
468 prob.comps[i].class0_fp[j][k],
469 VP9_NMV_UPDATE_PROB);
470 }
471 }
472 for (j = 0; j < 3; ++j) {
473 savings += update_nmv_savings(branch_ct_fp[i][j],
474 cpi->common.fc.nmvc.comps[i].fp[j],
475 prob.comps[i].fp[j],
476 VP9_NMV_UPDATE_PROB);
477 }
478 }
479 if (usehp) {
480 for (i = 0; i < 2; ++i) {
481 savings += update_nmv_savings(branch_ct_class0_hp[i],
482 cpi->common.fc.nmvc.comps[i].class0_hp,
483 prob.comps[i].class0_hp,
484 VP9_NMV_UPDATE_PROB);
485 savings += update_nmv_savings(branch_ct_hp[i],
486 cpi->common.fc.nmvc.comps[i].hp,
487 prob.comps[i].hp,
488 VP9_NMV_UPDATE_PROB);
489 }
490 }
491 if (savings <= 0) {
492 vp9_write_bit(bc, 0);
493 return;
494 }
495 vp9_write_bit(bc, 1);
496 #endif
497
498 for (j = 0; j < MV_JOINTS - 1; ++j) {
499 update_nmv(bc, branch_ct_joint[j],
500 &cpi->common.fc.nmvc.joints[j],
501 prob.joints[j],
502 VP9_NMV_UPDATE_PROB);
503 }
504 for (i = 0; i < 2; ++i) {
505 update_nmv(bc, branch_ct_sign[i],
506 &cpi->common.fc.nmvc.comps[i].sign,
507 prob.comps[i].sign,
508 VP9_NMV_UPDATE_PROB);
509 for (j = 0; j < MV_CLASSES - 1; ++j) {
510 update_nmv(bc, branch_ct_classes[i][j],
511 &cpi->common.fc.nmvc.comps[i].classes[j],
512 prob.comps[i].classes[j],
513 VP9_NMV_UPDATE_PROB);
514 }
515 for (j = 0; j < CLASS0_SIZE - 1; ++j) {
516 update_nmv(bc, branch_ct_class0[i][j],
517 &cpi->common.fc.nmvc.comps[i].class0[j],
518 prob.comps[i].class0[j],
519 VP9_NMV_UPDATE_PROB);
520 }
521 for (j = 0; j < MV_OFFSET_BITS; ++j) {
522 update_nmv(bc, branch_ct_bits[i][j],
523 &cpi->common.fc.nmvc.comps[i].bits[j],
524 prob.comps[i].bits[j],
525 VP9_NMV_UPDATE_PROB);
526 }
527 }
528 for (i = 0; i < 2; ++i) {
529 for (j = 0; j < CLASS0_SIZE; ++j) {
530 int k;
531 for (k = 0; k < 3; ++k) {
532 update_nmv(bc, branch_ct_class0_fp[i][j][k],
533 &cpi->common.fc.nmvc.comps[i].class0_fp[j][k],
534 prob.comps[i].class0_fp[j][k],
535 VP9_NMV_UPDATE_PROB);
536 }
537 }
538 for (j = 0; j < 3; ++j) {
539 update_nmv(bc, branch_ct_fp[i][j],
540 &cpi->common.fc.nmvc.comps[i].fp[j],
541 prob.comps[i].fp[j],
542 VP9_NMV_UPDATE_PROB);
543 }
544 }
545 if (usehp) {
546 for (i = 0; i < 2; ++i) {
547 update_nmv(bc, branch_ct_class0_hp[i],
548 &cpi->common.fc.nmvc.comps[i].class0_hp,
549 prob.comps[i].class0_hp,
550 VP9_NMV_UPDATE_PROB);
551 update_nmv(bc, branch_ct_hp[i],
552 &cpi->common.fc.nmvc.comps[i].hp,
553 prob.comps[i].hp,
554 VP9_NMV_UPDATE_PROB);
555 }
556 }
557 }
558
559 void vp9_encode_nmv(vp9_writer* const bc, const MV* const mv,
560 const MV* const ref, const nmv_context* const mvctx) {
561 MV_JOINT_TYPE j = vp9_get_mv_joint(*mv);
562 write_token(bc, vp9_mv_joint_tree, mvctx->joints,
563 vp9_mv_joint_encodings + j);
564 if (j == MV_JOINT_HZVNZ || j == MV_JOINT_HNZVNZ) {
565 encode_nmv_component(bc, mv->row, ref->col, &mvctx->comps[0]);
566 }
567 if (j == MV_JOINT_HNZVZ || j == MV_JOINT_HNZVNZ) {
568 encode_nmv_component(bc, mv->col, ref->col, &mvctx->comps[1]);
569 }
570 }
571
572 void vp9_encode_nmv_fp(vp9_writer* const bc, const MV* const mv,
573 const MV* const ref, const nmv_context* const mvctx,
574 int usehp) {
575 MV_JOINT_TYPE j = vp9_get_mv_joint(*mv);
576 usehp = usehp && vp9_use_nmv_hp(ref);
577 if (j == MV_JOINT_HZVNZ || j == MV_JOINT_HNZVNZ) {
578 encode_nmv_component_fp(bc, mv->row, ref->row, &mvctx->comps[0], usehp);
579 }
580 if (j == MV_JOINT_HNZVZ || j == MV_JOINT_HNZVNZ) {
581 encode_nmv_component_fp(bc, mv->col, ref->col, &mvctx->comps[1], usehp);
582 }
583 }
584
585 void vp9_build_nmv_cost_table(int *mvjoint,
586 int *mvcost[2],
587 const nmv_context* const mvctx,
588 int usehp,
589 int mvc_flag_v,
590 int mvc_flag_h) {
591 vp9_clear_system_state();
592 vp9_cost_tokens(mvjoint, mvctx->joints, vp9_mv_joint_tree);
593 if (mvc_flag_v)
594 build_nmv_component_cost_table(mvcost[0], &mvctx->comps[0], usehp);
595 if (mvc_flag_h)
596 build_nmv_component_cost_table(mvcost[1], &mvctx->comps[1], usehp);
597 }
598
599 void vp9_update_nmv_count(VP9_COMP *cpi, MACROBLOCK *x,
600 int_mv *best_ref_mv, int_mv *second_best_ref_mv) {
601 MB_MODE_INFO * mbmi = &x->e_mbd.mode_info_context->mbmi;
602 MV mv;
603
604 if (mbmi->mode == SPLITMV) {
605 int i;
606
607 for (i = 0; i < x->partition_info->count; i++) {
608 if (x->partition_info->bmi[i].mode == NEW4X4) {
609 if (x->e_mbd.allow_high_precision_mv) {
610 mv.row = (x->partition_info->bmi[i].mv.as_mv.row
611 - best_ref_mv->as_mv.row);
612 mv.col = (x->partition_info->bmi[i].mv.as_mv.col
613 - best_ref_mv->as_mv.col);
614 vp9_increment_nmv(&mv, &best_ref_mv->as_mv, &cpi->NMVcount, 1);
615 if (x->e_mbd.mode_info_context->mbmi.second_ref_frame > 0) {
616 mv.row = (x->partition_info->bmi[i].second_mv.as_mv.row
617 - second_best_ref_mv->as_mv.row);
618 mv.col = (x->partition_info->bmi[i].second_mv.as_mv.col
619 - second_best_ref_mv->as_mv.col);
620 vp9_increment_nmv(&mv, &second_best_ref_mv->as_mv,
621 &cpi->NMVcount, 1);
622 }
623 } else {
624 mv.row = (x->partition_info->bmi[i].mv.as_mv.row
625 - best_ref_mv->as_mv.row);
626 mv.col = (x->partition_info->bmi[i].mv.as_mv.col
627 - best_ref_mv->as_mv.col);
628 vp9_increment_nmv(&mv, &best_ref_mv->as_mv, &cpi->NMVcount, 0);
629 if (x->e_mbd.mode_info_context->mbmi.second_ref_frame > 0) {
630 mv.row = (x->partition_info->bmi[i].second_mv.as_mv.row
631 - second_best_ref_mv->as_mv.row);
632 mv.col = (x->partition_info->bmi[i].second_mv.as_mv.col
633 - second_best_ref_mv->as_mv.col);
634 vp9_increment_nmv(&mv, &second_best_ref_mv->as_mv,
635 &cpi->NMVcount, 0);
636 }
637 }
638 }
639 }
640 } else if (mbmi->mode == NEWMV) {
641 if (x->e_mbd.allow_high_precision_mv) {
642 mv.row = (mbmi->mv[0].as_mv.row - best_ref_mv->as_mv.row);
643 mv.col = (mbmi->mv[0].as_mv.col - best_ref_mv->as_mv.col);
644 vp9_increment_nmv(&mv, &best_ref_mv->as_mv, &cpi->NMVcount, 1);
645 if (mbmi->second_ref_frame > 0) {
646 mv.row = (mbmi->mv[1].as_mv.row - second_best_ref_mv->as_mv.row);
647 mv.col = (mbmi->mv[1].as_mv.col - second_best_ref_mv->as_mv.col);
648 vp9_increment_nmv(&mv, &second_best_ref_mv->as_mv, &cpi->NMVcount, 1);
649 }
650 } else {
651 mv.row = (mbmi->mv[0].as_mv.row - best_ref_mv->as_mv.row);
652 mv.col = (mbmi->mv[0].as_mv.col - best_ref_mv->as_mv.col);
653 vp9_increment_nmv(&mv, &best_ref_mv->as_mv, &cpi->NMVcount, 0);
654 if (mbmi->second_ref_frame > 0) {
655 mv.row = (mbmi->mv[1].as_mv.row - second_best_ref_mv->as_mv.row);
656 mv.col = (mbmi->mv[1].as_mv.col - second_best_ref_mv->as_mv.col);
657 vp9_increment_nmv(&mv, &second_best_ref_mv->as_mv, &cpi->NMVcount, 0);
658 }
659 }
660 }
661 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698