Coverage Report

Created: 2026-10-28 08:13

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ffmpeg/libavcodec/sheervideo.c
Line
Count
Source
1
/*
2
 * BitJazz SheerVideo decoder
3
 * Copyright (c) 2016 Paul B Mahol
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
#include "libavutil/attributes.h"
23
#define CACHED_BITSTREAM_READER !ARCH_X86_32
24
3.37G
#define SHEER_VLC_BITS 12
25
26
#include "libavutil/intreadwrite.h"
27
#include "avcodec.h"
28
#include "codec_internal.h"
29
#include "get_bits.h"
30
#include "thread.h"
31
#include "sheervideodata.h"
32
33
typedef struct SheerVideoContext {
34
    unsigned format;
35
    int alt;
36
    VLC vlc[2];
37
    void (*decode_frame)(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb);
38
} SheerVideoContext;
39
40
static void decode_ca4i(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
41
1.92k
{
42
1.92k
    SheerVideoContext *s = avctx->priv_data;
43
1.92k
    uint16_t *dst_y, *dst_u, *dst_v, *dst_a;
44
1.92k
    int x, y;
45
46
1.92k
    dst_a = (uint16_t *)p->data[3];
47
1.92k
    dst_y = (uint16_t *)p->data[0];
48
1.92k
    dst_u = (uint16_t *)p->data[1];
49
1.92k
    dst_v = (uint16_t *)p->data[2];
50
51
3.87M
    for (y = 0; y < avctx->height; y++) {
52
3.87M
        if (get_bits1(gb)) {
53
107k
            for (x = 0; x < avctx->width; x++) {
54
95.0k
                dst_a[x] = get_bits(gb, 10);
55
95.0k
                dst_y[x] = get_bits(gb, 10);
56
95.0k
                dst_u[x] = get_bits(gb, 10);
57
95.0k
                dst_v[x] = get_bits(gb, 10);
58
95.0k
            }
59
3.86M
        } else {
60
3.86M
            int pred[4] = { 502, 512, 512, 502 };
61
62
35.7M
            for (x = 0; x < avctx->width; x++) {
63
31.8M
                int y, u, v, a;
64
65
31.8M
                a = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
66
31.8M
                y = get_vlc2(gb, s->vlc[0].table, SHEER_VLC_BITS, 2);
67
31.8M
                u = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
68
31.8M
                v = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
69
70
31.8M
                dst_a[x] = pred[3] = (a + pred[3]) & 0x3ff;
71
31.8M
                dst_y[x] = pred[0] = (y + pred[0]) & 0x3ff;
72
31.8M
                dst_u[x] = pred[1] = (u + pred[1]) & 0x3ff;
73
31.8M
                dst_v[x] = pred[2] = (v + pred[2]) & 0x3ff;
74
31.8M
            }
75
3.86M
        }
76
77
3.87M
        dst_y += p->linesize[0] / 2;
78
3.87M
        dst_u += p->linesize[1] / 2;
79
3.87M
        dst_v += p->linesize[2] / 2;
80
3.87M
        dst_a += p->linesize[3] / 2;
81
3.87M
    }
82
1.92k
}
83
84
static void decode_ca4p(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
85
4.49k
{
86
4.49k
    SheerVideoContext *s = avctx->priv_data;
87
4.49k
    uint16_t *dst_y, *dst_u, *dst_v, *dst_a;
88
4.49k
    int x, y;
89
90
4.49k
    dst_a = (uint16_t *)p->data[3];
91
4.49k
    dst_y = (uint16_t *)p->data[0];
92
4.49k
    dst_u = (uint16_t *)p->data[1];
93
4.49k
    dst_v = (uint16_t *)p->data[2];
94
95
4.49k
    if (get_bits1(gb)) {
96
2.68M
        for (x = 0; x < avctx->width; x++) {
97
2.68M
            dst_a[x] = get_bits(gb, 10);
98
2.68M
            dst_y[x] = get_bits(gb, 10);
99
2.68M
            dst_u[x] = get_bits(gb, 10);
100
2.68M
            dst_v[x] = get_bits(gb, 10);
101
2.68M
        }
102
2.83k
    } else {
103
2.83k
        int pred[4] = { 502, 512, 512, 502 };
104
105
14.3M
        for (x = 0; x < avctx->width; x++) {
106
14.3M
            int y, u, v, a;
107
108
14.3M
            a = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
109
14.3M
            y = get_vlc2(gb, s->vlc[0].table, SHEER_VLC_BITS, 2);
110
14.3M
            u = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
111
14.3M
            v = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
112
113
14.3M
            dst_a[x] = pred[3] = (a + pred[3]) & 0x3ff;
114
14.3M
            dst_y[x] = pred[0] = (y + pred[0]) & 0x3ff;
115
14.3M
            dst_u[x] = pred[1] = (u + pred[1]) & 0x3ff;
116
14.3M
            dst_v[x] = pred[2] = (v + pred[2]) & 0x3ff;
117
14.3M
        }
118
2.83k
    }
119
120
4.49k
    dst_y += p->linesize[0] / 2;
121
4.49k
    dst_u += p->linesize[1] / 2;
122
4.49k
    dst_v += p->linesize[2] / 2;
123
4.49k
    dst_a += p->linesize[3] / 2;
124
125
1.46M
    for (y = 1; y < avctx->height; y++) {
126
1.45M
        if (get_bits1(gb)) {
127
181k
            for (x = 0; x < avctx->width; x++) {
128
168k
                dst_a[x] = get_bits(gb, 10);
129
168k
                dst_y[x] = get_bits(gb, 10);
130
168k
                dst_u[x] = get_bits(gb, 10);
131
168k
                dst_v[x] = get_bits(gb, 10);
132
168k
            }
133
1.44M
        } else {
134
1.44M
            int pred_TL[4], pred_L[4], pred_T[4];
135
1.44M
            int y, u, v, a;
136
137
1.44M
            pred_TL[0] = pred_L[0] = dst_y[-p->linesize[0] / 2];
138
1.44M
            pred_TL[1] = pred_L[1] = dst_u[-p->linesize[1] / 2];
139
1.44M
            pred_TL[2] = pred_L[2] = dst_v[-p->linesize[2] / 2];
140
1.44M
            pred_TL[3] = pred_L[3] = dst_a[-p->linesize[3] / 2];
141
142
25.1M
            for (x = 0; x < avctx->width; x++) {
143
23.7M
                pred_T[0] = dst_y[-p->linesize[0] / 2 + x];
144
23.7M
                pred_T[1] = dst_u[-p->linesize[1] / 2 + x];
145
23.7M
                pred_T[2] = dst_v[-p->linesize[2] / 2 + x];
146
23.7M
                pred_T[3] = dst_a[-p->linesize[3] / 2 + x];
147
148
23.7M
                a = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
149
23.7M
                y = get_vlc2(gb, s->vlc[0].table, SHEER_VLC_BITS, 2);
150
23.7M
                u = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
151
23.7M
                v = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
152
153
23.7M
                dst_a[x] = pred_L[3] = (a + ((3 * (pred_T[3] + pred_L[3]) - 2 * pred_TL[3]) >> 2)) & 0x3ff;
154
23.7M
                dst_y[x] = pred_L[0] = (y + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0x3ff;
155
23.7M
                dst_u[x] = pred_L[1] = (u + ((3 * (pred_T[1] + pred_L[1]) - 2 * pred_TL[1]) >> 2)) & 0x3ff;
156
23.7M
                dst_v[x] = pred_L[2] = (v + ((3 * (pred_T[2] + pred_L[2]) - 2 * pred_TL[2]) >> 2)) & 0x3ff;
157
158
23.7M
                pred_TL[0] = pred_T[0];
159
23.7M
                pred_TL[1] = pred_T[1];
160
23.7M
                pred_TL[2] = pred_T[2];
161
23.7M
                pred_TL[3] = pred_T[3];
162
23.7M
            }
163
1.44M
        }
164
165
1.45M
        dst_y += p->linesize[0] / 2;
166
1.45M
        dst_u += p->linesize[1] / 2;
167
1.45M
        dst_v += p->linesize[2] / 2;
168
1.45M
        dst_a += p->linesize[3] / 2;
169
1.45M
    }
170
4.49k
}
171
172
static void decode_ybr10i(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
173
1.43k
{
174
1.43k
    SheerVideoContext *s = avctx->priv_data;
175
1.43k
    uint16_t *dst_y, *dst_u, *dst_v;
176
1.43k
    int x, y;
177
178
1.43k
    dst_y = (uint16_t *)p->data[0];
179
1.43k
    dst_u = (uint16_t *)p->data[1];
180
1.43k
    dst_v = (uint16_t *)p->data[2];
181
182
1.64M
    for (y = 0; y < avctx->height; y++) {
183
1.64M
        if (get_bits1(gb)) {
184
352k
            for (x = 0; x < avctx->width; x++) {
185
328k
                dst_y[x] = get_bits(gb, 10);
186
328k
                dst_u[x] = get_bits(gb, 10);
187
328k
                dst_v[x] = get_bits(gb, 10);
188
328k
            }
189
1.61M
        } else {
190
1.61M
            int pred[4] = { 502, 512, 512, 512 };
191
192
38.0M
            for (x = 0; x < avctx->width; x++) {
193
36.4M
                int y, u, v;
194
195
36.4M
                y = get_vlc2(gb, s->vlc[0].table, SHEER_VLC_BITS, 2);
196
36.4M
                u = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
197
36.4M
                v = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
198
199
36.4M
                dst_y[x] = pred[0] = (y + pred[0]) & 0x3ff;
200
36.4M
                dst_u[x] = pred[1] = (u + pred[1]) & 0x3ff;
201
36.4M
                dst_v[x] = pred[2] = (v + pred[2]) & 0x3ff;
202
36.4M
            }
203
1.61M
        }
204
205
1.64M
        dst_y += p->linesize[0] / 2;
206
1.64M
        dst_u += p->linesize[1] / 2;
207
1.64M
        dst_v += p->linesize[2] / 2;
208
1.64M
    }
209
1.43k
}
210
211
static void decode_ybr10(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
212
2.79k
{
213
2.79k
    SheerVideoContext *s = avctx->priv_data;
214
2.79k
    uint16_t *dst_y, *dst_u, *dst_v;
215
2.79k
    int x, y;
216
217
2.79k
    dst_y = (uint16_t *)p->data[0];
218
2.79k
    dst_u = (uint16_t *)p->data[1];
219
2.79k
    dst_v = (uint16_t *)p->data[2];
220
221
2.79k
    if (get_bits1(gb)) {
222
1.52M
        for (x = 0; x < avctx->width; x++) {
223
1.52M
            dst_y[x] = get_bits(gb, 10);
224
1.52M
            dst_u[x] = get_bits(gb, 10);
225
1.52M
            dst_v[x] = get_bits(gb, 10);
226
1.52M
        }
227
1.77k
    } else {
228
1.77k
        int pred[4] = { 502, 512, 512, 512 };
229
230
4.25M
        for (x = 0; x < avctx->width; x++) {
231
4.25M
            int y, u, v;
232
233
4.25M
            y = get_vlc2(gb, s->vlc[0].table, SHEER_VLC_BITS, 2);
234
4.25M
            u = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
235
4.25M
            v = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
236
237
4.25M
            dst_y[x] = pred[0] = (y + pred[0]) & 0x3ff;
238
4.25M
            dst_u[x] = pred[1] = (u + pred[1]) & 0x3ff;
239
4.25M
            dst_v[x] = pred[2] = (v + pred[2]) & 0x3ff;
240
4.25M
        }
241
1.77k
    }
242
243
2.79k
    dst_y += p->linesize[0] / 2;
244
2.79k
    dst_u += p->linesize[1] / 2;
245
2.79k
    dst_v += p->linesize[2] / 2;
246
247
3.58M
    for (y = 1; y < avctx->height; y++) {
248
3.57M
        if (get_bits1(gb)) {
249
277k
            for (x = 0; x < avctx->width; x++) {
250
253k
                dst_y[x] = get_bits(gb, 10);
251
253k
                dst_u[x] = get_bits(gb, 10);
252
253k
                dst_v[x] = get_bits(gb, 10);
253
253k
            }
254
3.55M
        } else {
255
3.55M
            int pred_TL[4], pred_L[4], pred_T[4];
256
3.55M
            int y, u, v;
257
258
3.55M
            pred_TL[0] = pred_L[0] = dst_y[-p->linesize[0] / 2];
259
3.55M
            pred_TL[1] = pred_L[1] = dst_u[-p->linesize[1] / 2];
260
3.55M
            pred_TL[2] = pred_L[2] = dst_v[-p->linesize[2] / 2];
261
262
38.3M
            for (x = 0; x < avctx->width; x++) {
263
34.8M
                pred_T[0] = dst_y[-p->linesize[0] / 2 + x];
264
34.8M
                pred_T[1] = dst_u[-p->linesize[1] / 2 + x];
265
34.8M
                pred_T[2] = dst_v[-p->linesize[2] / 2 + x];
266
267
34.8M
                y = get_vlc2(gb, s->vlc[0].table, SHEER_VLC_BITS, 2);
268
34.8M
                u = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
269
34.8M
                v = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
270
271
34.8M
                dst_y[x] = pred_L[0] = (y + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0x3ff;
272
34.8M
                dst_u[x] = pred_L[1] = (u + ((3 * (pred_T[1] + pred_L[1]) - 2 * pred_TL[1]) >> 2)) & 0x3ff;
273
34.8M
                dst_v[x] = pred_L[2] = (v + ((3 * (pred_T[2] + pred_L[2]) - 2 * pred_TL[2]) >> 2)) & 0x3ff;
274
275
34.8M
                pred_TL[0] = pred_T[0];
276
34.8M
                pred_TL[1] = pred_T[1];
277
34.8M
                pred_TL[2] = pred_T[2];
278
34.8M
            }
279
3.55M
        }
280
281
3.57M
        dst_y += p->linesize[0] / 2;
282
3.57M
        dst_u += p->linesize[1] / 2;
283
3.57M
        dst_v += p->linesize[2] / 2;
284
3.57M
    }
285
2.79k
}
286
287
static void decode_yry10i(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
288
2.64k
{
289
2.64k
    SheerVideoContext *s = avctx->priv_data;
290
2.64k
    uint16_t *dst_y, *dst_u, *dst_v;
291
2.64k
    int x, y;
292
293
2.64k
    dst_y = (uint16_t *)p->data[0];
294
2.64k
    dst_u = (uint16_t *)p->data[1];
295
2.64k
    dst_v = (uint16_t *)p->data[2];
296
297
3.39M
    for (y = 0; y < avctx->height; y++) {
298
3.39M
        if (get_bits1(gb)) {
299
3.01M
            for (x = 0; x < avctx->width; x += 2) {
300
2.99M
                dst_y[x    ] = get_bits(gb, 10);
301
2.99M
                dst_u[x / 2] = get_bits(gb, 10);
302
2.99M
                dst_y[x + 1] = get_bits(gb, 10);
303
2.99M
                dst_v[x / 2] = get_bits(gb, 10);
304
2.99M
            }
305
3.37M
        } else {
306
3.37M
            int pred[4] = { 502, 512, 512, 0 };
307
308
14.5M
            for (x = 0; x < avctx->width; x += 2) {
309
11.1M
                int y1, y2, u, v;
310
311
11.1M
                y1 = get_vlc2(gb, s->vlc[0].table, SHEER_VLC_BITS, 2);
312
11.1M
                u  = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
313
11.1M
                y2 = get_vlc2(gb, s->vlc[0].table, SHEER_VLC_BITS, 2);
314
11.1M
                v  = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
315
316
11.1M
                dst_y[x    ] = pred[0] = (y1 + pred[0]) & 0x3ff;
317
11.1M
                dst_u[x / 2] = pred[1] = (u  + pred[1]) & 0x3ff;
318
11.1M
                dst_y[x + 1] = pred[0] = (y2 + pred[0]) & 0x3ff;
319
11.1M
                dst_v[x / 2] = pred[2] = (v  + pred[2]) & 0x3ff;
320
11.1M
            }
321
3.37M
        }
322
323
3.39M
        dst_y += p->linesize[0] / 2;
324
3.39M
        dst_u += p->linesize[1] / 2;
325
3.39M
        dst_v += p->linesize[2] / 2;
326
3.39M
    }
327
2.64k
}
328
329
static void decode_yry10(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
330
3.96k
{
331
3.96k
    SheerVideoContext *s = avctx->priv_data;
332
3.96k
    uint16_t *dst_y, *dst_u, *dst_v;
333
3.96k
    int x, y;
334
335
3.96k
    dst_y = (uint16_t *)p->data[0];
336
3.96k
    dst_u = (uint16_t *)p->data[1];
337
3.96k
    dst_v = (uint16_t *)p->data[2];
338
339
3.96k
    if (get_bits1(gb)) {
340
1.21M
        for (x = 0; x < avctx->width; x += 2) {
341
1.21M
            dst_y[x    ] = get_bits(gb, 10);
342
1.21M
            dst_u[x / 2] = get_bits(gb, 10);
343
1.21M
            dst_y[x + 1] = get_bits(gb, 10);
344
1.21M
            dst_v[x / 2] = get_bits(gb, 10);
345
1.21M
        }
346
2.73k
    } else {
347
2.73k
        int pred[4] = { 502, 512, 512, 0 };
348
349
6.72M
        for (x = 0; x < avctx->width; x += 2) {
350
6.72M
            int y1, y2, u, v;
351
352
6.72M
            y1 = get_vlc2(gb, s->vlc[0].table, SHEER_VLC_BITS, 2);
353
6.72M
            u  = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
354
6.72M
            y2 = get_vlc2(gb, s->vlc[0].table, SHEER_VLC_BITS, 2);
355
6.72M
            v  = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
356
357
6.72M
            dst_y[x    ] = pred[0] = (y1 + pred[0]) & 0x3ff;
358
6.72M
            dst_u[x / 2] = pred[1] = (u  + pred[1]) & 0x3ff;
359
6.72M
            dst_y[x + 1] = pred[0] = (y2 + pred[0]) & 0x3ff;
360
6.72M
            dst_v[x / 2] = pred[2] = (v  + pred[2]) & 0x3ff;
361
6.72M
        }
362
2.73k
    }
363
364
3.96k
    dst_y += p->linesize[0] / 2;
365
3.96k
    dst_u += p->linesize[1] / 2;
366
3.96k
    dst_v += p->linesize[2] / 2;
367
368
5.71M
    for (y = 1; y < avctx->height; y++) {
369
5.71M
        if (get_bits1(gb)) {
370
136k
            for (x = 0; x < avctx->width; x += 2) {
371
118k
                dst_y[x    ] = get_bits(gb, 10);
372
118k
                dst_u[x / 2] = get_bits(gb, 10);
373
118k
                dst_y[x + 1] = get_bits(gb, 10);
374
118k
                dst_v[x / 2] = get_bits(gb, 10);
375
118k
            }
376
5.69M
        } else {
377
5.69M
            int pred_TL[6], pred_L[6], pred_T[6];
378
5.69M
            int y1, y2, u, v;
379
380
5.69M
            pred_TL[0] = pred_L[0] = dst_y[-p->linesize[0] / 2];
381
5.69M
            pred_TL[1] = pred_L[1] = dst_u[-p->linesize[1] / 2];
382
5.69M
            pred_TL[2] = pred_L[2] = dst_v[-p->linesize[2] / 2];
383
384
25.3M
            for (x = 0; x < avctx->width; x += 2) {
385
19.6M
                pred_T[0] = dst_y[-p->linesize[0] / 2 + x];
386
19.6M
                pred_T[3] = dst_y[-p->linesize[0] / 2 + x + 1];
387
19.6M
                pred_T[1] = dst_u[-p->linesize[1] / 2 + x / 2];
388
19.6M
                pred_T[2] = dst_v[-p->linesize[2] / 2 + x / 2];
389
390
19.6M
                y1 = get_vlc2(gb, s->vlc[0].table, SHEER_VLC_BITS, 2);
391
19.6M
                u  = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
392
19.6M
                y2 = get_vlc2(gb, s->vlc[0].table, SHEER_VLC_BITS, 2);
393
19.6M
                v  = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
394
395
19.6M
                dst_y[x    ] = pred_L[0] = (y1 + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0x3ff;
396
19.6M
                dst_u[x / 2] = pred_L[1] = (u + (((pred_L[1] - pred_TL[1]) >> 1) + pred_T[1])) & 0x3ff;
397
19.6M
                dst_y[x + 1] = pred_L[0] = (y2 + ((3 * (pred_T[3] + pred_L[0]) - 2 * pred_T[0]) >> 2)) & 0x3ff;
398
19.6M
                dst_v[x / 2] = pred_L[2] = (v + (((pred_L[2] - pred_TL[2]) >> 1) + pred_T[2])) & 0x3ff;
399
400
19.6M
                pred_TL[0] = pred_T[3];
401
19.6M
                pred_TL[1] = pred_T[1];
402
19.6M
                pred_TL[2] = pred_T[2];
403
19.6M
            }
404
5.69M
        }
405
406
5.71M
        dst_y += p->linesize[0] / 2;
407
5.71M
        dst_u += p->linesize[1] / 2;
408
5.71M
        dst_v += p->linesize[2] / 2;
409
5.71M
    }
410
3.96k
}
411
412
static void decode_ca2i(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
413
2.53k
{
414
2.53k
    SheerVideoContext *s = avctx->priv_data;
415
2.53k
    uint16_t *dst_y, *dst_u, *dst_v, *dst_a;
416
2.53k
    int x, y;
417
418
2.53k
    dst_y = (uint16_t *)p->data[0];
419
2.53k
    dst_u = (uint16_t *)p->data[1];
420
2.53k
    dst_v = (uint16_t *)p->data[2];
421
2.53k
    dst_a = (uint16_t *)p->data[3];
422
423
2.97M
    for (y = 0; y < avctx->height; y++) {
424
2.97M
        if (get_bits1(gb)) {
425
314k
            for (x = 0; x < avctx->width; x += 2) {
426
301k
                dst_a[x    ] = get_bits(gb, 10);
427
301k
                dst_y[x    ] = get_bits(gb, 10);
428
301k
                dst_u[x / 2] = get_bits(gb, 10);
429
301k
                dst_a[x + 1] = get_bits(gb, 10);
430
301k
                dst_y[x + 1] = get_bits(gb, 10);
431
301k
                dst_v[x / 2] = get_bits(gb, 10);
432
301k
            }
433
2.95M
        } else {
434
2.95M
            int pred[4] = { 502, 512, 512, 502 };
435
436
31.8M
            for (x = 0; x < avctx->width; x += 2) {
437
28.8M
                int y1, y2, u, v, a1, a2;
438
439
28.8M
                a1 = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
440
28.8M
                y1 = get_vlc2(gb, s->vlc[0].table, SHEER_VLC_BITS, 2);
441
28.8M
                u  = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
442
28.8M
                a2 = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
443
28.8M
                y2 = get_vlc2(gb, s->vlc[0].table, SHEER_VLC_BITS, 2);
444
28.8M
                v  = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
445
446
28.8M
                dst_y[x    ] = pred[0] = (y1 + pred[0]) & 0x3ff;
447
28.8M
                dst_u[x / 2] = pred[1] = (u  + pred[1]) & 0x3ff;
448
28.8M
                dst_y[x + 1] = pred[0] = (y2 + pred[0]) & 0x3ff;
449
28.8M
                dst_a[x    ] = pred[3] = (a1 + pred[3]) & 0x3ff;
450
28.8M
                dst_v[x / 2] = pred[2] = (v  + pred[2]) & 0x3ff;
451
28.8M
                dst_a[x + 1] = pred[3] = (a2 + pred[3]) & 0x3ff;
452
28.8M
            }
453
2.95M
        }
454
455
2.97M
        dst_y += p->linesize[0] / 2;
456
2.97M
        dst_u += p->linesize[1] / 2;
457
2.97M
        dst_v += p->linesize[2] / 2;
458
2.97M
        dst_a += p->linesize[3] / 2;
459
2.97M
    }
460
2.53k
}
461
462
static void decode_ca2p(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
463
6.25k
{
464
6.25k
    SheerVideoContext *s = avctx->priv_data;
465
6.25k
    uint16_t *dst_y, *dst_u, *dst_v, *dst_a;
466
6.25k
    int x, y;
467
468
6.25k
    dst_y = (uint16_t *)p->data[0];
469
6.25k
    dst_u = (uint16_t *)p->data[1];
470
6.25k
    dst_v = (uint16_t *)p->data[2];
471
6.25k
    dst_a = (uint16_t *)p->data[3];
472
473
6.25k
    if (get_bits1(gb)) {
474
227k
        for (x = 0; x < avctx->width; x += 2) {
475
225k
            dst_a[x    ] = get_bits(gb, 10);
476
225k
            dst_y[x    ] = get_bits(gb, 10);
477
225k
            dst_u[x / 2] = get_bits(gb, 10);
478
225k
            dst_a[x + 1] = get_bits(gb, 10);
479
225k
            dst_y[x + 1] = get_bits(gb, 10);
480
225k
            dst_v[x / 2] = get_bits(gb, 10);
481
225k
        }
482
4.93k
    } else {
483
4.93k
        int pred[4] = { 502, 512, 512, 502 };
484
485
2.81M
        for (x = 0; x < avctx->width; x += 2) {
486
2.80M
            int y1, y2, u, v, a1, a2;
487
488
2.80M
            a1 = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
489
2.80M
            y1 = get_vlc2(gb, s->vlc[0].table, SHEER_VLC_BITS, 2);
490
2.80M
            u  = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
491
2.80M
            a2 = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
492
2.80M
            y2 = get_vlc2(gb, s->vlc[0].table, SHEER_VLC_BITS, 2);
493
2.80M
            v  = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
494
495
2.80M
            dst_y[x    ] = pred[0] = (y1 + pred[0]) & 0x3ff;
496
2.80M
            dst_u[x / 2] = pred[1] = (u  + pred[1]) & 0x3ff;
497
2.80M
            dst_y[x + 1] = pred[0] = (y2 + pred[0]) & 0x3ff;
498
2.80M
            dst_a[x    ] = pred[3] = (a1 + pred[3]) & 0x3ff;
499
2.80M
            dst_v[x / 2] = pred[2] = (v  + pred[2]) & 0x3ff;
500
2.80M
            dst_a[x + 1] = pred[3] = (a2 + pred[3]) & 0x3ff;
501
2.80M
        }
502
4.93k
    }
503
504
6.25k
    dst_y += p->linesize[0] / 2;
505
6.25k
    dst_u += p->linesize[1] / 2;
506
6.25k
    dst_v += p->linesize[2] / 2;
507
6.25k
    dst_a += p->linesize[3] / 2;
508
509
6.46M
    for (y = 1; y < avctx->height; y++) {
510
6.45M
        if (get_bits1(gb)) {
511
311k
            for (x = 0; x < avctx->width; x += 2) {
512
292k
                dst_a[x    ] = get_bits(gb, 10);
513
292k
                dst_y[x    ] = get_bits(gb, 10);
514
292k
                dst_u[x / 2] = get_bits(gb, 10);
515
292k
                dst_a[x + 1] = get_bits(gb, 10);
516
292k
                dst_y[x + 1] = get_bits(gb, 10);
517
292k
                dst_v[x / 2] = get_bits(gb, 10);
518
292k
            }
519
6.44M
        } else {
520
6.44M
            int pred_TL[6], pred_L[6], pred_T[6];
521
6.44M
            int y1, y2, u, v, a1, a2;
522
523
6.44M
            pred_TL[0] = pred_L[0] = dst_y[-p->linesize[0] / 2];
524
6.44M
            pred_TL[1] = pred_L[1] = dst_u[-p->linesize[1] / 2];
525
6.44M
            pred_TL[2] = pred_L[2] = dst_v[-p->linesize[2] / 2];
526
6.44M
            pred_TL[4] = pred_L[4] = dst_a[-p->linesize[3] / 2];
527
528
28.9M
            for (x = 0; x < avctx->width; x += 2) {
529
22.5M
                pred_T[0] = dst_y[-p->linesize[0] / 2 + x];
530
22.5M
                pred_T[3] = dst_y[-p->linesize[0] / 2 + x + 1];
531
22.5M
                pred_T[1] = dst_u[-p->linesize[1] / 2 + x / 2];
532
22.5M
                pred_T[2] = dst_v[-p->linesize[2] / 2 + x / 2];
533
22.5M
                pred_T[4] = dst_a[-p->linesize[3] / 2 + x];
534
22.5M
                pred_T[5] = dst_a[-p->linesize[3] / 2 + x + 1];
535
536
22.5M
                a1 = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
537
22.5M
                y1 = get_vlc2(gb, s->vlc[0].table, SHEER_VLC_BITS, 2);
538
22.5M
                u  = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
539
22.5M
                a2 = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
540
22.5M
                y2 = get_vlc2(gb, s->vlc[0].table, SHEER_VLC_BITS, 2);
541
22.5M
                v  = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
542
543
22.5M
                dst_y[x    ] = pred_L[0] = (y1 + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0x3ff;
544
22.5M
                dst_u[x / 2] = pred_L[1] = (u + (((pred_L[1] - pred_TL[1]) >> 1) + pred_T[1])) & 0x3ff;
545
22.5M
                dst_y[x + 1] = pred_L[0] = (y2 + ((3 * (pred_T[3] + pred_L[0]) - 2 * pred_T[0]) >> 2)) & 0x3ff;
546
22.5M
                dst_v[x / 2] = pred_L[2] = (v + (((pred_L[2] - pred_TL[2]) >> 1) + pred_T[2])) & 0x3ff;
547
22.5M
                dst_a[x    ] = pred_L[4] = (a1 + ((3 * (pred_T[4] + pred_L[4]) - 2 * pred_TL[4]) >> 2)) & 0x3ff;
548
22.5M
                dst_a[x + 1] = pred_L[4] = (a2 + ((3 * (pred_T[5] + pred_L[4]) - 2 * pred_T[4]) >> 2)) & 0x3ff;
549
550
22.5M
                pred_TL[0] = pred_T[3];
551
22.5M
                pred_TL[1] = pred_T[1];
552
22.5M
                pred_TL[2] = pred_T[2];
553
22.5M
                pred_TL[4] = pred_T[5];
554
22.5M
            }
555
6.44M
        }
556
557
6.45M
        dst_y += p->linesize[0] / 2;
558
6.45M
        dst_u += p->linesize[1] / 2;
559
6.45M
        dst_v += p->linesize[2] / 2;
560
6.45M
        dst_a += p->linesize[3] / 2;
561
6.45M
    }
562
6.25k
}
563
564
static void decode_c82i(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
565
2.91k
{
566
2.91k
    SheerVideoContext *s = avctx->priv_data;
567
2.91k
    uint8_t *dst_y, *dst_u, *dst_v, *dst_a;
568
2.91k
    int x, y;
569
570
2.91k
    dst_y = p->data[0];
571
2.91k
    dst_u = p->data[1];
572
2.91k
    dst_v = p->data[2];
573
2.91k
    dst_a = p->data[3];
574
575
7.95M
    for (y = 0; y < avctx->height; y += 1) {
576
7.94M
        if (get_bits1(gb)) {
577
117k
            for (x = 0; x < avctx->width; x += 2) {
578
86.0k
                dst_a[x    ] = get_bits(gb, 8);
579
86.0k
                dst_y[x    ] = get_bits(gb, 8);
580
86.0k
                dst_u[x / 2] = get_bits(gb, 8);
581
86.0k
                dst_a[x + 1] = get_bits(gb, 8);
582
86.0k
                dst_y[x + 1] = get_bits(gb, 8);
583
86.0k
                dst_v[x / 2] = get_bits(gb, 8);
584
86.0k
            }
585
7.91M
        } else {
586
7.91M
            int pred[4] = { 125, -128, -128, 125 };
587
588
22.2M
            for (x = 0; x < avctx->width; x += 2) {
589
14.2M
                int y1, y2, u, v, a1, a2;
590
591
14.2M
                a1 = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
592
14.2M
                y1 = get_vlc2(gb, s->vlc[0].table, SHEER_VLC_BITS, 2);
593
14.2M
                u  = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
594
14.2M
                a2 = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
595
14.2M
                y2 = get_vlc2(gb, s->vlc[0].table, SHEER_VLC_BITS, 2);
596
14.2M
                v  = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
597
598
14.2M
                dst_y[x    ] = pred[0] = (y1 + pred[0]) & 0xff;
599
14.2M
                dst_y[x + 1] = pred[0] = (y2 + pred[0]) & 0xff;
600
14.2M
                dst_u[x / 2] = pred[1] = (u  + pred[1]) & 0xff;
601
14.2M
                dst_v[x / 2] = pred[2] = (v  + pred[2]) & 0xff;
602
14.2M
                dst_a[x    ] = pred[3] = (a1 + pred[3]) & 0xff;
603
14.2M
                dst_a[x + 1] = pred[3] = (a2 + pred[3]) & 0xff;
604
14.2M
            }
605
7.91M
        }
606
607
7.94M
        dst_y += p->linesize[0];
608
7.94M
        dst_u += p->linesize[1];
609
7.94M
        dst_v += p->linesize[2];
610
7.94M
        dst_a += p->linesize[3];
611
7.94M
    }
612
2.91k
}
613
614
static void decode_c82p(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
615
4.60k
{
616
4.60k
    SheerVideoContext *s = avctx->priv_data;
617
4.60k
    uint8_t *dst_y, *dst_u, *dst_v, *dst_a;
618
4.60k
    int x, y;
619
620
4.60k
    dst_y = p->data[0];
621
4.60k
    dst_u = p->data[1];
622
4.60k
    dst_v = p->data[2];
623
4.60k
    dst_a = p->data[3];
624
625
4.60k
    if (get_bits1(gb)) {
626
10.4k
        for (x = 0; x < avctx->width; x += 2) {
627
9.84k
            dst_a[x    ] = get_bits(gb, 8);
628
9.84k
            dst_y[x    ] = get_bits(gb, 8);
629
9.84k
            dst_u[x / 2] = get_bits(gb, 8);
630
9.84k
            dst_a[x + 1] = get_bits(gb, 8);
631
9.84k
            dst_y[x + 1] = get_bits(gb, 8);
632
9.84k
            dst_v[x / 2] = get_bits(gb, 8);
633
9.84k
        }
634
4.00k
    } else {
635
4.00k
        int pred[4] = { 125, -128, -128, 125 };
636
637
3.83M
        for (x = 0; x < avctx->width; x += 2) {
638
3.83M
            int y1, y2, u, v, a1, a2;
639
640
3.83M
            a1 = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
641
3.83M
            y1 = get_vlc2(gb, s->vlc[0].table, SHEER_VLC_BITS, 2);
642
3.83M
            u  = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
643
3.83M
            a2 = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
644
3.83M
            y2 = get_vlc2(gb, s->vlc[0].table, SHEER_VLC_BITS, 2);
645
3.83M
            v  = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
646
647
3.83M
            dst_y[x    ] = pred[0] = (y1 + pred[0]) & 0xff;
648
3.83M
            dst_u[x / 2] = pred[1] = (u  + pred[1]) & 0xff;
649
3.83M
            dst_y[x + 1] = pred[0] = (y2 + pred[0]) & 0xff;
650
3.83M
            dst_a[x    ] = pred[3] = (a1 + pred[3]) & 0xff;
651
3.83M
            dst_v[x / 2] = pred[2] = (v  + pred[2]) & 0xff;
652
3.83M
            dst_a[x + 1] = pred[3] = (a2 + pred[3]) & 0xff;
653
3.83M
        }
654
4.00k
    }
655
656
4.60k
    dst_y += p->linesize[0];
657
4.60k
    dst_u += p->linesize[1];
658
4.60k
    dst_v += p->linesize[2];
659
4.60k
    dst_a += p->linesize[3];
660
661
7.75M
    for (y = 1; y < avctx->height; y++) {
662
7.74M
        if (get_bits1(gb)) {
663
313k
            for (x = 0; x < avctx->width; x += 2) {
664
266k
                dst_a[x    ] = get_bits(gb, 8);
665
266k
                dst_y[x    ] = get_bits(gb, 8);
666
266k
                dst_u[x / 2] = get_bits(gb, 8);
667
266k
                dst_a[x + 1] = get_bits(gb, 8);
668
266k
                dst_y[x + 1] = get_bits(gb, 8);
669
266k
                dst_v[x / 2] = get_bits(gb, 8);
670
266k
            }
671
7.69M
        } else {
672
7.69M
            int pred_TL[6], pred_L[6], pred_T[6];
673
7.69M
            int y1, y2, u, v, a1, a2;
674
675
7.69M
            pred_TL[0] = pred_L[0] = dst_y[-p->linesize[0]];
676
7.69M
            pred_TL[1] = pred_L[1] = dst_u[-p->linesize[1]];
677
7.69M
            pred_TL[2] = pred_L[2] = dst_v[-p->linesize[2]];
678
7.69M
            pred_TL[4] = pred_L[4] = dst_a[-p->linesize[3]];
679
680
39.5M
            for (x = 0; x < avctx->width; x += 2) {
681
31.8M
                pred_T[0] = dst_y[-p->linesize[0] + x];
682
31.8M
                pred_T[3] = dst_y[-p->linesize[0] + x + 1];
683
31.8M
                pred_T[1] = dst_u[-p->linesize[1] + x / 2];
684
31.8M
                pred_T[2] = dst_v[-p->linesize[2] + x / 2];
685
31.8M
                pred_T[4] = dst_a[-p->linesize[3] + x];
686
31.8M
                pred_T[5] = dst_a[-p->linesize[3] + x + 1];
687
688
31.8M
                a1 = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
689
31.8M
                y1 = get_vlc2(gb, s->vlc[0].table, SHEER_VLC_BITS, 2);
690
31.8M
                u  = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
691
31.8M
                a2 = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
692
31.8M
                y2 = get_vlc2(gb, s->vlc[0].table, SHEER_VLC_BITS, 2);
693
31.8M
                v  = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
694
695
31.8M
                dst_y[x    ] = pred_L[0] = (y1 + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0xff;
696
31.8M
                dst_u[x / 2] = pred_L[1] = (u + (((pred_L[1] - pred_TL[1]) >> 1) + pred_T[1])) & 0xff;
697
31.8M
                dst_y[x + 1] = pred_L[0] = (y2 + ((3 * (pred_T[3] + pred_L[0]) - 2 * pred_T[0]) >> 2)) & 0xff;
698
31.8M
                dst_v[x / 2] = pred_L[2] = (v + (((pred_L[2] - pred_TL[2]) >> 1) + pred_T[2])) & 0xff;
699
31.8M
                dst_a[x    ] = pred_L[4] = (a1 + ((3 * (pred_T[4] + pred_L[4]) - 2 * pred_TL[4]) >> 2)) & 0xff;
700
31.8M
                dst_a[x + 1] = pred_L[4] = (a2 + ((3 * (pred_T[5] + pred_L[4]) - 2 * pred_T[4]) >> 2)) & 0xff;
701
702
31.8M
                pred_TL[0] = pred_T[3];
703
31.8M
                pred_TL[1] = pred_T[1];
704
31.8M
                pred_TL[2] = pred_T[2];
705
31.8M
                pred_TL[4] = pred_T[5];
706
31.8M
            }
707
7.69M
        }
708
709
7.74M
        dst_y += p->linesize[0];
710
7.74M
        dst_u += p->linesize[1];
711
7.74M
        dst_v += p->linesize[2];
712
7.74M
        dst_a += p->linesize[3];
713
7.74M
    }
714
4.60k
}
715
716
static void decode_ybyr(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
717
4.29k
{
718
4.29k
    SheerVideoContext *s = avctx->priv_data;
719
4.29k
    uint8_t *dst_y, *dst_u, *dst_v;
720
4.29k
    int x, y;
721
722
4.29k
    dst_y = p->data[0];
723
4.29k
    dst_u = p->data[1];
724
4.29k
    dst_v = p->data[2];
725
726
4.29k
    if (get_bits1(gb)) {
727
21.8k
        for (x = 0; x < avctx->width; x += 2) {
728
20.2k
            dst_y[x    ] = get_bits(gb, 8);
729
20.2k
            dst_u[x / 2] = get_bits(gb, 8) + 128;
730
20.2k
            dst_y[x + 1] = get_bits(gb, 8);
731
20.2k
            dst_v[x / 2] = get_bits(gb, 8) + 128;
732
20.2k
        }
733
2.69k
    } else {
734
2.69k
        int pred[4] = { -128, 128, 128, 0 };
735
736
3.23M
        for (x = 0; x < avctx->width; x += 2) {
737
3.23M
            int y1, y2, u, v;
738
739
3.23M
            y1 = get_vlc2(gb, s->vlc[0].table, SHEER_VLC_BITS, 2);
740
3.23M
            u  = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
741
3.23M
            y2 = get_vlc2(gb, s->vlc[0].table, SHEER_VLC_BITS, 2);
742
3.23M
            v  = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
743
744
3.23M
            dst_y[x    ] = pred[0] = (y1 + pred[0]) & 0xff;
745
3.23M
            dst_u[x / 2] = pred[1] = (u  + pred[1]) & 0xff;
746
3.23M
            dst_y[x + 1] = pred[0] = (y2 + pred[0]) & 0xff;
747
3.23M
            dst_v[x / 2] = pred[2] = (v  + pred[2]) & 0xff;
748
3.23M
        }
749
2.69k
    }
750
751
4.29k
    dst_y += p->linesize[0];
752
4.29k
    dst_u += p->linesize[1];
753
4.29k
    dst_v += p->linesize[2];
754
755
4.29M
    for (y = 1; y < avctx->height; y++) {
756
4.28M
        if (get_bits1(gb)) {
757
559k
            for (x = 0; x < avctx->width; x += 2) {
758
520k
                dst_y[x    ] = get_bits(gb, 8);
759
520k
                dst_u[x / 2] = get_bits(gb, 8) + 128;
760
520k
                dst_y[x + 1] = get_bits(gb, 8);
761
520k
                dst_v[x / 2] = get_bits(gb, 8) + 128;
762
520k
            }
763
4.24M
        } else {
764
4.24M
            int pred_TL[4], pred_L[4], pred_T[4];
765
4.24M
            int y1, y2, u, v;
766
767
4.24M
            pred_TL[0] = pred_L[0] = dst_y[-p->linesize[0]];
768
4.24M
            pred_TL[1] = pred_L[1] = dst_u[-p->linesize[1]];
769
4.24M
            pred_TL[2] = pred_L[2] = dst_v[-p->linesize[2]];
770
771
26.9M
            for (x = 0; x < avctx->width; x += 2) {
772
22.6M
                pred_T[0] = dst_y[-p->linesize[0] + x];
773
22.6M
                pred_T[3] = dst_y[-p->linesize[0] + x + 1];
774
22.6M
                pred_T[1] = dst_u[-p->linesize[1] + x / 2];
775
22.6M
                pred_T[2] = dst_v[-p->linesize[2] + x / 2];
776
777
22.6M
                y1 = get_vlc2(gb, s->vlc[0].table, SHEER_VLC_BITS, 2);
778
22.6M
                u  = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
779
22.6M
                y2 = get_vlc2(gb, s->vlc[0].table, SHEER_VLC_BITS, 2);
780
22.6M
                v  = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
781
782
22.6M
                dst_y[x    ] = pred_L[0] = (y1 + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0xff;
783
22.6M
                dst_u[x / 2] = pred_L[1] = (u + (((pred_L[1] - pred_TL[1]) >> 1) + pred_T[1])) & 0xff;
784
22.6M
                dst_y[x + 1] = pred_L[0] = (y2 + ((3 * (pred_T[3] + pred_L[0]) - 2 * pred_T[0]) >> 2)) & 0xff;
785
22.6M
                dst_v[x / 2] = pred_L[2] = (v + (((pred_L[2] - pred_TL[2]) >> 1) + pred_T[2])) & 0xff;
786
787
22.6M
                pred_TL[0] = pred_T[3];
788
22.6M
                pred_TL[1] = pred_T[1];
789
22.6M
                pred_TL[2] = pred_T[2];
790
22.6M
            }
791
4.24M
        }
792
793
4.28M
        dst_y += p->linesize[0];
794
4.28M
        dst_u += p->linesize[1];
795
4.28M
        dst_v += p->linesize[2];
796
4.28M
    }
797
4.29k
}
798
799
static void decode_byryi(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
800
3.82k
{
801
3.82k
    SheerVideoContext *s = avctx->priv_data;
802
3.82k
    uint8_t *dst_y, *dst_u, *dst_v;
803
3.82k
    int x, y;
804
805
3.82k
    dst_y = p->data[0];
806
3.82k
    dst_u = p->data[1];
807
3.82k
    dst_v = p->data[2];
808
809
3.82k
    if (get_bits1(gb)) {
810
1.32M
        for (x = 0; x < avctx->width; x += 2) {
811
1.32M
            dst_y[x    ] = get_bits(gb, 8);
812
1.32M
            dst_u[x / 2] = get_bits(gb, 8);
813
1.32M
            dst_y[x + 1] = get_bits(gb, 8);
814
1.32M
            dst_v[x / 2] = get_bits(gb, 8);
815
1.32M
        }
816
3.46k
    } else {
817
3.46k
        int pred[4] = { 125, -128, -128, 0 };
818
819
2.05M
        for (x = 0; x < avctx->width; x += 2) {
820
2.05M
            int y1, y2, u, v;
821
822
2.05M
            y1 = get_vlc2(gb, s->vlc[0].table, SHEER_VLC_BITS, 2);
823
2.05M
            u  = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
824
2.05M
            y2 = get_vlc2(gb, s->vlc[0].table, SHEER_VLC_BITS, 2);
825
2.05M
            v  = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
826
827
2.05M
            dst_y[x    ] = pred[0] = (y1 + pred[0]) & 0xff;
828
2.05M
            dst_u[x / 2] = pred[1] = (u  + pred[1]) & 0xff;
829
2.05M
            dst_y[x + 1] = pred[0] = (y2 + pred[0]) & 0xff;
830
2.05M
            dst_v[x / 2] = pred[2] = (v  + pred[2]) & 0xff;
831
2.05M
        }
832
3.46k
    }
833
834
3.82k
    dst_y += p->linesize[0];
835
3.82k
    dst_u += p->linesize[1];
836
3.82k
    dst_v += p->linesize[2];
837
838
5.34M
    for (y = 1; y < avctx->height; y++) {
839
5.33M
        if (get_bits1(gb)) {
840
432k
            for (x = 0; x < avctx->width; x += 2) {
841
398k
                dst_y[x    ] = get_bits(gb, 8);
842
398k
                dst_u[x / 2] = get_bits(gb, 8);
843
398k
                dst_y[x + 1] = get_bits(gb, 8);
844
398k
                dst_v[x / 2] = get_bits(gb, 8);
845
398k
            }
846
5.30M
        } else {
847
5.30M
            int pred_L[4];
848
5.30M
            int y1, y2, u, v;
849
850
5.30M
            pred_L[0] = dst_y[-p->linesize[0]];
851
5.30M
            pred_L[1] = dst_u[-p->linesize[1]];
852
5.30M
            pred_L[2] = dst_v[-p->linesize[2]];
853
854
24.4M
            for (x = 0; x < avctx->width; x += 2) {
855
19.1M
                y1 = get_vlc2(gb, s->vlc[0].table, SHEER_VLC_BITS, 2);
856
19.1M
                u  = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
857
19.1M
                y2 = get_vlc2(gb, s->vlc[0].table, SHEER_VLC_BITS, 2);
858
19.1M
                v  = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
859
860
19.1M
                dst_y[x    ] = pred_L[0] = (y1 + pred_L[0]) & 0xff;
861
19.1M
                dst_u[x / 2] = pred_L[1] = (u  + pred_L[1]) & 0xff;
862
19.1M
                dst_y[x + 1] = pred_L[0] = (y2 + pred_L[0]) & 0xff;
863
19.1M
                dst_v[x / 2] = pred_L[2] = (v +  pred_L[2]) & 0xff;
864
19.1M
            }
865
5.30M
        }
866
867
5.33M
        dst_y += p->linesize[0];
868
5.33M
        dst_u += p->linesize[1];
869
5.33M
        dst_v += p->linesize[2];
870
5.33M
    }
871
3.82k
}
872
873
static void decode_byry(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
874
3.96k
{
875
3.96k
    SheerVideoContext *s = avctx->priv_data;
876
3.96k
    uint8_t *dst_y, *dst_u, *dst_v;
877
3.96k
    int x, y;
878
879
3.96k
    dst_y = p->data[0];
880
3.96k
    dst_u = p->data[1];
881
3.96k
    dst_v = p->data[2];
882
883
3.96k
    if (get_bits1(gb)) {
884
8.11k
        for (x = 0; x < avctx->width; x += 2) {
885
7.42k
            dst_y[x    ] = get_bits(gb, 8);
886
7.42k
            dst_u[x / 2] = get_bits(gb, 8);
887
7.42k
            dst_y[x + 1] = get_bits(gb, 8);
888
7.42k
            dst_v[x / 2] = get_bits(gb, 8);
889
7.42k
        }
890
3.28k
    } else {
891
3.28k
        int pred[4] = { 125, -128, -128, 0 };
892
893
5.20M
        for (x = 0; x < avctx->width; x += 2) {
894
5.19M
            int y1, y2, u, v;
895
896
5.19M
            y1 = get_vlc2(gb, s->vlc[0].table, SHEER_VLC_BITS, 2);
897
5.19M
            u  = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
898
5.19M
            y2 = get_vlc2(gb, s->vlc[0].table, SHEER_VLC_BITS, 2);
899
5.19M
            v  = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
900
901
5.19M
            dst_y[x    ] = pred[0] = (y1 + pred[0]) & 0xff;
902
5.19M
            dst_u[x / 2] = pred[1] = (u  + pred[1]) & 0xff;
903
5.19M
            dst_y[x + 1] = pred[0] = (y2 + pred[0]) & 0xff;
904
5.19M
            dst_v[x / 2] = pred[2] = (v  + pred[2]) & 0xff;
905
5.19M
        }
906
3.28k
    }
907
908
3.96k
    dst_y += p->linesize[0];
909
3.96k
    dst_u += p->linesize[1];
910
3.96k
    dst_v += p->linesize[2];
911
912
4.17M
    for (y = 1; y < avctx->height; y++) {
913
4.17M
        if (get_bits1(gb)) {
914
611k
            for (x = 0; x < avctx->width; x += 2) {
915
580k
                dst_y[x    ] = get_bits(gb, 8);
916
580k
                dst_u[x / 2] = get_bits(gb, 8);
917
580k
                dst_y[x + 1] = get_bits(gb, 8);
918
580k
                dst_v[x / 2] = get_bits(gb, 8);
919
580k
            }
920
4.14M
        } else {
921
4.14M
            int pred_TL[4], pred_L[4], pred_T[4];
922
4.14M
            int y1, y2, u, v;
923
924
4.14M
            pred_TL[0] = pred_L[0] = dst_y[-p->linesize[0]];
925
4.14M
            pred_TL[1] = pred_L[1] = dst_u[-p->linesize[1]];
926
4.14M
            pred_TL[2] = pred_L[2] = dst_v[-p->linesize[2]];
927
928
32.5M
            for (x = 0; x < avctx->width; x += 2) {
929
28.4M
                pred_T[0] = dst_y[-p->linesize[0] + x];
930
28.4M
                pred_T[3] = dst_y[-p->linesize[0] + x + 1];
931
28.4M
                pred_T[1] = dst_u[-p->linesize[1] + x / 2];
932
28.4M
                pred_T[2] = dst_v[-p->linesize[2] + x / 2];
933
934
28.4M
                y1 = get_vlc2(gb, s->vlc[0].table, SHEER_VLC_BITS, 2);
935
28.4M
                u  = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
936
28.4M
                y2 = get_vlc2(gb, s->vlc[0].table, SHEER_VLC_BITS, 2);
937
28.4M
                v  = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
938
939
28.4M
                dst_y[x    ] = pred_L[0] = (y1 + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0xff;
940
28.4M
                dst_u[x / 2] = pred_L[1] = (u + (((pred_L[1] - pred_TL[1]) >> 1) + pred_T[1])) & 0xff;
941
28.4M
                dst_y[x + 1] = pred_L[0] = (y2 + ((3 * (pred_T[3] + pred_L[0]) - 2 * pred_T[0]) >> 2)) & 0xff;
942
28.4M
                dst_v[x / 2] = pred_L[2] = (v + (((pred_L[2] - pred_TL[2]) >> 1) + pred_T[2])) & 0xff;
943
944
28.4M
                pred_TL[0] = pred_T[3];
945
28.4M
                pred_TL[1] = pred_T[1];
946
28.4M
                pred_TL[2] = pred_T[2];
947
28.4M
            }
948
4.14M
        }
949
950
4.17M
        dst_y += p->linesize[0];
951
4.17M
        dst_u += p->linesize[1];
952
4.17M
        dst_v += p->linesize[2];
953
4.17M
    }
954
3.96k
}
955
956
static void decode_ybri(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
957
2.99k
{
958
2.99k
    SheerVideoContext *s = avctx->priv_data;
959
2.99k
    uint8_t *dst_y, *dst_u, *dst_v;
960
2.99k
    int x, y;
961
962
2.99k
    dst_y = p->data[0];
963
2.99k
    dst_u = p->data[1];
964
2.99k
    dst_v = p->data[2];
965
966
2.99k
    if (get_bits1(gb)) {
967
4.40M
        for (x = 0; x < avctx->width; x++) {
968
4.40M
            dst_y[x] = get_bits(gb, 8);
969
4.40M
            dst_u[x] = get_bits(gb, 8);
970
4.40M
            dst_v[x] = get_bits(gb, 8);
971
4.40M
        }
972
2.33k
    } else {
973
2.33k
        int pred[4] = { s->alt ? 125 : -146, -128, -128, -128 };
974
975
7.28M
        for (x = 0; x < avctx->width; x++) {
976
7.28M
            int y, u, v;
977
978
7.28M
            y = get_vlc2(gb, s->vlc[0].table, SHEER_VLC_BITS, 2);
979
7.28M
            u = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
980
7.28M
            v = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
981
982
7.28M
            dst_y[x] = pred[0] = (y + pred[0]) & 0xff;
983
7.28M
            dst_u[x] = pred[1] = (u + pred[1]) & 0xff;
984
7.28M
            dst_v[x] = pred[2] = (v + pred[2]) & 0xff;
985
7.28M
        }
986
2.33k
    }
987
988
2.99k
    dst_y += p->linesize[0];
989
2.99k
    dst_u += p->linesize[1];
990
2.99k
    dst_v += p->linesize[2];
991
992
1.53M
    for (y = 1; y < avctx->height; y++) {
993
1.53M
        if (get_bits1(gb)) {
994
342k
            for (x = 0; x < avctx->width; x++) {
995
324k
                dst_y[x] = get_bits(gb, 8);
996
324k
                dst_u[x] = get_bits(gb, 8);
997
324k
                dst_v[x] = get_bits(gb, 8);
998
324k
            }
999
1.51M
        } else {
1000
1.51M
            int pred_L[4];
1001
1.51M
            int y, u, v;
1002
1003
1.51M
            pred_L[0] = dst_y[-p->linesize[0]];
1004
1.51M
            pred_L[1] = dst_u[-p->linesize[1]];
1005
1.51M
            pred_L[2] = dst_v[-p->linesize[2]];
1006
1007
25.3M
            for (x = 0; x < avctx->width; x++) {
1008
23.8M
                y = get_vlc2(gb, s->vlc[0].table, SHEER_VLC_BITS, 2);
1009
23.8M
                u = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
1010
23.8M
                v = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
1011
1012
23.8M
                dst_y[x] = pred_L[0] = (y + pred_L[0]) & 0xff;
1013
23.8M
                dst_u[x] = pred_L[1] = (u + pred_L[1]) & 0xff;
1014
23.8M
                dst_v[x] = pred_L[2] = (v + pred_L[2]) & 0xff;
1015
23.8M
            }
1016
1.51M
        }
1017
1018
1.53M
        dst_y += p->linesize[0];
1019
1.53M
        dst_u += p->linesize[1];
1020
1.53M
        dst_v += p->linesize[2];
1021
1.53M
    }
1022
2.99k
}
1023
1024
static void decode_ybr(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
1025
2.62k
{
1026
2.62k
    SheerVideoContext *s = avctx->priv_data;
1027
2.62k
    uint8_t *dst_y, *dst_u, *dst_v;
1028
2.62k
    int x, y;
1029
1030
2.62k
    dst_y = p->data[0];
1031
2.62k
    dst_u = p->data[1];
1032
2.62k
    dst_v = p->data[2];
1033
1034
2.62k
    if (get_bits1(gb)) {
1035
239k
        for (x = 0; x < avctx->width; x++) {
1036
238k
            dst_y[x] = get_bits(gb, 8);
1037
238k
            dst_u[x] = get_bits(gb, 8);
1038
238k
            dst_v[x] = get_bits(gb, 8);
1039
238k
        }
1040
2.15k
    } else {
1041
2.15k
        int pred[4] = { s->alt ? 125 : -146, -128, -128, -128 };
1042
1043
7.23M
        for (x = 0; x < avctx->width; x++) {
1044
7.23M
            int y, u, v;
1045
1046
7.23M
            y = get_vlc2(gb, s->vlc[0].table, SHEER_VLC_BITS, 2);
1047
7.23M
            u = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
1048
7.23M
            v = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
1049
1050
7.23M
            dst_y[x] = pred[0] = (y + pred[0]) & 0xff;
1051
7.23M
            dst_u[x] = pred[1] = (u + pred[1]) & 0xff;
1052
7.23M
            dst_v[x] = pred[2] = (v + pred[2]) & 0xff;
1053
7.23M
        }
1054
2.15k
    }
1055
1056
2.62k
    dst_y += p->linesize[0];
1057
2.62k
    dst_u += p->linesize[1];
1058
2.62k
    dst_v += p->linesize[2];
1059
1060
1.97M
    for (y = 1; y < avctx->height; y++) {
1061
1.97M
        if (get_bits1(gb)) {
1062
545k
            for (x = 0; x < avctx->width; x++) {
1063
509k
                dst_y[x] = get_bits(gb, 8);
1064
509k
                dst_u[x] = get_bits(gb, 8);
1065
509k
                dst_v[x] = get_bits(gb, 8);
1066
509k
            }
1067
1.93M
        } else {
1068
1.93M
            int pred_TL[4], pred_L[4], pred_T[4];
1069
1.93M
            int y, u, v;
1070
1071
1.93M
            pred_TL[0] = pred_L[0] = dst_y[-p->linesize[0]];
1072
1.93M
            pred_TL[1] = pred_L[1] = dst_u[-p->linesize[1]];
1073
1.93M
            pred_TL[2] = pred_L[2] = dst_v[-p->linesize[2]];
1074
1075
35.5M
            for (x = 0; x < avctx->width; x++) {
1076
33.6M
                pred_T[0] = dst_y[-p->linesize[0] + x];
1077
33.6M
                pred_T[1] = dst_u[-p->linesize[1] + x];
1078
33.6M
                pred_T[2] = dst_v[-p->linesize[2] + x];
1079
1080
33.6M
                y = get_vlc2(gb, s->vlc[0].table, SHEER_VLC_BITS, 2);
1081
33.6M
                u = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
1082
33.6M
                v = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
1083
1084
33.6M
                dst_y[x] = pred_L[0] = (y + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0xff;
1085
33.6M
                dst_u[x] = pred_L[1] = (u + ((3 * (pred_T[1] + pred_L[1]) - 2 * pred_TL[1]) >> 2)) & 0xff;
1086
33.6M
                dst_v[x] = pred_L[2] = (v + ((3 * (pred_T[2] + pred_L[2]) - 2 * pred_TL[2]) >> 2)) & 0xff;
1087
1088
33.6M
                pred_TL[0] = pred_T[0];
1089
33.6M
                pred_TL[1] = pred_T[1];
1090
33.6M
                pred_TL[2] = pred_T[2];
1091
33.6M
            }
1092
1.93M
        }
1093
1094
1.97M
        dst_y += p->linesize[0];
1095
1.97M
        dst_u += p->linesize[1];
1096
1.97M
        dst_v += p->linesize[2];
1097
1.97M
    }
1098
2.62k
}
1099
1100
static void decode_aybri(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
1101
3.47k
{
1102
3.47k
    SheerVideoContext *s = avctx->priv_data;
1103
3.47k
    uint8_t *dst_a, *dst_y, *dst_u, *dst_v;
1104
3.47k
    int x, y;
1105
1106
3.47k
    dst_a = p->data[3];
1107
3.47k
    dst_y = p->data[0];
1108
3.47k
    dst_u = p->data[1];
1109
3.47k
    dst_v = p->data[2];
1110
1111
3.47k
    if (get_bits1(gb)) {
1112
30.8k
        for (x = 0; x < avctx->width; x++) {
1113
30.2k
            dst_a[x] = get_bits(gb, 8);
1114
30.2k
            dst_y[x] = get_bits(gb, 8);
1115
30.2k
            dst_u[x] = get_bits(gb, 8);
1116
30.2k
            dst_v[x] = get_bits(gb, 8);
1117
30.2k
        }
1118
2.80k
    } else {
1119
2.80k
        int pred[4] = { 125, s->alt ? 125 : -146, -128, -128 };
1120
1121
11.3M
        for (x = 0; x < avctx->width; x++) {
1122
11.3M
            int a, y, u, v;
1123
1124
11.3M
            a = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
1125
11.3M
            y = get_vlc2(gb, s->vlc[0].table, SHEER_VLC_BITS, 2);
1126
11.3M
            u = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
1127
11.3M
            v = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
1128
1129
11.3M
            dst_a[x] = pred[0] = (a + pred[0]) & 0xff;
1130
11.3M
            dst_y[x] = pred[1] = (y + pred[1]) & 0xff;
1131
11.3M
            dst_u[x] = pred[2] = (u + pred[2]) & 0xff;
1132
11.3M
            dst_v[x] = pred[3] = (v + pred[3]) & 0xff;
1133
11.3M
        }
1134
2.80k
    }
1135
1136
3.47k
    dst_a += p->linesize[3];
1137
3.47k
    dst_y += p->linesize[0];
1138
3.47k
    dst_u += p->linesize[1];
1139
3.47k
    dst_v += p->linesize[2];
1140
1141
1.69M
    for (y = 1; y < avctx->height; y++) {
1142
1.68M
        if (get_bits1(gb)) {
1143
518k
            for (x = 0; x < avctx->width; x++) {
1144
505k
                dst_a[x] = get_bits(gb, 8);
1145
505k
                dst_y[x] = get_bits(gb, 8);
1146
505k
                dst_u[x] = get_bits(gb, 8);
1147
505k
                dst_v[x] = get_bits(gb, 8);
1148
505k
            }
1149
1.67M
        } else {
1150
1.67M
            int pred_L[4];
1151
1.67M
            int a, y, u, v;
1152
1153
1.67M
            pred_L[0] = dst_a[-p->linesize[3]];
1154
1.67M
            pred_L[1] = dst_y[-p->linesize[0]];
1155
1.67M
            pred_L[2] = dst_u[-p->linesize[1]];
1156
1.67M
            pred_L[3] = dst_v[-p->linesize[2]];
1157
1158
32.2M
            for (x = 0; x < avctx->width; x++) {
1159
30.5M
                a = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
1160
30.5M
                y = get_vlc2(gb, s->vlc[0].table, SHEER_VLC_BITS, 2);
1161
30.5M
                u = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
1162
30.5M
                v = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
1163
1164
30.5M
                dst_a[x] = pred_L[0] = (a + pred_L[0]) & 0xff;
1165
30.5M
                dst_y[x] = pred_L[1] = (y + pred_L[1]) & 0xff;
1166
30.5M
                dst_u[x] = pred_L[2] = (u + pred_L[2]) & 0xff;
1167
30.5M
                dst_v[x] = pred_L[3] = (v + pred_L[3]) & 0xff;
1168
30.5M
            }
1169
1.67M
        }
1170
1171
1.68M
        dst_a += p->linesize[3];
1172
1.68M
        dst_y += p->linesize[0];
1173
1.68M
        dst_u += p->linesize[1];
1174
1.68M
        dst_v += p->linesize[2];
1175
1.68M
    }
1176
3.47k
}
1177
1178
static void decode_aybr(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
1179
4.04k
{
1180
4.04k
    SheerVideoContext *s = avctx->priv_data;
1181
4.04k
    uint8_t *dst_a, *dst_y, *dst_u, *dst_v;
1182
4.04k
    int x, y;
1183
1184
4.04k
    dst_a = p->data[3];
1185
4.04k
    dst_y = p->data[0];
1186
4.04k
    dst_u = p->data[1];
1187
4.04k
    dst_v = p->data[2];
1188
1189
4.04k
    if (get_bits1(gb)) {
1190
369k
        for (x = 0; x < avctx->width; x++) {
1191
368k
            dst_a[x] = get_bits(gb, 8);
1192
368k
            dst_y[x] = get_bits(gb, 8);
1193
368k
            dst_u[x] = get_bits(gb, 8);
1194
368k
            dst_v[x] = get_bits(gb, 8);
1195
368k
        }
1196
3.56k
    } else {
1197
3.56k
        int pred[4] = { 125, s->alt ? 125 : -146, -128, -128 };
1198
1199
10.6M
        for (x = 0; x < avctx->width; x++) {
1200
10.6M
            int a, y, u, v;
1201
1202
10.6M
            a = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
1203
10.6M
            y = get_vlc2(gb, s->vlc[0].table, SHEER_VLC_BITS, 2);
1204
10.6M
            u = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
1205
10.6M
            v = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
1206
1207
10.6M
            dst_a[x] = pred[0] = (a + pred[0]) & 0xff;
1208
10.6M
            dst_y[x] = pred[1] = (y + pred[1]) & 0xff;
1209
10.6M
            dst_u[x] = pred[2] = (u + pred[2]) & 0xff;
1210
10.6M
            dst_v[x] = pred[3] = (v + pred[3]) & 0xff;
1211
10.6M
        }
1212
3.56k
    }
1213
1214
4.04k
    dst_a += p->linesize[3];
1215
4.04k
    dst_y += p->linesize[0];
1216
4.04k
    dst_u += p->linesize[1];
1217
4.04k
    dst_v += p->linesize[2];
1218
1219
1.16M
    for (y = 1; y < avctx->height; y++) {
1220
1.15M
        if (get_bits1(gb)) {
1221
304k
            for (x = 0; x < avctx->width; x++) {
1222
291k
                dst_a[x] = get_bits(gb, 8);
1223
291k
                dst_y[x] = get_bits(gb, 8);
1224
291k
                dst_u[x] = get_bits(gb, 8);
1225
291k
                dst_v[x] = get_bits(gb, 8);
1226
291k
            }
1227
1.14M
        } else {
1228
1.14M
            int pred_TL[4], pred_L[4], pred_T[4];
1229
1.14M
            int a, y, u, v;
1230
1231
1.14M
            pred_TL[0] = pred_L[0] = dst_a[-p->linesize[3]];
1232
1.14M
            pred_TL[1] = pred_L[1] = dst_y[-p->linesize[0]];
1233
1.14M
            pred_TL[2] = pred_L[2] = dst_u[-p->linesize[1]];
1234
1.14M
            pred_TL[3] = pred_L[3] = dst_v[-p->linesize[2]];
1235
1236
33.9M
            for (x = 0; x < avctx->width; x++) {
1237
32.7M
                pred_T[0] = dst_a[-p->linesize[3] + x];
1238
32.7M
                pred_T[1] = dst_y[-p->linesize[0] + x];
1239
32.7M
                pred_T[2] = dst_u[-p->linesize[1] + x];
1240
32.7M
                pred_T[3] = dst_v[-p->linesize[2] + x];
1241
1242
32.7M
                a = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
1243
32.7M
                y = get_vlc2(gb, s->vlc[0].table, SHEER_VLC_BITS, 2);
1244
32.7M
                u = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
1245
32.7M
                v = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
1246
1247
32.7M
                dst_a[x] = pred_L[0] = (a + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0xff;
1248
32.7M
                dst_y[x] = pred_L[1] = (y + ((3 * (pred_T[1] + pred_L[1]) - 2 * pred_TL[1]) >> 2)) & 0xff;
1249
32.7M
                dst_u[x] = pred_L[2] = (u + ((3 * (pred_T[2] + pred_L[2]) - 2 * pred_TL[2]) >> 2)) & 0xff;
1250
32.7M
                dst_v[x] = pred_L[3] = (v + ((3 * (pred_T[3] + pred_L[3]) - 2 * pred_TL[3]) >> 2)) & 0xff;
1251
1252
32.7M
                pred_TL[0] = pred_T[0];
1253
32.7M
                pred_TL[1] = pred_T[1];
1254
32.7M
                pred_TL[2] = pred_T[2];
1255
32.7M
                pred_TL[3] = pred_T[3];
1256
32.7M
            }
1257
1.14M
        }
1258
1259
1.15M
        dst_a += p->linesize[3];
1260
1.15M
        dst_y += p->linesize[0];
1261
1.15M
        dst_u += p->linesize[1];
1262
1.15M
        dst_v += p->linesize[2];
1263
1.15M
    }
1264
4.04k
}
1265
1266
static void decode_argxi(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
1267
2.13k
{
1268
2.13k
    SheerVideoContext *s = avctx->priv_data;
1269
2.13k
    uint16_t *dst_r, *dst_g, *dst_b, *dst_a;
1270
2.13k
    int x, y;
1271
1272
2.13k
    dst_r = (uint16_t *)p->data[2];
1273
2.13k
    dst_g = (uint16_t *)p->data[0];
1274
2.13k
    dst_b = (uint16_t *)p->data[1];
1275
2.13k
    dst_a = (uint16_t *)p->data[3];
1276
1277
3.29M
    for (y = 0; y < avctx->height; y++) {
1278
3.29M
        if (get_bits1(gb)) {
1279
846k
            for (x = 0; x < avctx->width; x++) {
1280
830k
                dst_a[x] = get_bits(gb, 10);
1281
830k
                dst_r[x] = get_bits(gb, 10);
1282
830k
                dst_g[x] = get_bits(gb, 10);
1283
830k
                dst_b[x] = get_bits(gb, 10);
1284
830k
            }
1285
3.27M
        } else {
1286
3.27M
            int pred[4] = { 512, 512, 512, 512 };
1287
1288
50.4M
            for (x = 0; x < avctx->width; x++) {
1289
47.1M
                int r, g, b, a;
1290
1291
47.1M
                a = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
1292
47.1M
                r = get_vlc2(gb, s->vlc[0].table, SHEER_VLC_BITS, 2);
1293
47.1M
                g = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
1294
47.1M
                b = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
1295
1296
47.1M
                dst_a[x] = pred[3] = (a + pred[3]) & 0x3ff;
1297
47.1M
                dst_r[x] = pred[0] = (r + pred[0]) & 0x3ff;
1298
47.1M
                dst_g[x] = pred[1] = (r + g + pred[1]) & 0x3ff;
1299
47.1M
                dst_b[x] = pred[2] = (r + g + b + pred[2]) & 0x3ff;
1300
47.1M
            }
1301
3.27M
        }
1302
1303
3.29M
        dst_r += p->linesize[2] / 2;
1304
3.29M
        dst_g += p->linesize[0] / 2;
1305
3.29M
        dst_b += p->linesize[1] / 2;
1306
3.29M
        dst_a += p->linesize[3] / 2;
1307
3.29M
    }
1308
2.13k
}
1309
1310
static void decode_argx(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
1311
3.88k
{
1312
3.88k
    SheerVideoContext *s = avctx->priv_data;
1313
3.88k
    uint16_t *dst_r, *dst_g, *dst_b, *dst_a;
1314
3.88k
    int x, y;
1315
1316
3.88k
    dst_r = (uint16_t *)p->data[2];
1317
3.88k
    dst_g = (uint16_t *)p->data[0];
1318
3.88k
    dst_b = (uint16_t *)p->data[1];
1319
3.88k
    dst_a = (uint16_t *)p->data[3];
1320
1321
3.88k
    if (get_bits1(gb)) {
1322
1.72M
        for (x = 0; x < avctx->width; x++) {
1323
1.72M
            dst_a[x] = get_bits(gb, 10);
1324
1.72M
            dst_r[x] = get_bits(gb, 10);
1325
1.72M
            dst_g[x] = get_bits(gb, 10);
1326
1.72M
            dst_b[x] = get_bits(gb, 10);
1327
1.72M
        }
1328
3.38k
    } else {
1329
3.38k
        int pred[4] = { 512, 512, 512, 512 };
1330
1331
8.88M
        for (x = 0; x < avctx->width; x++) {
1332
8.88M
            int r, g, b, a;
1333
1334
8.88M
            a = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
1335
8.88M
            r = get_vlc2(gb, s->vlc[0].table, SHEER_VLC_BITS, 2);
1336
8.88M
            g = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
1337
8.88M
            b = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
1338
1339
8.88M
            dst_a[x] = pred[3] = (a + pred[3]) & 0x3ff;
1340
8.88M
            dst_r[x] = pred[0] = (r + pred[0]) & 0x3ff;
1341
8.88M
            dst_g[x] = pred[1] = (r + g + pred[1]) & 0x3ff;
1342
8.88M
            dst_b[x] = pred[2] = (r + g + b + pred[2]) & 0x3ff;
1343
8.88M
        }
1344
3.38k
    }
1345
1346
3.88k
    dst_r += p->linesize[2] / 2;
1347
3.88k
    dst_g += p->linesize[0] / 2;
1348
3.88k
    dst_b += p->linesize[1] / 2;
1349
3.88k
    dst_a += p->linesize[3] / 2;
1350
1351
986k
    for (y = 1; y < avctx->height; y++) {
1352
982k
        if (get_bits1(gb)) {
1353
120k
            for (x = 0; x < avctx->width; x++) {
1354
114k
                dst_a[x] = get_bits(gb, 10);
1355
114k
                dst_r[x] = get_bits(gb, 10);
1356
114k
                dst_g[x] = get_bits(gb, 10);
1357
114k
                dst_b[x] = get_bits(gb, 10);
1358
114k
            }
1359
976k
        } else {
1360
976k
            int pred_TL[4], pred_L[4], pred_T[4];
1361
976k
            int r, g, b, a;
1362
1363
976k
            pred_TL[0] = pred_L[0] = dst_r[-p->linesize[2] / 2];
1364
976k
            pred_TL[1] = pred_L[1] = dst_g[-p->linesize[0] / 2];
1365
976k
            pred_TL[2] = pred_L[2] = dst_b[-p->linesize[1] / 2];
1366
976k
            pred_TL[3] = pred_L[3] = dst_a[-p->linesize[3] / 2];
1367
1368
37.1M
            for (x = 0; x < avctx->width; x++) {
1369
36.2M
                pred_T[0] = dst_r[-p->linesize[2] / 2 + x];
1370
36.2M
                pred_T[1] = dst_g[-p->linesize[0] / 2 + x];
1371
36.2M
                pred_T[2] = dst_b[-p->linesize[1] / 2 + x];
1372
36.2M
                pred_T[3] = dst_a[-p->linesize[3] / 2 + x];
1373
1374
36.2M
                a = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
1375
36.2M
                r = get_vlc2(gb, s->vlc[0].table, SHEER_VLC_BITS, 2);
1376
36.2M
                g = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
1377
36.2M
                b = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
1378
1379
36.2M
                dst_a[x] = pred_L[3] = (a + ((3 * (pred_T[3] + pred_L[3]) - 2 * pred_TL[3]) >> 2)) & 0x3ff;
1380
36.2M
                dst_r[x] = pred_L[0] = (r + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0x3ff;
1381
36.2M
                dst_g[x] = pred_L[1] = (r + g + ((3 * (pred_T[1] + pred_L[1]) - 2 * pred_TL[1]) >> 2)) & 0x3ff;
1382
36.2M
                dst_b[x] = pred_L[2] = (r + g + b + ((3 * (pred_T[2] + pred_L[2]) - 2 * pred_TL[2]) >> 2)) & 0x3ff;
1383
1384
36.2M
                pred_TL[0] = pred_T[0];
1385
36.2M
                pred_TL[1] = pred_T[1];
1386
36.2M
                pred_TL[2] = pred_T[2];
1387
36.2M
                pred_TL[3] = pred_T[3];
1388
36.2M
            }
1389
976k
        }
1390
1391
982k
        dst_r += p->linesize[2] / 2;
1392
982k
        dst_g += p->linesize[0] / 2;
1393
982k
        dst_b += p->linesize[1] / 2;
1394
982k
        dst_a += p->linesize[3] / 2;
1395
982k
    }
1396
3.88k
}
1397
1398
static void decode_rgbxi(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
1399
1.31k
{
1400
1.31k
    SheerVideoContext *s = avctx->priv_data;
1401
1.31k
    uint16_t *dst_r, *dst_g, *dst_b;
1402
1.31k
    int x, y;
1403
1404
1.31k
    dst_r = (uint16_t *)p->data[2];
1405
1.31k
    dst_g = (uint16_t *)p->data[0];
1406
1.31k
    dst_b = (uint16_t *)p->data[1];
1407
1408
4.26M
    for (y = 0; y < avctx->height; y++) {
1409
4.26M
        if (get_bits1(gb)) {
1410
3.93M
            for (x = 0; x < avctx->width; x++) {
1411
3.90M
                dst_r[x] = get_bits(gb, 10);
1412
3.90M
                dst_g[x] = get_bits(gb, 10);
1413
3.90M
                dst_b[x] = get_bits(gb, 10);
1414
3.90M
            }
1415
4.23M
        } else {
1416
4.23M
            int pred[4] = { 512, 512, 512, 0 };
1417
1418
61.1M
            for (x = 0; x < avctx->width; x++) {
1419
56.9M
                int r, g, b;
1420
1421
56.9M
                r = get_vlc2(gb, s->vlc[0].table, SHEER_VLC_BITS, 2);
1422
56.9M
                g = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
1423
56.9M
                b = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
1424
1425
56.9M
                dst_r[x] = pred[0] = (r + pred[0]) & 0x3ff;
1426
56.9M
                dst_g[x] = pred[1] = (r + g + pred[1]) & 0x3ff;
1427
56.9M
                dst_b[x] = pred[2] = (r + g + b + pred[2]) & 0x3ff;
1428
56.9M
            }
1429
4.23M
        }
1430
1431
4.26M
        dst_r += p->linesize[2] / 2;
1432
4.26M
        dst_g += p->linesize[0] / 2;
1433
4.26M
        dst_b += p->linesize[1] / 2;
1434
4.26M
    }
1435
1.31k
}
1436
1437
static void decode_rgbx(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
1438
3.18k
{
1439
3.18k
    SheerVideoContext *s = avctx->priv_data;
1440
3.18k
    uint16_t *dst_r, *dst_g, *dst_b;
1441
3.18k
    int x, y;
1442
1443
3.18k
    dst_r = (uint16_t *)p->data[2];
1444
3.18k
    dst_g = (uint16_t *)p->data[0];
1445
3.18k
    dst_b = (uint16_t *)p->data[1];
1446
1447
3.18k
    if (get_bits1(gb)) {
1448
82.5k
        for (x = 0; x < avctx->width; x++) {
1449
81.2k
            dst_r[x] = get_bits(gb, 10);
1450
81.2k
            dst_g[x] = get_bits(gb, 10);
1451
81.2k
            dst_b[x] = get_bits(gb, 10);
1452
81.2k
        }
1453
1.88k
    } else {
1454
1.88k
        int pred[4] = { 512, 512, 512, 0 };
1455
1456
6.58M
        for (x = 0; x < avctx->width; x++) {
1457
6.57M
            int r, g, b;
1458
1459
6.57M
            r = get_vlc2(gb, s->vlc[0].table, SHEER_VLC_BITS, 2);
1460
6.57M
            g = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
1461
6.57M
            b = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
1462
1463
6.57M
            dst_r[x] = pred[0] = (r + pred[0]) & 0x3ff;
1464
6.57M
            dst_g[x] = pred[1] = (r + g + pred[1]) & 0x3ff;
1465
6.57M
            dst_b[x] = pred[2] = (r + g + b + pred[2]) & 0x3ff;
1466
6.57M
        }
1467
1.88k
    }
1468
1469
3.18k
    dst_r += p->linesize[2] / 2;
1470
3.18k
    dst_g += p->linesize[0] / 2;
1471
3.18k
    dst_b += p->linesize[1] / 2;
1472
1473
3.22M
    for (y = 1; y < avctx->height; y++) {
1474
3.22M
        if (get_bits1(gb)) {
1475
224k
            for (x = 0; x < avctx->width; x++) {
1476
197k
                dst_r[x] = get_bits(gb, 10);
1477
197k
                dst_g[x] = get_bits(gb, 10);
1478
197k
                dst_b[x] = get_bits(gb, 10);
1479
197k
            }
1480
3.19M
        } else {
1481
3.19M
            int pred_TL[4], pred_L[4], pred_T[4];
1482
3.19M
            int r, g, b;
1483
1484
3.19M
            pred_TL[0] = pred_L[0] = dst_r[-p->linesize[2] / 2];
1485
3.19M
            pred_TL[1] = pred_L[1] = dst_g[-p->linesize[0] / 2];
1486
3.19M
            pred_TL[2] = pred_L[2] = dst_b[-p->linesize[1] / 2];
1487
1488
23.7M
            for (x = 0; x < avctx->width; x++) {
1489
20.5M
                pred_T[0] = dst_r[-p->linesize[2] / 2 + x];
1490
20.5M
                pred_T[1] = dst_g[-p->linesize[0] / 2 + x];
1491
20.5M
                pred_T[2] = dst_b[-p->linesize[1] / 2 + x];
1492
1493
20.5M
                r = get_vlc2(gb, s->vlc[0].table, SHEER_VLC_BITS, 2);
1494
20.5M
                g = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
1495
20.5M
                b = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
1496
1497
20.5M
                dst_r[x] = pred_L[0] = (r + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0x3ff;
1498
20.5M
                dst_g[x] = pred_L[1] = (r + g + ((3 * (pred_T[1] + pred_L[1]) - 2 * pred_TL[1]) >> 2)) & 0x3ff;
1499
20.5M
                dst_b[x] = pred_L[2] = (r + g + b + ((3 * (pred_T[2] + pred_L[2]) - 2 * pred_TL[2]) >> 2)) & 0x3ff;
1500
1501
20.5M
                pred_TL[0] = pred_T[0];
1502
20.5M
                pred_TL[1] = pred_T[1];
1503
20.5M
                pred_TL[2] = pred_T[2];
1504
20.5M
            }
1505
3.19M
        }
1506
1507
3.22M
        dst_r += p->linesize[2] / 2;
1508
3.22M
        dst_g += p->linesize[0] / 2;
1509
3.22M
        dst_b += p->linesize[1] / 2;
1510
3.22M
    }
1511
3.18k
}
1512
1513
static void decode_argbi(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
1514
3.35k
{
1515
3.35k
    SheerVideoContext *s = avctx->priv_data;
1516
3.35k
    uint8_t *dst;
1517
3.35k
    int x, y;
1518
1519
3.35k
    dst = p->data[0];
1520
3.35k
    if (get_bits1(gb)) {
1521
1.54M
        for (x = 0; x < avctx->width; x++) {
1522
1.54M
            dst[x * 4 + 0] = get_bits(gb, 8);
1523
1.54M
            dst[x * 4 + 1] = get_bits(gb, 8);
1524
1.54M
            dst[x * 4 + 2] = get_bits(gb, 8);
1525
1.54M
            dst[x * 4 + 3] = get_bits(gb, 8);
1526
1.54M
        }
1527
2.51k
    } else {
1528
2.51k
        int pred[4] = { -128, -128, -128, -128 };
1529
1530
6.82M
        for (x = 0; x < avctx->width; x++) {
1531
6.81M
            int a, r, g, b;
1532
1533
6.81M
            a = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
1534
6.81M
            r = get_vlc2(gb, s->vlc[0].table, SHEER_VLC_BITS, 2);
1535
6.81M
            g = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
1536
6.81M
            b = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
1537
1538
6.81M
            dst[4 * x + 0] = pred[0] = (a + pred[0]) & 0xff;
1539
6.81M
            dst[4 * x + 1] = pred[1] = (r + pred[1]) & 0xff;
1540
6.81M
            dst[4 * x + 2] = pred[2] = (r + g + pred[2]) & 0xff;
1541
6.81M
            dst[4 * x + 3] = pred[3] = (r + g + b + pred[3]) & 0xff;
1542
6.81M
        }
1543
2.51k
    }
1544
1545
3.35k
    dst += p->linesize[0];
1546
2.21M
    for (y = 1; y < avctx->height; y++) {
1547
2.21M
        if (get_bits1(gb)) {
1548
400k
            for (x = 0; x < avctx->width; x++) {
1549
373k
                dst[x * 4 + 0] = get_bits(gb, 8);
1550
373k
                dst[x * 4 + 1] = get_bits(gb, 8);
1551
373k
                dst[x * 4 + 2] = get_bits(gb, 8);
1552
373k
                dst[x * 4 + 3] = get_bits(gb, 8);
1553
373k
            }
1554
2.18M
        } else {
1555
2.18M
            int pred_L[4];
1556
2.18M
            int a, r, g, b;
1557
1558
2.18M
            pred_L[0] = dst[-p->linesize[0] + 0];
1559
2.18M
            pred_L[1] = dst[-p->linesize[0] + 1];
1560
2.18M
            pred_L[2] = dst[-p->linesize[0] + 2];
1561
2.18M
            pred_L[3] = dst[-p->linesize[0] + 3];
1562
1563
43.5M
            for (x = 0; x < avctx->width; x++) {
1564
41.4M
                a = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
1565
41.4M
                r = get_vlc2(gb, s->vlc[0].table, SHEER_VLC_BITS, 2);
1566
41.4M
                g = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
1567
41.4M
                b = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
1568
1569
41.4M
                dst[4 * x + 0] = pred_L[0] = (a + pred_L[0]) & 0xff;
1570
41.4M
                dst[4 * x + 1] = pred_L[1] = (r + pred_L[1]) & 0xff;
1571
41.4M
                dst[4 * x + 2] = pred_L[2] = (r + g + pred_L[2]) & 0xff;
1572
41.4M
                dst[4 * x + 3] = pred_L[3] = (r + g + b + pred_L[3]) & 0xff;
1573
41.4M
            }
1574
2.18M
        }
1575
2.21M
        dst += p->linesize[0];
1576
2.21M
    }
1577
3.35k
}
1578
1579
static void decode_argb(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
1580
24.0k
{
1581
24.0k
    SheerVideoContext *s = avctx->priv_data;
1582
24.0k
    uint8_t *dst;
1583
24.0k
    int x, y;
1584
1585
24.0k
    dst = p->data[0];
1586
24.0k
    if (get_bits1(gb)) {
1587
289k
        for (x = 0; x < avctx->width; x++) {
1588
288k
            dst[x * 4 + 0] = get_bits(gb, 8);
1589
288k
            dst[x * 4 + 1] = get_bits(gb, 8);
1590
288k
            dst[x * 4 + 2] = get_bits(gb, 8);
1591
288k
            dst[x * 4 + 3] = get_bits(gb, 8);
1592
288k
        }
1593
23.0k
    } else {
1594
23.0k
        int pred[4] = { -128, -128, -128, -128 };
1595
1596
6.26M
        for (x = 0; x < avctx->width; x++) {
1597
6.23M
            int a, r, g, b;
1598
1599
6.23M
            a = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
1600
6.23M
            r = get_vlc2(gb, s->vlc[0].table, SHEER_VLC_BITS, 2);
1601
6.23M
            g = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
1602
6.23M
            b = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
1603
1604
6.23M
            dst[4 * x + 0] = pred[0] = (a + pred[0]) & 0xff;
1605
6.23M
            dst[4 * x + 1] = pred[1] = (r + pred[1]) & 0xff;
1606
6.23M
            dst[4 * x + 2] = pred[2] = (r + g + pred[2]) & 0xff;
1607
6.23M
            dst[4 * x + 3] = pred[3] = (r + g + b + pred[3]) & 0xff;
1608
6.23M
        }
1609
23.0k
    }
1610
1611
24.0k
    dst += p->linesize[0];
1612
7.50M
    for (y = 1; y < avctx->height; y++) {
1613
7.47M
        if (get_bits1(gb)) {
1614
221k
            for (x = 0; x < avctx->width; x++) {
1615
173k
                dst[x * 4 + 0] = get_bits(gb, 8);
1616
173k
                dst[x * 4 + 1] = get_bits(gb, 8);
1617
173k
                dst[x * 4 + 2] = get_bits(gb, 8);
1618
173k
                dst[x * 4 + 3] = get_bits(gb, 8);
1619
173k
            }
1620
7.43M
        } else {
1621
7.43M
            int pred_TL[4], pred_L[4], pred_T[4];
1622
7.43M
            int a, r, g, b;
1623
1624
7.43M
            pred_TL[0] = pred_L[0] = dst[-p->linesize[0] + 0];
1625
7.43M
            pred_TL[1] = pred_L[1] = dst[-p->linesize[0] + 1];
1626
7.43M
            pred_TL[2] = pred_L[2] = dst[-p->linesize[0] + 2];
1627
7.43M
            pred_TL[3] = pred_L[3] = dst[-p->linesize[0] + 3];
1628
1629
45.3M
            for (x = 0; x < avctx->width; x++) {
1630
37.9M
                pred_T[0] = dst[-p->linesize[0] + 4 * x + 0];
1631
37.9M
                pred_T[1] = dst[-p->linesize[0] + 4 * x + 1];
1632
37.9M
                pred_T[2] = dst[-p->linesize[0] + 4 * x + 2];
1633
37.9M
                pred_T[3] = dst[-p->linesize[0] + 4 * x + 3];
1634
1635
37.9M
                a = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
1636
37.9M
                r = get_vlc2(gb, s->vlc[0].table, SHEER_VLC_BITS, 2);
1637
37.9M
                g = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
1638
37.9M
                b = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
1639
1640
37.9M
                dst[4 * x + 0] = pred_L[0] = (a + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0xff;
1641
37.9M
                dst[4 * x + 1] = pred_L[1] = (r + ((3 * (pred_T[1] + pred_L[1]) - 2 * pred_TL[1]) >> 2)) & 0xff;
1642
37.9M
                dst[4 * x + 2] = pred_L[2] = (r + g + ((3 * (pred_T[2] + pred_L[2]) - 2 * pred_TL[2]) >> 2)) & 0xff;
1643
37.9M
                dst[4 * x + 3] = pred_L[3] = (r + g + b + ((3 * (pred_T[3] + pred_L[3]) - 2 * pred_TL[3]) >> 2)) & 0xff;
1644
1645
37.9M
                pred_TL[0] = pred_T[0];
1646
37.9M
                pred_TL[1] = pred_T[1];
1647
37.9M
                pred_TL[2] = pred_T[2];
1648
37.9M
                pred_TL[3] = pred_T[3];
1649
37.9M
            }
1650
7.43M
        }
1651
7.47M
        dst += p->linesize[0];
1652
7.47M
    }
1653
24.0k
}
1654
1655
static void decode_rgbi(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
1656
2.85k
{
1657
2.85k
    SheerVideoContext *s = avctx->priv_data;
1658
2.85k
    uint8_t *dst;
1659
2.85k
    int x, y;
1660
1661
2.85k
    dst = p->data[0];
1662
2.85k
    if (get_bits1(gb)) {
1663
1.12M
        for (x = 0; x < avctx->width; x++) {
1664
1.12M
            dst[x * 4 + 0] = get_bits(gb, 8);
1665
1.12M
            dst[x * 4 + 1] = get_bits(gb, 8);
1666
1.12M
            dst[x * 4 + 2] = get_bits(gb, 8);
1667
1.12M
        }
1668
1.60k
    } else {
1669
1.60k
        int pred[4] = { -128, -128, -128, -128 };
1670
1671
12.2M
        for (x = 0; x < avctx->width; x++) {
1672
12.2M
            int r, g, b;
1673
1674
12.2M
            r = get_vlc2(gb, s->vlc[0].table, SHEER_VLC_BITS, 2);
1675
12.2M
            g = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
1676
12.2M
            b = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
1677
1678
12.2M
            dst[4 * x + 0] = pred[0] = (r + pred[0]) & 0xff;
1679
12.2M
            dst[4 * x + 1] = pred[1] = (r + g + pred[1]) & 0xff;
1680
12.2M
            dst[4 * x + 2] = pred[2] = (r + g + b + pred[2]) & 0xff;
1681
12.2M
        }
1682
1.60k
    }
1683
1684
2.85k
    dst += p->linesize[0];
1685
1.55M
    for (y = 1; y < avctx->height; y++) {
1686
1.54M
        if (get_bits1(gb)) {
1687
382k
            for (x = 0; x < avctx->width; x++) {
1688
365k
                dst[x * 4 + 0] = get_bits(gb, 8);
1689
365k
                dst[x * 4 + 1] = get_bits(gb, 8);
1690
365k
                dst[x * 4 + 2] = get_bits(gb, 8);
1691
365k
            }
1692
1.53M
        } else {
1693
1.53M
            int pred_L[4];
1694
1.53M
            int r, g, b;
1695
1696
1.53M
            pred_L[0] = dst[-p->linesize[0] + 0];
1697
1.53M
            pred_L[1] = dst[-p->linesize[0] + 1];
1698
1.53M
            pred_L[2] = dst[-p->linesize[0] + 2];
1699
1700
31.5M
            for (x = 0; x < avctx->width; x++) {
1701
29.9M
                r = get_vlc2(gb, s->vlc[0].table, SHEER_VLC_BITS, 2);
1702
29.9M
                g = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
1703
29.9M
                b = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
1704
1705
29.9M
                dst[4 * x + 0] = pred_L[0] = (r + pred_L[0]) & 0xff;
1706
29.9M
                dst[4 * x + 1] = pred_L[1] = (r + g + pred_L[1]) & 0xff;
1707
29.9M
                dst[4 * x + 2] = pred_L[2] = (r + g + b + pred_L[2]) & 0xff;
1708
29.9M
            }
1709
1.53M
        }
1710
1.54M
        dst += p->linesize[0];
1711
1.54M
    }
1712
2.85k
}
1713
1714
static void decode_rgb(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
1715
3.25k
{
1716
3.25k
    SheerVideoContext *s = avctx->priv_data;
1717
3.25k
    uint8_t *dst;
1718
3.25k
    int x, y;
1719
1720
3.25k
    dst = p->data[0];
1721
3.25k
    if (get_bits1(gb)) {
1722
43.9k
        for (x = 0; x < avctx->width; x++) {
1723
43.2k
            dst[x * 4 + 0] = get_bits(gb, 8);
1724
43.2k
            dst[x * 4 + 1] = get_bits(gb, 8);
1725
43.2k
            dst[x * 4 + 2] = get_bits(gb, 8);
1726
43.2k
        }
1727
2.62k
    } else {
1728
2.62k
        int pred[4] = { -128, -128, -128, -128 };
1729
1730
5.59M
        for (x = 0; x < avctx->width; x++) {
1731
5.59M
            int r, g, b;
1732
1733
5.59M
            r = get_vlc2(gb, s->vlc[0].table, SHEER_VLC_BITS, 2);
1734
5.59M
            g = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
1735
5.59M
            b = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
1736
1737
5.59M
            dst[4 * x + 0] = pred[0] = (r + pred[0]) & 0xff;
1738
5.59M
            dst[4 * x + 1] = pred[1] = (r + g + pred[1]) & 0xff;
1739
5.59M
            dst[4 * x + 2] = pred[2] = (r + g + b + pred[2]) & 0xff;
1740
5.59M
        }
1741
2.62k
    }
1742
1743
3.25k
    dst += p->linesize[0];
1744
1.02M
    for (y = 1; y < avctx->height; y++) {
1745
1.02M
        if (get_bits1(gb)) {
1746
174k
            for (x = 0; x < avctx->width; x++) {
1747
159k
                dst[x * 4 + 0] = get_bits(gb, 8);
1748
159k
                dst[x * 4 + 1] = get_bits(gb, 8);
1749
159k
                dst[x * 4 + 2] = get_bits(gb, 8);
1750
159k
            }
1751
1.00M
        } else {
1752
1.00M
            int pred_TL[4], pred_L[4], pred_T[4];
1753
1.00M
            int r, g, b;
1754
1755
1.00M
            pred_TL[0] = pred_L[0] = dst[-p->linesize[0] + 0];
1756
1.00M
            pred_TL[1] = pred_L[1] = dst[-p->linesize[0] + 1];
1757
1.00M
            pred_TL[2] = pred_L[2] = dst[-p->linesize[0] + 2];
1758
1759
25.5M
            for (x = 0; x < avctx->width; x++) {
1760
24.5M
                pred_T[0] = dst[-p->linesize[0] + 4 * x + 0];
1761
24.5M
                pred_T[1] = dst[-p->linesize[0] + 4 * x + 1];
1762
24.5M
                pred_T[2] = dst[-p->linesize[0] + 4 * x + 2];
1763
1764
24.5M
                r = get_vlc2(gb, s->vlc[0].table, SHEER_VLC_BITS, 2);
1765
24.5M
                g = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
1766
24.5M
                b = get_vlc2(gb, s->vlc[1].table, SHEER_VLC_BITS, 2);
1767
1768
24.5M
                dst[4 * x + 0] = pred_L[0] = (r + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0xff;
1769
24.5M
                dst[4 * x + 1] = pred_L[1] = (r + g + ((3 * (pred_T[1] + pred_L[1]) - 2 * pred_TL[1]) >> 2)) & 0xff;
1770
24.5M
                dst[4 * x + 2] = pred_L[2] = (r + g + b + ((3 * (pred_T[2] + pred_L[2]) - 2 * pred_TL[2]) >> 2)) & 0xff;
1771
1772
24.5M
                pred_TL[0] = pred_T[0];
1773
24.5M
                pred_TL[1] = pred_T[1];
1774
24.5M
                pred_TL[2] = pred_T[2];
1775
24.5M
            }
1776
1.00M
        }
1777
1.02M
        dst += p->linesize[0];
1778
1.02M
    }
1779
3.25k
}
1780
1781
static av_cold int build_vlc(VLC *vlc, const SheerTable *table)
1782
34.3k
{
1783
34.3k
    const uint8_t *cur = table->lens;
1784
34.3k
    uint8_t  lens[1024];
1785
34.3k
    unsigned count = 0;
1786
1787
1.10M
    for (int step = 1, len = 1; len > 0; len += step) {
1788
1.06M
        unsigned new_count = count;
1789
1790
1.06M
        if (len == 16) {
1791
34.3k
            new_count += table->nb_16s;
1792
34.3k
            step       = -1;
1793
34.3k
        } else
1794
1.03M
            new_count += *cur++;
1795
1796
22.1M
        for (; count < new_count; count++)
1797
21.0M
            lens[count]  = len;
1798
1.06M
    }
1799
1800
34.3k
    ff_vlc_free(vlc);
1801
34.3k
    return ff_vlc_init_from_lengths(vlc, SHEER_VLC_BITS, count,
1802
34.3k
                                    lens, sizeof(*lens), NULL, 0, 0, 0, 0, NULL);
1803
34.3k
}
1804
1805
static int decode_frame(AVCodecContext *avctx, AVFrame *p,
1806
                        int *got_frame, AVPacket *avpkt)
1807
235k
{
1808
235k
    SheerVideoContext *s = avctx->priv_data;
1809
235k
    const SheerTable *table;
1810
235k
    GetBitContext gb;
1811
235k
    unsigned format;
1812
235k
    int ret;
1813
1814
235k
    if (avpkt->size <= 20)
1815
52.9k
        return AVERROR_INVALIDDATA;
1816
1817
182k
    if (AV_RL32(avpkt->data) != MKTAG('S','h','i','r') &&
1818
180k
        AV_RL32(avpkt->data) != MKTAG('Z','w','a','k'))
1819
23.1k
        return AVERROR_INVALIDDATA;
1820
1821
159k
    s->alt = 0;
1822
159k
    format = AV_RL32(avpkt->data + 16);
1823
159k
    av_log(avctx, AV_LOG_DEBUG, "format: %s\n", av_fourcc2str(format));
1824
159k
    switch (format) {
1825
3.88k
    case MKTAG(' ', 'R', 'G', 'B'):
1826
3.88k
        avctx->pix_fmt = AV_PIX_FMT_RGB0;
1827
3.88k
        s->decode_frame = decode_rgb;
1828
3.88k
        table           = rgb;
1829
3.88k
        break;
1830
3.49k
    case MKTAG(' ', 'r', 'G', 'B'):
1831
3.49k
        avctx->pix_fmt = AV_PIX_FMT_RGB0;
1832
3.49k
        s->decode_frame = decode_rgbi;
1833
3.49k
        table           = rgbi;
1834
3.49k
        break;
1835
4.47k
    case MKTAG('A', 'R', 'G', 'X'):
1836
4.47k
        avctx->pix_fmt = AV_PIX_FMT_GBRAP10;
1837
4.47k
        s->decode_frame = decode_argx;
1838
4.47k
        table           = rgbx;
1839
4.47k
        break;
1840
2.59k
    case MKTAG('A', 'r', 'G', 'X'):
1841
2.59k
        avctx->pix_fmt = AV_PIX_FMT_GBRAP10;
1842
2.59k
        s->decode_frame = decode_argxi;
1843
2.59k
        table           = rgbxi;
1844
2.59k
        break;
1845
3.99k
    case MKTAG('R', 'G', 'B', 'X'):
1846
3.99k
        avctx->pix_fmt = AV_PIX_FMT_GBRP10;
1847
3.99k
        s->decode_frame = decode_rgbx;
1848
3.99k
        table           = rgbx;
1849
3.99k
        break;
1850
1.62k
    case MKTAG('r', 'G', 'B', 'X'):
1851
1.62k
        avctx->pix_fmt = AV_PIX_FMT_GBRP10;
1852
1.62k
        s->decode_frame = decode_rgbxi;
1853
1.62k
        table           = rgbxi;
1854
1.62k
        break;
1855
24.6k
    case MKTAG('A', 'R', 'G', 'B'):
1856
24.6k
        avctx->pix_fmt = AV_PIX_FMT_ARGB;
1857
24.6k
        s->decode_frame = decode_argb;
1858
24.6k
        table           = rgb;
1859
24.6k
        break;
1860
4.13k
    case MKTAG('A', 'r', 'G', 'B'):
1861
4.13k
        avctx->pix_fmt = AV_PIX_FMT_ARGB;
1862
4.13k
        s->decode_frame = decode_argbi;
1863
4.13k
        table           = rgbi;
1864
4.13k
        break;
1865
1.16k
    case MKTAG('A', 'Y', 'B', 'R'):
1866
1.16k
        s->alt = 1;
1867
1.16k
        av_fallthrough;
1868
6.48k
    case MKTAG('A', 'Y', 'b', 'R'):
1869
6.48k
        avctx->pix_fmt = AV_PIX_FMT_YUVA444P;
1870
6.48k
        s->decode_frame = decode_aybr;
1871
6.48k
        table           = ybr;
1872
6.48k
        break;
1873
2.58k
    case MKTAG('A', 'y', 'B', 'R'):
1874
2.58k
        s->alt = 1;
1875
2.58k
        av_fallthrough;
1876
4.06k
    case MKTAG('A', 'y', 'b', 'R'):
1877
4.06k
        avctx->pix_fmt = AV_PIX_FMT_YUVA444P;
1878
4.06k
        s->decode_frame = decode_aybri;
1879
4.06k
        table           = ybri;
1880
4.06k
        break;
1881
1.85k
    case MKTAG(' ', 'Y', 'B', 'R'):
1882
1.85k
        s->alt = 1;
1883
1.85k
        av_fallthrough;
1884
3.43k
    case MKTAG(' ', 'Y', 'b', 'R'):
1885
3.43k
        avctx->pix_fmt = AV_PIX_FMT_YUV444P;
1886
3.43k
        s->decode_frame = decode_ybr;
1887
3.43k
        table           = ybr;
1888
3.43k
        break;
1889
2.48k
    case MKTAG(' ', 'y', 'B', 'R'):
1890
2.48k
        s->alt = 1;
1891
2.48k
        av_fallthrough;
1892
4.30k
    case MKTAG(' ', 'y', 'b', 'R'):
1893
4.30k
        avctx->pix_fmt = AV_PIX_FMT_YUV444P;
1894
4.30k
        s->decode_frame = decode_ybri;
1895
4.30k
        table           = ybri;
1896
4.30k
        break;
1897
3.62k
    case MKTAG('Y', 'B', 'R', 0x0a):
1898
3.62k
        avctx->pix_fmt = AV_PIX_FMT_YUV444P10;
1899
3.62k
        s->decode_frame = decode_ybr10;
1900
3.62k
        table           = ybr10;
1901
3.62k
        break;
1902
2.30k
    case MKTAG('y', 'B', 'R', 0x0a):
1903
2.30k
        avctx->pix_fmt = AV_PIX_FMT_YUV444P10;
1904
2.30k
        s->decode_frame = decode_ybr10i;
1905
2.30k
        table           = ybr10i;
1906
2.30k
        break;
1907
6.57k
    case MKTAG('C', 'A', '4', 'p'):
1908
6.57k
        avctx->pix_fmt = AV_PIX_FMT_YUVA444P10;
1909
6.57k
        s->decode_frame = decode_ca4p;
1910
6.57k
        table           = ybr10;
1911
6.57k
        break;
1912
2.81k
    case MKTAG('C', 'A', '4', 'i'):
1913
2.81k
        avctx->pix_fmt = AV_PIX_FMT_YUVA444P10;
1914
2.81k
        s->decode_frame = decode_ca4i;
1915
2.81k
        table           = ybr10i;
1916
2.81k
        break;
1917
4.59k
    case MKTAG('B', 'Y', 'R', 'Y'):
1918
4.59k
        avctx->pix_fmt = AV_PIX_FMT_YUV422P;
1919
4.59k
        s->decode_frame = decode_byry;
1920
4.59k
        table           = byry;
1921
4.59k
        break;
1922
4.35k
    case MKTAG('B', 'Y', 'R', 'y'):
1923
4.35k
        avctx->pix_fmt = AV_PIX_FMT_YUV422P;
1924
4.35k
        s->decode_frame = decode_byryi;
1925
4.35k
        table           = byryi;
1926
4.35k
        break;
1927
6.76k
    case MKTAG('Y', 'b', 'Y', 'r'):
1928
6.76k
        avctx->pix_fmt = AV_PIX_FMT_YUV422P;
1929
6.76k
        s->decode_frame = decode_ybyr;
1930
6.76k
        table           = ybyr;
1931
6.76k
        break;
1932
5.23k
    case MKTAG('C', '8', '2', 'p'):
1933
5.23k
        avctx->pix_fmt = AV_PIX_FMT_YUVA422P;
1934
5.23k
        s->decode_frame = decode_c82p;
1935
5.23k
        table           = byry;
1936
5.23k
        break;
1937
3.33k
    case MKTAG('C', '8', '2', 'i'):
1938
3.33k
        avctx->pix_fmt = AV_PIX_FMT_YUVA422P;
1939
3.33k
        s->decode_frame = decode_c82i;
1940
3.33k
        table           = byryi;
1941
3.33k
        break;
1942
4.97k
    case MKTAG(0xa2, 'Y', 'R', 'Y'):
1943
4.97k
        avctx->pix_fmt = AV_PIX_FMT_YUV422P10;
1944
4.97k
        s->decode_frame = decode_yry10;
1945
4.97k
        table           = yry10;
1946
4.97k
        break;
1947
9.01k
    case MKTAG(0xa2, 'Y', 'R', 'y'):
1948
9.01k
        avctx->pix_fmt = AV_PIX_FMT_YUV422P10;
1949
9.01k
        s->decode_frame = decode_yry10i;
1950
9.01k
        table           = yry10i;
1951
9.01k
        break;
1952
7.08k
    case MKTAG('C', 'A', '2', 'p'):
1953
7.08k
        avctx->pix_fmt = AV_PIX_FMT_YUVA422P10;
1954
7.08k
        s->decode_frame = decode_ca2p;
1955
7.08k
        table           = yry10;
1956
7.08k
        break;
1957
3.05k
    case MKTAG('C', 'A', '2', 'i'):
1958
3.05k
        avctx->pix_fmt = AV_PIX_FMT_YUVA422P10;
1959
3.05k
        s->decode_frame = decode_ca2i;
1960
3.05k
        table           = yry10i;
1961
3.05k
        break;
1962
28.7k
    default:
1963
28.7k
        avpriv_request_sample(avctx, "unsupported format: 0x%X", format);
1964
28.7k
        return AVERROR_PATCHWELCOME;
1965
159k
    }
1966
1967
130k
    if (s->format != format) {
1968
17.1k
        if ((ret = build_vlc(&s->vlc[0], &table[0])) < 0 ||
1969
17.1k
            (ret = build_vlc(&s->vlc[1], &table[1])) < 0) {
1970
0
            s->format = 0;
1971
0
            return ret;
1972
0
        }
1973
17.1k
        s->format = format;
1974
17.1k
    }
1975
130k
    if (avpkt->size < 20 + avctx->width * avctx->height / 16) {
1976
19.9k
        av_log(avctx, AV_LOG_ERROR, "Input packet too small\n");
1977
19.9k
        return AVERROR_INVALIDDATA;
1978
19.9k
    }
1979
1980
110k
    if ((ret = ff_thread_get_buffer(avctx, p, 0)) < 0)
1981
8.11k
        return ret;
1982
1983
102k
    if ((ret = init_get_bits8(&gb, avpkt->data + 20, avpkt->size - 20)) < 0)
1984
0
        return ret;
1985
1986
102k
    s->decode_frame(avctx, p, &gb);
1987
1988
102k
    *got_frame = 1;
1989
1990
102k
    return avpkt->size;
1991
102k
}
1992
1993
static av_cold int decode_end(AVCodecContext *avctx)
1994
6.61k
{
1995
6.61k
    SheerVideoContext *s = avctx->priv_data;
1996
1997
6.61k
    ff_vlc_free(&s->vlc[0]);
1998
6.61k
    ff_vlc_free(&s->vlc[1]);
1999
2000
6.61k
    return 0;
2001
6.61k
}
2002
2003
const FFCodec ff_sheervideo_decoder = {
2004
    .p.name           = "sheervideo",
2005
    CODEC_LONG_NAME("BitJazz SheerVideo"),
2006
    .p.type           = AVMEDIA_TYPE_VIDEO,
2007
    .p.id             = AV_CODEC_ID_SHEERVIDEO,
2008
    .p.capabilities   = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS,
2009
    .priv_data_size   = sizeof(SheerVideoContext),
2010
    .close            = decode_end,
2011
    FF_CODEC_DECODE_CB(decode_frame),
2012
};