Coverage Report

Created: 2026-02-14 06:59

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ffmpeg/libavcodec/cavs.c
Line
Count
Source
1
/*
2
 * Chinese AVS video (AVS1-P2, JiZhun profile) decoder.
3
 * Copyright (c) 2006  Stefan Gehrer <stefan.gehrer@gmx.de>
4
 *
5
 * This file is part of FFmpeg.
6
 *
7
 * FFmpeg is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU Lesser General Public
9
 * License as published by the Free Software Foundation; either
10
 * version 2.1 of the License, or (at your option) any later version.
11
 *
12
 * FFmpeg is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
 * Lesser General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Lesser General Public
18
 * License along with FFmpeg; if not, write to the Free Software
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
 */
21
22
/**
23
 * @file
24
 * Chinese AVS video (AVS1-P2, JiZhun profile) decoder
25
 * @author Stefan Gehrer <stefan.gehrer@gmx.de>
26
 */
27
28
#include "libavutil/mem.h"
29
#include "avcodec.h"
30
#include "golomb.h"
31
#include "h264chroma.h"
32
#include "idctdsp.h"
33
#include "mathops.h"
34
#include "qpeldsp.h"
35
#include "cavs.h"
36
37
static const uint8_t alpha_tab[64] = {
38
     0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  1,  2,  2,  2,  3,  3,
39
     4,  4,  5,  5,  6,  7,  8,  9, 10, 11, 12, 13, 15, 16, 18, 20,
40
    22, 24, 26, 28, 30, 33, 33, 35, 35, 36, 37, 37, 39, 39, 42, 44,
41
    46, 48, 50, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64
42
};
43
44
static const uint8_t beta_tab[64] = {
45
     0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  1,  1,  1,  2,  2,  2,
46
     2,  2,  3,  3,  3,  3,  4,  4,  4,  4,  5,  5,  5,  5,  6,  6,
47
     6,  7,  7,  7,  8,  8,  8,  9,  9, 10, 10, 11, 11, 12, 13, 14,
48
    15, 16, 17, 18, 19, 20, 21, 22, 23, 23, 24, 24, 25, 25, 26, 27
49
};
50
51
static const uint8_t tc_tab[64] = {
52
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
53
    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2,
54
    2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4,
55
    5, 5, 5, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9
56
};
57
58
/** mark block as unavailable, i.e. out of picture
59
 *  or not yet decoded */
60
static const cavs_vector un_mv = { 0, 0, 1, NOT_AVAIL };
61
62
static const int8_t left_modifier_l[8] = {  0, -1,  6, -1, -1, 7, 6, 7 };
63
static const int8_t top_modifier_l[8]  = { -1,  1,  5, -1, -1, 5, 7, 7 };
64
static const int8_t left_modifier_c[7] = {  5, -1,  2, -1,  6, 5, 6 };
65
static const int8_t top_modifier_c[7]  = {  4,  1, -1, -1,  4, 6, 6 };
66
67
/*****************************************************************************
68
 *
69
 * in-loop deblocking filter
70
 *
71
 ****************************************************************************/
72
73
static inline int get_bs(cavs_vector *mvP, cavs_vector *mvQ, int b)
74
19.0M
{
75
19.0M
    if ((mvP->ref == REF_INTRA) || (mvQ->ref == REF_INTRA))
76
41.8k
        return 2;
77
19.0M
    if((abs(mvP->x - mvQ->x) >= 4) ||
78
17.9M
       (abs(mvP->y - mvQ->y) >= 4) ||
79
17.6M
       (mvP->ref != mvQ->ref))
80
5.03M
        return 1;
81
14.0M
    if (b) {
82
12.3M
        mvP += MV_BWD_OFFS;
83
12.3M
        mvQ += MV_BWD_OFFS;
84
12.3M
        if((abs(mvP->x - mvQ->x) >= 4) ||
85
11.3M
           (abs(mvP->y - mvQ->y) >= 4) ||
86
11.2M
           (mvP->ref != mvQ->ref))
87
1.77M
            return 1;
88
12.3M
    }
89
12.2M
    return 0;
90
14.0M
}
91
92
#define SET_PARAMS                                                \
93
8.51M
    alpha = alpha_tab[av_clip_uintp2(qp_avg + h->alpha_offset, 6)];  \
94
8.51M
    beta  =  beta_tab[av_clip_uintp2(qp_avg + h->beta_offset,  6)];  \
95
8.51M
    tc    =    tc_tab[av_clip_uintp2(qp_avg + h->alpha_offset, 6)];
96
97
/**
98
 * in-loop deblocking filter for a single macroblock
99
 *
100
 * boundary strength (bs) mapping:
101
 *
102
 * --4---5--
103
 * 0   2   |
104
 * | 6 | 7 |
105
 * 1   3   |
106
 * ---------
107
 */
