FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
sheervideo.c
Go to the documentation of this file.
1 /*
2  * BitJazz SheerVideo decoder
3  * Copyright (c) 2016 Paul B Mahol
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25 
26 #include "libavutil/intreadwrite.h"
27 #include "avcodec.h"
28 #include "get_bits.h"
29 #include "internal.h"
30 #include "thread.h"
31 
32 typedef struct SheerVideoContext {
33  unsigned format;
34  int alt;
35  VLC vlc[2];
38 
39 static const uint8_t l_r_rgb[256] = {
40  3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 7, 7, 8,
41  8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10,
42  10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12,
43  12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13,
44  13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
45  14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
46  15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
47  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
48  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
49  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 15, 15, 15,
50  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 14, 14, 14,
51  14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 13, 13, 13,
52  13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 12, 12, 12, 12, 12, 12,
53  12, 12, 12, 12, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 10, 10,
54  10, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8,
55  8, 8, 8, 7, 7, 7, 7, 7, 6, 6, 6, 5, 5, 4, 4, 4,
56 };
57 
58 static const uint8_t l_r_rgbi[256] = {
59  3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 7, 7, 7,
60  8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9,
61  10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11,
62  11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12,
63  12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
64  13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14,
65  14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15,
66  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
67  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
68  15, 15, 15, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
69  14, 14, 14, 14, 14, 14, 14, 14, 14, 13, 13, 13, 13, 13, 13, 13,
70  13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 12, 12, 12, 12,
71  12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 11, 11, 11, 11, 11,
72  11, 11, 11, 11, 11, 11, 11, 10, 10, 10, 10, 10, 10, 10, 10, 10,
73  10, 10, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 8, 8,
74  8, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 5, 5, 4, 4, 4,
75 };
76 
77 static const uint8_t l_g_rgbi[256] = {
78  1, 3, 4, 5, 6, 7, 7, 8, 9, 9, 10, 10, 10, 10, 11, 11,
79  11, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14,
80  14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16,
81  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 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, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
87  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
88  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
89  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
90  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
91  16, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 14,
92  14, 14, 14, 14, 14, 13, 13, 13, 13, 13, 13, 12, 12, 12, 12, 12,
93  11, 11, 11, 10, 10, 10, 9, 9, 9, 8, 8, 7, 6, 5, 5, 3,
94 };
95 
96 static const uint8_t l_g_rgb[256] = {
97  2, 2, 4, 4, 6, 7, 9, 9, 10, 11, 11, 11, 12, 12, 12, 13,
98  13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15,
99  15, 15, 15, 15, 15, 15, 15, 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, 16, 16, 16, 16, 16,
110  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 15, 15, 15, 15,
111  15, 15, 15, 15, 15, 15, 14, 14, 14, 14, 14, 14, 14, 14, 13, 13,
112  13, 13, 12, 12, 12, 11, 11, 11, 10, 9, 9, 8, 6, 4, 3, 3,
113 };
114 
115 static const uint8_t l_y_ybr[256] = {
116  3, 3, 4, 4, 5, 5, 6, 6, 6, 7, 7, 7, 7, 7, 8, 8,
117  8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10,
118  10, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12,
119  12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14,
120  14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15,
121  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 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, 16, 16, 16,
124  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
125  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
126  16, 16, 16, 16, 16, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
127  15, 15, 15, 15, 15, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
128  14, 14, 14, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 12,
129  12, 12, 12, 12, 12, 12, 12, 12, 11, 11, 11, 11, 11, 11, 11, 11,
130  11, 10, 10, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9, 8, 8,
131  8, 8, 8, 8, 7, 7, 7, 7, 6, 6, 6, 6, 5, 4, 4, 3,
132 };
133 
134 static const uint8_t l_u_ybr[256] = {
135  1, 2, 4, 6, 9, 10, 11, 11, 12, 12, 13, 13, 13, 14, 14, 14,
136  14, 14, 15, 15, 15, 15, 15, 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, 16, 16, 16, 16, 16, 16, 16,
148  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
149  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 15, 15, 15, 15,
150  14, 14, 14, 14, 14, 13, 13, 13, 12, 12, 11, 11, 10, 8, 5, 3,
151 };
152 
153 static const uint8_t l_y_ybyr[256] = {
154  3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 7, 7, 8,
155  8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10,
156  10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12,
157  12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13,
158  13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
159  14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
160  15, 15, 15, 15, 15, 15, 15, 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, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
163  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 15, 15,
164  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 14,
165  14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 13, 13,
166  13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 12, 12, 12, 12, 12, 12,
167  12, 12, 12, 12, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 10, 10,
168  10, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8,
169  8, 8, 8, 7, 7, 7, 7, 7, 6, 6, 6, 5, 5, 4, 4, 4,
170 };
171 
172 static const uint8_t l_u_ybyr[256] = {
173  1, 2, 4, 6, 8, 9, 10, 10, 11, 11, 12, 12, 12, 13, 13, 14,
174  14, 14, 14, 14, 15, 15, 15, 15, 15, 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, 16, 16, 16, 16, 16, 16, 16,
186  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
187  16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 15, 15, 15, 15, 14, 14,
188  14, 14, 13, 13, 13, 12, 12, 11, 11, 10, 10, 9, 8, 7, 6, 3,
189 };
190 
191 static const uint8_t l_y_byry[256] = {
192  3, 3, 4, 4, 5, 5, 6, 6, 6, 7, 7, 7, 7, 7, 8, 8,
193  8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10,
194  10, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12,
195  12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14,
196  14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15,
197  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16,
198  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
199  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
200  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
201  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
202  16, 16, 16, 16, 16, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
203  15, 15, 15, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
204  14, 14, 14, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 12,
205  12, 12, 12, 12, 12, 12, 12, 12, 12, 11, 11, 11, 11, 11, 11, 11,
206  11, 10, 10, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9, 8, 8,
207  8, 8, 8, 8, 7, 7, 7, 7, 6, 6, 6, 6, 5, 4, 4, 3,
208 };
209 
210 static const uint8_t l_u_byry[256] = {
211  1, 2, 4, 6, 8, 9, 9, 10, 11, 11, 12, 12, 13, 13, 13, 14,
212  14, 14, 14, 15, 15, 15, 15, 15, 15, 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, 15, 15, 15, 15, 15, 15, 14,
226  14, 14, 14, 13, 13, 12, 12, 12, 11, 11, 10, 9, 8, 7, 6, 3,
227 };
228 
229 static const uint8_t l_y_ybr10i[1024] = {
230  3, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7,
231  7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
232  8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
233  9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
234  10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11,
235  11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
236  11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12,
237  12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
238  12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
239  12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
240  13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
241  13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
242  13, 13, 13, 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, 14, 14,
244  14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
245  14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
246  14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
247  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
248  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
249  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
250  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
251  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16,
252  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
253  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
254  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
255  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
256  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
257  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
258  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
259  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
260  16, 16, 16, 16, 16, 16, 16, 16, 16, 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, 15, 15, 15, 15, 15, 15, 15, 15, 15,
273  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
274  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
275  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
276  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
277  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
278  14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
279  14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
280  14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
281  14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
282  13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
283  13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
284  13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
285  13, 13, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
286  12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
287  12, 12, 12, 12, 12, 12, 12, 12, 11, 11, 11, 11, 11, 11, 11, 11,
288  11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
289  11, 11, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
290  10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 9, 9, 9, 9,
291  9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
292  8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7,
293  7, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5,
294 };
295 
296 static const uint8_t l_y_ybr10[1024] = {
297  4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7, 7,
298  7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
299  8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
300  9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
301  10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11,
302  11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
303  11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
304  12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
305  13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
306  13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
307  13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
308  14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
309  14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
310  14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
311  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
312  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
313  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
314  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 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, 16, 16, 16, 16, 16, 16, 16,
318  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
319  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
320  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
321  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
322  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
323  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
324  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
325  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
326  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
327  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
328  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
329  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
330  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
331  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
332  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
333  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
334  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
335  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
336  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
337  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
338  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
339  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
340  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
341  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
342  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
343  16, 16, 16, 16, 16, 16, 16, 16, 15, 15, 15, 15, 15, 15, 15, 15,
344  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
345  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
346  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
347  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
348  14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
349  14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
350  14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 13, 13,
351  13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
352  13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
353  13, 13, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
354  12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 11,
355  11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
356  11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 10, 10, 10, 10, 10, 10,
357  10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 9,
358  9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
359  8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7,
360  7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5,
361 };
362 
363 static const uint8_t l_u_ybr10i[1024] = {
364  2, 3, 4, 4, 5, 5, 6, 7, 7, 8, 8, 9, 9, 9, 9, 10,
365  10, 10, 10, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12,
366  13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14,
367  14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
368  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
369  15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
370  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
371  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
372  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
373  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
374  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
375  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
376  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
377  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
378  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
379  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
380  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
381  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
382  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
383  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
384  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
385  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
386  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
387  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
388  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
389  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
390  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
391  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
392  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
393  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
394  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
395  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
396  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
397  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 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, 15, 15,
423  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
424  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 14, 14, 14, 14, 14, 14,
425  14, 14, 14, 14, 14, 14, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
426  13, 12, 12, 12, 12, 12, 12, 11, 11, 11, 11, 11, 11, 11, 10, 10,
427  10, 10, 10, 9, 9, 9, 8, 8, 8, 7, 6, 5, 5, 4, 4, 3,
428 };
429 
430 static const uint8_t l_u_ybr10[1024] = {
431  2, 3, 3, 4, 5, 5, 6, 7, 8, 9, 9, 10, 10, 10, 11, 11,
432  12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14,
433  14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
434  15, 15, 15, 15, 15, 15, 15, 15, 15, 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, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
449  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
450  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
451  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
452  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
453  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
454  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
455  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
456  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
457  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
458  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
459  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
460  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
461  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
462  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
463  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
464  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
465  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
466  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
467  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
468  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
469  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
470  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
471  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
472  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
473  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
474  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
475  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 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, 15, 15, 15, 15, 15, 15, 15,
492  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 14, 14, 14,
493  14, 14, 14, 14, 14, 14, 14, 13, 13, 13, 13, 13, 13, 12, 12, 12,
494  12, 11, 11, 11, 10, 10, 9, 9, 8, 8, 7, 6, 5, 4, 4, 3,
495 };
496 
497 static const uint8_t l_r_rgbx[1024] = {
498  4, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7,
499  7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
500  8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
501  9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10,
502  10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
503  10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
504  11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12,
505  12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
506  12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
507  13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
508  13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
509  13, 13, 13, 13, 13, 13, 13, 13, 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, 14, 14,
512  14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15,
513  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
514  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
515  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
516  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
517  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16,
518  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
519  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
520  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
521  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
522  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
523  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
524  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
525  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
526  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
527  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
528  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
529  16, 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, 15, 15, 15, 15, 15, 15,
543  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
544  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
545  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
546  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
547  15, 15, 15, 15, 15, 15, 15, 14, 14, 14, 14, 14, 14, 14, 14, 14,
548  14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
549  14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
550  14, 14, 14, 14, 14, 14, 14, 14, 14, 13, 13, 13, 13, 13, 13, 13,
551  13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
552  13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
553  13, 13, 13, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
554  12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
555  12, 12, 12, 12, 12, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
556  11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
557  11, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
558  10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9,
559  9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8,
560  8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7,
561  7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5,
562 };
563 
564 static const uint8_t l_g_rgbx[1024] = {
565  3, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7,
566  8, 8, 9, 9, 9, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 12,
567  12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13,
568  13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
569  14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
570  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
571  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 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, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
586  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
587  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
588  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
589  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
590  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
591  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
592  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
593  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
594  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
595  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
596  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
597  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
598  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
599  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
600  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
601  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
602  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
603  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
604  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
605  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
606  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
607  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
608  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
609  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
610  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
611  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
612  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
613  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
614  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
615  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
616  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
617  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
618  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
619  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
620  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
621  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
622  16, 16, 16, 16, 16, 16, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
623  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
624  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 14, 14, 14,
625  14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 13,
626  13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 12, 12, 12, 12, 12, 12,
627  12, 12, 11, 11, 11, 11, 11, 11, 10, 10, 10, 10, 9, 9, 9, 9,
628  8, 7, 7, 7, 6, 6, 6, 6, 6, 5, 5, 5, 5, 4, 4, 4,
629 };
630 
631 static const uint8_t l_y_yry10[1024] = {
632  4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7, 7,
633  7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
634  8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
635  9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
636  10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11,
637  11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
638  11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
639  12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
640  13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
641  13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
642  13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
643  14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
644  14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
645  14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
646  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
647  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
648  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
649  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16,
650  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
651  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
652  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
653  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
654  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
655  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
656  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
657  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
658  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
659  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
660  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
661  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
662  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
663  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
664  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
665  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
666  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
667  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
668  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
669  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
670  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
671  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
672  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
673  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
674  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
675  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
676  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
677  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
678  16, 16, 16, 16, 16, 16, 16, 16, 15, 15, 15, 15, 15, 15, 15, 15,
679  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
680  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
681  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
682  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
683  14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
684  14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
685  14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 13, 13,
686  13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
687  13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
688  13, 13, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
689  12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 11,
690  11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
691  11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 10, 10, 10, 10, 10, 10,
692  10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 9,
693  9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
694  8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7,
695  7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5,
696 };
697 
698 static const uint8_t l_y_yry10i[1024] = {
699  3, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7,
700  7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
701  8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
702  9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
703  10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11,
704  11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
705  11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12,
706  12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
707  12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
708  12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
709  13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
710  13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
711  13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
712  14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
713  14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
714  14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
715  14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
716  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
717  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
718  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
719  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
720  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16,
721  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
722  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
723  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
724  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
725  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
726  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
727  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
728  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
729  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
730  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
731  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
732  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
733  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
734  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
735  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
736  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
737  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
738  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
739  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
740  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
741  16, 16, 16, 16, 16, 16, 16, 15, 15, 15, 15, 15, 15, 15, 15, 15,
742  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
743  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
744  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
745  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
746  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
747  14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
748  14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
749  14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
750  14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
751  14, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
752  13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
753  13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
754  13, 13, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
755  12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
756  12, 12, 12, 12, 12, 12, 12, 12, 11, 11, 11, 11, 11, 11, 11, 11,
757  11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
758  11, 11, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
759  10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 9, 9, 9, 9,
760  9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
761  8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7,
762  7, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5,
763 };
764 
765 static const uint8_t l_u_yry10[1024] = {
766  2, 3, 3, 4, 5, 6, 7, 7, 8, 8, 8, 9, 9, 10, 10, 10,
767  10, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13,
768  13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
769  14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
770  15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
771  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
772  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
773  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
774  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
775  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
776  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
777  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
778  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
779  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
780  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
781  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
782  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
783  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
784  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
785  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
786  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
787  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
788  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
789  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
790  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
791  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
792  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
793  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
794  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
795  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
796  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
797  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
798  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
799  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
800  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
801  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
802  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
803  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
804  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
805  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
806  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
807  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
808  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
809  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
810  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
811  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
812  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
813  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
814  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
815  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
816  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
817  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
818  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
819  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
820  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
821  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
822  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
823  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
824  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
825  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
826  16, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
827  15, 15, 15, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 13, 13,
828  13, 13, 13, 13, 13, 12, 12, 12, 12, 12, 12, 12, 11, 11, 11, 11,
829  10, 10, 10, 10, 9, 9, 9, 8, 8, 7, 7, 6, 5, 4, 4, 3,
830 };
831 
832 static const uint8_t l_u_yry10i[1024] = {
833  2, 4, 4, 4, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9,
834  9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11,
835  11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13,
836  13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14,
837  14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15,
838  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
839  15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
840  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
841  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
842  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
843  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
844  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
845  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
846  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
847  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
848  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
849  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
850  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
851  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
852  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
853  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
854  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
855  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
856  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
857  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
858  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
859  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
860  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
861  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
862  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
863  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
864  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
865  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
866  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
867  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
868  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
869  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
870  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
871  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
872  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
873  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
874  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
875  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
876  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
877  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
878  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
879  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
880  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
881  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
882  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
883  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
884  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
885  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
886  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
887  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
888  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
889  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
890  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
891  16, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
892  15, 15, 15, 15, 15, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
893  14, 14, 14, 14, 14, 14, 14, 13, 13, 13, 13, 13, 13, 13, 13, 13,
894  13, 13, 13, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 11,
895  11, 11, 11, 11, 11, 11, 11, 10, 10, 10, 10, 10, 10, 9, 9, 9,
896  9, 9, 8, 8, 8, 8, 7, 7, 7, 6, 6, 5, 5, 4, 4, 3,
897 };
898 
899 static const uint8_t l_y_ybri[256] = {
900  3, 3, 4, 4, 5, 5, 6, 6, 6, 7, 7, 7, 7, 7, 8, 8,
901  8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10,
902  10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12,
903  12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13,
904  13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14,
905  14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15,
906  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
907  15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
908  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
909  16, 16, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
910  15, 15, 15, 15, 15, 15, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
911  14, 14, 14, 14, 14, 14, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
912  13, 13, 13, 13, 13, 13, 13, 12, 12, 12, 12, 12, 12, 12, 12, 12,
913  12, 12, 12, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 10, 10,
914  10, 10, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9, 9, 8, 8,
915  8, 8, 8, 7, 7, 7, 7, 7, 6, 6, 6, 5, 5, 5, 4, 3,
916 };
917 
918 static const uint8_t l_u_ybri[256] = {
919  1, 3, 5, 6, 8, 8, 9, 10, 10, 11, 11, 12, 12, 13, 13, 13,
920  14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16,
921  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
922  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
923  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
924  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
925  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
926  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
927  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
928  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
929  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
930  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
931  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
932  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
933  16, 16, 16, 16, 16, 16, 15, 15, 15, 15, 15, 14, 14, 14, 14, 14,
934  14, 13, 13, 13, 12, 12, 11, 11, 10, 10, 9, 8, 8, 6, 5, 2,
935 };
936 
937 static const uint8_t l_y_byryi[256] = {
938  3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8,
939  8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10,
940  10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12,
941  12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13,
942  13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14,
943  14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15,
944  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
945  15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
946  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
947  16, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
948  15, 15, 15, 15, 15, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
949  14, 14, 14, 14, 14, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
950  13, 13, 13, 13, 13, 13, 13, 12, 12, 12, 12, 12, 12, 12, 12, 12,
951  12, 12, 12, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 10,
952  10, 10, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9, 9, 8, 8,
953  8, 8, 8, 7, 7, 7, 7, 7, 7, 6, 6, 6, 5, 4, 4, 3,
954 };
955 
956 static const uint8_t l_u_byryi[256] = {
957  1, 3, 4, 6, 6, 7, 8, 8, 9, 9, 10, 10, 10, 11, 11, 11,
958  12, 12, 12, 12, 13, 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15,
959  15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
960  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
961  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
962  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
963  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
964  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
965  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
966  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
967  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
968  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
969  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
970  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 15, 15,
971  15, 15, 15, 15, 14, 14, 14, 14, 14, 13, 13, 13, 13, 12, 12, 12,
972  12, 11, 11, 11, 10, 10, 10, 9, 9, 8, 8, 7, 7, 5, 4, 3,
973 };
974 
975 static const uint8_t l_r_rgbxi[1024] = {
976  3, 4, 4, 4, 5, 5, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8,
977  8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
978  9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
979  10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11,
980  11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
981  11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
982  12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
983  12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
984  13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14,
985  14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
986  14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15,
987  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
988  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
989  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
990  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
991  15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
992  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
993  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
994  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
995  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
996  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
997  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
998  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
999  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1000  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1001  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1002  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1003  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1004  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1005  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1006  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1007  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1008  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1009  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1010  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1011  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1012  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1013  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1014  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1015  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1016  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1017  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1018  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1019  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1020  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1021  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1022  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1023  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1024  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15,
1025  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
1026  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
1027  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
1028  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
1029  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 14, 14, 14,
1030  14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
1031  14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 13, 13, 13, 13, 13, 13,
1032  13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 12,
1033  12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
1034  12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 11, 11, 11, 11,
1035  11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
1036  11, 11, 11, 11, 11, 11, 11, 10, 10, 10, 10, 10, 10, 10, 10, 10,
1037  10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 9, 9,
1038  9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8,
1039  8, 8, 8, 8, 7, 7, 7, 7, 6, 6, 6, 5, 5, 4, 4, 4,
1040 };
1041 
1042 static const uint8_t l_g_rgbxi[1024] = {
1043  2, 3, 4, 4, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,
1044  9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11,
1045  11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13,
1046  13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14,
1047  14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15,
1048  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
1049  15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16,
1050  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1051  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1052  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1053  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1054  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1055  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1056  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1057  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1058  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1059  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1060  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1061  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1062  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1063  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1064  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1065  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1066  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1067  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1068  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1069  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1070  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1071  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1072  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1073  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1074  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1075  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1076  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1077  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1078  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1079  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1080  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1081  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1082  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1083  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1084  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1085  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1086  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1087  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1088  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1089  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1090  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1091  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1092  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1093  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1094  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1095  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1096  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1097  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1098  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1099  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1100  16, 16, 16, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
1101  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
1102  15, 15, 15, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
1103  14, 14, 14, 14, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
1104  13, 13, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 11, 11,
1105  11, 11, 11, 11, 11, 10, 10, 10, 10, 10, 10, 10, 10, 9, 9, 9,
1106  9, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 6, 6, 4, 4, 3,
1107 };
1108 
1109 static void decode_ca4i(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
1110 {
1111  SheerVideoContext *s = avctx->priv_data;
1112  uint16_t *dst_y, *dst_u, *dst_v, *dst_a;
1113  int x, y;
1114 
1115  dst_a = (uint16_t *)p->data[3];
1116  dst_y = (uint16_t *)p->data[0];
1117  dst_u = (uint16_t *)p->data[1];
1118  dst_v = (uint16_t *)p->data[2];
1119 
1120  for (y = 0; y < avctx->height; y++) {
1121  if (get_bits1(gb)) {
1122  for (x = 0; x < avctx->width; x++) {
1123  dst_a[x] = get_bits(gb, 10);
1124  dst_y[x] = get_bits(gb, 10);
1125  dst_u[x] = get_bits(gb, 10);
1126  dst_v[x] = get_bits(gb, 10);
1127  }
1128  } else {
1129  int pred[4] = { 502, 512, 512, 502 };
1130 
1131  for (x = 0; x < avctx->width; x++) {
1132  int y, u, v, a;
1133 
1134  a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1135  y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1136  u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1137  v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1138 
1139  dst_a[x] = pred[3] = (a + pred[3]) & 0x3ff;
1140  dst_y[x] = pred[0] = (y + pred[0]) & 0x3ff;
1141  dst_u[x] = pred[1] = (u + pred[1]) & 0x3ff;
1142  dst_v[x] = pred[2] = (v + pred[2]) & 0x3ff;
1143  }
1144  }
1145 
1146  dst_y += p->linesize[0] / 2;
1147  dst_u += p->linesize[1] / 2;
1148  dst_v += p->linesize[2] / 2;
1149  dst_a += p->linesize[3] / 2;
1150  }
1151 }
1152 
1153 static void decode_ca4p(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
1154 {
1155  SheerVideoContext *s = avctx->priv_data;
1156  uint16_t *dst_y, *dst_u, *dst_v, *dst_a;
1157  int x, y;
1158 
1159  dst_a = (uint16_t *)p->data[3];
1160  dst_y = (uint16_t *)p->data[0];
1161  dst_u = (uint16_t *)p->data[1];
1162  dst_v = (uint16_t *)p->data[2];
1163 
1164  if (get_bits1(gb)) {
1165  for (x = 0; x < avctx->width; x++) {
1166  dst_a[x] = get_bits(gb, 10);
1167  dst_y[x] = get_bits(gb, 10);
1168  dst_u[x] = get_bits(gb, 10);
1169  dst_v[x] = get_bits(gb, 10);
1170  }
1171  } else {
1172  int pred[4] = { 502, 512, 512, 502 };
1173 
1174  for (x = 0; x < avctx->width; x++) {
1175  int y, u, v, a;
1176 
1177  a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1178  y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1179  u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1180  v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1181 
1182  dst_a[x] = pred[3] = (a + pred[3]) & 0x3ff;
1183  dst_y[x] = pred[0] = (y + pred[0]) & 0x3ff;
1184  dst_u[x] = pred[1] = (u + pred[1]) & 0x3ff;
1185  dst_v[x] = pred[2] = (v + pred[2]) & 0x3ff;
1186  }
1187  }
1188 
1189  dst_y += p->linesize[0] / 2;
1190  dst_u += p->linesize[1] / 2;
1191  dst_v += p->linesize[2] / 2;
1192  dst_a += p->linesize[3] / 2;
1193 
1194  for (y = 1; y < avctx->height; y++) {
1195  if (get_bits1(gb)) {
1196  for (x = 0; x < avctx->width; x++) {
1197  dst_a[x] = get_bits(gb, 10);
1198  dst_y[x] = get_bits(gb, 10);
1199  dst_u[x] = get_bits(gb, 10);
1200  dst_v[x] = get_bits(gb, 10);
1201  }
1202  } else {
1203  int pred_TL[4], pred_L[4], pred_T[4];
1204  int y, u, v, a;
1205 
1206  pred_TL[0] = pred_L[0] = dst_y[-p->linesize[0] / 2];
1207  pred_TL[1] = pred_L[1] = dst_u[-p->linesize[1] / 2];
1208  pred_TL[2] = pred_L[2] = dst_v[-p->linesize[2] / 2];
1209  pred_TL[3] = pred_L[3] = dst_a[-p->linesize[3] / 2];
1210 
1211  for (x = 0; x < avctx->width; x++) {
1212  pred_T[0] = dst_y[-p->linesize[0] / 2 + x];
1213  pred_T[1] = dst_u[-p->linesize[1] / 2 + x];
1214  pred_T[2] = dst_v[-p->linesize[2] / 2 + x];
1215  pred_T[3] = dst_a[-p->linesize[3] / 2 + x];
1216 
1217  a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1218  y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1219  u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1220  v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1221 
1222  dst_a[x] = pred_L[3] = (a + ((3 * (pred_T[3] + pred_L[3]) - 2 * pred_TL[3]) >> 2)) & 0x3ff;
1223  dst_y[x] = pred_L[0] = (y + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0x3ff;
1224  dst_u[x] = pred_L[1] = (u + ((3 * (pred_T[1] + pred_L[1]) - 2 * pred_TL[1]) >> 2)) & 0x3ff;
1225  dst_v[x] = pred_L[2] = (v + ((3 * (pred_T[2] + pred_L[2]) - 2 * pred_TL[2]) >> 2)) & 0x3ff;
1226 
1227  pred_TL[0] = pred_T[0];
1228  pred_TL[1] = pred_T[1];
1229  pred_TL[2] = pred_T[2];
1230  pred_TL[3] = pred_T[3];
1231  }
1232  }
1233 
1234  dst_y += p->linesize[0] / 2;
1235  dst_u += p->linesize[1] / 2;
1236  dst_v += p->linesize[2] / 2;
1237  dst_a += p->linesize[3] / 2;
1238  }
1239 }
1240 
1242 {
1243  SheerVideoContext *s = avctx->priv_data;
1244  uint16_t *dst_y, *dst_u, *dst_v;
1245  int x, y;
1246 
1247  dst_y = (uint16_t *)p->data[0];
1248  dst_u = (uint16_t *)p->data[1];
1249  dst_v = (uint16_t *)p->data[2];
1250 
1251  for (y = 0; y < avctx->height; y++) {
1252  if (get_bits1(gb)) {
1253  for (x = 0; x < avctx->width; x++) {
1254  dst_y[x] = get_bits(gb, 10);
1255  dst_u[x] = get_bits(gb, 10);
1256  dst_v[x] = get_bits(gb, 10);
1257  }
1258  } else {
1259  int pred[4] = { 502, 512, 512, 512 };
1260 
1261  for (x = 0; x < avctx->width; x++) {
1262  int y, u, v;
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[0] = (y + pred[0]) & 0x3ff;
1269  dst_u[x] = pred[1] = (u + pred[1]) & 0x3ff;
1270  dst_v[x] = pred[2] = (v + pred[2]) & 0x3ff;
1271  }
1272  }
1273 
1274  dst_y += p->linesize[0] / 2;
1275  dst_u += p->linesize[1] / 2;
1276  dst_v += p->linesize[2] / 2;
1277  }
1278 }
1279 
1280 static void decode_ybr10(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
1281 {
1282  SheerVideoContext *s = avctx->priv_data;
1283  uint16_t *dst_y, *dst_u, *dst_v;
1284  int x, y;
1285 
1286  dst_y = (uint16_t *)p->data[0];
1287  dst_u = (uint16_t *)p->data[1];
1288  dst_v = (uint16_t *)p->data[2];
1289 
1290  if (get_bits1(gb)) {
1291  for (x = 0; x < avctx->width; x++) {
1292  dst_y[x] = get_bits(gb, 10);
1293  dst_u[x] = get_bits(gb, 10);
1294  dst_v[x] = get_bits(gb, 10);
1295  }
1296  } else {
1297  int pred[4] = { 502, 512, 512, 512 };
1298 
1299  for (x = 0; x < avctx->width; x++) {
1300  int y, u, v;
1301 
1302  y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1303  u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1304  v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1305 
1306  dst_y[x] = pred[0] = (y + pred[0]) & 0x3ff;
1307  dst_u[x] = pred[1] = (u + pred[1]) & 0x3ff;
1308  dst_v[x] = pred[2] = (v + pred[2]) & 0x3ff;
1309  }
1310  }
1311 
1312  dst_y += p->linesize[0] / 2;
1313  dst_u += p->linesize[1] / 2;
1314  dst_v += p->linesize[2] / 2;
1315 
1316  for (y = 1; y < avctx->height; y++) {
1317  if (get_bits1(gb)) {
1318  for (x = 0; x < avctx->width; x++) {
1319  dst_y[x] = get_bits(gb, 10);
1320  dst_u[x] = get_bits(gb, 10);
1321  dst_v[x] = get_bits(gb, 10);
1322  }
1323  } else {
1324  int pred_TL[4], pred_L[4], pred_T[4];
1325  int y, u, v;
1326 
1327  pred_TL[0] = pred_L[0] = dst_y[-p->linesize[0] / 2];
1328  pred_TL[1] = pred_L[1] = dst_u[-p->linesize[1] / 2];
1329  pred_TL[2] = pred_L[2] = dst_v[-p->linesize[2] / 2];
1330 
1331  for (x = 0; x < avctx->width; x++) {
1332  pred_T[0] = dst_y[-p->linesize[0] / 2 + x];
1333  pred_T[1] = dst_u[-p->linesize[1] / 2 + x];
1334  pred_T[2] = dst_v[-p->linesize[2] / 2 + x];
1335 
1336  y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1337  u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1338  v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1339 
1340  dst_y[x] = pred_L[0] = (y + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0x3ff;
1341  dst_u[x] = pred_L[1] = (u + ((3 * (pred_T[1] + pred_L[1]) - 2 * pred_TL[1]) >> 2)) & 0x3ff;
1342  dst_v[x] = pred_L[2] = (v + ((3 * (pred_T[2] + pred_L[2]) - 2 * pred_TL[2]) >> 2)) & 0x3ff;
1343 
1344  pred_TL[0] = pred_T[0];
1345  pred_TL[1] = pred_T[1];
1346  pred_TL[2] = pred_T[2];
1347  }
1348  }
1349 
1350  dst_y += p->linesize[0] / 2;
1351  dst_u += p->linesize[1] / 2;
1352  dst_v += p->linesize[2] / 2;
1353  }
1354 }
1355 
1357 {
1358  SheerVideoContext *s = avctx->priv_data;
1359  uint16_t *dst_y, *dst_u, *dst_v;
1360  int x, y;
1361 
1362  dst_y = (uint16_t *)p->data[0];
1363  dst_u = (uint16_t *)p->data[1];
1364  dst_v = (uint16_t *)p->data[2];
1365 
1366  for (y = 0; y < avctx->height; y++) {
1367  if (get_bits1(gb)) {
1368  for (x = 0; x < avctx->width; x += 2) {
1369  dst_y[x ] = get_bits(gb, 10);
1370  dst_u[x / 2] = get_bits(gb, 10);
1371  dst_y[x + 1] = get_bits(gb, 10);
1372  dst_v[x / 2] = get_bits(gb, 10);
1373  }
1374  } else {
1375  int pred[4] = { 502, 512, 512, 0 };
1376 
1377  for (x = 0; x < avctx->width; x += 2) {
1378  int y1, y2, u, v;
1379 
1380  y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1381  u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1382  y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1383  v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1384 
1385  dst_y[x ] = pred[0] = (y1 + pred[0]) & 0x3ff;
1386  dst_u[x / 2] = pred[1] = (u + pred[1]) & 0x3ff;
1387  dst_y[x + 1] = pred[0] = (y2 + pred[0]) & 0x3ff;
1388  dst_v[x / 2] = pred[2] = (v + pred[2]) & 0x3ff;
1389  }
1390  }
1391 
1392  dst_y += p->linesize[0] / 2;
1393  dst_u += p->linesize[1] / 2;
1394  dst_v += p->linesize[2] / 2;
1395  }
1396 }
1397 
1398 static void decode_yry10(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
1399 {
1400  SheerVideoContext *s = avctx->priv_data;
1401  uint16_t *dst_y, *dst_u, *dst_v;
1402  int x, y;
1403 
1404  dst_y = (uint16_t *)p->data[0];
1405  dst_u = (uint16_t *)p->data[1];
1406  dst_v = (uint16_t *)p->data[2];
1407 
1408  if (get_bits1(gb)) {
1409  for (x = 0; x < avctx->width; x += 2) {
1410  dst_y[x ] = get_bits(gb, 10);
1411  dst_u[x / 2] = get_bits(gb, 10);
1412  dst_y[x + 1] = get_bits(gb, 10);
1413  dst_v[x / 2] = get_bits(gb, 10);
1414  }
1415  } else {
1416  int pred[4] = { 502, 512, 512, 0 };
1417 
1418  for (x = 0; x < avctx->width; x += 2) {
1419  int y1, y2, u, v;
1420 
1421  y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1422  u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1423  y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1424  v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1425 
1426  dst_y[x ] = pred[0] = (y1 + pred[0]) & 0x3ff;
1427  dst_u[x / 2] = pred[1] = (u + pred[1]) & 0x3ff;
1428  dst_y[x + 1] = pred[0] = (y2 + pred[0]) & 0x3ff;
1429  dst_v[x / 2] = pred[2] = (v + pred[2]) & 0x3ff;
1430  }
1431  }
1432 
1433  dst_y += p->linesize[0] / 2;
1434  dst_u += p->linesize[1] / 2;
1435  dst_v += p->linesize[2] / 2;
1436 
1437  for (y = 1; y < avctx->height; y++) {
1438  if (get_bits1(gb)) {
1439  for (x = 0; x < avctx->width; x += 2) {
1440  dst_y[x ] = get_bits(gb, 10);
1441  dst_u[x / 2] = get_bits(gb, 10);
1442  dst_y[x + 1] = get_bits(gb, 10);
1443  dst_v[x / 2] = get_bits(gb, 10);
1444  }
1445  } else {
1446  int pred_TL[6], pred_L[6], pred_T[6];
1447  int y1, y2, u, v;
1448 
1449  pred_TL[0] = pred_L[0] = dst_y[-p->linesize[0] / 2];
1450  pred_TL[1] = pred_L[1] = dst_u[-p->linesize[1] / 2];
1451  pred_TL[2] = pred_L[2] = dst_v[-p->linesize[2] / 2];
1452 
1453  for (x = 0; x < avctx->width; x += 2) {
1454  pred_T[0] = dst_y[-p->linesize[0] / 2 + x];
1455  pred_T[3] = dst_y[-p->linesize[0] / 2 + x + 1];
1456  pred_T[1] = dst_u[-p->linesize[1] / 2 + x / 2];
1457  pred_T[2] = dst_v[-p->linesize[2] / 2 + x / 2];
1458 
1459  y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1460  u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1461  y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1462  v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1463 
1464  dst_y[x ] = pred_L[0] = (y1 + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0x3ff;
1465  dst_u[x / 2] = pred_L[1] = (u + (((pred_L[1] - pred_TL[1]) >> 1) + pred_T[1])) & 0x3ff;
1466  dst_y[x + 1] = pred_L[0] = (y2 + ((3 * (pred_T[3] + pred_L[0]) - 2 * pred_T[0]) >> 2)) & 0x3ff;
1467  dst_v[x / 2] = pred_L[2] = (v + (((pred_L[2] - pred_TL[2]) >> 1) + pred_T[2])) & 0x3ff;
1468 
1469  pred_TL[0] = pred_T[3];
1470  pred_TL[1] = pred_T[1];
1471  pred_TL[2] = pred_T[2];
1472  }
1473  }
1474 
1475  dst_y += p->linesize[0] / 2;
1476  dst_u += p->linesize[1] / 2;
1477  dst_v += p->linesize[2] / 2;
1478  }
1479 }
1480 
1481 static void decode_ca2i(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
1482 {
1483  SheerVideoContext *s = avctx->priv_data;
1484  uint16_t *dst_y, *dst_u, *dst_v, *dst_a;
1485  int x, y;
1486 
1487  dst_y = (uint16_t *)p->data[0];
1488  dst_u = (uint16_t *)p->data[1];
1489  dst_v = (uint16_t *)p->data[2];
1490  dst_a = (uint16_t *)p->data[3];
1491 
1492  for (y = 0; y < avctx->height; y++) {
1493  if (get_bits1(gb)) {
1494  for (x = 0; x < avctx->width; x += 2) {
1495  dst_a[x ] = get_bits(gb, 10);
1496  dst_y[x ] = get_bits(gb, 10);
1497  dst_u[x / 2] = get_bits(gb, 10);
1498  dst_a[x + 1] = get_bits(gb, 10);
1499  dst_y[x + 1] = get_bits(gb, 10);
1500  dst_v[x / 2] = get_bits(gb, 10);
1501  }
1502  } else {
1503  int pred[4] = { 502, 512, 512, 502 };
1504 
1505  for (x = 0; x < avctx->width; x += 2) {
1506  int y1, y2, u, v, a1, a2;
1507 
1508  a1 = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1509  y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1510  u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1511  a2 = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1512  y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1513  v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1514 
1515  dst_y[x ] = pred[0] = (y1 + pred[0]) & 0x3ff;
1516  dst_u[x / 2] = pred[1] = (u + pred[1]) & 0x3ff;
1517  dst_y[x + 1] = pred[0] = (y2 + pred[0]) & 0x3ff;
1518  dst_a[x ] = pred[3] = (a1 + pred[3]) & 0x3ff;
1519  dst_v[x / 2] = pred[2] = (v + pred[2]) & 0x3ff;
1520  dst_a[x + 1] = pred[3] = (a2 + pred[3]) & 0x3ff;
1521  }
1522  }
1523 
1524  dst_y += p->linesize[0] / 2;
1525  dst_u += p->linesize[1] / 2;
1526  dst_v += p->linesize[2] / 2;
1527  dst_a += p->linesize[3] / 2;
1528  }
1529 }
1530 
1531 static void decode_ca2p(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
1532 {
1533  SheerVideoContext *s = avctx->priv_data;
1534  uint16_t *dst_y, *dst_u, *dst_v, *dst_a;
1535  int x, y;
1536 
1537  dst_y = (uint16_t *)p->data[0];
1538  dst_u = (uint16_t *)p->data[1];
1539  dst_v = (uint16_t *)p->data[2];
1540  dst_a = (uint16_t *)p->data[3];
1541 
1542  if (get_bits1(gb)) {
1543  for (x = 0; x < avctx->width; x += 2) {
1544  dst_a[x ] = get_bits(gb, 10);
1545  dst_y[x ] = get_bits(gb, 10);
1546  dst_u[x / 2] = get_bits(gb, 10);
1547  dst_a[x + 1] = get_bits(gb, 10);
1548  dst_y[x + 1] = get_bits(gb, 10);
1549  dst_v[x / 2] = get_bits(gb, 10);
1550  }
1551  } else {
1552  int pred[4] = { 502, 512, 512, 502 };
1553 
1554  for (x = 0; x < avctx->width; x += 2) {
1555  int y1, y2, u, v, a1, a2;
1556 
1557  a1 = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1558  y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1559  u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1560  a2 = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1561  y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1562  v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1563 
1564  dst_y[x ] = pred[0] = (y1 + pred[0]) & 0x3ff;
1565  dst_u[x / 2] = pred[1] = (u + pred[1]) & 0x3ff;
1566  dst_y[x + 1] = pred[0] = (y2 + pred[0]) & 0x3ff;
1567  dst_a[x ] = pred[3] = (a1 + pred[3]) & 0x3ff;
1568  dst_v[x / 2] = pred[2] = (v + pred[2]) & 0x3ff;
1569  dst_a[x + 1] = pred[3] = (a2 + pred[3]) & 0x3ff;
1570  }
1571  }
1572 
1573  dst_y += p->linesize[0] / 2;
1574  dst_u += p->linesize[1] / 2;
1575  dst_v += p->linesize[2] / 2;
1576  dst_a += p->linesize[3] / 2;
1577 
1578  for (y = 1; y < avctx->height; y++) {
1579  if (get_bits1(gb)) {
1580  for (x = 0; x < avctx->width; x += 2) {
1581  dst_a[x ] = get_bits(gb, 10);
1582  dst_y[x ] = get_bits(gb, 10);
1583  dst_u[x / 2] = get_bits(gb, 10);
1584  dst_a[x + 1] = get_bits(gb, 10);
1585  dst_y[x + 1] = get_bits(gb, 10);
1586  dst_v[x / 2] = get_bits(gb, 10);
1587  }
1588  } else {
1589  int pred_TL[6], pred_L[6], pred_T[6];
1590  int y1, y2, u, v, a1, a2;
1591 
1592  pred_TL[0] = pred_L[0] = dst_y[-p->linesize[0] / 2];
1593  pred_TL[1] = pred_L[1] = dst_u[-p->linesize[1] / 2];
1594  pred_TL[2] = pred_L[2] = dst_v[-p->linesize[2] / 2];
1595  pred_TL[4] = pred_L[4] = dst_a[-p->linesize[3] / 2];
1596 
1597  for (x = 0; x < avctx->width; x += 2) {
1598  pred_T[0] = dst_y[-p->linesize[0] / 2 + x];
1599  pred_T[3] = dst_y[-p->linesize[0] / 2 + x + 1];
1600  pred_T[1] = dst_u[-p->linesize[1] / 2 + x / 2];
1601  pred_T[2] = dst_v[-p->linesize[2] / 2 + x / 2];
1602  pred_T[4] = dst_a[-p->linesize[3] / 2 + x];
1603  pred_T[5] = dst_a[-p->linesize[3] / 2 + x + 1];
1604 
1605  a1 = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1606  y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1607  u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1608  a2 = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1609  y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1610  v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1611 
1612  dst_y[x ] = pred_L[0] = (y1 + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0x3ff;
1613  dst_u[x / 2] = pred_L[1] = (u + (((pred_L[1] - pred_TL[1]) >> 1) + pred_T[1])) & 0x3ff;
1614  dst_y[x + 1] = pred_L[0] = (y2 + ((3 * (pred_T[3] + pred_L[0]) - 2 * pred_T[0]) >> 2)) & 0x3ff;
1615  dst_v[x / 2] = pred_L[2] = (v + (((pred_L[2] - pred_TL[2]) >> 1) + pred_T[2])) & 0x3ff;
1616  dst_a[x ] = pred_L[4] = (a1 + ((3 * (pred_T[4] + pred_L[4]) - 2 * pred_TL[4]) >> 2)) & 0x3ff;
1617  dst_a[x + 1] = pred_L[4] = (a2 + ((3 * (pred_T[5] + pred_L[4]) - 2 * pred_T[4]) >> 2)) & 0x3ff;
1618 
1619  pred_TL[0] = pred_T[3];
1620  pred_TL[1] = pred_T[1];
1621  pred_TL[2] = pred_T[2];
1622  pred_TL[4] = pred_T[5];
1623  }
1624  }
1625 
1626  dst_y += p->linesize[0] / 2;
1627  dst_u += p->linesize[1] / 2;
1628  dst_v += p->linesize[2] / 2;
1629  dst_a += p->linesize[3] / 2;
1630  }
1631 }
1632 
1633 static void decode_c82i(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
1634 {
1635  SheerVideoContext *s = avctx->priv_data;
1636  uint8_t *dst_y, *dst_u, *dst_v, *dst_a;
1637  int x, y;
1638 
1639  dst_y = p->data[0];
1640  dst_u = p->data[1];
1641  dst_v = p->data[2];
1642  dst_a = p->data[3];
1643 
1644  for (y = 0; y < avctx->height; y += 1) {
1645  if (get_bits1(gb)) {
1646  for (x = 0; x < avctx->width; x += 2) {
1647  dst_a[x ] = get_bits(gb, 8);
1648  dst_y[x ] = get_bits(gb, 8);
1649  dst_u[x / 2] = get_bits(gb, 8);
1650  dst_a[x + 1] = get_bits(gb, 8);
1651  dst_y[x + 1] = get_bits(gb, 8);
1652  dst_v[x / 2] = get_bits(gb, 8);
1653  }
1654  } else {
1655  int pred[4] = { 125, -128, -128, 125 };
1656 
1657  for (x = 0; x < avctx->width; x += 2) {
1658  int y1, y2, u, v, a1, a2;
1659 
1660  a1 = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1661  y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1662  u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1663  a2 = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1664  y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1665  v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1666 
1667  dst_y[x ] = pred[0] = (y1 + pred[0]) & 0xff;
1668  dst_y[x + 1] = pred[0] = (y2 + pred[0]) & 0xff;
1669  dst_u[x / 2] = pred[1] = (u + pred[1]) & 0xff;
1670  dst_v[x / 2] = pred[2] = (v + pred[2]) & 0xff;
1671  dst_a[x ] = pred[3] = (a1 + pred[3]) & 0xff;
1672  dst_a[x + 1] = pred[3] = (a2 + pred[3]) & 0xff;
1673  }
1674  }
1675 
1676  dst_y += p->linesize[0];
1677  dst_u += p->linesize[1];
1678  dst_v += p->linesize[2];
1679  dst_a += p->linesize[3];
1680  }
1681 }
1682 
1683 static void decode_c82p(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
1684 {
1685  SheerVideoContext *s = avctx->priv_data;
1686  uint8_t *dst_y, *dst_u, *dst_v, *dst_a;
1687  int x, y;
1688 
1689  dst_y = p->data[0];
1690  dst_u = p->data[1];
1691  dst_v = p->data[2];
1692  dst_a = p->data[3];
1693 
1694  if (get_bits1(gb)) {
1695  for (x = 0; x < avctx->width; x += 2) {
1696  dst_a[x ] = get_bits(gb, 8);
1697  dst_y[x ] = get_bits(gb, 8);
1698  dst_u[x / 2] = get_bits(gb, 8);
1699  dst_a[x + 1] = get_bits(gb, 8);
1700  dst_y[x + 1] = get_bits(gb, 8);
1701  dst_v[x / 2] = get_bits(gb, 8);
1702  }
1703  } else {
1704  int pred[4] = { 125, -128, -128, 125 };
1705 
1706  for (x = 0; x < avctx->width; x += 2) {
1707  int y1, y2, u, v, a1, a2;
1708 
1709  a1 = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1710  y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1711  u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1712  a2 = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1713  y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1714  v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1715 
1716  dst_y[x ] = pred[0] = (y1 + pred[0]) & 0xff;
1717  dst_u[x / 2] = pred[1] = (u + pred[1]) & 0xff;
1718  dst_y[x + 1] = pred[0] = (y2 + pred[0]) & 0xff;
1719  dst_a[x ] = pred[3] = (a1 + pred[3]) & 0xff;
1720  dst_v[x / 2] = pred[2] = (v + pred[2]) & 0xff;
1721  dst_a[x + 1] = pred[3] = (a2 + pred[3]) & 0xff;
1722  }
1723  }
1724 
1725  dst_y += p->linesize[0];
1726  dst_u += p->linesize[1];
1727  dst_v += p->linesize[2];
1728  dst_a += p->linesize[3];
1729 
1730  for (y = 1; y < avctx->height; y++) {
1731  if (get_bits1(gb)) {
1732  for (x = 0; x < avctx->width; x += 2) {
1733  dst_a[x ] = get_bits(gb, 8);
1734  dst_y[x ] = get_bits(gb, 8);
1735  dst_u[x / 2] = get_bits(gb, 8);
1736  dst_a[x + 1] = get_bits(gb, 8);
1737  dst_y[x + 1] = get_bits(gb, 8);
1738  dst_v[x / 2] = get_bits(gb, 8);
1739  }
1740  } else {
1741  int pred_TL[6], pred_L[6], pred_T[6];
1742  int y1, y2, u, v, a1, a2;
1743 
1744  pred_TL[0] = pred_L[0] = dst_y[-p->linesize[0]];
1745  pred_TL[1] = pred_L[1] = dst_u[-p->linesize[1]];
1746  pred_TL[2] = pred_L[2] = dst_v[-p->linesize[2]];
1747  pred_TL[4] = pred_L[4] = dst_a[-p->linesize[3]];
1748 
1749  for (x = 0; x < avctx->width; x += 2) {
1750  pred_T[0] = dst_y[-p->linesize[0] + x];
1751  pred_T[3] = dst_y[-p->linesize[0] + x + 1];
1752  pred_T[1] = dst_u[-p->linesize[1] + x / 2];
1753  pred_T[2] = dst_v[-p->linesize[2] + x / 2];
1754  pred_T[4] = dst_a[-p->linesize[3] + x];
1755  pred_T[5] = dst_a[-p->linesize[3] + x + 1];
1756 
1757  a1 = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1758  y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1759  u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1760  a2 = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1761  y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1762  v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1763 
1764  dst_y[x ] = pred_L[0] = (y1 + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0xff;
1765  dst_u[x / 2] = pred_L[1] = (u + (((pred_L[1] - pred_TL[1]) >> 1) + pred_T[1])) & 0xff;
1766  dst_y[x + 1] = pred_L[0] = (y2 + ((3 * (pred_T[3] + pred_L[0]) - 2 * pred_T[0]) >> 2)) & 0xff;
1767  dst_v[x / 2] = pred_L[2] = (v + (((pred_L[2] - pred_TL[2]) >> 1) + pred_T[2])) & 0xff;
1768  dst_a[x ] = pred_L[4] = (a1 + ((3 * (pred_T[4] + pred_L[4]) - 2 * pred_TL[4]) >> 2)) & 0xff;
1769  dst_a[x + 1] = pred_L[4] = (a2 + ((3 * (pred_T[5] + pred_L[4]) - 2 * pred_T[4]) >> 2)) & 0xff;
1770 
1771  pred_TL[0] = pred_T[3];
1772  pred_TL[1] = pred_T[1];
1773  pred_TL[2] = pred_T[2];
1774  pred_TL[4] = pred_T[5];
1775  }
1776  }
1777 
1778  dst_y += p->linesize[0];
1779  dst_u += p->linesize[1];
1780  dst_v += p->linesize[2];
1781  dst_a += p->linesize[3];
1782  }
1783 }
1784 
1785 static void decode_ybyr(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
1786 {
1787  SheerVideoContext *s = avctx->priv_data;
1788  uint8_t *dst_y, *dst_u, *dst_v;
1789  int x, y;
1790 
1791  dst_y = p->data[0];
1792  dst_u = p->data[1];
1793  dst_v = p->data[2];
1794 
1795  if (get_bits1(gb)) {
1796  for (x = 0; x < avctx->width; x += 2) {
1797  dst_y[x ] = get_bits(gb, 8);
1798  dst_u[x / 2] = get_bits(gb, 8) + 128;
1799  dst_y[x + 1] = get_bits(gb, 8);
1800  dst_v[x / 2] = get_bits(gb, 8) + 128;
1801  }
1802  } else {
1803  int pred[4] = { -128, 128, 128, 0 };
1804 
1805  for (x = 0; x < avctx->width; x += 2) {
1806  int y1, y2, u, v;
1807 
1808  y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1809  u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1810  y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1811  v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1812 
1813  dst_y[x ] = pred[0] = (y1 + pred[0]) & 0xff;
1814  dst_u[x / 2] = pred[1] = (u + pred[1]) & 0xff;
1815  dst_y[x + 1] = pred[0] = (y2 + pred[0]) & 0xff;
1816  dst_v[x / 2] = pred[2] = (v + pred[2]) & 0xff;
1817  }
1818  }
1819 
1820  dst_y += p->linesize[0];
1821  dst_u += p->linesize[1];
1822  dst_v += p->linesize[2];
1823 
1824  for (y = 1; y < avctx->height; y++) {
1825  if (get_bits1(gb)) {
1826  for (x = 0; x < avctx->width; x += 2) {
1827  dst_y[x ] = get_bits(gb, 8);
1828  dst_u[x / 2] = get_bits(gb, 8) + 128;
1829  dst_y[x + 1] = get_bits(gb, 8);
1830  dst_v[x / 2] = get_bits(gb, 8) + 128;
1831  }
1832  } else {
1833  int pred_TL[4], pred_L[4], pred_T[4];
1834  int y1, y2, u, v;
1835 
1836  pred_TL[0] = pred_L[0] = dst_y[-p->linesize[0]];
1837  pred_TL[1] = pred_L[1] = dst_u[-p->linesize[1]];
1838  pred_TL[2] = pred_L[2] = dst_v[-p->linesize[2]];
1839 
1840  for (x = 0; x < avctx->width; x += 2) {
1841  pred_T[0] = dst_y[-p->linesize[0] + x];
1842  pred_T[3] = dst_y[-p->linesize[0] + x + 1];
1843  pred_T[1] = dst_u[-p->linesize[1] + x / 2];
1844  pred_T[2] = dst_v[-p->linesize[2] + x / 2];
1845 
1846  y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1847  u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1848  y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1849  v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1850 
1851  dst_y[x ] = pred_L[0] = (y1 + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0xff;
1852  dst_u[x / 2] = pred_L[1] = (u + (((pred_L[1] - pred_TL[1]) >> 1) + pred_T[1])) & 0xff;
1853  dst_y[x + 1] = pred_L[0] = (y2 + ((3 * (pred_T[3] + pred_L[0]) - 2 * pred_T[0]) >> 2)) & 0xff;
1854  dst_v[x / 2] = pred_L[2] = (v + (((pred_L[2] - pred_TL[2]) >> 1) + pred_T[2])) & 0xff;
1855 
1856  pred_TL[0] = pred_T[3];
1857  pred_TL[1] = pred_T[1];
1858  pred_TL[2] = pred_T[2];
1859  }
1860  }
1861 
1862  dst_y += p->linesize[0];
1863  dst_u += p->linesize[1];
1864  dst_v += p->linesize[2];
1865  }
1866 }
1867 
1868 static void decode_byryi(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
1869 {
1870  SheerVideoContext *s = avctx->priv_data;
1871  uint8_t *dst_y, *dst_u, *dst_v;
1872  int x, y;
1873 
1874  dst_y = p->data[0];
1875  dst_u = p->data[1];
1876  dst_v = p->data[2];
1877 
1878  if (get_bits1(gb)) {
1879  for (x = 0; x < avctx->width; x += 2) {
1880  dst_y[x ] = get_bits(gb, 8);
1881  dst_u[x / 2] = get_bits(gb, 8);
1882  dst_y[x + 1] = get_bits(gb, 8);
1883  dst_v[x / 2] = get_bits(gb, 8);
1884  }
1885  } else {
1886  int pred[4] = { 125, -128, -128, 0 };
1887 
1888  for (x = 0; x < avctx->width; x += 2) {
1889  int y1, y2, u, v;
1890 
1891  y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1892  u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1893  y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1894  v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1895 
1896  dst_y[x ] = pred[0] = (y1 + pred[0]) & 0xff;
1897  dst_u[x / 2] = pred[1] = (u + pred[1]) & 0xff;
1898  dst_y[x + 1] = pred[0] = (y2 + pred[0]) & 0xff;
1899  dst_v[x / 2] = pred[2] = (v + pred[2]) & 0xff;
1900  }
1901  }
1902 
1903  dst_y += p->linesize[0];
1904  dst_u += p->linesize[1];
1905  dst_v += p->linesize[2];
1906 
1907  for (y = 1; y < avctx->height; y++) {
1908  if (get_bits1(gb)) {
1909  for (x = 0; x < avctx->width; x += 2) {
1910  dst_y[x ] = get_bits(gb, 8);
1911  dst_u[x / 2] = get_bits(gb, 8);
1912  dst_y[x + 1] = get_bits(gb, 8);
1913  dst_v[x / 2] = get_bits(gb, 8);
1914  }
1915  } else {
1916  int pred_L[4];
1917  int y1, y2, u, v;
1918 
1919  pred_L[0] = dst_y[-p->linesize[0]];
1920  pred_L[1] = dst_u[-p->linesize[1]];
1921  pred_L[2] = dst_v[-p->linesize[2]];
1922 
1923  for (x = 0; x < avctx->width; x += 2) {
1924  y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1925  u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1926  y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1927  v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1928 
1929  dst_y[x ] = pred_L[0] = (y1 + pred_L[0]) & 0xff;
1930  dst_u[x / 2] = pred_L[1] = (u + pred_L[1]) & 0xff;
1931  dst_y[x + 1] = pred_L[0] = (y2 + pred_L[0]) & 0xff;
1932  dst_v[x / 2] = pred_L[2] = (v + pred_L[2]) & 0xff;
1933  }
1934  }
1935 
1936  dst_y += p->linesize[0];
1937  dst_u += p->linesize[1];
1938  dst_v += p->linesize[2];
1939  }
1940 }
1941 
1942 static void decode_byry(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
1943 {
1944  SheerVideoContext *s = avctx->priv_data;
1945  uint8_t *dst_y, *dst_u, *dst_v;
1946  int x, y;
1947 
1948  dst_y = p->data[0];
1949  dst_u = p->data[1];
1950  dst_v = p->data[2];
1951 
1952  if (get_bits1(gb)) {
1953  for (x = 0; x < avctx->width; x += 2) {
1954  dst_y[x ] = get_bits(gb, 8);
1955  dst_u[x / 2] = get_bits(gb, 8);
1956  dst_y[x + 1] = get_bits(gb, 8);
1957  dst_v[x / 2] = get_bits(gb, 8);
1958  }
1959  } else {
1960  int pred[4] = { 125, -128, -128, 0 };
1961 
1962  for (x = 0; x < avctx->width; x += 2) {
1963  int y1, y2, u, v;
1964 
1965  y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1966  u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1967  y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1968  v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1969 
1970  dst_y[x ] = pred[0] = (y1 + pred[0]) & 0xff;
1971  dst_u[x / 2] = pred[1] = (u + pred[1]) & 0xff;
1972  dst_y[x + 1] = pred[0] = (y2 + pred[0]) & 0xff;
1973  dst_v[x / 2] = pred[2] = (v + pred[2]) & 0xff;
1974  }
1975  }
1976 
1977  dst_y += p->linesize[0];
1978  dst_u += p->linesize[1];
1979  dst_v += p->linesize[2];
1980 
1981  for (y = 1; y < avctx->height; y++) {
1982  if (get_bits1(gb)) {
1983  for (x = 0; x < avctx->width; x += 2) {
1984  dst_y[x ] = get_bits(gb, 8);
1985  dst_u[x / 2] = get_bits(gb, 8);
1986  dst_y[x + 1] = get_bits(gb, 8);
1987  dst_v[x / 2] = get_bits(gb, 8);
1988  }
1989  } else {
1990  int pred_TL[4], pred_L[4], pred_T[4];
1991  int y1, y2, u, v;
1992 
1993  pred_TL[0] = pred_L[0] = dst_y[-p->linesize[0]];
1994  pred_TL[1] = pred_L[1] = dst_u[-p->linesize[1]];
1995  pred_TL[2] = pred_L[2] = dst_v[-p->linesize[2]];
1996 
1997  for (x = 0; x < avctx->width; x += 2) {
1998  pred_T[0] = dst_y[-p->linesize[0] + x];
1999  pred_T[3] = dst_y[-p->linesize[0] + x + 1];
2000  pred_T[1] = dst_u[-p->linesize[1] + x / 2];
2001  pred_T[2] = dst_v[-p->linesize[2] + x / 2];
2002 
2003  y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
2004  u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2005  y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
2006  v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2007 
2008  dst_y[x ] = pred_L[0] = (y1 + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0xff;
2009  dst_u[x / 2] = pred_L[1] = (u + (((pred_L[1] - pred_TL[1]) >> 1) + pred_T[1])) & 0xff;
2010  dst_y[x + 1] = pred_L[0] = (y2 + ((3 * (pred_T[3] + pred_L[0]) - 2 * pred_T[0]) >> 2)) & 0xff;
2011  dst_v[x / 2] = pred_L[2] = (v + (((pred_L[2] - pred_TL[2]) >> 1) + pred_T[2])) & 0xff;
2012 
2013  pred_TL[0] = pred_T[3];
2014  pred_TL[1] = pred_T[1];
2015  pred_TL[2] = pred_T[2];
2016  }
2017  }
2018 
2019  dst_y += p->linesize[0];
2020  dst_u += p->linesize[1];
2021  dst_v += p->linesize[2];
2022  }
2023 }
2024 
2025 static void decode_ybri(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
2026 {
2027  SheerVideoContext *s = avctx->priv_data;
2028  uint8_t *dst_y, *dst_u, *dst_v;
2029  int x, y;
2030 
2031  dst_y = p->data[0];
2032  dst_u = p->data[1];
2033  dst_v = p->data[2];
2034 
2035  if (get_bits1(gb)) {
2036  for (x = 0; x < avctx->width; x++) {
2037  dst_y[x] = get_bits(gb, 8);
2038  dst_u[x] = get_bits(gb, 8);
2039  dst_v[x] = get_bits(gb, 8);
2040  }
2041  } else {
2042  int pred[4] = { s->alt ? 125 : -146, -128, -128, -128 };
2043 
2044  for (x = 0; x < avctx->width; x++) {
2045  int y, u, v;
2046 
2047  y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
2048  u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2049  v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2050 
2051  dst_y[x] = pred[0] = (y + pred[0]) & 0xff;
2052  dst_u[x] = pred[1] = (u + pred[1]) & 0xff;
2053  dst_v[x] = pred[2] = (v + pred[2]) & 0xff;
2054  }
2055  }
2056 
2057  dst_y += p->linesize[0];
2058  dst_u += p->linesize[1];
2059  dst_v += p->linesize[2];
2060 
2061  for (y = 1; y < avctx->height; y++) {
2062  if (get_bits1(gb)) {
2063  for (x = 0; x < avctx->width; x++) {
2064  dst_y[x] = get_bits(gb, 8);
2065  dst_u[x] = get_bits(gb, 8);
2066  dst_v[x] = get_bits(gb, 8);
2067  }
2068  } else {
2069  int pred_L[4];
2070  int y, u, v;
2071 
2072  pred_L[0] = dst_y[-p->linesize[0]];
2073  pred_L[1] = dst_u[-p->linesize[1]];
2074  pred_L[2] = dst_v[-p->linesize[2]];
2075 
2076  for (x = 0; x < avctx->width; x++) {
2077  y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
2078  u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2079  v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2080 
2081  dst_y[x] = pred_L[0] = (y + pred_L[0]) & 0xff;
2082  dst_u[x] = pred_L[1] = (u + pred_L[1]) & 0xff;
2083  dst_v[x] = pred_L[2] = (v + pred_L[2]) & 0xff;
2084  }
2085  }
2086 
2087  dst_y += p->linesize[0];
2088  dst_u += p->linesize[1];
2089  dst_v += p->linesize[2];
2090  }
2091 }
2092 
2093 static void decode_ybr(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
2094 {
2095  SheerVideoContext *s = avctx->priv_data;
2096  uint8_t *dst_y, *dst_u, *dst_v;
2097  int x, y;
2098 
2099  dst_y = p->data[0];
2100  dst_u = p->data[1];
2101  dst_v = p->data[2];
2102 
2103  if (get_bits1(gb)) {
2104  for (x = 0; x < avctx->width; x++) {
2105  dst_y[x] = get_bits(gb, 8);
2106  dst_u[x] = get_bits(gb, 8);
2107  dst_v[x] = get_bits(gb, 8);
2108  }
2109  } else {
2110  int pred[4] = { s->alt ? 125 : -146, -128, -128, -128 };
2111 
2112  for (x = 0; x < avctx->width; x++) {
2113  int y, u, v;
2114 
2115  y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
2116  u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2117  v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2118 
2119  dst_y[x] = pred[0] = (y + pred[0]) & 0xff;
2120  dst_u[x] = pred[1] = (u + pred[1]) & 0xff;
2121  dst_v[x] = pred[2] = (v + pred[2]) & 0xff;
2122  }
2123  }
2124 
2125  dst_y += p->linesize[0];
2126  dst_u += p->linesize[1];
2127  dst_v += p->linesize[2];
2128 
2129  for (y = 1; y < avctx->height; y++) {
2130  if (get_bits1(gb)) {
2131  for (x = 0; x < avctx->width; x++) {
2132  dst_y[x] = get_bits(gb, 8);
2133  dst_u[x] = get_bits(gb, 8);
2134  dst_v[x] = get_bits(gb, 8);
2135  }
2136  } else {
2137  int pred_TL[4], pred_L[4], pred_T[4];
2138  int y, u, v;
2139 
2140  pred_TL[0] = pred_L[0] = dst_y[-p->linesize[0]];
2141  pred_TL[1] = pred_L[1] = dst_u[-p->linesize[1]];
2142  pred_TL[2] = pred_L[2] = dst_v[-p->linesize[2]];
2143 
2144  for (x = 0; x < avctx->width; x++) {
2145  pred_T[0] = dst_y[-p->linesize[0] + x];
2146  pred_T[1] = dst_u[-p->linesize[1] + x];
2147  pred_T[2] = dst_v[-p->linesize[2] + x];
2148 
2149  y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
2150  u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2151  v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2152 
2153  dst_y[x] = pred_L[0] = (y + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0xff;
2154  dst_u[x] = pred_L[1] = (u + ((3 * (pred_T[1] + pred_L[1]) - 2 * pred_TL[1]) >> 2)) & 0xff;
2155  dst_v[x] = pred_L[2] = (v + ((3 * (pred_T[2] + pred_L[2]) - 2 * pred_TL[2]) >> 2)) & 0xff;
2156 
2157  pred_TL[0] = pred_T[0];
2158  pred_TL[1] = pred_T[1];
2159  pred_TL[2] = pred_T[2];
2160  }
2161  }
2162 
2163  dst_y += p->linesize[0];
2164  dst_u += p->linesize[1];
2165  dst_v += p->linesize[2];
2166  }
2167 }
2168 
2169 static void decode_aybri(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
2170 {
2171  SheerVideoContext *s = avctx->priv_data;
2172  uint8_t *dst_a, *dst_y, *dst_u, *dst_v;
2173  int x, y;
2174 
2175  dst_a = p->data[3];
2176  dst_y = p->data[0];
2177  dst_u = p->data[1];
2178  dst_v = p->data[2];
2179 
2180  if (get_bits1(gb)) {
2181  for (x = 0; x < avctx->width; x++) {
2182  dst_a[x] = get_bits(gb, 8);
2183  dst_y[x] = get_bits(gb, 8);
2184  dst_u[x] = get_bits(gb, 8);
2185  dst_v[x] = get_bits(gb, 8);
2186  }
2187  } else {
2188  int pred[4] = { 125, s->alt ? 125 : -146, -128, -128 };
2189 
2190  for (x = 0; x < avctx->width; x++) {
2191  int a, y, u, v;
2192 
2193  a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2194  y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
2195  u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2196  v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2197 
2198  dst_a[x] = pred[0] = (a + pred[0]) & 0xff;
2199  dst_y[x] = pred[1] = (y + pred[1]) & 0xff;
2200  dst_u[x] = pred[2] = (u + pred[2]) & 0xff;
2201  dst_v[x] = pred[3] = (v + pred[3]) & 0xff;
2202  }
2203  }
2204 
2205  dst_a += p->linesize[3];
2206  dst_y += p->linesize[0];
2207  dst_u += p->linesize[1];
2208  dst_v += p->linesize[2];
2209 
2210  for (y = 1; y < avctx->height; y++) {
2211  if (get_bits1(gb)) {
2212  for (x = 0; x < avctx->width; x++) {
2213  dst_a[x] = get_bits(gb, 8);
2214  dst_y[x] = get_bits(gb, 8);
2215  dst_u[x] = get_bits(gb, 8);
2216  dst_v[x] = get_bits(gb, 8);
2217  }
2218  } else {
2219  int pred_L[4];
2220  int a, y, u, v;
2221 
2222  pred_L[0] = dst_a[-p->linesize[3]];
2223  pred_L[1] = dst_y[-p->linesize[0]];
2224  pred_L[2] = dst_u[-p->linesize[1]];
2225  pred_L[3] = dst_v[-p->linesize[2]];
2226 
2227  for (x = 0; x < avctx->width; x++) {
2228  a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2229  y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
2230  u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2231  v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2232 
2233  dst_a[x] = pred_L[0] = (a + pred_L[0]) & 0xff;
2234  dst_y[x] = pred_L[1] = (y + pred_L[1]) & 0xff;
2235  dst_u[x] = pred_L[2] = (u + pred_L[2]) & 0xff;
2236  dst_v[x] = pred_L[3] = (v + pred_L[3]) & 0xff;
2237  }
2238  }
2239 
2240  dst_a += p->linesize[3];
2241  dst_y += p->linesize[0];
2242  dst_u += p->linesize[1];
2243  dst_v += p->linesize[2];
2244  }
2245 }
2246 
2247 static void decode_aybr(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
2248 {
2249  SheerVideoContext *s = avctx->priv_data;
2250  uint8_t *dst_a, *dst_y, *dst_u, *dst_v;
2251  int x, y;
2252 
2253  dst_a = p->data[3];
2254  dst_y = p->data[0];
2255  dst_u = p->data[1];
2256  dst_v = p->data[2];
2257 
2258  if (get_bits1(gb)) {
2259  for (x = 0; x < avctx->width; x++) {
2260  dst_a[x] = get_bits(gb, 8);
2261  dst_y[x] = get_bits(gb, 8);
2262  dst_u[x] = get_bits(gb, 8);
2263  dst_v[x] = get_bits(gb, 8);
2264  }
2265  } else {
2266  int pred[4] = { 125, s->alt ? 125 : -146, -128, -128 };
2267 
2268  for (x = 0; x < avctx->width; x++) {
2269  int a, y, u, v;
2270 
2271  a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2272  y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
2273  u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2274  v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2275 
2276  dst_a[x] = pred[0] = (a + pred[0]) & 0xff;
2277  dst_y[x] = pred[1] = (y + pred[1]) & 0xff;
2278  dst_u[x] = pred[2] = (u + pred[2]) & 0xff;
2279  dst_v[x] = pred[3] = (v + pred[3]) & 0xff;
2280  }
2281  }
2282 
2283  dst_a += p->linesize[3];
2284  dst_y += p->linesize[0];
2285  dst_u += p->linesize[1];
2286  dst_v += p->linesize[2];
2287 
2288  for (y = 1; y < avctx->height; y++) {
2289  if (get_bits1(gb)) {
2290  for (x = 0; x < avctx->width; x++) {
2291  dst_a[x] = get_bits(gb, 8);
2292  dst_y[x] = get_bits(gb, 8);
2293  dst_u[x] = get_bits(gb, 8);
2294  dst_v[x] = get_bits(gb, 8);
2295  }
2296  } else {
2297  int pred_TL[4], pred_L[4], pred_T[4];
2298  int a, y, u, v;
2299 
2300  pred_TL[0] = pred_L[0] = dst_a[-p->linesize[3]];
2301  pred_TL[1] = pred_L[1] = dst_y[-p->linesize[0]];
2302  pred_TL[2] = pred_L[2] = dst_u[-p->linesize[1]];
2303  pred_TL[3] = pred_L[3] = dst_v[-p->linesize[2]];
2304 
2305  for (x = 0; x < avctx->width; x++) {
2306  pred_T[0] = dst_a[-p->linesize[3] + x];
2307  pred_T[1] = dst_y[-p->linesize[0] + x];
2308  pred_T[2] = dst_u[-p->linesize[1] + x];
2309  pred_T[3] = dst_v[-p->linesize[2] + x];
2310 
2311  a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2312  y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
2313  u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2314  v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2315 
2316  dst_a[x] = pred_L[0] = (a + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0xff;
2317  dst_y[x] = pred_L[1] = (y + ((3 * (pred_T[1] + pred_L[1]) - 2 * pred_TL[1]) >> 2)) & 0xff;
2318  dst_u[x] = pred_L[2] = (u + ((3 * (pred_T[2] + pred_L[2]) - 2 * pred_TL[2]) >> 2)) & 0xff;
2319  dst_v[x] = pred_L[3] = (v + ((3 * (pred_T[3] + pred_L[3]) - 2 * pred_TL[3]) >> 2)) & 0xff;
2320 
2321  pred_TL[0] = pred_T[0];
2322  pred_TL[1] = pred_T[1];
2323  pred_TL[2] = pred_T[2];
2324  pred_TL[3] = pred_T[3];
2325  }
2326  }
2327 
2328  dst_a += p->linesize[3];
2329  dst_y += p->linesize[0];
2330  dst_u += p->linesize[1];
2331  dst_v += p->linesize[2];
2332  }
2333 }
2334 
2335 static void decode_argxi(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
2336 {
2337  SheerVideoContext *s = avctx->priv_data;
2338  uint16_t *dst_r, *dst_g, *dst_b, *dst_a;
2339  int x, y;
2340 
2341  dst_r = (uint16_t *)p->data[2];
2342  dst_g = (uint16_t *)p->data[0];
2343  dst_b = (uint16_t *)p->data[1];
2344  dst_a = (uint16_t *)p->data[3];
2345 
2346  for (y = 0; y < avctx->height; y++) {
2347  if (get_bits1(gb)) {
2348  for (x = 0; x < avctx->width; x++) {
2349  dst_a[x] = get_bits(gb, 10);
2350  dst_r[x] = get_bits(gb, 10);
2351  dst_g[x] = get_bits(gb, 10);
2352  dst_b[x] = get_bits(gb, 10);
2353  }
2354  } else {
2355  int pred[4] = { 512, 512, 512, 512 };
2356 
2357  for (x = 0; x < avctx->width; x++) {
2358  int r, g, b, a;
2359 
2360  a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2361  r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
2362  g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2363  b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2364 
2365  dst_a[x] = pred[3] = (a + pred[3]) & 0x3ff;
2366  dst_r[x] = pred[0] = (r + pred[0]) & 0x3ff;
2367  dst_g[x] = pred[1] = (r + g + pred[1]) & 0x3ff;
2368  dst_b[x] = pred[2] = (r + g + b + pred[2]) & 0x3ff;
2369  }
2370  }
2371 
2372  dst_r += p->linesize[2] / 2;
2373  dst_g += p->linesize[0] / 2;
2374  dst_b += p->linesize[1] / 2;
2375  dst_a += p->linesize[3] / 2;
2376  }
2377 }
2378 
2379 static void decode_argx(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
2380 {
2381  SheerVideoContext *s = avctx->priv_data;
2382  uint16_t *dst_r, *dst_g, *dst_b, *dst_a;
2383  int x, y;
2384 
2385  dst_r = (uint16_t *)p->data[2];
2386  dst_g = (uint16_t *)p->data[0];
2387  dst_b = (uint16_t *)p->data[1];
2388  dst_a = (uint16_t *)p->data[3];
2389 
2390  if (get_bits1(gb)) {
2391  for (x = 0; x < avctx->width; x++) {
2392  dst_a[x] = get_bits(gb, 10);
2393  dst_r[x] = get_bits(gb, 10);
2394  dst_g[x] = get_bits(gb, 10);
2395  dst_b[x] = get_bits(gb, 10);
2396  }
2397  } else {
2398  int pred[4] = { 512, 512, 512, 512 };
2399 
2400  for (x = 0; x < avctx->width; x++) {
2401  int r, g, b, a;
2402 
2403  a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2404  r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
2405  g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2406  b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2407 
2408  dst_a[x] = pred[3] = (a + pred[3]) & 0x3ff;
2409  dst_r[x] = pred[0] = (r + pred[0]) & 0x3ff;
2410  dst_g[x] = pred[1] = (r + g + pred[1]) & 0x3ff;
2411  dst_b[x] = pred[2] = (r + g + b + pred[2]) & 0x3ff;
2412  }
2413  }
2414 
2415  dst_r += p->linesize[2] / 2;
2416  dst_g += p->linesize[0] / 2;
2417  dst_b += p->linesize[1] / 2;
2418  dst_a += p->linesize[3] / 2;
2419 
2420  for (y = 1; y < avctx->height; y++) {
2421  if (get_bits1(gb)) {
2422  for (x = 0; x < avctx->width; x++) {
2423  dst_a[x] = get_bits(gb, 10);
2424  dst_r[x] = get_bits(gb, 10);
2425  dst_g[x] = get_bits(gb, 10);
2426  dst_b[x] = get_bits(gb, 10);
2427  }
2428  } else {
2429  int pred_TL[4], pred_L[4], pred_T[4];
2430  int r, g, b, a;
2431 
2432  pred_TL[0] = pred_L[0] = dst_r[-p->linesize[2] / 2];
2433  pred_TL[1] = pred_L[1] = dst_g[-p->linesize[0] / 2];
2434  pred_TL[2] = pred_L[2] = dst_b[-p->linesize[1] / 2];
2435  pred_TL[3] = pred_L[3] = dst_a[-p->linesize[3] / 2];
2436 
2437  for (x = 0; x < avctx->width; x++) {
2438  pred_T[0] = dst_r[-p->linesize[2] / 2 + x];
2439  pred_T[1] = dst_g[-p->linesize[0] / 2 + x];
2440  pred_T[2] = dst_b[-p->linesize[1] / 2 + x];
2441  pred_T[3] = dst_a[-p->linesize[3] / 2 + x];
2442 
2443  a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2444  r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
2445  g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2446  b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2447 
2448  dst_a[x] = pred_L[3] = (a + ((3 * (pred_T[3] + pred_L[3]) - 2 * pred_TL[3]) >> 2)) & 0x3ff;
2449  dst_r[x] = pred_L[0] = (r + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0x3ff;
2450  dst_g[x] = pred_L[1] = (r + g + ((3 * (pred_T[1] + pred_L[1]) - 2 * pred_TL[1]) >> 2)) & 0x3ff;
2451  dst_b[x] = pred_L[2] = (r + g + b + ((3 * (pred_T[2] + pred_L[2]) - 2 * pred_TL[2]) >> 2)) & 0x3ff;
2452 
2453  pred_TL[0] = pred_T[0];
2454  pred_TL[1] = pred_T[1];
2455  pred_TL[2] = pred_T[2];
2456  pred_TL[3] = pred_T[3];
2457  }
2458  }
2459 
2460  dst_r += p->linesize[2] / 2;
2461  dst_g += p->linesize[0] / 2;
2462  dst_b += p->linesize[1] / 2;
2463  dst_a += p->linesize[3] / 2;
2464  }
2465 }
2466 
2467 static void decode_rgbxi(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
2468 {
2469  SheerVideoContext *s = avctx->priv_data;
2470  uint16_t *dst_r, *dst_g, *dst_b;
2471  int x, y;
2472 
2473  dst_r = (uint16_t *)p->data[2];
2474  dst_g = (uint16_t *)p->data[0];
2475  dst_b = (uint16_t *)p->data[1];
2476 
2477  for (y = 0; y < avctx->height; y++) {
2478  if (get_bits1(gb)) {
2479  for (x = 0; x < avctx->width; x++) {
2480  dst_r[x] = get_bits(gb, 10);
2481  dst_g[x] = get_bits(gb, 10);
2482  dst_b[x] = get_bits(gb, 10);
2483  }
2484  } else {
2485  int pred[4] = { 512, 512, 512, 0 };
2486 
2487  for (x = 0; x < avctx->width; x++) {
2488  int r, g, b;
2489 
2490  r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
2491  g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2492  b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2493 
2494  dst_r[x] = pred[0] = (r + pred[0]) & 0x3ff;
2495  dst_g[x] = pred[1] = (r + g + pred[1]) & 0x3ff;
2496  dst_b[x] = pred[2] = (r + g + b + pred[2]) & 0x3ff;
2497  }
2498  }
2499 
2500  dst_r += p->linesize[2] / 2;
2501  dst_g += p->linesize[0] / 2;
2502  dst_b += p->linesize[1] / 2;
2503  }
2504 }
2505 
2506 static void decode_rgbx(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
2507 {
2508  SheerVideoContext *s = avctx->priv_data;
2509  uint16_t *dst_r, *dst_g, *dst_b;
2510  int x, y;
2511 
2512  dst_r = (uint16_t *)p->data[2];
2513  dst_g = (uint16_t *)p->data[0];
2514  dst_b = (uint16_t *)p->data[1];
2515 
2516  if (get_bits1(gb)) {
2517  for (x = 0; x < avctx->width; x++) {
2518  dst_r[x] = get_bits(gb, 10);
2519  dst_g[x] = get_bits(gb, 10);
2520  dst_b[x] = get_bits(gb, 10);
2521  }
2522  } else {
2523  int pred[4] = { 512, 512, 512, 0 };
2524 
2525  for (x = 0; x < avctx->width; x++) {
2526  int r, g, b;
2527 
2528  r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
2529  g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2530  b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2531 
2532  dst_r[x] = pred[0] = (r + pred[0]) & 0x3ff;
2533  dst_g[x] = pred[1] = (r + g + pred[1]) & 0x3ff;
2534  dst_b[x] = pred[2] = (r + g + b + pred[2]) & 0x3ff;
2535  }
2536  }
2537 
2538  dst_r += p->linesize[2] / 2;
2539  dst_g += p->linesize[0] / 2;
2540  dst_b += p->linesize[1] / 2;
2541 
2542  for (y = 1; y < avctx->height; y++) {
2543  if (get_bits1(gb)) {
2544  for (x = 0; x < avctx->width; x++) {
2545  dst_r[x] = get_bits(gb, 10);
2546  dst_g[x] = get_bits(gb, 10);
2547  dst_b[x] = get_bits(gb, 10);
2548  }
2549  } else {
2550  int pred_TL[4], pred_L[4], pred_T[4];
2551  int r, g, b;
2552 
2553  pred_TL[0] = pred_L[0] = dst_r[-p->linesize[2] / 2];
2554  pred_TL[1] = pred_L[1] = dst_g[-p->linesize[0] / 2];
2555  pred_TL[2] = pred_L[2] = dst_b[-p->linesize[1] / 2];
2556 
2557  for (x = 0; x < avctx->width; x++) {
2558  pred_T[0] = dst_r[-p->linesize[2] / 2 + x];
2559  pred_T[1] = dst_g[-p->linesize[0] / 2 + x];
2560  pred_T[2] = dst_b[-p->linesize[1] / 2 + x];
2561 
2562  r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
2563  g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2564  b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2565 
2566  dst_r[x] = pred_L[0] = (r + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0x3ff;
2567  dst_g[x] = pred_L[1] = (r + g + ((3 * (pred_T[1] + pred_L[1]) - 2 * pred_TL[1]) >> 2)) & 0x3ff;
2568  dst_b[x] = pred_L[2] = (r + g + b + ((3 * (pred_T[2] + pred_L[2]) - 2 * pred_TL[2]) >> 2)) & 0x3ff;
2569 
2570  pred_TL[0] = pred_T[0];
2571  pred_TL[1] = pred_T[1];
2572  pred_TL[2] = pred_T[2];
2573  }
2574  }
2575 
2576  dst_r += p->linesize[2] / 2;
2577  dst_g += p->linesize[0] / 2;
2578  dst_b += p->linesize[1] / 2;
2579  }
2580 }
2581 
2582 static void decode_argbi(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
2583 {
2584  SheerVideoContext *s = avctx->priv_data;
2585  uint8_t *dst;
2586  int x, y;
2587 
2588  dst = p->data[0];
2589  if (get_bits1(gb)) {
2590  for (x = 0; x < avctx->width; x++) {
2591  dst[x * 4 + 0] = get_bits(gb, 8);
2592  dst[x * 4 + 1] = get_bits(gb, 8);
2593  dst[x * 4 + 2] = get_bits(gb, 8);
2594  dst[x * 4 + 3] = get_bits(gb, 8);
2595  }
2596  } else {
2597  int pred[4] = { -128, -128, -128, -128 };
2598 
2599  for (x = 0; x < avctx->width; x++) {
2600  int a, r, g, b;
2601 
2602  a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2603  r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
2604  g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2605  b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2606 
2607  dst[4 * x + 0] = pred[0] = (a + pred[0]) & 0xff;
2608  dst[4 * x + 1] = pred[1] = (r + pred[1]) & 0xff;
2609  dst[4 * x + 2] = pred[2] = (r + g + pred[2]) & 0xff;
2610  dst[4 * x + 3] = pred[3] = (r + g + b + pred[3]) & 0xff;
2611  }
2612  }
2613 
2614  dst += p->linesize[0];
2615  for (y = 1; y < avctx->height; y++) {
2616  if (get_bits1(gb)) {
2617  for (x = 0; x < avctx->width; x++) {
2618  dst[x * 4 + 0] = get_bits(gb, 8);
2619  dst[x * 4 + 1] = get_bits(gb, 8);
2620  dst[x * 4 + 2] = get_bits(gb, 8);
2621  dst[x * 4 + 3] = get_bits(gb, 8);
2622  }
2623  } else {
2624  int pred_L[4];
2625  int a, r, g, b;
2626 
2627  pred_L[0] = dst[-p->linesize[0] + 0];
2628  pred_L[1] = dst[-p->linesize[0] + 1];
2629  pred_L[2] = dst[-p->linesize[0] + 2];
2630  pred_L[3] = dst[-p->linesize[0] + 3];
2631 
2632  for (x = 0; x < avctx->width; x++) {
2633  a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2634  r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
2635  g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2636  b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2637 
2638  dst[4 * x + 0] = pred_L[0] = (a + pred_L[0]) & 0xff;
2639  dst[4 * x + 1] = pred_L[1] = (r + pred_L[1]) & 0xff;
2640  dst[4 * x + 2] = pred_L[2] = (r + g + pred_L[2]) & 0xff;
2641  dst[4 * x + 3] = pred_L[3] = (r + g + b + pred_L[3]) & 0xff;
2642  }
2643  }
2644  dst += p->linesize[0];
2645  }
2646 }
2647 
2648 static void decode_argb(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
2649 {
2650  SheerVideoContext *s = avctx->priv_data;
2651  uint8_t *dst;
2652  int x, y;
2653 
2654  dst = p->data[0];
2655  if (get_bits1(gb)) {
2656  for (x = 0; x < avctx->width; x++) {
2657  dst[x * 4 + 0] = get_bits(gb, 8);
2658  dst[x * 4 + 1] = get_bits(gb, 8);
2659  dst[x * 4 + 2] = get_bits(gb, 8);
2660  dst[x * 4 + 3] = get_bits(gb, 8);
2661  }
2662  } else {
2663  int pred[4] = { -128, -128, -128, -128 };
2664 
2665  for (x = 0; x < avctx->width; x++) {
2666  int a, r, g, b;
2667 
2668  a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2669  r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
2670  g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2671  b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2672 
2673  dst[4 * x + 0] = pred[0] = (a + pred[0]) & 0xff;
2674  dst[4 * x + 1] = pred[1] = (r + pred[1]) & 0xff;
2675  dst[4 * x + 2] = pred[2] = (r + g + pred[2]) & 0xff;
2676  dst[4 * x + 3] = pred[3] = (r + g + b + pred[3]) & 0xff;
2677  }
2678  }
2679 
2680  dst += p->linesize[0];
2681  for (y = 1; y < avctx->height; y++) {
2682  if (get_bits1(gb)) {
2683  for (x = 0; x < avctx->width; x++) {
2684  dst[x * 4 + 0] = get_bits(gb, 8);
2685  dst[x * 4 + 1] = get_bits(gb, 8);
2686  dst[x * 4 + 2] = get_bits(gb, 8);
2687  dst[x * 4 + 3] = get_bits(gb, 8);
2688  }
2689  } else {
2690  int pred_TL[4], pred_L[4], pred_T[4];
2691  int a, r, g, b;
2692 
2693  pred_TL[0] = pred_L[0] = dst[-p->linesize[0] + 0];
2694  pred_TL[1] = pred_L[1] = dst[-p->linesize[0] + 1];
2695  pred_TL[2] = pred_L[2] = dst[-p->linesize[0] + 2];
2696  pred_TL[3] = pred_L[3] = dst[-p->linesize[0] + 3];
2697 
2698  for (x = 0; x < avctx->width; x++) {
2699  pred_T[0] = dst[-p->linesize[0] + 4 * x + 0];
2700  pred_T[1] = dst[-p->linesize[0] + 4 * x + 1];
2701  pred_T[2] = dst[-p->linesize[0] + 4 * x + 2];
2702  pred_T[3] = dst[-p->linesize[0] + 4 * x + 3];
2703 
2704  a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2705  r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
2706  g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2707  b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2708 
2709  dst[4 * x + 0] = pred_L[0] = (a + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0xff;
2710  dst[4 * x + 1] = pred_L[1] = (r + ((3 * (pred_T[1] + pred_L[1]) - 2 * pred_TL[1]) >> 2)) & 0xff;
2711  dst[4 * x + 2] = pred_L[2] = (r + g + ((3 * (pred_T[2] + pred_L[2]) - 2 * pred_TL[2]) >> 2)) & 0xff;
2712  dst[4 * x + 3] = pred_L[3] = (r + g + b + ((3 * (pred_T[3] + pred_L[3]) - 2 * pred_TL[3]) >> 2)) & 0xff;
2713 
2714  pred_TL[0] = pred_T[0];
2715  pred_TL[1] = pred_T[1];
2716  pred_TL[2] = pred_T[2];
2717  pred_TL[3] = pred_T[3];
2718  }
2719  }
2720  dst += p->linesize[0];
2721  }
2722 }
2723 
2724 static void decode_rgbi(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
2725 {
2726  SheerVideoContext *s = avctx->priv_data;
2727  uint8_t *dst;
2728  int x, y;
2729 
2730  dst = p->data[0];
2731  if (get_bits1(gb)) {
2732  for (x = 0; x < avctx->width; x++) {
2733  dst[x * 4 + 0] = get_bits(gb, 8);
2734  dst[x * 4 + 1] = get_bits(gb, 8);
2735  dst[x * 4 + 2] = get_bits(gb, 8);
2736  }
2737  } else {
2738  int pred[4] = { -128, -128, -128, -128 };
2739 
2740  for (x = 0; x < avctx->width; x++) {
2741  int r, g, b;
2742 
2743  r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
2744  g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2745  b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2746 
2747  dst[4 * x + 0] = pred[0] = (r + pred[0]) & 0xff;
2748  dst[4 * x + 1] = pred[1] = (r + g + pred[1]) & 0xff;
2749  dst[4 * x + 2] = pred[2] = (r + g + b + pred[2]) & 0xff;
2750  }
2751  }
2752 
2753  dst += p->linesize[0];
2754  for (y = 1; y < avctx->height; y++) {
2755  if (get_bits1(gb)) {
2756  for (x = 0; x < avctx->width; x++) {
2757  dst[x * 4 + 0] = get_bits(gb, 8);
2758  dst[x * 4 + 1] = get_bits(gb, 8);
2759  dst[x * 4 + 2] = get_bits(gb, 8);
2760  }
2761  } else {
2762  int pred_L[4];
2763  int r, g, b;
2764 
2765  pred_L[0] = dst[-p->linesize[0] + 0];
2766  pred_L[1] = dst[-p->linesize[0] + 1];
2767  pred_L[2] = dst[-p->linesize[0] + 2];
2768 
2769  for (x = 0; x < avctx->width; x++) {
2770  r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
2771  g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2772  b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2773 
2774  dst[4 * x + 0] = pred_L[0] = (r + pred_L[0]) & 0xff;
2775  dst[4 * x + 1] = pred_L[1] = (r + g + pred_L[1]) & 0xff;
2776  dst[4 * x + 2] = pred_L[2] = (r + g + b + pred_L[2]) & 0xff;
2777  }
2778  }
2779  dst += p->linesize[0];
2780  }
2781 }
2782 
2783 static void decode_rgb(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
2784 {
2785  SheerVideoContext *s = avctx->priv_data;
2786  uint8_t *dst;
2787  int x, y;
2788 
2789  dst = p->data[0];
2790  if (get_bits1(gb)) {
2791  for (x = 0; x < avctx->width; x++) {
2792  dst[x * 4 + 0] = get_bits(gb, 8);
2793  dst[x * 4 + 1] = get_bits(gb, 8);
2794  dst[x * 4 + 2] = get_bits(gb, 8);
2795  }
2796  } else {
2797  int pred[4] = { -128, -128, -128, -128 };
2798 
2799  for (x = 0; x < avctx->width; x++) {
2800  int r, g, b;
2801 
2802  r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
2803  g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2804  b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2805 
2806  dst[4 * x + 0] = pred[0] = (r + pred[0]) & 0xff;
2807  dst[4 * x + 1] = pred[1] = (r + g + pred[1]) & 0xff;
2808  dst[4 * x + 2] = pred[2] = (r + g + b + pred[2]) & 0xff;
2809  }
2810  }
2811 
2812  dst += p->linesize[0];
2813  for (y = 1; y < avctx->height; y++) {
2814  if (get_bits1(gb)) {
2815  for (x = 0; x < avctx->width; x++) {
2816  dst[x * 4 + 0] = get_bits(gb, 8);
2817  dst[x * 4 + 1] = get_bits(gb, 8);
2818  dst[x * 4 + 2] = get_bits(gb, 8);
2819  }
2820  } else {
2821  int pred_TL[4], pred_L[4], pred_T[4];
2822  int r, g, b;
2823 
2824  pred_TL[0] = pred_L[0] = dst[-p->linesize[0] + 0];
2825  pred_TL[1] = pred_L[1] = dst[-p->linesize[0] + 1];
2826  pred_TL[2] = pred_L[2] = dst[-p->linesize[0] + 2];
2827 
2828  for (x = 0; x < avctx->width; x++) {
2829  pred_T[0] = dst[-p->linesize[0] + 4 * x + 0];
2830  pred_T[1] = dst[-p->linesize[0] + 4 * x + 1];
2831  pred_T[2] = dst[-p->linesize[0] + 4 * x + 2];
2832 
2833  r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
2834  g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2835  b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2836 
2837  dst[4 * x + 0] = pred_L[0] = (r + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0xff;
2838  dst[4 * x + 1] = pred_L[1] = (r + g + ((3 * (pred_T[1] + pred_L[1]) - 2 * pred_TL[1]) >> 2)) & 0xff;
2839  dst[4 * x + 2] = pred_L[2] = (r + g + b + ((3 * (pred_T[2] + pred_L[2]) - 2 * pred_TL[2]) >> 2)) & 0xff;
2840 
2841  pred_TL[0] = pred_T[0];
2842  pred_TL[1] = pred_T[1];
2843  pred_TL[2] = pred_T[2];
2844  }
2845  }
2846  dst += p->linesize[0];
2847  }
2848 }
2849 
2850 static int build_vlc(VLC *vlc, const uint8_t *len, int count)
2851 {
2852  uint32_t codes[1024];
2853  uint8_t bits[1024];
2854  uint16_t syms[1024];
2855  uint64_t index;
2856  int i;
2857 
2858  index = 0;
2859  for (i = 0; i < count; i++) {
2860  codes[i] = index >> (32 - len[i]);
2861  bits[i] = len[i];
2862  syms[i] = i;
2863  index += 1ULL << (32 - len[i]);
2864  }
2865 
2866  ff_free_vlc(vlc);
2867  return ff_init_vlc_sparse(vlc, 16, count,
2868  bits, sizeof(*bits), sizeof(*bits),
2869  codes, sizeof(*codes), sizeof(*codes),
2870  syms, sizeof(*syms), sizeof(*syms), 0);
2871 }
2872 
2873 static int decode_frame(AVCodecContext *avctx,
2874  void *data, int *got_frame,
2875  AVPacket *avpkt)
2876 {
2877  SheerVideoContext *s = avctx->priv_data;
2878  ThreadFrame frame = { .f = data };
2879  AVFrame *p = data;
2880  GetBitContext gb;
2881  unsigned format;
2882  int ret;
2883 
2884  if (avpkt->size <= 20)
2885  return AVERROR_INVALIDDATA;
2886 
2887  if (AV_RL32(avpkt->data) != MKTAG('S','h','i','r') &&
2888  AV_RL32(avpkt->data) != MKTAG('Z','w','a','k'))
2889  return AVERROR_INVALIDDATA;
2890 
2891  s->alt = 0;
2892  format = AV_RL32(avpkt->data + 16);
2893  av_log(avctx, AV_LOG_DEBUG, "format: %s\n", av_fourcc2str(format));
2894  switch (format) {
2895  case MKTAG(' ', 'R', 'G', 'B'):
2896  avctx->pix_fmt = AV_PIX_FMT_RGB0;
2897  s->decode_frame = decode_rgb;
2898  if (s->format != format) {
2899  ret = build_vlc(&s->vlc[0], l_r_rgb, 256);
2900  ret |= build_vlc(&s->vlc[1], l_g_rgb, 256);
2901  }
2902  break;
2903  case MKTAG(' ', 'r', 'G', 'B'):
2904  avctx->pix_fmt = AV_PIX_FMT_RGB0;
2906  if (s->format != format) {
2907  ret = build_vlc(&s->vlc[0], l_r_rgbi, 256);
2908  ret |= build_vlc(&s->vlc[1], l_g_rgbi, 256);
2909  }
2910  break;
2911  case MKTAG('A', 'R', 'G', 'X'):
2912  avctx->pix_fmt = AV_PIX_FMT_GBRAP10;
2914  if (s->format != format) {
2915  ret = build_vlc(&s->vlc[0], l_r_rgbx, 1024);
2916  ret |= build_vlc(&s->vlc[1], l_g_rgbx, 1024);
2917  }
2918  break;
2919  case MKTAG('A', 'r', 'G', 'X'):
2920  avctx->pix_fmt = AV_PIX_FMT_GBRAP10;
2922  if (s->format != format) {
2923  ret = build_vlc(&s->vlc[0], l_r_rgbxi, 1024);
2924  ret |= build_vlc(&s->vlc[1], l_g_rgbxi, 1024);
2925  }
2926  break;
2927  case MKTAG('R', 'G', 'B', 'X'):
2928  avctx->pix_fmt = AV_PIX_FMT_GBRP10;
2930  if (s->format != format) {
2931  ret = build_vlc(&s->vlc[0], l_r_rgbx, 1024);
2932  ret |= build_vlc(&s->vlc[1], l_g_rgbx, 1024);
2933  }
2934  break;
2935  case MKTAG('r', 'G', 'B', 'X'):
2936  avctx->pix_fmt = AV_PIX_FMT_GBRP10;
2938  if (s->format != format) {
2939  ret = build_vlc(&s->vlc[0], l_r_rgbxi, 1024);
2940  ret |= build_vlc(&s->vlc[1], l_g_rgbxi, 1024);
2941  }
2942  break;
2943  case MKTAG('A', 'R', 'G', 'B'):
2944  avctx->pix_fmt = AV_PIX_FMT_ARGB;
2946  if (s->format != format) {
2947  ret = build_vlc(&s->vlc[0], l_r_rgb, 256);
2948  ret |= build_vlc(&s->vlc[1], l_g_rgb, 256);
2949  }
2950  break;
2951  case MKTAG('A', 'r', 'G', 'B'):
2952  avctx->pix_fmt = AV_PIX_FMT_ARGB;
2954  if (s->format != format) {
2955  ret = build_vlc(&s->vlc[0], l_r_rgbi, 256);
2956  ret |= build_vlc(&s->vlc[1], l_g_rgbi, 256);
2957  }
2958  break;
2959  case MKTAG('A', 'Y', 'B', 'R'):
2960  s->alt = 1;
2961  case MKTAG('A', 'Y', 'b', 'R'):
2962  avctx->pix_fmt = AV_PIX_FMT_YUVA444P;
2964  if (s->format != format) {
2965  ret = build_vlc(&s->vlc[0], l_y_ybr, 256);
2966  ret |= build_vlc(&s->vlc[1], l_u_ybr, 256);
2967  }
2968  break;
2969  case MKTAG('A', 'y', 'B', 'R'):
2970  s->alt = 1;
2971  case MKTAG('A', 'y', 'b', 'R'):
2972  avctx->pix_fmt = AV_PIX_FMT_YUVA444P;
2974  if (s->format != format) {
2975  ret = build_vlc(&s->vlc[0], l_y_ybri, 256);
2976  ret |= build_vlc(&s->vlc[1], l_u_ybri, 256);
2977  }
2978  break;
2979  case MKTAG(' ', 'Y', 'B', 'R'):
2980  s->alt = 1;
2981  case MKTAG(' ', 'Y', 'b', 'R'):
2982  avctx->pix_fmt = AV_PIX_FMT_YUV444P;
2983  s->decode_frame = decode_ybr;
2984  if (s->format != format) {
2985  ret = build_vlc(&s->vlc[0], l_y_ybr, 256);
2986  ret |= build_vlc(&s->vlc[1], l_u_ybr, 256);
2987  }
2988  break;
2989  case MKTAG(' ', 'y', 'B', 'R'):
2990  s->alt = 1;
2991  case MKTAG(' ', 'y', 'b', 'R'):
2992  avctx->pix_fmt = AV_PIX_FMT_YUV444P;
2994  if (s->format != format) {
2995  ret = build_vlc(&s->vlc[0], l_y_ybri, 256);
2996  ret |= build_vlc(&s->vlc[1], l_u_ybri, 256);
2997  }
2998  break;
2999  case MKTAG('Y', 'B', 'R', 0x0a):
3000  avctx->pix_fmt = AV_PIX_FMT_YUV444P10;
3002  if (s->format != format) {
3003  ret = build_vlc(&s->vlc[0], l_y_ybr10, 1024);
3004  ret |= build_vlc(&s->vlc[1], l_u_ybr10, 1024);
3005  }
3006  break;
3007  case MKTAG('y', 'B', 'R', 0x0a):
3008  avctx->pix_fmt = AV_PIX_FMT_YUV444P10;
3010  if (s->format != format) {
3011  ret = build_vlc(&s->vlc[0], l_y_ybr10i, 1024);
3012  ret |= build_vlc(&s->vlc[1], l_u_ybr10i, 1024);
3013  }
3014  break;
3015  case MKTAG('C', 'A', '4', 'p'):
3016  avctx->pix_fmt = AV_PIX_FMT_YUVA444P10;
3018  if (s->format != format) {
3019  ret = build_vlc(&s->vlc[0], l_y_ybr10, 1024);
3020  ret |= build_vlc(&s->vlc[1], l_u_ybr10, 1024);
3021  }
3022  break;
3023  case MKTAG('C', 'A', '4', 'i'):
3024  avctx->pix_fmt = AV_PIX_FMT_YUVA444P10;
3026  if (s->format != format) {
3027  ret = build_vlc(&s->vlc[0], l_y_ybr10i, 1024);
3028  ret |= build_vlc(&s->vlc[1], l_u_ybr10i, 1024);
3029  }
3030  break;
3031  case MKTAG('B', 'Y', 'R', 'Y'):
3032  avctx->pix_fmt = AV_PIX_FMT_YUV422P;
3034  if (s->format != format) {
3035  ret = build_vlc(&s->vlc[0], l_y_byry, 256);
3036  ret |= build_vlc(&s->vlc[1], l_u_byry, 256);
3037  }
3038  break;
3039  case MKTAG('B', 'Y', 'R', 'y'):
3040  avctx->pix_fmt = AV_PIX_FMT_YUV422P;
3042  if (s->format != format) {
3043  ret = build_vlc(&s->vlc[0], l_y_byryi, 256);
3044  ret |= build_vlc(&s->vlc[1], l_u_byryi, 256);
3045  }
3046  break;
3047  case MKTAG('Y', 'b', 'Y', 'r'):
3048  avctx->pix_fmt = AV_PIX_FMT_YUV422P;
3050  if (s->format != format) {
3051  ret = build_vlc(&s->vlc[0], l_y_ybyr, 256);
3052  ret |= build_vlc(&s->vlc[1], l_u_ybyr, 256);
3053  }
3054  break;
3055  case MKTAG('C', '8', '2', 'p'):
3056  avctx->pix_fmt = AV_PIX_FMT_YUVA422P;
3058  if (s->format != format) {
3059  ret = build_vlc(&s->vlc[0], l_y_byry, 256);
3060  ret |= build_vlc(&s->vlc[1], l_u_byry, 256);
3061  }
3062  break;
3063  case MKTAG('C', '8', '2', 'i'):
3064  avctx->pix_fmt = AV_PIX_FMT_YUVA422P;
3066  if (s->format != format) {
3067  ret = build_vlc(&s->vlc[0], l_y_byryi, 256);
3068  ret |= build_vlc(&s->vlc[1], l_u_byryi, 256);
3069  }
3070  break;
3071  case MKTAG(0xa2, 'Y', 'R', 'Y'):
3072  avctx->pix_fmt = AV_PIX_FMT_YUV422P10;
3074  if (s->format != format) {
3075  ret = build_vlc(&s->vlc[0], l_y_yry10, 1024);
3076  ret |= build_vlc(&s->vlc[1], l_u_yry10, 1024);
3077  }
3078  break;
3079  case MKTAG(0xa2, 'Y', 'R', 'y'):
3080  avctx->pix_fmt = AV_PIX_FMT_YUV422P10;
3082  if (s->format != format) {
3083  ret = build_vlc(&s->vlc[0], l_y_yry10i, 1024);
3084  ret |= build_vlc(&s->vlc[1], l_u_yry10i, 1024);
3085  }
3086  break;
3087  case MKTAG('C', 'A', '2', 'p'):
3088  avctx->pix_fmt = AV_PIX_FMT_YUVA422P10;
3090  if (s->format != format) {
3091  ret = build_vlc(&s->vlc[0], l_y_yry10, 1024);
3092  ret |= build_vlc(&s->vlc[1], l_u_yry10, 1024);
3093  }
3094  break;
3095  case MKTAG('C', 'A', '2', 'i'):
3096  avctx->pix_fmt = AV_PIX_FMT_YUVA422P10;
3098  if (s->format != format) {
3099  ret = build_vlc(&s->vlc[0], l_y_yry10i, 1024);
3100  ret |= build_vlc(&s->vlc[1], l_u_yry10i, 1024);
3101  }
3102  break;
3103  default:
3104  avpriv_request_sample(avctx, "unsupported format: 0x%X", format);
3105  return AVERROR_PATCHWELCOME;
3106  }
3107 
3108  if (avpkt->size < 20 + avctx->width * avctx->height / 16) {
3109  av_log(avctx, AV_LOG_ERROR, "Input packet too small\n");
3110  return AVERROR_INVALIDDATA;
3111  }
3112 
3113  if (s->format != format) {
3114  if (ret < 0)
3115  return ret;
3116  s->format = format;
3117  }
3118 
3120  p->key_frame = 1;
3121 
3122  if ((ret = ff_thread_get_buffer(avctx, &frame, 0)) < 0)
3123  return ret;
3124 
3125  if ((ret = init_get_bits8(&gb, avpkt->data + 20, avpkt->size - 20)) < 0)
3126  return ret;
3127 
3128  s->decode_frame(avctx, p, &gb);
3129 
3130  *got_frame = 1;
3131 
3132  return avpkt->size;
3133 }
3134 
3135 #if HAVE_THREADS
3136 static int decode_init_thread_copy(AVCodecContext *avctx)
3137 {
3138  SheerVideoContext *s = avctx->priv_data;
3139 
3140  s->format = 0;
3141  memset(&s->vlc[0], 0, sizeof(s->vlc[0]));
3142  memset(&s->vlc[1], 0, sizeof(s->vlc[1]));
3143 
3144  return 0;
3145 }
3146 #endif
3147 
3149 {
3150  SheerVideoContext *s = avctx->priv_data;
3151 
3152  ff_free_vlc(&s->vlc[0]);
3153  ff_free_vlc(&s->vlc[1]);
3154 
3155  return 0;
3156 }
3157 
3159  .name = "sheervideo",
3160  .long_name = NULL_IF_CONFIG_SMALL("BitJazz SheerVideo"),
3161  .type = AVMEDIA_TYPE_VIDEO,
3162  .id = AV_CODEC_ID_SHEERVIDEO,
3163  .priv_data_size = sizeof(SheerVideoContext),
3164  .init_thread_copy = ONLY_IF_THREADS_ENABLED(decode_init_thread_copy),
3165  .close = decode_end,
3166  .decode = decode_frame,
3167  .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS,
3168 };
static const uint8_t l_u_yry10i[1024]
Definition: sheervideo.c:832
static av_cold int decode_end(AVCodecContext *avctx)
Definition: sheervideo.c:3148
static const uint8_t l_y_ybri[256]
Definition: sheervideo.c:899
const char * s
Definition: avisynth_c.h:768
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
static void decode_c82p(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
Definition: sheervideo.c:1683
This structure describes decoded (raw) audio or video data.
Definition: frame.h:201
static const uint8_t l_y_ybr10[1024]
Definition: sheervideo.c:296
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:101
static const uint8_t l_u_ybr[256]
Definition: sheervideo.c:134
static void decode_ca2p(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
Definition: sheervideo.c:1531
static void decode_byryi(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
Definition: sheervideo.c:1868
#define AV_PIX_FMT_GBRAP10
Definition: pixfmt.h:399
#define AV_PIX_FMT_YUVA422P10
Definition: pixfmt.h:415
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:67
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:261
static int init_thread_copy(AVCodecContext *avctx)
Definition: tta.c:392
const char * g
Definition: vf_curves.c:112
static void decode_aybri(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
Definition: sheervideo.c:2169
static void decode_ybr10(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
Definition: sheervideo.c:1280
static void decode_rgbx(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
Definition: sheervideo.c:2506
int ff_init_vlc_sparse(VLC *vlc_arg, int nb_bits, int nb_codes, const void *bits, int bits_wrap, int bits_size, const void *codes, int codes_wrap, int codes_size, const void *symbols, int symbols_wrap, int symbols_size, int flags)
Definition: bitstream.c:268
int size
Definition: avcodec.h:1680
const char * b
Definition: vf_curves.c:113
#define AV_PIX_FMT_GBRP10
Definition: pixfmt.h:395
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1989
static void decode_ca2i(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
Definition: sheervideo.c:1481
#define a1
Definition: regdef.h:47
static const uint8_t l_g_rgb[256]
Definition: sheervideo.c:96
static const uint8_t l_y_byry[256]
Definition: sheervideo.c:191
AVCodec.
Definition: avcodec.h:3739
static int build_vlc(VLC *vlc, const uint8_t *len, int count)
Definition: sheervideo.c:2850
void void avpriv_request_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
uint8_t bits
Definition: crc.c:296
uint8_t
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: sheervideo.c:2873
#define av_cold
Definition: attributes.h:82
static const uint8_t l_g_rgbx[1024]
Definition: sheervideo.c:564
packed RGB 8:8:8, 32bpp, RGBXRGBX... X=unused/undefined
Definition: pixfmt.h:252
AVCodec ff_sheervideo_decoder
Definition: sheervideo.c:3158
Multithreading support functions.
static const uint8_t l_y_yry10[1024]
Definition: sheervideo.c:631
static AVFrame * frame
static void decode_argbi(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
Definition: sheervideo.c:2582
uint8_t * data
Definition: avcodec.h:1679
static void decode_rgbi(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
Definition: sheervideo.c:2724
static const uint8_t l_u_ybr10i[1024]
Definition: sheervideo.c:363
bitstream reader API header.
static void decode_argxi(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
Definition: sheervideo.c:2335
static void decode_aybr(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
Definition: sheervideo.c:2247
#define av_log(a,...)
static const uint8_t l_y_ybyr[256]
Definition: sheervideo.c:153
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
Definition: pixfmt.h:188
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
static const uint8_t l_r_rgbxi[1024]
Definition: sheervideo.c:975
static void decode_rgb(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
Definition: sheervideo.c:2783
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:179
const char * r
Definition: vf_curves.c:111
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:197
static const uint8_t l_g_rgbi[256]
Definition: sheervideo.c:77
#define av_fourcc2str(fourcc)
Definition: avutil.h:348
const char * name
Name of the codec implementation.
Definition: avcodec.h:3746
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:382
GLsizei count
Definition: opengl_enc.c:109
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
Definition: pixfmt.h:93
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
Definition: avcodec.h:1065
static void decode_c82i(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
Definition: sheervideo.c:1633
Definition: vlc.h:26
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:66
#define ONLY_IF_THREADS_ENABLED(x)
Define a function with only the non-default version specified.
Definition: internal.h:218
static const uint8_t l_y_yry10i[1024]
Definition: sheervideo.c:698
static const uint8_t l_r_rgb[256]
Definition: sheervideo.c:39
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:284
int width
picture width / height.
Definition: avcodec.h:1948
static void decode_byry(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
Definition: sheervideo.c:1942
typedef void(APIENTRY *FF_PFNGLACTIVETEXTUREPROC)(GLenum texture)
#define a2
Definition: regdef.h:48
static const uint8_t l_u_byry[256]
Definition: sheervideo.c:210
static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE(*table)[2], int bits, int max_depth)
Parse a vlc code.
Definition: get_bits.h:554
#define AV_PIX_FMT_YUVA444P10
Definition: pixfmt.h:416
static void decode_argx(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
Definition: sheervideo.c:2379
int bits
Definition: vlc.h:27
static const float pred[4]
Definition: siprdata.h:259
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:62
static void decode_argb(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
Definition: sheervideo.c:2648
static const uint8_t l_g_rgbxi[1024]
Definition: sheervideo.c:1042
Libavcodec external API header.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:232
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
Definition: get_bits.h:456
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Definition: pixfmt.h:189
static void decode_ca4p(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
Definition: sheervideo.c:1153
int ff_thread_get_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
Wrapper around get_buffer() for frame-multithreaded codecs.
main external API structure.
Definition: avcodec.h:1761
static void decode_ca4i(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
Definition: sheervideo.c:1109
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:313
static const char * format
Definition: movenc.c:47
int index
Definition: gxfenc.c:89
static void decode_ybri(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
Definition: sheervideo.c:2025
static const uint8_t l_u_yry10[1024]
Definition: sheervideo.c:765
static const uint8_t l_r_rgbx[1024]
Definition: sheervideo.c:497
#define u(width,...)
void(* decode_frame)(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
Definition: sheervideo.c:36
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:380
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:215
static void decode_yry10(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
Definition: sheervideo.c:1398
common internal api header.
if(ret< 0)
Definition: vf_mcdeint.c:279
static const uint8_t l_y_ybr10i[1024]
Definition: sheervideo.c:229
static void decode_ybr10i(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
Definition: sheervideo.c:1241
unsigned format
Definition: sheervideo.c:33
static const uint8_t l_u_ybri[256]
Definition: sheervideo.c:918
static const uint8_t l_r_rgbi[256]
Definition: sheervideo.c:58
void * priv_data
Definition: avcodec.h:1803
static void decode_rgbxi(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
Definition: sheervideo.c:2467
int len
static const uint8_t l_u_byryi[256]
Definition: sheervideo.c:956
VLC_TYPE(* table)[2]
code, bits
Definition: vlc.h:28
static void decode_ybr(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
Definition: sheervideo.c:2093
int key_frame
1 -> keyframe, 0-> not
Definition: frame.h:279
static const uint8_t l_y_ybr[256]
Definition: sheervideo.c:115
#define MKTAG(a, b, c, d)
Definition: common.h:342
static const uint8_t l_y_byryi[256]
Definition: sheervideo.c:937
static void decode_ybyr(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
Definition: sheervideo.c:1785
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
Definition: bytestream.h:87
This structure stores compressed data.
Definition: avcodec.h:1656
void ff_free_vlc(VLC *vlc)
Definition: bitstream.c:354
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:1002
static void decode_yry10i(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
Definition: sheervideo.c:1356
static const uint8_t l_u_ybyr[256]
Definition: sheervideo.c:172
for(j=16;j >0;--j)
static const uint8_t l_u_ybr10[1024]
Definition: sheervideo.c:430