83 0x0, 0x8, 0x0, 0x8, 0xc, 0x8, 0xc, 0xe, 0xc, 0xe, 0xf, 0xe, 0xf
86 0x0, 0x0, 0x8, 0x8, 0x8, 0xc, 0xc, 0xc, 0xe, 0xe, 0xe, 0xf, 0xf
88 static const uint8_t max_tx_for_bl_bp[
N_BS_SIZES] = {
94 int row = td->
row, col = td->
col, row7 = td->
row7;
95 enum TxfmMode max_tx = max_tx_for_bl_bp[
b->bs];
101 if (!
s->s.h.segmentation.enabled) {
103 }
else if (
s->s.h.keyframe ||
s->s.h.intraonly) {
104 b->seg_id = !
s->s.h.segmentation.update_map ? 0 :
106 s->s.h.segmentation.prob);
107 }
else if (!
s->s.h.segmentation.update_map ||
108 (
s->s.h.segmentation.temporal &&
110 s->s.h.segmentation.pred_prob[
s->above_segpred_ctx[col] +
118 for (y = 0; y < h4; y++) {
119 int idx_base = (y + row) * 8 *
s->sb_cols + col;
120 for (x = 0; x < w4; x++)
129 memset(&
s->above_segpred_ctx[col], 1, w4);
133 s->s.h.segmentation.prob);
135 memset(&
s->above_segpred_ctx[col], 0, w4);
138 if (
s->s.h.segmentation.enabled &&
139 (
s->s.h.segmentation.update_map ||
s->s.h.keyframe ||
s->s.h.intraonly)) {
141 bw4, bh4, 8 *
s->sb_cols,
b->seg_id);
144 b->skip =
s->s.h.segmentation.enabled &&
145 s->s.h.segmentation.feat[
b->seg_id].skip_enabled;
152 if (
s->s.h.keyframe ||
s->s.h.intraonly) {
154 }
else if (
s->s.h.segmentation.enabled &&
s->s.h.segmentation.feat[
b->seg_id].ref_enabled) {
155 b->intra = !
s->s.h.segmentation.feat[
b->seg_id].ref_val;
159 if (have_a && have_l) {
163 c = have_a ? 2 *
s->above_intra_ctx[col] :
175 c = (
s->above_skip_ctx[col] ? max_tx :
176 s->above_txfm_ctx[col]) +
180 c =
s->above_skip_ctx[col] ? 1 :
181 (
s->above_txfm_ctx[col] * 2 > max_tx);
214 b->tx =
FFMIN(max_tx,
s->s.h.txfmmode);
217 if (
s->s.h.keyframe ||
s->s.h.intraonly) {
218 uint8_t *
a = &
s->above_mode_ctx[col * 2];
237 b->mode[1] =
b->mode[0];
251 b->mode[3] =
b->mode[2];
254 b->mode[2] =
b->mode[0];
257 b->mode[3] =
b->mode[1];
264 b->mode[1] =
b->mode[0];
271 }
else if (
b->intra) {
275 s->prob.p.y_mode[0]);
279 s->prob.p.y_mode[0]);
282 b->mode[1] =
b->mode[0];
286 s->prob.p.y_mode[0]);
290 s->prob.p.y_mode[0]);
293 b->mode[3] =
b->mode[2];
296 b->mode[2] =
b->mode[0];
297 b->mode[3] =
b->mode[1];
300 static const uint8_t size_group[10] = {
301 3, 3, 3, 3, 2, 2, 2, 1, 1, 1
303 int sz = size_group[
b->bs];
306 s->prob.p.y_mode[sz]);
309 b->mode[3] =
b->mode[0];
313 s->prob.p.uv_mode[
b->mode[3]]);
316 static const uint8_t inter_mode_ctx_lut[14][14] = {
317 { 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5 },
318 { 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5 },
319 { 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5 },
320 { 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5 },
321 { 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5 },
322 { 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5 },
323 { 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5 },
324 { 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5 },
325 { 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5 },
326 { 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5 },
327 { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 2, 2, 1, 3 },
328 { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 2, 2, 1, 3 },
329 { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 1, 1, 0, 3 },
330 { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 3, 3, 3, 4 },
333 if (
s->s.h.segmentation.enabled &&
s->s.h.segmentation.feat[
b->seg_id].ref_enabled) {
334 av_assert2(
s->s.h.segmentation.feat[
b->seg_id].ref_val != 0);
336 b->ref[0] =
s->s.h.segmentation.feat[
b->seg_id].ref_val - 1;
349 }
else if (
s->above_comp_ctx[col]) {
353 c = 2 + (
s->above_intra_ctx[col] ||
354 s->above_ref_ctx[col] ==
s->s.h.fixcompref);
356 c = (!
s->above_intra_ctx[col] &&
357 s->above_ref_ctx[col] ==
s->s.h.fixcompref) ^
362 c =
s->above_comp_ctx[col] ? 3 :
363 (!
s->above_intra_ctx[col] &&
s->above_ref_ctx[col] ==
s->s.h.fixcompref);
379 int fix_idx =
s->s.h.signbias[
s->s.h.fixcompref], var_idx = !fix_idx,
c,
bit;
381 b->ref[fix_idx] =
s->s.h.fixcompref;
385 if (
s->above_intra_ctx[col]) {
392 c = 1 + 2 * (
s->above_ref_ctx[col] !=
s->s.h.varcompref[1]);
394 int refl = td->
left_ref_ctx[row7], refa =
s->above_ref_ctx[col];
396 if (refl == refa && refa ==
s->s.h.varcompref[1]) {
399 if ((refa ==
s->s.h.fixcompref && refl ==
s->s.h.varcompref[0]) ||
400 (refl ==
s->s.h.fixcompref && refa ==
s->s.h.varcompref[0])) {
403 c = (refa == refl) ? 3 : 1;
406 if (refa ==
s->s.h.varcompref[1] && refl !=
s->s.h.varcompref[1]) {
409 c = (refl ==
s->s.h.varcompref[1] &&
410 refa !=
s->s.h.varcompref[1]) ? 2 : 4;
412 }
else if (!
s->above_comp_ctx[col]) {
413 if (refl ==
s->s.h.varcompref[1] && refa !=
s->s.h.varcompref[1]) {
416 c = (refa ==
s->s.h.varcompref[1] &&
417 refl !=
s->s.h.varcompref[1]) ? 2 : 4;
420 c = (refl == refa) ? 4 : 2;
424 if (
s->above_intra_ctx[col]) {
426 }
else if (
s->above_comp_ctx[col]) {
427 c = 4 * (
s->above_ref_ctx[col] !=
s->s.h.varcompref[1]);
429 c = 3 * (
s->above_ref_ctx[col] !=
s->s.h.varcompref[1]);
444 b->ref[var_idx] =
s->s.h.varcompref[
bit];
449 if (have_a && !
s->above_intra_ctx[col]) {
452 if (
s->above_comp_ctx[col]) {
454 !
s->above_ref_ctx[col]);
456 c = (3 * !
s->above_ref_ctx[col]) +
459 }
else if (
s->above_comp_ctx[col]) {
461 (!
s->s.h.fixcompref || !
s->above_ref_ctx[col]);
465 }
else if (
s->above_intra_ctx[col]) {
467 }
else if (
s->above_comp_ctx[col]) {
468 c = 1 + (!
s->s.h.fixcompref || !
s->above_ref_ctx[col]);
470 c = 4 * (!
s->above_ref_ctx[col]);
492 if (
s->above_intra_ctx[col]) {
494 }
else if (
s->above_comp_ctx[col]) {
495 c = 1 + 2 * (
s->s.h.fixcompref == 1 ||
496 s->above_ref_ctx[col] == 1);
497 }
else if (!
s->above_ref_ctx[col]) {
500 c = 4 * (
s->above_ref_ctx[col] == 1);
502 }
else if (
s->above_intra_ctx[col]) {
506 c = 1 + 2 * (
s->s.h.fixcompref == 1 ||
513 }
else if (
s->above_comp_ctx[col]) {
516 c = 3 * (
s->s.h.fixcompref == 1 ||
522 c = 1 + 2 * (
s->s.h.fixcompref == 1 ||
523 s->above_ref_ctx[col] == 1);
526 (
s->s.h.fixcompref == 1 ||
s->above_ref_ctx[col] == 1);
529 if (!
s->above_ref_ctx[col]) {
530 c = 1 + 2 * (
s->s.h.fixcompref == 1 ||
533 c = 3 * (
s->above_ref_ctx[col] == 1) +
536 }
else if (!
s->above_ref_ctx[col]) {
543 c = 4 * (
s->above_ref_ctx[col] == 1);
546 2 * (
s->above_ref_ctx[col] == 1);
549 if (
s->above_intra_ctx[col] ||
550 (!
s->above_comp_ctx[col] && !
s->above_ref_ctx[col])) {
552 }
else if (
s->above_comp_ctx[col]) {
553 c = 3 * (
s->s.h.fixcompref == 1 ||
s->above_ref_ctx[col] == 1);
555 c = 4 * (
s->above_ref_ctx[col] == 1);
578 if (
s->s.h.segmentation.enabled &&
s->s.h.segmentation.feat[
b->seg_id].skip_enabled) {
584 static const uint8_t off[10] = {
585 3, 0, 0, 1, 0, 0, 0, 0, 0, 0
590 int c = inter_mode_ctx_lut[
s->above_mode_ctx[col + off[
b->bs]]]
594 s->prob.p.mv_mode[
c]);
597 b->mode[3] =
b->mode[0];
605 if (have_a &&
s->above_mode_ctx[col] >=
NEARESTMV) {
610 c =
s->above_filter_ctx[col];
619 s->prob.p.filter[
c]);
623 b->filter =
s->s.h.filtermode;
627 int c = inter_mode_ctx_lut[
s->above_mode_ctx[col]][td->
left_mode_ctx[row7]];
630 s->prob.p.mv_mode[
c]);
636 s->prob.p.mv_mode[
c]);
640 b->mode[1] =
b->mode[0];
647 s->prob.p.mv_mode[
c]);
653 s->prob.p.mv_mode[
c]);
657 b->mode[3] =
b->mode[2];
662 b->mode[2] =
b->mode[0];
665 b->mode[3] =
b->mode[1];
679 vref =
b->ref[
b->comp ?
s->s.h.signbias[
s->s.h.varcompref[0]] : 0];
683#define SPLAT_CTX(var, val, n) \
685 case 1: var = val; break; \
686 case 2: AV_WN16A(&var, val * 0x0101); break; \
687 case 4: AV_WN32A(&var, val * 0x01010101); break; \
688 case 8: AV_WN64A(&var, val * 0x0101010101010101ULL); break; \
690 uint64_t v64 = val * 0x0101010101010101ULL; \
691 AV_WN64A( &var, v64); \
692 AV_WN64A(&((uint8_t *) &var)[8], v64); \
697#define SPLAT_CTX(var, val, n) \
699 case 1: var = val; break; \
700 case 2: AV_WN16A(&var, val * 0x0101); break; \
701 case 4: AV_WN32A(&var, val * 0x01010101); break; \
703 uint32_t v32 = val * 0x01010101; \
704 AV_WN32A( &var, v32); \
705 AV_WN32A(&((uint8_t *) &var)[4], v32); \
709 uint32_t v32 = val * 0x01010101; \
710 AV_WN32A( &var, v32); \
711 AV_WN32A(&((uint8_t *) &var)[4], v32); \
712 AV_WN32A(&((uint8_t *) &var)[8], v32); \
713 AV_WN32A(&((uint8_t *) &var)[12], v32); \
720#define SET_CTXS(perf, dir, off, n) \
722 SPLAT_CTX(perf->dir##_skip_ctx[off], b->skip, n); \
723 SPLAT_CTX(perf->dir##_txfm_ctx[off], b->tx, n); \
724 SPLAT_CTX(perf->dir##_partition_ctx[off], dir##_ctx[b->bs], n); \
725 if (!s->s.h.keyframe && !s->s.h.intraonly) { \
726 SPLAT_CTX(perf->dir##_intra_ctx[off], b->intra, n); \
727 SPLAT_CTX(perf->dir##_comp_ctx[off], b->comp, n); \
728 SPLAT_CTX(perf->dir##_mode_ctx[off], b->mode[3], n); \
730 SPLAT_CTX(perf->dir##_ref_ctx[off], vref, n); \
731 if (s->s.h.filtermode == FILTER_SWITCHABLE) { \
732 SPLAT_CTX(perf->dir##_filter_ctx[off], filter_id, n); \
737 case 1:
SET_CTXS(
s, above, col, 1);
break;
738 case 2:
SET_CTXS(
s, above, col, 2);
break;
739 case 4:
SET_CTXS(
s, above, col, 4);
break;
740 case 8:
SET_CTXS(
s, above, col, 8);
break;
751 if (!
s->s.h.keyframe && !
s->s.h.intraonly) {
759 AV_COPY32(&
s->above_mv_ctx[col * 2 + 0][0], &
b->mv[2][0]);
760 AV_COPY32(&
s->above_mv_ctx[col * 2 + 0][1], &
b->mv[2][1]);
761 AV_WN32A(&
s->above_mv_ctx[col * 2 + 1][0], mv0);
762 AV_WN32A(&
s->above_mv_ctx[col * 2 + 1][1], mv1);
766 for (n = 0; n < w4 * 2; n++) {
767 AV_WN32A(&
s->above_mv_ctx[col * 2 + n][0], mv0);
768 AV_WN32A(&
s->above_mv_ctx[col * 2 + n][1], mv1);
770 for (n = 0; n < h4 * 2; n++) {
778 for (y = 0; y < h4; y++) {
779 int x, o = (row + y) *
s->sb_cols * 8 + col;
783 for (x = 0; x < w4; x++) {
787 }
else if (
b->comp) {
788 for (x = 0; x < w4; x++) {
789 mv[x].ref[0] =
b->ref[0];
790 mv[x].ref[1] =
b->ref[1];
795 for (x = 0; x < w4; x++) {
796 mv[x].ref[0] =
b->ref[0];
1265 VP9Filter *lflvl, ptrdiff_t yoff, ptrdiff_t uvoff,
1271 int bytesperpixel =
s->bytesperpixel;
1281 td->
min_mv.
x = -(128 + col * 64);
1282 td->
min_mv.
y = -(128 + row * 64);
1283 td->
max_mv.
x = 128 + (
s->cols - col - w4) * 64;
1284 td->
max_mv.
y = 128 + (
s->rows - row - h4) * 64;
1291 b->uvtx =
b->tx - ((
s->ss_h && w4 * 2 == (1 <<
b->tx)) ||
1292 (
s->ss_v && h4 * 2 == (1 <<
b->tx)));
1305 if (bytesperpixel == 1) {
1310 if (!has_coeffs &&
b->bs <=
BS_8x8 && !
b->intra) {
1312 memset(&
s->above_skip_ctx[col], 1, w4);
1316 int row7 = td->
row7;
1318#define SPLAT_ZERO_CTX(v, n) \
1320 case 1: v = 0; break; \
1321 case 2: AV_ZERO16(&v); break; \
1322 case 4: AV_ZERO32(&v); break; \
1323 case 8: AV_ZERO64(&v); break; \
1324 case 16: AV_ZERO128(&v); break; \
1326#define SPLAT_ZERO_YUV(dir, var, off, n, dir2) \
1328 SPLAT_ZERO_CTX(dir##_y_##var[off * 2], n * 2); \
1329 if (s->ss_##dir2) { \
1330 SPLAT_ZERO_CTX(dir##_uv_##var[0][off], n); \
1331 SPLAT_ZERO_CTX(dir##_uv_##var[1][off], n); \
1333 SPLAT_ZERO_CTX(dir##_uv_##var[0][off * 2], n * 2); \
1334 SPLAT_ZERO_CTX(dir##_uv_##var[1][off * 2], n * 2); \
1354 s->td[0].block += w4 * h4 * 64 * bytesperpixel;
1355 s->td[0].uvblock[0] += w4 * h4 * 64 * bytesperpixel >> (
s->ss_h +
s->ss_v);
1356 s->td[0].uvblock[1] += w4 * h4 * 64 * bytesperpixel >> (
s->ss_h +
s->ss_v);
1357 s->td[0].eob += 4 * w4 * h4;
1358 s->td[0].uveob[0] += 4 * w4 * h4 >> (
s->ss_h +
s->ss_v);
1359 s->td[0].uveob[1] += 4 * w4 * h4 >> (
s->ss_h +
s->ss_v);
1368 emu[0] = (col + w4) * 8 * bytesperpixel >
f->linesize[0] ||
1369 (row + h4) >
s->rows;
1370 emu[1] = ((col + w4) * 8 >>
s->ss_h) * bytesperpixel >
f->linesize[1] ||
1371 (row + h4) >
s->rows;
1376 td->
dst[0] =
f->data[0] + yoff;
1384 td->
dst[1] =
f->data[1] + uvoff;
1385 td->
dst[2] =
f->data[2] + uvoff;
1389 if (
s->s.h.bpp > 8) {
1395 if (
s->s.h.bpp > 8) {
1402 int w =
FFMIN(
s->cols - col, w4) * 8,
h =
FFMIN(
s->rows - row, h4) * 8, n, o = 0;
1404 for (n = 0; o <
w; n++) {
1409 s->dsp.mc[n][0][0][0][0](
f->data[0] + yoff + o * bytesperpixel,
f->linesize[0],
1410 td->
tmp_y + o * bytesperpixel, 128,
h, 0, 0);
1416 int w =
FFMIN(
s->cols - col, w4) * 8 >>
s->ss_h;
1417 int h =
FFMIN(
s->rows - row, h4) * 8 >>
s->ss_v, n, o = 0;
1419 for (n =
s->ss_h; o <
w; n++) {
1424 s->dsp.mc[n][0][0][0][0](
f->data[1] + uvoff + o * bytesperpixel,
f->linesize[1],
1425 td->
tmp_uv[0] + o * bytesperpixel, 128,
h, 0, 0);
1426 s->dsp.mc[n][0][0][0][0](
f->data[2] + uvoff + o * bytesperpixel,
f->linesize[2],
1427 td->
tmp_uv[1] + o * bytesperpixel, 128,
h, 0, 0);
1434 if (
s->s.h.filter.level &&
1435 (lvl =
s->s.h.segmentation.feat[
b->seg_id].lflvl[
b->intra ? 0 :
b->ref[0] + 1]
1436 [
b->mode[3] !=
ZEROMV]) > 0) {
1437 int x_end =
FFMIN(
s->cols - col, w4), y_end =
FFMIN(
s->rows - row, h4);
1438 int skip_inter = !
b->intra &&
b->skip, col7 = td->
col7, row7 = td->
row7;
1441 mask_edges(lflvl->
mask[0], 0, 0, row7, col7, x_end, y_end, 0, 0,
b->tx, skip_inter);
1442 if (
s->ss_h ||
s->ss_v)
1444 s->cols & 1 && col + w4 >=
s->cols ?
s->cols & 7 : 0,
1445 s->rows & 1 && row + h4 >=
s->rows ?
s->rows & 7 : 0,
1446 b->uvtx, skip_inter);
1451 s->td[0].block += w4 * h4 * 64 * bytesperpixel;
1452 s->td[0].uvblock[0] += w4 * h4 * 64 * bytesperpixel >> (
s->ss_v +
s->ss_h);
1453 s->td[0].uvblock[1] += w4 * h4 * 64 * bytesperpixel >> (
s->ss_v +
s->ss_h);
1454 s->td[0].eob += 4 * w4 * h4;
1455 s->td[0].uveob[0] += 4 * w4 * h4 >> (
s->ss_v +
s->ss_h);
1456 s->td[0].uveob[1] += 4 * w4 * h4 >> (
s->ss_v +
s->ss_h);