108
void ff_cavs_filter(AVSContext *h, enum cavs_mb mb_type)
109
3.46M
{
110
3.46M
    uint8_t bs[8];
111
3.46M
    int qp_avg, alpha, beta, tc;
112
3.46M
    int i;
113
114
    /* save un-deblocked lines */
115
3.46M
    h->topleft_border_y = h->top_border_y[h->mbx * 16 + 15];
116
3.46M
    h->topleft_border_u = h->top_border_u[h->mbx * 10 + 8];
117
3.46M
    h->topleft_border_v = h->top_border_v[h->mbx * 10 + 8];
118
3.46M
    memcpy(&h->top_border_y[h->mbx * 16],     h->cy + 15 * h->l_stride, 16);
119
3.46M
    memcpy(&h->top_border_u[h->mbx * 10 + 1], h->cu +  7 * h->c_stride, 8);
120
3.46M
    memcpy(&h->top_border_v[h->mbx * 10 + 1], h->cv +  7 * h->c_stride, 8);
121
31.1M
    for (i = 0; i < 8; i++) {
122
27.7M
        h->left_border_y[i * 2 + 1] = *(h->cy + 15 + (i * 2 + 0) * h->l_stride);
123
27.7M
        h->left_border_y[i * 2 + 2] = *(h->cy + 15 + (i * 2 + 1) * h->l_stride);
124
27.7M
        h->left_border_u[i + 1]     = *(h->cu + 7  +  i          * h->c_stride);
125
27.7M
        h->left_border_v[i + 1]     = *(h->cv + 7  +  i          * h->c_stride);
126
27.7M
    }
127
3.46M
    if (!h->loop_filter_disable) {
128
        /* determine bs */
129
3.09M
        if (mb_type == I_8X8)
130
77.2k
            memset(bs, 2, 8);
131
3.01M
        else {
132
3.01M
            memset(bs, 0, 8);
133
3.01M
            if (ff_cavs_partition_flags[mb_type] & SPLITV) {
134
1.75M
                bs[2] = get_bs(&h->mv[MV_FWD_X0], &h->mv[MV_FWD_X1], mb_type > P_8X8);
135
1.75M
                bs[3] = get_bs(&h->mv[MV_FWD_X2], &h->mv[MV_FWD_X3], mb_type > P_8X8);
136
1.75M
            }
137
3.01M
            if (ff_cavs_partition_flags[mb_type] & SPLITH) {
138
1.75M
                bs[6] = get_bs(&h->mv[MV_FWD_X0], &h->mv[MV_FWD_X2], mb_type > P_8X8);
139
1.75M
                bs[7] = get_bs(&h->mv[MV_FWD_X1], &h->mv[MV_FWD_X3], mb_type > P_8X8);
140
1.75M
            }
141
3.01M
            bs[0] = get_bs(&h->mv[MV_FWD_A1], &h->mv[MV_FWD_X0], mb_type > P_8X8);
142
3.01M
            bs[1] = get_bs(&h->mv[MV_FWD_A3], &h->mv[MV_FWD_X2], mb_type > P_8X8);
143
3.01M
            bs[4] = get_bs(&h->mv[MV_FWD_B2], &h->mv[MV_FWD_X0], mb_type > P_8X8);
144
3.01M
            bs[5] = get_bs(&h->mv[MV_FWD_B3], &h->mv[MV_FWD_X1], mb_type > P_8X8);
145
3.01M
        }
146
3.09M
        if (AV_RN64(bs)) {
147
2.36M
            if (h->flags & A_AVAIL) {
148
1.21M
                qp_avg = (h->qp + h->left_qp + 1) >> 1;
149
1.21M
                SET_PARAMS;
150
1.21M
                h->cdsp.cavs_filter_lv(h->cy, h->l_stride, alpha, beta, tc, bs[0], bs[1]);
151
1.21M
                qp_avg = (ff_cavs_chroma_qp[h->qp] + ff_cavs_chroma_qp[h->left_qp] + 1) >> 1;
152
1.21M
                SET_PARAMS;
153
1.21M
                h->cdsp.cavs_filter_cv(h->cu, h->c_stride, alpha, beta, tc, bs[0], bs[1]);
154
1.21M
                h->cdsp.cavs_filter_cv(h->cv, h->c_stride, alpha, beta, tc, bs[0], bs[1]);
155
1.21M
            }
156
2.36M
            qp_avg = h->qp;
157
2.36M
            SET_PARAMS;
158
2.36M
            h->cdsp.cavs_filter_lv(h->cy + 8,               h->l_stride, alpha, beta, tc, bs[2], bs[3]);
159
2.36M
            h->cdsp.cavs_filter_lh(h->cy + 8 * h->l_stride, h->l_stride, alpha, beta, tc, bs[6], bs[7]);
160
161
2.36M
            if (h->flags & B_AVAIL) {
162
1.86M
                qp_avg = (h->qp + h->top_qp[h->mbx] + 1) >> 1;
163
1.86M
                SET_PARAMS;
164
1.86M
                h->cdsp.cavs_filter_lh(h->cy, h->l_stride, alpha, beta, tc, bs[4], bs[5]);
165
1.86M
                qp_avg = (ff_cavs_chroma_qp[h->qp] + ff_cavs_chroma_qp[h->top_qp[h->mbx]] + 1) >> 1;
166
1.86M
                SET_PARAMS;
167
1.86M
                h->cdsp.cavs_filter_ch(h->cu, h->c_stride, alpha, beta, tc, bs[4], bs[5]);
168
1.86M
                h->cdsp.cavs_filter_ch(h->cv, h->c_stride, alpha, beta, tc, bs[4], bs[5]);
169
1.86M
            }
170
2.36M
        }
171
3.09M
    }
172
3.46M
    h->left_qp        = h->qp;
173
3.46M
    h->top_qp[h->mbx] = h->qp;
174
3.46M
}
175
176
#undef SET_PARAMS
177
178
/*****************************************************************************
179
 *
180
 * spatial intra prediction
181
 *
182
 ****************************************************************************/
183
184
void ff_cavs_load_intra_pred_luma(AVSContext *h, uint8_t *top,
185
                                  uint8_t **left, int block)
