Coverage Report

Created: 2025-11-16 07:20

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ffmpeg/libavcodec/vc1.c
Line
Count
Source
1
/*
2
 * VC-1 and WMV3 decoder common code
3
 * Copyright (c) 2011 Mashiat Sarker Shakkhar
4
 * Copyright (c) 2006-2007 Konstantin Shishkov
5
 * Partly based on vc9.c (c) 2005 Anonymous, Alex Beregszaszi, Michael Niedermayer
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
/**
25
 * @file
26
 * VC-1 and WMV3 decoder common code
27
 */
28
29
#include "avcodec.h"
30
#include "decode.h"
31
#include "mpegvideo.h"
32
#include "vc1.h"
33
#include "vc1data.h"
34
#include "wmv2data.h"
35
#include "unary.h"
36
37
/***********************************************************************/
38
/**
39
 * @name VC-1 Bitplane decoding
40
 * @see 8.7, p56
41
 * @{
42
 */
43
44
/** Decode rows by checking if they are skipped
45
 * @param plane Buffer to store decoded bits
46
 * @param[in] width Width of this buffer
47
 * @param[in] height Height of this buffer
48
 * @param[in] stride of this buffer
49
 */
50
static void decode_rowskip(uint8_t* plane, int width, int height, int stride,
51
                           GetBitContext *gb)
52
162k
{
53
162k
    int x, y;
54
55
3.74M
    for (y = 0; y < height; y++) {
56
3.58M
        if (!get_bits1(gb)) //rowskip
57
2.80M
            memset(plane, 0, width);
58
777k
        else
59
13.9M
            for (x = 0; x < width; x++)
60
13.1M
                plane[x] = get_bits1(gb);
61
3.58M
        plane += stride;
62
3.58M
    }
63
162k
}
64
65
/** Decode columns by checking if they are skipped
66
 * @param plane Buffer to store decoded bits
67
 * @param[in] width Width of this buffer
68
 * @param[in] height Height of this buffer
69
 * @param[in] stride of this buffer
70
 * @todo FIXME: Optimize
71
 */
72
static void decode_colskip(uint8_t* plane, int width, int height, int stride,
73
                           GetBitContext *gb)
74
205k
{
75
205k
    int x, y;
76
77
3.50M
    for (x = 0; x < width; x++) {
78
3.30M
        if (!get_bits1(gb)) //colskip
79
50.2M
            for (y = 0; y < height; y++)
80
47.7M
                plane[y*stride] = 0;
81
797k
        else
82
18.7M
            for (y = 0; y < height; y++)
83
17.9M
                plane[y*stride] = get_bits1(gb);
84
3.30M
        plane ++;
85
3.30M
    }
86
205k
}
87
88
/** Decode a bitplane's bits
89
 * @param data bitplane where to store the decode bits
90
 * @param[out] raw_flag pointer to the flag indicating that this bitplane is not coded explicitly
91
 * @param v VC-1 context for bit reading and logging
92
 * @return Status
93
 * @todo FIXME: Optimize
94
 */
95
static int bitplane_decoding(uint8_t* data, int *raw_flag, VC1Context *v)
96
795k
{
97
795k
    GetBitContext *const gb = &v->gb;
98
99
795k
    int imode, x, y, code, offset;
100
795k
    uint8_t invert, *planep = data;
101
795k
    int width, height, stride;
102
103
795k
    width  = v->s.mb_width;
104
795k
    height = v->s.mb_height >> v->field_mode;
105
795k
    stride = v->s.mb_stride;
106
795k
    invert = get_bits1(gb);
107
795k
    imode = get_vlc2(gb, ff_vc1_imode_vlc, VC1_IMODE_VLC_BITS, 1);
108
109
795k
    *raw_flag = 0;
110
795k
    switch (imode) {
111
213k
    case IMODE_RAW:
112
        //Data is actually read in the MB layer (same for all tests == "raw")
113
213k
        *raw_flag = 1; //invert ignored
114
213k
        return invert;
115
91.0k
    case IMODE_DIFF2:
116
245k
    case IMODE_NORM2:
117
245k
        if ((height * width) & 1) {
118
112k
            *planep++ = get_bits1(gb);
119
112k
            y = offset = 1;
120
112k
            if (offset == width) {
121
32.3k
                offset = 0;
122
32.3k
                planep += stride - width;
123
32.3k
            }
124
112k
        }
125
132k
        else
126
132k
            y = offset = 0;
127
        // decode bitplane as one long line
128
59.9M
        for (; y < height * width; y += 2) {
129
59.7M
            code = get_vlc2(gb, ff_vc1_norm2_vlc, VC1_NORM2_VLC_BITS, 1);
130
59.7M
            *planep++ = code & 1;
131
59.7M
            offset++;
132
59.7M
            if (offset == width) {
133
2.41M
                offset  = 0;
134
2.41M
                planep += stride - width;
135
2.41M
            }
136
59.7M
            *planep++ = code >> 1;
137
59.7M
            offset++;
138
59.7M
            if (offset == width) {
139
7.51M
                offset  = 0;
140
7.51M
                planep += stride - width;
141
7.51M
            }
142
59.7M
        }
143
245k
        break;
144
40.4k
    case IMODE_DIFF6:
145
215k
    case IMODE_NORM6:
146
215k
        if (!(height % 3) && (width % 3)) { // use 2x3 decoding
147
863k
            for (y = 0; y < height; y += 3) {
148
2.21M
                for (x = width & 1; x < width; x += 2) {
149
1.38M
                    code = get_vlc2(gb, ff_vc1_norm6_vlc, VC1_NORM6_VLC_BITS, 2);
150
1.38M
                    if (code < 0) {
151
5.21k
                        av_log(v->s.avctx, AV_LOG_DEBUG, "invalid NORM-6 VLC\n");
152
5.21k
                        return -1;
153
5.21k
                    }
154
1.38M
                    planep[x + 0]              = (code >> 0) & 1;
155
1.38M
                    planep[x + 1]              = (code >> 1) & 1;
156
1.38M
                    planep[x + 0 + stride]     = (code >> 2) & 1;
157
1.38M
                    planep[x + 1 + stride]     = (code >> 3) & 1;
158
1.38M
                    planep[x + 0 + stride * 2] = (code >> 4) & 1;
159
1.38M
                    planep[x + 1 + stride * 2] = (code >> 5) & 1;
160
1.38M
                }
161
828k
                planep += stride * 3;
162
828k
            }
163
30.0k
            if (width & 1)
164
21.4k
                decode_colskip(data, 1, height, stride, &v->gb);
165
179k
        } else { // 3x2
166
179k
            planep += (height & 1) * stride;
167
4.47M
            for (y = height & 1; y < height; y += 2) {
168
9.34M
                for (x = width % 3; x < width; x += 3) {
169
5.04M
                    code = get_vlc2(gb, ff_vc1_norm6_vlc, VC1_NORM6_VLC_BITS, 2);
170
5.04M
                    if (code < 0) {
171
14.7k
                        av_log(v->s.avctx, AV_LOG_DEBUG, "invalid NORM-6 VLC\n");
172
14.7k
                        return -1;
173
14.7k
                    }
174
5.03M
                    planep[x + 0]          = (code >> 0) & 1;
175
5.03M
                    planep[x + 1]          = (code >> 1) & 1;
176
5.03M
                    planep[x + 2]          = (code >> 2) & 1;
177
5.03M
                    planep[x + 0 + stride] = (code >> 3) & 1;
178
5.03M
                    planep[x + 1 + stride] = (code >> 4) & 1;
179
5.03M
                    planep[x + 2 + stride] = (code >> 5) & 1;
180
5.03M
                }
181
4.29M
                planep += stride * 2;
182
4.29M
            }
183
165k
            x = width % 3;
184
165k
            if (x)
185
131k
                decode_colskip(data,             x, height, stride, &v->gb);
186
165k
            if (height & 1)
187
92.7k
                decode_rowskip(data + x, width - x,      1, stride, &v->gb);
188
165k
        }
189
195k
        break;
190
195k
    case IMODE_ROWSKIP:
191
69.3k
        decode_rowskip(data, width, height, stride, &v->gb);
192
69.3k
        break;
193
52.5k
    case IMODE_COLSKIP:
194
52.5k
        decode_colskip(data, width, height, stride, &v->gb);
195
52.5k
        break;
196
0
    default:
197
0
        break;
198
795k
    }
199
200
    /* Applying diff operator */
201
562k
    if (imode == IMODE_DIFF2 || imode == IMODE_DIFF6) {
202
128k
        planep = data;
203
128k
        planep[0] ^= invert;
204
5.77M
        for (x = 1; x < width; x++)
205
5.65M
            planep[x] ^= planep[x-1];
206
6.41M
        for (y = 1; y < height; y++) {
207
6.28M
            planep += stride;
208
6.28M
            planep[0] ^= planep[-stride];
209
51.3M
            for (x = 1; x < width; x++) {
210
45.0M
                if (planep[x-1] != planep[x-stride]) planep[x] ^= invert;
211
33.7M
                else                                 planep[x] ^= planep[x-1];
212
45.0M
            }
213
6.28M
        }
214
434k
    } else if (invert) {
215
220k
        planep = data;
216
101M
        for (x = 0; x < stride * height; x++)
217
101M
            planep[x] = !planep[x]; //FIXME stride
218
220k
    }
219
562k
    return (imode << 1) + invert;
220
795k
}
221
222
/** @} */ //Bitplane group
223
224
/***********************************************************************/
225
/** VOP Dquant decoding
226
 * @param v VC-1 Context
227
 */
