51 uint32_t v32 = v * 0x01010101;
60 uint64_t v64 = v * 0x0101010101010101ULL;
66 uint32_t v32 = v * 0x01010101;
81 0x0, 0x8, 0x0, 0x8, 0xc, 0x8, 0xc, 0xe, 0xc, 0xe, 0xf, 0xe, 0xf
84 0x0, 0x0, 0x8, 0x8, 0x8, 0xc, 0xc, 0xc, 0xe, 0xe, 0xe, 0xf, 0xf
86 static const uint8_t max_tx_for_bl_bp[
N_BS_SIZES] = {
92 int row =
td->row, col =
td->col, row7 =
td->row7;
93 enum TxfmMode max_tx = max_tx_for_bl_bp[
b->bs];
96 int have_a = row > 0, have_l = col >
td->tile_col_start;
99 if (!
s->s.h.segmentation.enabled) {
101 }
else if (
s->s.h.keyframe ||
s->s.h.intraonly) {
102 b->seg_id = !
s->s.h.segmentation.update_map ? 0 :
104 }
else if (!
s->s.h.segmentation.update_map ||
105 (
s->s.h.segmentation.temporal &&
107 s->s.h.segmentation.pred_prob[
s->above_segpred_ctx[col] +
108 td->left_segpred_ctx[row7]]))) {
115 for (y = 0; y < h4; y++) {
116 int idx_base = (y + row) * 8 *
s->sb_cols + col;
117 for (x = 0; x < w4; x++)
126 memset(&
s->above_segpred_ctx[col], 1, w4);
127 memset(&
td->left_segpred_ctx[row7], 1, h4);
130 s->s.h.segmentation.prob);
132 memset(&
s->above_segpred_ctx[col], 0, w4);
133 memset(&
td->left_segpred_ctx[row7], 0, h4);
135 if (
s->s.h.segmentation.enabled &&
136 (
s->s.h.segmentation.update_map ||
s->s.h.keyframe ||
s->s.h.intraonly)) {
138 bw4, bh4, 8 *
s->sb_cols,
b->seg_id);
141 b->skip =
s->s.h.segmentation.enabled &&
142 s->s.h.segmentation.feat[
b->seg_id].skip_enabled;
144 int c =
td->left_skip_ctx[row7] +
s->above_skip_ctx[col];
146 td->counts.skip[
c][
b->skip]++;
149 if (
s->s.h.keyframe ||
s->s.h.intraonly) {
151 }
else if (
s->s.h.segmentation.enabled &&
s->s.h.segmentation.feat[
b->seg_id].ref_enabled) {
152 b->intra = !
s->s.h.segmentation.feat[
b->seg_id].ref_val;
156 if (have_a && have_l) {
157 c =
s->above_intra_ctx[col] +
td->left_intra_ctx[row7];
160 c = have_a ? 2 *
s->above_intra_ctx[col] :
161 have_l ? 2 *
td->left_intra_ctx[row7] : 0;
164 td->counts.intra[
c][
bit]++;
172 c = (
s->above_skip_ctx[col] ? max_tx :
173 s->above_txfm_ctx[col]) +
174 (
td->left_skip_ctx[row7] ? max_tx :
175 td->left_txfm_ctx[row7]) > max_tx;
177 c =
s->above_skip_ctx[col] ? 1 :
178 (
s->above_txfm_ctx[col] * 2 > max_tx);
181 c =
td->left_skip_ctx[row7] ? 1 :
182 (
td->left_txfm_ctx[row7] * 2 > max_tx);
194 td->counts.tx32p[
c][
b->tx]++;
200 td->counts.tx16p[
c][
b->tx]++;
204 td->counts.tx8p[
c][
b->tx]++;
211 b->tx =
FFMIN(max_tx,
s->s.h.txfmmode);
214 if (
s->s.h.keyframe ||
s->s.h.intraonly) {
215 uint8_t *
a = &
s->above_mode_ctx[col * 2];
216 uint8_t *l = &
td->left_mode_ctx[(row7) << 1];
234 b->mode[1] =
b->mode[0];
248 b->mode[3] =
b->mode[2];
251 b->mode[2] =
b->mode[0];
254 b->mode[3] =
b->mode[1];
261 b->mode[1] =
b->mode[0];
268 }
else if (
b->intra) {
272 s->prob.p.y_mode[0]);
273 td->counts.y_mode[0][
b->mode[0]]++;
276 s->prob.p.y_mode[0]);
277 td->counts.y_mode[0][
b->mode[1]]++;
279 b->mode[1] =
b->mode[0];
283 s->prob.p.y_mode[0]);
284 td->counts.y_mode[0][
b->mode[2]]++;
287 s->prob.p.y_mode[0]);
288 td->counts.y_mode[0][
b->mode[3]]++;
290 b->mode[3] =
b->mode[2];
293 b->mode[2] =
b->mode[0];
294 b->mode[3] =
b->mode[1];
297 static const uint8_t size_group[10] = {
298 3, 3, 3, 3, 2, 2, 2, 1, 1, 1
300 int sz = size_group[
b->bs];
303 s->prob.p.y_mode[sz]);
306 b->mode[3] =
b->mode[0];
307 td->counts.y_mode[sz][
b->mode[3]]++;
310 s->prob.p.uv_mode[
b->mode[3]]);
311 td->counts.uv_mode[
b->mode[3]][
b->uvmode]++;
313 static const uint8_t inter_mode_ctx_lut[14][14] = {
314 { 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5 },
315 { 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5 },
316 { 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5 },
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 { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 2, 2, 1, 3 },
325 { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 2, 2, 1, 3 },
326 { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 1, 1, 0, 3 },
327 { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 3, 3, 3, 4 },
330 if (
s->s.h.segmentation.enabled &&
s->s.h.segmentation.feat[
b->seg_id].ref_enabled) {
331 av_assert2(
s->s.h.segmentation.feat[
b->seg_id].ref_val != 0);
333 b->ref[0] =
s->s.h.segmentation.feat[
b->seg_id].ref_val - 1;
344 if (
s->above_comp_ctx[col] &&
td->left_comp_ctx[row7]) {
346 }
else if (
s->above_comp_ctx[col]) {
347 c = 2 + (
td->left_intra_ctx[row7] ||
348 td->left_ref_ctx[row7] ==
s->s.h.fixcompref);
349 }
else if (
td->left_comp_ctx[row7]) {
350 c = 2 + (
s->above_intra_ctx[col] ||
351 s->above_ref_ctx[col] ==
s->s.h.fixcompref);
353 c = (!
s->above_intra_ctx[col] &&
354 s->above_ref_ctx[col] ==
s->s.h.fixcompref) ^
355 (!
td->left_intra_ctx[row7] &&
356 td->left_ref_ctx[row & 7] ==
s->s.h.fixcompref);
359 c =
s->above_comp_ctx[col] ? 3 :
360 (!
s->above_intra_ctx[col] &&
s->above_ref_ctx[col] ==
s->s.h.fixcompref);
363 c =
td->left_comp_ctx[row7] ? 3 :
364 (!
td->left_intra_ctx[row7] &&
td->left_ref_ctx[row7] ==
s->s.h.fixcompref);
369 td->counts.comp[
c][
b->comp]++;
376 int fix_idx =
s->s.h.signbias[
s->s.h.fixcompref], var_idx = !fix_idx,
c,
bit;
378 b->ref[fix_idx] =
s->s.h.fixcompref;
382 if (
s->above_intra_ctx[col]) {
383 if (
td->left_intra_ctx[row7]) {
386 c = 1 + 2 * (
td->left_ref_ctx[row7] !=
s->s.h.varcompref[1]);
388 }
else if (
td->left_intra_ctx[row7]) {
389 c = 1 + 2 * (
s->above_ref_ctx[col] !=
s->s.h.varcompref[1]);
391 int refl =
td->left_ref_ctx[row7], refa =
s->above_ref_ctx[col];
393 if (refl == refa && refa ==
s->s.h.varcompref[1]) {
395 }
else if (!
td->left_comp_ctx[row7] && !
s->above_comp_ctx[col]) {
396 if ((refa ==
s->s.h.fixcompref && refl ==
s->s.h.varcompref[0]) ||
397 (refl ==
s->s.h.fixcompref && refa ==
s->s.h.varcompref[0])) {
400 c = (refa == refl) ? 3 : 1;
402 }
else if (!
td->left_comp_ctx[row7]) {
403 if (refa ==
s->s.h.varcompref[1] && refl !=
s->s.h.varcompref[1]) {
406 c = (refl ==
s->s.h.varcompref[1] &&
407 refa !=
s->s.h.varcompref[1]) ? 2 : 4;
409 }
else if (!
s->above_comp_ctx[col]) {
410 if (refl ==
s->s.h.varcompref[1] && refa !=
s->s.h.varcompref[1]) {
413 c = (refa ==
s->s.h.varcompref[1] &&
414 refl !=
s->s.h.varcompref[1]) ? 2 : 4;
417 c = (refl == refa) ? 4 : 2;
421 if (
s->above_intra_ctx[col]) {
423 }
else if (
s->above_comp_ctx[col]) {
424 c = 4 * (
s->above_ref_ctx[col] !=
s->s.h.varcompref[1]);
426 c = 3 * (
s->above_ref_ctx[col] !=
s->s.h.varcompref[1]);
430 if (
td->left_intra_ctx[row7]) {
432 }
else if (
td->left_comp_ctx[row7]) {
433 c = 4 * (
td->left_ref_ctx[row7] !=
s->s.h.varcompref[1]);
435 c = 3 * (
td->left_ref_ctx[row7] !=
s->s.h.varcompref[1]);
441 b->ref[var_idx] =
s->s.h.varcompref[
bit];
442 td->counts.comp_ref[
c][
bit]++;
446 if (have_a && !
s->above_intra_ctx[col]) {
447 if (have_l && !
td->left_intra_ctx[row7]) {
448 if (
td->left_comp_ctx[row7]) {
449 if (
s->above_comp_ctx[col]) {
450 c = 1 + (!
s->s.h.fixcompref || !
td->left_ref_ctx[row7] ||
451 !
s->above_ref_ctx[col]);
453 c = (3 * !
s->above_ref_ctx[col]) +
454 (!
s->s.h.fixcompref || !
td->left_ref_ctx[row7]);
456 }
else if (
s->above_comp_ctx[col]) {
457 c = (3 * !
td->left_ref_ctx[row7]) +
458 (!
s->s.h.fixcompref || !
s->above_ref_ctx[col]);
460 c = 2 * !
td->left_ref_ctx[row7] + 2 * !
s->above_ref_ctx[col];
462 }
else if (
s->above_intra_ctx[col]) {
464 }
else if (
s->above_comp_ctx[col]) {
465 c = 1 + (!
s->s.h.fixcompref || !
s->above_ref_ctx[col]);
467 c = 4 * (!
s->above_ref_ctx[col]);
469 }
else if (have_l && !
td->left_intra_ctx[row7]) {
470 if (
td->left_intra_ctx[row7]) {
472 }
else if (
td->left_comp_ctx[row7]) {
473 c = 1 + (!
s->s.h.fixcompref || !
td->left_ref_ctx[row7]);
475 c = 4 * (!
td->left_ref_ctx[row7]);
481 td->counts.single_ref[
c][0][
bit]++;
488 if (
td->left_intra_ctx[row7]) {
489 if (
s->above_intra_ctx[col]) {
491 }
else if (
s->above_comp_ctx[col]) {
492 c = 1 + 2 * (
s->s.h.fixcompref == 1 ||
493 s->above_ref_ctx[col] == 1);
494 }
else if (!
s->above_ref_ctx[col]) {
497 c = 4 * (
s->above_ref_ctx[col] == 1);
499 }
else if (
s->above_intra_ctx[col]) {
500 if (
td->left_intra_ctx[row7]) {
502 }
else if (
td->left_comp_ctx[row7]) {
503 c = 1 + 2 * (
s->s.h.fixcompref == 1 ||
504 td->left_ref_ctx[row7] == 1);
505 }
else if (!
td->left_ref_ctx[row7]) {
508 c = 4 * (
td->left_ref_ctx[row7] == 1);
510 }
else if (
s->above_comp_ctx[col]) {
511 if (
td->left_comp_ctx[row7]) {
512 if (
td->left_ref_ctx[row7] ==
s->above_ref_ctx[col]) {
513 c = 3 * (
s->s.h.fixcompref == 1 ||
514 td->left_ref_ctx[row7] == 1);
518 }
else if (!
td->left_ref_ctx[row7]) {
519 c = 1 + 2 * (
s->s.h.fixcompref == 1 ||
520 s->above_ref_ctx[col] == 1);
522 c = 3 * (
td->left_ref_ctx[row7] == 1) +
523 (
s->s.h.fixcompref == 1 ||
s->above_ref_ctx[col] == 1);
525 }
else if (
td->left_comp_ctx[row7]) {
526 if (!
s->above_ref_ctx[col]) {
527 c = 1 + 2 * (
s->s.h.fixcompref == 1 ||
528 td->left_ref_ctx[row7] == 1);
530 c = 3 * (
s->above_ref_ctx[col] == 1) +
531 (
s->s.h.fixcompref == 1 ||
td->left_ref_ctx[row7] == 1);
533 }
else if (!
s->above_ref_ctx[col]) {
534 if (!
td->left_ref_ctx[row7]) {
537 c = 4 * (
td->left_ref_ctx[row7] == 1);
539 }
else if (!
td->left_ref_ctx[row7]) {
540 c = 4 * (
s->above_ref_ctx[col] == 1);
542 c = 2 * (
td->left_ref_ctx[row7] == 1) +
543 2 * (
s->above_ref_ctx[col] == 1);
546 if (
s->above_intra_ctx[col] ||
547 (!
s->above_comp_ctx[col] && !
s->above_ref_ctx[col])) {
549 }
else if (
s->above_comp_ctx[col]) {
550 c = 3 * (
s->s.h.fixcompref == 1 ||
s->above_ref_ctx[col] == 1);
552 c = 4 * (
s->above_ref_ctx[col] == 1);
556 if (
td->left_intra_ctx[row7] ||
557 (!
td->left_comp_ctx[row7] && !
td->left_ref_ctx[row7])) {
559 }
else if (
td->left_comp_ctx[row7]) {
560 c = 3 * (
s->s.h.fixcompref == 1 ||
td->left_ref_ctx[row7] == 1);
562 c = 4 * (
td->left_ref_ctx[row7] == 1);
568 td->counts.single_ref[
c][1][
bit]++;
575 if (
s->s.h.segmentation.enabled &&
s->s.h.segmentation.feat[
b->seg_id].skip_enabled) {
581 static const uint8_t off[10] = {
582 3, 0, 0, 1, 0, 0, 0, 0, 0, 0
587 int c = inter_mode_ctx_lut[
s->above_mode_ctx[col + off[
b->bs]]]
588 [
td->left_mode_ctx[row7 + off[
b->bs]]];
591 s->prob.p.mv_mode[
c]);
594 b->mode[3] =
b->mode[0];
595 td->counts.mv_mode[
c][
b->mode[0] - 10]++;
602 if (have_a &&
s->above_mode_ctx[col] >=
NEARESTMV) {
603 if (have_l &&
td->left_mode_ctx[row7] >=
NEARESTMV) {
604 c =
s->above_filter_ctx[col] ==
td->left_filter_ctx[row7] ?
605 td->left_filter_ctx[row7] : 3;
607 c =
s->above_filter_ctx[col];
609 }
else if (have_l &&
td->left_mode_ctx[row7] >=
NEARESTMV) {
610 c =
td->left_filter_ctx[row7];
616 s->prob.p.filter[
c]);
617 td->counts.filter[
c][filter_id]++;
620 b->filter =
s->s.h.filtermode;
624 int c = inter_mode_ctx_lut[
s->above_mode_ctx[col]][
td->left_mode_ctx[row7]];
627 s->prob.p.mv_mode[
c]);
628 td->counts.mv_mode[
c][
b->mode[0] - 10]++;
633 s->prob.p.mv_mode[
c]);
634 td->counts.mv_mode[
c][
b->mode[1] - 10]++;
637 b->mode[1] =
b->mode[0];
644 s->prob.p.mv_mode[
c]);
645 td->counts.mv_mode[
c][
b->mode[2] - 10]++;
650 s->prob.p.mv_mode[
c]);
651 td->counts.mv_mode[
c][
b->mode[3] - 10]++;
654 b->mode[3] =
b->mode[2];
659 b->mode[2] =
b->mode[0];
662 b->mode[3] =
b->mode[1];
676 vref =
b->ref[
b->comp ?
s->s.h.signbias[
s->s.h.varcompref[0]] : 0];
680 #define SPLAT_CTX(var, val, n) \
682 case 1: var = val; break; \
683 case 2: AV_WN16A(&var, val * 0x0101); break; \
684 case 4: AV_WN32A(&var, val * 0x01010101); break; \
685 case 8: AV_WN64A(&var, val * 0x0101010101010101ULL); break; \
687 uint64_t v64 = val * 0x0101010101010101ULL; \
688 AV_WN64A( &var, v64); \
689 AV_WN64A(&((uint8_t *) &var)[8], v64); \
694 #define SPLAT_CTX(var, val, n) \
696 case 1: var = val; break; \
697 case 2: AV_WN16A(&var, val * 0x0101); break; \
698 case 4: AV_WN32A(&var, val * 0x01010101); break; \
700 uint32_t v32 = val * 0x01010101; \
701 AV_WN32A( &var, v32); \
702 AV_WN32A(&((uint8_t *) &var)[4], v32); \
706 uint32_t v32 = val * 0x01010101; \
707 AV_WN32A( &var, v32); \
708 AV_WN32A(&((uint8_t *) &var)[4], v32); \
709 AV_WN32A(&((uint8_t *) &var)[8], v32); \
710 AV_WN32A(&((uint8_t *) &var)[12], v32); \
717 #define SET_CTXS(perf, dir, off, n) \
719 SPLAT_CTX(perf->dir##_skip_ctx[off], b->skip, n); \
720 SPLAT_CTX(perf->dir##_txfm_ctx[off], b->tx, n); \
721 SPLAT_CTX(perf->dir##_partition_ctx[off], dir##_ctx[b->bs], n); \
722 if (!s->s.h.keyframe && !s->s.h.intraonly) { \
723 SPLAT_CTX(perf->dir##_intra_ctx[off], b->intra, n); \
724 SPLAT_CTX(perf->dir##_comp_ctx[off], b->comp, n); \
725 SPLAT_CTX(perf->dir##_mode_ctx[off], b->mode[3], n); \
727 SPLAT_CTX(perf->dir##_ref_ctx[off], vref, n); \
728 if (s->s.h.filtermode == FILTER_SWITCHABLE) { \
729 SPLAT_CTX(perf->dir##_filter_ctx[off], filter_id, n); \
734 case 1:
SET_CTXS(
s, above, col, 1);
break;
735 case 2:
SET_CTXS(
s, above, col, 2);
break;
736 case 4:
SET_CTXS(
s, above, col, 4);
break;
737 case 8:
SET_CTXS(
s, above, col, 8);
break;
748 if (!
s->s.h.keyframe && !
s->s.h.intraonly) {
752 AV_COPY32(&
td->left_mv_ctx[row7 * 2 + 0][0], &
b->mv[1][0]);
753 AV_COPY32(&
td->left_mv_ctx[row7 * 2 + 0][1], &
b->mv[1][1]);
754 AV_WN32A(&
td->left_mv_ctx[row7 * 2 + 1][0], mv0);
755 AV_WN32A(&
td->left_mv_ctx[row7 * 2 + 1][1], mv1);
756 AV_COPY32(&
s->above_mv_ctx[col * 2 + 0][0], &
b->mv[2][0]);
757 AV_COPY32(&
s->above_mv_ctx[col * 2 + 0][1], &
b->mv[2][1]);
758 AV_WN32A(&
s->above_mv_ctx[col * 2 + 1][0], mv0);
759 AV_WN32A(&
s->above_mv_ctx[col * 2 + 1][1], mv1);
763 for (n = 0; n < w4 * 2; n++) {
764 AV_WN32A(&
s->above_mv_ctx[col * 2 + n][0], mv0);
765 AV_WN32A(&
s->above_mv_ctx[col * 2 + n][1], mv1);
767 for (n = 0; n < h4 * 2; n++) {
768 AV_WN32A(&
td->left_mv_ctx[row7 * 2 + n][0], mv0);
769 AV_WN32A(&
td->left_mv_ctx[row7 * 2 + n][1], mv1);
775 for (y = 0; y < h4; y++) {
776 int x, o = (row + y) *
s->sb_cols * 8 + col;
780 for (x = 0; x < w4; x++) {
784 }
else if (
b->comp) {
785 for (x = 0; x < w4; x++) {
786 mv[x].ref[0] =
b->ref[0];
787 mv[x].ref[1] =
b->ref[1];
792 for (x = 0; x < w4; x++) {
793 mv[x].ref[0] =
b->ref[0];
804 int is_tx32x32,
int is8bitsperpixel,
int bpp,
unsigned (*cnt)[6][3],
805 unsigned (*eob)[6][2], uint8_t (*p)[6][11],
806 int nnz,
const int16_t *scan,
const int16_t (*nb)[2],
807 const int16_t *band_counts, int16_t *qmul)
809 int i = 0, band = 0, band_left = band_counts[band];
810 const uint8_t *tp = p[0][nnz];
817 eob[band][nnz][
val]++;
825 band_left = band_counts[++band];
827 nnz = (1 + cache[nb[
i][0]] + cache[nb[
i][1]]) >> 1;
877 if (!is8bitsperpixel) {
902 #define STORE_COEF(c, i, v) do { \
903 if (is8bitsperpixel) { \
906 AV_WN32A(&c[i * 2], v); \
910 band_left = band_counts[++band];
915 nnz = (1 + cache[nb[
i][0]] + cache[nb[
i][1]]) >> 1;
917 }
while (++
i < n_coeffs);
923 unsigned (*cnt)[6][3],
unsigned (*eob)[6][2],
924 uint8_t (*p)[6][11],
int nnz,
const int16_t *scan,
925 const int16_t (*nb)[2],
const int16_t *band_counts,
929 nnz, scan, nb, band_counts, qmul);
933 unsigned (*cnt)[6][3],
unsigned (*eob)[6][2],
934 uint8_t (*p)[6][11],
int nnz,
const int16_t *scan,
935 const int16_t (*nb)[2],
const int16_t *band_counts,
939 nnz, scan, nb, band_counts, qmul);
943 unsigned (*cnt)[6][3],
unsigned (*eob)[6][2],
944 uint8_t (*p)[6][11],
int nnz,
const int16_t *scan,
945 const int16_t (*nb)[2],
const int16_t *band_counts,
949 nnz, scan, nb, band_counts, qmul);
953 unsigned (*cnt)[6][3],
unsigned (*eob)[6][2],
954 uint8_t (*p)[6][11],
int nnz,
const int16_t *scan,
955 const int16_t (*nb)[2],
const int16_t *band_counts,
959 nnz, scan, nb, band_counts, qmul);
966 int row =
td->row, col =
td->col;
967 uint8_t (*p)[6][11] =
s->prob.coef[
b->tx][0 ][!
b->intra];
968 unsigned (*
c)[6][3] =
td->counts.coef[
b->tx][0 ][!
b->intra];
969 unsigned (*e)[6][2] =
td->counts.eob[
b->tx][0 ][!
b->intra];
971 int end_x =
FFMIN(2 * (
s->cols - col), w4);
972 int end_y =
FFMIN(2 * (
s->rows - row), h4);
973 int n, pl, x, y,
ret;
974 int16_t (*qmul)[2] =
s->s.h.segmentation.feat[
b->seg_id].qmul;
975 int tx = 4 *
s->s.h.lossless +
b->tx;
980 uint8_t *
a = &
s->above_y_nnz_ctx[col * 2];
981 uint8_t *l = &
td->left_y_nnz_ctx[(row & 7) << 1];
982 static const int16_t band_counts[4][8] = {
983 { 1, 2, 3, 4, 3, 16 - 13 },
984 { 1, 2, 3, 4, 11, 64 - 21 },
985 { 1, 2, 3, 4, 11, 256 - 21 },
986 { 1, 2, 3, 4, 11, 1024 - 21 },
988 const int16_t *y_band_counts = band_counts[
b->tx];
989 const int16_t *uv_band_counts = band_counts[
b->uvtx];
990 int bytesperpixel = is8bitsperpixel ? 1 : 2;
993 #define MERGE(la, end, step, rd) \
994 for (n = 0; n < end; n += step) \
996 #define MERGE_CTX(step, rd) \
998 MERGE(l, end_y, step, rd); \
999 MERGE(a, end_x, step, rd); \
1002 #define DECODE_Y_COEF_LOOP(step, mode_index, v) \
1003 for (n = 0, y = 0; y < end_y; y += step) { \
1004 for (x = 0; x < end_x; x += step, n += step * step) { \
1005 enum TxfmType txtp = ff_vp9_intra_txfm_type[b->mode[mode_index]]; \
1006 ret = (is8bitsperpixel ? decode_coeffs_b##v##_8bpp : decode_coeffs_b##v##_16bpp) \
1007 (td, td->block + 16 * n * bytesperpixel, 16 * step * step, \
1008 c, e, p, a[x] + l[y], yscans[txtp], \
1009 ynbs[txtp], y_band_counts, qmul[0]); \
1010 a[x] = l[y] = !!ret; \
1011 total_coeff |= !!ret; \
1013 AV_WN16A(&td->eob[n], ret); \
1020 #define SPLAT(la, end, step, cond) \
1022 for (n = 1; n < end; n += step) \
1023 la[n] = la[n - 1]; \
1024 } else if (step == 4) { \
1026 for (n = 0; n < end; n += step) \
1027 AV_WN32A(&la[n], la[n] * 0x01010101); \
1029 for (n = 0; n < end; n += step) \
1030 memset(&la[n + 1], la[n], FFMIN(end - n - 1, 3)); \
1034 if (HAVE_FAST_64BIT) { \
1035 for (n = 0; n < end; n += step) \
1036 AV_WN64A(&la[n], la[n] * 0x0101010101010101ULL); \
1038 for (n = 0; n < end; n += step) { \
1039 uint32_t v32 = la[n] * 0x01010101; \
1040 AV_WN32A(&la[n], v32); \
1041 AV_WN32A(&la[n + 4], v32); \
1045 for (n = 0; n < end; n += step) \
1046 memset(&la[n + 1], la[n], FFMIN(end - n - 1, 7)); \
1049 #define SPLAT_CTX(step) \
1051 SPLAT(a, end_x, step, end_x == w4); \
1052 SPLAT(l, end_y, step, end_y == h4); \
1077 #define DECODE_UV_COEF_LOOP(step, v) \
1078 for (n = 0, y = 0; y < end_y; y += step) { \
1079 for (x = 0; x < end_x; x += step, n += step * step) { \
1080 ret = (is8bitsperpixel ? decode_coeffs_b##v##_8bpp : decode_coeffs_b##v##_16bpp) \
1081 (td, td->uvblock[pl] + 16 * n * bytesperpixel, \
1082 16 * step * step, c, e, p, a[x] + l[y], \
1083 uvscan, uvnb, uv_band_counts, qmul[1]); \
1084 a[x] = l[y] = !!ret; \
1085 total_coeff |= !!ret; \
1087 AV_WN16A(&td->uveob[pl][n], ret); \
1089 td->uveob[pl][n] = ret; \
1094 p =
s->prob.coef[
b->uvtx][1 ][!
b->intra];
1095 c =
td->counts.coef[
b->uvtx][1 ][!
b->intra];
1096 e =
td->counts.eob[
b->uvtx][1 ][!
b->intra];
1101 for (pl = 0; pl < 2; pl++) {
1102 a = &
s->above_uv_nnz_ctx[pl][col << !
s->ss_h];
1103 l = &
td->left_uv_nnz_ctx[pl][(row & 7) << !
s->ss_v];
1140 int row_and_7,
int col_and_7,
1141 int w,
int h,
int col_end,
int row_end,
1144 static const unsigned wide_filter_col_mask[2] = { 0x11, 0x01 };
1145 static const unsigned wide_filter_row_mask[2] = { 0x03, 0x07 };
1157 if (tx ==
TX_4X4 && (ss_v | ss_h)) {
1172 if (tx ==
TX_4X4 && !skip_inter) {
1173 int t = 1 << col_and_7, m_col = (t <<
w) - t, y;
1175 int m_row_8 = m_col & wide_filter_col_mask[ss_h], m_row_4 = m_col - m_row_8;
1177 for (y = row_and_7; y <
h + row_and_7; y++) {
1178 int col_mask_id = 2 - !(y & wide_filter_row_mask[ss_v]);
1180 mask[0][y][1] |= m_row_8;
1181 mask[0][y][2] |= m_row_4;
1192 if ((ss_h & ss_v) && (col_end & 1) && (y & 1)) {
1193 mask[1][y][col_mask_id] |= (t << (
w - 1)) - t;
1195 mask[1][y][col_mask_id] |= m_col;
1198 mask[0][y][3] |= m_col;
1200 if (ss_h && (col_end & 1))
1201 mask[1][y][3] |= (t << (
w - 1)) - t;
1203 mask[1][y][3] |= m_col;
1207 int y, t = 1 << col_and_7, m_col = (t <<
w) - t;
1210 int mask_id = (tx ==
TX_8X8);
1211 int l2 = tx + ss_h - 1, step1d;
1212 static const unsigned masks[4] = { 0xff, 0x55, 0x11, 0x01 };
1213 int m_row = m_col & masks[l2];
1217 if (ss_h && tx >
TX_8X8 && (
w ^ (
w - 1)) == 1) {
1218 int m_row_16 = ((t << (
w - 1)) - t) & masks[l2];
1219 int m_row_8 = m_row - m_row_16;
1221 for (y = row_and_7; y <
h + row_and_7; y++) {
1222 mask[0][y][0] |= m_row_16;
1223 mask[0][y][1] |= m_row_8;
1226 for (y = row_and_7; y <
h + row_and_7; y++)
1227 mask[0][y][mask_id] |= m_row;
1232 if (ss_v && tx >
TX_8X8 && (
h ^ (
h - 1)) == 1) {
1233 for (y = row_and_7; y <
h + row_and_7 - 1; y += step1d)
1234 mask[1][y][0] |= m_col;
1235 if (y - row_and_7 ==
h - 1)
1236 mask[1][y][1] |= m_col;
1238 for (y = row_and_7; y <
h + row_and_7; y += step1d)
1239 mask[1][y][mask_id] |= m_col;
1241 }
else if (tx !=
TX_4X4) {
1244 mask_id = (tx ==
TX_8X8) || (
h == ss_v);
1245 mask[1][row_and_7][mask_id] |= m_col;
1246 mask_id = (tx ==
TX_8X8) || (
w == ss_h);
1247 for (y = row_and_7; y <
h + row_and_7; y++)
1248 mask[0][y][mask_id] |= t;
1250 int t8 = t & wide_filter_col_mask[ss_h],
t4 = t -
t8;
1252 for (y = row_and_7; y <
h + row_and_7; y++) {
1256 mask[1][row_and_7][2 - !(row_and_7 & wide_filter_row_mask[ss_v])] |= m_col;
1262 VP9Filter *lflvl, ptrdiff_t yoff, ptrdiff_t uvoff,
1268 int bytesperpixel =
s->bytesperpixel;
1278 td->min_mv.x = -(128 + col * 64);
1279 td->min_mv.y = -(128 + row * 64);
1280 td->max_mv.x = 128 + (
s->cols - col - w4) * 64;
1281 td->max_mv.y = 128 + (
s->rows - row - h4) * 64;
1288 b->uvtx =
b->tx - ((
s->ss_h && w4 * 2 == (1 <<
b->tx)) ||
1289 (
s->ss_v && h4 * 2 == (1 <<
b->tx)));
1291 if (
td->block_structure) {
1292 td->block_structure[
td->nb_block_structure].row = row;
1293 td->block_structure[
td->nb_block_structure].col = col;
1294 td->block_structure[
td->nb_block_structure].block_size_idx_x =
av_log2(w4);
1295 td->block_structure[
td->nb_block_structure].block_size_idx_y =
av_log2(h4);
1296 td->nb_block_structure++;
1302 if (bytesperpixel == 1) {
1307 if (!has_coeffs &&
b->bs <=
BS_8x8 && !
b->intra) {
1309 memset(&
s->above_skip_ctx[col], 1, w4);
1310 memset(&
td->left_skip_ctx[
td->row7], 1, h4);
1313 int row7 =
td->row7;
1315 #define SPLAT_ZERO_CTX(v, n) \
1317 case 1: v = 0; break; \
1318 case 2: AV_ZERO16(&v); break; \
1319 case 4: AV_ZERO32(&v); break; \
1320 case 8: AV_ZERO64(&v); break; \
1321 case 16: AV_ZERO128(&v); break; \
1323 #define SPLAT_ZERO_YUV(dir, var, off, n, dir2) \
1325 SPLAT_ZERO_CTX(dir##_y_##var[off * 2], n * 2); \
1326 if (s->ss_##dir2) { \
1327 SPLAT_ZERO_CTX(dir##_uv_##var[0][off], n); \
1328 SPLAT_ZERO_CTX(dir##_uv_##var[1][off], n); \
1330 SPLAT_ZERO_CTX(dir##_uv_##var[0][off * 2], n * 2); \
1331 SPLAT_ZERO_CTX(dir##_uv_##var[1][off * 2], n * 2); \
1351 s->td[0].block += w4 * h4 * 64 * bytesperpixel;
1352 s->td[0].uvblock[0] += w4 * h4 * 64 * bytesperpixel >> (
s->ss_h +
s->ss_v);
1353 s->td[0].uvblock[1] += w4 * h4 * 64 * bytesperpixel >> (
s->ss_h +
s->ss_v);
1354 s->td[0].eob += 4 * w4 * h4;
1355 s->td[0].uveob[0] += 4 * w4 * h4 >> (
s->ss_h +
s->ss_v);
1356 s->td[0].uveob[1] += 4 * w4 * h4 >> (
s->ss_h +
s->ss_v);
1365 emu[0] = (col + w4) * 8 * bytesperpixel >
f->linesize[0] ||
1366 (row + h4) >
s->rows;
1367 emu[1] = ((col + w4) * 8 >>
s->ss_h) * bytesperpixel >
f->linesize[1] ||
1368 (row + h4) >
s->rows;
1370 td->dst[0] =
td->tmp_y;
1373 td->dst[0] =
f->data[0] + yoff;
1374 td->y_stride =
f->linesize[0];
1377 td->dst[1] =
td->tmp_uv[0];
1378 td->dst[2] =
td->tmp_uv[1];
1379 td->uv_stride = 128;
1381 td->dst[1] =
f->data[1] + uvoff;
1382 td->dst[2] =
f->data[2] + uvoff;
1383 td->uv_stride =
f->linesize[1];
1386 if (
s->s.h.bpp > 8) {
1392 if (
s->s.h.bpp > 8) {
1399 int w =
FFMIN(
s->cols - col, w4) * 8,
h =
FFMIN(
s->rows - row, h4) * 8, n, o = 0;
1401 for (n = 0; o <
w; n++) {
1406 s->dsp.mc[n][0][0][0][0](
f->data[0] + yoff + o * bytesperpixel,
f->linesize[0],
1407 td->tmp_y + o * bytesperpixel, 128,
h, 0, 0);
1413 int w =
FFMIN(
s->cols - col, w4) * 8 >>
s->ss_h;
1414 int h =
FFMIN(
s->rows - row, h4) * 8 >>
s->ss_v, n, o = 0;
1416 for (n =
s->ss_h; o <
w; n++) {
1421 s->dsp.mc[n][0][0][0][0](
f->data[1] + uvoff + o * bytesperpixel,
f->linesize[1],
1422 td->tmp_uv[0] + o * bytesperpixel, 128,
h, 0, 0);
1423 s->dsp.mc[n][0][0][0][0](
f->data[2] + uvoff + o * bytesperpixel,
f->linesize[2],
1424 td->tmp_uv[1] + o * bytesperpixel, 128,
h, 0, 0);
1431 if (
s->s.h.filter.level &&
1432 (lvl =
s->s.h.segmentation.feat[
b->seg_id].lflvl[
b->intra ? 0 :
b->ref[0] + 1]
1433 [
b->mode[3] !=
ZEROMV]) > 0) {
1434 int x_end =
FFMIN(
s->cols - col, w4), y_end =
FFMIN(
s->rows - row, h4);
1435 int skip_inter = !
b->intra &&
b->skip, col7 =
td->col7, row7 =
td->row7;
1438 mask_edges(lflvl->
mask[0], 0, 0, row7, col7, x_end, y_end, 0, 0,
b->tx, skip_inter);
1439 if (
s->ss_h ||
s->ss_v)
1441 s->cols & 1 && col + w4 >=
s->cols ?
s->cols & 7 : 0,
1442 s->rows & 1 && row + h4 >=
s->rows ?
s->rows & 7 : 0,
1443 b->uvtx, skip_inter);
1448 s->td[0].block += w4 * h4 * 64 * bytesperpixel;
1449 s->td[0].uvblock[0] += w4 * h4 * 64 * bytesperpixel >> (
s->ss_v +
s->ss_h);
1450 s->td[0].uvblock[1] += w4 * h4 * 64 * bytesperpixel >> (
s->ss_v +
s->ss_h);
1451 s->td[0].eob += 4 * w4 * h4;
1452 s->td[0].uveob[0] += 4 * w4 * h4 >> (
s->ss_v +
s->ss_h);
1453 s->td[0].uveob[1] += 4 * w4 * h4 >> (
s->ss_v +
s->ss_h);