186
389k
{
187
389k
    int i;
188
189
389k
    switch (block) {
190
101k
    case 0:
191
101k
        *left               = h->left_border_y;
192
101k
        h->left_border_y[0] = h->left_border_y[1];
193
101k
        memset(&h->left_border_y[17], h->left_border_y[16], 9);
194
101k
        memcpy(&top[1], &h->top_border_y[h->mbx * 16], 16);
195
101k
        top[17] = top[16];
196
101k
        top[0]  = top[1];
197
101k
        if ((h->flags & A_AVAIL) && (h->flags & B_AVAIL))
198
37.0k
            h->left_border_y[0] = top[0] = h->topleft_border_y;
199
101k
        break;
200
96.6k
    case 1:
201
96.6k
        *left = h->intern_border_y;
202
869k
        for (i = 0; i < 8; i++)
203
772k
            h->intern_border_y[i + 1] = *(h->cy + 7 + i * h->l_stride);
204
96.6k
        memset(&h->intern_border_y[9], h->intern_border_y[8], 9);
205
96.6k
        h->intern_border_y[0] = h->intern_border_y[1];
206
96.6k
        memcpy(&top[1], &h->top_border_y[h->mbx * 16 + 8], 8);
207
96.6k
        if (h->flags & C_AVAIL)
208
37.2k
            memcpy(&top[9], &h->top_border_y[(h->mbx + 1) * 16], 8);
209
59.3k
        else
210
59.3k
            memset(&top[9], top[8], 9);
211
96.6k
        top[17] = top[16];
212
96.6k
        top[0]  = top[1];
213
96.6k
        if (h->flags & B_AVAIL)
214
65.0k
            h->intern_border_y[0] = top[0] = h->top_border_y[h->mbx * 16 + 7];
215
96.6k
        break;
216
95.9k
    case 2:
217
95.9k
        *left = &h->left_border_y[8];
218
95.9k
        memcpy(&top[1], h->cy + 7 * h->l_stride, 16);
219
95.9k
        top[17] = top[16];
220
95.9k
        top[0]  = top[1];
221
95.9k
        if (h->flags & A_AVAIL)
222
56.9k
            top[0] = h->left_border_y[8];
223
95.9k
        break;
224
95.5k
    case 3:
225
95.5k
        *left = &h->intern_border_y[8];
226
860k
        for (i = 0; i < 8; i++)
227
764k
            h->intern_border_y[i + 9] = *(h->cy + 7 + (i + 8) * h->l_stride);
228
95.5k
        memset(&h->intern_border_y[17], h->intern_border_y[16], 9);
229
95.5k
        memcpy(&top[0], h->cy + 7 + 7 * h->l_stride, 9);
230
95.5k
        memset(&top[9], top[8], 9);
231
95.5k
        break;
232
389k
    }
233
389k
}
234
235
void ff_cavs_load_intra_pred_chroma(AVSContext *h)
236
95.4k
{
237
    /* extend borders by one pixel */
238
95.4k
    h->left_border_u[9]              = h->left_border_u[8];
239
95.4k
    h->left_border_v[9]              = h->left_border_v[8];
240
95.4k
    if(h->flags & C_AVAIL) {
241
37.1k
        h->top_border_u[h->mbx*10 + 9] = h->top_border_u[h->mbx*10 + 11];
242
37.1k
        h->top_border_v[h->mbx*10 + 9] = h->top_border_v[h->mbx*10 + 11];
243
58.3k
    } else {
244
58.3k
        h->top_border_u[h->mbx * 10 + 9] = h->top_border_u[h->mbx * 10 + 8];
245
58.3k
        h->top_border_v[h->mbx * 10 + 9] = h->top_border_v[h->mbx * 10 + 8];
246
58.3k
    }
247
95.4k
    if((h->flags & A_AVAIL) && (h->flags & B_AVAIL)) {
248
36.8k
        h->top_border_u[h->mbx * 10] = h->left_border_u[0] = h->topleft_border_u;
249
36.8k
        h->top_border_v[h->mbx * 10] = h->left_border_v[0] = h->topleft_border_v;
250
58.5k
    } else {
251
58.5k
        h->left_border_u[0]          = h->left_border_u[1];
252
58.5k
        h->left_border_v[0]          = h->left_border_v[1];
253
58.5k
        h->top_border_u[h->mbx * 10] = h->top_border_u[h->mbx * 10 + 1];
254
58.5k
        h->top_border_v[h->mbx * 10] = h->top_border_v[h->mbx * 10 + 1];
255
58.5k
    }
256
95.4k
}
257
258
static void intra_pred_vert(uint8_t *d, uint8_t *top, uint8_t *left, ptrdiff_t stride)
259
81.1k
{
260
81.1k
    int y;
261
81.1k
    uint64_t a = AV_RN64(&top[1]);
262
730k
    for (y = 0; y < 8; y++)
263
649k
        *((uint64_t *)(d + y * stride)) = a;
264
81.1k
}
265
266
static void intra_pred_horiz(uint8_t *d, uint8_t *top, uint8_t *left, ptrdiff_t stride)
267
110k
{
268
110k
    int y;
269
110k
    uint64_t a;
270
993k
    for (y = 0; y < 8; y++) {
271
883k
        a = left[y + 1] * 0x0101010101010101ULL;
272
883k
        *((uint64_t *)(d + y * stride)) = a;
273
883k
    }
274
110k
}
275
276
static void intra_pred_dc_128(uint8_t *d, uint8_t *top, uint8_t *left, ptrdiff_t stride)
277
24.8k
{
278
24.8k
    int y;
279
24.8k
    uint64_t a = 0x8080808080808080ULL;
280
223k
    for (y = 0; y < 8; y++)
281
198k
        *((uint64_t *)(d + y * stride)) = a;
282
24.8k
}
283
284
static void intra_pred_plane(uint8_t *d, uint8_t *top, uint8_t *left, ptrdiff_t stride)
285
2.25k
{
286
2.25k
    int x, y, ia;
287
2.25k
    int ih = 0;
288
2.25k
    int iv = 0;
289
2.25k
    const uint8_t *cm = ff_crop_tab + MAX_NEG_CROP;
290
291
11.2k
    for (x = 0; x < 4; x++) {
292
9.02k
        ih += (x + 1) *  (top[5 + x] -  top[3 - x]);
293
9.02k
        iv += (x + 1) * (left[5 + x] - left[3 - x]);
294
9.02k
    }
295
2.25k
    ia = (top[8] + left[8]) << 4;
296
2.25k
    ih = (17 * ih + 16) >> 5;
297
2.25k
    iv = (17 * iv + 16) >> 5;
298
20.3k
    for (y = 0; y < 8; y++)
299
162k
        for (x = 0; x < 8; x++)
300
144k
            d[y * stride + x] = cm[(ia + (x - 3) * ih + (y - 3) * iv + 16) >> 5];
301
2.25k
}
302
303
#define LOWPASS(ARRAY, INDEX)                                           \
304
35.1M
    ((ARRAY[(INDEX) - 1] + 2 * ARRAY[(INDEX)] + ARRAY[(INDEX) + 1] + 2) >> 2)
