Browse code

avcodec: add BitJazz SheerVideo decoder

Signed-off-by: Paul B Mahol <onemda@gmail.com>

Paul B Mahol authored on 2016/05/31 02:33:31
Showing 9 changed files
... ...
@@ -39,6 +39,7 @@ version <next>:
39 39
 - MTAF demuxer and decoder
40 40
 - MagicYUV decoder
41 41
 - OpenExr improvements (tile data and B44/B44A support)
42
+- BitJazz SheerVideo decoder
42 43
 
43 44
 version 3.0:
44 45
 - Common Encryption (CENC) MP4 encoding and decoding support
... ...
@@ -644,6 +644,7 @@ following image formats are supported:
644 644
 @item Bethesda VID video     @tab     @tab  X
645 645
     @tab Used in some games from Bethesda Softworks.
646 646
 @item Bink Video             @tab     @tab  X
647
+@item BitJazz SheerVideo     @tab     @tab  X
647 648
 @item Bitmap Brothers JV video  @tab   @tab X
648 649
 @item y41p Brooktree uncompressed 4:1:1 12-bit     @tab  X  @tab  X
649 650
 @item Brute Force & Ignorance   @tab   @tab X
... ...
@@ -474,6 +474,7 @@ OBJS-$(CONFIG_SDX2_DPCM_DECODER)       += dpcm.o
474 474
 OBJS-$(CONFIG_SGI_DECODER)             += sgidec.o
475 475
 OBJS-$(CONFIG_SGI_ENCODER)             += sgienc.o rle.o
476 476
 OBJS-$(CONFIG_SGIRLE_DECODER)          += sgirledec.o
477
+OBJS-$(CONFIG_SHEERVIDEO_DECODER)      += sheervideo.o
477 478
 OBJS-$(CONFIG_SHORTEN_DECODER)         += shorten.o
478 479
 OBJS-$(CONFIG_SIPR_DECODER)            += sipr.o acelp_pitch_delay.o \
479 480
                                           celp_math.o acelp_vectors.o \
... ...
@@ -294,6 +294,7 @@ void avcodec_register_all(void)
294 294
     REGISTER_DECODER(SDX2_DPCM,         sdx2_dpcm);
295 295
     REGISTER_ENCDEC (SGI,               sgi);
296 296
     REGISTER_DECODER(SGIRLE,            sgirle);
297
+    REGISTER_DECODER(SHEERVIDEO,        sheervideo);
297 298
     REGISTER_DECODER(SMACKER,           smacker);
298 299
     REGISTER_DECODER(SMC,               smc);
299 300
     REGISTER_DECODER(SMVJPEG,           smvjpeg);
