32 uint8_t *dst_edge, ptrdiff_t stride_edge,
33 uint8_t *dst_inner, ptrdiff_t stride_inner,
34 uint8_t *l,
int col,
int x,
int w,
36 int p,
int ss_h,
int ss_v,
int bytesperpixel)
39 int have_top = row > 0 || y > 0;
40 int have_left = col >
td->tile_col_start || x > 0;
41 int have_right = x <
w - 1;
43 static const uint8_t mode_conv[10][2 ][2 ] = {
68 uint8_t needs_topleft:1;
69 uint8_t needs_topright:1;
70 uint8_t invert_left:1;
74 [
DC_PRED] = { .needs_top = 1, .needs_left = 1 },
83 [
HOR_UP_PRED] = { .needs_left = 1, .invert_left = 1 },
94 mode = mode_conv[
mode][have_left][have_top];
95 if (edges[
mode].needs_top) {
96 uint8_t *top, *topleft;
97 int n_px_need = 4 << tx, n_px_have = (((
s->cols - col) << !ss_h) - x) * 4;
100 if (tx ==
TX_4X4 && edges[
mode].needs_topright && have_right)
107 top = !(row & 7) && !y ?
108 s->intra_pred_data[p] + (col * (8 >> ss_h) + x * 4) * bytesperpixel :
109 y == 0 ? &dst_edge[-stride_edge] : &dst_inner[-stride_inner];
111 topleft = !(row & 7) && !y ?
112 s->intra_pred_data[p] + (col * (8 >> ss_h) + x * 4) * bytesperpixel :
113 y == 0 || x == 0 ? &dst_edge[-stride_edge] :
114 &dst_inner[-stride_inner];
118 (!edges[
mode].needs_topleft || (have_left && top == topleft)) &&
119 (tx !=
TX_4X4 || !edges[
mode].needs_topright || have_right) &&
120 n_px_need + n_px_need_tr <= n_px_have) {
124 if (n_px_need <= n_px_have) {
125 memcpy(*
a, top, n_px_need * bytesperpixel);
127 #define memset_bpp(c, i1, v, i2, num) do { \
128 if (bytesperpixel == 1) { \
129 memset(&(c)[(i1)], (v)[(i2)], (num)); \
131 int n, val = AV_RN16A(&(v)[(i2) * 2]); \
132 for (n = 0; n < (num); n++) { \
133 AV_WN16A(&(c)[((i1) + n) * 2], val); \
137 memcpy(*
a, top, n_px_have * bytesperpixel);
138 memset_bpp(*
a, n_px_have, (*
a), n_px_have - 1, n_px_need - n_px_have);
141 #define memset_val(c, val, num) do { \
142 if (bytesperpixel == 1) { \
143 memset((c), (val), (num)); \
146 for (n = 0; n < (num); n++) { \
147 AV_WN16A(&(c)[n * 2], (val)); \
153 if (edges[
mode].needs_topleft) {
154 if (have_left && have_top) {
155 #define assign_bpp(c, i1, v, i2) do { \
156 if (bytesperpixel == 1) { \
157 (c)[(i1)] = (v)[(i2)]; \
159 AV_COPY16(&(c)[(i1) * 2], &(v)[(i2) * 2]); \
164 #define assign_val(c, i, v) do { \
165 if (bytesperpixel == 1) { \
168 AV_WN16A(&(c)[(i) * 2], (v)); \
171 assign_val((*
a), -1, (128 << (bpp - 8)) + (have_top ? +1 : -1));
174 if (tx ==
TX_4X4 && edges[
mode].needs_topright) {
175 if (have_top && have_right &&
176 n_px_need + n_px_need_tr <= n_px_have) {
177 memcpy(&(*
a)[4 * bytesperpixel], &top[4 * bytesperpixel], 4 * bytesperpixel);
184 if (edges[
mode].needs_left) {
186 int n_px_need = 4 << tx,
i, n_px_have = (((
s->rows - row) << !ss_v) - y) * 4;
187 uint8_t *dst = x == 0 ? dst_edge : dst_inner;
188 ptrdiff_t
stride = x == 0 ? stride_edge : stride_inner;
190 if (edges[
mode].invert_left) {
191 if (n_px_need <= n_px_have) {
192 for (
i = 0;
i < n_px_need;
i++)
195 for (
i = 0;
i < n_px_have;
i++)
197 memset_bpp(l, n_px_have, l, n_px_have - 1, n_px_need - n_px_have);
200 if (n_px_need <= n_px_have) {
201 for (
i = 0;
i < n_px_need;
i++)
204 for (
i = 0;
i < n_px_have;
i++)
206 memset_bpp(l, 0, l, n_px_need - n_px_have, n_px_need - n_px_have);
210 memset_val(l, (128 << (bpp - 8)) + 1, 4 << tx);
218 ptrdiff_t uv_off,
int bytesperpixel)
222 int row =
td->row, col =
td->col;
225 int end_x =
FFMIN(2 * (
s->cols - col), w4);
226 int end_y =
FFMIN(2 * (
s->rows - row), h4);
227 int tx = 4 *
s->s.h.lossless +
b->tx, uvtx =
b->uvtx + 4 *
s->s.h.lossless;
228 int uvstep1d = 1 <<
b->uvtx, p;
229 uint8_t *dst =
td->dst[0], *dst_r =
s->s.frames[
CUR_FRAME].tf.f->data[0] + y_off;
233 for (n = 0, y = 0; y < end_y; y += step1d) {
234 uint8_t *ptr = dst, *ptr_r = dst_r;
235 for (x = 0; x < end_x; x += step1d, ptr += 4 * step1d * bytesperpixel,
236 ptr_r += 4 * step1d * bytesperpixel, n +=
step) {
239 uint8_t *
a = &a_buf[32];
245 ptr,
td->y_stride, l,
246 col, x, w4, row, y,
b->tx, 0, 0, 0, bytesperpixel);
247 s->dsp.intra_pred[
b->tx][
mode](ptr,
td->y_stride, l,
a);
249 s->dsp.itxfm_add[tx][txtp](ptr,
td->y_stride,
250 td->block + 16 * n * bytesperpixel, eob);
252 dst_r += 4 * step1d *
s->s.frames[
CUR_FRAME].tf.f->linesize[0];
253 dst += 4 * step1d *
td->y_stride;
260 step = 1 << (
b->uvtx * 2);
261 for (p = 0; p < 2; p++) {
262 dst =
td->dst[1 + p];
263 dst_r =
s->s.frames[
CUR_FRAME].tf.f->data[1 + p] + uv_off;
264 for (n = 0, y = 0; y < end_y; y += uvstep1d) {
265 uint8_t *ptr = dst, *ptr_r = dst_r;
266 for (x = 0; x < end_x; x += uvstep1d, ptr += 4 * uvstep1d * bytesperpixel,
267 ptr_r += 4 * uvstep1d * bytesperpixel, n +=
step) {
268 int mode =
b->uvmode;
269 uint8_t *
a = &a_buf[32];
274 ptr,
td->uv_stride, l, col, x, w4, row, y,
275 b->uvtx, p + 1,
s->ss_h,
s->ss_v, bytesperpixel);
276 s->dsp.intra_pred[
b->uvtx][
mode](ptr,
td->uv_stride, l,
a);
278 s->dsp.itxfm_add[uvtx][
DCT_DCT](ptr,
td->uv_stride,
279 td->uvblock[p] + 16 * n * bytesperpixel, eob);
281 dst_r += 4 * uvstep1d *
s->s.frames[
CUR_FRAME].tf.f->linesize[1];
282 dst += 4 * uvstep1d *
td->uv_stride;
298 uint8_t *dst, ptrdiff_t dst_stride,
299 const uint8_t *
ref, ptrdiff_t ref_stride,
301 ptrdiff_t y, ptrdiff_t x,
const VP56mv *
mv,
302 int bw,
int bh,
int w,
int h,
int bytesperpixel)
305 int mx =
mv->x, my =
mv->y,
th;
309 ref += y * ref_stride + x * bytesperpixel;
315 th = (y + bh + 4 * !!my + 7) >> 6;
320 if (x < !!mx * 3 || y < !!my * 3 ||
321 x + !!mx * 4 >
w - bw || y + !!my * 5 >
h - bh) {
322 s->vdsp.emulated_edge_mc(
td->edge_emu_buffer,
323 ref - !!my * 3 * ref_stride - !!mx * 3 * bytesperpixel,
325 bw + !!mx * 7, bh + !!my * 7,
326 x - !!mx * 3, y - !!my * 3,
w,
h);
327 ref =
td->edge_emu_buffer + !!my * 3 * 160 + !!mx * 3 * bytesperpixel;
330 mc[!!mx][!!my](dst, dst_stride,
ref, ref_stride, bh, mx << 1, my << 1);
334 uint8_t *dst_u, uint8_t *dst_v,
335 ptrdiff_t dst_stride,
336 const uint8_t *ref_u, ptrdiff_t src_stride_u,
337 const uint8_t *ref_v, ptrdiff_t src_stride_v,
339 ptrdiff_t y, ptrdiff_t x,
const VP56mv *
mv,
340 int bw,
int bh,
int w,
int h,
int bytesperpixel)
343 int mx =
mv->x * (1 << !
s->ss_h), my =
mv->y * (1 << !
s->ss_v),
th;
347 ref_u += y * src_stride_u + x * bytesperpixel;
348 ref_v += y * src_stride_v + x * bytesperpixel;
354 th = (y + bh + 4 * !!my + 7) >> (6 -
s->ss_v);
359 if (x < !!mx * 3 || y < !!my * 3 ||
360 x + !!mx * 4 >
w - bw || y + !!my * 5 >
h - bh) {
361 s->vdsp.emulated_edge_mc(
td->edge_emu_buffer,
362 ref_u - !!my * 3 * src_stride_u - !!mx * 3 * bytesperpixel,
364 bw + !!mx * 7, bh + !!my * 7,
365 x - !!mx * 3, y - !!my * 3,
w,
h);
366 ref_u =
td->edge_emu_buffer + !!my * 3 * 160 + !!mx * 3 * bytesperpixel;
367 mc[!!mx][!!my](dst_u, dst_stride, ref_u, 160, bh, mx, my);
369 s->vdsp.emulated_edge_mc(
td->edge_emu_buffer,
370 ref_v - !!my * 3 * src_stride_v - !!mx * 3 * bytesperpixel,
372 bw + !!mx * 7, bh + !!my * 7,
373 x - !!mx * 3, y - !!my * 3,
w,
h);
374 ref_v =
td->edge_emu_buffer + !!my * 3 * 160 + !!mx * 3 * bytesperpixel;
375 mc[!!mx][!!my](dst_v, dst_stride, ref_v, 160, bh, mx, my);
377 mc[!!mx][!!my](dst_u, dst_stride, ref_u, src_stride_u, bh, mx, my);
378 mc[!!mx][!!my](dst_v, dst_stride, ref_v, src_stride_v, bh, mx, my);
382 #define mc_luma_dir(td, mc, dst, dst_ls, src, src_ls, tref, row, col, mv, \
383 px, py, pw, ph, bw, bh, w, h, i) \
384 mc_luma_unscaled(td, s->dsp.mc, dst, dst_ls, src, src_ls, tref, row, col, \
385 mv, bw, bh, w, h, bytesperpixel)
386 #define mc_chroma_dir(td, mc, dstu, dstv, dst_ls, srcu, srcu_ls, srcv, srcv_ls, tref, \
387 row, col, mv, px, py, pw, ph, bw, bh, w, h, i) \
388 mc_chroma_unscaled(td, s->dsp.mc, dstu, dstv, dst_ls, srcu, srcu_ls, srcv, srcv_ls, tref, \
389 row, col, mv, bw, bh, w, h, bytesperpixel)
391 #define FN(x) x##_8bpp
392 #define BYTES_PER_PIXEL 1
395 #undef BYTES_PER_PIXEL
396 #define FN(x) x##_16bpp
397 #define BYTES_PER_PIXEL 2
402 #undef BYTES_PER_PIXEL
407 uint8_t *dst, ptrdiff_t dst_stride,
408 const uint8_t *
ref, ptrdiff_t ref_stride,
410 ptrdiff_t y, ptrdiff_t x,
const VP56mv *in_mv,
411 int px,
int py,
int pw,
int ph,
412 int bw,
int bh,
int w,
int h,
int bytesperpixel,
413 const uint16_t *
scale,
const uint8_t *
step)
419 y, x, in_mv, bw, bh,
w,
h, bytesperpixel);
421 #define scale_mv(n, dim) (((int64_t)(n) * scale[dim]) >> 14)
423 int refbw_m1, refbh_m1;
427 mv.x =
av_clip(in_mv->
x, -(x + pw - px + 4) * 8, (
s->cols * 8 - x + px + 3) * 8);
428 mv.y =
av_clip(in_mv->
y, -(y + ph - py + 4) * 8, (
s->rows * 8 - y + py + 3) * 8);
437 ref += y * ref_stride + x * bytesperpixel;
440 refbw_m1 = ((bw - 1) *
step[0] + mx) >> 4;
441 refbh_m1 = ((bh - 1) *
step[1] + my) >> 4;
445 th = (y + refbh_m1 + 4 + 7) >> 6;
450 if (x < 3 || y < 3 || x + 4 >=
w - refbw_m1 || y + 5 >=
h - refbh_m1) {
451 s->vdsp.emulated_edge_mc(
td->edge_emu_buffer,
452 ref - 3 * ref_stride - 3 * bytesperpixel,
454 refbw_m1 + 8, refbh_m1 + 8,
456 ref =
td->edge_emu_buffer + 3 * 288 + 3 * bytesperpixel;
459 smc(dst, dst_stride,
ref, ref_stride, bh, mx, my,
step[0],
step[1]);
465 uint8_t *dst_u, uint8_t *dst_v,
466 ptrdiff_t dst_stride,
467 const uint8_t *ref_u, ptrdiff_t src_stride_u,
468 const uint8_t *ref_v, ptrdiff_t src_stride_v,
470 ptrdiff_t y, ptrdiff_t x,
const VP56mv *in_mv,
471 int px,
int py,
int pw,
int ph,
472 int bw,
int bh,
int w,
int h,
int bytesperpixel,
473 const uint16_t *
scale,
const uint8_t *
step)
479 ref_v, src_stride_v, ref_frame,
480 y, x, in_mv, bw, bh,
w,
h, bytesperpixel);
483 int refbw_m1, refbh_m1;
489 mv.x =
av_clip(in_mv->
x, -(x + pw - px + 4) * 16, (
s->cols * 4 - x + px + 3) * 16);
492 mv.x =
av_clip(in_mv->
x, -(x + pw - px + 4) * 8, (
s->cols * 8 - x + px + 3) * 8);
497 mv.y =
av_clip(in_mv->
y, -(y + ph - py + 4) * 16, (
s->rows * 4 - y + py + 3) * 16);
500 mv.y =
av_clip(in_mv->
y, -(y + ph - py + 4) * 8, (
s->rows * 8 - y + py + 3) * 8);
506 ref_u += y * src_stride_u + x * bytesperpixel;
507 ref_v += y * src_stride_v + x * bytesperpixel;
510 refbw_m1 = ((bw - 1) *
step[0] + mx) >> 4;
511 refbh_m1 = ((bh - 1) *
step[1] + my) >> 4;
515 th = (y + refbh_m1 + 4 + 7) >> (6 -
s->ss_v);
520 if (x < 3 || y < 3 || x + 4 >=
w - refbw_m1 || y + 5 >=
h - refbh_m1) {
521 s->vdsp.emulated_edge_mc(
td->edge_emu_buffer,
522 ref_u - 3 * src_stride_u - 3 * bytesperpixel,
524 refbw_m1 + 8, refbh_m1 + 8,
526 ref_u =
td->edge_emu_buffer + 3 * 288 + 3 * bytesperpixel;
527 smc(dst_u, dst_stride, ref_u, 288, bh, mx, my,
step[0],
step[1]);
529 s->vdsp.emulated_edge_mc(
td->edge_emu_buffer,
530 ref_v - 3 * src_stride_v - 3 * bytesperpixel,
532 refbw_m1 + 8, refbh_m1 + 8,
534 ref_v =
td->edge_emu_buffer + 3 * 288 + 3 * bytesperpixel;
535 smc(dst_v, dst_stride, ref_v, 288, bh, mx, my,
step[0],
step[1]);
537 smc(dst_u, dst_stride, ref_u, src_stride_u, bh, mx, my,
step[0],
step[1]);
538 smc(dst_v, dst_stride, ref_v, src_stride_v, bh, mx, my,
step[0],
step[1]);
543 #define mc_luma_dir(td, mc, dst, dst_ls, src, src_ls, tref, row, col, mv, \
544 px, py, pw, ph, bw, bh, w, h, i) \
545 mc_luma_scaled(td, s->dsp.s##mc, s->dsp.mc, dst, dst_ls, src, src_ls, tref, row, col, \
546 mv, px, py, pw, ph, bw, bh, w, h, bytesperpixel, \
547 s->mvscale[b->ref[i]], s->mvstep[b->ref[i]])
548 #define mc_chroma_dir(td, mc, dstu, dstv, dst_ls, srcu, srcu_ls, srcv, srcv_ls, tref, \
549 row, col, mv, px, py, pw, ph, bw, bh, w, h, i) \
550 mc_chroma_scaled(td, s->dsp.s##mc, s->dsp.mc, dstu, dstv, dst_ls, srcu, srcu_ls, srcv, srcv_ls, tref, \
551 row, col, mv, px, py, pw, ph, bw, bh, w, h, bytesperpixel, \
552 s->mvscale[b->ref[i]], s->mvstep[b->ref[i]])
554 #define FN(x) x##_scaled_8bpp
555 #define BYTES_PER_PIXEL 1
558 #undef BYTES_PER_PIXEL
559 #define FN(x) x##_scaled_16bpp
560 #define BYTES_PER_PIXEL 2
565 #undef BYTES_PER_PIXEL
572 int row =
td->row, col =
td->col;
576 if (!
s->td->error_info) {
579 "reference frame has invalid dimensions\n");
584 if (
s->mvscale[
b->ref[0]][0] || (
b->comp &&
s->mvscale[
b->ref[1]][0])) {
585 if (bytesperpixel == 1) {
586 inter_pred_scaled_8bpp(
td);
588 inter_pred_scaled_16bpp(
td);
591 if (bytesperpixel == 1) {
594 inter_pred_16bpp(
td);
603 int end_x =
FFMIN(2 * (
s->cols - col), w4);
604 int end_y =
FFMIN(2 * (
s->rows - row), h4);
605 int tx = 4 *
s->s.h.lossless +
b->tx, uvtx =
b->uvtx + 4 *
s->s.h.lossless;
606 int uvstep1d = 1 <<
b->uvtx, p;
607 uint8_t *dst =
td->dst[0];
610 for (n = 0, y = 0; y < end_y; y += step1d) {
612 for (x = 0; x < end_x; x += step1d,
613 ptr += 4 * step1d * bytesperpixel, n +=
step) {
617 s->dsp.itxfm_add[tx][
DCT_DCT](ptr,
td->y_stride,
618 td->block + 16 * n * bytesperpixel, eob);
620 dst += 4 *
td->y_stride * step1d;
626 step = 1 << (
b->uvtx * 2);
627 for (p = 0; p < 2; p++) {
628 dst =
td->dst[p + 1];
629 for (n = 0, y = 0; y < end_y; y += uvstep1d) {
631 for (x = 0; x < end_x; x += uvstep1d,
632 ptr += 4 * uvstep1d * bytesperpixel, n +=
step) {
636 s->dsp.itxfm_add[uvtx][
DCT_DCT](ptr,
td->uv_stride,
637 td->uvblock[p] + 16 * n * bytesperpixel, eob);
639 dst += 4 * uvstep1d *
td->uv_stride;