305
306
static void intra_pred_lp(uint8_t *d, uint8_t *top, uint8_t *left, ptrdiff_t stride)
307
136k
{
308
136k
    int x, y;
309
1.22M
    for (y = 0; y < 8; y++)
310
9.81M
        for (x = 0; x < 8; x++)
311
8.72M
            d[y * stride + x] = (LOWPASS(top, x + 1) + LOWPASS(left, y + 1)) >> 1;
312
136k
}
313
314
static void intra_pred_down_left(uint8_t *d, uint8_t *top, uint8_t *left, ptrdiff_t stride)
315
55.8k
{
316
55.8k
    int x, y;
317
502k
    for (y = 0; y < 8; y++)
318
4.02M
        for (x = 0; x < 8; x++)
319
3.57M
            d[y * stride + x] = (LOWPASS(top, x + y + 2) + LOWPASS(left, x + y + 2)) >> 1;
320
55.8k
}
321
322
static void intra_pred_down_right(uint8_t *d, uint8_t *top, uint8_t *left, ptrdiff_t stride)
323
30.1k
{
324
30.1k
    int x, y;
325
271k
    for (y = 0; y < 8; y++)
326
2.16M
        for (x = 0; x < 8; x++)
327
1.92M
            if (x == y)
328
241k
                d[y * stride + x] = (left[1] + 2 * top[0] + top[1] + 2) >> 2;
329
1.68M
            else if (x > y)
330
843k
                d[y * stride + x] = LOWPASS(top, x - y);
331
843k
            else
332
843k
                d[y * stride + x] = LOWPASS(left, y - x);
333
30.1k
}
334
335
static void intra_pred_lp_left(uint8_t *d, uint8_t *top, uint8_t *left, ptrdiff_t stride)
336
57.3k
{
337
57.3k
    int x, y;
338
516k
    for (y = 0; y < 8; y++)
339
4.13M
        for (x = 0; x < 8; x++)
340
3.67M
            d[y * stride + x] = LOWPASS(left, y + 1);
341
57.3k
}
342
343
static void intra_pred_lp_top(uint8_t *d, uint8_t *top, uint8_t *left, ptrdiff_t stride)
344
81.9k
{
345
81.9k
    int x, y;
346
737k
    for (y = 0; y < 8; y++)
347
5.90M
        for (x = 0; x < 8; x++)
348
5.24M
            d[y * stride + x] = LOWPASS(top, x + 1);
349
81.9k
}
350
351
#undef LOWPASS
352
353
static inline void modify_pred(const int8_t *mod_table, int *mode)
354
250k
{
355
250k
    *mode = mod_table[*mode];
356
250k
    if (*mode < 0) {
357
82.0k
        av_log(NULL, AV_LOG_ERROR, "Illegal intra prediction mode\n");
358
82.0k
        *mode = 0;
359
82.0k
    }
360
250k
}
361
362
void ff_cavs_modify_mb_i(AVSContext *h, int *pred_mode_uv)
363
103k
{
364
    /* save pred modes before they get modified */
365
103k
    h->pred_mode_Y[3]             = h->pred_mode_Y[5];
366
103k
    h->pred_mode_Y[6]             = h->pred_mode_Y[8];
367
103k
    h->top_pred_Y[h->mbx * 2 + 0] = h->pred_mode_Y[7];
368
103k
    h->top_pred_Y[h->mbx * 2 + 1] = h->pred_mode_Y[8];
369
370
    /* modify pred modes according to availability of neighbour samples */
371
103k
    if (!(h->flags & A_AVAIL)) {
372
45.7k
        modify_pred(left_modifier_l, &h->pred_mode_Y[4]);
373
45.7k
        modify_pred(left_modifier_l, &h->pred_mode_Y[7]);
374
45.7k
        modify_pred(left_modifier_c, pred_mode_uv);
375
45.7k
    }
376
103k
    if (!(h->flags & B_AVAIL)) {
377
37.6k
        modify_pred(top_modifier_l, &h->pred_mode_Y[4]);
378
37.6k
        modify_pred(top_modifier_l, &h->pred_mode_Y[5]);
379
37.6k
        modify_pred(top_modifier_c, pred_mode_uv);
380
37.6k
    }
381
103k
}
382
383
/*****************************************************************************
384
 *
385
 * motion compensation
386
 *
387
 ****************************************************************************/
388
389
static inline void mc_dir_part(AVSContext *h, AVFrame *pic, int chroma_height,
390
                               int list, uint8_t *dest_y,
391
                               uint8_t *dest_cb, uint8_t *dest_cr,
392
                               int src_x_offset, int src_y_offset,
393
                               qpel_mc_func *qpix_op,
394
                               h264_chroma_mc_func chroma_op, cavs_vector *mv)
395
16.4M
{
396
16.4M
    const int mx         = mv->x + src_x_offset * 8;
397
16.4M
    const int my         = mv->y + src_y_offset * 8;
398
16.4M
    const int luma_xy    = (mx & 3) + ((my & 3) << 2);
399
16.4M
    uint8_t *src_y       = pic->data[0] + (mx >> 2) + (my >> 2) * h->l_stride;
400
16.4M
    uint8_t *src_cb      = pic->data[1] + (mx >> 3) + (my >> 3) * h->c_stride;
401
16.4M
    uint8_t *src_cr      = pic->data[2] + (mx >> 3) + (my >> 3) * h->c_stride;
402
16.4M
    int extra_width      = 0;
403
16.4M
    int extra_height     = extra_width;
404
16.4M
    const int full_mx    = mx >> 2;
405
16.4M
    const int full_my    = my >> 2;
406
16.4M
    const int pic_width  = 16 * h->mb_width;
407
16.4M
    const int pic_height = 16 * h->mb_height;
408
16.4M
    int emu = 0;
409
410
16.4M
    if (!pic->data[0])
411
230k
        return;
412
16.2M
    if (mx & 7)
413
3.75M
        extra_width  -= 3;
414
16.2M
    if (my & 7)
415
3.48M
        extra_height -= 3;
416
417
16.2M
    if (full_mx < 0 - extra_width ||
418
15.4M
        full_my < 0 - extra_height ||
419
15.3M
        full_mx + 16 /* FIXME */ > pic_width + extra_width ||
420
13.1M
        full_my + 16 /* FIXME */ > pic_height + extra_height) {
421
3.13M
        h->vdsp.emulated_edge_mc(h->edge_emu_buffer,
422
3.13M
                                 src_y - 2 - 2 * h->l_stride,
423
3.13M
                                 h->l_stride, h->l_stride,
424
3.13M
                                 16 + 5, 16 + 5 /* FIXME */,
425
3.13M
                                 full_mx - 2, full_my - 2,
426
3.13M
                                 pic_width, pic_height);
427
3.13M
        src_y = h->edge_emu_buffer + 2 + 2 * h->l_stride;
428
3.13M
        emu   = 1;
429
3.13M
    }
430
431
    // FIXME try variable height perhaps?
432
16.2M
    qpix_op[luma_xy](dest_y, src_y, h->l_stride);
433
434
16.2M
    if (emu) {
435
3.13M
        h->vdsp.emulated_edge_mc(h->edge_emu_buffer, src_cb,
436
3.13M
                                 h->c_stride, h->c_stride,
437
3.13M
                                 9, 9 /* FIXME */,
438
3.13M
                                 mx >> 3, my >> 3,
439
3.13M
                                 pic_width >> 1, pic_height >> 1);
440
3.13M
        src_cb = h->edge_emu_buffer;
441
3.13M
    }
442
16.2M
    chroma_op(dest_cb, src_cb, h->c_stride, chroma_height, mx & 7, my & 7);
443
444
16.2M
    if (emu) {
445
3.13M
        h->vdsp.emulated_edge_mc(h->edge_emu_buffer, src_cr,
446
3.13M
                                 h->c_stride, h->c_stride,
447
3.13M
                                 9, 9 /* FIXME */,
448
3.13M
                                 mx >> 3, my >> 3,
449
3.13M
                                 pic_width >> 1, pic_height >> 1);
450
3.13M
        src_cr = h->edge_emu_buffer;
451
3.13M
    }
452
16.2M
    chroma_op(dest_cr, src_cr, h->c_stride, chroma_height, mx & 7, my & 7);
453
16.2M
}
454
455
static inline void mc_part_std(AVSContext *h, int chroma_height,
456
                               uint8_t *dest_y,
457
                               uint8_t *dest_cb,
458
                               uint8_t *dest_cr,
459
                               int x_offset, int y_offset,
460
                               qpel_mc_func *qpix_put,
461
                               h264_chroma_mc_func chroma_put,
462
                               qpel_mc_func *qpix_avg,
463
                               h264_chroma_mc_func chroma_avg,
464
                               cavs_vector *mv)