... ...
@@ -407,6 +407,7 @@ enum AVCodecID {
407 407
     AV_CODEC_ID_TRUEMOTION2RT,
408 408
     AV_CODEC_ID_M101,
409 409
     AV_CODEC_ID_MAGICYUV,
410
+    AV_CODEC_ID_SHEERVIDEO,
410 411
 
411 412
     /* various PCM "codecs" */
412 413
     AV_CODEC_ID_FIRST_AUDIO = 0x10000,     ///< A dummy id pointing at the start of audio codecs
... ...
@@ -1549,6 +1549,13 @@ static const AVCodecDescriptor codec_descriptors[] = {
1549 1549
         .long_name = NULL_IF_CONFIG_SMALL("MagicYUV Lossless Video"),
1550 1550
         .props     = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSLESS,
1551 1551
     },
1552
+    {
1553
+        .id        = AV_CODEC_ID_SHEERVIDEO,
1554
+        .type      = AVMEDIA_TYPE_VIDEO,
1555
+        .name      = "sheervideo",
1556
+        .long_name = NULL_IF_CONFIG_SMALL("BitJazz SheerVideo"),
1557
+        .props     = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSLESS,
1558
+    },
1552 1559
 
1553 1560
     /* various PCM "codecs" */
1554 1561
     {
1555 1562
new file mode 100644
... ...
@@ -0,0 +1,1882 @@
0
+/*
1
+ * BitJazz SheerVideo decoder
2
+ * Copyright (c) 2016 Paul B Mahol
3
+ *
4
+ * This file is part of FFmpeg.
5
+ *
6
+ * FFmpeg is free software; you can redistribute it and/or
7
+ * modify it under the terms of the GNU Lesser General Public
8
+ * License as published by the Free Software Foundation; either
9
+ * version 2.1 of the License, or (at your option) any later version.
10
+ *
11
+ * FFmpeg is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
+ * Lesser General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU Lesser General Public
17
+ * License along with FFmpeg; if not, write to the Free Software
18
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
+ */
20
+
21
+#include <stdio.h>
22
+#include <stdlib.h>
23
+#include <string.h>
24
+
25
+#include "libavutil/intreadwrite.h"
26
+#include "avcodec.h"
27
+#include "get_bits.h"
28
+#include "internal.h"
29
+#include "thread.h"
30
+
31
+typedef struct SheerVideoContext {
32
+    unsigned format;
33
+    VLC vlc[2];
34
+    void (*decode_frame)(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb);
35
+} SheerVideoContext;
36
+
37
+static const uint8_t l_r_rgb[256] = {
38
+     3,  3,  4,  4,  5,  5,  5,  6,  6,  6,  7,  7,  7,  7,  7,  8,
39
+     8,  8,  8,  8,  9,  9,  9,  9,  9,  9,  9,  9, 10, 10, 10, 10,
40
+    10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12,
41
+    12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13,
42
+    13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
43
+    14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
44
+    15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
45
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
46
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
47
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 15, 15, 15,
48
+    15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 14, 14, 14,
49
+    14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 13, 13, 13,
50
+    13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 12, 12, 12, 12, 12, 12,
51
+    12, 12, 12, 12, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 10, 10,
52
+    10, 10, 10, 10, 10, 10,  9,  9,  9,  9,  9,  9,  9,  8,  8,  8,
53
+     8,  8,  8,  7,  7,  7,  7,  7,  6,  6,  6,  5,  5,  4,  4,  4,
54
+};
55
+
56
+static const uint8_t l_g_rgb[256] = {
57
+     2,  2,  4,  4,  6,  7,  9,  9, 10, 11, 11, 11, 12, 12, 12, 13,
58
+    13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15,
59
+    15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16,
60
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
61
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
62
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
63
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
64
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
65
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
66
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
67
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
68
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
69
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
70
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 15, 15, 15, 15,
71
+    15, 15, 15, 15, 15, 15, 14, 14, 14, 14, 14, 14, 14, 14, 13, 13,
72
+    13, 13, 12, 12, 12, 11, 11, 11, 10,  9,  9,  8,  6,  4,  3,  3,
73
+};
74
+
75
+static const uint8_t l_y_ybr[256] = {
76
+     3,  3,  4,  4,  5,  5,  6,  6,  6,  7,  7,  7,  7,  7,  8,  8,
77
+     8,  8,  8,  9,  9,  9,  9,  9,  9,  9, 10, 10, 10, 10, 10, 10,
78
+    10, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12,
79
+    12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14,
80
+    14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15,
81
+    15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16,
82
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
83
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
84
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
85
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
86
+    16, 16, 16, 16, 16, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
87
+    15, 15, 15, 15, 15, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
88
+    14, 14, 14, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 12,
89
+    12, 12, 12, 12, 12, 12, 12, 12, 11, 11, 11, 11, 11, 11, 11, 11,
90
+    11, 10, 10, 10, 10, 10, 10, 10,  9,  9,  9,  9,  9,  9,  8,  8,
91
+     8,  8,  8,  8,  7,  7,  7,  7,  6,  6,  6,  6,  5,  4,  4,  3,
92
+};
93
+
94
+static const uint8_t l_u_ybr[256] = {
95
+     1,  2,  4,  6,  9, 10, 11, 11, 12, 12, 13, 13, 13, 14, 14, 14,
96
+    14, 14, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16,
97
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
98
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
99
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
100
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
101
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
102
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
103
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
104
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
105
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
106
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
107
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
108
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
109
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 15, 15, 15, 15,
110
+    14, 14, 14, 14, 14, 13, 13, 13, 12, 12, 11, 11, 10,  8,  5,  3,
111
+};
112
+
113
+static const uint8_t l_y_ybyr[256] = {
114
+     3,  3,  4,  4,  5,  5,  5,  6,  6,  6,  7,  7,  7,  7,  7,  8,
115
+     8,  8,  8,  8,  9,  9,  9,  9,  9,  9,  9,  9, 10, 10, 10, 10,
116
+    10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12,
117
+    12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13,
118
+    13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
119
+    14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
120
+    15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16,
121
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
122
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
123
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 15, 15,
124
+    15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 14,
125
+    14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 13, 13,
126
+    13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 12, 12, 12, 12, 12, 12,
127
+    12, 12, 12, 12, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 10, 10,
128
+    10, 10, 10, 10, 10, 10,  9,  9,  9,  9,  9,  9,  9,  8,  8,  8,
129
+     8,  8,  8,  7,  7,  7,  7,  7,  6,  6,  6,  5,  5,  4,  4,  4,
130
+};
131
+
132
+static const uint8_t l_u_ybyr[256] = {
133
+     1,  2,  4,  6,  8,  9, 10, 10, 11, 11, 12, 12, 12, 13, 13, 14,
134
+    14, 14, 14, 14, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16,
135
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
136
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
137
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
138
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
139
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
140
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
141
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
142
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
143
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
144
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
145
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
146
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
147
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 15, 15, 15, 15, 14, 14,
148
+    14, 14, 13, 13, 13, 12, 12, 11, 11, 10, 10,  9,  8,  7,  6,  3,
149
+};
150
+
151
+static const uint8_t l_y_byry[256] = {
152
+     3,  3,  4,  4,  5,  5,  6,  6,  6,  7,  7,  7,  7,  7,  8,  8,
153
+     8,  8,  8,  9,  9,  9,  9,  9,  9,  9, 10, 10, 10, 10, 10, 10,
154
+    10, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12,
155
+    12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14,
156
+    14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15,
157
+    15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16,
158
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
159
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
160
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
161
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
162
+    16, 16, 16, 16, 16, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
163
+    15, 15, 15, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
164
+    14, 14, 14, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 12,
165
+    12, 12, 12, 12, 12, 12, 12, 12, 12, 11, 11, 11, 11, 11, 11, 11,
166
+    11, 10, 10, 10, 10, 10, 10, 10,  9,  9,  9,  9,  9,  9,  8,  8,
167
+     8,  8,  8,  8,  7,  7,  7,  7,  6,  6,  6,  6,  5,  4,  4,  3,
168
+};
169
+
170
+static const uint8_t l_u_byry[256] = {
171
+     1,  2,  4,  6,  8,  9,  9, 10, 11, 11, 12, 12, 13, 13, 13, 14,
172
+    14, 14, 14, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16,
173
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
174
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
175
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
176
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
177
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
178
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
179
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
180
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
181
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
182
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
183
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
184
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
185
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 15, 15, 15, 15, 15, 14,
186
+    14, 14, 14, 13, 13, 12, 12, 12, 11, 11, 10,  9,  8,  7,  6,  3,
187
+};
188
+
189
+static const uint8_t l_y_ybr10[1024] = {
190
+     4,  5,  5,  5,  5,  5,  5,  6,  6,  6,  6,  6,  6,  7,  7,  7,
191
+     7,  7,  7,  7,  7,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,
192
+     8,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,
193
+     9,  9,  9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
194
+    10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11,
195
+    11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
196
+    11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
197
+    12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
198
+    13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
199
+    13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
200
+    13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
201
+    14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
202
+    14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
203
+    14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
204
+    15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
205
+    15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
206
+    15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
207
+    15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16,
208
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
209
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
210
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
211
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
212
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
213
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
214
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
215
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
216
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
217
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
218
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
219
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
220
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
221
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
222
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
223
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
224
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
225
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
226
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
227
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
228
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
229
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
230
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
231
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
232
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
233
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
234
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
235
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
236
+    16, 16, 16, 16, 16, 16, 16, 16, 15, 15, 15, 15, 15, 15, 15, 15,
237
+    15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
238
+    15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
239
+    15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
240
+    15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
241
+    14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
242
+    14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
243
+    14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 13, 13,
244
+    13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
245
+    13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
246
+    13, 13, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
247
+    12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 11,
248
+    11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
249
+    11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 10, 10, 10, 10, 10, 10,
250
+    10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,  9,
251
+     9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,
252
+     8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  7,  7,  7,
253
+     7,  7,  7,  7,  6,  6,  6,  6,  6,  6,  6,  5,  5,  5,  5,  5,
254
+};
255
+
256
+static const uint8_t l_u_ybr10[1024] = {
257
+     2,  3,  3,  4,  5,  5,  6,  7,  8,  9,  9, 10, 10, 10, 11, 11,
258
+    12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14,
259
+    14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
260
+    15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16,
261
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
262
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
263
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
264
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
265
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
266
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
267
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
268
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
269
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
270
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
271
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
272
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
273
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
274
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
275
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
276
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
277
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
278
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
279
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
280
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
281
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
282
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
283
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
284
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
285
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
286
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
287
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
288
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
289
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
290
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
291
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
292
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
293
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
294
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
295
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
296
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
297
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
298
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
299
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
300
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
301
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
302
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
303
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
304
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
305
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
306
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
307
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
308
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
309
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
310
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
311
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
312
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
313
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
314
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
315
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
316
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
317
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 15, 15, 15, 15, 15, 15,
318
+    15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 14, 14, 14,
319
+    14, 14, 14, 14, 14, 14, 14, 13, 13, 13, 13, 13, 13, 12, 12, 12,
320
+    12, 11, 11, 11, 10, 10,  9,  9,  8,  8,  7,  6,  5,  4,  4,  3,
321
+};
322
+
323
+static const uint8_t l_r_rgbx[1024] = {
324
+     4,  5,  5,  5,  6,  6,  6,  6,  6,  6,  6,  6,  6,  7,  7,  7,
325
+     7,  7,  7,  7,  7,  7,  7,  8,  8,  8,  8,  8,  8,  8,  8,  8,
326
+     8,  8,  8,  8,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,
327
+     9,  9,  9,  9,  9,  9,  9, 10, 10, 10, 10, 10, 10, 10, 10, 10,
328
+    10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
329
+    10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
330
+    11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12,
331
+    12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
332
+    12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
333
+    13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
334
+    13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
335
+    13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14,
336
+    14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
337
+    14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
338
+    14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15,
339
+    15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
340
+    15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
341
+    15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
342
+    15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
343
+    15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16,
344
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
345
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
346
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
347
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
348
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
349
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
350
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
351
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
352
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
353
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
354
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
355
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
356
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
357
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
358
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
359
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
360
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
361
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
362
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
363
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
364
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
365
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
366
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
367
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
368
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 15, 15, 15, 15, 15,
369
+    15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
370
+    15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
371
+    15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
372
+    15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
373
+    15, 15, 15, 15, 15, 15, 15, 14, 14, 14, 14, 14, 14, 14, 14, 14,
374
+    14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
375
+    14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
376
+    14, 14, 14, 14, 14, 14, 14, 14, 14, 13, 13, 13, 13, 13, 13, 13,
377
+    13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
378
+    13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
379
+    13, 13, 13, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
380
+    12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
381
+    12, 12, 12, 12, 12, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
382
+    11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
383
+    11, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
384
+    10, 10, 10, 10, 10, 10, 10, 10, 10, 10,  9,  9,  9,  9,  9,  9,
385
+     9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  8,  8,  8,
386
+     8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  7,  7,  7,  7,  7,  7,
387
+     7,  7,  7,  7,  6,  6,  6,  6,  6,  6,  6,  6,  5,  5,  5,  5,
388
+};
389
+
390
+static const uint8_t l_g_rgbx[1024] = {
391
+     3,  4,  4,  5,  5,  5,  5,  5,  5,  6,  6,  6,  6,  7,  7,  7,
392
+     8,  8,  9,  9,  9, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 12,
393
+    12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13,
394
+    13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
395
+    14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
396
+    15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
397
+    15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16,
398
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
399
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
400
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
401
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
402
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
403
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
404
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
405
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
406
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
407
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
408
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
409
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
410
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
411
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
412
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
413
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
414
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
415
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
416
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
417
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
418
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
419
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
420
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
421
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
422
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
423
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
424
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
425
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
426
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
427
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
428
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
429
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
430
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
431
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
432
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
433
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
434
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
435
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
436
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
437
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
438
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
439
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
440
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
441
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
442
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
443
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
444
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
445
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
446
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
447
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
448
+    16, 16, 16, 16, 16, 16, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
449
+    15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
450
+    15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 14, 14, 14,
451
+    14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 13,
452
+    13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 12, 12, 12, 12, 12, 12,
453
+    12, 12, 11, 11, 11, 11, 11, 11, 10, 10, 10, 10,  9,  9,  9,  9,
454
+     8,  7,  7,  7,  6,  6,  6,  6,  6,  5,  5,  5,  5,  4,  4,  4,
455
+};
456
+
457
+static const uint8_t l_y_yry10[1024] = {
458
+     4,  5,  5,  5,  5,  5,  5,  6,  6,  6,  6,  6,  6,  7,  7,  7,
459
+     7,  7,  7,  7,  7,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,
460
+     8,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,
461
+     9,  9,  9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
462
+    10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11,
463
+    11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
464
+    11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
465
+    12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
466
+    13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
467
+    13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
468
+    13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
469
+    14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
470
+    14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
471
+    14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
472
+    15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
473
+    15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
474
+    15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
475
+    15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16,
476
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
477
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
478
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
479
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
480
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
481
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
482
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
483
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
484
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
485
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
486
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
487
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
488
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
489
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
490
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
491
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
492
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
493
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
494
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
495
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
496
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
497
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
498
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
499
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
500
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
501
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
502
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
503
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
504
+    16, 16, 16, 16, 16, 16, 16, 16, 15, 15, 15, 15, 15, 15, 15, 15,
505
+    15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
506
+    15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
507
+    15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
508
+    15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
509
+    14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
510
+    14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
511
+    14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 13, 13,
512
+    13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
513
+    13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
514
+    13, 13, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
515
+    12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 11,
516
+    11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
517
+    11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 10, 10, 10, 10, 10, 10,
518
+    10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,  9,
519
+     9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,
520
+     8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  7,  7,  7,
521
+     7,  7,  7,  7,  6,  6,  6,  6,  6,  6,  6,  5,  5,  5,  5,  5,
522
+};
523
+
524
+static const uint8_t l_u_yry10[1024] = {
525
+     2,  3,  3,  4,  5,  6,  7,  7,  8,  8,  8,  9,  9, 10, 10, 10,
526
+    10, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13,
527
+    13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
528
+    14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
529
+    15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
530
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
531
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
532
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
533
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
534
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
535
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
536
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
537
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
538
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
539
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
540
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
541
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
542
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
543
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
544
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
545
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
546
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
547
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
548
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
549
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
550
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
551
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
552
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
553
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
554
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
555
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
556
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
557
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
558
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
559
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
560
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
561
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
562
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
563
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
564
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
565
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
566
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
567
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
568
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
569
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
570
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
571
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
572
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
573
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
574
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
575
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
576
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
577
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
578
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
579
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
580
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
581
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
582
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
583
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
584
+    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
585
+    16, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
586
+    15, 15, 15, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 13, 13,
587
+    13, 13, 13, 13, 13, 12, 12, 12, 12, 12, 12, 12, 11, 11, 11, 11,
588
+    10, 10, 10, 10,  9,  9,  9,  8,  8,  7,  7,  6,  5,  4,  4,  3,
589
+};
590
+
591
+static void decode_ca4p(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
592
+{
593
+    SheerVideoContext *s = avctx->priv_data;
594
+    uint16_t *dst_y, *dst_u, *dst_v, *dst_a;
595
+    int x, y;
596
+
597
+    dst_a = (uint16_t *)p->data[3];
598
+    dst_y = (uint16_t *)p->data[0];
599
+    dst_u = (uint16_t *)p->data[1];
600
+    dst_v = (uint16_t *)p->data[2];
601
+
602
+    if (get_bits1(gb)) {
603
+        for (x = 0; x < avctx->width; x++) {
604
+            dst_a[x] = get_bits(gb, 10);
605
+            dst_y[x] = get_bits(gb, 10);
606
+            dst_u[x] = get_bits(gb, 10);
607
+            dst_v[x] = get_bits(gb, 10);
608
+        }
609
+    } else {
610
+        int pred[4] = { 502, 512, 512, 502 };
611
+
612
+        for (x = 0; x < avctx->width; x++) {
613
+            int y, u, v, a;
614
+
615
+            a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
616
+            y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
617
+            u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
618
+            v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
619
+
620
+            dst_a[x] = pred[3] = (a + pred[3]) & 0x3ff;
621
+            dst_y[x] = pred[0] = (y + pred[0]) & 0x3ff;
622
+            dst_u[x] = pred[1] = (u + pred[1]) & 0x3ff;
623
+            dst_v[x] = pred[2] = (v + pred[2]) & 0x3ff;
624
+        }
625
+    }
626
+
627
+    dst_y += p->linesize[0] / 2;
628
+    dst_u += p->linesize[1] / 2;
629
+    dst_v += p->linesize[2] / 2;
630
+    dst_a += p->linesize[3] / 2;
631
+
632
+    for (y = 1; y < avctx->height; y++) {
633
+        if (get_bits1(gb)) {
634
+            for (x = 0; x < avctx->width; x++) {
635
+                dst_a[x] = get_bits(gb, 10);
636
+                dst_y[x] = get_bits(gb, 10);
637
+                dst_u[x] = get_bits(gb, 10);
638
+                dst_v[x] = get_bits(gb, 10);
639
+            }
640
+        } else {
641
+            int pred_TL[4], pred_L[4], pred_T[4];
642
+            int y, u, v, a;
643
+
644
+            pred_TL[0] = pred_L[0] = dst_y[-p->linesize[0] / 2];
645
+            pred_TL[1] = pred_L[1] = dst_u[-p->linesize[1] / 2];
646
+            pred_TL[2] = pred_L[2] = dst_v[-p->linesize[2] / 2];
647
+            pred_TL[3] = pred_L[3] = dst_a[-p->linesize[3] / 2];
648
+
649
+            for (x = 0; x < avctx->width; x++) {
650
+                pred_T[0] = dst_y[-p->linesize[0] / 2 + x];
651
+                pred_T[1] = dst_u[-p->linesize[1] / 2 + x];
652
+                pred_T[2] = dst_v[-p->linesize[2] / 2 + x];
653
+                pred_T[3] = dst_a[-p->linesize[3] / 2 + x];
654
+
655
+                a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
656
+                y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
657
+                u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
658
+                v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
659
+
660
+                dst_a[x] = pred_L[3] = (a + ((3 * (pred_T[3] + pred_L[3]) - 2 * pred_TL[3]) >> 2)) & 0x3ff;
661
+                dst_y[x] = pred_L[0] = (y + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0x3ff;
662
+                dst_u[x] = pred_L[1] = (u + ((3 * (pred_T[1] + pred_L[1]) - 2 * pred_TL[1]) >> 2)) & 0x3ff;
663
+                dst_v[x] = pred_L[2] = (v + ((3 * (pred_T[2] + pred_L[2]) - 2 * pred_TL[2]) >> 2)) & 0x3ff;
664
+
665
+                pred_TL[0] = pred_T[0];
666
+                pred_TL[1] = pred_T[1];
667
+                pred_TL[2] = pred_T[2];
668
+                pred_TL[3] = pred_T[3];
669
+            }
670
+        }
671
+
672
+        dst_y += p->linesize[0] / 2;
673
+        dst_u += p->linesize[1] / 2;
674
+        dst_v += p->linesize[2] / 2;
675
+        dst_a += p->linesize[3] / 2;
676
+    }
677
+}
678
+
679
+static void decode_ybr10(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
680
+{
681
+    SheerVideoContext *s = avctx->priv_data;
682
+    uint16_t *dst_y, *dst_u, *dst_v;
683
+    int x, y;
684
+
685
+    dst_y = (uint16_t *)p->data[0];
686
+    dst_u = (uint16_t *)p->data[1];
687
+    dst_v = (uint16_t *)p->data[2];
688
+
689
+    if (get_bits1(gb)) {
690
+        for (x = 0; x < avctx->width; x++) {
691
+            dst_y[x] = get_bits(gb, 10);
692
+            dst_u[x] = get_bits(gb, 10);
693
+            dst_v[x] = get_bits(gb, 10);
694
+        }
695
+    } else {
696
+        int pred[4] = { 502, 512, 512, 512 };
697
+
698
+        for (x = 0; x < avctx->width; x++) {
699
+            int y, u, v;
700
+
701
+            y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
702
+            u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
703
+            v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
704
+
705
+            dst_y[x] = pred[0] = (y + pred[0]) & 0x3ff;
706
+            dst_u[x] = pred[1] = (u + pred[1]) & 0x3ff;
707
+            dst_v[x] = pred[2] = (v + pred[2]) & 0x3ff;
708
+        }
709
+    }
710
+
711
+    dst_y += p->linesize[0] / 2;
712
+    dst_u += p->linesize[1] / 2;
713
+    dst_v += p->linesize[2] / 2;
714
+
715
+    for (y = 1; y < avctx->height; y++) {
716
+        if (get_bits1(gb)) {
717
+            for (x = 0; x < avctx->width; x++) {
718
+                dst_y[x] = get_bits(gb, 10);
719
+                dst_u[x] = get_bits(gb, 10);
720
+                dst_v[x] = get_bits(gb, 10);
721
+            }
722
+        } else {
723
+            int pred_TL[4], pred_L[4], pred_T[4];
724
+            int y, u, v;
725
+
726
+            pred_TL[0] = pred_L[0] = dst_y[-p->linesize[0] / 2];
727
+            pred_TL[1] = pred_L[1] = dst_u[-p->linesize[1] / 2];
728
+            pred_TL[2] = pred_L[2] = dst_v[-p->linesize[2] / 2];
729
+
730
+            for (x = 0; x < avctx->width; x++) {
731
+                pred_T[0] = dst_y[-p->linesize[0] / 2 + x];
732
+                pred_T[1] = dst_u[-p->linesize[1] / 2 + x];
733
+                pred_T[2] = dst_v[-p->linesize[2] / 2 + x];
734
+
735
+                y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
736
+                u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
737
+                v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
738
+
739
+                dst_y[x] = pred_L[0] = (y + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0x3ff;
740
+                dst_u[x] = pred_L[1] = (u + ((3 * (pred_T[1] + pred_L[1]) - 2 * pred_TL[1]) >> 2)) & 0x3ff;
741
+                dst_v[x] = pred_L[2] = (v + ((3 * (pred_T[2] + pred_L[2]) - 2 * pred_TL[2]) >> 2)) & 0x3ff;
742
+
743
+                pred_TL[0] = pred_T[0];
744
+                pred_TL[1] = pred_T[1];
745
+                pred_TL[2] = pred_T[2];
746
+            }
747
+        }
748
+
749
+        dst_y += p->linesize[0] / 2;
750
+        dst_u += p->linesize[1] / 2;
751
+        dst_v += p->linesize[2] / 2;
752
+    }
753
+}
754
+
755
+static void decode_yry10(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
756
+{
757
+    SheerVideoContext *s = avctx->priv_data;
758
+    uint16_t *dst_y, *dst_u, *dst_v;
759
+    int x, y;
760
+
761
+    dst_y = (uint16_t *)p->data[0];
762
+    dst_u = (uint16_t *)p->data[1];
763
+    dst_v = (uint16_t *)p->data[2];
764
+
765
+    if (get_bits1(gb)) {
766
+        for (x = 0; x < avctx->width; x += 2) {
767
+            dst_y[x    ] = get_bits(gb, 10);
768
+            dst_u[x / 2] = get_bits(gb, 10);
769
+            dst_y[x + 1] = get_bits(gb, 10);
770
+            dst_v[x / 2] = get_bits(gb, 10);
771
+        }
772
+    } else {
773
+        int pred[4] = { 502, 512, 512, 0 };
774
+
775
+        for (x = 0; x < avctx->width; x += 2) {
776
+            int y1, y2, u, v;
777
+
778
+            y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
779
+            u  = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
780
+            y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
781
+            v  = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
782
+
783
+            dst_y[x    ] = pred[0] = (y1 + pred[0]) & 0x3ff;
784
+            dst_u[x / 2] = pred[1] = (u  + pred[1]) & 0x3ff;
785
+            dst_y[x + 1] = pred[0] = (y2 + pred[0]) & 0x3ff;
786
+            dst_v[x / 2] = pred[2] = (v  + pred[2]) & 0x3ff;
787
+        }
788
+    }
789
+
790
+    dst_y += p->linesize[0] / 2;
791
+    dst_u += p->linesize[1] / 2;
792
+    dst_v += p->linesize[2] / 2;
793
+
794
+    for (y = 1; y < avctx->height; y++) {
795
+        if (get_bits1(gb)) {
796
+            for (x = 0; x < avctx->width; x += 2) {
797
+                dst_y[x    ] = get_bits(gb, 10);
798
+                dst_u[x / 2] = get_bits(gb, 10);
799
+                dst_y[x + 1] = get_bits(gb, 10);
800
+                dst_v[x / 2] = get_bits(gb, 10);
801
+            }
802
+        } else {
803
+            int pred_TL[6], pred_L[6], pred_T[6];
804
+            int y1, y2, u, v;
805
+
806
+            pred_TL[0] = pred_L[0] = dst_y[-p->linesize[0] / 2];
807
+            pred_TL[1] = pred_L[1] = dst_u[-p->linesize[1] / 2];
808
+            pred_TL[2] = pred_L[2] = dst_v[-p->linesize[2] / 2];
809
+
810
+            for (x = 0; x < avctx->width; x += 2) {
811
+                pred_T[0] = dst_y[-p->linesize[0] / 2 + x];
812
+                pred_T[3] = dst_y[-p->linesize[0] / 2 + x + 1];
813
+                pred_T[1] = dst_u[-p->linesize[1] / 2 + x / 2];
814
+                pred_T[2] = dst_v[-p->linesize[2] / 2 + x / 2];
815
+
816
+                y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
817
+                u  = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
818
+                y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
819
+                v  = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
820
+
821
+                dst_y[x    ] = pred_L[0] = (y1 + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0x3ff;
822
+                dst_u[x / 2] = pred_L[1] = (u + (((pred_L[1] - pred_TL[1]) >> 1) + pred_T[1])) & 0x3ff;
823
+                dst_y[x + 1] = pred_L[0] = (y2 + ((3 * (pred_T[3] + pred_L[0]) - 2 * pred_T[0]) >> 2)) & 0x3ff;
824
+                dst_v[x / 2] = pred_L[2] = (v + (((pred_L[2] - pred_TL[2]) >> 1) + pred_T[2])) & 0x3ff;
825
+
826
+                pred_TL[0] = pred_T[3];
827
+                pred_TL[1] = pred_T[1];
828
+                pred_TL[2] = pred_T[2];
829
+            }
830
+        }
831
+
832
+        dst_y += p->linesize[0] / 2;
833
+        dst_u += p->linesize[1] / 2;
834
+        dst_v += p->linesize[2] / 2;
835
+    }
836
+}
837
+
838
+static void decode_ca2p(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
839
+{
840
+    SheerVideoContext *s = avctx->priv_data;
841
+    uint16_t *dst_y, *dst_u, *dst_v, *dst_a;
842
+    int x, y;
843
+
844
+    dst_y = (uint16_t *)p->data[0];
845
+    dst_u = (uint16_t *)p->data[1];
846
+    dst_v = (uint16_t *)p->data[2];
847
+    dst_a = (uint16_t *)p->data[3];
848
+
849
+    if (get_bits1(gb)) {
850
+        for (x = 0; x < avctx->width; x += 2) {
851
+            dst_y[x    ] = get_bits(gb, 10);
852
+            dst_u[x / 2] = get_bits(gb, 10);
853
+            dst_y[x + 1] = get_bits(gb, 10);
854
+            dst_a[x    ] = get_bits(gb, 10);
855
+            dst_v[x / 2] = get_bits(gb, 10);
856
+            dst_a[x + 1] = get_bits(gb, 10);
857
+        }
858
+    } else {
859
+        int pred[4] = { 502, 512, 512, 502 };
860
+
861
+        for (x = 0; x < avctx->width; x += 2) {
862
+            int y1, y2, u, v, a1, a2;
863
+
864
+            a1 = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
865
+            y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
866
+            u  = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
867
+            a2 = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
868
+            y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
869
+            v  = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
870
+
871
+            dst_y[x    ] = pred[0] = (y1 + pred[0]) & 0x3ff;
872
+            dst_u[x / 2] = pred[1] = (u  + pred[1]) & 0x3ff;
873
+            dst_y[x + 1] = pred[0] = (y2 + pred[0]) & 0x3ff;
874
+            dst_a[x    ] = pred[3] = (a1 + pred[3]) & 0x3ff;
875
+            dst_v[x / 2] = pred[2] = (v  + pred[2]) & 0x3ff;
876
+            dst_a[x + 1] = pred[3] = (a2 + pred[3]) & 0x3ff;
877
+        }
878
+    }
879
+
880
+    dst_y += p->linesize[0] / 2;
881
+    dst_u += p->linesize[1] / 2;
882
+    dst_v += p->linesize[2] / 2;
883
+    dst_a += p->linesize[3] / 2;
884
+
885
+    for (y = 1; y < avctx->height; y++) {
886
+        if (get_bits1(gb)) {
887
+            for (x = 0; x < avctx->width; x += 2) {
888
+                dst_y[x    ] = get_bits(gb, 10);
889
+                dst_u[x / 2] = get_bits(gb, 10);
890
+                dst_y[x + 1] = get_bits(gb, 10);
891
+                dst_a[x    ] = get_bits(gb, 10);
892
+                dst_v[x / 2] = get_bits(gb, 10);
893
+                dst_a[x + 1] = get_bits(gb, 10);
894
+            }
895
+        } else {
896
+            int pred_TL[6], pred_L[6], pred_T[6];
897
+            int y1, y2, u, v, a1, a2;
898
+
899
+            pred_TL[0] = pred_L[0] = dst_y[-p->linesize[0] / 2];
900
+            pred_TL[1] = pred_L[1] = dst_u[-p->linesize[1] / 2];
901
+            pred_TL[2] = pred_L[2] = dst_v[-p->linesize[2] / 2];
902
+            pred_TL[4] = pred_L[4] = dst_a[-p->linesize[3] / 2];
903
+
904
+            for (x = 0; x < avctx->width; x += 2) {
905
+                pred_T[0] = dst_y[-p->linesize[0] / 2 + x];
906
+                pred_T[3] = dst_y[-p->linesize[0] / 2 + x + 1];
907
+                pred_T[1] = dst_u[-p->linesize[1] / 2 + x / 2];
908
+                pred_T[2] = dst_v[-p->linesize[2] / 2 + x / 2];
909
+                pred_T[4] = dst_a[-p->linesize[3] / 2 + x];
910
+                pred_T[5] = dst_a[-p->linesize[3] / 2 + x + 1];
911
+
912
+                a1 = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
913
+                y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
914
+                u  = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
915
+                a2 = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
916
+                y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
917
+                v  = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
918
+
919
+                dst_y[x    ] = pred_L[0] = (y1 + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0x3ff;
920
+                dst_u[x / 2] = pred_L[1] = (u + (((pred_L[1] - pred_TL[1]) >> 1) + pred_T[1])) & 0x3ff;
921
+                dst_y[x + 1] = pred_L[0] = (y2 + ((3 * (pred_T[3] + pred_L[0]) - 2 * pred_T[0]) >> 2)) & 0x3ff;
922
+                dst_v[x / 2] = pred_L[2] = (v + (((pred_L[2] - pred_TL[2]) >> 1) + pred_T[2])) & 0x3ff;
923
+                dst_a[x    ] = pred_L[4] = (a1 + ((3 * (pred_T[4] + pred_L[4]) - 2 * pred_TL[4]) >> 2)) & 0x3ff;
924
+                dst_a[x + 1] = pred_L[4] = (a2 + ((3 * (pred_T[5] + pred_L[4]) - 2 * pred_T[4]) >> 2)) & 0x3ff;
925
+
926
+                pred_TL[0] = pred_T[3];
927
+                pred_TL[1] = pred_T[1];
928
+                pred_TL[2] = pred_T[2];
929
+                pred_TL[4] = pred_T[5];
930
+            }
931
+        }
932
+
933
+        dst_y += p->linesize[0] / 2;
934
+        dst_u += p->linesize[1] / 2;
935
+        dst_v += p->linesize[2] / 2;
936
+        dst_a += p->linesize[3] / 2;
937
+    }
938
+}
939
+
940
+static void decode_c82p(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
941
+{
942
+    SheerVideoContext *s = avctx->priv_data;
943
+    uint8_t *dst_y, *dst_u, *dst_v, *dst_a;
944
+    int x, y;
945
+
946
+    dst_y = p->data[0];
947
+    dst_u = p->data[1];
948
+    dst_v = p->data[2];
949
+    dst_a = p->data[3];
950
+
951
+    if (get_bits1(gb)) {
952
+        for (x = 0; x < avctx->width; x += 2) {
953
+            dst_y[x    ] = get_bits(gb, 8);
954
+            dst_u[x / 2] = get_bits(gb, 8);
955
+            dst_y[x + 1] = get_bits(gb, 8);
956
+            dst_a[x    ] = get_bits(gb, 8);
957
+            dst_v[x / 2] = get_bits(gb, 8);
958
+            dst_a[x + 1] = get_bits(gb, 8);
959
+        }
960
+    } else {
961
+        int pred[4] = { -125, 128, 128, 125 };
962
+
963
+        for (x = 0; x < avctx->width; x += 2) {
964
+            int y1, y2, u, v, a1, a2;
965
+
966
+            a1 = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
967
+            y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
968
+            u  = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
969
+            a2 = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
970
+            y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
971
+            v  = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
972
+
973
+            dst_y[x    ] = pred[0] = (y1 + pred[0]) & 0xff;
974
+            dst_u[x / 2] = pred[1] = (u  + pred[1]) & 0xff;
975
+            dst_y[x + 1] = pred[0] = (y2 + pred[0]) & 0xff;
976
+            dst_a[x    ] = pred[3] = (a1 + pred[3]) & 0xff;
977
+            dst_v[x / 2] = pred[2] = (v  + pred[2]) & 0xff;
978
+            dst_a[x + 1] = pred[3] = (a2 + pred[3]) & 0xff;
979
+        }
980
+    }
981
+
982
+    dst_y += p->linesize[0];
983
+    dst_u += p->linesize[1];
984
+    dst_v += p->linesize[2];
985
+    dst_a += p->linesize[3];
986
+
987
+    for (y = 1; y < avctx->height; y++) {
988
+        if (get_bits1(gb)) {
989
+            for (x = 0; x < avctx->width; x += 2) {
990
+                dst_y[x    ] = get_bits(gb, 8);
991
+                dst_u[x / 2] = get_bits(gb, 8);
992
+                dst_y[x + 1] = get_bits(gb, 8);
993
+                dst_a[x    ] = get_bits(gb, 8);
994
+                dst_v[x / 2] = get_bits(gb, 8);
995
+                dst_a[x + 1] = get_bits(gb, 8);
996
+            }
997
+        } else {
998
+            int pred_TL[6], pred_L[6], pred_T[6];
999
+            int y1, y2, u, v, a1, a2;
1000
+
1001
+            pred_TL[0] = pred_L[0] = dst_y[-p->linesize[0]];
1002
+            pred_TL[1] = pred_L[1] = dst_u[-p->linesize[1]];
1003
+            pred_TL[2] = pred_L[2] = dst_v[-p->linesize[2]];
1004
+            pred_TL[4] = pred_L[4] = dst_a[-p->linesize[3]];
1005
+
1006
+            for (x = 0; x < avctx->width; x += 2) {
1007
+                pred_T[0] = dst_y[-p->linesize[0] + x];
1008
+                pred_T[3] = dst_y[-p->linesize[0] + x + 1];
1009
+                pred_T[1] = dst_u[-p->linesize[1] + x / 2];
1010
+                pred_T[2] = dst_v[-p->linesize[2] + x / 2];
1011
+                pred_T[4] = dst_a[-p->linesize[3] + x];
1012
+                pred_T[5] = dst_a[-p->linesize[3] + x + 1];
1013
+
1014
+                a1 = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1015
+                y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1016
+                u  = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1017
+                a2 = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1018
+                y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1019
+                v  = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1020
+
1021
+                dst_y[x    ] = pred_L[0] = (y1 + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0xff;
1022
+                dst_u[x / 2] = pred_L[1] = (u + (((pred_L[1] - pred_TL[1]) >> 1) + pred_T[1])) & 0xff;
1023
+                dst_y[x + 1] = pred_L[0] = (y2 + ((3 * (pred_T[3] + pred_L[0]) - 2 * pred_T[0]) >> 2)) & 0xff;
1024
+                dst_v[x / 2] = pred_L[2] = (v + (((pred_L[2] - pred_TL[2]) >> 1) + pred_T[2])) & 0xff;
1025
+                dst_a[x    ] = pred_L[4] = (a1 + ((3 * (pred_T[4] + pred_L[4]) - 2 * pred_TL[4]) >> 2)) & 0xff;
1026
+                dst_a[x + 1] = pred_L[4] = (a2 + ((3 * (pred_T[5] + pred_L[4]) - 2 * pred_T[4]) >> 2)) & 0xff;
1027
+
1028
+                pred_TL[0] = pred_T[3];
1029
+                pred_TL[1] = pred_T[1];
1030
+                pred_TL[2] = pred_T[2];
1031
+                pred_TL[4] = pred_T[5];
1032
+            }
1033
+        }
1034
+
1035
+        dst_y += p->linesize[0];
1036
+        dst_u += p->linesize[1];
1037
+        dst_v += p->linesize[2];
1038
+        dst_a += p->linesize[3];
1039
+    }
1040
+}
1041
+
1042
+static void decode_ybyr(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
1043
+{
1044
+    SheerVideoContext *s = avctx->priv_data;
1045
+    uint8_t *dst_y, *dst_u, *dst_v;
1046
+    int x, y;
1047
+
1048
+    dst_y = p->data[0];
1049
+    dst_u = p->data[1];
1050
+    dst_v = p->data[2];
1051
+
1052
+    if (get_bits1(gb)) {
1053
+        for (x = 0; x < avctx->width; x += 2) {
1054
+            dst_y[x    ] = get_bits(gb, 8);
1055
+            dst_u[x / 2] = get_bits(gb, 8);
1056
+            dst_y[x + 1] = get_bits(gb, 8);
1057
+            dst_v[x / 2] = get_bits(gb, 8);
1058
+        }
1059
+    } else {
1060
+        int pred[4] = { -125, 128, 128, 0 };
1061
+
1062
+        for (x = 0; x < avctx->width; x += 2) {
1063
+            int y1, y2, u, v;
1064
+
1065
+            y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1066
+            u  = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1067
+            y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1068
+            v  = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1069
+
1070
+            dst_y[x    ] = pred[0] = (y1 + pred[0]) & 0xff;
1071
+            dst_u[x / 2] = pred[1] = (u  + pred[1]) & 0xff;
1072
+            dst_y[x + 1] = pred[0] = (y2 + pred[0]) & 0xff;
1073
+            dst_v[x / 2] = pred[2] = (v  + pred[2]) & 0xff;
1074
+        }
1075
+    }
1076
+
1077
+    dst_y += p->linesize[0];
1078
+    dst_u += p->linesize[1];
1079
+    dst_v += p->linesize[2];
1080
+
1081
+    for (y = 1; y < avctx->height; y++) {
1082
+        if (get_bits1(gb)) {
1083
+            for (x = 0; x < avctx->width; x += 2) {
1084
+                dst_y[x    ] = get_bits(gb, 8);
1085
+                dst_u[x / 2] = get_bits(gb, 8);
1086
+                dst_y[x + 1] = get_bits(gb, 8);
1087
+                dst_v[x / 2] = get_bits(gb, 8);
1088
+            }
1089
+        } else {
1090
+            int pred_TL[4], pred_L[4], pred_T[4];
1091
+            int y1, y2, u, v;
1092
+
1093
+            pred_TL[0] = pred_L[0] = dst_y[-p->linesize[0]];
1094
+            pred_TL[1] = pred_L[1] = dst_u[-p->linesize[1]];
1095
+            pred_TL[2] = pred_L[2] = dst_v[-p->linesize[2]];
1096
+
1097
+            for (x = 0; x < avctx->width; x += 2) {
1098
+                pred_T[0] = dst_y[-p->linesize[0] + x];
1099
+                pred_T[3] = dst_y[-p->linesize[0] + x + 1];
1100
+                pred_T[1] = dst_u[-p->linesize[1] + x / 2];
1101
+                pred_T[2] = dst_v[-p->linesize[2] + x / 2];
1102
+
1103
+                y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1104
+                u  = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1105
+                y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1106
+                v  = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1107
+
1108
+                dst_y[x    ] = pred_L[0] = (y1 + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0xff;
1109
+                dst_u[x / 2] = pred_L[1] = (u + (((pred_L[1] - pred_TL[1]) >> 1) + pred_T[1])) & 0xff;
1110
+                dst_y[x + 1] = pred_L[0] = (y2 + ((3 * (pred_T[3] + pred_L[0]) - 2 * pred_T[0]) >> 2)) & 0xff;
1111
+                dst_v[x / 2] = pred_L[2] = (v + (((pred_L[2] - pred_TL[2]) >> 1) + pred_T[2])) & 0xff;
1112
+
1113
+                pred_TL[0] = pred_T[3];
1114
+                pred_TL[1] = pred_T[1];
1115
+                pred_TL[2] = pred_T[2];
1116
+            }
1117
+        }
1118
+
1119
+        dst_y += p->linesize[0];
1120
+        dst_u += p->linesize[1];
1121
+        dst_v += p->linesize[2];
1122
+    }
1123
+}
1124
+
1125
+static void decode_byry(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
1126
+{
1127
+    SheerVideoContext *s = avctx->priv_data;
1128
+    uint8_t *dst_y, *dst_u, *dst_v;
1129
+    int x, y;
1130
+
1131
+    dst_y = p->data[0];
1132
+    dst_u = p->data[1];
1133
+    dst_v = p->data[2];
1134
+
1135
+    if (get_bits1(gb)) {
1136
+        for (x = 0; x < avctx->width; x += 2) {
1137
+            dst_y[x    ] = get_bits(gb, 8);
1138
+            dst_u[x / 2] = get_bits(gb, 8);
1139
+            dst_y[x + 1] = get_bits(gb, 8);
1140
+            dst_v[x / 2] = get_bits(gb, 8);
1141
+        }
1142
+    } else {
1143
+        int pred[4] = { 125, -128, -128, 0 };
1144
+
1145
+        for (x = 0; x < avctx->width; x += 2) {
1146
+            int y1, y2, u, v;
1147
+
1148
+            y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1149
+            u  = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1150
+            y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1151
+            v  = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1152
+
1153
+            dst_y[x    ] = pred[0] = (y1 + pred[0]) & 0xff;
1154
+            dst_u[x / 2] = pred[1] = (u  + pred[1]) & 0xff;
1155
+            dst_y[x + 1] = pred[0] = (y2 + pred[0]) & 0xff;
1156
+            dst_v[x / 2] = pred[2] = (v  + pred[2]) & 0xff;
1157
+        }
1158
+    }
1159
+
1160
+    dst_y += p->linesize[0];
1161
+    dst_u += p->linesize[1];
1162
+    dst_v += p->linesize[2];
1163
+
1164
+    for (y = 1; y < avctx->height; y++) {
1165
+        if (get_bits1(gb)) {
1166
+            for (x = 0; x < avctx->width; x += 2) {
1167
+                dst_y[x    ] = get_bits(gb, 8);
1168
+                dst_u[x / 2] = get_bits(gb, 8);
1169
+                dst_y[x + 1] = get_bits(gb, 8);
1170
+                dst_v[x / 2] = get_bits(gb, 8);
1171
+            }
1172
+        } else {
1173
+            int pred_TL[4], pred_L[4], pred_T[4];
1174
+            int y1, y2, u, v;
1175
+
1176
+            pred_TL[0] = pred_L[0] = dst_y[-p->linesize[0]];
1177
+            pred_TL[1] = pred_L[1] = dst_u[-p->linesize[1]];
1178
+            pred_TL[2] = pred_L[2] = dst_v[-p->linesize[2]];
1179
+
1180
+            for (x = 0; x < avctx->width; x += 2) {
1181
+                pred_T[0] = dst_y[-p->linesize[0] + x];
1182
+                pred_T[3] = dst_y[-p->linesize[0] + x + 1];
1183
+                pred_T[1] = dst_u[-p->linesize[1] + x / 2];
1184
+                pred_T[2] = dst_v[-p->linesize[2] + x / 2];
1185
+
1186
+                y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1187
+                u  = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1188
+                y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1189
+                v  = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1190
+
1191
+                dst_y[x    ] = pred_L[0] = (y1 + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0xff;
1192
+                dst_u[x / 2] = pred_L[1] = (u + (((pred_L[1] - pred_TL[1]) >> 1) + pred_T[1])) & 0xff;
1193
+                dst_y[x + 1] = pred_L[0] = (y2 + ((3 * (pred_T[3] + pred_L[0]) - 2 * pred_T[0]) >> 2)) & 0xff;
1194
+                dst_v[x / 2] = pred_L[2] = (v + (((pred_L[2] - pred_TL[2]) >> 1) + pred_T[2])) & 0xff;
1195
+
1196
+                pred_TL[0] = pred_T[3];
1197
+                pred_TL[1] = pred_T[1];
1198
+                pred_TL[2] = pred_T[2];
1199
+            }
1200
+        }
1201
+
1202
+        dst_y += p->linesize[0];
1203
+        dst_u += p->linesize[1];
1204
+        dst_v += p->linesize[2];
1205
+    }
1206
+}
1207
+
1208
+static void decode_ybr(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
1209
+{
1210
+    SheerVideoContext *s = avctx->priv_data;
1211
+    uint8_t *dst_y, *dst_u, *dst_v;
1212
+    int x, y;
1213
+
1214
+    dst_y = p->data[0];
1215
+    dst_u = p->data[1];
1216
+    dst_v = p->data[2];
1217
+
1218
+    if (get_bits1(gb)) {
1219
+        for (x = 0; x < avctx->width; x++) {
1220
+            dst_y[x] = get_bits(gb, 8);
1221
+            dst_u[x] = get_bits(gb, 8);
1222
+            dst_v[x] = get_bits(gb, 8);
1223
+        }
1224
+    } else {
1225
+        int pred[4] = { 125, -128, -128, -128 };
1226
+
1227
+        for (x = 0; x < avctx->width; x++) {
1228
+            int y, u, v;
1229
+
1230
+            y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1231
+            u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1232
+            v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1233
+
1234
+            dst_y[x] = pred[0] = (y + pred[0]) & 0xff;
1235
+            dst_u[x] = pred[1] = (u + pred[1]) & 0xff;
1236
+            dst_v[x] = pred[2] = (v + pred[2]) & 0xff;
1237
+        }
1238
+    }
1239
+
1240
+    dst_y += p->linesize[0];
1241
+    dst_u += p->linesize[1];
1242
+    dst_v += p->linesize[2];
1243
+
1244
+    for (y = 1; y < avctx->height; y++) {
1245
+        if (get_bits1(gb)) {
1246
+            for (x = 0; x < avctx->width; x++) {
1247
+                dst_y[x] = get_bits(gb, 8);
1248
+                dst_u[x] = get_bits(gb, 8);
1249
+                dst_v[x] = get_bits(gb, 8);
1250
+            }
1251
+        } else {
1252
+            int pred_TL[4], pred_L[4], pred_T[4];
1253
+            int y, u, v;
1254
+
1255
+            pred_TL[0] = pred_L[0] = dst_y[-p->linesize[0]];
1256
+            pred_TL[1] = pred_L[1] = dst_u[-p->linesize[1]];
1257
+            pred_TL[2] = pred_L[2] = dst_v[-p->linesize[2]];
1258
+
1259
+            for (x = 0; x < avctx->width; x++) {
1260
+                pred_T[0] = dst_y[-p->linesize[0] + x];
1261
+                pred_T[1] = dst_u[-p->linesize[1] + x];
1262
+                pred_T[2] = dst_v[-p->linesize[2] + x];
1263
+
1264
+                y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1265
+                u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1266
+                v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1267
+
1268
+                dst_y[x] = pred_L[0] = (y + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0xff;
1269
+                dst_u[x] = pred_L[1] = (u + ((3 * (pred_T[1] + pred_L[1]) - 2 * pred_TL[1]) >> 2)) & 0xff;
1270
+                dst_v[x] = pred_L[2] = (v + ((3 * (pred_T[2] + pred_L[2]) - 2 * pred_TL[2]) >> 2)) & 0xff;
1271
+
1272
+                pred_TL[0] = pred_T[0];
1273
+                pred_TL[1] = pred_T[1];
1274
+                pred_TL[2] = pred_T[2];
1275
+            }
1276
+        }
1277
+
1278
+        dst_y += p->linesize[0];
1279
+        dst_u += p->linesize[1];
1280
+        dst_v += p->linesize[2];
1281
+    }
1282
+}
1283
+
1284
+static void decode_aybr(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
1285
+{
1286
+    SheerVideoContext *s = avctx->priv_data;
1287
+    uint8_t *dst_a, *dst_y, *dst_u, *dst_v;
1288
+    int x, y;
1289
+
1290
+    dst_a = p->data[3];
1291
+    dst_y = p->data[0];
1292
+    dst_u = p->data[1];
1293
+    dst_v = p->data[2];
1294
+
1295
+    if (get_bits1(gb)) {
1296
+        for (x = 0; x < avctx->width; x++) {
1297
+            dst_a[x] = get_bits(gb, 8);
1298
+            dst_y[x] = get_bits(gb, 8);
1299
+            dst_u[x] = get_bits(gb, 8);
1300
+            dst_v[x] = get_bits(gb, 8);
1301
+        }
1302
+    } else {
1303
+        int pred[4] = { 125, 125, -128, -128 };
1304
+
1305
+        for (x = 0; x < avctx->width; x++) {
1306
+            int a, y, u, v;
1307
+
1308
+            a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1309
+            y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1310
+            u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1311
+            v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1312
+
1313
+            dst_a[x] = pred[0] = (a + pred[0]) & 0xff;
1314
+            dst_y[x] = pred[1] = (y + pred[1]) & 0xff;
1315
+            dst_u[x] = pred[2] = (u + pred[2]) & 0xff;
1316
+            dst_v[x] = pred[3] = (v + pred[3]) & 0xff;
1317
+        }
1318
+    }
1319
+
1320
+    dst_a += p->linesize[3];
1321
+    dst_y += p->linesize[0];
1322
+    dst_u += p->linesize[1];
1323
+    dst_v += p->linesize[2];
1324
+
1325
+    for (y = 1; y < avctx->height; y++) {
1326
+        if (get_bits1(gb)) {
1327
+            for (x = 0; x < avctx->width; x++) {
1328
+                dst_a[x] = get_bits(gb, 8);
1329
+                dst_y[x] = get_bits(gb, 8);
1330
+                dst_u[x] = get_bits(gb, 8);
1331
+                dst_v[x] = get_bits(gb, 8);
1332
+            }
1333
+        } else {
1334
+            int pred_TL[4], pred_L[4], pred_T[4];
1335
+            int a, y, u, v;
1336
+
1337
+            pred_TL[0] = pred_L[0] = dst_a[-p->linesize[3]];
1338
+            pred_TL[1] = pred_L[1] = dst_y[-p->linesize[0]];
1339
+            pred_TL[2] = pred_L[2] = dst_u[-p->linesize[1]];
1340
+            pred_TL[3] = pred_L[3] = dst_v[-p->linesize[2]];
1341
+
1342
+            for (x = 0; x < avctx->width; x++) {
1343
+                pred_T[0] = dst_a[-p->linesize[3] + x];
1344
+                pred_T[1] = dst_y[-p->linesize[0] + x];
1345
+                pred_T[2] = dst_u[-p->linesize[1] + x];
1346
+                pred_T[3] = dst_v[-p->linesize[2] + x];
1347
+
1348
+                a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1349
+                y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1350
+                u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1351
+                v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1352
+
1353
+                dst_a[x] = pred_L[0] = (a + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0xff;
1354
+                dst_y[x] = pred_L[1] = (y + ((3 * (pred_T[1] + pred_L[1]) - 2 * pred_TL[1]) >> 2)) & 0xff;
1355
+                dst_u[x] = pred_L[2] = (u + ((3 * (pred_T[2] + pred_L[2]) - 2 * pred_TL[2]) >> 2)) & 0xff;
1356
+                dst_v[x] = pred_L[3] = (v + ((3 * (pred_T[3] + pred_L[3]) - 2 * pred_TL[3]) >> 2)) & 0xff;
1357
+
1358
+                pred_TL[0] = pred_T[0];
1359
+                pred_TL[1] = pred_T[1];
1360
+                pred_TL[2] = pred_T[2];
1361
+                pred_TL[3] = pred_T[3];
1362
+            }
1363
+        }
1364
+
1365
+        dst_a += p->linesize[3];
1366
+        dst_y += p->linesize[0];
1367
+        dst_u += p->linesize[1];
1368
+        dst_v += p->linesize[2];
1369
+    }
1370
+}
1371
+
1372
+static void decode_argx(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
1373
+{
1374
+    SheerVideoContext *s = avctx->priv_data;
1375
+    uint16_t *dst_r, *dst_g, *dst_b, *dst_a;
1376
+    int x, y;
1377
+
1378
+    dst_r = (uint16_t *)p->data[2];
1379
+    dst_g = (uint16_t *)p->data[0];
1380
+    dst_b = (uint16_t *)p->data[1];
1381
+    dst_a = (uint16_t *)p->data[3];
1382
+
1383
+    if (get_bits1(gb)) {
1384
+        for (x = 0; x < avctx->width; x++) {
1385
+            dst_a[x] = get_bits(gb, 10);
1386
+            dst_r[x] = get_bits(gb, 10);
1387
+            dst_g[x] = get_bits(gb, 10);
1388
+            dst_b[x] = get_bits(gb, 10);
1389
+        }
1390
+    } else {
1391
+        int pred[4] = { 512, 512, 512, 0 };
1392
+
1393
+        for (x = 0; x < avctx->width; x++) {
1394
+            int r, g, b, a;
1395
+
1396
+            a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1397
+            r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1398
+            g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1399
+            b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1400
+
1401
+            dst_a[x] = pred[3] = (a + pred[3]) & 0x3ff;
1402
+            dst_r[x] = pred[0] = (r + pred[0]) & 0x3ff;
1403
+            dst_g[x] = pred[1] = (r + g + pred[1]) & 0x3ff;
1404
+            dst_b[x] = pred[2] = (r + g + b + pred[2]) & 0x3ff;
1405
+        }
1406
+    }
1407
+
1408
+    dst_r += p->linesize[2] / 2;
1409
+    dst_g += p->linesize[0] / 2;
1410
+    dst_b += p->linesize[1] / 2;
1411
+    dst_a += p->linesize[3] / 2;
1412
+
1413
+    for (y = 1; y < avctx->height; y++) {
1414
+        if (get_bits1(gb)) {
1415
+            for (x = 0; x < avctx->width; x++) {
1416
+                dst_a[x] = get_bits(gb, 10);
1417
+                dst_r[x] = get_bits(gb, 10);
1418
+                dst_g[x] = get_bits(gb, 10);
1419
+                dst_b[x] = get_bits(gb, 10);
1420
+            }
1421
+        } else {
1422
+            int pred_TL[4], pred_L[4], pred_T[4];
1423
+            int r, g, b, a;
1424
+
1425
+            pred_TL[0] = pred_L[0] = dst_r[-p->linesize[2] / 2];
1426
+            pred_TL[1] = pred_L[1] = dst_g[-p->linesize[0] / 2];
1427
+            pred_TL[2] = pred_L[2] = dst_b[-p->linesize[1] / 2];
1428
+            pred_TL[3] = pred_L[3] = dst_a[-p->linesize[3] / 2];
1429
+
1430
+            for (x = 0; x < avctx->width; x++) {
1431
+                pred_T[0] = dst_r[-p->linesize[2] / 2 + x];
1432
+                pred_T[1] = dst_g[-p->linesize[0] / 2 + x];
1433
+                pred_T[2] = dst_b[-p->linesize[1] / 2 + x];
1434
+                pred_T[3] = dst_a[-p->linesize[3] / 2 + x];
1435
+
1436
+                a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1437
+                r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1438
+                g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1439
+                b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1440
+
1441
+                dst_a[x] = pred_L[3] = (a + ((3 * (pred_T[3] + pred_L[3]) - 2 * pred_TL[3]) >> 2)) & 0x3ff;
1442
+                dst_r[x] = pred_L[0] = (r + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0x3ff;
1443
+                dst_g[x] = pred_L[1] = (r + g + ((3 * (pred_T[1] + pred_L[1]) - 2 * pred_TL[1]) >> 2)) & 0x3ff;
1444
+                dst_b[x] = pred_L[2] = (r + g + b + ((3 * (pred_T[2] + pred_L[2]) - 2 * pred_TL[2]) >> 2)) & 0x3ff;
1445
+
1446
+                pred_TL[0] = pred_T[0];
1447
+                pred_TL[1] = pred_T[1];
1448
+                pred_TL[2] = pred_T[2];
1449
+                pred_TL[3] = pred_T[3];
1450
+            }
1451
+        }
1452
+
1453
+        dst_r += p->linesize[2] / 2;
1454
+        dst_g += p->linesize[0] / 2;
1455
+        dst_b += p->linesize[1] / 2;
1456
+        dst_a += p->linesize[3] / 2;
1457
+    }
1458
+}
1459
+
1460
+static void decode_rgbx(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
1461
+{
1462
+    SheerVideoContext *s = avctx->priv_data;
1463
+    uint16_t *dst_r, *dst_g, *dst_b;
1464
+    int x, y;
1465
+
1466
+    dst_r = (uint16_t *)p->data[2];
1467
+    dst_g = (uint16_t *)p->data[0];
1468
+    dst_b = (uint16_t *)p->data[1];
1469
+
1470
+    if (get_bits1(gb)) {
1471
+        for (x = 0; x < avctx->width; x++) {
1472
+            dst_r[x] = get_bits(gb, 10);
1473
+            dst_g[x] = get_bits(gb, 10);
1474
+            dst_b[x] = get_bits(gb, 10);
1475
+        }
1476
+    } else {
1477
+        int pred[4] = { 512, 512, 512, 0 };
1478
+
1479
+        for (x = 0; x < avctx->width; x++) {
1480
+            int r, g, b;
1481
+
1482
+            r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1483
+            g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1484
+            b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1485
+
1486
+            dst_r[x] = pred[0] = (r + pred[0]) & 0x3ff;
1487
+            dst_g[x] = pred[1] = (r + g + pred[1]) & 0x3ff;
1488
+            dst_b[x] = pred[2] = (r + g + b + pred[2]) & 0x3ff;
1489
+        }
1490
+    }
1491
+
1492
+    dst_r += p->linesize[2] / 2;
1493
+    dst_g += p->linesize[0] / 2;
1494
+    dst_b += p->linesize[1] / 2;
1495
+
1496
+    for (y = 1; y < avctx->height; y++) {
1497
+        if (get_bits1(gb)) {
1498
+            for (x = 0; x < avctx->width; x++) {
1499
+                dst_r[x] = get_bits(gb, 10);
1500
+                dst_g[x] = get_bits(gb, 10);
1501
+                dst_b[x] = get_bits(gb, 10);
1502
+            }
1503
+        } else {
1504
+            int pred_TL[4], pred_L[4], pred_T[4];
1505
+            int r, g, b;
1506
+
1507
+            pred_TL[0] = pred_L[0] = dst_r[-p->linesize[2] / 2];
1508
+            pred_TL[1] = pred_L[1] = dst_g[-p->linesize[0] / 2];
1509
+            pred_TL[2] = pred_L[2] = dst_b[-p->linesize[1] / 2];
1510
+
1511
+            for (x = 0; x < avctx->width; x++) {
1512
+                pred_T[0] = dst_r[-p->linesize[2] / 2 + x];
1513
+                pred_T[1] = dst_g[-p->linesize[0] / 2 + x];
1514
+                pred_T[2] = dst_b[-p->linesize[1] / 2 + x];
1515
+
1516
+                r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1517
+                g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1518
+                b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1519
+
1520
+                dst_r[x] = pred_L[0] = (r + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0x3ff;
1521
+                dst_g[x] = pred_L[1] = (r + g + ((3 * (pred_T[1] + pred_L[1]) - 2 * pred_TL[1]) >> 2)) & 0x3ff;
1522
+                dst_b[x] = pred_L[2] = (r + g + b + ((3 * (pred_T[2] + pred_L[2]) - 2 * pred_TL[2]) >> 2)) & 0x3ff;
1523
+
1524
+                pred_TL[0] = pred_T[0];
1525
+                pred_TL[1] = pred_T[1];
1526
+                pred_TL[2] = pred_T[2];
1527
+            }
1528
+        }
1529
+
1530
+        dst_r += p->linesize[2] / 2;
1531
+        dst_g += p->linesize[0] / 2;
1532
+        dst_b += p->linesize[1] / 2;
1533
+    }
1534
+}
1535
+
1536
+static void decode_argb(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
1537
+{
1538
+    SheerVideoContext *s = avctx->priv_data;
1539
+    uint8_t *dst;
1540
+    int x, y;
1541
+
1542
+    dst = p->data[0];
1543
+    if (get_bits1(gb)) {
1544
+        for (x = 0; x < avctx->width; x++) {
1545
+            dst[x * 4 + 0] = get_bits(gb, 8);
1546
+            dst[x * 4 + 1] = get_bits(gb, 8);
1547
+            dst[x * 4 + 2] = get_bits(gb, 8);
1548
+            dst[x * 4 + 3] = get_bits(gb, 8);
1549
+        }
1550
+    } else {
1551
+        int pred[4] = { -128, -128, -128, -128 };
1552
+
1553
+        for (x = 0; x < avctx->width; x++) {
1554
+            int a, r, g, b;
1555
+
1556
+            a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1557
+            r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1558
+            g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1559
+            b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1560
+
1561
+            dst[4 * x + 0] = pred[0] = (a + pred[0]) & 0xff;
1562
+            dst[4 * x + 1] = pred[1] = (r + pred[1]) & 0xff;
1563
+            dst[4 * x + 2] = pred[2] = (r + g + pred[2]) & 0xff;
1564
+            dst[4 * x + 3] = pred[3] = (r + g + b + pred[3]) & 0xff;
1565
+        }
1566
+    }
1567
+
1568
+    dst += p->linesize[0];
1569
+    for (y = 1; y < avctx->height; y++) {
1570
+        if (get_bits1(gb)) {
1571
+            for (x = 0; x < avctx->width; x++) {
1572
+                dst[x * 4 + 0] = get_bits(gb, 8);
1573
+                dst[x * 4 + 1] = get_bits(gb, 8);
1574
+                dst[x * 4 + 2] = get_bits(gb, 8);
1575
+                dst[x * 4 + 3] = get_bits(gb, 8);
1576
+            }
1577
+        } else {
1578
+            int pred_TL[4], pred_L[4], pred_T[4];
1579
+            int a, r, g, b;
1580
+
1581
+            pred_TL[0] = pred_L[0] = dst[-p->linesize[0] + 0];
1582
+            pred_TL[1] = pred_L[1] = dst[-p->linesize[0] + 1];
1583
+            pred_TL[2] = pred_L[2] = dst[-p->linesize[0] + 2];
1584
+            pred_TL[3] = pred_L[3] = dst[-p->linesize[0] + 3];
1585
+
1586
+            for (x = 0; x < avctx->width; x++) {
1587
+                pred_T[0] = dst[-p->linesize[0] + 4 * x + 0];
1588
+                pred_T[1] = dst[-p->linesize[0] + 4 * x + 1];
1589
+                pred_T[2] = dst[-p->linesize[0] + 4 * x + 2];
1590
+                pred_T[3] = dst[-p->linesize[0] + 4 * x + 3];
1591
+
1592
+                a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1593
+                r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1594
+                g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1595
+                b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1596
+
1597
+                dst[4 * x + 0] = pred_L[0] = (a + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0xff;
1598
+                dst[4 * x + 1] = pred_L[1] = (r + ((3 * (pred_T[1] + pred_L[1]) - 2 * pred_TL[1]) >> 2)) & 0xff;
1599
+                dst[4 * x + 2] = pred_L[2] = (r + g + ((3 * (pred_T[2] + pred_L[2]) - 2 * pred_TL[2]) >> 2)) & 0xff;
1600
+                dst[4 * x + 3] = pred_L[3] = (r + g + b + ((3 * (pred_T[3] + pred_L[3]) - 2 * pred_TL[3]) >> 2)) & 0xff;
1601
+
1602
+                pred_TL[0] = pred_T[0];
1603
+                pred_TL[1] = pred_T[1];
1604
+                pred_TL[2] = pred_T[2];
1605
+                pred_TL[3] = pred_T[3];
1606
+            }
1607
+        }
1608
+        dst += p->linesize[0];
1609
+    }
1610
+}
1611
+
1612
+static void decode_rgb(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
1613
+{
1614
+    SheerVideoContext *s = avctx->priv_data;
1615
+    uint8_t *dst;
1616
+    int x, y;
1617
+
1618
+    dst = p->data[0];
1619
+    if (get_bits1(gb)) {
1620
+        for (x = 0; x < avctx->width; x++) {
1621
+            dst[x * 4 + 0] = get_bits(gb, 8);
1622
+            dst[x * 4 + 1] = get_bits(gb, 8);
1623
+            dst[x * 4 + 2] = get_bits(gb, 8);
1624
+        }
1625
+    } else {
1626
+        int pred[4] = { -128, -128, -128, -128 };
1627
+
1628
+        for (x = 0; x < avctx->width; x++) {
1629
+            int r, g, b;
1630
+
1631
+            r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1632
+            g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1633
+            b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1634
+
1635
+            dst[4 * x + 0] = pred[0] = (r + pred[0]) & 0xff;
1636
+            dst[4 * x + 1] = pred[1] = (r + g + pred[1]) & 0xff;
1637
+            dst[4 * x + 2] = pred[2] = (r + g + b + pred[2]) & 0xff;
1638
+        }
1639
+    }
1640
+
1641
+    dst += p->linesize[0];
1642
+    for (y = 1; y < avctx->height; y++) {
1643
+        if (get_bits1(gb)) {
1644
+            for (x = 0; x < avctx->width; x++) {
1645
+                dst[x * 4 + 0] = get_bits(gb, 8);
1646
+                dst[x * 4 + 1] = get_bits(gb, 8);
1647
+                dst[x * 4 + 2] = get_bits(gb, 8);
1648
+            }
1649
+        } else {
1650
+            int pred_TL[4], pred_L[4], pred_T[4];
1651
+            int r, g, b;
1652
+
1653
+            pred_TL[0] = pred_L[0] = dst[-p->linesize[0] + 0];
1654
+            pred_TL[1] = pred_L[1] = dst[-p->linesize[0] + 1];
1655
+            pred_TL[2] = pred_L[2] = dst[-p->linesize[0] + 2];
1656
+
1657
+            for (x = 0; x < avctx->width; x++) {
1658
+                pred_T[0] = dst[-p->linesize[0] + 4 * x + 0];
1659
+                pred_T[1] = dst[-p->linesize[0] + 4 * x + 1];
1660
+                pred_T[2] = dst[-p->linesize[0] + 4 * x + 2];
1661
+
1662
+                r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1663
+                g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1664
+                b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1665
+
1666
+                dst[4 * x + 0] = pred_L[0] = (r + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0xff;
1667
+                dst[4 * x + 1] = pred_L[1] = (r + g + ((3 * (pred_T[1] + pred_L[1]) - 2 * pred_TL[1]) >> 2)) & 0xff;
1668
+                dst[4 * x + 2] = pred_L[2] = (r + g + b + ((3 * (pred_T[2] + pred_L[2]) - 2 * pred_TL[2]) >> 2)) & 0xff;
1669
+
1670
+                pred_TL[0] = pred_T[0];
1671
+                pred_TL[1] = pred_T[1];
1672
+                pred_TL[2] = pred_T[2];
1673
+            }
1674
+        }
1675
+        dst += p->linesize[0];
1676
+    }
1677
+}
1678
+
1679
+static int build_vlc(VLC *vlc, const uint8_t *len, int count)
1680
+{
1681
+    uint32_t codes[1024];
1682
+    uint8_t bits[1024];
1683
+    uint16_t syms[1024];
1684
+    uint64_t index;
1685
+    int i;
1686
+
1687
+    index = 0;
1688
+    for (i = 0; i < count; i++) {
1689
+        codes[i]  = index >> (32 - len[i]);
1690
+        bits[i] = len[i];
1691
+        syms[i]  = i;
1692
+        index += 1ULL << (32 - len[i]);
1693
+    }
1694
+
1695
+    ff_free_vlc(vlc);
1696
+    return ff_init_vlc_sparse(vlc, 16, count,
1697
+                              bits,  sizeof(*bits),  sizeof(*bits),
1698
+                              codes, sizeof(*codes), sizeof(*codes),
1699
+                              syms,  sizeof(*syms),  sizeof(*syms), 0);
1700
+}
1701
+
1702
+static int decode_frame(AVCodecContext *avctx,
1703
+                        void *data, int *got_frame,
1704
+                        AVPacket *avpkt)
1705
+{
1706
+    SheerVideoContext *s = avctx->priv_data;
1707
+    ThreadFrame frame = { .f = data };
1708
+    AVFrame *p = data;
1709
+    GetBitContext gb;
1710
+    unsigned format;
1711
+    int ret;
1712
+
1713
+    if (avpkt->size <= 20)
1714
+        return AVERROR_INVALIDDATA;
1715
+
1716
+    if (AV_RL32(avpkt->data) != MKTAG('S','h','i','r') &&
1717
+        AV_RL32(avpkt->data) != MKTAG('Z','w','a','k'))
1718
+        return AVERROR_INVALIDDATA;
1719
+
1720
+    format = AV_RL32(avpkt->data + 16);
1721
+    switch (format) {
1722
+    case MKTAG(' ', 'R', 'G', 'B'):
1723
+        avctx->pix_fmt = AV_PIX_FMT_RGB0;
1724
+        s->decode_frame = decode_rgb;
1725
+        if (s->format != format) {
1726
+            build_vlc(&s->vlc[0], l_r_rgb, 256);
1727
+            build_vlc(&s->vlc[1], l_g_rgb, 256);
1728
+        }
1729
+        break;
1730
+    case MKTAG('A', 'R', 'G', 'X'):
1731
+        avctx->pix_fmt = AV_PIX_FMT_GBRAP12;
1732
+        s->decode_frame = decode_argx;
1733
+        if (s->format != format) {
1734
+            build_vlc(&s->vlc[0], l_r_rgbx, 1024);
1735
+            build_vlc(&s->vlc[1], l_g_rgbx, 1024);
1736
+        }
1737
+        break;
1738
+    case MKTAG('R', 'G', 'B', 'X'):
1739
+        avctx->pix_fmt = AV_PIX_FMT_GBRP10;
1740
+        s->decode_frame = decode_rgbx;
1741
+        if (s->format != format) {
1742
+            build_vlc(&s->vlc[0], l_r_rgbx, 1024);
1743
+            build_vlc(&s->vlc[1], l_g_rgbx, 1024);
1744
+        }
1745
+        break;
1746
+    case MKTAG('A', 'R', 'G', 'B'):
1747
+        avctx->pix_fmt = AV_PIX_FMT_ARGB;
1748
+        s->decode_frame = decode_argb;
1749
+        if (s->format != format) {
1750
+            build_vlc(&s->vlc[0], l_r_rgb, 256);
1751
+            build_vlc(&s->vlc[1], l_g_rgb, 256);
1752
+        }
1753
+        break;
1754
+    case MKTAG('A', 'Y', 'b', 'R'):
1755
+        avctx->pix_fmt = AV_PIX_FMT_YUVA444P;
1756
+        s->decode_frame = decode_aybr;
1757
+        if (s->format != format) {
1758
+            build_vlc(&s->vlc[0], l_y_ybr, 256);
1759
+            build_vlc(&s->vlc[1], l_u_ybr, 256);
1760
+        }
1761
+        break;
1762
+    case MKTAG(' ', 'Y', 'b', 'R'):
1763
+        avctx->pix_fmt = AV_PIX_FMT_YUV444P;
1764
+        s->decode_frame = decode_ybr;
1765
+        if (s->format != format) {
1766
+            build_vlc(&s->vlc[0], l_y_ybr, 256);
1767
+            build_vlc(&s->vlc[1], l_u_ybr, 256);
1768
+        }
1769
+        break;
1770
+    case MKTAG('Y', 'B', 'R', 0x0a):
1771
+        avctx->pix_fmt = AV_PIX_FMT_YUV444P10;
1772
+        s->decode_frame = decode_ybr10;
1773
+        if (s->format != format) {
1774
+            build_vlc(&s->vlc[0], l_y_ybr10, 1024);
1775
+            build_vlc(&s->vlc[1], l_u_ybr10, 1024);
1776
+        }
1777
+        break;
1778
+    case MKTAG('C', 'A', '4', 'p'):
1779
+        avctx->pix_fmt = AV_PIX_FMT_YUVA444P10;
1780
+        s->decode_frame = decode_ca4p;
1781
+        if (s->format != format) {
1782
+            build_vlc(&s->vlc[0], l_y_ybr10, 1024);
1783
+            build_vlc(&s->vlc[1], l_u_ybr10, 1024);
1784
+        }
1785
+        break;
1786
+    case MKTAG('B', 'Y', 'R', 'Y'):
1787
+        avctx->pix_fmt = AV_PIX_FMT_YUV422P;
1788
+        s->decode_frame = decode_byry;
1789
+        if (s->format != format) {
1790
+            build_vlc(&s->vlc[0], l_y_byry, 256);
1791
+            build_vlc(&s->vlc[1], l_u_byry, 256);
1792
+        }
1793
+        break;
1794
+    case MKTAG('Y', 'b', 'Y', 'r'):
1795
+        avctx->pix_fmt = AV_PIX_FMT_YUV422P;
1796
+        s->decode_frame = decode_ybyr;
1797
+        if (s->format != format) {
1798
+            build_vlc(&s->vlc[0], l_y_ybyr, 256);
1799
+            build_vlc(&s->vlc[1], l_u_ybyr, 256);
1800
+        }
1801
+        break;
1802
+    case MKTAG('C', '8', '2', 'p'):
1803
+        avctx->pix_fmt = AV_PIX_FMT_YUVA422P;
1804
+        s->decode_frame = decode_c82p;
1805
+        if (s->format != format) {
1806
+            build_vlc(&s->vlc[0], l_y_byry, 256);
1807
+            build_vlc(&s->vlc[1], l_u_byry, 256);
1808
+        }
1809
+        break;
1810
+    case MKTAG(0xa2, 'Y', 'R', 'Y'):
1811
+        avctx->pix_fmt = AV_PIX_FMT_YUV422P10;
1812
+        s->decode_frame = decode_yry10;
1813
+        if (s->format != format) {
1814
+            build_vlc(&s->vlc[0], l_y_yry10, 1024);
1815
+            build_vlc(&s->vlc[1], l_u_yry10, 1024);
1816
+        }
1817
+        break;
1818
+    case MKTAG('C', 'A', '2', 'p'):
1819
+        avctx->pix_fmt = AV_PIX_FMT_YUVA422P10;
1820
+        s->decode_frame = decode_ca2p;
1821
+        if (s->format != format) {
1822
+            build_vlc(&s->vlc[0], l_y_yry10, 1024);
1823
+            build_vlc(&s->vlc[1], l_u_yry10, 1024);
1824
+        }
1825
+        break;
1826
+    default:
1827
+        avpriv_request_sample(avctx, "unsupported format: 0x%X", format);
1828
+        return AVERROR_PATCHWELCOME;
1829
+    }
1830
+    s->format = format;
1831
+
1832
+    p->pict_type = AV_PICTURE_TYPE_I;
1833
+    p->key_frame = 1;
1834
+
1835
+    if ((ret = ff_thread_get_buffer(avctx, &frame, 0)) < 0)
1836
+        return ret;
1837
+
1838
+    if ((ret = init_get_bits8(&gb, avpkt->data + 20, avpkt->size - 20)) < 0)
1839
+        return ret;
1840
+
1841
+    s->decode_frame(avctx, p, &gb);
1842
+
1843
+    *got_frame = 1;
1844
+
1845
+    return avpkt->size;
1846
+}
1847
+
1848
+#if HAVE_THREADS
1849
+static int decode_init_thread_copy(AVCodecContext *avctx)
1850
+{
1851
+    SheerVideoContext *s = avctx->priv_data;
1852
+
1853
+    s->format = 0;
1854
+    memset(&s->vlc[0], 0, sizeof(s->vlc[0]));
1855
+    memset(&s->vlc[1], 0, sizeof(s->vlc[1]));
1856
+
1857
+    return 0;
1858
+}
1859
+#endif
1860
+
1861
+static av_cold int decode_end(AVCodecContext *avctx)
1862
+{
1863
+    SheerVideoContext *s = avctx->priv_data;
1864
+
1865
+    ff_free_vlc(&s->vlc[0]);
1866
+    ff_free_vlc(&s->vlc[1]);
1867
+
1868
+    return 0;
1869
+}
1870
+
1871
+AVCodec ff_sheervideo_decoder = {
1872
+    .name             = "sheervideo",
1873
+    .long_name        = NULL_IF_CONFIG_SMALL("BitJazz SheerVideo"),
1874
+    .type             = AVMEDIA_TYPE_VIDEO,
1875
+    .id               = AV_CODEC_ID_SHEERVIDEO,
1876
+    .priv_data_size   = sizeof(SheerVideoContext),
1877
+    .init_thread_copy = ONLY_IF_THREADS_ENABLED(decode_init_thread_copy),
1878
+    .close            = decode_end,
1879
+    .decode           = decode_frame,
1880
+    .capabilities     = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS,
1881
+};
... ...
@@ -28,8 +28,8 @@
28 28
 #include "libavutil/version.h"
29 29
 
30 30
 #define LIBAVCODEC_VERSION_MAJOR  57
31
-#define LIBAVCODEC_VERSION_MINOR  44
32
-#define LIBAVCODEC_VERSION_MICRO 101
31
+#define LIBAVCODEC_VERSION_MINOR  45
32
+#define LIBAVCODEC_VERSION_MICRO 100
33 33
 
34 34
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
35 35
                                                LIBAVCODEC_VERSION_MINOR, \
... ...
@@ -277,6 +277,15 @@ const AVCodecTag ff_codec_movvideo_tags[] = {
277 277
     { AV_CODEC_ID_MAGICYUV, MKTAG('M', '8', 'Y', '4') },
278 278
     { AV_CODEC_ID_MAGICYUV, MKTAG('M', '8', 'Y', 'A') },
279 279
 
280
+    { AV_CODEC_ID_SHEERVIDEO, MKTAG('S', 'h', 'r', '0') },
281
+    { AV_CODEC_ID_SHEERVIDEO, MKTAG('S', 'h', 'r', '1') },
282
+    { AV_CODEC_ID_SHEERVIDEO, MKTAG('S', 'h', 'r', '2') },
283
+    { AV_CODEC_ID_SHEERVIDEO, MKTAG('S', 'h', 'r', '3') },
284
+    { AV_CODEC_ID_SHEERVIDEO, MKTAG('S', 'h', 'r', '4') },
285
+    { AV_CODEC_ID_SHEERVIDEO, MKTAG('S', 'h', 'r', '5') },
286
+    { AV_CODEC_ID_SHEERVIDEO, MKTAG('S', 'h', 'r', '6') },
287
+    { AV_CODEC_ID_SHEERVIDEO, MKTAG('S', 'h', 'r', '7') },
288
+
280 289
     { AV_CODEC_ID_NONE, 0 },
281 290
 };
282 291