228
static int vop_dquant_decoding(VC1Context *v)
229
397k
{
230
397k
    GetBitContext *const gb = &v->gb;
231
397k
    int pqdiff;
232
233
    //variable size
234
397k
    if (v->dquant != 2) {
235
309k
        v->dquantfrm = get_bits1(gb);
236
309k
        if (!v->dquantfrm)
237
159k
            return 0;
238
239
149k
        v->dqprofile = get_bits(gb, 2);
240
149k
        switch (v->dqprofile) {
241
27.0k
        case DQPROFILE_SINGLE_EDGE:
242
53.7k
        case DQPROFILE_DOUBLE_EDGES:
243
53.7k
            v->dqsbedge = get_bits(gb, 2);
244
53.7k
            break;
245
69.6k
        case DQPROFILE_ALL_MBS:
246
69.6k
            v->dqbilevel = get_bits1(gb);
247
69.6k
            if (!v->dqbilevel) {
248
29.0k
                v->halfpq = 0;
249
29.0k
                return 0;
250
29.0k
            }
251
67.0k
        default:
252
67.0k
            break; //Forbidden ?
253
149k
        }
254
149k
    }
255
256
208k
    pqdiff = get_bits(gb, 3);
257
208k
    if (pqdiff == 7)
258
53.0k
        v->altpq = get_bits(gb, 5);
259
155k
    else
260
155k
        v->altpq = v->pq + pqdiff + 1;
261
262
208k
    return 0;
263
397k
}
264
265
static int decode_sequence_header_adv(VC1Context *v, GetBitContext *gb);
266
267
/**
268
 * Decode Simple/Main Profiles sequence header
269
 * @see Figure 7-8, p16-17
270
 * @param avctx Codec context
271
 * @param gb GetBit context initialized from Codec context extra_data
272
 * @return Status
273
 */