465
9.23M
{
466
9.23M
    qpel_mc_func *qpix_op =  qpix_put;
467
9.23M
    h264_chroma_mc_func chroma_op = chroma_put;
468
469
9.23M
    dest_y   += x_offset * 2 + y_offset * h->l_stride * 2;
470
9.23M
    dest_cb  += x_offset     + y_offset * h->c_stride;
471
9.23M
    dest_cr  += x_offset     + y_offset * h->c_stride;
472
9.23M
    x_offset += 8 * h->mbx;
473
9.23M
    y_offset += 8 * h->mby;
474
475
9.23M
    if (mv->ref >= 0) {
476
8.98M
        AVFrame *ref = h->DPB[mv->ref].f;
477
8.98M
        mc_dir_part(h, ref, chroma_height, 0,
478
8.98M
                    dest_y, dest_cb, dest_cr, x_offset, y_offset,
479
8.98M
                    qpix_op, chroma_op, mv);
480
481
8.98M
        qpix_op   = qpix_avg;
482
8.98M
        chroma_op = chroma_avg;
483
8.98M
    }
484
485
9.23M
    if ((mv + MV_BWD_OFFS)->ref >= 0) {
486
7.50M
        AVFrame *ref = h->DPB[0].f;
487
7.50M
        mc_dir_part(h, ref, chroma_height, 1,
488
7.50M
                    dest_y, dest_cb, dest_cr, x_offset, y_offset,
489
7.50M
                    qpix_op, chroma_op, mv + MV_BWD_OFFS);
490
7.50M
    }
491
9.23M
}
492
493
void ff_cavs_inter(AVSContext *h, enum cavs_mb mb_type)
494
3.37M
{
495
3.37M
    if (ff_cavs_partition_flags[mb_type] == 0) { // 16x16
496
1.41M
        mc_part_std(h, 8, h->cy, h->cu, h->cv, 0, 0,
497
1.41M
                    h->cdsp.put_cavs_qpel_pixels_tab[0],
498
1.41M
                    h->h264chroma.put_h264_chroma_pixels_tab[0],
499
1.41M
                    h->cdsp.avg_cavs_qpel_pixels_tab[0],
500
1.41M
                    h->h264chroma.avg_h264_chroma_pixels_tab[0],
501
1.41M
                    &h->mv[MV_FWD_X0]);
502
1.95M
    } else {
503
1.95M
        mc_part_std(h, 4, h->cy, h->cu, h->cv, 0, 0,
504
1.95M
                    h->cdsp.put_cavs_qpel_pixels_tab[1],
505
1.95M
                    h->h264chroma.put_h264_chroma_pixels_tab[1],
506
1.95M
                    h->cdsp.avg_cavs_qpel_pixels_tab[1],
507
1.95M
                    h->h264chroma.avg_h264_chroma_pixels_tab[1],
508
1.95M
                    &h->mv[MV_FWD_X0]);
509
1.95M
        mc_part_std(h, 4, h->cy, h->cu, h->cv, 4, 0,
510
1.95M
                    h->cdsp.put_cavs_qpel_pixels_tab[1],
511
1.95M
                    h->h264chroma.put_h264_chroma_pixels_tab[1],
512
1.95M
                    h->cdsp.avg_cavs_qpel_pixels_tab[1],
513
1.95M
                    h->h264chroma.avg_h264_chroma_pixels_tab[1],
514
1.95M
                    &h->mv[MV_FWD_X1]);
515
1.95M
        mc_part_std(h, 4, h->cy, h->cu, h->cv, 0, 4,
516
1.95M
                    h->cdsp.put_cavs_qpel_pixels_tab[1],
517
1.95M
                    h->h264chroma.put_h264_chroma_pixels_tab[1],
518
1.95M
                    h->cdsp.avg_cavs_qpel_pixels_tab[1],
519
1.95M
                    h->h264chroma.avg_h264_chroma_pixels_tab[1],
520
1.95M
                    &h->mv[MV_FWD_X2]);
521
1.95M
        mc_part_std(h, 4, h->cy, h->cu, h->cv, 4, 4,
522
1.95M
                    h->cdsp.put_cavs_qpel_pixels_tab[1],
523
1.95M
                    h->h264chroma.put_h264_chroma_pixels_tab[1],
524
1.95M
                    h->cdsp.avg_cavs_qpel_pixels_tab[1],
525
1.95M
                    h->h264chroma.avg_h264_chroma_pixels_tab[1],
526
1.95M
                    &h->mv[MV_FWD_X3]);
527
1.95M
    }
528
3.37M
}
529
530
/*****************************************************************************
531
 *
532
 * motion vector prediction
533
 *
534
 ****************************************************************************/
