34 uint8_t *dst_edge, ptrdiff_t stride_edge,
35 uint8_t *dst_inner, ptrdiff_t stride_inner,
36 uint8_t *l,
int col,
int x,
int w,
38 int p,
int ss_h,
int ss_v,
int bytesperpixel)
41 int have_top = row > 0 || y > 0;
43 int have_right = x <
w - 1;
45 static const uint8_t mode_conv[10][2 ][2 ] = {
70 uint8_t needs_topleft:1;
71 uint8_t needs_topright:1;
72 uint8_t invert_left:1;
76 [
DC_PRED] = { .needs_top = 1, .needs_left = 1 },
85 [
HOR_UP_PRED] = { .needs_left = 1, .invert_left = 1 },
96 mode = mode_conv[
mode][have_left][have_top];
97 if (edges[
mode].needs_top) {
98 uint8_t *top, *topleft;
99 int n_px_need = 4 << tx, n_px_have = (((
s->cols - col) << !ss_h) - x) * 4;
100 int n_px_need_tr = 0;
102 if (tx ==
TX_4X4 && edges[
mode].needs_topright && have_right)
109 top = !(row & 7) && !y ?
110 s->intra_pred_data[p] + (col * (8 >> ss_h) + x * 4) * bytesperpixel :
111 y == 0 ? &dst_edge[-stride_edge] : &dst_inner[-stride_inner];
113 topleft = !(row & 7) && !y ?
114 s->intra_pred_data[p] + (col * (8 >> ss_h) + x * 4) * bytesperpixel :
115 y == 0 || x == 0 ? &dst_edge[-stride_edge] :
116 &dst_inner[-stride_inner];
120 (!edges[
mode].needs_topleft || (have_left && top == topleft)) &&
121 (tx !=
TX_4X4 || !edges[
mode].needs_topright || have_right) &&
122 n_px_need + n_px_need_tr <= n_px_have) {
126 if (n_px_need <= n_px_have) {
127 memcpy(*
a, top, n_px_need * bytesperpixel);
129 #define memset_bpp(c, i1, v, i2, num) do { \
130 if (bytesperpixel == 1) { \
131 memset(&(c)[(i1)], (v)[(i2)], (num)); \
133 int n, val = AV_RN16A(&(v)[(i2) * 2]); \
134 for (n = 0; n < (num); n++) { \
135 AV_WN16A(&(c)[((i1) + n) * 2], val); \
139 memcpy(*
a, top, n_px_have * bytesperpixel);
140 memset_bpp(*
a, n_px_have, (*
a), n_px_have - 1, n_px_need - n_px_have);
143 #define memset_val(c, val, num) do { \
144 if (bytesperpixel == 1) { \
145 memset((c), (val), (num)); \
148 for (n = 0; n < (num); n++) { \
149 AV_WN16A(&(c)[n * 2], (val)); \
155 if (edges[
mode].needs_topleft) {
156 if (have_left && have_top) {
157 #define assign_bpp(c, i1, v, i2) do { \
158 if (bytesperpixel == 1) { \
159 (c)[(i1)] = (v)[(i2)]; \
161 AV_COPY16(&(c)[(i1) * 2], &(v)[(i2) * 2]); \
166 #define assign_val(c, i, v) do { \
167 if (bytesperpixel == 1) { \
170 AV_WN16A(&(c)[(i) * 2], (v)); \
173 assign_val((*
a), -1, (128 << (bpp - 8)) + (have_top ? +1 : -1));
176 if (tx ==
TX_4X4 && edges[
mode].needs_topright) {
177 if (have_top && have_right &&
178 n_px_need + n_px_need_tr <= n_px_have) {
179 memcpy(&(*
a)[4 * bytesperpixel], &top[4 * bytesperpixel], 4 * bytesperpixel);
186 if (edges[
mode].needs_left) {
188 int n_px_need = 4 << tx,
i, n_px_have = (((
s->rows - row) << !ss_v) - y) * 4;
189 uint8_t *
dst = x == 0 ? dst_edge : dst_inner;
190 ptrdiff_t
stride = x == 0 ? stride_edge : stride_inner;
192 if (edges[
mode].invert_left) {
193 if (n_px_need <= n_px_have) {
194 for (
i = 0;
i < n_px_need;
i++)
197 for (
i = 0;
i < n_px_have;
i++)
199 memset_bpp(l, n_px_have, l, n_px_have - 1, n_px_need - n_px_have);
202 if (n_px_need <= n_px_have) {
203 for (
i = 0;
i < n_px_need;
i++)
206 for (
i = 0;
i < n_px_have;
i++)
208 memset_bpp(l, 0, l, n_px_need - n_px_have, n_px_need - n_px_have);
212 memset_val(l, (128 << (bpp - 8)) + 1, 4 << tx);
220 ptrdiff_t uv_off,
int bytesperpixel)
224 int row = td->
row, col = td->
col;
227 int end_x =
FFMIN(2 * (
s->cols - col), w4);
228 int end_y =
FFMIN(2 * (
s->rows - row), h4);
229 int tx = 4 *
s->s.h.lossless +
b->tx, uvtx =
b->uvtx + 4 *
s->s.h.lossless;
230 int uvstep1d = 1 <<
b->uvtx, p;
231 uint8_t *
dst = td->
dst[0], *dst_r =
s->s.frames[
CUR_FRAME].tf.f->data[0] + y_off;
235 for (n = 0, y = 0; y < end_y; y += step1d) {
236 uint8_t *ptr =
dst, *ptr_r = dst_r;
237 for (x = 0; x < end_x; x += step1d, ptr += 4 * step1d * bytesperpixel,
238 ptr_r += 4 * step1d * bytesperpixel, n +=
step) {
241 uint8_t *
a = &a_buf[32];
248 col, x, w4, row, y,
b->tx, 0, 0, 0, bytesperpixel);
251 s->dsp.itxfm_add[tx][txtp](ptr, td->
y_stride,
252 td->
block + 16 * n * bytesperpixel, eob);
254 dst_r += 4 * step1d *
s->s.frames[
CUR_FRAME].tf.f->linesize[0];
262 step = 1 << (
b->uvtx * 2);
263 for (p = 0; p < 2; p++) {
265 dst_r =
s->s.frames[
CUR_FRAME].tf.f->data[1 + p] + uv_off;
266 for (n = 0, y = 0; y < end_y; y += uvstep1d) {
267 uint8_t *ptr =
dst, *ptr_r = dst_r;
268 for (x = 0; x < end_x; x += uvstep1d, ptr += 4 * uvstep1d * bytesperpixel,
269 ptr_r += 4 * uvstep1d * bytesperpixel, n +=
step) {
270 int mode =
b->uvmode;
271 uint8_t *
a = &a_buf[32];
276 ptr, td->
uv_stride, l, col, x, w4, row, y,
277 b->uvtx, p + 1,
s->ss_h,
s->ss_v, bytesperpixel);
281 td->
uvblock[p] + 16 * n * bytesperpixel, eob);
283 dst_r += 4 * uvstep1d *
s->s.frames[
CUR_FRAME].tf.f->linesize[1];
300 uint8_t *
dst, ptrdiff_t dst_stride,
301 const uint8_t *
ref, ptrdiff_t ref_stride,
303 ptrdiff_t y, ptrdiff_t x,
const VP9mv *
mv,
304 int bw,
int bh,
int w,
int h,
int bytesperpixel)
311 ref += y * ref_stride + x * bytesperpixel;
317 th = (y + bh + 4 * !!
my + 7) >> 6;
322 if (x < !!
mx * 3 || y < !!
my * 3 ||
323 x + !!
mx * 4 >
w - bw || y + !!
my * 5 >
h - bh) {
325 ref - !!
my * 3 * ref_stride - !!
mx * 3 * bytesperpixel,
327 bw + !!
mx * 7, bh + !!
my * 7,
328 x - !!
mx * 3, y - !!
my * 3,
w,
h);
336 uint8_t *dst_u, uint8_t *dst_v,
337 ptrdiff_t dst_stride,
338 const uint8_t *ref_u, ptrdiff_t src_stride_u,
339 const uint8_t *ref_v, ptrdiff_t src_stride_v,
341 ptrdiff_t y, ptrdiff_t x,
const VP9mv *
mv,
342 int bw,
int bh,
int w,
int h,
int bytesperpixel)
345 int mx =
mv->x * (1 << !
s->ss_h),
my =
mv->y * (1 << !
s->ss_v), th;
349 ref_u += y * src_stride_u + x * bytesperpixel;
350 ref_v += y * src_stride_v + x * bytesperpixel;
356 th = (y + bh + 4 * !!
my + 7) >> (6 -
s->ss_v);
361 if (x < !!
mx * 3 || y < !!
my * 3 ||
362 x + !!
mx * 4 >
w - bw || y + !!
my * 5 >
h - bh) {
364 ref_u - !!
my * 3 * src_stride_u - !!
mx * 3 * bytesperpixel,
366 bw + !!
mx * 7, bh + !!
my * 7,
367 x - !!
mx * 3, y - !!
my * 3,
w,
h);
369 mc[!!
mx][!!
my](dst_u, dst_stride, ref_u, 160, bh,
mx,
my);
372 ref_v - !!
my * 3 * src_stride_v - !!
mx * 3 * bytesperpixel,
374 bw + !!
mx * 7, bh + !!
my * 7,
375 x - !!
mx * 3, y - !!
my * 3,
w,
h);
377 mc[!!
mx][!!
my](dst_v, dst_stride, ref_v, 160, bh,
mx,
my);
379 mc[!!
mx][!!
my](dst_u, dst_stride, ref_u, src_stride_u, bh,
mx,
my);
380 mc[!!
mx][!!
my](dst_v, dst_stride, ref_v, src_stride_v, bh,
mx,
my);
384 #define mc_luma_dir(td, mc, dst, dst_ls, src, src_ls, tref, row, col, mv, \
385 px, py, pw, ph, bw, bh, w, h, i) \
386 mc_luma_unscaled(td, s->dsp.mc, dst, dst_ls, src, src_ls, tref, row, col, \
387 mv, bw, bh, w, h, bytesperpixel)
388 #define mc_chroma_dir(td, mc, dstu, dstv, dst_ls, srcu, srcu_ls, srcv, srcv_ls, tref, \
389 row, col, mv, px, py, pw, ph, bw, bh, w, h, i) \
390 mc_chroma_unscaled(td, s->dsp.mc, dstu, dstv, dst_ls, srcu, srcu_ls, srcv, srcv_ls, tref, \
391 row, col, mv, bw, bh, w, h, bytesperpixel)
393 #define FN(x) x##_8bpp
394 #define BYTES_PER_PIXEL 1
397 #undef BYTES_PER_PIXEL
398 #define FN(x) x##_16bpp
399 #define BYTES_PER_PIXEL 2
404 #undef BYTES_PER_PIXEL
409 uint8_t *
dst, ptrdiff_t dst_stride,
410 const uint8_t *
ref, ptrdiff_t ref_stride,
412 ptrdiff_t y, ptrdiff_t x,
const VP9mv *in_mv,
413 int px,
int py,
int pw,
int ph,
414 int bw,
int bh,
int w,
int h,
int bytesperpixel,
415 const uint16_t *
scale,
const uint8_t *
step)
421 y, x, in_mv, bw, bh,
w,
h, bytesperpixel);
423 #define scale_mv(n, dim) (((int64_t)(n) * scale[dim]) >> 14)
425 int refbw_m1, refbh_m1;
429 mv.x =
av_clip(in_mv->
x, -(x + pw - px + 4) * 8, (
s->cols * 8 - x + px + 3) * 8);
430 mv.y =
av_clip(in_mv->
y, -(y +
ph - py + 4) * 8, (
s->rows * 8 - y + py + 3) * 8);
439 ref += y * ref_stride + x * bytesperpixel;
442 refbw_m1 = ((bw - 1) *
step[0] +
mx) >> 4;
443 refbh_m1 = ((bh - 1) *
step[1] +
my) >> 4;
447 th = (y + refbh_m1 + 4 + 7) >> 6;
452 if (x < 3 || y < 3 || x + 4 >=
w - refbw_m1 || y + 5 >=
h - refbh_m1) {
454 ref - 3 * ref_stride - 3 * bytesperpixel,
456 refbw_m1 + 8, refbh_m1 + 8,
467 uint8_t *dst_u, uint8_t *dst_v,
468 ptrdiff_t dst_stride,
469 const uint8_t *ref_u, ptrdiff_t src_stride_u,
470 const uint8_t *ref_v, ptrdiff_t src_stride_v,
472 ptrdiff_t y, ptrdiff_t x,
const VP9mv *in_mv,
473 int px,
int py,
int pw,
int ph,
474 int bw,
int bh,
int w,
int h,
int bytesperpixel,
475 const uint16_t *
scale,
const uint8_t *
step)
482 y, x, in_mv, bw, bh,
w,
h, bytesperpixel);
485 int refbw_m1, refbh_m1;
491 mv.x =
av_clip(in_mv->
x, -(x + pw - px + 4) * 16, (
s->cols * 4 - x + px + 3) * 16);
494 mv.x =
av_clip(in_mv->
x, -(x + pw - px + 4) * 8, (
s->cols * 8 - x + px + 3) * 8);
499 mv.y =
av_clip(in_mv->
y, -(y +
ph - py + 4) * 16, (
s->rows * 4 - y + py + 3) * 16);
502 mv.y =
av_clip(in_mv->
y, -(y +
ph - py + 4) * 8, (
s->rows * 8 - y + py + 3) * 8);
508 ref_u += y * src_stride_u + x * bytesperpixel;
509 ref_v += y * src_stride_v + x * bytesperpixel;
512 refbw_m1 = ((bw - 1) *
step[0] +
mx) >> 4;
513 refbh_m1 = ((bh - 1) *
step[1] +
my) >> 4;
517 th = (y + refbh_m1 + 4 + 7) >> (6 -
s->ss_v);
522 if (x < 3 || y < 3 || x + 4 >=
w - refbw_m1 || y + 5 >=
h - refbh_m1) {
524 ref_u - 3 * src_stride_u - 3 * bytesperpixel,
526 refbw_m1 + 8, refbh_m1 + 8,
529 smc(dst_u, dst_stride, ref_u, 288, bh,
mx,
my,
step[0],
step[1]);
532 ref_v - 3 * src_stride_v - 3 * bytesperpixel,
534 refbw_m1 + 8, refbh_m1 + 8,
537 smc(dst_v, dst_stride, ref_v, 288, bh,
mx,
my,
step[0],
step[1]);
539 smc(dst_u, dst_stride, ref_u, src_stride_u, bh,
mx,
my,
step[0],
step[1]);
540 smc(dst_v, dst_stride, ref_v, src_stride_v, bh,
mx,
my,
step[0],
step[1]);
545 #define mc_luma_dir(td, mc, dst, dst_ls, src, src_ls, tref, row, col, mv, \
546 px, py, pw, ph, bw, bh, w, h, i) \
547 mc_luma_scaled(td, s->dsp.s##mc, s->dsp.mc, dst, dst_ls, src, src_ls, tref, row, col, \
548 mv, px, py, pw, ph, bw, bh, w, h, bytesperpixel, \
549 s->mvscale[b->ref[i]], s->mvstep[b->ref[i]])
550 #define mc_chroma_dir(td, mc, dstu, dstv, dst_ls, srcu, srcu_ls, srcv, srcv_ls, tref, \
551 row, col, mv, px, py, pw, ph, bw, bh, w, h, i) \
552 mc_chroma_scaled(td, s->dsp.s##mc, s->dsp.mc, dstu, dstv, dst_ls, srcu, srcu_ls, srcv, srcv_ls, tref, \
553 row, col, mv, px, py, pw, ph, bw, bh, w, h, bytesperpixel, \
554 s->mvscale[b->ref[i]], s->mvstep[b->ref[i]])
556 #define FN(x) x##_scaled_8bpp
557 #define BYTES_PER_PIXEL 1
560 #undef BYTES_PER_PIXEL
561 #define FN(x) x##_scaled_16bpp
562 #define BYTES_PER_PIXEL 2
567 #undef BYTES_PER_PIXEL
574 int row = td->
row, col = td->
col;
578 if (!
s->td->error_info) {
581 "reference frame has invalid dimensions\n");
586 if (
s->mvscale[
b->ref[0]][0] || (
b->comp &&
s->mvscale[
b->ref[1]][0])) {
587 if (bytesperpixel == 1) {
588 inter_pred_scaled_8bpp(td);
590 inter_pred_scaled_16bpp(td);
593 if (bytesperpixel == 1) {
596 inter_pred_16bpp(td);
605 int end_x =
FFMIN(2 * (
s->cols - col), w4);
606 int end_y =
FFMIN(2 * (
s->rows - row), h4);
607 int tx = 4 *
s->s.h.lossless +
b->tx, uvtx =
b->uvtx + 4 *
s->s.h.lossless;
608 int uvstep1d = 1 <<
b->uvtx, p;
609 uint8_t *
dst = td->
dst[0];
612 for (n = 0, y = 0; y < end_y; y += step1d) {
614 for (x = 0; x < end_x; x += step1d,
615 ptr += 4 * step1d * bytesperpixel, n +=
step) {
620 td->
block + 16 * n * bytesperpixel, eob);
628 step = 1 << (
b->uvtx * 2);
629 for (p = 0; p < 2; p++) {
631 for (n = 0, y = 0; y < end_y; y += uvstep1d) {
633 for (x = 0; x < end_x; x += uvstep1d,
634 ptr += 4 * uvstep1d * bytesperpixel, n +=
step) {
639 td->
uvblock[p] + 16 * n * bytesperpixel, eob);