274
int ff_vc1_decode_sequence_header(AVCodecContext *avctx, VC1Context *v, GetBitContext *gb)
275
260k
{
276
260k
    av_log(avctx, AV_LOG_DEBUG, "Header: %0X\n", show_bits_long(gb, 32));
277
260k
    v->profile = get_bits(gb, 2);
278
260k
    if (v->profile == PROFILE_COMPLEX) {
279
24.0k
        av_log(avctx, AV_LOG_WARNING, "WMV3 Complex Profile is not fully supported\n");
280
24.0k
    }
281
282
260k
    if (v->profile == PROFILE_ADVANCED) {
283
183k
        v->zz_8x4 = ff_vc1_adv_progressive_8x4_zz;
284
183k
        v->zz_4x8 = ff_vc1_adv_progressive_4x8_zz;
285
183k
        return decode_sequence_header_adv(v, gb);
286
183k
    } else {
287
77.3k
        v->chromaformat = 1;
288
77.3k
        v->zz_8x4 = ff_wmv2_scantableA;
289
77.3k
        v->zz_4x8 = ff_wmv2_scantableB;
290
77.3k
        v->res_y411   = get_bits1(gb);
291
77.3k
        v->res_sprite = get_bits1(gb);
292
77.3k
        if (v->res_y411) {
293
2.81k
            av_log(avctx, AV_LOG_ERROR,
294
2.81k
                   "Old interlaced mode is not supported\n");
295
2.81k
            return -1;
296
2.81k
        }
297
77.3k
    }
298
299
    // (fps-2)/4 (->30)
300
74.5k
    v->frmrtq_postproc = get_bits(gb, 3); //common
301
    // (bitrate-32kbps)/64kbps
302
74.5k
    v->bitrtq_postproc = get_bits(gb, 5); //common
303
74.5k
    v->loop_filter     = get_bits1(gb); //common
304
74.5k
    if (v->loop_filter == 1 && v->profile == PROFILE_SIMPLE) {
305
1.90k
        av_log(avctx, AV_LOG_ERROR,
306
1.90k
               "LOOPFILTER shall not be enabled in Simple Profile\n");
307
1.90k
    }
308
74.5k
    if (v->s.avctx->skip_loop_filter >= AVDISCARD_ALL)
309
0
        v->loop_filter = 0;
310
311
74.5k
    v->res_x8          = get_bits1(gb); //reserved
312
74.5k
    v->multires        = get_bits1(gb);
313
74.5k
    v->res_fasttx      = get_bits1(gb);
314
315
74.5k
    v->fastuvmc        = get_bits1(gb); //common
316
74.5k
    if (!v->profile && !v->fastuvmc) {
317
3.12k
        av_log(avctx, AV_LOG_ERROR,
318
3.12k
               "FASTUVMC unavailable in Simple Profile\n");
319
3.12k
        return -1;
320
3.12k
    }
321
71.4k
    v->extended_mv     = get_bits1(gb); //common
322
71.4k
    if (!v->profile && v->extended_mv) {
323
1.02k
        av_log(avctx, AV_LOG_ERROR,
324
1.02k
               "Extended MVs unavailable in Simple Profile\n");
325
1.02k
        return -1;
326
1.02k
    }
327
70.4k
    v->dquant          = get_bits(gb, 2); //common
328
70.4k
    v->vstransform     = get_bits1(gb); //common
329
330
70.4k
    v->res_transtab    = get_bits1(gb);
331
70.4k
    if (v->res_transtab) {
332
16.7k
        av_log(avctx, AV_LOG_ERROR,
333
16.7k
               "1 for reserved RES_TRANSTAB is forbidden\n");
334
16.7k
        return -1;
335
16.7k
    }
336
337
53.6k
    v->overlap         = get_bits1(gb); //common
338
339
53.6k
    v->resync_marker   = get_bits1(gb);
340
53.6k
    v->rangered        = get_bits1(gb);
341
53.6k
    if (v->rangered && v->profile == PROFILE_SIMPLE) {
342
6.38k
        av_log(avctx, AV_LOG_INFO,
343
6.38k
               "RANGERED should be set to 0 in Simple Profile\n");
344
6.38k
    }
345
346
53.6k
    v->max_b_frames = avctx->max_b_frames = get_bits(gb, 3); //common
347
53.6k
    v->quantizer_mode = get_bits(gb, 2); //common
348
349
53.6k
    v->finterpflag = get_bits1(gb); //common
350
351
53.6k
    if (v->res_sprite) {
352
18.2k
        int w = get_bits(gb, 11);
353
18.2k
        int h = get_bits(gb, 11);
354
18.2k
        int ret = ff_set_dimensions(v->s.avctx, w, h);
355
18.2k
        if (ret < 0) {
356
4.93k
            av_log(avctx, AV_LOG_ERROR, "Failed to set dimensions %d %d\n", w, h);
357
4.93k
            return ret;
358
4.93k
        }
359
13.3k
        skip_bits(gb, 5); //frame rate
360
13.3k
        v->res_x8 = get_bits1(gb);
361
13.3k
        if (get_bits1(gb)) { // something to do with DC VLC selection
362
1.74k
            av_log(avctx, AV_LOG_ERROR, "Unsupported sprite feature\n");
363
1.74k
            return -1;
364
1.74k
        }
365
11.5k
        skip_bits(gb, 3); //slice code
366
11.5k
        v->res_rtm_flag = 0;
367
35.4k
    } else {
368
35.4k
        v->res_rtm_flag = get_bits1(gb); //reserved
369
35.4k
    }
370
    //TODO: figure out what they mean (always 0x402F)
371
47.0k
    if (!v->res_fasttx)
372
27.0k
        skip_bits(gb, 16);
373
47.0k
    av_log(avctx, AV_LOG_DEBUG,
374
47.0k
           "Profile %i:\nfrmrtq_postproc=%i, bitrtq_postproc=%i\n"
375
47.0k
           "LoopFilter=%i, MultiRes=%i, FastUVMC=%i, Extended MV=%i\n"
376
47.0k
           "Rangered=%i, VSTransform=%i, Overlap=%i, SyncMarker=%i\n"
377
47.0k
           "DQuant=%i, Quantizer mode=%i, Max B-frames=%i\n",
378
47.0k
           v->profile, v->frmrtq_postproc, v->bitrtq_postproc,
379
47.0k
           v->loop_filter, v->multires, v->fastuvmc, v->extended_mv,
380
47.0k
           v->rangered, v->vstransform, v->overlap, v->resync_marker,
381
47.0k
           v->dquant, v->quantizer_mode, avctx->max_b_frames);
382
47.0k
    return 0;
383
53.6k
}
384
385
static int decode_sequence_header_adv(VC1Context *v, GetBitContext *gb)
386
183k
{
387
183k
    v->res_rtm_flag = 1;
388
183k
    v->level = get_bits(gb, 3);
389
183k
    if (v->level >= 5) {
390
122k
        av_log(v->s.avctx, AV_LOG_ERROR, "Reserved LEVEL %i\n",v->level);
391
122k
    }
392
183k
    v->chromaformat = get_bits(gb, 2);
393
183k
    if (v->chromaformat != 1) {
394
4.80k
        av_log(v->s.avctx, AV_LOG_ERROR,
395
4.80k
               "Only 4:2:0 chroma format supported\n");
396
4.80k
        return -1;
397
4.80k
    }
398
399
    // (fps-2)/4 (->30)
400
178k
    v->frmrtq_postproc       = get_bits(gb, 3); //common
401
    // (bitrate-32kbps)/64kbps
402
178k
    v->bitrtq_postproc       = get_bits(gb, 5); //common
403
178k
    v->postprocflag          = get_bits1(gb);   //common
404
405
178k
    v->max_coded_width       = (get_bits(gb, 12) + 1) << 1;
406
178k
    v->max_coded_height      = (get_bits(gb, 12) + 1) << 1;
407
178k
    v->broadcast             = get_bits1(gb);
408
178k
    v->interlace             = get_bits1(gb);
409
178k
    v->tfcntrflag            = get_bits1(gb);
410
178k
    v->finterpflag           = get_bits1(gb);
411
178k
    skip_bits1(gb); // reserved
412
413
178k
    av_log(v->s.avctx, AV_LOG_DEBUG,
414
178k
           "Advanced Profile level %i:\nfrmrtq_postproc=%i, bitrtq_postproc=%i\n"
415
178k
           "LoopFilter=%i, ChromaFormat=%i, Pulldown=%i, Interlace: %i\n"
416
178k
           "TFCTRflag=%i, FINTERPflag=%i\n",
417
178k
           v->level, v->frmrtq_postproc, v->bitrtq_postproc,
418
178k
           v->loop_filter, v->chromaformat, v->broadcast, v->interlace,
419
178k
           v->tfcntrflag, v->finterpflag);
420
421
178k
    v->psf = get_bits1(gb);
422
178k
    if (v->psf) { //PsF, 6.1.13
423
19.5k
        av_log(v->s.avctx, AV_LOG_ERROR, "Progressive Segmented Frame mode: not supported (yet)\n");
424
19.5k
        return -1;
425
19.5k
    }
426
158k
    v->max_b_frames = v->s.avctx->max_b_frames = 7;
427
158k
    if (get_bits1(gb)) { //Display Info - decoding is not affected by it
428
94.0k
        int w, h, ar = 0;
429
94.0k
        av_log(v->s.avctx, AV_LOG_DEBUG, "Display extended info:\n");
430
94.0k
        w = get_bits(gb, 14) + 1;
431
94.0k
        h = get_bits(gb, 14) + 1;
432
94.0k
        av_log(v->s.avctx, AV_LOG_DEBUG, "Display dimensions: %ix%i\n", w, h);
433
94.0k
        if (get_bits1(gb))
434
25.2k
            ar = get_bits(gb, 4);
435
94.0k
        if (ar && ar < 14) {
436
14.0k
            v->s.avctx->sample_aspect_ratio = ff_vc1_pixel_aspect[ar];
437
80.0k
        } else if (ar == 15) {
438
8.83k
            w = get_bits(gb, 8) + 1;
439
8.83k
            h = get_bits(gb, 8) + 1;
440
8.83k
            v->s.avctx->sample_aspect_ratio = (AVRational){w, h};
441
71.1k
        } else {
442
71.1k
            if (v->s.avctx->width  > v->max_coded_width ||
443
53.3k
                v->s.avctx->height > v->max_coded_height) {
444
23.8k
                avpriv_request_sample(v->s.avctx, "Huge resolution");
445
23.8k
            } else
446
47.3k
                av_reduce(&v->s.avctx->sample_aspect_ratio.num,
447
47.3k
                      &v->s.avctx->sample_aspect_ratio.den,
448
47.3k
                      v->s.avctx->height * w,
449
47.3k
                      v->s.avctx->width * h,
450
47.3k
                      1 << 30);
451
71.1k
        }
452
94.0k
        ff_set_sar(v->s.avctx, v->s.avctx->sample_aspect_ratio);
453
94.0k
        av_log(v->s.avctx, AV_LOG_DEBUG, "Aspect: %i:%i\n",
454
94.0k
               v->s.avctx->sample_aspect_ratio.num,
455
94.0k
               v->s.avctx->sample_aspect_ratio.den);
456
457
94.0k
        if (get_bits1(gb)) { //framerate stuff
458
55.9k
            if (get_bits1(gb)) {
459
22.8k
                v->s.avctx->framerate.den = 32;
460
22.8k
                v->s.avctx->framerate.num = get_bits(gb, 16) + 1;
461
33.1k
            } else {
462
33.1k
                int nr, dr;
463
33.1k
                nr = get_bits(gb, 8);
464
33.1k
                dr = get_bits(gb, 4);
465
33.1k
                if (nr > 0 && nr < 8 && dr > 0 && dr < 3) {
466
7.19k
                    v->s.avctx->framerate.den = ff_vc1_fps_dr[dr - 1];
467
7.19k
                    v->s.avctx->framerate.num = ff_vc1_fps_nr[nr - 1] * 1000;
468
7.19k
                }
469
33.1k
            }
470
55.9k
        }
471
472
94.0k
        if (get_bits1(gb)) {
473
26.2k
            v->color_prim    = get_bits(gb, 8);
474
26.2k
            v->transfer_char = get_bits(gb, 8);
475
26.2k
            v->matrix_coef   = get_bits(gb, 8);
476
26.2k
        }
477
94.0k
    }
478
479
158k
    v->hrd_param_flag = get_bits1(gb);
480
158k
    if (v->hrd_param_flag) {
481
40.9k
        int i;
482
40.9k
        v->hrd_num_leaky_buckets = get_bits(gb, 5);
483
40.9k
        skip_bits(gb, 4); //bitrate exponent
484
40.9k
        skip_bits(gb, 4); //buffer size exponent
485
694k
        for (i = 0; i < v->hrd_num_leaky_buckets; i++) {
486
653k
            skip_bits(gb, 16); //hrd_rate[n]
487
653k
            skip_bits(gb, 16); //hrd_buffer[n]
488
653k
        }
489
40.9k
    }
490
158k
    return 0;
491
178k
}
492
493
int ff_vc1_decode_entry_point(AVCodecContext *avctx, VC1Context *v, GetBitContext *gb)
494
382k
{
495
382k
    int i;
496
382k
    int w,h;
497
382k
    int ret;
498
499
382k
    av_log(avctx, AV_LOG_DEBUG, "Entry point: %08X\n", show_bits_long(gb, 32));
500
382k
    v->broken_link    = get_bits1(gb);
501
382k
    v->closed_entry   = get_bits1(gb);
502
382k
    v->panscanflag    = get_bits1(gb);
503
382k
    v->refdist_flag   = get_bits1(gb);
504
382k
    v->loop_filter    = get_bits1(gb);
505
382k
    if (v->s.avctx->skip_loop_filter >= AVDISCARD_ALL)
506
0
        v->loop_filter = 0;
507
382k
    v->fastuvmc       = get_bits1(gb);
508
382k
    v->extended_mv    = get_bits1(gb);
509
382k
    v->dquant         = get_bits(gb, 2);
510
382k
    v->vstransform    = get_bits1(gb);
511
382k
    v->overlap        = get_bits1(gb);
512
382k
    v->quantizer_mode = get_bits(gb, 2);
513
514
382k
    if (v->hrd_param_flag) {
515
885k
        for (i = 0; i < v->hrd_num_leaky_buckets; i++) {
516
832k
            skip_bits(gb, 8); //hrd_full[n]
517
832k
        }
518
52.1k
    }
519
520
382k
    if(get_bits1(gb)){
521
316k
        w = (get_bits(gb, 12)+1)<<1;
522
316k
        h = (get_bits(gb, 12)+1)<<1;
523
316k
    } else {
524
65.9k
        w = v->max_coded_width;
525
65.9k
        h = v->max_coded_height;
526
65.9k
    }
527
382k
    if ((ret = ff_set_dimensions(avctx, w, h)) < 0) {
528
15.8k
        av_log(avctx, AV_LOG_ERROR, "Failed to set dimensions %d %d\n", w, h);
529
15.8k
        return ret;
530
15.8k
    }
531
532
367k
    if (v->extended_mv)
533
229k
        v->extended_dmv = get_bits1(gb);
534
367k
    if ((v->range_mapy_flag = get_bits1(gb))) {
535
197k
        av_log(avctx, AV_LOG_ERROR, "Luma scaling is not supported, expect wrong picture\n");
536
197k
        v->range_mapy = get_bits(gb, 3);
537
197k
    }
538
367k
    if ((v->range_mapuv_flag = get_bits1(gb))) {
539
99.6k
        av_log(avctx, AV_LOG_ERROR, "Chroma scaling is not supported, expect wrong picture\n");
540
99.6k
        v->range_mapuv = get_bits(gb, 3);
541
99.6k
    }
542
543
367k
    av_log(avctx, AV_LOG_DEBUG, "Entry point info:\n"
544
367k
           "BrokenLink=%i, ClosedEntry=%i, PanscanFlag=%i\n"
545
367k
           "RefDist=%i, Postproc=%i, FastUVMC=%i, ExtMV=%i\n"
546
367k
           "DQuant=%i, VSTransform=%i, Overlap=%i, Qmode=%i\n",
547
367k
           v->broken_link, v->closed_entry, v->panscanflag, v->refdist_flag, v->loop_filter,
548
367k
           v->fastuvmc, v->extended_mv, v->dquant, v->vstransform, v->overlap, v->quantizer_mode);
549
550
367k
    return 0;
551
382k
}
552
553
/* fill lookup tables for intensity compensation */
554
1.84M
#define INIT_LUT(lumscale, lumshift, luty, lutuv, chain) do {                 \
555
1.84M
        int scale, shift, i;                                                  \