535
536
static inline void scale_mv(AVSContext *h, int *d_x, int *d_y,
537
                            cavs_vector *src, int distp)
538
8.77M
{
539
8.77M
    int64_t den = h->scale_den[FFMAX(src->ref, 0)];
540
8.77M
    *d_x = (src->x * distp * den + 256 + FF_SIGNBIT(src->x)) >> 9;
541
8.77M
    *d_y = (src->y * distp * den + 256 + FF_SIGNBIT(src->y)) >> 9;
542
8.77M
}
543
544
static inline void mv_pred_median(AVSContext *h,
545
                                  cavs_vector *mvP,
546
                                  cavs_vector *mvA,
547
                                  cavs_vector *mvB,
548
                                  cavs_vector *mvC)
549
2.92M
{
550
2.92M
    int ax, ay, bx, by, cx, cy;
551
2.92M
    int len_ab, len_bc, len_ca, len_mid;
552
553
    /* scale candidates according to their temporal span */
554
2.92M
    scale_mv(h, &ax, &ay, mvA, mvP->dist);
555
2.92M
    scale_mv(h, &bx, &by, mvB, mvP->dist);
556
2.92M
    scale_mv(h, &cx, &cy, mvC, mvP->dist);
557
    /* find the geometrical median of the three candidates */
558
2.92M
    len_ab  = abs(ax - bx) + abs(ay - by);
559
2.92M
    len_bc  = abs(bx - cx) + abs(by - cy);
560
2.92M
    len_ca  = abs(cx - ax) + abs(cy - ay);
561
2.92M
    len_mid = mid_pred(len_ab, len_bc, len_ca);
562
2.92M
    if (len_mid == len_ab) {
563
2.50M
        mvP->x = cx;
564
2.50M
        mvP->y = cy;
565
2.50M
    } else if (len_mid == len_bc) {
566
298k
        mvP->x = ax;
567
298k
        mvP->y = ay;
568
298k
    } else {
569
122k
        mvP->x = bx;
570
122k
        mvP->y = by;
571
122k
    }
572
2.92M
}
573
574
void ff_cavs_mv(AVSContext *h, enum cavs_mv_loc nP, enum cavs_mv_loc nC,
575
                enum cavs_mv_pred mode, enum cavs_block size, int ref)
576
5.10M
{
577
5.10M
    cavs_vector *mvP = &h->mv[nP];
578
5.10M
    cavs_vector *mvA = &h->mv[nP-1];
579
5.10M
    cavs_vector *mvB = &h->mv[nP-4];
580
5.10M
    cavs_vector *mvC = &h->mv[nC];
581
5.10M
    const cavs_vector *mvP2 = NULL;
582
583
5.10M
    mvP->ref  = ref;
584
5.10M
    mvP->dist = h->dist[mvP->ref];
585
5.10M
    if (mvC->ref == NOT_AVAIL || (nP == MV_FWD_X3) || (nP == MV_BWD_X3 ))
586
2.43M
        mvC = &h->mv[nP - 5];  // set to top-left (mvD)
587
5.10M
    if (mode == MV_PRED_PSKIP &&
588
660k
        (mvA->ref == NOT_AVAIL ||
589
293k
         mvB->ref == NOT_AVAIL ||
590
282k
         (mvA->x | mvA->y | mvA->ref) == 0 ||
591
651k
         (mvB->x | mvB->y | mvB->ref) == 0)) {
592
651k
        mvP2 = &un_mv;
593
    /* if there is only one suitable candidate, take it */
594
4.45M
    } else if (mvA->ref >= 0 && mvB->ref < 0  && mvC->ref < 0) {
595
616k
        mvP2 = mvA;
596
3.83M
    } else if (mvA->ref < 0  && mvB->ref >= 0 && mvC->ref < 0) {
597
775k
        mvP2 = mvB;
598
3.06M
    } else if (mvA->ref < 0  && mvB->ref < 0  && mvC->ref >= 0) {
599
30.4k
        mvP2 = mvC;
600
3.03M
    } else if (mode == MV_PRED_LEFT     && mvA->ref == ref) {
601
37.7k
        mvP2 = mvA;
602
2.99M
    } else if (mode == MV_PRED_TOP      && mvB->ref == ref) {
603
8.33k
        mvP2 = mvB;
604
2.98M
    } else if (mode == MV_PRED_TOPRIGHT && mvC->ref == ref) {
605
58.8k
        mvP2 = mvC;
606
58.8k
    }
607
5.10M
    if (mvP2) {
608
2.17M
        mvP->x = mvP2->x;
609
2.17M
        mvP->y = mvP2->y;
610
2.17M
    } else
611
2.92M
        mv_pred_median(h, mvP, mvA, mvB, mvC);
612
613
5.10M
    if (mode < MV_PRED_PSKIP) {
614
1.13M
        int mx = get_se_golomb(&h->gb) + (unsigned)mvP->x;
615
1.13M
        int my = get_se_golomb(&h->gb) + (unsigned)mvP->y;
616
617
1.13M
        if (mx != (int16_t)mx || my != (int16_t)my) {
618
56.4k
            av_log(h->avctx, AV_LOG_ERROR, "MV %d %d out of supported range\n", mx, my);
619
1.07M
        } else {
620
1.07M
            mvP->x = mx;
621
1.07M
            mvP->y = my;
622
1.07M
        }
623
1.13M
    }
624
5.10M
    set_mvs(mvP, size);
625
5.10M
}
626
627
/*****************************************************************************
628
 *
629
 * macroblock level
630
 *
631
 ****************************************************************************/
632
633
/**
634
 * initialise predictors for motion vectors and intra prediction
635
 */
