]> git.sesse.net Git - ffmpeg/blob - libavcodec/vp9_mc_template.c
Merge commit '6503cbf842a026faec517eb980551089168c7d8a'
[ffmpeg] / libavcodec / vp9_mc_template.c
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 static void FN(inter_pred)(AVCodecContext *ctx)
25 {
26     static const uint8_t bwlog_tab[2][N_BS_SIZES] = {
27         { 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4 },
28         { 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 4, 4 },
29     };
30     VP9Context *s = ctx->priv_data;
31     VP9Block *b = s->b;
32     int row = s->row, col = s->col;
33     ThreadFrame *tref1 = &s->refs[s->refidx[b->ref[0]]], *tref2;
34     AVFrame *ref1 = tref1->f, *ref2;
35     int w1 = ref1->width, h1 = ref1->height, w2, h2;
36     ptrdiff_t ls_y = s->y_stride, ls_uv = s->uv_stride;
37
38     if (b->comp) {
39         tref2 = &s->refs[s->refidx[b->ref[1]]];
40         ref2 = tref2->f;
41         w2 = ref2->width;
42         h2 = ref2->height;
43     }
44
45     // y inter pred
46     if (b->bs > BS_8x8) {
47         if (b->bs == BS_8x4) {
48             mc_luma_dir(s, mc[3][b->filter][0], s->dst[0], ls_y,
49                         ref1->data[0], ref1->linesize[0], tref1,
50                         row << 3, col << 3, &b->mv[0][0], 8, 4, w1, h1, 0);
51             mc_luma_dir(s, mc[3][b->filter][0],
52                         s->dst[0] + 4 * ls_y, ls_y,
53                         ref1->data[0], ref1->linesize[0], tref1,
54                         (row << 3) + 4, col << 3, &b->mv[2][0], 8, 4, w1, h1, 0);
55
56             if (b->comp) {
57                 mc_luma_dir(s, mc[3][b->filter][1], s->dst[0], ls_y,
58                             ref2->data[0], ref2->linesize[0], tref2,
59                             row << 3, col << 3, &b->mv[0][1], 8, 4, w2, h2, 1);
60                 mc_luma_dir(s, mc[3][b->filter][1],
61                             s->dst[0] + 4 * ls_y, ls_y,
62                             ref2->data[0], ref2->linesize[0], tref2,
63                             (row << 3) + 4, col << 3, &b->mv[2][1], 8, 4, w2, h2, 1);
64             }
65         } else if (b->bs == BS_4x8) {
66             mc_luma_dir(s, mc[4][b->filter][0], s->dst[0], ls_y,
67                         ref1->data[0], ref1->linesize[0], tref1,
68                         row << 3, col << 3, &b->mv[0][0], 4, 8, w1, h1, 0);
69             mc_luma_dir(s, mc[4][b->filter][0], s->dst[0] + 4, ls_y,
70                         ref1->data[0], ref1->linesize[0], tref1,
71                         row << 3, (col << 3) + 4, &b->mv[1][0], 4, 8, w1, h1, 0);
72
73             if (b->comp) {
74                 mc_luma_dir(s, mc[4][b->filter][1], s->dst[0], ls_y,
75                             ref2->data[0], ref2->linesize[0], tref2,
76                             row << 3, col << 3, &b->mv[0][1], 4, 8, w2, h2, 1);
77                 mc_luma_dir(s, mc[4][b->filter][1], s->dst[0] + 4, ls_y,
78                             ref2->data[0], ref2->linesize[0], tref2,
79                             row << 3, (col << 3) + 4, &b->mv[1][1], 4, 8, w2, h2, 1);
80             }
81         } else {
82             av_assert2(b->bs == BS_4x4);
83
84             // FIXME if two horizontally adjacent blocks have the same MV,
85             // do a w8 instead of a w4 call
86             mc_luma_dir(s, mc[4][b->filter][0], s->dst[0], ls_y,
87                         ref1->data[0], ref1->linesize[0], tref1,
88                         row << 3, col << 3, &b->mv[0][0], 4, 4, w1, h1, 0);
89             mc_luma_dir(s, mc[4][b->filter][0], s->dst[0] + 4, ls_y,
90                         ref1->data[0], ref1->linesize[0], tref1,
91                         row << 3, (col << 3) + 4, &b->mv[1][0], 4, 4, w1, h1, 0);
92             mc_luma_dir(s, mc[4][b->filter][0],
93                         s->dst[0] + 4 * ls_y, ls_y,
94                         ref1->data[0], ref1->linesize[0], tref1,
95                         (row << 3) + 4, col << 3, &b->mv[2][0], 4, 4, w1, h1, 0);
96             mc_luma_dir(s, mc[4][b->filter][0],
97                         s->dst[0] + 4 * ls_y + 4, ls_y,
98                         ref1->data[0], ref1->linesize[0], tref1,
99                         (row << 3) + 4, (col << 3) + 4, &b->mv[3][0], 4, 4, w1, h1, 0);
100
101             if (b->comp) {
102                 mc_luma_dir(s, mc[4][b->filter][1], s->dst[0], ls_y,
103                             ref2->data[0], ref2->linesize[0], tref2,
104                             row << 3, col << 3, &b->mv[0][1], 4, 4, w2, h2, 1);
105                 mc_luma_dir(s, mc[4][b->filter][1], s->dst[0] + 4, ls_y,
106                             ref2->data[0], ref2->linesize[0], tref2,
107                             row << 3, (col << 3) + 4, &b->mv[1][1], 4, 4, w2, h2, 1);
108                 mc_luma_dir(s, mc[4][b->filter][1],
109                             s->dst[0] + 4 * ls_y, ls_y,
110                             ref2->data[0], ref2->linesize[0], tref2,
111                             (row << 3) + 4, col << 3, &b->mv[2][1], 4, 4, w2, h2, 1);
112                 mc_luma_dir(s, mc[4][b->filter][1],
113                             s->dst[0] + 4 * ls_y + 4, ls_y,
114                             ref2->data[0], ref2->linesize[0], tref2,
115                             (row << 3) + 4, (col << 3) + 4, &b->mv[3][1], 4, 4, w2, h2, 1);
116             }
117         }
118     } else {
119         int bwl = bwlog_tab[0][b->bs];
120         int bw = bwh_tab[0][b->bs][0] * 4, bh = bwh_tab[0][b->bs][1] * 4;
121
122         mc_luma_dir(s, mc[bwl][b->filter][0], s->dst[0], ls_y,
123                     ref1->data[0], ref1->linesize[0], tref1,
124                     row << 3, col << 3, &b->mv[0][0],bw, bh, w1, h1, 0);
125
126         if (b->comp)
127             mc_luma_dir(s, mc[bwl][b->filter][1], s->dst[0], ls_y,
128                         ref2->data[0], ref2->linesize[0], tref2,
129                         row << 3, col << 3, &b->mv[0][1], bw, bh, w2, h2, 1);
130     }
131
132     // uv inter pred
133     {
134         int bwl = bwlog_tab[1][b->bs];
135         int bw = bwh_tab[1][b->bs][0] * 4, bh = bwh_tab[1][b->bs][1] * 4;
136         VP56mv mvuv;
137
138         w1 = (w1 + 1) >> 1;
139         h1 = (h1 + 1) >> 1;
140         if (b->comp) {
141             w2 = (w2 + 1) >> 1;
142             h2 = (h2 + 1) >> 1;
143         }
144         if (b->bs > BS_8x8) {
145             mvuv.x = ROUNDED_DIV(b->mv[0][0].x + b->mv[1][0].x + b->mv[2][0].x + b->mv[3][0].x, 4);
146             mvuv.y = ROUNDED_DIV(b->mv[0][0].y + b->mv[1][0].y + b->mv[2][0].y + b->mv[3][0].y, 4);
147         } else {
148             mvuv = b->mv[0][0];
149         }
150
151         mc_chroma_dir(s, mc[bwl][b->filter][0],
152                       s->dst[1], s->dst[2], ls_uv,
153                       ref1->data[1], ref1->linesize[1],
154                       ref1->data[2], ref1->linesize[2], tref1,
155                       row << 2, col << 2, &mvuv, bw, bh, w1, h1, 0);
156
157         if (b->comp) {
158             if (b->bs > BS_8x8) {
159                 mvuv.x = ROUNDED_DIV(b->mv[0][1].x + b->mv[1][1].x + b->mv[2][1].x + b->mv[3][1].x, 4);
160                 mvuv.y = ROUNDED_DIV(b->mv[0][1].y + b->mv[1][1].y + b->mv[2][1].y + b->mv[3][1].y, 4);
161             } else {
162                 mvuv = b->mv[0][1];
163             }
164             mc_chroma_dir(s, mc[bwl][b->filter][1],
165                           s->dst[1], s->dst[2], ls_uv,
166                           ref2->data[1], ref2->linesize[1],
167                           ref2->data[2], ref2->linesize[2], tref2,
168                           row << 2, col << 2, &mvuv, bw, bh, w2, h2, 1);
169         }
170     }
171 }