556
1.84M
        if (!lumscale) {                                                      \
557
36.0k
            scale = -64;                                                      \
558
36.0k
            shift = (255 - lumshift * 2) * 64;                                \
559
36.0k
            if (lumshift > 31)                                                \
560
36.0k
                shift += 128 << 6;                                            \
561
1.80M
        } else {                                                              \
562
1.80M
            scale = lumscale + 32;                                            \
563
1.80M
            if (lumshift > 31)                                                \
564
1.80M
                shift = (lumshift - 64) * 64;                                 \
565
1.80M
            else                                                              \
566
1.80M
                shift = lumshift << 6;                                        \
567
1.80M
        }                                                                     \
568
474M
        for (i = 0; i < 256; i++) {                                           \
569
472M
            int iy = chain ? luty[i]  : i;                                    \
570
472M
            int iu = chain ? lutuv[i] : i;                                    \
571
472M
            luty[i]  = av_clip_uint8((scale * iy + shift + 32) >> 6);         \
572
472M
            lutuv[i] = av_clip_uint8((scale * (iu - 128) + 128*64 + 32) >> 6);\
573
472M
        }                                                                     \
574
1.84M
    } while(0)
575
576
static void rotate_luts(VC1Context *v)
577
833k
{
578
833k
    if (v->s.pict_type == AV_PICTURE_TYPE_BI || v->s.pict_type == AV_PICTURE_TYPE_B) {
579
159k
        v->curr_use_ic = &v->aux_use_ic;
580
159k
        v->curr_luty   = v->aux_luty;
581
159k
        v->curr_lutuv  = v->aux_lutuv;
582
674k
    } else {
583
2.02M
#define ROTATE(DEF, L, N, C) do {                             \
584
2.02M
            DEF;                                              \
585
2.02M
            memcpy(&tmp, L   , sizeof(tmp));                  \
586
2.02M
            memcpy(L   , N   , sizeof(tmp));                  \
587
2.02M
            memcpy(N   , &tmp, sizeof(tmp));                  \
588
2.02M
            C = N;                                            \
589
2.02M
    } while(0)
590
591
674k
        ROTATE(int tmp,             &v->last_use_ic, &v->next_use_ic, v->curr_use_ic);
592
674k
        ROTATE(uint8_t tmp[2][256],  v->last_luty,    v->next_luty,   v->curr_luty);
593
674k
        ROTATE(uint8_t tmp[2][256],  v->last_lutuv,   v->next_lutuv,  v->curr_lutuv);
594
674k
    }
595
596
833k
    INIT_LUT(32, 0, v->curr_luty[0], v->curr_lutuv[0], 0);
597
833k
    INIT_LUT(32, 0, v->curr_luty[1], v->curr_lutuv[1], 0);
598
833k
    *v->curr_use_ic = 0;
599
833k
}
600
601
453k
static int read_bfraction(VC1Context *v, GetBitContext* gb) {
602
453k
    int bfraction_lut_index = get_bits(gb, 3);
603
604
453k
    if (bfraction_lut_index == 7)
605
28.5k
        bfraction_lut_index = 7 + get_bits(gb, 4);
606
607
453k
    if (bfraction_lut_index == 21) {
608
3.70k
        av_log(v->s.avctx, AV_LOG_ERROR, "bfraction invalid\n");
609
3.70k
        return AVERROR_INVALIDDATA;
610
3.70k
    }
611
449k
    v->bfraction_lut_index = bfraction_lut_index;
612
449k
    v->bfraction           = ff_vc1_bfraction_lut[v->bfraction_lut_index];
613
449k
    return 0;
614
453k
}
615
616
int ff_vc1_parse_frame_header(VC1Context *v, GetBitContext* gb)
617
833k
{
618
833k
    int pqindex, lowquant, status;
619
620
833k
    v->field_mode = 0;
621
833k
    v->fcm = PROGRESSIVE;
622
833k
    if (v->finterpflag)
623
516k
        v->interpfrm = get_bits1(gb);
624
833k
    if (v->s.avctx->codec_id == AV_CODEC_ID_MSS2)
625
56.4k
        v->respic   =
626
56.4k
        v->rangered =
627
56.4k
        v->multires = get_bits(gb, 2) == 1;
628
776k
    else
629
776k
        skip_bits(gb, 2); //framecnt unused
630
833k
    v->rangeredfrm = 0;
631
833k
    if (v->rangered)
632
326k
        v->rangeredfrm = get_bits1(gb);
633
833k
    if (get_bits1(gb)) {
634
156k
        v->s.pict_type = AV_PICTURE_TYPE_P;
635
676k
    } else {
636
676k
        if (v->s.avctx->max_b_frames && !get_bits1(gb)) {
637
235k
            v->s.pict_type = AV_PICTURE_TYPE_B;
638
235k
        } else
639
441k
            v->s.pict_type = AV_PICTURE_TYPE_I;
640
676k
    }
641
642
833k
    v->bi_type = 0;
643
833k
    if (v->s.pict_type == AV_PICTURE_TYPE_B) {
644
235k
        if (read_bfraction(v, gb) < 0)
645
960
            return AVERROR_INVALIDDATA;
646
234k
        if (v->bfraction == 0) {
647
2.73k
            v->s.pict_type = AV_PICTURE_TYPE_BI;
648
2.73k
        }
649
234k
    }
650
832k
    if (v->s.pict_type == AV_PICTURE_TYPE_I || v->s.pict_type == AV_PICTURE_TYPE_BI)
651
444k
        skip_bits(gb, 7); // skip buffer fullness
652
653
832k
    if (v->parse_only)
654
216k
        return 0;
655
656
    /* calculate RND */
657
615k
    if (v->s.pict_type == AV_PICTURE_TYPE_I || v->s.pict_type == AV_PICTURE_TYPE_BI)
658
418k
        v->rnd = 1;
659
615k
    if (v->s.pict_type == AV_PICTURE_TYPE_P)
660
138k
        v->rnd ^= 1;
661
662
615k
    if (get_bits_left(gb) < 5)
663
32.1k
        return AVERROR_INVALIDDATA;
664
    /* Quantizer stuff */
665
583k
    pqindex = get_bits(gb, 5);
666
583k
    if (!pqindex)
667
11.0k
        return -1;
668
572k
    if (v->quantizer_mode == QUANT_FRAME_IMPLICIT)
669
403k
        v->pq = ff_vc1_pquant_table[0][pqindex];
670
168k
    else
671
168k
        v->pq = ff_vc1_pquant_table[1][pqindex];
672
572k
    v->pqindex = pqindex;
673
572k
    if (pqindex < 9)
674
144k
        v->halfpq = get_bits1(gb);
675
428k
    else
676
428k
        v->halfpq = 0;
677
572k
    switch (v->quantizer_mode) {
678
403k
    case QUANT_FRAME_IMPLICIT:
679
403k
        v->pquantizer = pqindex < 9;
680
403k
        break;
681
91.4k
    case QUANT_NON_UNIFORM:
682
91.4k
        v->pquantizer = 0;
683
91.4k
        break;
684
31.3k
    case QUANT_FRAME_EXPLICIT:
685
31.3k
        v->pquantizer = get_bits1(gb);
686
31.3k
        break;
687
46.0k
    default:
688
46.0k
        v->pquantizer = 1;
689
46.0k
        break;
690
572k
    }
691
572k
    v->dquantfrm = 0;
692
572k
    if (v->extended_mv == 1)
693
304k
        v->mvrange = get_unary(gb, 0, 3);
694
572k
    v->k_x = v->mvrange + 9 + (v->mvrange >> 1); //k_x can be 9 10 12 13
695
572k
    v->k_y = v->mvrange + 8; //k_y can be 8 9 10 11
696
572k
    v->range_x = 1 << (v->k_x - 1);
697
572k
    v->range_y = 1 << (v->k_y - 1);
698
572k
    if (v->multires && v->s.pict_type != AV_PICTURE_TYPE_B)
699
330k
        v->respic = get_bits(gb, 2);
700
701
572k
    if (v->res_x8 && (v->s.pict_type == AV_PICTURE_TYPE_I || v->s.pict_type == AV_PICTURE_TYPE_BI)) {
702
294k
        v->x8_type = get_bits1(gb);
703
294k
    } else
704
277k
        v->x8_type = 0;
705
572k
    ff_dlog(v->s.avctx, "%c Frame: QP=[%i]%i (+%i/2) %i\n",
706
572k
            (v->s.pict_type == AV_PICTURE_TYPE_P) ? 'P' : ((v->s.pict_type == AV_PICTURE_TYPE_I) ? 'I' : 'B'),
707
572k
            pqindex, v->pq, v->halfpq, v->rangeredfrm);
708
709
572k
    if (v->first_pic_header_flag)
710
517k
        rotate_luts(v);
711
712
572k
    switch (v->s.pict_type) {
713
128k
    case AV_PICTURE_TYPE_P:
714
128k
        v->tt_index = (v->pq > 4) + (v->pq > 12);
715
716
128k
        lowquant = (v->pq > 12) ? 0 : 1;
717
128k
        v->mv_mode = ff_vc1_mv_pmode_table[lowquant][get_unary(gb, 1, 4)];
718
128k
        if (v->mv_mode == MV_PMODE_INTENSITY_COMP) {
719
28.0k
            v->mv_mode2 = ff_vc1_mv_pmode_table2[lowquant][get_unary(gb, 1, 3)];
720
28.0k
            v->lumscale = get_bits(gb, 6);
721
28.0k
            v->lumshift = get_bits(gb, 6);
722
28.0k
            v->last_use_ic = 1;
723
            /* fill lookup tables for intensity compensation */
724
28.0k
            INIT_LUT(v->lumscale, v->lumshift, v->last_luty[0], v->last_lutuv[0], 1);
725
28.0k
            INIT_LUT(v->lumscale, v->lumshift, v->last_luty[1], v->last_lutuv[1], 1);
726
28.0k
        }
727
128k
        if (v->mv_mode == MV_PMODE_INTENSITY_COMP) {
728
28.0k
            v->s.quarter_sample = (v->mv_mode2 != MV_PMODE_1MV_HPEL &&
729
25.6k
                                   v->mv_mode2 != MV_PMODE_1MV_HPEL_BILIN);
730
28.0k
            v->s.mspel          = (v->mv_mode2 != MV_PMODE_1MV_HPEL_BILIN);
731
100k
        } else {
732
100k
            v->s.quarter_sample = (v->mv_mode != MV_PMODE_1MV_HPEL &&
733
83.7k
                                   v->mv_mode != MV_PMODE_1MV_HPEL_BILIN);
734
100k
            v->s.mspel          = (v->mv_mode != MV_PMODE_1MV_HPEL_BILIN);
735
100k
        }
736
737
128k
        if ((v->mv_mode  == MV_PMODE_INTENSITY_COMP &&
738
28.0k
             v->mv_mode2 == MV_PMODE_MIXED_MV)      ||
739
124k
            v->mv_mode   == MV_PMODE_MIXED_MV) {
740
39.6k
            status = bitplane_decoding(v->mv_type_mb_plane, &v->mv_type_is_raw, v);
741
39.6k
            if (status < 0)
742
1.44k
                return -1;
743
38.2k
            av_log(v->s.avctx, AV_LOG_DEBUG, "MB MV Type plane encoding: "
744
38.2k
                   "Imode: %i, Invert: %i\n", status>>1, status&1);
745
89.1k
        } else {
746
89.1k
            v->mv_type_is_raw = 0;
747
89.1k
            memset(v->mv_type_mb_plane, 0, v->s.mb_stride * v->s.mb_height);
748
89.1k
        }
749
127k
        status = bitplane_decoding(v->s.mbskip_table, &v->skip_is_raw, v);
750
127k
        if (status < 0)
751
3.03k
            return -1;
752
124k
        av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: "
753
124k
               "Imode: %i, Invert: %i\n", status>>1, status&1);
754
755
124k
        if (get_bits_left(gb) < 4)
756
33.9k
            return AVERROR_INVALIDDATA;
757
758
        /* Hopefully this is correct for P-frames */
759
90.3k
        v->mv_table_index = get_bits(gb, 2); //but using ff_vc1_ tables
760
90.3k
        v->cbptab = get_bits(gb, 2);
761
90.3k
        v->cbpcy_vlc = ff_vc1_cbpcy_p_vlc[v->cbptab];
762
763
90.3k
        if (v->dquant) {
764
68.8k
            av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n");
765
68.8k
            vop_dquant_decoding(v);
766
68.8k
        }
767
768
90.3k
        if (v->vstransform) {
769
62.1k
            v->ttmbf = get_bits1(gb);
770
62.1k
            if (v->ttmbf) {
771
32.4k
                v->ttfrm = ff_vc1_ttfrm_to_tt[get_bits(gb, 2)];
772
32.4k
            } else
773
29.7k
                v->ttfrm = 0; //FIXME Is that so ?
774
62.1k
        } else {
775
28.2k
            v->ttmbf = 1;
776
28.2k
            v->ttfrm = TT_8X8;
777
28.2k
        }
778
90.3k
        break;
779
45.2k
    case AV_PICTURE_TYPE_B:
780
45.2k
        v->tt_index = (v->pq > 4) + (v->pq > 12);
781
782
45.2k
        v->mv_mode          = get_bits1(gb) ? MV_PMODE_1MV : MV_PMODE_1MV_HPEL_BILIN;
783
45.2k
        v->s.quarter_sample = (v->mv_mode == MV_PMODE_1MV);
784
45.2k
        v->s.mspel          = v->s.quarter_sample;
785
786
45.2k
        status = bitplane_decoding(v->direct_mb_plane, &v->dmb_is_raw, v);
787
45.2k
        if (status < 0)
788
2.26k
            return -1;
789
42.9k
        av_log(v->s.avctx, AV_LOG_DEBUG, "MB Direct Type plane encoding: "
790
42.9k
               "Imode: %i, Invert: %i\n", status>>1, status&1);
791
42.9k
        status = bitplane_decoding(v->s.mbskip_table, &v->skip_is_raw, v);
792
42.9k
        if (status < 0)
793
888
            return -1;
794
42.0k
        av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: "
795
42.0k
               "Imode: %i, Invert: %i\n", status>>1, status&1);