636
void ff_cavs_init_mb(AVSContext *h)
637
3.48M
{
638
3.48M
    int i;
639
640
    /* copy predictors from top line (MB B and C) into cache */
641
13.9M
    for (i = 0; i < 3; i++) {
642
10.4M
        h->mv[MV_FWD_B2 + i] = h->top_mv[0][h->mbx * 2 + i];
643
10.4M
        h->mv[MV_BWD_B2 + i] = h->top_mv[1][h->mbx * 2 + i];
644
10.4M
    }
645
3.48M
    h->pred_mode_Y[1] = h->top_pred_Y[h->mbx * 2 + 0];
646
3.48M
    h->pred_mode_Y[2] = h->top_pred_Y[h->mbx * 2 + 1];
647
    /* clear top predictors if MB B is not available */
648
3.48M
    if (!(h->flags & B_AVAIL)) {
649
553k
        h->mv[MV_FWD_B2]  = un_mv;
650
553k
        h->mv[MV_FWD_B3]  = un_mv;
651
553k
        h->mv[MV_BWD_B2]  = un_mv;
652
553k
        h->mv[MV_BWD_B3]  = un_mv;
653
553k
        h->pred_mode_Y[1] = h->pred_mode_Y[2] = NOT_AVAIL;
654
553k
        h->flags         &= ~(C_AVAIL | D_AVAIL);
655
2.93M
    } else if (h->mbx) {
656
1.68M
        h->flags |= D_AVAIL;
657
1.68M
    }
658
3.48M
    if (h->mbx == h->mb_width - 1) // MB C not available
659
1.36M
        h->flags &= ~C_AVAIL;
660
    /* clear top-right predictors if MB C is not available */
661
3.48M
    if (!(h->flags & C_AVAIL)) {
662
1.79M
        h->mv[MV_FWD_C2] = un_mv;
663
1.79M
        h->mv[MV_BWD_C2] = un_mv;
664
1.79M
    }
665
    /* clear top-left predictors if MB D is not available */
666
3.48M
    if (!(h->flags & D_AVAIL)) {
667
1.80M
        h->mv[MV_FWD_D3] = un_mv;
668
1.80M
        h->mv[MV_BWD_D3] = un_mv;
669
1.80M
    }
670
3.48M
}
671
672
/**
673
 * save predictors for later macroblocks and increase
674
 * macroblock address
675
 * @return 0 if end of frame is reached, 1 otherwise
676
 */
677
int ff_cavs_next_mb(AVSContext *h)
678
3.46M
{
679
3.46M
    int i;
680
681
3.46M
    h->flags |= A_AVAIL;
682
3.46M
    h->cy    += 16;
683
3.46M
    h->cu    += 8;
684
3.46M
    h->cv    += 8;
685
    /* copy mvs as predictors to the left */
686
24.2M
    for (i = 0; i <= 20; i += 4)
687
20.7M
        h->mv[i] = h->mv[i + 2];
688
    /* copy bottom mvs from cache to top line */
689
3.46M
    h->top_mv[0][h->mbx * 2 + 0] = h->mv[MV_FWD_X2];
690
3.46M
    h->top_mv[0][h->mbx * 2 + 1] = h->mv[MV_FWD_X3];
691
3.46M
    h->top_mv[1][h->mbx * 2 + 0] = h->mv[MV_BWD_X2];
692
3.46M
    h->top_mv[1][h->mbx * 2 + 1] = h->mv[MV_BWD_X3];
693
    /* next MB address */
694
3.46M
    h->mbidx++;
695
3.46M
    h->mbx++;
696
3.46M
    if (h->mbx == h->mb_width) { // New mb line
697
1.35M
        h->flags = B_AVAIL | C_AVAIL;
698
        /* clear left pred_modes */
699
1.35M
        h->pred_mode_Y[3] = h->pred_mode_Y[6] = NOT_AVAIL;
700
        /* clear left mv predictors */
701
9.51M
        for (i = 0; i <= 20; i += 4)
702
8.15M
            h->mv[i] = un_mv;
703
1.35M
        h->mbx = 0;
704
1.35M
        h->mby++;
705
        /* re-calculate sample pointers */
706
1.35M
        h->cy = h->cur.f->data[0] + h->mby * 16 * h->l_stride;
707
1.35M
        h->cu = h->cur.f->data[1] + h->mby * 8 * h->c_stride;
708
1.35M
        h->cv = h->cur.f->data[2] + h->mby * 8 * h->c_stride;
709
1.35M
        if (h->mby == h->mb_height) { // Frame end
710
14.4k
            return 0;
711
14.4k
        }
712
1.35M
    }
713
3.45M
    return 1;
714
3.46M
}
715
716
/*****************************************************************************
717
 *
718
 * frame level
719
 *
720
 ****************************************************************************/
721
722
int ff_cavs_init_pic(AVSContext *h)
723
40.3k
{
724
40.3k
    int i;
725
726
    /* clear some predictors */
727
282k
    for (i = 0; i <= 20; i += 4)
728
241k
        h->mv[i] = un_mv;
729
40.3k
    h->mv[MV_BWD_X0] = ff_cavs_dir_mv;
730
40.3k
    set_mvs(&h->mv[MV_BWD_X0], BLK_16X16);
731
40.3k
    h->mv[MV_FWD_X0] = ff_cavs_dir_mv;
732
40.3k
    set_mvs(&h->mv[MV_FWD_X0], BLK_16X16);
733
40.3k
    h->pred_mode_Y[3] = h->pred_mode_Y[6] = NOT_AVAIL;
734
40.3k
    h->cy             = h->cur.f->data[0];
735
40.3k
    h->cu             = h->cur.f->data[1];
736
40.3k
    h->cv             = h->cur.f->data[2];
737
40.3k
    h->l_stride       = h->cur.f->linesize[0];
738
40.3k
    h->c_stride       = h->cur.f->linesize[1];
739
40.3k
    h->luma_scan[2]   = 8 * h->l_stride;
740
40.3k
    h->luma_scan[3]   = 8 * h->l_stride + 8;
741
40.3k
    h->mbx            = h->mby = h->mbidx = 0;
742
40.3k
    h->flags          = 0;
743
744
40.3k
    return 0;
745
40.3k
}
746
747
/*****************************************************************************
748
 *
749
 * headers and interface
750
 *
751
 ****************************************************************************/
752
753
/**
754
 * some predictions require data from the top-neighbouring macroblock.
755
 * this data has to be stored for one complete row of macroblocks
756
 * and this storage space is allocated here
757
 */
