LCOV - code coverage report
Current view: top level - libavcodec - vp9recon.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 273 283 96.5 %
Date: 2017-12-11 20:48:03 Functions: 11 11 100.0 %

          Line data    Source code
       1             : /*
       2             :  * VP9 compatible video decoder
       3             :  *
       4             :  * Copyright (C) 2013 Ronald S. Bultje <rsbultje gmail com>
       5             :  * Copyright (C) 2013 Clément Bœsch <u pkh me>
       6             :  *
       7             :  * This file is part of FFmpeg.
       8             :  *
       9             :  * FFmpeg is free software; you can redistribute it and/or
      10             :  * modify it under the terms of the GNU Lesser General Public
      11             :  * License as published by the Free Software Foundation; either
      12             :  * version 2.1 of the License, or (at your option) any later version.
      13             :  *
      14             :  * FFmpeg is distributed in the hope that it will be useful,
      15             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      16             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      17             :  * Lesser General Public License for more details.
      18             :  *
      19             :  * You should have received a copy of the GNU Lesser General Public
      20             :  * License along with FFmpeg; if not, write to the Free Software
      21             :  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
      22             :  */
      23             : 
      24             : #include "libavutil/avassert.h"
      25             : 
      26             : #include "avcodec.h"
      27             : #include "internal.h"
      28             : #include "videodsp.h"
      29             : #include "vp9data.h"
      30             : #include "vp9dec.h"
      31             : 
      32     1354602 : static av_always_inline int check_intra_mode(VP9TileData *td, int mode, uint8_t **a,
      33             :                                              uint8_t *dst_edge, ptrdiff_t stride_edge,
      34             :                                              uint8_t *dst_inner, ptrdiff_t stride_inner,
      35             :                                              uint8_t *l, int col, int x, int w,
      36             :                                              int row, int y, enum TxfmMode tx,
      37             :                                              int p, int ss_h, int ss_v, int bytesperpixel)
      38             : {
      39     1354602 :     VP9Context *s = td->s;
      40     1354602 :     int have_top = row > 0 || y > 0;
      41     1354602 :     int have_left = col > td->tile_col_start || x > 0;
      42     1354602 :     int have_right = x < w - 1;
      43     1354602 :     int bpp = s->s.h.bpp;
      44             :     static const uint8_t mode_conv[10][2 /* have_left */][2 /* have_top */] = {
      45             :         [VERT_PRED]            = { { DC_127_PRED,          VERT_PRED            },
      46             :                                    { DC_127_PRED,          VERT_PRED            } },
      47             :         [HOR_PRED]             = { { DC_129_PRED,          DC_129_PRED          },
      48             :                                    { HOR_PRED,             HOR_PRED             } },
      49             :         [DC_PRED]              = { { DC_128_PRED,          TOP_DC_PRED          },
      50             :                                    { LEFT_DC_PRED,         DC_PRED              } },
      51             :         [DIAG_DOWN_LEFT_PRED]  = { { DC_127_PRED,          DIAG_DOWN_LEFT_PRED  },
      52             :                                    { DC_127_PRED,          DIAG_DOWN_LEFT_PRED  } },
      53             :         [DIAG_DOWN_RIGHT_PRED] = { { DIAG_DOWN_RIGHT_PRED, DIAG_DOWN_RIGHT_PRED },
      54             :                                    { DIAG_DOWN_RIGHT_PRED, DIAG_DOWN_RIGHT_PRED } },
      55             :         [VERT_RIGHT_PRED]      = { { VERT_RIGHT_PRED,      VERT_RIGHT_PRED      },
      56             :                                    { VERT_RIGHT_PRED,      VERT_RIGHT_PRED      } },
      57             :         [HOR_DOWN_PRED]        = { { HOR_DOWN_PRED,        HOR_DOWN_PRED        },
      58             :                                    { HOR_DOWN_PRED,        HOR_DOWN_PRED        } },
      59             :         [VERT_LEFT_PRED]       = { { DC_127_PRED,          VERT_LEFT_PRED       },
      60             :                                    { DC_127_PRED,          VERT_LEFT_PRED       } },
      61             :         [HOR_UP_PRED]          = { { DC_129_PRED,          DC_129_PRED          },
      62             :                                    { HOR_UP_PRED,          HOR_UP_PRED          } },
      63             :         [TM_VP8_PRED]          = { { DC_129_PRED,          VERT_PRED            },
      64             :                                    { HOR_PRED,             TM_VP8_PRED          } },
      65             :     };
      66             :     static const struct {
      67             :         uint8_t needs_left:1;
      68             :         uint8_t needs_top:1;
      69             :         uint8_t needs_topleft:1;
      70             :         uint8_t needs_topright:1;
      71             :         uint8_t invert_left:1;
      72             :     } edges[N_INTRA_PRED_MODES] = {
      73             :         [VERT_PRED]            = { .needs_top  = 1 },
      74             :         [HOR_PRED]             = { .needs_left = 1 },
      75             :         [DC_PRED]              = { .needs_top  = 1, .needs_left = 1 },
      76             :         [DIAG_DOWN_LEFT_PRED]  = { .needs_top  = 1, .needs_topright = 1 },
      77             :         [DIAG_DOWN_RIGHT_PRED] = { .needs_left = 1, .needs_top = 1,
      78             :                                    .needs_topleft = 1 },
      79             :         [VERT_RIGHT_PRED]      = { .needs_left = 1, .needs_top = 1,
      80             :                                    .needs_topleft = 1 },
      81             :         [HOR_DOWN_PRED]        = { .needs_left = 1, .needs_top = 1,
      82             :                                    .needs_topleft = 1 },
      83             :         [VERT_LEFT_PRED]       = { .needs_top  = 1, .needs_topright = 1 },
      84             :         [HOR_UP_PRED]          = { .needs_left = 1, .invert_left = 1 },
      85             :         [TM_VP8_PRED]          = { .needs_left = 1, .needs_top = 1,
      86             :                                    .needs_topleft = 1 },
      87             :         [LEFT_DC_PRED]         = { .needs_left = 1 },
      88             :         [TOP_DC_PRED]          = { .needs_top  = 1 },
      89             :         [DC_128_PRED]          = { 0 },
      90             :         [DC_127_PRED]          = { 0 },
      91             :         [DC_129_PRED]          = { 0 }
      92             :     };
      93             : 
      94             :     av_assert2(mode >= 0 && mode < 10);
      95     1354602 :     mode = mode_conv[mode][have_left][have_top];
      96     1354602 :     if (edges[mode].needs_top) {
      97             :         uint8_t *top, *topleft;
      98      927856 :         int n_px_need = 4 << tx, n_px_have = (((s->cols - col) << !ss_h) - x) * 4;
      99      927856 :         int n_px_need_tr = 0;
     100             : 
     101      927856 :         if (tx == TX_4X4 && edges[mode].needs_topright && have_right)
     102       20959 :             n_px_need_tr = 4;
     103             : 
     104             :         // if top of sb64-row, use s->intra_pred_data[] instead of
     105             :         // dst[-stride] for intra prediction (it contains pre- instead of
     106             :         // post-loopfilter data)
     107      927856 :         if (have_top) {
     108     2023688 :             top = !(row & 7) && !y ?
     109     1847330 :                 s->intra_pred_data[p] + (col * (8 >> ss_h) + x * 4) * bytesperpixel :
     110      832417 :                 y == 0 ? &dst_edge[-stride_edge] : &dst_inner[-stride_inner];
     111      923665 :             if (have_left)
     112     1963490 :                 topleft = !(row & 7) && !y ?
     113     1793274 :                     s->intra_pred_data[p] + (col * (8 >> ss_h) + x * 4) * bytesperpixel :
     114      955386 :                     y == 0 || x == 0 ? &dst_edge[-stride_edge] :
     115      145924 :                     &dst_inner[-stride_inner];
     116             :         }
     117             : 
     118     1851521 :         if (have_top &&
     119     1169906 :             (!edges[mode].needs_topleft || (have_left && top == topleft)) &&
     120     1580011 :             (tx != TX_4X4 || !edges[mode].needs_topright || have_right) &&
     121      888790 :             n_px_need + n_px_need_tr <= n_px_have) {
     122      888636 :             *a = top;
     123             :         } else {
     124       39220 :             if (have_top) {
     125       35029 :                 if (n_px_need <= n_px_have) {
     126       34891 :                     memcpy(*a, top, n_px_need * bytesperpixel);
     127             :                 } else {
     128             : #define memset_bpp(c, i1, v, i2, num) do { \
     129             :     if (bytesperpixel == 1) { \
     130             :         memset(&(c)[(i1)], (v)[(i2)], (num)); \
     131             :     } else { \
     132             :         int n, val = AV_RN16A(&(v)[(i2) * 2]); \
     133             :         for (n = 0; n < (num); n++) { \
     134             :             AV_WN16A(&(c)[((i1) + n) * 2], val); \
     135             :         } \
     136             :     } \
     137             : } while (0)
     138         138 :                     memcpy(*a, top, n_px_have * bytesperpixel);
     139         138 :                     memset_bpp(*a, n_px_have, (*a), n_px_have - 1, n_px_need - n_px_have);
     140             :                 }
     141             :             } else {
     142             : #define memset_val(c, val, num) do { \
     143             :     if (bytesperpixel == 1) { \
     144             :         memset((c), (val), (num)); \
     145             :     } else { \
     146             :         int n; \
     147             :         for (n = 0; n < (num); n++) { \
     148             :             AV_WN16A(&(c)[n * 2], (val)); \
     149             :         } \
     150             :     } \
     151             : } while (0)
     152        4191 :                 memset_val(*a, (128 << (bpp - 8)) - 1, n_px_need);
     153             :             }
     154       39220 :             if (edges[mode].needs_topleft) {
     155        6915 :                 if (have_left && have_top) {
     156             : #define assign_bpp(c, i1, v, i2) do { \
     157             :     if (bytesperpixel == 1) { \
     158             :         (c)[(i1)] = (v)[(i2)]; \
     159             :     } else { \
     160             :         AV_COPY16(&(c)[(i1) * 2], &(v)[(i2) * 2]); \
     161             :     } \
     162             : } while (0)
     163          51 :                     assign_bpp(*a, -1, topleft, -1);
     164             :                 } else {
     165             : #define assign_val(c, i, v) do { \
     166             :     if (bytesperpixel == 1) { \
     167             :         (c)[(i)] = (v); \
     168             :     } else { \
     169             :         AV_WN16A(&(c)[(i) * 2], (v)); \
     170             :     } \
     171             : } while (0)
     172        6864 :                     assign_val((*a), -1, (128 << (bpp - 8)) + (have_top ? +1 : -1));
     173             :                 }
     174             :             }
     175       39220 :             if (tx == TX_4X4 && edges[mode].needs_topright) {
     176       32219 :                 if (have_top && have_right &&
     177          16 :                     n_px_need + n_px_need_tr <= n_px_have) {
     178           0 :                     memcpy(&(*a)[4 * bytesperpixel], &top[4 * bytesperpixel], 4 * bytesperpixel);
     179             :                 } else {
     180       32203 :                     memset_bpp(*a, 4, *a, 3, 4);
     181             :                 }
     182             :             }
     183             :         }
     184             :     }
     185     1354602 :     if (edges[mode].needs_left) {
     186     1118570 :         if (have_left) {
     187     1115648 :             int n_px_need = 4 << tx, i, n_px_have = (((s->rows - row) << !ss_v) - y) * 4;
     188     1115648 :             uint8_t *dst = x == 0 ? dst_edge : dst_inner;
     189     1115648 :             ptrdiff_t stride = x == 0 ? stride_edge : stride_inner;
     190             : 
     191     1115648 :             if (edges[mode].invert_left) {
     192       58832 :                 if (n_px_need <= n_px_have) {
     193      350708 :                     for (i = 0; i < n_px_need; i++)
     194      291884 :                         assign_bpp(l, i, &dst[i * stride], -1);
     195             :                 } else {
     196         104 :                     for (i = 0; i < n_px_have; i++)
     197          96 :                         assign_bpp(l, i, &dst[i * stride], -1);
     198           8 :                     memset_bpp(l, n_px_have, l, n_px_have - 1, n_px_need - n_px_have);
     199             :                 }
     200             :             } else {
     201     1056816 :                 if (n_px_need <= n_px_have) {
     202     6744718 :                     for (i = 0; i < n_px_need; i++)
     203     5689188 :                         assign_bpp(l, n_px_need - 1 - i, &dst[i * stride], -1);
     204             :                 } else {
     205        7758 :                     for (i = 0; i < n_px_have; i++)
     206        6472 :                         assign_bpp(l, n_px_need - 1 - i, &dst[i * stride], -1);
     207        1286 :                     memset_bpp(l, 0, l, n_px_need - n_px_have, n_px_need - n_px_have);
     208             :                 }
     209             :             }
     210             :         } else {
     211        2922 :             memset_val(l, (128 << (bpp - 8)) + 1, 4 << tx);
     212             :         }
     213             :     }
     214             : 
     215     1354602 :     return mode;
     216             : }
     217             : 
     218      250164 : static av_always_inline void intra_recon(VP9TileData *td, ptrdiff_t y_off,
     219             :                                          ptrdiff_t uv_off, int bytesperpixel)
     220             : {
     221      250164 :     VP9Context *s = td->s;
     222      250164 :     VP9Block *b = td->b;
     223      250164 :     int row = td->row, col = td->col;
     224      250164 :     int w4 = ff_vp9_bwh_tab[1][b->bs][0] << 1, step1d = 1 << b->tx, n;
     225      250164 :     int h4 = ff_vp9_bwh_tab[1][b->bs][1] << 1, x, y, step = 1 << (b->tx * 2);
     226      250164 :     int end_x = FFMIN(2 * (s->cols - col), w4);
     227      250164 :     int end_y = FFMIN(2 * (s->rows - row), h4);
     228      250164 :     int tx = 4 * s->s.h.lossless + b->tx, uvtx = b->uvtx + 4 * s->s.h.lossless;
     229      250164 :     int uvstep1d = 1 << b->uvtx, p;
     230      250164 :     uint8_t *dst = td->dst[0], *dst_r = s->s.frames[CUR_FRAME].tf.f->data[0] + y_off;
     231      250164 :     LOCAL_ALIGNED_32(uint8_t, a_buf, [96]);
     232      250164 :     LOCAL_ALIGNED_32(uint8_t, l, [64]);
     233             : 
     234      645755 :     for (n = 0, y = 0; y < end_y; y += step1d) {
     235      395591 :         uint8_t *ptr = dst, *ptr_r = dst_r;
     236     2276914 :         for (x = 0; x < end_x; x += step1d, ptr += 4 * step1d * bytesperpixel,
     237      742866 :                                ptr_r += 4 * step1d * bytesperpixel, n += step) {
     238     1805868 :             int mode = b->mode[b->bs > BS_8x8 && b->tx == TX_4X4 ?
     239     1063002 :                                y * 2 + x : 0];
     240      742866 :             uint8_t *a = &a_buf[32];
     241      742866 :             enum TxfmType txtp = ff_vp9_intra_txfm_type[mode];
     242      742866 :             int eob = b->skip ? 0 : b->tx > TX_8X8 ? AV_RN16A(&td->eob[n]) : td->eob[n];
     243             : 
     244     1485732 :             mode = check_intra_mode(td, mode, &a, ptr_r,
     245      742866 :                                     s->s.frames[CUR_FRAME].tf.f->linesize[0],
     246             :                                     ptr, td->y_stride, l,
     247             :                                     col, x, w4, row, y, b->tx, 0, 0, 0, bytesperpixel);
     248      742866 :             s->dsp.intra_pred[b->tx][mode](ptr, td->y_stride, l, a);
     249      742866 :             if (eob)
     250     1052998 :                 s->dsp.itxfm_add[tx][txtp](ptr, td->y_stride,
     251      526499 :                                            td->block + 16 * n * bytesperpixel, eob);
     252             :         }
     253      395591 :         dst_r += 4 * step1d * s->s.frames[CUR_FRAME].tf.f->linesize[0];
     254      395591 :         dst   += 4 * step1d * td->y_stride;
     255             :     }
     256             : 
     257             :     // U/V
     258      250164 :     w4    >>= s->ss_h;
     259      250164 :     end_x >>= s->ss_h;
     260      250164 :     end_y >>= s->ss_v;
     261      250164 :     step = 1 << (b->uvtx * 2);
     262      750492 :     for (p = 0; p < 2; p++) {
     263      500328 :         dst   = td->dst[1 + p];
     264      500328 :         dst_r = s->s.frames[CUR_FRAME].tf.f->data[1 + p] + uv_off;
     265     1038872 :         for (n = 0, y = 0; y < end_y; y += uvstep1d) {
     266      538544 :             uint8_t *ptr = dst, *ptr_r = dst_r;
     267     2300560 :             for (x = 0; x < end_x; x += uvstep1d, ptr += 4 * uvstep1d * bytesperpixel,
     268      611736 :                                    ptr_r += 4 * uvstep1d * bytesperpixel, n += step) {
     269      611736 :                 int mode = b->uvmode;
     270      611736 :                 uint8_t *a = &a_buf[32];
     271      611736 :                 int eob = b->skip ? 0 : b->uvtx > TX_8X8 ? AV_RN16A(&td->uveob[p][n]) : td->uveob[p][n];
     272             : 
     273     1835208 :                 mode = check_intra_mode(td, mode, &a, ptr_r,
     274      611736 :                                         s->s.frames[CUR_FRAME].tf.f->linesize[1],
     275             :                                         ptr, td->uv_stride, l, col, x, w4, row, y,
     276     1223472 :                                         b->uvtx, p + 1, s->ss_h, s->ss_v, bytesperpixel);
     277      611736 :                 s->dsp.intra_pred[b->uvtx][mode](ptr, td->uv_stride, l, a);
     278      611736 :                 if (eob)
     279      439180 :                     s->dsp.itxfm_add[uvtx][DCT_DCT](ptr, td->uv_stride,
     280      219590 :                                                     td->uvblock[p] + 16 * n * bytesperpixel, eob);
     281             :             }
     282      538544 :             dst_r += 4 * uvstep1d * s->s.frames[CUR_FRAME].tf.f->linesize[1];
     283      538544 :             dst   += 4 * uvstep1d * td->uv_stride;
     284             :         }
     285             :     }
     286      250164 : }
     287             : 
     288      245954 : void ff_vp9_intra_recon_8bpp(VP9TileData *td, ptrdiff_t y_off, ptrdiff_t uv_off)
     289             : {
     290      245954 :     intra_recon(td, y_off, uv_off, 1);
     291      245954 : }
     292             : 
     293        4210 : void ff_vp9_intra_recon_16bpp(VP9TileData *td, ptrdiff_t y_off, ptrdiff_t uv_off)
     294             : {
     295        4210 :     intra_recon(td, y_off, uv_off, 2);
     296        4210 : }
     297             : 
     298      639705 : static av_always_inline void mc_luma_unscaled(VP9TileData *td, vp9_mc_func (*mc)[2],
     299             :                                               uint8_t *dst, ptrdiff_t dst_stride,
     300             :                                               const uint8_t *ref, ptrdiff_t ref_stride,
     301             :                                               ThreadFrame *ref_frame,
     302             :                                               ptrdiff_t y, ptrdiff_t x, const VP56mv *mv,
     303             :                                               int bw, int bh, int w, int h, int bytesperpixel)
     304             : {
     305      639705 :     VP9Context *s = td->s;
     306      639705 :     int mx = mv->x, my = mv->y, th;
     307             : 
     308      639705 :     y += my >> 3;
     309      639705 :     x += mx >> 3;
     310      639705 :     ref += y * ref_stride + x * bytesperpixel;
     311      639705 :     mx &= 7;
     312      639705 :     my &= 7;
     313             :     // FIXME bilinear filter only needs 0/1 pixels, not 3/4
     314             :     // we use +7 because the last 7 pixels of each sbrow can be changed in
     315             :     // the longest loopfilter of the next sbrow
     316      639705 :     th = (y + bh + 4 * !!my + 7) >> 6;
     317      639705 :     ff_thread_await_progress(ref_frame, FFMAX(th, 0), 0);
     318             :     // The arm/aarch64 _hv filters read one more row than what actually is
     319             :     // needed, so switch to emulated edge one pixel sooner vertically
     320             :     // (!!my * 5) than horizontally (!!mx * 4).
     321     1257097 :     if (x < !!mx * 3 || y < !!my * 3 ||
     322     1208595 :         x + !!mx * 4 > w - bw || y + !!my * 5 > h - bh) {
     323      415116 :         s->vdsp.emulated_edge_mc(td->edge_emu_buffer,
     324       69186 :                                  ref - !!my * 3 * ref_stride - !!mx * 3 * bytesperpixel,
     325             :                                  160, ref_stride,
     326      138372 :                                  bw + !!mx * 7, bh + !!my * 7,
     327      138372 :                                  x - !!mx * 3, y - !!my * 3, w, h);
     328       69186 :         ref = td->edge_emu_buffer + !!my * 3 * 160 + !!mx * 3 * bytesperpixel;
     329       69186 :         ref_stride = 160;
     330             :     }
     331      639705 :     mc[!!mx][!!my](dst, dst_stride, ref, ref_stride, bh, mx << 1, my << 1);
     332      639705 : }
     333             : 
     334      559630 : static av_always_inline void mc_chroma_unscaled(VP9TileData *td, vp9_mc_func (*mc)[2],
     335             :                                                 uint8_t *dst_u, uint8_t *dst_v,
     336             :                                                 ptrdiff_t dst_stride,
     337             :                                                 const uint8_t *ref_u, ptrdiff_t src_stride_u,
     338             :                                                 const uint8_t *ref_v, ptrdiff_t src_stride_v,
     339             :                                                 ThreadFrame *ref_frame,
     340             :                                                 ptrdiff_t y, ptrdiff_t x, const VP56mv *mv,
     341             :                                                 int bw, int bh, int w, int h, int bytesperpixel)
     342             : {
     343      559630 :     VP9Context *s = td->s;
     344      559630 :     int mx = mv->x * (1 << !s->ss_h), my = mv->y * (1 << !s->ss_v), th;
     345             : 
     346      559630 :     y += my >> 4;
     347      559630 :     x += mx >> 4;
     348      559630 :     ref_u += y * src_stride_u + x * bytesperpixel;
     349      559630 :     ref_v += y * src_stride_v + x * bytesperpixel;
     350      559630 :     mx &= 15;
     351      559630 :     my &= 15;
     352             :     // FIXME bilinear filter only needs 0/1 pixels, not 3/4
     353             :     // we use +7 because the last 7 pixels of each sbrow can be changed in
     354             :     // the longest loopfilter of the next sbrow
     355      559630 :     th = (y + bh + 4 * !!my + 7) >> (6 - s->ss_v);
     356      559630 :     ff_thread_await_progress(ref_frame, FFMAX(th, 0), 0);
     357             :     // The arm/aarch64 _hv filters read one more row than what actually is
     358             :     // needed, so switch to emulated edge one pixel sooner vertically
     359             :     // (!!my * 5) than horizontally (!!mx * 4).
     360     1089711 :     if (x < !!mx * 3 || y < !!my * 3 ||
     361     1029382 :         x + !!mx * 4 > w - bw || y + !!my * 5 > h - bh) {
     362      511134 :         s->vdsp.emulated_edge_mc(td->edge_emu_buffer,
     363       85189 :                                  ref_u - !!my * 3 * src_stride_u - !!mx * 3 * bytesperpixel,
     364             :                                  160, src_stride_u,
     365      170378 :                                  bw + !!mx * 7, bh + !!my * 7,
     366      170378 :                                  x - !!mx * 3, y - !!my * 3, w, h);
     367       85189 :         ref_u = td->edge_emu_buffer + !!my * 3 * 160 + !!mx * 3 * bytesperpixel;
     368       85189 :         mc[!!mx][!!my](dst_u, dst_stride, ref_u, 160, bh, mx, my);
     369             : 
     370      511134 :         s->vdsp.emulated_edge_mc(td->edge_emu_buffer,
     371       85189 :                                  ref_v - !!my * 3 * src_stride_v - !!mx * 3 * bytesperpixel,
     372             :                                  160, src_stride_v,
     373      170378 :                                  bw + !!mx * 7, bh + !!my * 7,
     374      170378 :                                  x - !!mx * 3, y - !!my * 3, w, h);
     375       85189 :         ref_v = td->edge_emu_buffer + !!my * 3 * 160 + !!mx * 3 * bytesperpixel;
     376       85189 :         mc[!!mx][!!my](dst_v, dst_stride, ref_v, 160, bh, mx, my);
     377             :     } else {
     378      474441 :         mc[!!mx][!!my](dst_u, dst_stride, ref_u, src_stride_u, bh, mx, my);
     379      474441 :         mc[!!mx][!!my](dst_v, dst_stride, ref_v, src_stride_v, bh, mx, my);
     380             :     }
     381      559630 : }
     382             : 
     383             : #define mc_luma_dir(td, mc, dst, dst_ls, src, src_ls, tref, row, col, mv, \
     384             :                     px, py, pw, ph, bw, bh, w, h, i) \
     385             :     mc_luma_unscaled(td, s->dsp.mc, dst, dst_ls, src, src_ls, tref, row, col, \
     386             :                      mv, bw, bh, w, h, bytesperpixel)
     387             : #define mc_chroma_dir(td, mc, dstu, dstv, dst_ls, srcu, srcu_ls, srcv, srcv_ls, tref, \
     388             :                       row, col, mv, px, py, pw, ph, bw, bh, w, h, i) \
     389             :     mc_chroma_unscaled(td, s->dsp.mc, dstu, dstv, dst_ls, srcu, srcu_ls, srcv, srcv_ls, tref, \
     390             :                        row, col, mv, bw, bh, w, h, bytesperpixel)
     391             : #define SCALED 0
     392             : #define FN(x) x##_8bpp
     393             : #define BYTES_PER_PIXEL 1
     394             : #include "vp9_mc_template.c"
     395             : #undef FN
     396             : #undef BYTES_PER_PIXEL
     397             : #define FN(x) x##_16bpp
     398             : #define BYTES_PER_PIXEL 2
     399             : #include "vp9_mc_template.c"
     400             : #undef mc_luma_dir
     401             : #undef mc_chroma_dir
     402             : #undef FN
     403             : #undef BYTES_PER_PIXEL
     404             : #undef SCALED
     405             : 
     406         689 : static av_always_inline void mc_luma_scaled(VP9TileData *td, vp9_scaled_mc_func smc,
     407             :                                             vp9_mc_func (*mc)[2],
     408             :                                             uint8_t *dst, ptrdiff_t dst_stride,
     409             :                                             const uint8_t *ref, ptrdiff_t ref_stride,
     410             :                                             ThreadFrame *ref_frame,
     411             :                                             ptrdiff_t y, ptrdiff_t x, const VP56mv *in_mv,
     412             :                                             int px, int py, int pw, int ph,
     413             :                                             int bw, int bh, int w, int h, int bytesperpixel,
     414             :                                             const uint16_t *scale, const uint8_t *step)
     415             : {
     416         689 :     VP9Context *s = td->s;
     417         689 :     if (s->s.frames[CUR_FRAME].tf.f->width == ref_frame->f->width &&
     418           0 :         s->s.frames[CUR_FRAME].tf.f->height == ref_frame->f->height) {
     419           0 :         mc_luma_unscaled(td, mc, dst, dst_stride, ref, ref_stride, ref_frame,
     420             :                          y, x, in_mv, bw, bh, w, h, bytesperpixel);
     421             :     } else {
     422             : #define scale_mv(n, dim) (((int64_t)(n) * scale[dim]) >> 14)
     423             :     int mx, my;
     424             :     int refbw_m1, refbh_m1;
     425             :     int th;
     426             :     VP56mv mv;
     427             : 
     428         689 :     mv.x = av_clip(in_mv->x, -(x + pw - px + 4) * 8, (s->cols * 8 - x + px + 3) * 8);
     429         689 :     mv.y = av_clip(in_mv->y, -(y + ph - py + 4) * 8, (s->rows * 8 - y + py + 3) * 8);
     430             :     // BUG libvpx seems to scale the two components separately. This introduces
     431             :     // rounding errors but we have to reproduce them to be exactly compatible
     432             :     // with the output from libvpx...
     433         689 :     mx = scale_mv(mv.x * 2, 0) + scale_mv(x * 16, 0);
     434         689 :     my = scale_mv(mv.y * 2, 1) + scale_mv(y * 16, 1);
     435             : 
     436         689 :     y = my >> 4;
     437         689 :     x = mx >> 4;
     438         689 :     ref += y * ref_stride + x * bytesperpixel;
     439         689 :     mx &= 15;
     440         689 :     my &= 15;
     441         689 :     refbw_m1 = ((bw - 1) * step[0] + mx) >> 4;
     442         689 :     refbh_m1 = ((bh - 1) * step[1] + my) >> 4;
     443             :     // FIXME bilinear filter only needs 0/1 pixels, not 3/4
     444             :     // we use +7 because the last 7 pixels of each sbrow can be changed in
     445             :     // the longest loopfilter of the next sbrow
     446         689 :     th = (y + refbh_m1 + 4 + 7) >> 6;
     447         689 :     ff_thread_await_progress(ref_frame, FFMAX(th, 0), 0);
     448             :     // The arm/aarch64 _hv filters read one more row than what actually is
     449             :     // needed, so switch to emulated edge one pixel sooner vertically
     450             :     // (y + 5 >= h - refbh_m1) than horizontally (x + 4 >= w - refbw_m1).
     451         689 :     if (x < 3 || y < 3 || x + 4 >= w - refbw_m1 || y + 5 >= h - refbh_m1) {
     452         536 :         s->vdsp.emulated_edge_mc(td->edge_emu_buffer,
     453         134 :                                  ref - 3 * ref_stride - 3 * bytesperpixel,
     454             :                                  288, ref_stride,
     455             :                                  refbw_m1 + 8, refbh_m1 + 8,
     456         268 :                                  x - 3, y - 3, w, h);
     457         134 :         ref = td->edge_emu_buffer + 3 * 288 + 3 * bytesperpixel;
     458         134 :         ref_stride = 288;
     459             :     }
     460         689 :     smc(dst, dst_stride, ref, ref_stride, bh, mx, my, step[0], step[1]);
     461             :     }
     462         689 : }
     463             : 
     464         689 : static av_always_inline void mc_chroma_scaled(VP9TileData *td, vp9_scaled_mc_func smc,
     465             :                                               vp9_mc_func (*mc)[2],
     466             :                                               uint8_t *dst_u, uint8_t *dst_v,
     467             :                                               ptrdiff_t dst_stride,
     468             :                                               const uint8_t *ref_u, ptrdiff_t src_stride_u,
     469             :                                               const uint8_t *ref_v, ptrdiff_t src_stride_v,
     470             :                                               ThreadFrame *ref_frame,
     471             :                                               ptrdiff_t y, ptrdiff_t x, const VP56mv *in_mv,
     472             :                                               int px, int py, int pw, int ph,
     473             :                                               int bw, int bh, int w, int h, int bytesperpixel,
     474             :                                               const uint16_t *scale, const uint8_t *step)
     475             : {
     476         689 :     VP9Context *s = td->s;
     477         689 :     if (s->s.frames[CUR_FRAME].tf.f->width == ref_frame->f->width &&
     478           0 :         s->s.frames[CUR_FRAME].tf.f->height == ref_frame->f->height) {
     479           0 :         mc_chroma_unscaled(td, mc, dst_u, dst_v, dst_stride, ref_u, src_stride_u,
     480             :                            ref_v, src_stride_v, ref_frame,
     481             :                            y, x, in_mv, bw, bh, w, h, bytesperpixel);
     482             :     } else {
     483             :     int mx, my;
     484             :     int refbw_m1, refbh_m1;
     485             :     int th;
     486             :     VP56mv mv;
     487             : 
     488         689 :     if (s->ss_h) {
     489             :         // BUG https://code.google.com/p/webm/issues/detail?id=820
     490         689 :         mv.x = av_clip(in_mv->x, -(x + pw - px + 4) * 16, (s->cols * 4 - x + px + 3) * 16);
     491         689 :         mx = scale_mv(mv.x, 0) + (scale_mv(x * 16, 0) & ~15) + (scale_mv(x * 32, 0) & 15);
     492             :     } else {
     493           0 :         mv.x = av_clip(in_mv->x, -(x + pw - px + 4) * 8, (s->cols * 8 - x + px + 3) * 8);
     494           0 :         mx = scale_mv(mv.x * 2, 0) + scale_mv(x * 16, 0);
     495             :     }
     496         689 :     if (s->ss_v) {
     497             :         // BUG https://code.google.com/p/webm/issues/detail?id=820
     498         689 :         mv.y = av_clip(in_mv->y, -(y + ph - py + 4) * 16, (s->rows * 4 - y + py + 3) * 16);
     499         689 :         my = scale_mv(mv.y, 1) + (scale_mv(y * 16, 1) & ~15) + (scale_mv(y * 32, 1) & 15);
     500             :     } else {
     501           0 :         mv.y = av_clip(in_mv->y, -(y + ph - py + 4) * 8, (s->rows * 8 - y + py + 3) * 8);
     502           0 :         my = scale_mv(mv.y * 2, 1) + scale_mv(y * 16, 1);
     503             :     }
     504             : #undef scale_mv
     505         689 :     y = my >> 4;
     506         689 :     x = mx >> 4;
     507         689 :     ref_u += y * src_stride_u + x * bytesperpixel;
     508         689 :     ref_v += y * src_stride_v + x * bytesperpixel;
     509         689 :     mx &= 15;
     510         689 :     my &= 15;
     511         689 :     refbw_m1 = ((bw - 1) * step[0] + mx) >> 4;
     512         689 :     refbh_m1 = ((bh - 1) * step[1] + my) >> 4;
     513             :     // FIXME bilinear filter only needs 0/1 pixels, not 3/4
     514             :     // we use +7 because the last 7 pixels of each sbrow can be changed in
     515             :     // the longest loopfilter of the next sbrow
     516         689 :     th = (y + refbh_m1 + 4 + 7) >> (6 - s->ss_v);
     517         689 :     ff_thread_await_progress(ref_frame, FFMAX(th, 0), 0);
     518             :     // The arm/aarch64 _hv filters read one more row than what actually is
     519             :     // needed, so switch to emulated edge one pixel sooner vertically
     520             :     // (y + 5 >= h - refbh_m1) than horizontally (x + 4 >= w - refbw_m1).
     521         689 :     if (x < 3 || y < 3 || x + 4 >= w - refbw_m1 || y + 5 >= h - refbh_m1) {
     522         708 :         s->vdsp.emulated_edge_mc(td->edge_emu_buffer,
     523         177 :                                  ref_u - 3 * src_stride_u - 3 * bytesperpixel,
     524             :                                  288, src_stride_u,
     525             :                                  refbw_m1 + 8, refbh_m1 + 8,
     526         354 :                                  x - 3, y - 3, w, h);
     527         177 :         ref_u = td->edge_emu_buffer + 3 * 288 + 3 * bytesperpixel;
     528         177 :         smc(dst_u, dst_stride, ref_u, 288, bh, mx, my, step[0], step[1]);
     529             : 
     530         708 :         s->vdsp.emulated_edge_mc(td->edge_emu_buffer,
     531         177 :                                  ref_v - 3 * src_stride_v - 3 * bytesperpixel,
     532             :                                  288, src_stride_v,
     533             :                                  refbw_m1 + 8, refbh_m1 + 8,
     534         354 :                                  x - 3, y - 3, w, h);
     535         177 :         ref_v = td->edge_emu_buffer + 3 * 288 + 3 * bytesperpixel;
     536         177 :         smc(dst_v, dst_stride, ref_v, 288, bh, mx, my, step[0], step[1]);
     537             :     } else {
     538         512 :         smc(dst_u, dst_stride, ref_u, src_stride_u, bh, mx, my, step[0], step[1]);
     539         512 :         smc(dst_v, dst_stride, ref_v, src_stride_v, bh, mx, my, step[0], step[1]);
     540             :     }
     541             :     }
     542         689 : }
     543             : 
     544             : #define mc_luma_dir(td, mc, dst, dst_ls, src, src_ls, tref, row, col, mv, \
     545             :                     px, py, pw, ph, bw, bh, w, h, i) \
     546             :     mc_luma_scaled(td, s->dsp.s##mc, s->dsp.mc, dst, dst_ls, src, src_ls, tref, row, col, \
     547             :                    mv, px, py, pw, ph, bw, bh, w, h, bytesperpixel, \
     548             :                    s->mvscale[b->ref[i]], s->mvstep[b->ref[i]])
     549             : #define mc_chroma_dir(td, mc, dstu, dstv, dst_ls, srcu, srcu_ls, srcv, srcv_ls, tref, \
     550             :                       row, col, mv, px, py, pw, ph, bw, bh, w, h, i) \
     551             :     mc_chroma_scaled(td, s->dsp.s##mc, s->dsp.mc, dstu, dstv, dst_ls, srcu, srcu_ls, srcv, srcv_ls, tref, \
     552             :                      row, col, mv, px, py, pw, ph, bw, bh, w, h, bytesperpixel, \
     553             :                      s->mvscale[b->ref[i]], s->mvstep[b->ref[i]])
     554             : #define SCALED 1
     555             : #define FN(x) x##_scaled_8bpp
     556             : #define BYTES_PER_PIXEL 1
     557             : #include "vp9_mc_template.c"
     558             : #undef FN
     559             : #undef BYTES_PER_PIXEL
     560             : #define FN(x) x##_scaled_16bpp
     561             : #define BYTES_PER_PIXEL 2
     562             : #include "vp9_mc_template.c"
     563             : #undef mc_luma_dir
     564             : #undef mc_chroma_dir
     565             : #undef FN
     566             : #undef BYTES_PER_PIXEL
     567             : #undef SCALED
     568             : 
     569      528478 : static av_always_inline void inter_recon(VP9TileData *td, int bytesperpixel)
     570             : {
     571      528478 :     VP9Context *s = td->s;
     572      528478 :     VP9Block *b = td->b;
     573      528478 :     int row = td->row, col = td->col;
     574             : 
     575      528478 :     if (s->mvscale[b->ref[0]][0] || (b->comp && s->mvscale[b->ref[1]][0])) {
     576        1378 :         if (bytesperpixel == 1) {
     577         689 :             inter_pred_scaled_8bpp(td);
     578             :         } else {
     579           0 :             inter_pred_scaled_16bpp(td);
     580             :         }
     581             :     } else {
     582      527789 :         if (bytesperpixel == 1) {
     583      513341 :             inter_pred_8bpp(td);
     584             :         } else {
     585       14448 :             inter_pred_16bpp(td);
     586             :         }
     587             :     }
     588             : 
     589      528478 :     if (!b->skip) {
     590             :         /* mostly copied intra_recon() */
     591             : 
     592      137266 :         int w4 = ff_vp9_bwh_tab[1][b->bs][0] << 1, step1d = 1 << b->tx, n;
     593      137266 :         int h4 = ff_vp9_bwh_tab[1][b->bs][1] << 1, x, y, step = 1 << (b->tx * 2);
     594      137266 :         int end_x = FFMIN(2 * (s->cols - col), w4);
     595      137266 :         int end_y = FFMIN(2 * (s->rows - row), h4);
     596      137266 :         int tx = 4 * s->s.h.lossless + b->tx, uvtx = b->uvtx + 4 * s->s.h.lossless;
     597      137266 :         int uvstep1d = 1 << b->uvtx, p;
     598      137266 :         uint8_t *dst = td->dst[0];
     599             : 
     600             :         // y itxfm add
     601      363642 :         for (n = 0, y = 0; y < end_y; y += step1d) {
     602      226376 :             uint8_t *ptr = dst;
     603     1294606 :             for (x = 0; x < end_x; x += step1d,
     604      420927 :                  ptr += 4 * step1d * bytesperpixel, n += step) {
     605      420927 :                 int eob = b->tx > TX_8X8 ? AV_RN16A(&td->eob[n]) : td->eob[n];
     606             : 
     607      420927 :                 if (eob)
     608      479092 :                     s->dsp.itxfm_add[tx][DCT_DCT](ptr, td->y_stride,
     609      239546 :                                                   td->block + 16 * n * bytesperpixel, eob);
     610             :             }
     611      226376 :             dst += 4 * td->y_stride * step1d;
     612             :         }
     613             : 
     614             :         // uv itxfm add
     615      137266 :         end_x >>= s->ss_h;
     616      137266 :         end_y >>= s->ss_v;
     617      137266 :         step = 1 << (b->uvtx * 2);
     618      411798 :         for (p = 0; p < 2; p++) {
     619      274532 :             dst = td->dst[p + 1];
     620      573100 :             for (n = 0, y = 0; y < end_y; y += uvstep1d) {
     621      298568 :                 uint8_t *ptr = dst;
     622     1277636 :                 for (x = 0; x < end_x; x += uvstep1d,
     623      340250 :                      ptr += 4 * uvstep1d * bytesperpixel, n += step) {
     624      340250 :                     int eob = b->uvtx > TX_8X8 ? AV_RN16A(&td->uveob[p][n]) : td->uveob[p][n];
     625             : 
     626      340250 :                     if (eob)
     627      132736 :                         s->dsp.itxfm_add[uvtx][DCT_DCT](ptr, td->uv_stride,
     628       66368 :                                                         td->uvblock[p] + 16 * n * bytesperpixel, eob);
     629             :                 }
     630      298568 :                 dst += 4 * uvstep1d * td->uv_stride;
     631             :             }
     632             :         }
     633             :     }
     634      528478 : }
     635             : 
     636      514030 : void ff_vp9_inter_recon_8bpp(VP9TileData *td)
     637             : {
     638      514030 :     inter_recon(td, 1);
     639      514030 : }
     640             : 
     641       14448 : void ff_vp9_inter_recon_16bpp(VP9TileData *td)
     642             : {
     643       14448 :     inter_recon(td, 2);
     644       14448 : }

Generated by: LCOV version 1.13