796
797
42.0k
        v->mv_table_index   = get_bits(gb, 2);
798
42.0k
        v->cbptab           = get_bits(gb, 2);
799
42.0k
        v->cbpcy_vlc        = ff_vc1_cbpcy_p_vlc[v->cbptab];
800
801
42.0k
        if (v->dquant) {
802
33.5k
            av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n");
803
33.5k
            vop_dquant_decoding(v);
804
33.5k
        }
805
806
42.0k
        if (v->vstransform) {
807
31.7k
            v->ttmbf = get_bits1(gb);
808
31.7k
            if (v->ttmbf) {
809
10.7k
                v->ttfrm = ff_vc1_ttfrm_to_tt[get_bits(gb, 2)];
810
10.7k
            } else
811
20.9k
                v->ttfrm = 0;
812
31.7k
        } else {
813
10.3k
            v->ttmbf = 1;
814
10.3k
            v->ttfrm = TT_8X8;
815
10.3k
        }
816
42.0k
        break;
817
572k
    }
818
819
530k
    if (!v->x8_type) {
820
        /* AC Syntax */
821
467k
        v->c_ac_table_index = decode012(gb);
822
467k
        if (v->s.pict_type == AV_PICTURE_TYPE_I || v->s.pict_type == AV_PICTURE_TYPE_BI) {
823
334k
            v->y_ac_table_index = decode012(gb);
824
334k
        }
825
        /* DC Syntax */
826
467k
        v->dc_table_index = get_bits1(gb);
827
467k
    }
828
829
530k
    if (v->s.pict_type == AV_PICTURE_TYPE_BI) {
830
2.63k
        v->s.pict_type = AV_PICTURE_TYPE_B;
831
2.63k
        v->bi_type     = 1;
832
2.63k
    }
833
530k
    return 0;