758
int ff_cavs_init_top_lines(AVSContext *h)
759
6.46k
{
760
    /* alloc top line of predictors */
761
6.46k
    h->top_qp       = av_mallocz(h->mb_width);
762
6.46k
    h->top_mv[0]    = av_calloc(h->mb_width * 2 + 1,  sizeof(cavs_vector));
763
6.46k
    h->top_mv[1]    = av_calloc(h->mb_width * 2 + 1,  sizeof(cavs_vector));
764
6.46k
    h->top_pred_Y   = av_calloc(h->mb_width * 2,  sizeof(*h->top_pred_Y));
765
6.46k
    h->top_border_y = av_calloc(h->mb_width + 1,  16);
766
6.46k
    h->top_border_u = av_calloc(h->mb_width,  10);
767
6.46k
    h->top_border_v = av_calloc(h->mb_width,  10);
768
769
    /* alloc space for co-located MVs and types */
770
6.46k
    h->col_mv        = av_calloc(h->mb_width * h->mb_height,
771
6.46k
                                 4 * sizeof(*h->col_mv));
772
6.46k
    h->col_type_base = av_mallocz(h->mb_width * h->mb_height);
773
6.46k
    h->block         = av_mallocz(64 * sizeof(int16_t));
774
775
6.46k
    if (!h->top_qp || !h->top_mv[0] || !h->top_mv[1] || !h->top_pred_Y ||
776
6.46k
        !h->top_border_y || !h->top_border_u || !h->top_border_v ||
777
6.46k
        !h->col_mv || !h->col_type_base || !h->block) {
778
0
        av_freep(&h->top_qp);
779
0
        av_freep(&h->top_mv[0]);
780
0
        av_freep(&h->top_mv[1]);
781
0
        av_freep(&h->top_pred_Y);
782
0
        av_freep(&h->top_border_y);
783
0
        av_freep(&h->top_border_u);
784
0
        av_freep(&h->top_border_v);
785
0
        av_freep(&h->col_mv);
786
0
        av_freep(&h->col_type_base);
787
0
        av_freep(&h->block);
788
0
        return AVERROR(ENOMEM);
789
0
    }
790
6.46k
    return 0;
791
6.46k
}
792
793
av_cold int ff_cavs_init(AVCodecContext *avctx)
794
7.34k
{
795
7.34k
    AVSContext *h = avctx->priv_data;
796
7.34k
    uint8_t permutation[64];
797
798
7.34k
    ff_blockdsp_init(&h->bdsp);
799
7.34k
    ff_h264chroma_init(&h->h264chroma, 8);
800
7.34k
    ff_videodsp_init(&h->vdsp, 8);
801
7.34k
    ff_cavsdsp_init(&h->cdsp);
802
7.34k
    ff_init_scantable_permutation(permutation, h->cdsp.idct_perm);
803
7.34k
    ff_permute_scantable(h->permutated_scantable, ff_zigzag_direct, permutation);
804
805
7.34k
    h->avctx       = avctx;
806
7.34k
    avctx->pix_fmt = AV_PIX_FMT_YUV420P;
807
808
7.34k
    h->cur.f    = av_frame_alloc();
809
7.34k
    h->DPB[0].f = av_frame_alloc();
810
7.34k
    h->DPB[1].f = av_frame_alloc();
811
7.34k
    if (!h->cur.f || !h->DPB[0].f || !h->DPB[1].f)
812
0
        return AVERROR(ENOMEM);
813
814
7.34k
    h->luma_scan[0]                     = 0;
815
7.34k
    h->luma_scan[1]                     = 8;
816
7.34k
    h->intra_pred_l[INTRA_L_VERT]       = intra_pred_vert;
817
7.34k
    h->intra_pred_l[INTRA_L_HORIZ]      = intra_pred_horiz;
818
7.34k
    h->intra_pred_l[INTRA_L_LP]         = intra_pred_lp;
819
7.34k
    h->intra_pred_l[INTRA_L_DOWN_LEFT]  = intra_pred_down_left;
820
7.34k
    h->intra_pred_l[INTRA_L_DOWN_RIGHT] = intra_pred_down_right;
821
7.34k
    h->intra_pred_l[INTRA_L_LP_LEFT]    = intra_pred_lp_left;
822
7.34k
    h->intra_pred_l[INTRA_L_LP_TOP]     = intra_pred_lp_top;
823
7.34k
    h->intra_pred_l[INTRA_L_DC_128]     = intra_pred_dc_128;
824
7.34k
    h->intra_pred_c[INTRA_C_LP]         = intra_pred_lp;
825
7.34k
    h->intra_pred_c[INTRA_C_HORIZ]      = intra_pred_horiz;
826
7.34k
    h->intra_pred_c[INTRA_C_VERT]       = intra_pred_vert;
827
7.34k
    h->intra_pred_c[INTRA_C_PLANE]      = intra_pred_plane;
828
7.34k
    h->intra_pred_c[INTRA_C_LP_LEFT]    = intra_pred_lp_left;
829
7.34k
    h->intra_pred_c[INTRA_C_LP_TOP]     = intra_pred_lp_top;
830
7.34k
    h->intra_pred_c[INTRA_C_DC_128]     = intra_pred_dc_128;
831
7.34k
    h->mv[7]                            = un_mv;
832
7.34k
    h->mv[19]                           = un_mv;
833
7.34k
    return 0;
834
7.34k
}
835
836
av_cold int ff_cavs_end(AVCodecContext *avctx)
837
7.34k
{
838
7.34k
    AVSContext *h = avctx->priv_data;
839
840
7.34k
    av_frame_free(&h->cur.f);
841
7.34k
    av_frame_free(&h->DPB[0].f);
842
7.34k
    av_frame_free(&h->DPB[1].f);
843
844
7.34k
    av_freep(&h->top_qp);
845
7.34k
    av_freep(&h->top_mv[0]);
846
7.34k
    av_freep(&h->top_mv[1]);
847
7.34k
    av_freep(&h->top_pred_Y);
848
7.34k
    av_freep(&h->top_border_y);
849
7.34k
    av_freep(&h->top_border_u);
850
7.34k
    av_freep(&h->top_border_v);
851
7.34k
    av_freep(&h->col_mv);
852
7.34k
    av_freep(&h->col_type_base);
853
7.34k
    av_freep(&h->block);
854
7.34k
    av_freep(&h->edge_emu_buffer);
855
7.34k
    return 0;
856
7.34k
}