834
572k
}
835
836
int ff_vc1_parse_frame_header_adv(VC1Context *v, GetBitContext* gb)
837
618k
{
838
618k
    int pqindex, lowquant;
839
618k
    int status;
840
618k
    int field_mode, fcm;
841
842
618k
    v->numref          = 0;
843
618k
    v->p_frame_skipped = 0;
844
618k
    if (v->second_field) {
845
31.5k
        if (v->fcm != ILACE_FIELD || v->field_mode!=1)
846
0
            return -1;
847
31.5k
        if (v->fptype & 4)
848
5.45k
            v->s.pict_type = (v->fptype & 1) ? AV_PICTURE_TYPE_BI : AV_PICTURE_TYPE_B;
849
26.1k
        else
850
26.1k
            v->s.pict_type = (v->fptype & 1) ? AV_PICTURE_TYPE_P : AV_PICTURE_TYPE_I;
851
31.5k
        v->s.cur_pic.ptr->f->pict_type = v->s.pict_type;
852
31.5k
        if (!v->pic_header_flag)
853
28.5k
            goto parse_common_info;
854
31.5k
    }
855
856
589k
    field_mode = 0;
857
589k
    if (v->interlace) {
858
461k
        fcm = decode012(gb);
859
461k
        if (fcm) {
860
292k
            if (fcm == ILACE_FIELD)
861
147k
                field_mode = 1;
862
292k
        }
863
461k
    } else {
864
128k
        fcm = PROGRESSIVE;
865
128k
    }
866
589k
    if (!v->first_pic_header_flag && v->field_mode != field_mode)
867
6.81k
        return AVERROR_INVALIDDATA;
868
582k
    v->field_mode = field_mode;
869
582k
    v->fcm = fcm;
870
871
582k
    av_assert0(    v->s.mb_height == v->s.height + 15 >> 4
872
582k
                || v->s.mb_height == FFALIGN(v->s.height + 15 >> 4, 2));
873
582k
    if (v->field_mode) {
874
142k
        v->s.mb_height = FFALIGN(v->s.height + 15 >> 4, 2);
875
142k
        v->fptype = get_bits(gb, 3);
876
142k
        if (v->fptype & 4) // B-picture
877
83.4k
            v->s.pict_type = (v->fptype & 2) ? AV_PICTURE_TYPE_BI : AV_PICTURE_TYPE_B;
878
58.7k
        else
879
58.7k
            v->s.pict_type = (v->fptype & 2) ? AV_PICTURE_TYPE_P : AV_PICTURE_TYPE_I;
880
440k
    } else {
881
440k
        v->s.mb_height = v->s.height + 15 >> 4;
882
440k
        switch (get_unary(gb, 0, 4)) {
883
230k
        case 0:
884
230k
            v->s.pict_type = AV_PICTURE_TYPE_P;
885
230k
            break;
886
139k
        case 1:
887
139k
            v->s.pict_type = AV_PICTURE_TYPE_B;
888
139k
            break;
889
39.1k
        case 2:
890
39.1k
            v->s.pict_type = AV_PICTURE_TYPE_I;
891
39.1k
            break;
892
15.1k
        case 3:
893
15.1k
            v->s.pict_type = AV_PICTURE_TYPE_BI;
894
15.1k
            break;
895
16.4k
        case 4:
896
16.4k
            v->s.pict_type = AV_PICTURE_TYPE_P; // skipped pic
897
16.4k
            v->p_frame_skipped = 1;
898
16.4k
            break;
899
440k
        }
900
440k
    }
901
582k
    if (v->tfcntrflag)
902
255k
        skip_bits(gb, 8);
903
582k
    if (v->broadcast) {
904
389k
        if (!v->interlace || v->psf) {
905
45.9k
            v->rptfrm = get_bits(gb, 2);
906
343k
        } else {
907
343k
            v->tff = get_bits1(gb);
908
343k
            v->rff = get_bits1(gb);
909
343k
        }
910
389k
    } else {
911
193k
        v->tff = 1;
912
193k
    }
913
582k
    if (v->panscanflag) {
914
268k
        avpriv_report_missing_feature(v->s.avctx, "Pan-scan");
915
        //...
916
268k
    }
917
582k
    if (v->p_frame_skipped) {
918
16.4k
        return 0;
919
16.4k
    }
920
566k
    v->rnd = get_bits1(gb);
921
566k
    if (v->interlace)
922
449k
        v->uvsamp = get_bits1(gb);
923
566k
    if (v->field_mode) {
924
142k
        if (!v->refdist_flag)
925
85.4k
            v->refdist = 0;
926
56.7k
        else if ((v->s.pict_type != AV_PICTURE_TYPE_B) && (v->s.pict_type != AV_PICTURE_TYPE_BI)) {
927
28.4k
            v->refdist = get_bits(gb, 2);
928
28.4k
            if (v->refdist == 3)
929
6.94k
                v->refdist += get_unary(gb, 0, 14);
930
28.4k
            if (v->refdist > 16)
931
532
                return AVERROR_INVALIDDATA;
932
28.4k
        }
933
141k
        if ((v->s.pict_type == AV_PICTURE_TYPE_B) || (v->s.pict_type == AV_PICTURE_TYPE_BI)) {
934
83.4k
            if (read_bfraction(v, gb) < 0)
935
1.42k
                return AVERROR_INVALIDDATA;
936
82.0k
            v->frfd = (v->bfraction * v->refdist) >> 8;
937
82.0k
            v->brfd = v->refdist - v->frfd - 1;
938
82.0k
            if (v->brfd < 0)
939
73.3k
                v->brfd = 0;
940
82.0k
        }
941
140k
        goto parse_common_info;
942
141k
    }
943
423k
    if (v->fcm == PROGRESSIVE) {
944
283k
        if (v->finterpflag)
945
134k
            v->interpfrm = get_bits1(gb);
946
283k
        if (v->s.pict_type == AV_PICTURE_TYPE_B) {
947
77.5k
            if (read_bfraction(v, gb) < 0)
948
727
                return AVERROR_INVALIDDATA;
949
76.8k
            if (v->bfraction == 0) {
950
3.43k
                v->s.pict_type = AV_PICTURE_TYPE_BI; /* XXX: should not happen here */
951
3.43k
            }
952
76.8k
        }
953
283k
    }
954
955
592k
    parse_common_info:
956
592k
    if (v->field_mode)
957
168k
        v->cur_field_type = !(v->tff ^ v->second_field);
958
592k
    pqindex = get_bits(gb, 5);
959
592k
    if (!pqindex)
960
75.5k
        return -1;
961
516k
    if (v->quantizer_mode == QUANT_FRAME_IMPLICIT)
962
290k
        v->pq = ff_vc1_pquant_table[0][pqindex];
963
225k
    else
964
225k
        v->pq = ff_vc1_pquant_table[1][pqindex];
965
516k
    v->pqindex = pqindex;
966
516k
    if (pqindex < 9)
967
132k
        v->halfpq = get_bits1(gb);
968
383k
    else
969
383k
        v->halfpq = 0;
970
516k
    switch (v->quantizer_mode) {
971
290k
    case QUANT_FRAME_IMPLICIT:
972
290k
        v->pquantizer = pqindex < 9;
973
290k
        break;
974
163k
    case QUANT_NON_UNIFORM:
975
163k
        v->pquantizer = 0;
976
163k
        break;
977
28.8k
    case QUANT_FRAME_EXPLICIT:
978
28.8k
        v->pquantizer = get_bits1(gb);
979
28.8k
        break;
980
32.9k
    default:
981
32.9k
        v->pquantizer = 1;
982
32.9k
        break;
983
516k
    }
984
516k
    v->dquantfrm = 0;
985
516k
    if (v->postprocflag)
986
193k
        v->postproc = get_bits(gb, 2);
987
988
516k
    if (v->parse_only)
989
89.1k
        return 0;
990
991
427k
    if (v->first_pic_header_flag)
992
316k
        rotate_luts(v);
993
994
427k
    switch (v->s.pict_type) {
995
47.6k
    case AV_PICTURE_TYPE_I:
996
65.0k
    case AV_PICTURE_TYPE_BI:
997
65.0k
        if (v->fcm == ILACE_FRAME) { //interlace frame picture
998
14.7k
            status = bitplane_decoding(v->fieldtx_plane, &v->fieldtx_is_raw, v);
999
14.7k
            if (status < 0)
1000
615
                return -1;
1001
14.1k
            av_log(v->s.avctx, AV_LOG_DEBUG, "FIELDTX plane encoding: "
1002
14.1k
                   "Imode: %i, Invert: %i\n", status>>1, status&1);
1003
14.1k
        } else
1004
50.3k
            v->fieldtx_is_raw = 0;
1005
64.4k
        status = bitplane_decoding(v->acpred_plane, &v->acpred_is_raw, v);
1006
64.4k
        if (status < 0)
1007
1.20k
            return -1;
1008
63.2k
        av_log(v->s.avctx, AV_LOG_DEBUG, "ACPRED plane encoding: "
1009
63.2k
               "Imode: %i, Invert: %i\n", status>>1, status&1);
1010
63.2k
        v->condover = CONDOVER_NONE;
1011
63.2k
        if (v->overlap && v->pq <= 8) {
1012
13.4k
            v->condover = decode012(gb);
1013
13.4k
            if (v->condover == CONDOVER_SELECT) {
1014
2.16k
                status = bitplane_decoding(v->over_flags_plane, &v->overflg_is_raw, v);
1015
2.16k
                if (status < 0)
1016
308
                    return -1;
1017
1.85k
                av_log(v->s.avctx, AV_LOG_DEBUG, "CONDOVER plane encoding: "
1018
1.85k
                       "Imode: %i, Invert: %i\n", status>>1, status&1);
1019
1.85k
            }
1020
13.4k
        }
1021
62.9k
        break;
1022
233k
    case AV_PICTURE_TYPE_P:
1023
233k
        if (v->field_mode) {
1024
51.7k
            v->numref = get_bits1(gb);
1025
51.7k
            if (!v->numref) {
1026
23.7k
                v->reffield          = get_bits1(gb);
1027
23.7k
                v->ref_field_type[0] = v->reffield ^ !v->cur_field_type;
1028
23.7k
            }
1029
51.7k
        }
1030
233k
        if (v->extended_mv)
1031
94.1k
            v->mvrange = get_unary(gb, 0, 3);
1032
139k
        else
1033
139k
            v->mvrange = 0;
1034
233k
        if (v->interlace) {
1035
189k
            if (v->extended_dmv)
1036
85.8k
                v->dmvrange = get_unary(gb, 0, 3);
1037
104k
            else
1038
104k
                v->dmvrange = 0;
1039
189k
            if (v->fcm == ILACE_FRAME) { // interlaced frame picture
1040
58.2k
                v->fourmvswitch = get_bits1(gb);
1041
58.2k
                v->intcomp      = get_bits1(gb);
1042
58.2k
                if (v->intcomp) {
1043
29.9k
                    v->lumscale = get_bits(gb, 6);
1044
29.9k
                    v->lumshift = get_bits(gb, 6);
1045
29.9k
                    INIT_LUT(v->lumscale, v->lumshift, v->last_luty[0], v->last_lutuv[0], 1);
1046
29.9k
                    INIT_LUT(v->lumscale, v->lumshift, v->last_luty[1], v->last_lutuv[1], 1);
1047
29.9k
                    v->last_use_ic = 1;
1048
29.9k
                }
1049
58.2k
                status = bitplane_decoding(v->s.mbskip_table, &v->skip_is_raw, v);
1050
58.2k
                if (status < 0)
1051
1.73k
                    return -1;
1052
56.4k
                av_log(v->s.avctx, AV_LOG_DEBUG, "SKIPMB plane encoding: "
1053
56.4k
                       "Imode: %i, Invert: %i\n", status>>1, status&1);
1054
56.4k
                v->mbmodetab = get_bits(gb, 2);
1055
56.4k
                if (v->fourmvswitch)
1056
30.0k
                    v->mbmode_vlc = ff_vc1_intfr_4mv_mbmode_vlc[v->mbmodetab];
1057
26.3k
                else
1058
26.3k
                    v->mbmode_vlc = ff_vc1_intfr_non4mv_mbmode_vlc[v->mbmodetab];
1059
56.4k
                v->imvtab      = get_bits(gb, 2);
1060
56.4k
                v->imv_vlc     = ff_vc1_1ref_mvdata_vlc[v->imvtab];
1061
                // interlaced p-picture cbpcy range is [1, 63]
1062
56.4k
                v->icbptab     = get_bits(gb, 3);
1063
56.4k
                v->cbpcy_vlc   = ff_vc1_icbpcy_vlc[v->icbptab];
1064
56.4k
                v->twomvbptab     = get_bits(gb, 2);
1065
56.4k
                v->twomvbp_vlc = ff_vc1_2mv_block_pattern_vlc[v->twomvbptab];
1066
56.4k
                if (v->fourmvswitch) {
1067
30.0k
                    v->fourmvbptab     = get_bits(gb, 2);
1068
30.0k
                    v->fourmvbp_vlc = ff_vc1_4mv_block_pattern_vlc[v->fourmvbptab];
1069
30.0k
                }
1070
56.4k
            }
1071
189k
        }
1072
232k
        v->k_x = v->mvrange + 9 + (v->mvrange >> 1); //k_x can be 9 10 12 13
1073
232k
        v->k_y = v->mvrange + 8; //k_y can be 8 9 10 11
1074
232k
        v->range_x = 1 << (v->k_x - 1);
1075
232k
        v->range_y = 1 << (v->k_y - 1);
1076
1077
232k
        v->tt_index = (v->pq > 4) + (v->pq > 12);
1078
232k
        if (v->fcm != ILACE_FRAME) {
1079
175k
            int mvmode;
1080
175k
            mvmode     = get_unary(gb, 1, 4);
1081
175k
            lowquant   = (v->pq > 12) ? 0 : 1;
1082
175k
            v->mv_mode = ff_vc1_mv_pmode_table[lowquant][mvmode];
1083
175k
            if (v->mv_mode == MV_PMODE_INTENSITY_COMP) {
1084
30.5k
                int mvmode2;
1085
30.5k
                mvmode2 = get_unary(gb, 1, 3);
1086
30.5k
                v->mv_mode2 = ff_vc1_mv_pmode_table2[lowquant][mvmode2];
1087
30.5k
                if (v->field_mode) {
1088
22.3k
                    v->intcompfield = decode210(gb) ^ 3;
1089
22.3k
                } else
1090
8.27k
                    v->intcompfield = 3;
1091
1092
30.5k
                v->lumscale2 = v->lumscale = 32;
1093
30.5k
                v->lumshift2 = v->lumshift =  0;
1094
30.5k
                if (v->intcompfield & 1) {
1095
27.2k
                    v->lumscale = get_bits(gb, 6);
1096
27.2k
                    v->lumshift = get_bits(gb, 6);
1097
27.2k
                }
1098
30.5k
                if ((v->intcompfield & 2) && v->field_mode) {
1099
18.6k
                    v->lumscale2 = get_bits(gb, 6);
1100
18.6k
                    v->lumshift2 = get_bits(gb, 6);
1101
18.6k
                } else if(!v->field_mode) {
1102
8.27k
                    v->lumscale2 = v->lumscale;
1103
8.27k
                    v->lumshift2 = v->lumshift;
1104
8.27k
                }
1105
30.5k
                if (v->field_mode && v->second_field) {
1106
8.95k
                    if (v->cur_field_type) {
1107
5.74k
                        INIT_LUT(v->lumscale , v->lumshift , v->curr_luty[v->cur_field_type^1], v->curr_lutuv[v->cur_field_type^1], 0);
1108
5.74k
                        INIT_LUT(v->lumscale2, v->lumshift2, v->last_luty[v->cur_field_type  ], v->last_lutuv[v->cur_field_type  ], 1);
1109
5.74k
                    } else {
1110
3.21k
                        INIT_LUT(v->lumscale2, v->lumshift2, v->curr_luty[v->cur_field_type^1], v->curr_lutuv[v->cur_field_type^1], 0);
1111
3.21k
                        INIT_LUT(v->lumscale , v->lumshift , v->last_luty[v->cur_field_type  ], v->last_lutuv[v->cur_field_type  ], 1);
1112
3.21k
                    }
1113
8.95k
                    v->next_use_ic = *v->curr_use_ic = 1;
1114
21.6k
                } else {
1115
21.6k
                    INIT_LUT(v->lumscale , v->lumshift , v->last_luty[0], v->last_lutuv[0], 1);
1116
21.6k
                    INIT_LUT(v->lumscale2, v->lumshift2, v->last_luty[1], v->last_lutuv[1], 1);
1117
21.6k
                }
1118
30.5k
                v->last_use_ic = 1;
1119
30.5k
            }
1120
175k
            if (v->mv_mode == MV_PMODE_INTENSITY_COMP) {
1121
30.5k
                v->s.quarter_sample = (v->mv_mode2 != MV_PMODE_1MV_HPEL &&
1122
22.3k
                                       v->mv_mode2 != MV_PMODE_1MV_HPEL_BILIN);
1123
30.5k
                v->s.mspel          = (v->mv_mode2 != MV_PMODE_1MV_HPEL_BILIN);
1124
145k
            } else {
1125
145k
                v->s.quarter_sample = (v->mv_mode != MV_PMODE_1MV_HPEL &&
1126
133k
                                       v->mv_mode != MV_PMODE_1MV_HPEL_BILIN);
1127
145k
                v->s.mspel          = (v->mv_mode != MV_PMODE_1MV_HPEL_BILIN);
1128
145k
            }
1129
175k
        }
1130
232k
        if (v->fcm == PROGRESSIVE) { // progressive
1131
124k
            if ((v->mv_mode == MV_PMODE_INTENSITY_COMP &&
1132
8.27k
                 v->mv_mode2 == MV_PMODE_MIXED_MV)
1133
120k
                || v->mv_mode == MV_PMODE_MIXED_MV) {
1134
52.0k
                status = bitplane_decoding(v->mv_type_mb_plane, &v->mv_type_is_raw, v);
1135
52.0k
                if (status < 0)
1136
644
                    return -1;
1137
51.4k
                av_log(v->s.avctx, AV_LOG_DEBUG, "MB MV Type plane encoding: "
1138
51.4k
                       "Imode: %i, Invert: %i\n", status>>1, status&1);
1139
71.9k
            } else {
1140
71.9k
                v->mv_type_is_raw = 0;
1141
71.9k
                memset(v->mv_type_mb_plane, 0, v->s.mb_stride * v->s.mb_height);
1142
71.9k
            }
1143
123k
            status = bitplane_decoding(v->s.mbskip_table, &v->skip_is_raw, v);
1144
123k
            if (status < 0)
1145
1.32k
                return -1;
1146
122k
            av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: "
1147
122k
                   "Imode: %i, Invert: %i\n", status>>1, status&1);
1148
1149
            /* Hopefully this is correct for P-frames */
1150
122k
            v->mv_table_index   = get_bits(gb, 2); //but using ff_vc1_ tables
1151
122k
            v->cbptab           = get_bits(gb, 2);
1152
122k
            v->cbpcy_vlc        = ff_vc1_cbpcy_p_vlc[v->cbptab];
1153
122k
        } else if (v->fcm == ILACE_FRAME) { // frame interlaced
1154
56.4k
            v->s.quarter_sample = 1;
1155
56.4k
            v->s.mspel          = 1;
1156
56.4k
        } else {    // field interlaced
1157
51.7k
            v->mbmodetab = get_bits(gb, 3);
1158
51.7k
            v->imvtab = get_bits(gb, 2 + v->numref);
1159
51.7k
            if (!v->numref)
1160
23.7k
                v->imv_vlc = ff_vc1_1ref_mvdata_vlc[v->imvtab];
1161
27.9k
            else
1162
27.9k
                v->imv_vlc = ff_vc1_2ref_mvdata_vlc[v->imvtab];
1163
51.7k
            v->icbptab = get_bits(gb, 3);
1164
51.7k
            v->cbpcy_vlc = ff_vc1_icbpcy_vlc[v->icbptab];
1165
51.7k
            if ((v->mv_mode == MV_PMODE_INTENSITY_COMP &&
1166
49.7k
                v->mv_mode2 == MV_PMODE_MIXED_MV) || v->mv_mode == MV_PMODE_MIXED_MV) {
1167
12.8k
                v->fourmvbptab     = get_bits(gb, 2);
1168
12.8k
                v->fourmvbp_vlc = ff_vc1_4mv_block_pattern_vlc[v->fourmvbptab];
1169
12.8k
                v->mbmode_vlc   = ff_vc1_if_mmv_mbmode_vlc[v->mbmodetab];
1170
38.9k
            } else {
1171
38.9k
                v->mbmode_vlc   = ff_vc1_if_1mv_mbmode_vlc[v->mbmodetab];
1172
38.9k
            }
1173
51.7k
        }
1174
230k
        if (v->dquant) {
1175
163k
            av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n");
1176
163k
            vop_dquant_decoding(v);
1177
163k
        }
1178
1179
230k
        if (v->vstransform) {
1180
130k
            v->ttmbf = get_bits1(gb);
1181
130k
            if (v->ttmbf) {
1182
52.9k
                v->ttfrm = ff_vc1_ttfrm_to_tt[get_bits(gb, 2)];
1183
52.9k
            } else
1184
77.3k
                v->ttfrm = 0; //FIXME Is that so ?
1185
130k
        } else {
1186
99.9k
            v->ttmbf = 1;
1187
99.9k
            v->ttfrm = TT_8X8;
1188
99.9k
        }
1189
230k
        break;
1190
128k
    case AV_PICTURE_TYPE_B:
1191
128k
        if (v->fcm == ILACE_FRAME) {
1192
56.9k
            if (read_bfraction(v, gb) < 0)
1193
594
                return AVERROR_INVALIDDATA;
1194
56.3k
            if (v->bfraction == 0) {
1195
530
                return -1;
1196
530
            }
1197
56.3k
        }
1198
127k
        if (v->extended_mv)
1199
47.6k
            v->mvrange = get_unary(gb, 0, 3);
1200
79.6k
        else
1201
79.6k
            v->mvrange = 0;
1202
127k
        v->k_x     = v->mvrange + 9 + (v->mvrange >> 1); //k_x can be 9 10 12 13
1203
127k
        v->k_y     = v->mvrange + 8; //k_y can be 8 9 10 11
1204
127k
        v->range_x = 1 << (v->k_x - 1);
1205
127k
        v->range_y = 1 << (v->k_y - 1);
1206
1207
127k
        v->tt_index = (v->pq > 4) + (v->pq > 12);
1208
1209
127k
        if (v->field_mode) {
1210
24.8k
            int mvmode;
1211
24.8k
            av_log(v->s.avctx, AV_LOG_DEBUG, "B Fields\n");
1212
24.8k
            if (v->extended_dmv)
1213
9.73k
                v->dmvrange = get_unary(gb, 0, 3);
1214
24.8k
            mvmode = get_unary(gb, 1, 3);
1215
24.8k
            lowquant = (v->pq > 12) ? 0 : 1;
1216
24.8k
            v->mv_mode          = ff_vc1_mv_pmode_table2[lowquant][mvmode];
1217
24.8k
            v->s.quarter_sample = (v->mv_mode == MV_PMODE_1MV || v->mv_mode == MV_PMODE_MIXED_MV);
1218
24.8k
            v->s.mspel          = (v->mv_mode != MV_PMODE_1MV_HPEL_BILIN);
1219
24.8k
            status = bitplane_decoding(v->forward_mb_plane, &v->fmb_is_raw, v);
1220
24.8k
            if (status < 0)
1221
566
                return -1;
1222
24.3k
            av_log(v->s.avctx, AV_LOG_DEBUG, "MB Forward Type plane encoding: "
1223
24.3k
                   "Imode: %i, Invert: %i\n", status>>1, status&1);
1224
24.3k
            v->mbmodetab = get_bits(gb, 3);
1225
24.3k
            if (v->mv_mode == MV_PMODE_MIXED_MV)
1226
8.39k
                v->mbmode_vlc = ff_vc1_if_mmv_mbmode_vlc[v->mbmodetab];
1227
15.9k
            else
1228
15.9k
                v->mbmode_vlc = ff_vc1_if_1mv_mbmode_vlc[v->mbmodetab];
1229
24.3k
            v->imvtab     = get_bits(gb, 3);
1230
24.3k
            v->imv_vlc   = ff_vc1_2ref_mvdata_vlc[v->imvtab];
1231
24.3k
            v->icbptab   = get_bits(gb, 3);
1232
24.3k
            v->cbpcy_vlc = ff_vc1_icbpcy_vlc[v->icbptab];
1233
24.3k
            if (v->mv_mode == MV_PMODE_MIXED_MV) {
1234
8.39k
                v->fourmvbptab     = get_bits(gb, 2);
1235
8.39k
                v->fourmvbp_vlc = ff_vc1_4mv_block_pattern_vlc[v->fourmvbptab];
1236
8.39k
            }
1237
24.3k
            v->numref = 1; // interlaced field B pictures are always 2-ref
1238
102k
        } else if (v->fcm == ILACE_FRAME) {
1239
55.8k
            if (v->extended_dmv)
1240
20.8k
                v->dmvrange = get_unary(gb, 0, 3);
1241
55.8k
            if (get_bits1(gb)) /* intcomp - present but shall always be 0 */
1242
9.21k
                av_log(v->s.avctx, AV_LOG_WARNING, "Intensity compensation set for B picture\n");
1243
55.8k
            v->intcomp          = 0;
1244
55.8k
            v->mv_mode          = MV_PMODE_1MV;
1245
55.8k
            v->fourmvswitch     = 0;
1246
55.8k
            v->s.quarter_sample = 1;
1247
55.8k
            v->s.mspel          = 1;
1248
55.8k
            status              = bitplane_decoding(v->direct_mb_plane, &v->dmb_is_raw, v);
1249
55.8k
            if (status < 0)
1250
2.54k
                return -1;
1251
53.3k
            av_log(v->s.avctx, AV_LOG_DEBUG, "MB Direct Type plane encoding: "
1252
53.3k
                   "Imode: %i, Invert: %i\n", status>>1, status&1);
1253
53.3k
            status = bitplane_decoding(v->s.mbskip_table, &v->skip_is_raw, v);
1254
53.3k
            if (status < 0)
1255
972
                return -1;
1256
52.3k
            av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: "
1257
52.3k
                   "Imode: %i, Invert: %i\n", status>>1, status&1);
1258
52.3k
            v->mbmodetab       = get_bits(gb, 2);
1259
52.3k
            v->mbmode_vlc   = ff_vc1_intfr_non4mv_mbmode_vlc[v->mbmodetab];
1260
52.3k
            v->imvtab       = get_bits(gb, 2);
1261
52.3k
            v->imv_vlc      = ff_vc1_1ref_mvdata_vlc[v->imvtab];
1262
            // interlaced p/b-picture cbpcy range is [1, 63]
1263
52.3k
            v->icbptab      = get_bits(gb, 3);
1264
52.3k
            v->cbpcy_vlc    = ff_vc1_icbpcy_vlc[v->icbptab];
1265
52.3k
            v->twomvbptab      = get_bits(gb, 2);
1266
52.3k
            v->twomvbp_vlc  = ff_vc1_2mv_block_pattern_vlc[v->twomvbptab];
1267
52.3k
            v->fourmvbptab     = get_bits(gb, 2);
1268
52.3k
            v->fourmvbp_vlc = ff_vc1_4mv_block_pattern_vlc[v->fourmvbptab];
1269
52.3k
        } else {
1270
46.4k
            v->mv_mode          = get_bits1(gb) ? MV_PMODE_1MV : MV_PMODE_1MV_HPEL_BILIN;
1271
46.4k
            v->s.quarter_sample = (v->mv_mode == MV_PMODE_1MV);
1272
46.4k
            v->s.mspel          = v->s.quarter_sample;
1273
46.4k
            status              = bitplane_decoding(v->direct_mb_plane, &v->dmb_is_raw, v);
1274
46.4k
            if (status < 0)
1275
1.63k
                return -1;
1276
44.8k
            av_log(v->s.avctx, AV_LOG_DEBUG, "MB Direct Type plane encoding: "
1277
44.8k
                   "Imode: %i, Invert: %i\n", status>>1, status&1);
1278
44.8k
            status = bitplane_decoding(v->s.mbskip_table, &v->skip_is_raw, v);
1279
44.8k
            if (status < 0)
1280
801
                return -1;
1281
44.0k
            av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: "
1282
44.0k
                   "Imode: %i, Invert: %i\n", status>>1, status&1);
1283
44.0k
            v->mv_table_index = get_bits(gb, 2);
1284
44.0k
            v->cbptab = get_bits(gb, 2);
1285
44.0k
            v->cbpcy_vlc = ff_vc1_cbpcy_p_vlc[v->cbptab];
1286
44.0k
        }
1287
1288
120k
        if (v->dquant) {
1289
84.7k
            av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n");
1290
84.7k
            vop_dquant_decoding(v);
1291
84.7k
        }
1292
1293
120k
        if (v->vstransform) {
1294
74.3k
            v->ttmbf = get_bits1(gb);
1295
74.3k
            if (v->ttmbf) {
1296
23.6k
                v->ttfrm = ff_vc1_ttfrm_to_tt[get_bits(gb, 2)];
1297
23.6k
            } else
1298
50.7k
                v->ttfrm = 0;
1299
74.3k
        } else {
1300
46.3k
            v->ttmbf = 1;
1301
46.3k
            v->ttfrm = TT_8X8;
1302
46.3k
        }
1303
120k
        break;
1304
427k
    }
1305
1306
1307
    /* AC Syntax */
1308
413k
    v->c_ac_table_index = decode012(gb);
1309
413k
    if (v->s.pict_type == AV_PICTURE_TYPE_I || v->s.pict_type == AV_PICTURE_TYPE_BI) {
1310
62.9k
        v->y_ac_table_index = decode012(gb);
1311
62.9k
    }
1312
350k
    else if (v->fcm != PROGRESSIVE && !v->s.quarter_sample) {
1313
38.3k
        v->range_x <<= 1;
1314
38.3k
        v->range_y <<= 1;
1315
38.3k
    }
1316
1317
    /* DC Syntax */
1318
413k
    v->dc_table_index = get_bits1(gb);
1319
413k
    if ((v->s.pict_type == AV_PICTURE_TYPE_I || v->s.pict_type == AV_PICTURE_TYPE_BI)
1320
62.9k
        && v->dquant) {
1321
46.3k
        av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n");
1322
46.3k
        vop_dquant_decoding(v);
1323
46.3k
    }
1324
1325
413k
    v->bi_type = (v->s.pict_type == AV_PICTURE_TYPE_BI);
1326
413k
    if (v->bi_type)
1327
16.1k
        v->s.pict_type = AV_PICTURE_TYPE_B;
1328
1329
413k
    return 0;
1330
427k
}