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  VLC vlc[2];
37 
38 static const uint8_t l_r_rgb[256] = {
39  3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 7, 7, 8,
40  8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10,
41  10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12,
42  12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13,
43  13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
44  14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
45  15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
46  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
47  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
48  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 15, 15, 15,
49  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 14, 14, 14,
50  14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 13, 13, 13,
51  13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 12, 12, 12, 12, 12, 12,
52  12, 12, 12, 12, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 10, 10,
53  10, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8,
54  8, 8, 8, 7, 7, 7, 7, 7, 6, 6, 6, 5, 5, 4, 4, 4,
55 };
56 
57 static const uint8_t l_r_rgbi[256] = {
58  3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 7, 7, 7,
59  8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9,
60  10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11,
61  11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12,
62  12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
63  13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14,
64  14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15,
65  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
66  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
67  15, 15, 15, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
68  14, 14, 14, 14, 14, 14, 14, 14, 14, 13, 13, 13, 13, 13, 13, 13,
69  13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 12, 12, 12, 12,
70  12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 11, 11, 11, 11, 11,
71  11, 11, 11, 11, 11, 11, 11, 10, 10, 10, 10, 10, 10, 10, 10, 10,
72  10, 10, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 8, 8,
73  8, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 5, 5, 4, 4, 4,
74 };
75 
76 static const uint8_t l_g_rgbi[256] = {
77  1, 3, 4, 5, 6, 7, 7, 8, 9, 9, 10, 10, 10, 10, 11, 11,
78  11, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14,
79  14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16,
80  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 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, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 14,
91  14, 14, 14, 14, 14, 13, 13, 13, 13, 13, 13, 12, 12, 12, 12, 12,
92  11, 11, 11, 10, 10, 10, 9, 9, 9, 8, 8, 7, 6, 5, 5, 3,
93 };
94 
95 static const uint8_t l_g_rgb[256] = {
96  2, 2, 4, 4, 6, 7, 9, 9, 10, 11, 11, 11, 12, 12, 12, 13,
97  13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15,
98  15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16,
99  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
100  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
101  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
102  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
103  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
104  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
105  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
106  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
107  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
108  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
109  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 15, 15, 15, 15,
110  15, 15, 15, 15, 15, 15, 14, 14, 14, 14, 14, 14, 14, 14, 13, 13,
111  13, 13, 12, 12, 12, 11, 11, 11, 10, 9, 9, 8, 6, 4, 3, 3,
112 };
113 
114 static const uint8_t l_y_ybr[256] = {
115  3, 3, 4, 4, 5, 5, 6, 6, 6, 7, 7, 7, 7, 7, 8, 8,
116  8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10,
117  10, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12,
118  12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14,
119  14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15,
120  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16,
121  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
122  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
123  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 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, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
126  15, 15, 15, 15, 15, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
127  14, 14, 14, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 12,
128  12, 12, 12, 12, 12, 12, 12, 12, 11, 11, 11, 11, 11, 11, 11, 11,
129  11, 10, 10, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9, 8, 8,
130  8, 8, 8, 8, 7, 7, 7, 7, 6, 6, 6, 6, 5, 4, 4, 3,
131 };
132 
133 static const uint8_t l_u_ybr[256] = {
134  1, 2, 4, 6, 9, 10, 11, 11, 12, 12, 13, 13, 13, 14, 14, 14,
135  14, 14, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16,
136  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
137  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
138  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
139  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
140  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
141  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
142  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
143  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
144  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
145  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
146  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
147  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
148  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 15, 15, 15, 15,
149  14, 14, 14, 14, 14, 13, 13, 13, 12, 12, 11, 11, 10, 8, 5, 3,
150 };
151 
152 static const uint8_t l_y_ybyr[256] = {
153  3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 7, 7, 8,
154  8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10,
155  10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12,
156  12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13,
157  13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
158  14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
159  15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16,
160  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
161  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
162  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 15, 15,
163  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 14,
164  14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 13, 13,
165  13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 12, 12, 12, 12, 12, 12,
166  12, 12, 12, 12, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 10, 10,
167  10, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8,
168  8, 8, 8, 7, 7, 7, 7, 7, 6, 6, 6, 5, 5, 4, 4, 4,
169 };
170 
171 static const uint8_t l_u_ybyr[256] = {
172  1, 2, 4, 6, 8, 9, 10, 10, 11, 11, 12, 12, 12, 13, 13, 14,
173  14, 14, 14, 14, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16,
174  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
175  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
176  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
177  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
178  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
179  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
180  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
181  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
182  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
183  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
184  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
185  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
186  16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 15, 15, 15, 15, 14, 14,
187  14, 14, 13, 13, 13, 12, 12, 11, 11, 10, 10, 9, 8, 7, 6, 3,
188 };
189 
190 static const uint8_t l_y_byry[256] = {
191  3, 3, 4, 4, 5, 5, 6, 6, 6, 7, 7, 7, 7, 7, 8, 8,
192  8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10,
193  10, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12,
194  12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14,
195  14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15,
196  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16,
197  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 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, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
202  15, 15, 15, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
203  14, 14, 14, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 12,
204  12, 12, 12, 12, 12, 12, 12, 12, 12, 11, 11, 11, 11, 11, 11, 11,
205  11, 10, 10, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9, 8, 8,
206  8, 8, 8, 8, 7, 7, 7, 7, 6, 6, 6, 6, 5, 4, 4, 3,
207 };
208 
209 static const uint8_t l_u_byry[256] = {
210  1, 2, 4, 6, 8, 9, 9, 10, 11, 11, 12, 12, 13, 13, 13, 14,
211  14, 14, 14, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16,
212  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
213  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
214  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
215  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
216  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
217  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
218  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
219  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
220  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
221  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
222  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
223  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
224  16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 15, 15, 15, 15, 15, 14,
225  14, 14, 14, 13, 13, 12, 12, 12, 11, 11, 10, 9, 8, 7, 6, 3,
226 };
227 
228 static const uint8_t l_y_ybr10i[1024] = {
229  3, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7,
230  7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
231  8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
232  9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
233  10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11,
234  11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
235  11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12,
236  12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 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, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
239  13, 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, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
242  14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
243  14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
244  14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
245  14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
246  15, 15, 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, 16,
251  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 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, 15, 15, 15, 15, 15, 15, 15, 15, 15,
272  15, 15, 15, 15, 15, 15, 15, 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  14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
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  13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
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, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
285  12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
286  12, 12, 12, 12, 12, 12, 12, 12, 11, 11, 11, 11, 11, 11, 11, 11,
287  11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
288  11, 11, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
289  10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 9, 9, 9, 9,
290  9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
291  8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7,
292  7, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5,
293 };
294 
295 static const uint8_t l_y_ybr10[1024] = {
296  4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7, 7,
297  7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
298  8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
299  9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
300  10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11,
301  11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
302  11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
303  12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
304  13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
305  13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
306  13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
307  14, 14, 14, 14, 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, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
310  15, 15, 15, 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, 16, 16, 16, 16, 16, 16,
314  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
315  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
316  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
317  16, 16, 16, 16, 16, 16, 16, 16, 16, 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, 15, 15, 15, 15, 15, 15, 15, 15,
343  15, 15, 15, 15, 15, 15, 15, 15, 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  14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
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, 13, 13,
350  13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
351  13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
352  13, 13, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
353  12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 11,
354  11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
355  11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 10, 10, 10, 10, 10, 10,
356  10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 9,
357  9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
358  8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7,
359  7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5,
360 };
361 
362 static const uint8_t l_u_ybr10i[1024] = {
363  2, 3, 4, 4, 5, 5, 6, 7, 7, 8, 8, 9, 9, 9, 9, 10,
364  10, 10, 10, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12,
365  13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14,
366  14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
367  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
368  15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
369  16, 16, 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, 15, 15,
422  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
423  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 14, 14, 14, 14, 14, 14,
424  14, 14, 14, 14, 14, 14, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
425  13, 12, 12, 12, 12, 12, 12, 11, 11, 11, 11, 11, 11, 11, 10, 10,
426  10, 10, 10, 9, 9, 9, 8, 8, 8, 7, 6, 5, 5, 4, 4, 3,
427 };
428 
429 static const uint8_t l_u_ybr10[1024] = {
430  2, 3, 3, 4, 5, 5, 6, 7, 8, 9, 9, 10, 10, 10, 11, 11,
431  12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14,
432  14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
433  15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16,
434  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
435  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
436  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
437  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
438  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
439  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
440  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
441  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
442  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
443  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
444  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
445  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
446  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
447  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
448  16, 16, 16, 16, 16, 16, 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, 15, 15, 15, 15, 15, 15, 15,
491  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 14, 14, 14,
492  14, 14, 14, 14, 14, 14, 14, 13, 13, 13, 13, 13, 13, 12, 12, 12,
493  12, 11, 11, 11, 10, 10, 9, 9, 8, 8, 7, 6, 5, 4, 4, 3,
494 };
495 
496 static const uint8_t l_r_rgbx[1024] = {
497  4, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7,
498  7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
499  8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
500  9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10,
501  10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
502  10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
503  11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12,
504  12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
505  12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
506  13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
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, 14, 14, 14, 14, 14, 14, 14, 14,
509  14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
510  14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
511  14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15,
512  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 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, 16, 16, 16, 16, 16, 16,
517  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 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, 15, 15, 15, 15, 15, 15,
542  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 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, 14, 14, 14, 14, 14, 14, 14, 14, 14,
547  14, 14, 14, 14, 14, 14, 14, 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, 13, 13, 13, 13, 13, 13, 13,
550  13, 13, 13, 13, 13, 13, 13, 13, 13, 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, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
553  12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
554  12, 12, 12, 12, 12, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
555  11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
556  11, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
557  10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9,
558  9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8,
559  8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7,
560  7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5,
561 };
562 
563 static const uint8_t l_g_rgbx[1024] = {
564  3, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7,
565  8, 8, 9, 9, 9, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 12,
566  12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13,
567  13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
568  14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
569  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
570  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16,
571  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
572  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
573  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
574  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
575  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
576  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
577  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
578  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
579  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
580  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
581  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
582  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
583  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
584  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
585  16, 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, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
622  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
623  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 14, 14, 14,
624  14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 13,
625  13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 12, 12, 12, 12, 12, 12,
626  12, 12, 11, 11, 11, 11, 11, 11, 10, 10, 10, 10, 9, 9, 9, 9,
627  8, 7, 7, 7, 6, 6, 6, 6, 6, 5, 5, 5, 5, 4, 4, 4,
628 };
629 
630 static const uint8_t l_y_yry10[1024] = {
631  4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7, 7,
632  7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
633  8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
634  9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
635  10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11,
636  11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
637  11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
638  12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
639  13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
640  13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
641  13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
642  14, 14, 14, 14, 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, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
645  15, 15, 15, 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, 16, 16, 16, 16, 16, 16,
649  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 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, 15, 15, 15, 15, 15, 15, 15, 15,
678  15, 15, 15, 15, 15, 15, 15, 15, 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  14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
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, 13, 13,
685  13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
686  13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
687  13, 13, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
688  12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 11,
689  11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
690  11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 10, 10, 10, 10, 10, 10,
691  10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 9,
692  9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
693  8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7,
694  7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5,
695 };
696 
697 static const uint8_t l_y_yry10i[1024] = {
698  3, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7,
699  7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
700  8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
701  9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
702  10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11,
703  11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
704  11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12,
705  12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 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, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
708  13, 13, 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, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
711  14, 14, 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, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
715  15, 15, 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, 16,
720  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 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, 15, 15, 15, 15, 15, 15, 15, 15, 15,
741  15, 15, 15, 15, 15, 15, 15, 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  14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
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, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
751  13, 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, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
754  12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
755  12, 12, 12, 12, 12, 12, 12, 12, 11, 11, 11, 11, 11, 11, 11, 11,
756  11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
757  11, 11, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
758  10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 9, 9, 9, 9,
759  9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
760  8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7,
761  7, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5,
762 };
763 
764 static const uint8_t l_u_yry10[1024] = {
765  2, 3, 3, 4, 5, 6, 7, 7, 8, 8, 8, 9, 9, 10, 10, 10,
766  10, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13,
767  13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
768  14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
769  15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
770  16, 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, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
826  15, 15, 15, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 13, 13,
827  13, 13, 13, 13, 13, 12, 12, 12, 12, 12, 12, 12, 11, 11, 11, 11,
828  10, 10, 10, 10, 9, 9, 9, 8, 8, 7, 7, 6, 5, 4, 4, 3,
829 };
830 
831 static const uint8_t l_u_yry10i[1024] = {
832  2, 4, 4, 4, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9,
833  9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11,
834  11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13,
835  13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14,
836  14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15,
837  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
838  15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
839  16, 16, 16, 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, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
891  15, 15, 15, 15, 15, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
892  14, 14, 14, 14, 14, 14, 14, 13, 13, 13, 13, 13, 13, 13, 13, 13,
893  13, 13, 13, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 11,
894  11, 11, 11, 11, 11, 11, 11, 10, 10, 10, 10, 10, 10, 9, 9, 9,
895  9, 9, 8, 8, 8, 8, 7, 7, 7, 6, 6, 5, 5, 4, 4, 3,
896 };
897 
898 static const uint8_t l_y_ybri[256] = {
899  3, 3, 4, 4, 5, 5, 6, 6, 6, 7, 7, 7, 7, 7, 8, 8,
900  8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10,
901  10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12,
902  12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13,
903  13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14,
904  14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15,
905  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
906  15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
907  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
908  16, 16, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
909  15, 15, 15, 15, 15, 15, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
910  14, 14, 14, 14, 14, 14, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
911  13, 13, 13, 13, 13, 13, 13, 12, 12, 12, 12, 12, 12, 12, 12, 12,
912  12, 12, 12, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 10, 10,
913  10, 10, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9, 9, 8, 8,
914  8, 8, 8, 7, 7, 7, 7, 7, 6, 6, 6, 5, 5, 5, 4, 3,
915 };
916 
917 static const uint8_t l_u_ybri[256] = {
918  1, 3, 5, 6, 8, 8, 9, 10, 10, 11, 11, 12, 12, 13, 13, 13,
919  14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16,
920  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 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, 15, 15, 15, 15, 15, 14, 14, 14, 14, 14,
933  14, 13, 13, 13, 12, 12, 11, 11, 10, 10, 9, 8, 8, 6, 5, 2,
934 };
935 
936 static const uint8_t l_y_byryi[256] = {
937  3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8,
938  8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10,
939  10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12,
940  12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13,
941  13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14,
942  14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15,
943  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
944  15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
945  16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
946  16, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
947  15, 15, 15, 15, 15, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
948  14, 14, 14, 14, 14, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
949  13, 13, 13, 13, 13, 13, 13, 12, 12, 12, 12, 12, 12, 12, 12, 12,
950  12, 12, 12, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 10,
951  10, 10, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9, 9, 8, 8,
952  8, 8, 8, 7, 7, 7, 7, 7, 7, 6, 6, 6, 5, 4, 4, 3,
953 };
954 
955 static const uint8_t l_u_byryi[256] = {
956  1, 3, 4, 6, 6, 7, 8, 8, 9, 9, 10, 10, 10, 11, 11, 11,
957  12, 12, 12, 12, 13, 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15,
958  15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
959  16, 16, 16, 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, 15, 15, 15,
970  15, 15, 15, 15, 14, 14, 14, 14, 14, 13, 13, 13, 13, 12, 12, 12,
971  12, 11, 11, 11, 10, 10, 10, 9, 9, 8, 8, 7, 7, 5, 4, 3,
972 };
973 
974 static const uint8_t l_r_rgbxi[1024] = {
975  3, 4, 4, 4, 5, 5, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8,
976  8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
977  9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
978  10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11,
979  11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
980  11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
981  12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
982  12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
983  13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14,
984  14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
985  14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15,
986  15, 15, 15, 15, 15, 15, 15, 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, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
991  16, 16, 16, 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, 15,
1024  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 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, 14, 14, 14,
1029  14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
1030  14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 13, 13, 13, 13, 13, 13,
1031  13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 12,
1032  12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
1033  12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 11, 11, 11, 11,
1034  11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
1035  11, 11, 11, 11, 11, 11, 11, 10, 10, 10, 10, 10, 10, 10, 10, 10,
1036  10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 9, 9,
1037  9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8,
1038  8, 8, 8, 8, 7, 7, 7, 7, 6, 6, 6, 5, 5, 4, 4, 4,
1039 };
1040 
1041 static const uint8_t l_g_rgbxi[1024] = {
1042  2, 3, 4, 4, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,
1043  9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11,
1044  11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13,
1045  13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14,
1046  14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15,
1047  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
1048  15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16,
1049  16, 16, 16, 16, 16, 16, 16, 16, 16, 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, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
1100  15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
1101  15, 15, 15, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
1102  14, 14, 14, 14, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
1103  13, 13, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 11, 11,
1104  11, 11, 11, 11, 11, 10, 10, 10, 10, 10, 10, 10, 10, 9, 9, 9,
1105  9, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 6, 6, 4, 4, 3,
1106 };
1107 
1108 static void decode_ca4i(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
1109 {
1110  SheerVideoContext *s = avctx->priv_data;
1111  uint16_t *dst_y, *dst_u, *dst_v, *dst_a;
1112  int x, y;
1113 
1114  dst_a = (uint16_t *)p->data[3];
1115  dst_y = (uint16_t *)p->data[0];
1116  dst_u = (uint16_t *)p->data[1];
1117  dst_v = (uint16_t *)p->data[2];
1118 
1119  for (y = 0; y < avctx->height; y++) {
1120  if (get_bits1(gb)) {
1121  for (x = 0; x < avctx->width; x++) {
1122  dst_a[x] = get_bits(gb, 10);
1123  dst_y[x] = get_bits(gb, 10);
1124  dst_u[x] = get_bits(gb, 10);
1125  dst_v[x] = get_bits(gb, 10);
1126  }
1127  } else {
1128  int pred[4] = { 502, 512, 512, 502 };
1129 
1130  for (x = 0; x < avctx->width; x++) {
1131  int y, u, v, a;
1132 
1133  a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1134  y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1135  u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1136  v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1137 
1138  dst_a[x] = pred[3] = (a + pred[3]) & 0x3ff;
1139  dst_y[x] = pred[0] = (y + pred[0]) & 0x3ff;
1140  dst_u[x] = pred[1] = (u + pred[1]) & 0x3ff;
1141  dst_v[x] = pred[2] = (v + pred[2]) & 0x3ff;
1142  }
1143  }
1144 
1145  dst_y += p->linesize[0] / 2;
1146  dst_u += p->linesize[1] / 2;
1147  dst_v += p->linesize[2] / 2;
1148  dst_a += p->linesize[3] / 2;
1149  }
1150 }
1151 
1152 static void decode_ca4p(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
1153 {
1154  SheerVideoContext *s = avctx->priv_data;
1155  uint16_t *dst_y, *dst_u, *dst_v, *dst_a;
1156  int x, y;
1157 
1158  dst_a = (uint16_t *)p->data[3];
1159  dst_y = (uint16_t *)p->data[0];
1160  dst_u = (uint16_t *)p->data[1];
1161  dst_v = (uint16_t *)p->data[2];
1162 
1163  if (get_bits1(gb)) {
1164  for (x = 0; x < avctx->width; x++) {
1165  dst_a[x] = get_bits(gb, 10);
1166  dst_y[x] = get_bits(gb, 10);
1167  dst_u[x] = get_bits(gb, 10);
1168  dst_v[x] = get_bits(gb, 10);
1169  }
1170  } else {
1171  int pred[4] = { 502, 512, 512, 502 };
1172 
1173  for (x = 0; x < avctx->width; x++) {
1174  int y, u, v, a;
1175 
1176  a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1177  y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1178  u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1179  v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1180 
1181  dst_a[x] = pred[3] = (a + pred[3]) & 0x3ff;
1182  dst_y[x] = pred[0] = (y + pred[0]) & 0x3ff;
1183  dst_u[x] = pred[1] = (u + pred[1]) & 0x3ff;
1184  dst_v[x] = pred[2] = (v + pred[2]) & 0x3ff;
1185  }
1186  }
1187 
1188  dst_y += p->linesize[0] / 2;
1189  dst_u += p->linesize[1] / 2;
1190  dst_v += p->linesize[2] / 2;
1191  dst_a += p->linesize[3] / 2;
1192 
1193  for (y = 1; y < avctx->height; y++) {
1194  if (get_bits1(gb)) {
1195  for (x = 0; x < avctx->width; x++) {
1196  dst_a[x] = get_bits(gb, 10);
1197  dst_y[x] = get_bits(gb, 10);
1198  dst_u[x] = get_bits(gb, 10);
1199  dst_v[x] = get_bits(gb, 10);
1200  }
1201  } else {
1202  int pred_TL[4], pred_L[4], pred_T[4];
1203  int y, u, v, a;
1204 
1205  pred_TL[0] = pred_L[0] = dst_y[-p->linesize[0] / 2];
1206  pred_TL[1] = pred_L[1] = dst_u[-p->linesize[1] / 2];
1207  pred_TL[2] = pred_L[2] = dst_v[-p->linesize[2] / 2];
1208  pred_TL[3] = pred_L[3] = dst_a[-p->linesize[3] / 2];
1209 
1210  for (x = 0; x < avctx->width; x++) {
1211  pred_T[0] = dst_y[-p->linesize[0] / 2 + x];
1212  pred_T[1] = dst_u[-p->linesize[1] / 2 + x];
1213  pred_T[2] = dst_v[-p->linesize[2] / 2 + x];
1214  pred_T[3] = dst_a[-p->linesize[3] / 2 + x];
1215 
1216  a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1217  y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1218  u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1219  v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1220 
1221  dst_a[x] = pred_L[3] = (a + ((3 * (pred_T[3] + pred_L[3]) - 2 * pred_TL[3]) >> 2)) & 0x3ff;
1222  dst_y[x] = pred_L[0] = (y + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0x3ff;
1223  dst_u[x] = pred_L[1] = (u + ((3 * (pred_T[1] + pred_L[1]) - 2 * pred_TL[1]) >> 2)) & 0x3ff;
1224  dst_v[x] = pred_L[2] = (v + ((3 * (pred_T[2] + pred_L[2]) - 2 * pred_TL[2]) >> 2)) & 0x3ff;
1225 
1226  pred_TL[0] = pred_T[0];
1227  pred_TL[1] = pred_T[1];
1228  pred_TL[2] = pred_T[2];
1229  pred_TL[3] = pred_T[3];
1230  }
1231  }
1232 
1233  dst_y += p->linesize[0] / 2;
1234  dst_u += p->linesize[1] / 2;
1235  dst_v += p->linesize[2] / 2;
1236  dst_a += p->linesize[3] / 2;
1237  }
1238 }
1239 
1241 {
1242  SheerVideoContext *s = avctx->priv_data;
1243  uint16_t *dst_y, *dst_u, *dst_v;
1244  int x, y;
1245 
1246  dst_y = (uint16_t *)p->data[0];
1247  dst_u = (uint16_t *)p->data[1];
1248  dst_v = (uint16_t *)p->data[2];
1249 
1250  for (y = 0; y < avctx->height; y++) {
1251  if (get_bits1(gb)) {
1252  for (x = 0; x < avctx->width; x++) {
1253  dst_y[x] = get_bits(gb, 10);
1254  dst_u[x] = get_bits(gb, 10);
1255  dst_v[x] = get_bits(gb, 10);
1256  }
1257  } else {
1258  int pred[4] = { 502, 512, 512, 512 };
1259 
1260  for (x = 0; x < avctx->width; x++) {
1261  int y, u, v;
1262 
1263  y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1264  u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1265  v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1266 
1267  dst_y[x] = pred[0] = (y + pred[0]) & 0x3ff;
1268  dst_u[x] = pred[1] = (u + pred[1]) & 0x3ff;
1269  dst_v[x] = pred[2] = (v + pred[2]) & 0x3ff;
1270  }
1271  }
1272 
1273  dst_y += p->linesize[0] / 2;
1274  dst_u += p->linesize[1] / 2;
1275  dst_v += p->linesize[2] / 2;
1276  }
1277 }
1278 
1279 static void decode_ybr10(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
1280 {
1281  SheerVideoContext *s = avctx->priv_data;
1282  uint16_t *dst_y, *dst_u, *dst_v;
1283  int x, y;
1284 
1285  dst_y = (uint16_t *)p->data[0];
1286  dst_u = (uint16_t *)p->data[1];
1287  dst_v = (uint16_t *)p->data[2];
1288 
1289  if (get_bits1(gb)) {
1290  for (x = 0; x < avctx->width; x++) {
1291  dst_y[x] = get_bits(gb, 10);
1292  dst_u[x] = get_bits(gb, 10);
1293  dst_v[x] = get_bits(gb, 10);
1294  }
1295  } else {
1296  int pred[4] = { 502, 512, 512, 512 };
1297 
1298  for (x = 0; x < avctx->width; x++) {
1299  int y, u, v;
1300 
1301  y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1302  u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1303  v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1304 
1305  dst_y[x] = pred[0] = (y + pred[0]) & 0x3ff;
1306  dst_u[x] = pred[1] = (u + pred[1]) & 0x3ff;
1307  dst_v[x] = pred[2] = (v + pred[2]) & 0x3ff;
1308  }
1309  }
1310 
1311  dst_y += p->linesize[0] / 2;
1312  dst_u += p->linesize[1] / 2;
1313  dst_v += p->linesize[2] / 2;
1314 
1315  for (y = 1; y < avctx->height; y++) {
1316  if (get_bits1(gb)) {
1317  for (x = 0; x < avctx->width; x++) {
1318  dst_y[x] = get_bits(gb, 10);
1319  dst_u[x] = get_bits(gb, 10);
1320  dst_v[x] = get_bits(gb, 10);
1321  }
1322  } else {
1323  int pred_TL[4], pred_L[4], pred_T[4];
1324  int y, u, v;
1325 
1326  pred_TL[0] = pred_L[0] = dst_y[-p->linesize[0] / 2];
1327  pred_TL[1] = pred_L[1] = dst_u[-p->linesize[1] / 2];
1328  pred_TL[2] = pred_L[2] = dst_v[-p->linesize[2] / 2];
1329 
1330  for (x = 0; x < avctx->width; x++) {
1331  pred_T[0] = dst_y[-p->linesize[0] / 2 + x];
1332  pred_T[1] = dst_u[-p->linesize[1] / 2 + x];
1333  pred_T[2] = dst_v[-p->linesize[2] / 2 + x];
1334 
1335  y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1336  u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1337  v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1338 
1339  dst_y[x] = pred_L[0] = (y + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0x3ff;
1340  dst_u[x] = pred_L[1] = (u + ((3 * (pred_T[1] + pred_L[1]) - 2 * pred_TL[1]) >> 2)) & 0x3ff;
1341  dst_v[x] = pred_L[2] = (v + ((3 * (pred_T[2] + pred_L[2]) - 2 * pred_TL[2]) >> 2)) & 0x3ff;
1342 
1343  pred_TL[0] = pred_T[0];
1344  pred_TL[1] = pred_T[1];
1345  pred_TL[2] = pred_T[2];
1346  }
1347  }
1348 
1349  dst_y += p->linesize[0] / 2;
1350  dst_u += p->linesize[1] / 2;
1351  dst_v += p->linesize[2] / 2;
1352  }
1353 }
1354 
1356 {
1357  SheerVideoContext *s = avctx->priv_data;
1358  uint16_t *dst_y, *dst_u, *dst_v;
1359  int x, y;
1360 
1361  dst_y = (uint16_t *)p->data[0];
1362  dst_u = (uint16_t *)p->data[1];
1363  dst_v = (uint16_t *)p->data[2];
1364 
1365  for (y = 0; y < avctx->height; y++) {
1366  if (get_bits1(gb)) {
1367  for (x = 0; x < avctx->width; x += 2) {
1368  dst_y[x ] = get_bits(gb, 10);
1369  dst_u[x / 2] = get_bits(gb, 10);
1370  dst_y[x + 1] = get_bits(gb, 10);
1371  dst_v[x / 2] = get_bits(gb, 10);
1372  }
1373  } else {
1374  int pred[4] = { 502, 512, 512, 0 };
1375 
1376  for (x = 0; x < avctx->width; x += 2) {
1377  int y1, y2, u, v;
1378 
1379  y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1380  u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1381  y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1382  v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1383 
1384  dst_y[x ] = pred[0] = (y1 + pred[0]) & 0x3ff;
1385  dst_u[x / 2] = pred[1] = (u + pred[1]) & 0x3ff;
1386  dst_y[x + 1] = pred[0] = (y2 + pred[0]) & 0x3ff;
1387  dst_v[x / 2] = pred[2] = (v + pred[2]) & 0x3ff;
1388  }
1389  }
1390 
1391  dst_y += p->linesize[0] / 2;
1392  dst_u += p->linesize[1] / 2;
1393  dst_v += p->linesize[2] / 2;
1394  }
1395 }
1396 
1397 static void decode_yry10(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
1398 {
1399  SheerVideoContext *s = avctx->priv_data;
1400  uint16_t *dst_y, *dst_u, *dst_v;
1401  int x, y;
1402 
1403  dst_y = (uint16_t *)p->data[0];
1404  dst_u = (uint16_t *)p->data[1];
1405  dst_v = (uint16_t *)p->data[2];
1406 
1407  if (get_bits1(gb)) {
1408  for (x = 0; x < avctx->width; x += 2) {
1409  dst_y[x ] = get_bits(gb, 10);
1410  dst_u[x / 2] = get_bits(gb, 10);
1411  dst_y[x + 1] = get_bits(gb, 10);
1412  dst_v[x / 2] = get_bits(gb, 10);
1413  }
1414  } else {
1415  int pred[4] = { 502, 512, 512, 0 };
1416 
1417  for (x = 0; x < avctx->width; x += 2) {
1418  int y1, y2, u, v;
1419 
1420  y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1421  u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1422  y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1423  v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1424 
1425  dst_y[x ] = pred[0] = (y1 + pred[0]) & 0x3ff;
1426  dst_u[x / 2] = pred[1] = (u + pred[1]) & 0x3ff;
1427  dst_y[x + 1] = pred[0] = (y2 + pred[0]) & 0x3ff;
1428  dst_v[x / 2] = pred[2] = (v + pred[2]) & 0x3ff;
1429  }
1430  }
1431 
1432  dst_y += p->linesize[0] / 2;
1433  dst_u += p->linesize[1] / 2;
1434  dst_v += p->linesize[2] / 2;
1435 
1436  for (y = 1; y < avctx->height; y++) {
1437  if (get_bits1(gb)) {
1438  for (x = 0; x < avctx->width; x += 2) {
1439  dst_y[x ] = get_bits(gb, 10);
1440  dst_u[x / 2] = get_bits(gb, 10);
1441  dst_y[x + 1] = get_bits(gb, 10);
1442  dst_v[x / 2] = get_bits(gb, 10);
1443  }
1444  } else {
1445  int pred_TL[6], pred_L[6], pred_T[6];
1446  int y1, y2, u, v;
1447 
1448  pred_TL[0] = pred_L[0] = dst_y[-p->linesize[0] / 2];
1449  pred_TL[1] = pred_L[1] = dst_u[-p->linesize[1] / 2];
1450  pred_TL[2] = pred_L[2] = dst_v[-p->linesize[2] / 2];
1451 
1452  for (x = 0; x < avctx->width; x += 2) {
1453  pred_T[0] = dst_y[-p->linesize[0] / 2 + x];
1454  pred_T[3] = dst_y[-p->linesize[0] / 2 + x + 1];
1455  pred_T[1] = dst_u[-p->linesize[1] / 2 + x / 2];
1456  pred_T[2] = dst_v[-p->linesize[2] / 2 + x / 2];
1457 
1458  y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1459  u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1460  y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1461  v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1462 
1463  dst_y[x ] = pred_L[0] = (y1 + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0x3ff;
1464  dst_u[x / 2] = pred_L[1] = (u + (((pred_L[1] - pred_TL[1]) >> 1) + pred_T[1])) & 0x3ff;
1465  dst_y[x + 1] = pred_L[0] = (y2 + ((3 * (pred_T[3] + pred_L[0]) - 2 * pred_T[0]) >> 2)) & 0x3ff;
1466  dst_v[x / 2] = pred_L[2] = (v + (((pred_L[2] - pred_TL[2]) >> 1) + pred_T[2])) & 0x3ff;
1467 
1468  pred_TL[0] = pred_T[3];
1469  pred_TL[1] = pred_T[1];
1470  pred_TL[2] = pred_T[2];
1471  }
1472  }
1473 
1474  dst_y += p->linesize[0] / 2;
1475  dst_u += p->linesize[1] / 2;
1476  dst_v += p->linesize[2] / 2;
1477  }
1478 }
1479 
1480 static void decode_ca2i(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
1481 {
1482  SheerVideoContext *s = avctx->priv_data;
1483  uint16_t *dst_y, *dst_u, *dst_v, *dst_a;
1484  int x, y;
1485 
1486  dst_y = (uint16_t *)p->data[0];
1487  dst_u = (uint16_t *)p->data[1];
1488  dst_v = (uint16_t *)p->data[2];
1489  dst_a = (uint16_t *)p->data[3];
1490 
1491  for (y = 0; y < avctx->height; y++) {
1492  if (get_bits1(gb)) {
1493  for (x = 0; x < avctx->width; x += 2) {
1494  dst_a[x ] = get_bits(gb, 10);
1495  dst_y[x ] = get_bits(gb, 10);
1496  dst_u[x / 2] = get_bits(gb, 10);
1497  dst_a[x + 1] = get_bits(gb, 10);
1498  dst_y[x + 1] = get_bits(gb, 10);
1499  dst_v[x / 2] = get_bits(gb, 10);
1500  }
1501  } else {
1502  int pred[4] = { 502, 512, 512, 502 };
1503 
1504  for (x = 0; x < avctx->width; x += 2) {
1505  int y1, y2, u, v, a1, a2;
1506 
1507  a1 = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1508  y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1509  u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1510  a2 = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1511  y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1512  v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1513 
1514  dst_y[x ] = pred[0] = (y1 + pred[0]) & 0x3ff;
1515  dst_u[x / 2] = pred[1] = (u + pred[1]) & 0x3ff;
1516  dst_y[x + 1] = pred[0] = (y2 + pred[0]) & 0x3ff;
1517  dst_a[x ] = pred[3] = (a1 + pred[3]) & 0x3ff;
1518  dst_v[x / 2] = pred[2] = (v + pred[2]) & 0x3ff;
1519  dst_a[x + 1] = pred[3] = (a2 + pred[3]) & 0x3ff;
1520  }
1521  }
1522 
1523  dst_y += p->linesize[0] / 2;
1524  dst_u += p->linesize[1] / 2;
1525  dst_v += p->linesize[2] / 2;
1526  dst_a += p->linesize[3] / 2;
1527  }
1528 }
1529 
1530 static void decode_ca2p(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
1531 {
1532  SheerVideoContext *s = avctx->priv_data;
1533  uint16_t *dst_y, *dst_u, *dst_v, *dst_a;
1534  int x, y;
1535 
1536  dst_y = (uint16_t *)p->data[0];
1537  dst_u = (uint16_t *)p->data[1];
1538  dst_v = (uint16_t *)p->data[2];
1539  dst_a = (uint16_t *)p->data[3];
1540 
1541  if (get_bits1(gb)) {
1542  for (x = 0; x < avctx->width; x += 2) {
1543  dst_a[x ] = get_bits(gb, 10);
1544  dst_y[x ] = get_bits(gb, 10);
1545  dst_u[x / 2] = get_bits(gb, 10);
1546  dst_a[x + 1] = get_bits(gb, 10);
1547  dst_y[x + 1] = get_bits(gb, 10);
1548  dst_v[x / 2] = get_bits(gb, 10);
1549  }
1550  } else {
1551  int pred[4] = { 502, 512, 512, 502 };
1552 
1553  for (x = 0; x < avctx->width; x += 2) {
1554  int y1, y2, u, v, a1, a2;
1555 
1556  a1 = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1557  y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1558  u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1559  a2 = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1560  y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1561  v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1562 
1563  dst_y[x ] = pred[0] = (y1 + pred[0]) & 0x3ff;
1564  dst_u[x / 2] = pred[1] = (u + pred[1]) & 0x3ff;
1565  dst_y[x + 1] = pred[0] = (y2 + pred[0]) & 0x3ff;
1566  dst_a[x ] = pred[3] = (a1 + pred[3]) & 0x3ff;
1567  dst_v[x / 2] = pred[2] = (v + pred[2]) & 0x3ff;
1568  dst_a[x + 1] = pred[3] = (a2 + pred[3]) & 0x3ff;
1569  }
1570  }
1571 
1572  dst_y += p->linesize[0] / 2;
1573  dst_u += p->linesize[1] / 2;
1574  dst_v += p->linesize[2] / 2;
1575  dst_a += p->linesize[3] / 2;
1576 
1577  for (y = 1; y < avctx->height; y++) {
1578  if (get_bits1(gb)) {
1579  for (x = 0; x < avctx->width; x += 2) {
1580  dst_a[x ] = get_bits(gb, 10);
1581  dst_y[x ] = get_bits(gb, 10);
1582  dst_u[x / 2] = get_bits(gb, 10);
1583  dst_a[x + 1] = get_bits(gb, 10);
1584  dst_y[x + 1] = get_bits(gb, 10);
1585  dst_v[x / 2] = get_bits(gb, 10);
1586  }
1587  } else {
1588  int pred_TL[6], pred_L[6], pred_T[6];
1589  int y1, y2, u, v, a1, a2;
1590 
1591  pred_TL[0] = pred_L[0] = dst_y[-p->linesize[0] / 2];
1592  pred_TL[1] = pred_L[1] = dst_u[-p->linesize[1] / 2];
1593  pred_TL[2] = pred_L[2] = dst_v[-p->linesize[2] / 2];
1594  pred_TL[4] = pred_L[4] = dst_a[-p->linesize[3] / 2];
1595 
1596  for (x = 0; x < avctx->width; x += 2) {
1597  pred_T[0] = dst_y[-p->linesize[0] / 2 + x];
1598  pred_T[3] = dst_y[-p->linesize[0] / 2 + x + 1];
1599  pred_T[1] = dst_u[-p->linesize[1] / 2 + x / 2];
1600  pred_T[2] = dst_v[-p->linesize[2] / 2 + x / 2];
1601  pred_T[4] = dst_a[-p->linesize[3] / 2 + x];
1602  pred_T[5] = dst_a[-p->linesize[3] / 2 + x + 1];
1603 
1604  a1 = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1605  y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1606  u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1607  a2 = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1608  y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1609  v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1610 
1611  dst_y[x ] = pred_L[0] = (y1 + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0x3ff;
1612  dst_u[x / 2] = pred_L[1] = (u + (((pred_L[1] - pred_TL[1]) >> 1) + pred_T[1])) & 0x3ff;
1613  dst_y[x + 1] = pred_L[0] = (y2 + ((3 * (pred_T[3] + pred_L[0]) - 2 * pred_T[0]) >> 2)) & 0x3ff;
1614  dst_v[x / 2] = pred_L[2] = (v + (((pred_L[2] - pred_TL[2]) >> 1) + pred_T[2])) & 0x3ff;
1615  dst_a[x ] = pred_L[4] = (a1 + ((3 * (pred_T[4] + pred_L[4]) - 2 * pred_TL[4]) >> 2)) & 0x3ff;
1616  dst_a[x + 1] = pred_L[4] = (a2 + ((3 * (pred_T[5] + pred_L[4]) - 2 * pred_T[4]) >> 2)) & 0x3ff;
1617 
1618  pred_TL[0] = pred_T[3];
1619  pred_TL[1] = pred_T[1];
1620  pred_TL[2] = pred_T[2];
1621  pred_TL[4] = pred_T[5];
1622  }
1623  }
1624 
1625  dst_y += p->linesize[0] / 2;
1626  dst_u += p->linesize[1] / 2;
1627  dst_v += p->linesize[2] / 2;
1628  dst_a += p->linesize[3] / 2;
1629  }
1630 }
1631 
1632 static void decode_c82i(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
1633 {
1634  SheerVideoContext *s = avctx->priv_data;
1635  uint8_t *dst_y, *dst_u, *dst_v, *dst_a;
1636  int x, y;
1637 
1638  dst_y = p->data[0];
1639  dst_u = p->data[1];
1640  dst_v = p->data[2];
1641  dst_a = p->data[3];
1642 
1643  for (y = 0; y < avctx->height; y += 1) {
1644  if (get_bits1(gb)) {
1645  for (x = 0; x < avctx->width; x += 2) {
1646  dst_a[x ] = get_bits(gb, 8);
1647  dst_y[x ] = get_bits(gb, 8);
1648  dst_u[x / 2] = get_bits(gb, 8);
1649  dst_a[x + 1] = get_bits(gb, 8);
1650  dst_y[x + 1] = get_bits(gb, 8);
1651  dst_v[x / 2] = get_bits(gb, 8);
1652  }
1653  } else {
1654  int pred[4] = { 125, -128, -128, 125 };
1655 
1656  for (x = 0; x < avctx->width; x += 2) {
1657  int y1, y2, u, v, a1, a2;
1658 
1659  a1 = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1660  y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1661  u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1662  a2 = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1663  y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1664  v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1665 
1666  dst_y[x ] = pred[0] = (y1 + pred[0]) & 0xff;
1667  dst_y[x + 1] = pred[0] = (y2 + pred[0]) & 0xff;
1668  dst_u[x / 2] = pred[1] = (u + pred[1]) & 0xff;
1669  dst_v[x / 2] = pred[2] = (v + pred[2]) & 0xff;
1670  dst_a[x ] = pred[3] = (a1 + pred[3]) & 0xff;
1671  dst_a[x + 1] = pred[3] = (a2 + pred[3]) & 0xff;
1672  }
1673  }
1674 
1675  dst_y += p->linesize[0];
1676  dst_u += p->linesize[1];
1677  dst_v += p->linesize[2];
1678  dst_a += p->linesize[3];
1679  }
1680 }
1681 
1682 static void decode_c82p(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
1683 {
1684  SheerVideoContext *s = avctx->priv_data;
1685  uint8_t *dst_y, *dst_u, *dst_v, *dst_a;
1686  int x, y;
1687 
1688  dst_y = p->data[0];
1689  dst_u = p->data[1];
1690  dst_v = p->data[2];
1691  dst_a = p->data[3];
1692 
1693  if (get_bits1(gb)) {
1694  for (x = 0; x < avctx->width; x += 2) {
1695  dst_a[x ] = get_bits(gb, 8);
1696  dst_y[x ] = get_bits(gb, 8);
1697  dst_u[x / 2] = get_bits(gb, 8);
1698  dst_a[x + 1] = get_bits(gb, 8);
1699  dst_y[x + 1] = get_bits(gb, 8);
1700  dst_v[x / 2] = get_bits(gb, 8);
1701  }
1702  } else {
1703  int pred[4] = { 125, -128, -128, 125 };
1704 
1705  for (x = 0; x < avctx->width; x += 2) {
1706  int y1, y2, u, v, a1, a2;
1707 
1708  a1 = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1709  y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1710  u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1711  a2 = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1712  y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1713  v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1714 
1715  dst_y[x ] = pred[0] = (y1 + pred[0]) & 0xff;
1716  dst_u[x / 2] = pred[1] = (u + pred[1]) & 0xff;
1717  dst_y[x + 1] = pred[0] = (y2 + pred[0]) & 0xff;
1718  dst_a[x ] = pred[3] = (a1 + pred[3]) & 0xff;
1719  dst_v[x / 2] = pred[2] = (v + pred[2]) & 0xff;
1720  dst_a[x + 1] = pred[3] = (a2 + pred[3]) & 0xff;
1721  }
1722  }
1723 
1724  dst_y += p->linesize[0];
1725  dst_u += p->linesize[1];
1726  dst_v += p->linesize[2];
1727  dst_a += p->linesize[3];
1728 
1729  for (y = 1; y < avctx->height; y++) {
1730  if (get_bits1(gb)) {
1731  for (x = 0; x < avctx->width; x += 2) {
1732  dst_a[x ] = get_bits(gb, 8);
1733  dst_y[x ] = get_bits(gb, 8);
1734  dst_u[x / 2] = get_bits(gb, 8);
1735  dst_a[x + 1] = get_bits(gb, 8);
1736  dst_y[x + 1] = get_bits(gb, 8);
1737  dst_v[x / 2] = get_bits(gb, 8);
1738  }
1739  } else {
1740  int pred_TL[6], pred_L[6], pred_T[6];
1741  int y1, y2, u, v, a1, a2;
1742 
1743  pred_TL[0] = pred_L[0] = dst_y[-p->linesize[0]];
1744  pred_TL[1] = pred_L[1] = dst_u[-p->linesize[1]];
1745  pred_TL[2] = pred_L[2] = dst_v[-p->linesize[2]];
1746  pred_TL[4] = pred_L[4] = dst_a[-p->linesize[3]];
1747 
1748  for (x = 0; x < avctx->width; x += 2) {
1749  pred_T[0] = dst_y[-p->linesize[0] + x];
1750  pred_T[3] = dst_y[-p->linesize[0] + x + 1];
1751  pred_T[1] = dst_u[-p->linesize[1] + x / 2];
1752  pred_T[2] = dst_v[-p->linesize[2] + x / 2];
1753  pred_T[4] = dst_a[-p->linesize[3] + x];
1754  pred_T[5] = dst_a[-p->linesize[3] + x + 1];
1755 
1756  a1 = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1757  y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1758  u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1759  a2 = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1760  y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1761  v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1762 
1763  dst_y[x ] = pred_L[0] = (y1 + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0xff;
1764  dst_u[x / 2] = pred_L[1] = (u + (((pred_L[1] - pred_TL[1]) >> 1) + pred_T[1])) & 0xff;
1765  dst_y[x + 1] = pred_L[0] = (y2 + ((3 * (pred_T[3] + pred_L[0]) - 2 * pred_T[0]) >> 2)) & 0xff;
1766  dst_v[x / 2] = pred_L[2] = (v + (((pred_L[2] - pred_TL[2]) >> 1) + pred_T[2])) & 0xff;
1767  dst_a[x ] = pred_L[4] = (a1 + ((3 * (pred_T[4] + pred_L[4]) - 2 * pred_TL[4]) >> 2)) & 0xff;
1768  dst_a[x + 1] = pred_L[4] = (a2 + ((3 * (pred_T[5] + pred_L[4]) - 2 * pred_T[4]) >> 2)) & 0xff;
1769 
1770  pred_TL[0] = pred_T[3];
1771  pred_TL[1] = pred_T[1];
1772  pred_TL[2] = pred_T[2];
1773  pred_TL[4] = pred_T[5];
1774  }
1775  }
1776 
1777  dst_y += p->linesize[0];
1778  dst_u += p->linesize[1];
1779  dst_v += p->linesize[2];
1780  dst_a += p->linesize[3];
1781  }
1782 }
1783 
1784 static void decode_ybyr(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
1785 {
1786  SheerVideoContext *s = avctx->priv_data;
1787  uint8_t *dst_y, *dst_u, *dst_v;
1788  int x, y;
1789 
1790  dst_y = p->data[0];
1791  dst_u = p->data[1];
1792  dst_v = p->data[2];
1793 
1794  if (get_bits1(gb)) {
1795  for (x = 0; x < avctx->width; x += 2) {
1796  dst_y[x ] = get_bits(gb, 8);
1797  dst_u[x / 2] = get_bits(gb, 8) + 128;
1798  dst_y[x + 1] = get_bits(gb, 8);
1799  dst_v[x / 2] = get_bits(gb, 8) + 128;
1800  }
1801  } else {
1802  int pred[4] = { -128, 128, 128, 0 };
1803 
1804  for (x = 0; x < avctx->width; x += 2) {
1805  int y1, y2, u, v;
1806 
1807  y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1808  u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1809  y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1810  v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1811 
1812  dst_y[x ] = pred[0] = (y1 + pred[0]) & 0xff;
1813  dst_u[x / 2] = pred[1] = (u + pred[1]) & 0xff;
1814  dst_y[x + 1] = pred[0] = (y2 + pred[0]) & 0xff;
1815  dst_v[x / 2] = pred[2] = (v + pred[2]) & 0xff;
1816  }
1817  }
1818 
1819  dst_y += p->linesize[0];
1820  dst_u += p->linesize[1];
1821  dst_v += p->linesize[2];
1822 
1823  for (y = 1; y < avctx->height; y++) {
1824  if (get_bits1(gb)) {
1825  for (x = 0; x < avctx->width; x += 2) {
1826  dst_y[x ] = get_bits(gb, 8);
1827  dst_u[x / 2] = get_bits(gb, 8) + 128;
1828  dst_y[x + 1] = get_bits(gb, 8);
1829  dst_v[x / 2] = get_bits(gb, 8) + 128;
1830  }
1831  } else {
1832  int pred_TL[4], pred_L[4], pred_T[4];
1833  int y1, y2, u, v;
1834 
1835  pred_TL[0] = pred_L[0] = dst_y[-p->linesize[0]];
1836  pred_TL[1] = pred_L[1] = dst_u[-p->linesize[1]];
1837  pred_TL[2] = pred_L[2] = dst_v[-p->linesize[2]];
1838 
1839  for (x = 0; x < avctx->width; x += 2) {
1840  pred_T[0] = dst_y[-p->linesize[0] + x];
1841  pred_T[3] = dst_y[-p->linesize[0] + x + 1];
1842  pred_T[1] = dst_u[-p->linesize[1] + x / 2];
1843  pred_T[2] = dst_v[-p->linesize[2] + x / 2];
1844 
1845  y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1846  u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1847  y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1848  v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1849 
1850  dst_y[x ] = pred_L[0] = (y1 + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0xff;
1851  dst_u[x / 2] = pred_L[1] = (u + (((pred_L[1] - pred_TL[1]) >> 1) + pred_T[1])) & 0xff;
1852  dst_y[x + 1] = pred_L[0] = (y2 + ((3 * (pred_T[3] + pred_L[0]) - 2 * pred_T[0]) >> 2)) & 0xff;
1853  dst_v[x / 2] = pred_L[2] = (v + (((pred_L[2] - pred_TL[2]) >> 1) + pred_T[2])) & 0xff;
1854 
1855  pred_TL[0] = pred_T[3];
1856  pred_TL[1] = pred_T[1];
1857  pred_TL[2] = pred_T[2];
1858  }
1859  }
1860 
1861  dst_y += p->linesize[0];
1862  dst_u += p->linesize[1];
1863  dst_v += p->linesize[2];
1864  }
1865 }
1866 
1867 static void decode_byryi(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
1868 {
1869  SheerVideoContext *s = avctx->priv_data;
1870  uint8_t *dst_y, *dst_u, *dst_v;
1871  int x, y;
1872 
1873  dst_y = p->data[0];
1874  dst_u = p->data[1];
1875  dst_v = p->data[2];
1876 
1877  if (get_bits1(gb)) {
1878  for (x = 0; x < avctx->width; x += 2) {
1879  dst_y[x ] = get_bits(gb, 8);
1880  dst_u[x / 2] = get_bits(gb, 8);
1881  dst_y[x + 1] = get_bits(gb, 8);
1882  dst_v[x / 2] = get_bits(gb, 8);
1883  }
1884  } else {
1885  int pred[4] = { 125, -128, -128, 0 };
1886 
1887  for (x = 0; x < avctx->width; x += 2) {
1888  int y1, y2, u, v;
1889 
1890  y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1891  u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1892  y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1893  v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1894 
1895  dst_y[x ] = pred[0] = (y1 + pred[0]) & 0xff;
1896  dst_u[x / 2] = pred[1] = (u + pred[1]) & 0xff;
1897  dst_y[x + 1] = pred[0] = (y2 + pred[0]) & 0xff;
1898  dst_v[x / 2] = pred[2] = (v + pred[2]) & 0xff;
1899  }
1900  }
1901 
1902  dst_y += p->linesize[0];
1903  dst_u += p->linesize[1];
1904  dst_v += p->linesize[2];
1905 
1906  for (y = 1; y < avctx->height; y++) {
1907  if (get_bits1(gb)) {
1908  for (x = 0; x < avctx->width; x += 2) {
1909  dst_y[x ] = get_bits(gb, 8);
1910  dst_u[x / 2] = get_bits(gb, 8);
1911  dst_y[x + 1] = get_bits(gb, 8);
1912  dst_v[x / 2] = get_bits(gb, 8);
1913  }
1914  } else {
1915  int pred_L[4];
1916  int y1, y2, u, v;
1917 
1918  pred_L[0] = dst_y[-p->linesize[0]];
1919  pred_L[1] = dst_u[-p->linesize[1]];
1920  pred_L[2] = dst_v[-p->linesize[2]];
1921 
1922  for (x = 0; x < avctx->width; x += 2) {
1923  y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1924  u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1925  y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1926  v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1927 
1928  dst_y[x ] = pred_L[0] = (y1 + pred_L[0]) & 0xff;
1929  dst_u[x / 2] = pred_L[1] = (u + pred_L[1]) & 0xff;
1930  dst_y[x + 1] = pred_L[0] = (y2 + pred_L[0]) & 0xff;
1931  dst_v[x / 2] = pred_L[2] = (v + pred_L[2]) & 0xff;
1932  }
1933  }
1934 
1935  dst_y += p->linesize[0];
1936  dst_u += p->linesize[1];
1937  dst_v += p->linesize[2];
1938  }
1939 }
1940 
1941 static void decode_byry(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
1942 {
1943  SheerVideoContext *s = avctx->priv_data;
1944  uint8_t *dst_y, *dst_u, *dst_v;
1945  int x, y;
1946 
1947  dst_y = p->data[0];
1948  dst_u = p->data[1];
1949  dst_v = p->data[2];
1950 
1951  if (get_bits1(gb)) {
1952  for (x = 0; x < avctx->width; x += 2) {
1953  dst_y[x ] = get_bits(gb, 8);
1954  dst_u[x / 2] = get_bits(gb, 8);
1955  dst_y[x + 1] = get_bits(gb, 8);
1956  dst_v[x / 2] = get_bits(gb, 8);
1957  }
1958  } else {
1959  int pred[4] = { 125, -128, -128, 0 };
1960 
1961  for (x = 0; x < avctx->width; x += 2) {
1962  int y1, y2, u, v;
1963 
1964  y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1965  u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1966  y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
1967  v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
1968 
1969  dst_y[x ] = pred[0] = (y1 + pred[0]) & 0xff;
1970  dst_u[x / 2] = pred[1] = (u + pred[1]) & 0xff;
1971  dst_y[x + 1] = pred[0] = (y2 + pred[0]) & 0xff;
1972  dst_v[x / 2] = pred[2] = (v + pred[2]) & 0xff;
1973  }
1974  }
1975 
1976  dst_y += p->linesize[0];
1977  dst_u += p->linesize[1];
1978  dst_v += p->linesize[2];
1979 
1980  for (y = 1; y < avctx->height; y++) {
1981  if (get_bits1(gb)) {
1982  for (x = 0; x < avctx->width; x += 2) {
1983  dst_y[x ] = get_bits(gb, 8);
1984  dst_u[x / 2] = get_bits(gb, 8);
1985  dst_y[x + 1] = get_bits(gb, 8);
1986  dst_v[x / 2] = get_bits(gb, 8);
1987  }
1988  } else {
1989  int pred_TL[4], pred_L[4], pred_T[4];
1990  int y1, y2, u, v;
1991 
1992  pred_TL[0] = pred_L[0] = dst_y[-p->linesize[0]];
1993  pred_TL[1] = pred_L[1] = dst_u[-p->linesize[1]];
1994  pred_TL[2] = pred_L[2] = dst_v[-p->linesize[2]];
1995 
1996  for (x = 0; x < avctx->width; x += 2) {
1997  pred_T[0] = dst_y[-p->linesize[0] + x];
1998  pred_T[3] = dst_y[-p->linesize[0] + x + 1];
1999  pred_T[1] = dst_u[-p->linesize[1] + x / 2];
2000  pred_T[2] = dst_v[-p->linesize[2] + x / 2];
2001 
2002  y1 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
2003  u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2004  y2 = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
2005  v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2006 
2007  dst_y[x ] = pred_L[0] = (y1 + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0xff;
2008  dst_u[x / 2] = pred_L[1] = (u + (((pred_L[1] - pred_TL[1]) >> 1) + pred_T[1])) & 0xff;
2009  dst_y[x + 1] = pred_L[0] = (y2 + ((3 * (pred_T[3] + pred_L[0]) - 2 * pred_T[0]) >> 2)) & 0xff;
2010  dst_v[x / 2] = pred_L[2] = (v + (((pred_L[2] - pred_TL[2]) >> 1) + pred_T[2])) & 0xff;
2011 
2012  pred_TL[0] = pred_T[3];
2013  pred_TL[1] = pred_T[1];
2014  pred_TL[2] = pred_T[2];
2015  }
2016  }
2017 
2018  dst_y += p->linesize[0];
2019  dst_u += p->linesize[1];
2020  dst_v += p->linesize[2];
2021  }
2022 }
2023 
2024 static void decode_ybri(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
2025 {
2026  SheerVideoContext *s = avctx->priv_data;
2027  uint8_t *dst_y, *dst_u, *dst_v;
2028  int x, y;
2029 
2030  dst_y = p->data[0];
2031  dst_u = p->data[1];
2032  dst_v = p->data[2];
2033 
2034  if (get_bits1(gb)) {
2035  for (x = 0; x < avctx->width; x++) {
2036  dst_y[x] = get_bits(gb, 8);
2037  dst_u[x] = get_bits(gb, 8);
2038  dst_v[x] = get_bits(gb, 8);
2039  }
2040  } else {
2041  int pred[4] = { 125, -128, -128, -128 };
2042 
2043  for (x = 0; x < avctx->width; x++) {
2044  int y, u, v;
2045 
2046  y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
2047  u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2048  v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2049 
2050  dst_y[x] = pred[0] = (y + pred[0]) & 0xff;
2051  dst_u[x] = pred[1] = (u + pred[1]) & 0xff;
2052  dst_v[x] = pred[2] = (v + pred[2]) & 0xff;
2053  }
2054  }
2055 
2056  dst_y += p->linesize[0];
2057  dst_u += p->linesize[1];
2058  dst_v += p->linesize[2];
2059 
2060  for (y = 1; y < avctx->height; y++) {
2061  if (get_bits1(gb)) {
2062  for (x = 0; x < avctx->width; x++) {
2063  dst_y[x] = get_bits(gb, 8);
2064  dst_u[x] = get_bits(gb, 8);
2065  dst_v[x] = get_bits(gb, 8);
2066  }
2067  } else {
2068  int pred_L[4];
2069  int y, u, v;
2070 
2071  pred_L[0] = dst_y[-p->linesize[0]];
2072  pred_L[1] = dst_u[-p->linesize[1]];
2073  pred_L[2] = dst_v[-p->linesize[2]];
2074 
2075  for (x = 0; x < avctx->width; x++) {
2076  y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
2077  u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2078  v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2079 
2080  dst_y[x] = pred_L[0] = (y + pred_L[0]) & 0xff;
2081  dst_u[x] = pred_L[1] = (u + pred_L[1]) & 0xff;
2082  dst_v[x] = pred_L[2] = (v + pred_L[2]) & 0xff;
2083  }
2084  }
2085 
2086  dst_y += p->linesize[0];
2087  dst_u += p->linesize[1];
2088  dst_v += p->linesize[2];
2089  }
2090 }
2091 
2092 static void decode_ybr(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
2093 {
2094  SheerVideoContext *s = avctx->priv_data;
2095  uint8_t *dst_y, *dst_u, *dst_v;
2096  int x, y;
2097 
2098  dst_y = p->data[0];
2099  dst_u = p->data[1];
2100  dst_v = p->data[2];
2101 
2102  if (get_bits1(gb)) {
2103  for (x = 0; x < avctx->width; x++) {
2104  dst_y[x] = get_bits(gb, 8);
2105  dst_u[x] = get_bits(gb, 8);
2106  dst_v[x] = get_bits(gb, 8);
2107  }
2108  } else {
2109  int pred[4] = { 125, -128, -128, -128 };
2110 
2111  for (x = 0; x < avctx->width; x++) {
2112  int y, u, v;
2113 
2114  y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
2115  u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2116  v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2117 
2118  dst_y[x] = pred[0] = (y + pred[0]) & 0xff;
2119  dst_u[x] = pred[1] = (u + pred[1]) & 0xff;
2120  dst_v[x] = pred[2] = (v + pred[2]) & 0xff;
2121  }
2122  }
2123 
2124  dst_y += p->linesize[0];
2125  dst_u += p->linesize[1];
2126  dst_v += p->linesize[2];
2127 
2128  for (y = 1; y < avctx->height; y++) {
2129  if (get_bits1(gb)) {
2130  for (x = 0; x < avctx->width; x++) {
2131  dst_y[x] = get_bits(gb, 8);
2132  dst_u[x] = get_bits(gb, 8);
2133  dst_v[x] = get_bits(gb, 8);
2134  }
2135  } else {
2136  int pred_TL[4], pred_L[4], pred_T[4];
2137  int y, u, v;
2138 
2139  pred_TL[0] = pred_L[0] = dst_y[-p->linesize[0]];
2140  pred_TL[1] = pred_L[1] = dst_u[-p->linesize[1]];
2141  pred_TL[2] = pred_L[2] = dst_v[-p->linesize[2]];
2142 
2143  for (x = 0; x < avctx->width; x++) {
2144  pred_T[0] = dst_y[-p->linesize[0] + x];
2145  pred_T[1] = dst_u[-p->linesize[1] + x];
2146  pred_T[2] = dst_v[-p->linesize[2] + x];
2147 
2148  y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
2149  u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2150  v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2151 
2152  dst_y[x] = pred_L[0] = (y + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0xff;
2153  dst_u[x] = pred_L[1] = (u + ((3 * (pred_T[1] + pred_L[1]) - 2 * pred_TL[1]) >> 2)) & 0xff;
2154  dst_v[x] = pred_L[2] = (v + ((3 * (pred_T[2] + pred_L[2]) - 2 * pred_TL[2]) >> 2)) & 0xff;
2155 
2156  pred_TL[0] = pred_T[0];
2157  pred_TL[1] = pred_T[1];
2158  pred_TL[2] = pred_T[2];
2159  }
2160  }
2161 
2162  dst_y += p->linesize[0];
2163  dst_u += p->linesize[1];
2164  dst_v += p->linesize[2];
2165  }
2166 }
2167 
2168 static void decode_aybri(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
2169 {
2170  SheerVideoContext *s = avctx->priv_data;
2171  uint8_t *dst_a, *dst_y, *dst_u, *dst_v;
2172  int x, y;
2173 
2174  dst_a = p->data[3];
2175  dst_y = p->data[0];
2176  dst_u = p->data[1];
2177  dst_v = p->data[2];
2178 
2179  if (get_bits1(gb)) {
2180  for (x = 0; x < avctx->width; x++) {
2181  dst_a[x] = get_bits(gb, 8);
2182  dst_y[x] = get_bits(gb, 8);
2183  dst_u[x] = get_bits(gb, 8);
2184  dst_v[x] = get_bits(gb, 8);
2185  }
2186  } else {
2187  int pred[4] = { 125, 125, -128, -128 };
2188 
2189  for (x = 0; x < avctx->width; x++) {
2190  int a, y, u, v;
2191 
2192  a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2193  y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
2194  u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2195  v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2196 
2197  dst_a[x] = pred[0] = (a + pred[0]) & 0xff;
2198  dst_y[x] = pred[1] = (y + pred[1]) & 0xff;
2199  dst_u[x] = pred[2] = (u + pred[2]) & 0xff;
2200  dst_v[x] = pred[3] = (v + pred[3]) & 0xff;
2201  }
2202  }
2203 
2204  dst_a += p->linesize[3];
2205  dst_y += p->linesize[0];
2206  dst_u += p->linesize[1];
2207  dst_v += p->linesize[2];
2208 
2209  for (y = 1; y < avctx->height; y++) {
2210  if (get_bits1(gb)) {
2211  for (x = 0; x < avctx->width; x++) {
2212  dst_a[x] = get_bits(gb, 8);
2213  dst_y[x] = get_bits(gb, 8);
2214  dst_u[x] = get_bits(gb, 8);
2215  dst_v[x] = get_bits(gb, 8);
2216  }
2217  } else {
2218  int pred_L[4];
2219  int a, y, u, v;
2220 
2221  pred_L[0] = dst_a[-p->linesize[3]];
2222  pred_L[1] = dst_y[-p->linesize[0]];
2223  pred_L[2] = dst_u[-p->linesize[1]];
2224  pred_L[3] = dst_v[-p->linesize[2]];
2225 
2226  for (x = 0; x < avctx->width; x++) {
2227  a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2228  y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
2229  u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2230  v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2231 
2232  dst_a[x] = pred_L[0] = (a + pred_L[0]) & 0xff;
2233  dst_y[x] = pred_L[1] = (y + pred_L[1]) & 0xff;
2234  dst_u[x] = pred_L[2] = (u + pred_L[2]) & 0xff;
2235  dst_v[x] = pred_L[3] = (v + pred_L[3]) & 0xff;
2236  }
2237  }
2238 
2239  dst_a += p->linesize[3];
2240  dst_y += p->linesize[0];
2241  dst_u += p->linesize[1];
2242  dst_v += p->linesize[2];
2243  }
2244 }
2245 
2246 static void decode_aybr(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
2247 {
2248  SheerVideoContext *s = avctx->priv_data;
2249  uint8_t *dst_a, *dst_y, *dst_u, *dst_v;
2250  int x, y;
2251 
2252  dst_a = p->data[3];
2253  dst_y = p->data[0];
2254  dst_u = p->data[1];
2255  dst_v = p->data[2];
2256 
2257  if (get_bits1(gb)) {
2258  for (x = 0; x < avctx->width; x++) {
2259  dst_a[x] = get_bits(gb, 8);
2260  dst_y[x] = get_bits(gb, 8);
2261  dst_u[x] = get_bits(gb, 8);
2262  dst_v[x] = get_bits(gb, 8);
2263  }
2264  } else {
2265  int pred[4] = { 125, 125, -128, -128 };
2266 
2267  for (x = 0; x < avctx->width; x++) {
2268  int a, y, u, v;
2269 
2270  a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2271  y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
2272  u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2273  v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2274 
2275  dst_a[x] = pred[0] = (a + pred[0]) & 0xff;
2276  dst_y[x] = pred[1] = (y + pred[1]) & 0xff;
2277  dst_u[x] = pred[2] = (u + pred[2]) & 0xff;
2278  dst_v[x] = pred[3] = (v + pred[3]) & 0xff;
2279  }
2280  }
2281 
2282  dst_a += p->linesize[3];
2283  dst_y += p->linesize[0];
2284  dst_u += p->linesize[1];
2285  dst_v += p->linesize[2];
2286 
2287  for (y = 1; y < avctx->height; y++) {
2288  if (get_bits1(gb)) {
2289  for (x = 0; x < avctx->width; x++) {
2290  dst_a[x] = get_bits(gb, 8);
2291  dst_y[x] = get_bits(gb, 8);
2292  dst_u[x] = get_bits(gb, 8);
2293  dst_v[x] = get_bits(gb, 8);
2294  }
2295  } else {
2296  int pred_TL[4], pred_L[4], pred_T[4];
2297  int a, y, u, v;
2298 
2299  pred_TL[0] = pred_L[0] = dst_a[-p->linesize[3]];
2300  pred_TL[1] = pred_L[1] = dst_y[-p->linesize[0]];
2301  pred_TL[2] = pred_L[2] = dst_u[-p->linesize[1]];
2302  pred_TL[3] = pred_L[3] = dst_v[-p->linesize[2]];
2303 
2304  for (x = 0; x < avctx->width; x++) {
2305  pred_T[0] = dst_a[-p->linesize[3] + x];
2306  pred_T[1] = dst_y[-p->linesize[0] + x];
2307  pred_T[2] = dst_u[-p->linesize[1] + x];
2308  pred_T[3] = dst_v[-p->linesize[2] + x];
2309 
2310  a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2311  y = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
2312  u = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2313  v = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2314 
2315  dst_a[x] = pred_L[0] = (a + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0xff;
2316  dst_y[x] = pred_L[1] = (y + ((3 * (pred_T[1] + pred_L[1]) - 2 * pred_TL[1]) >> 2)) & 0xff;
2317  dst_u[x] = pred_L[2] = (u + ((3 * (pred_T[2] + pred_L[2]) - 2 * pred_TL[2]) >> 2)) & 0xff;
2318  dst_v[x] = pred_L[3] = (v + ((3 * (pred_T[3] + pred_L[3]) - 2 * pred_TL[3]) >> 2)) & 0xff;
2319 
2320  pred_TL[0] = pred_T[0];
2321  pred_TL[1] = pred_T[1];
2322  pred_TL[2] = pred_T[2];
2323  pred_TL[3] = pred_T[3];
2324  }
2325  }
2326 
2327  dst_a += p->linesize[3];
2328  dst_y += p->linesize[0];
2329  dst_u += p->linesize[1];
2330  dst_v += p->linesize[2];
2331  }
2332 }
2333 
2334 static void decode_argxi(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
2335 {
2336  SheerVideoContext *s = avctx->priv_data;
2337  uint16_t *dst_r, *dst_g, *dst_b, *dst_a;
2338  int x, y;
2339 
2340  dst_r = (uint16_t *)p->data[2];
2341  dst_g = (uint16_t *)p->data[0];
2342  dst_b = (uint16_t *)p->data[1];
2343  dst_a = (uint16_t *)p->data[3];
2344 
2345  for (y = 0; y < avctx->height; y++) {
2346  if (get_bits1(gb)) {
2347  for (x = 0; x < avctx->width; x++) {
2348  dst_a[x] = get_bits(gb, 10);
2349  dst_r[x] = get_bits(gb, 10);
2350  dst_g[x] = get_bits(gb, 10);
2351  dst_b[x] = get_bits(gb, 10);
2352  }
2353  } else {
2354  int pred[4] = { 512, 512, 512, 512 };
2355 
2356  for (x = 0; x < avctx->width; x++) {
2357  int r, g, b, a;
2358 
2359  a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2360  r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
2361  g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2362  b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2363 
2364  dst_a[x] = pred[3] = (a + pred[3]) & 0x3ff;
2365  dst_r[x] = pred[0] = (r + pred[0]) & 0x3ff;
2366  dst_g[x] = pred[1] = (r + g + pred[1]) & 0x3ff;
2367  dst_b[x] = pred[2] = (r + g + b + pred[2]) & 0x3ff;
2368  }
2369  }
2370 
2371  dst_r += p->linesize[2] / 2;
2372  dst_g += p->linesize[0] / 2;
2373  dst_b += p->linesize[1] / 2;
2374  dst_a += p->linesize[3] / 2;
2375  }
2376 }
2377 
2378 static void decode_argx(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
2379 {
2380  SheerVideoContext *s = avctx->priv_data;
2381  uint16_t *dst_r, *dst_g, *dst_b, *dst_a;
2382  int x, y;
2383 
2384  dst_r = (uint16_t *)p->data[2];
2385  dst_g = (uint16_t *)p->data[0];
2386  dst_b = (uint16_t *)p->data[1];
2387  dst_a = (uint16_t *)p->data[3];
2388 
2389  if (get_bits1(gb)) {
2390  for (x = 0; x < avctx->width; x++) {
2391  dst_a[x] = get_bits(gb, 10);
2392  dst_r[x] = get_bits(gb, 10);
2393  dst_g[x] = get_bits(gb, 10);
2394  dst_b[x] = get_bits(gb, 10);
2395  }
2396  } else {
2397  int pred[4] = { 512, 512, 512, 512 };
2398 
2399  for (x = 0; x < avctx->width; x++) {
2400  int r, g, b, a;
2401 
2402  a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2403  r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
2404  g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2405  b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2406 
2407  dst_a[x] = pred[3] = (a + pred[3]) & 0x3ff;
2408  dst_r[x] = pred[0] = (r + pred[0]) & 0x3ff;
2409  dst_g[x] = pred[1] = (r + g + pred[1]) & 0x3ff;
2410  dst_b[x] = pred[2] = (r + g + b + pred[2]) & 0x3ff;
2411  }
2412  }
2413 
2414  dst_r += p->linesize[2] / 2;
2415  dst_g += p->linesize[0] / 2;
2416  dst_b += p->linesize[1] / 2;
2417  dst_a += p->linesize[3] / 2;
2418 
2419  for (y = 1; y < avctx->height; y++) {
2420  if (get_bits1(gb)) {
2421  for (x = 0; x < avctx->width; x++) {
2422  dst_a[x] = get_bits(gb, 10);
2423  dst_r[x] = get_bits(gb, 10);
2424  dst_g[x] = get_bits(gb, 10);
2425  dst_b[x] = get_bits(gb, 10);
2426  }
2427  } else {
2428  int pred_TL[4], pred_L[4], pred_T[4];
2429  int r, g, b, a;
2430 
2431  pred_TL[0] = pred_L[0] = dst_r[-p->linesize[2] / 2];
2432  pred_TL[1] = pred_L[1] = dst_g[-p->linesize[0] / 2];
2433  pred_TL[2] = pred_L[2] = dst_b[-p->linesize[1] / 2];
2434  pred_TL[3] = pred_L[3] = dst_a[-p->linesize[3] / 2];
2435 
2436  for (x = 0; x < avctx->width; x++) {
2437  pred_T[0] = dst_r[-p->linesize[2] / 2 + x];
2438  pred_T[1] = dst_g[-p->linesize[0] / 2 + x];
2439  pred_T[2] = dst_b[-p->linesize[1] / 2 + x];
2440  pred_T[3] = dst_a[-p->linesize[3] / 2 + x];
2441 
2442  a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2443  r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
2444  g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2445  b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2446 
2447  dst_a[x] = pred_L[3] = (a + ((3 * (pred_T[3] + pred_L[3]) - 2 * pred_TL[3]) >> 2)) & 0x3ff;
2448  dst_r[x] = pred_L[0] = (r + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0x3ff;
2449  dst_g[x] = pred_L[1] = (r + g + ((3 * (pred_T[1] + pred_L[1]) - 2 * pred_TL[1]) >> 2)) & 0x3ff;
2450  dst_b[x] = pred_L[2] = (r + g + b + ((3 * (pred_T[2] + pred_L[2]) - 2 * pred_TL[2]) >> 2)) & 0x3ff;
2451 
2452  pred_TL[0] = pred_T[0];
2453  pred_TL[1] = pred_T[1];
2454  pred_TL[2] = pred_T[2];
2455  pred_TL[3] = pred_T[3];
2456  }
2457  }
2458 
2459  dst_r += p->linesize[2] / 2;
2460  dst_g += p->linesize[0] / 2;
2461  dst_b += p->linesize[1] / 2;
2462  dst_a += p->linesize[3] / 2;
2463  }
2464 }
2465 
2466 static void decode_rgbxi(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
2467 {
2468  SheerVideoContext *s = avctx->priv_data;
2469  uint16_t *dst_r, *dst_g, *dst_b;
2470  int x, y;
2471 
2472  dst_r = (uint16_t *)p->data[2];
2473  dst_g = (uint16_t *)p->data[0];
2474  dst_b = (uint16_t *)p->data[1];
2475 
2476  for (y = 0; y < avctx->height; y++) {
2477  if (get_bits1(gb)) {
2478  for (x = 0; x < avctx->width; x++) {
2479  dst_r[x] = get_bits(gb, 10);
2480  dst_g[x] = get_bits(gb, 10);
2481  dst_b[x] = get_bits(gb, 10);
2482  }
2483  } else {
2484  int pred[4] = { 512, 512, 512, 0 };
2485 
2486  for (x = 0; x < avctx->width; x++) {
2487  int r, g, b;
2488 
2489  r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
2490  g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2491  b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2492 
2493  dst_r[x] = pred[0] = (r + pred[0]) & 0x3ff;
2494  dst_g[x] = pred[1] = (r + g + pred[1]) & 0x3ff;
2495  dst_b[x] = pred[2] = (r + g + b + pred[2]) & 0x3ff;
2496  }
2497  }
2498 
2499  dst_r += p->linesize[2] / 2;
2500  dst_g += p->linesize[0] / 2;
2501  dst_b += p->linesize[1] / 2;
2502  }
2503 }
2504 
2505 static void decode_rgbx(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
2506 {
2507  SheerVideoContext *s = avctx->priv_data;
2508  uint16_t *dst_r, *dst_g, *dst_b;
2509  int x, y;
2510 
2511  dst_r = (uint16_t *)p->data[2];
2512  dst_g = (uint16_t *)p->data[0];
2513  dst_b = (uint16_t *)p->data[1];
2514 
2515  if (get_bits1(gb)) {
2516  for (x = 0; x < avctx->width; x++) {
2517  dst_r[x] = get_bits(gb, 10);
2518  dst_g[x] = get_bits(gb, 10);
2519  dst_b[x] = get_bits(gb, 10);
2520  }
2521  } else {
2522  int pred[4] = { 512, 512, 512, 0 };
2523 
2524  for (x = 0; x < avctx->width; x++) {
2525  int r, g, b;
2526 
2527  r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
2528  g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2529  b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2530 
2531  dst_r[x] = pred[0] = (r + pred[0]) & 0x3ff;
2532  dst_g[x] = pred[1] = (r + g + pred[1]) & 0x3ff;
2533  dst_b[x] = pred[2] = (r + g + b + pred[2]) & 0x3ff;
2534  }
2535  }
2536 
2537  dst_r += p->linesize[2] / 2;
2538  dst_g += p->linesize[0] / 2;
2539  dst_b += p->linesize[1] / 2;
2540 
2541  for (y = 1; y < avctx->height; y++) {
2542  if (get_bits1(gb)) {
2543  for (x = 0; x < avctx->width; x++) {
2544  dst_r[x] = get_bits(gb, 10);
2545  dst_g[x] = get_bits(gb, 10);
2546  dst_b[x] = get_bits(gb, 10);
2547  }
2548  } else {
2549  int pred_TL[4], pred_L[4], pred_T[4];
2550  int r, g, b;
2551 
2552  pred_TL[0] = pred_L[0] = dst_r[-p->linesize[2] / 2];
2553  pred_TL[1] = pred_L[1] = dst_g[-p->linesize[0] / 2];
2554  pred_TL[2] = pred_L[2] = dst_b[-p->linesize[1] / 2];
2555 
2556  for (x = 0; x < avctx->width; x++) {
2557  pred_T[0] = dst_r[-p->linesize[2] / 2 + x];
2558  pred_T[1] = dst_g[-p->linesize[0] / 2 + x];
2559  pred_T[2] = dst_b[-p->linesize[1] / 2 + x];
2560 
2561  r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
2562  g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2563  b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2564 
2565  dst_r[x] = pred_L[0] = (r + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0x3ff;
2566  dst_g[x] = pred_L[1] = (r + g + ((3 * (pred_T[1] + pred_L[1]) - 2 * pred_TL[1]) >> 2)) & 0x3ff;
2567  dst_b[x] = pred_L[2] = (r + g + b + ((3 * (pred_T[2] + pred_L[2]) - 2 * pred_TL[2]) >> 2)) & 0x3ff;
2568 
2569  pred_TL[0] = pred_T[0];
2570  pred_TL[1] = pred_T[1];
2571  pred_TL[2] = pred_T[2];
2572  }
2573  }
2574 
2575  dst_r += p->linesize[2] / 2;
2576  dst_g += p->linesize[0] / 2;
2577  dst_b += p->linesize[1] / 2;
2578  }
2579 }
2580 
2581 static void decode_argbi(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
2582 {
2583  SheerVideoContext *s = avctx->priv_data;
2584  uint8_t *dst;
2585  int x, y;
2586 
2587  dst = p->data[0];
2588  if (get_bits1(gb)) {
2589  for (x = 0; x < avctx->width; x++) {
2590  dst[x * 4 + 0] = get_bits(gb, 8);
2591  dst[x * 4 + 1] = get_bits(gb, 8);
2592  dst[x * 4 + 2] = get_bits(gb, 8);
2593  dst[x * 4 + 3] = get_bits(gb, 8);
2594  }
2595  } else {
2596  int pred[4] = { -128, -128, -128, -128 };
2597 
2598  for (x = 0; x < avctx->width; x++) {
2599  int a, r, g, b;
2600 
2601  a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2602  r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
2603  g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2604  b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2605 
2606  dst[4 * x + 0] = pred[0] = (a + pred[0]) & 0xff;
2607  dst[4 * x + 1] = pred[1] = (r + pred[1]) & 0xff;
2608  dst[4 * x + 2] = pred[2] = (r + g + pred[2]) & 0xff;
2609  dst[4 * x + 3] = pred[3] = (r + g + b + pred[3]) & 0xff;
2610  }
2611  }
2612 
2613  dst += p->linesize[0];
2614  for (y = 1; y < avctx->height; y++) {
2615  if (get_bits1(gb)) {
2616  for (x = 0; x < avctx->width; x++) {
2617  dst[x * 4 + 0] = get_bits(gb, 8);
2618  dst[x * 4 + 1] = get_bits(gb, 8);
2619  dst[x * 4 + 2] = get_bits(gb, 8);
2620  dst[x * 4 + 3] = get_bits(gb, 8);
2621  }
2622  } else {
2623  int pred_L[4];
2624  int a, r, g, b;
2625 
2626  pred_L[0] = dst[-p->linesize[0] + 0];
2627  pred_L[1] = dst[-p->linesize[0] + 1];
2628  pred_L[2] = dst[-p->linesize[0] + 2];
2629  pred_L[3] = dst[-p->linesize[0] + 3];
2630 
2631  for (x = 0; x < avctx->width; x++) {
2632  a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2633  r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
2634  g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2635  b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2636 
2637  dst[4 * x + 0] = pred_L[0] = (a + pred_L[0]) & 0xff;
2638  dst[4 * x + 1] = pred_L[1] = (r + pred_L[1]) & 0xff;
2639  dst[4 * x + 2] = pred_L[2] = (r + g + pred_L[2]) & 0xff;
2640  dst[4 * x + 3] = pred_L[3] = (r + g + b + pred_L[3]) & 0xff;
2641  }
2642  }
2643  dst += p->linesize[0];
2644  }
2645 }
2646 
2647 static void decode_argb(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
2648 {
2649  SheerVideoContext *s = avctx->priv_data;
2650  uint8_t *dst;
2651  int x, y;
2652 
2653  dst = p->data[0];
2654  if (get_bits1(gb)) {
2655  for (x = 0; x < avctx->width; x++) {
2656  dst[x * 4 + 0] = get_bits(gb, 8);
2657  dst[x * 4 + 1] = get_bits(gb, 8);
2658  dst[x * 4 + 2] = get_bits(gb, 8);
2659  dst[x * 4 + 3] = get_bits(gb, 8);
2660  }
2661  } else {
2662  int pred[4] = { -128, -128, -128, -128 };
2663 
2664  for (x = 0; x < avctx->width; x++) {
2665  int a, r, g, b;
2666 
2667  a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2668  r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
2669  g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2670  b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2671 
2672  dst[4 * x + 0] = pred[0] = (a + pred[0]) & 0xff;
2673  dst[4 * x + 1] = pred[1] = (r + pred[1]) & 0xff;
2674  dst[4 * x + 2] = pred[2] = (r + g + pred[2]) & 0xff;
2675  dst[4 * x + 3] = pred[3] = (r + g + b + pred[3]) & 0xff;
2676  }
2677  }
2678 
2679  dst += p->linesize[0];
2680  for (y = 1; y < avctx->height; y++) {
2681  if (get_bits1(gb)) {
2682  for (x = 0; x < avctx->width; x++) {
2683  dst[x * 4 + 0] = get_bits(gb, 8);
2684  dst[x * 4 + 1] = get_bits(gb, 8);
2685  dst[x * 4 + 2] = get_bits(gb, 8);
2686  dst[x * 4 + 3] = get_bits(gb, 8);
2687  }
2688  } else {
2689  int pred_TL[4], pred_L[4], pred_T[4];
2690  int a, r, g, b;
2691 
2692  pred_TL[0] = pred_L[0] = dst[-p->linesize[0] + 0];
2693  pred_TL[1] = pred_L[1] = dst[-p->linesize[0] + 1];
2694  pred_TL[2] = pred_L[2] = dst[-p->linesize[0] + 2];
2695  pred_TL[3] = pred_L[3] = dst[-p->linesize[0] + 3];
2696 
2697  for (x = 0; x < avctx->width; x++) {
2698  pred_T[0] = dst[-p->linesize[0] + 4 * x + 0];
2699  pred_T[1] = dst[-p->linesize[0] + 4 * x + 1];
2700  pred_T[2] = dst[-p->linesize[0] + 4 * x + 2];
2701  pred_T[3] = dst[-p->linesize[0] + 4 * x + 3];
2702 
2703  a = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2704  r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
2705  g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2706  b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2707 
2708  dst[4 * x + 0] = pred_L[0] = (a + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0xff;
2709  dst[4 * x + 1] = pred_L[1] = (r + ((3 * (pred_T[1] + pred_L[1]) - 2 * pred_TL[1]) >> 2)) & 0xff;
2710  dst[4 * x + 2] = pred_L[2] = (r + g + ((3 * (pred_T[2] + pred_L[2]) - 2 * pred_TL[2]) >> 2)) & 0xff;
2711  dst[4 * x + 3] = pred_L[3] = (r + g + b + ((3 * (pred_T[3] + pred_L[3]) - 2 * pred_TL[3]) >> 2)) & 0xff;
2712 
2713  pred_TL[0] = pred_T[0];
2714  pred_TL[1] = pred_T[1];
2715  pred_TL[2] = pred_T[2];
2716  pred_TL[3] = pred_T[3];
2717  }
2718  }
2719  dst += p->linesize[0];
2720  }
2721 }
2722 
2723 static void decode_rgbi(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
2724 {
2725  SheerVideoContext *s = avctx->priv_data;
2726  uint8_t *dst;
2727  int x, y;
2728 
2729  dst = p->data[0];
2730  if (get_bits1(gb)) {
2731  for (x = 0; x < avctx->width; x++) {
2732  dst[x * 4 + 0] = get_bits(gb, 8);
2733  dst[x * 4 + 1] = get_bits(gb, 8);
2734  dst[x * 4 + 2] = get_bits(gb, 8);
2735  }
2736  } else {
2737  int pred[4] = { -128, -128, -128, -128 };
2738 
2739  for (x = 0; x < avctx->width; x++) {
2740  int r, g, b;
2741 
2742  r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
2743  g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2744  b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2745 
2746  dst[4 * x + 0] = pred[0] = (r + pred[0]) & 0xff;
2747  dst[4 * x + 1] = pred[1] = (r + g + pred[1]) & 0xff;
2748  dst[4 * x + 2] = pred[2] = (r + g + b + pred[2]) & 0xff;
2749  }
2750  }
2751 
2752  dst += p->linesize[0];
2753  for (y = 1; y < avctx->height; y++) {
2754  if (get_bits1(gb)) {
2755  for (x = 0; x < avctx->width; x++) {
2756  dst[x * 4 + 0] = get_bits(gb, 8);
2757  dst[x * 4 + 1] = get_bits(gb, 8);
2758  dst[x * 4 + 2] = get_bits(gb, 8);
2759  }
2760  } else {
2761  int pred_L[4];
2762  int r, g, b;
2763 
2764  pred_L[0] = dst[-p->linesize[0] + 0];
2765  pred_L[1] = dst[-p->linesize[0] + 1];
2766  pred_L[2] = dst[-p->linesize[0] + 2];
2767 
2768  for (x = 0; x < avctx->width; x++) {
2769  r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
2770  g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2771  b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2772 
2773  dst[4 * x + 0] = pred_L[0] = (r + pred_L[0]) & 0xff;
2774  dst[4 * x + 1] = pred_L[1] = (r + g + pred_L[1]) & 0xff;
2775  dst[4 * x + 2] = pred_L[2] = (r + g + b + pred_L[2]) & 0xff;
2776  }
2777  }
2778  dst += p->linesize[0];
2779  }
2780 }
2781 
2782 static void decode_rgb(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
2783 {
2784  SheerVideoContext *s = avctx->priv_data;
2785  uint8_t *dst;
2786  int x, y;
2787 
2788  dst = p->data[0];
2789  if (get_bits1(gb)) {
2790  for (x = 0; x < avctx->width; x++) {
2791  dst[x * 4 + 0] = get_bits(gb, 8);
2792  dst[x * 4 + 1] = get_bits(gb, 8);
2793  dst[x * 4 + 2] = get_bits(gb, 8);
2794  }
2795  } else {
2796  int pred[4] = { -128, -128, -128, -128 };
2797 
2798  for (x = 0; x < avctx->width; x++) {
2799  int r, g, b;
2800 
2801  r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
2802  g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2803  b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2804 
2805  dst[4 * x + 0] = pred[0] = (r + pred[0]) & 0xff;
2806  dst[4 * x + 1] = pred[1] = (r + g + pred[1]) & 0xff;
2807  dst[4 * x + 2] = pred[2] = (r + g + b + pred[2]) & 0xff;
2808  }
2809  }
2810 
2811  dst += p->linesize[0];
2812  for (y = 1; y < avctx->height; y++) {
2813  if (get_bits1(gb)) {
2814  for (x = 0; x < avctx->width; x++) {
2815  dst[x * 4 + 0] = get_bits(gb, 8);
2816  dst[x * 4 + 1] = get_bits(gb, 8);
2817  dst[x * 4 + 2] = get_bits(gb, 8);
2818  }
2819  } else {
2820  int pred_TL[4], pred_L[4], pred_T[4];
2821  int r, g, b;
2822 
2823  pred_TL[0] = pred_L[0] = dst[-p->linesize[0] + 0];
2824  pred_TL[1] = pred_L[1] = dst[-p->linesize[0] + 1];
2825  pred_TL[2] = pred_L[2] = dst[-p->linesize[0] + 2];
2826 
2827  for (x = 0; x < avctx->width; x++) {
2828  pred_T[0] = dst[-p->linesize[0] + 4 * x + 0];
2829  pred_T[1] = dst[-p->linesize[0] + 4 * x + 1];
2830  pred_T[2] = dst[-p->linesize[0] + 4 * x + 2];
2831 
2832  r = get_vlc2(gb, s->vlc[0].table, s->vlc[0].bits, 2);
2833  g = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2834  b = get_vlc2(gb, s->vlc[1].table, s->vlc[1].bits, 2);
2835 
2836  dst[4 * x + 0] = pred_L[0] = (r + ((3 * (pred_T[0] + pred_L[0]) - 2 * pred_TL[0]) >> 2)) & 0xff;
2837  dst[4 * x + 1] = pred_L[1] = (r + g + ((3 * (pred_T[1] + pred_L[1]) - 2 * pred_TL[1]) >> 2)) & 0xff;
2838  dst[4 * x + 2] = pred_L[2] = (r + g + b + ((3 * (pred_T[2] + pred_L[2]) - 2 * pred_TL[2]) >> 2)) & 0xff;
2839 
2840  pred_TL[0] = pred_T[0];
2841  pred_TL[1] = pred_T[1];
2842  pred_TL[2] = pred_T[2];
2843  }
2844  }
2845  dst += p->linesize[0];
2846  }
2847 }
2848 
2849 static int build_vlc(VLC *vlc, const uint8_t *len, int count)
2850 {
2851  uint32_t codes[1024];
2852  uint8_t bits[1024];
2853  uint16_t syms[1024];
2854  uint64_t index;
2855  int i;
2856 
2857  index = 0;
2858  for (i = 0; i < count; i++) {
2859  codes[i] = index >> (32 - len[i]);
2860  bits[i] = len[i];
2861  syms[i] = i;
2862  index += 1ULL << (32 - len[i]);
2863  }
2864 
2865  ff_free_vlc(vlc);
2866  return ff_init_vlc_sparse(vlc, 16, count,
2867  bits, sizeof(*bits), sizeof(*bits),
2868  codes, sizeof(*codes), sizeof(*codes),
2869  syms, sizeof(*syms), sizeof(*syms), 0);
2870 }
2871 
2872 static int decode_frame(AVCodecContext *avctx,
2873  void *data, int *got_frame,
2874  AVPacket *avpkt)
2875 {
2876  SheerVideoContext *s = avctx->priv_data;
2877  ThreadFrame frame = { .f = data };
2878  AVFrame *p = data;
2879  GetBitContext gb;
2880  unsigned format;
2881  int ret;
2882 
2883  if (avpkt->size <= 20)
2884  return AVERROR_INVALIDDATA;
2885 
2886  if (AV_RL32(avpkt->data) != MKTAG('S','h','i','r') &&
2887  AV_RL32(avpkt->data) != MKTAG('Z','w','a','k'))
2888  return AVERROR_INVALIDDATA;
2889 
2890  format = AV_RL32(avpkt->data + 16);
2891  switch (format) {
2892  case MKTAG(' ', 'R', 'G', 'B'):
2893  avctx->pix_fmt = AV_PIX_FMT_RGB0;
2894  s->decode_frame = decode_rgb;
2895  if (s->format != format) {
2896  ret = build_vlc(&s->vlc[0], l_r_rgb, 256);
2897  ret |= build_vlc(&s->vlc[1], l_g_rgb, 256);
2898  }
2899  break;
2900  case MKTAG(' ', 'r', 'G', 'B'):
2901  avctx->pix_fmt = AV_PIX_FMT_RGB0;
2903  if (s->format != format) {
2904  ret = build_vlc(&s->vlc[0], l_r_rgbi, 256);
2905  ret |= build_vlc(&s->vlc[1], l_g_rgbi, 256);
2906  }
2907  break;
2908  case MKTAG('A', 'R', 'G', 'X'):
2909  avctx->pix_fmt = AV_PIX_FMT_GBRAP10;
2911  if (s->format != format) {
2912  ret = build_vlc(&s->vlc[0], l_r_rgbx, 1024);
2913  ret |= build_vlc(&s->vlc[1], l_g_rgbx, 1024);
2914  }
2915  break;
2916  case MKTAG('A', 'r', 'G', 'X'):
2917  avctx->pix_fmt = AV_PIX_FMT_GBRAP10;
2919  if (s->format != format) {
2920  ret = build_vlc(&s->vlc[0], l_r_rgbxi, 1024);
2921  ret |= build_vlc(&s->vlc[1], l_g_rgbxi, 1024);
2922  }
2923  break;
2924  case MKTAG('R', 'G', 'B', 'X'):
2925  avctx->pix_fmt = AV_PIX_FMT_GBRP10;
2927  if (s->format != format) {
2928  ret = build_vlc(&s->vlc[0], l_r_rgbx, 1024);
2929  ret |= build_vlc(&s->vlc[1], l_g_rgbx, 1024);
2930  }
2931  break;
2932  case MKTAG('r', 'G', 'B', 'X'):
2933  avctx->pix_fmt = AV_PIX_FMT_GBRP10;
2935  if (s->format != format) {
2936  ret = build_vlc(&s->vlc[0], l_r_rgbxi, 1024);
2937  ret |= build_vlc(&s->vlc[1], l_g_rgbxi, 1024);
2938  }
2939  break;
2940  case MKTAG('A', 'R', 'G', 'B'):
2941  avctx->pix_fmt = AV_PIX_FMT_ARGB;
2943  if (s->format != format) {
2944  ret = build_vlc(&s->vlc[0], l_r_rgb, 256);
2945  ret |= build_vlc(&s->vlc[1], l_g_rgb, 256);
2946  }
2947  break;
2948  case MKTAG('A', 'r', 'G', 'B'):
2949  avctx->pix_fmt = AV_PIX_FMT_ARGB;
2951  if (s->format != format) {
2952  ret = build_vlc(&s->vlc[0], l_r_rgbi, 256);
2953  ret |= build_vlc(&s->vlc[1], l_g_rgbi, 256);
2954  }
2955  break;
2956  case MKTAG('A', 'Y', 'B', 'R'):
2957  case MKTAG('A', 'Y', 'b', 'R'):
2958  avctx->pix_fmt = AV_PIX_FMT_YUVA444P;
2960  if (s->format != format) {
2961  ret = build_vlc(&s->vlc[0], l_y_ybr, 256);
2962  ret |= build_vlc(&s->vlc[1], l_u_ybr, 256);
2963  }
2964  break;
2965  case MKTAG('A', 'y', 'B', 'R'):
2966  case MKTAG('A', 'y', 'b', 'R'):
2967  avctx->pix_fmt = AV_PIX_FMT_YUVA444P;
2969  if (s->format != format) {
2970  ret = build_vlc(&s->vlc[0], l_y_ybri, 256);
2971  ret |= build_vlc(&s->vlc[1], l_u_ybri, 256);
2972  }
2973  break;
2974  case MKTAG(' ', 'Y', 'B', 'R'):
2975  case MKTAG(' ', 'Y', 'b', 'R'):
2976  avctx->pix_fmt = AV_PIX_FMT_YUV444P;
2977  s->decode_frame = decode_ybr;
2978  if (s->format != format) {
2979  ret = build_vlc(&s->vlc[0], l_y_ybr, 256);
2980  ret |= build_vlc(&s->vlc[1], l_u_ybr, 256);
2981  }
2982  break;
2983  case MKTAG(' ', 'y', 'B', 'R'):
2984  case MKTAG(' ', 'y', 'b', 'R'):
2985  avctx->pix_fmt = AV_PIX_FMT_YUV444P;
2987  if (s->format != format) {
2988  ret = build_vlc(&s->vlc[0], l_y_ybri, 256);
2989  ret |= build_vlc(&s->vlc[1], l_u_ybri, 256);
2990  }
2991  break;
2992  case MKTAG('Y', 'B', 'R', 0x0a):
2993  avctx->pix_fmt = AV_PIX_FMT_YUV444P10;
2995  if (s->format != format) {
2996  ret = build_vlc(&s->vlc[0], l_y_ybr10, 1024);
2997  ret |= build_vlc(&s->vlc[1], l_u_ybr10, 1024);
2998  }
2999  break;
3000  case MKTAG('y', 'B', 'R', 0x0a):
3001  avctx->pix_fmt = AV_PIX_FMT_YUV444P10;
3003  if (s->format != format) {
3004  ret = build_vlc(&s->vlc[0], l_y_ybr10i, 1024);
3005  ret |= build_vlc(&s->vlc[1], l_u_ybr10i, 1024);
3006  }
3007  break;
3008  case MKTAG('C', 'A', '4', 'p'):
3009  avctx->pix_fmt = AV_PIX_FMT_YUVA444P10;
3011  if (s->format != format) {
3012  ret = build_vlc(&s->vlc[0], l_y_ybr10, 1024);
3013  ret |= build_vlc(&s->vlc[1], l_u_ybr10, 1024);
3014  }
3015  break;
3016  case MKTAG('C', 'A', '4', 'i'):
3017  avctx->pix_fmt = AV_PIX_FMT_YUVA444P10;
3019  if (s->format != format) {
3020  ret = build_vlc(&s->vlc[0], l_y_ybr10i, 1024);
3021  ret |= build_vlc(&s->vlc[1], l_u_ybr10i, 1024);
3022  }
3023  break;
3024  case MKTAG('B', 'Y', 'R', 'Y'):
3025  avctx->pix_fmt = AV_PIX_FMT_YUV422P;
3027  if (s->format != format) {
3028  ret = build_vlc(&s->vlc[0], l_y_byry, 256);
3029  ret |= build_vlc(&s->vlc[1], l_u_byry, 256);
3030  }
3031  break;
3032  case MKTAG('B', 'Y', 'R', 'y'):
3033  avctx->pix_fmt = AV_PIX_FMT_YUV422P;
3035  if (s->format != format) {
3036  ret = build_vlc(&s->vlc[0], l_y_byryi, 256);
3037  ret |= build_vlc(&s->vlc[1], l_u_byryi, 256);
3038  }
3039  break;
3040  case MKTAG('Y', 'b', 'Y', 'r'):
3041  avctx->pix_fmt = AV_PIX_FMT_YUV422P;
3043  if (s->format != format) {
3044  ret = build_vlc(&s->vlc[0], l_y_ybyr, 256);
3045  ret |= build_vlc(&s->vlc[1], l_u_ybyr, 256);
3046  }
3047  break;
3048  case MKTAG('C', '8', '2', 'p'):
3049  avctx->pix_fmt = AV_PIX_FMT_YUVA422P;
3051  if (s->format != format) {
3052  ret = build_vlc(&s->vlc[0], l_y_byry, 256);
3053  ret |= build_vlc(&s->vlc[1], l_u_byry, 256);
3054  }
3055  break;
3056  case MKTAG('C', '8', '2', 'i'):
3057  avctx->pix_fmt = AV_PIX_FMT_YUVA422P;
3059  if (s->format != format) {
3060  ret = build_vlc(&s->vlc[0], l_y_byryi, 256);
3061  ret |= build_vlc(&s->vlc[1], l_u_byryi, 256);
3062  }
3063  break;
3064  case MKTAG(0xa2, 'Y', 'R', 'Y'):
3065  avctx->pix_fmt = AV_PIX_FMT_YUV422P10;
3067  if (s->format != format) {
3068  ret = build_vlc(&s->vlc[0], l_y_yry10, 1024);
3069  ret |= build_vlc(&s->vlc[1], l_u_yry10, 1024);
3070  }
3071  break;
3072  case MKTAG(0xa2, 'Y', 'R', 'y'):
3073  avctx->pix_fmt = AV_PIX_FMT_YUV422P10;
3075  if (s->format != format) {
3076  ret = build_vlc(&s->vlc[0], l_y_yry10i, 1024);
3077  ret |= build_vlc(&s->vlc[1], l_u_yry10i, 1024);
3078  }
3079  break;
3080  case MKTAG('C', 'A', '2', 'p'):
3081  avctx->pix_fmt = AV_PIX_FMT_YUVA422P10;
3083  if (s->format != format) {
3084  ret = build_vlc(&s->vlc[0], l_y_yry10, 1024);
3085  ret |= build_vlc(&s->vlc[1], l_u_yry10, 1024);
3086  }
3087  break;
3088  case MKTAG('C', 'A', '2', 'i'):
3089  avctx->pix_fmt = AV_PIX_FMT_YUVA422P10;
3091  if (s->format != format) {
3092  ret = build_vlc(&s->vlc[0], l_y_yry10i, 1024);
3093  ret |= build_vlc(&s->vlc[1], l_u_yry10i, 1024);
3094  }
3095  break;
3096  default:
3097  avpriv_request_sample(avctx, "unsupported format: 0x%X", format);
3098  return AVERROR_PATCHWELCOME;
3099  }
3100 
3101  if (s->format != format) {
3102  if (ret < 0)
3103  return ret;
3104  s->format = format;
3105  }
3106 
3108  p->key_frame = 1;
3109 
3110  if ((ret = ff_thread_get_buffer(avctx, &frame, 0)) < 0)
3111  return ret;
3112 
3113  if ((ret = init_get_bits8(&gb, avpkt->data + 20, avpkt->size - 20)) < 0)
3114  return ret;
3115 
3116  s->decode_frame(avctx, p, &gb);
3117 
3118  *got_frame = 1;
3119 
3120  return avpkt->size;
3121 }
3122 
3123 #if HAVE_THREADS
3124 static int decode_init_thread_copy(AVCodecContext *avctx)
3125 {
3126  SheerVideoContext *s = avctx->priv_data;
3127 
3128  s->format = 0;
3129  memset(&s->vlc[0], 0, sizeof(s->vlc[0]));
3130  memset(&s->vlc[1], 0, sizeof(s->vlc[1]));
3131 
3132  return 0;
3133 }
3134 #endif
3135 
3137 {
3138  SheerVideoContext *s = avctx->priv_data;
3139 
3140  ff_free_vlc(&s->vlc[0]);
3141  ff_free_vlc(&s->vlc[1]);
3142 
3143  return 0;
3144 }
3145 
3147  .name = "sheervideo",
3148  .long_name = NULL_IF_CONFIG_SMALL("BitJazz SheerVideo"),
3149  .type = AVMEDIA_TYPE_VIDEO,
3150  .id = AV_CODEC_ID_SHEERVIDEO,
3151  .priv_data_size = sizeof(SheerVideoContext),
3152  .init_thread_copy = ONLY_IF_THREADS_ENABLED(decode_init_thread_copy),
3153  .close = decode_end,
3154  .decode = decode_frame,
3155  .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS,
3156 };
static const uint8_t l_u_yry10i[1024]
Definition: sheervideo.c:831
static av_cold int decode_end(AVCodecContext *avctx)
Definition: sheervideo.c:3136
static const uint8_t l_y_ybri[256]
Definition: sheervideo.c:898
const char * s
Definition: avisynth_c.h:631
#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:1682
This structure describes decoded (raw) audio or video data.
Definition: frame.h:184
static const uint8_t l_y_ybr10[1024]
Definition: sheervideo.c:295
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:101
static const uint8_t l_u_ybr[256]
Definition: sheervideo.c:133
static void decode_ca2p(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
Definition: sheervideo.c:1530
static void decode_byryi(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
Definition: sheervideo.c:1867
#define AV_PIX_FMT_GBRAP10
Definition: pixfmt.h:361
#define AV_PIX_FMT_YUVA422P10
Definition: pixfmt.h:375
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:247
static int init_thread_copy(AVCodecContext *avctx)
Definition: tta.c:390
const char * g
Definition: vf_curves.c:108
static void decode_aybri(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
Definition: sheervideo.c:2168
static void decode_ybr10(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
Definition: sheervideo.c:1279
static void decode_rgbx(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
Definition: sheervideo.c:2505
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:275
int size
Definition: avcodec.h:1581
const char * b
Definition: vf_curves.c:109
#define AV_PIX_FMT_GBRP10
Definition: pixfmt.h:357
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1877
static void decode_ca2i(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
Definition: sheervideo.c:1480
#define a1
Definition: regdef.h:47
static const uint8_t l_g_rgb[256]
Definition: sheervideo.c:95
static const uint8_t l_y_byry[256]
Definition: sheervideo.c:190
AVCodec.
Definition: avcodec.h:3542
static int build_vlc(VLC *vlc, const uint8_t *len, int count)
Definition: sheervideo.c:2849
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:2872
#define av_cold
Definition: attributes.h:82
static const uint8_t l_g_rgbx[1024]
Definition: sheervideo.c:563
packed RGB 8:8:8, 32bpp, RGBXRGBX... X=unused/undefined
Definition: pixfmt.h:251
AVCodec ff_sheervideo_decoder
Definition: sheervideo.c:3146
Multithreading support functions.
static const uint8_t l_y_yry10[1024]
Definition: sheervideo.c:630
static AVFrame * frame
static void decode_argbi(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
Definition: sheervideo.c:2581
uint8_t * data
Definition: avcodec.h:1580
static void decode_rgbi(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
Definition: sheervideo.c:2723
static const uint8_t l_u_ybr10i[1024]
Definition: sheervideo.c:362
bitstream reader API header.
static void decode_argxi(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
Definition: sheervideo.c:2334
static void decode_aybr(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
Definition: sheervideo.c:2246
static const uint8_t l_y_ybyr[256]
Definition: sheervideo.c:152
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
Definition: pixfmt.h:187
static const uint8_t l_r_rgbxi[1024]
Definition: sheervideo.c:974
static void decode_rgb(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
Definition: sheervideo.c:2782
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:176
const char * r
Definition: vf_curves.c:107
static const uint8_t l_g_rgbi[256]
Definition: sheervideo.c:76
const char * name
Name of the codec implementation.
Definition: avcodec.h:3549
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:344
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:1019
static void decode_c82i(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
Definition: sheervideo.c:1632
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:215
static const uint8_t l_y_yry10i[1024]
Definition: sheervideo.c:697
static const uint8_t l_r_rgb[256]
Definition: sheervideo.c:38
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:258
int width
picture width / height.
Definition: avcodec.h:1836
static void decode_byry(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
Definition: sheervideo.c:1941
typedef void(APIENTRY *FF_PFNGLACTIVETEXTUREPROC)(GLenum texture)
#define a2
Definition: regdef.h:48
static const uint8_t l_u_byry[256]
Definition: sheervideo.c:209
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:535
#define AV_PIX_FMT_YUVA444P10
Definition: pixfmt.h:376
static void decode_argx(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
Definition: sheervideo.c:2378
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:2647
static const uint8_t l_g_rgbxi[1024]
Definition: sheervideo.c:1041
Libavcodec external API header.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:215
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
Definition: get_bits.h:437
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Definition: pixfmt.h:188
static void decode_ca4p(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
Definition: sheervideo.c:1152
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:1649
static void decode_ca4i(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
Definition: sheervideo.c:1108
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:299
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:2024
static const uint8_t l_u_yry10[1024]
Definition: sheervideo.c:764
static const uint8_t l_r_rgbx[1024]
Definition: sheervideo.c:496
#define u(width,...)
void(* decode_frame)(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
Definition: sheervideo.c:35
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:342
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:198
static void decode_yry10(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
Definition: sheervideo.c:1397
common internal api header.
if(ret< 0)
Definition: vf_mcdeint.c:282
static const uint8_t l_y_ybr10i[1024]
Definition: sheervideo.c:228
static void decode_ybr10i(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
Definition: sheervideo.c:1240
unsigned format
Definition: sheervideo.c:33
static const uint8_t l_u_ybri[256]
Definition: sheervideo.c:917
static const uint8_t l_r_rgbi[256]
Definition: sheervideo.c:57
void * priv_data
Definition: avcodec.h:1691
static void decode_rgbxi(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
Definition: sheervideo.c:2466
int len
static const uint8_t l_u_byryi[256]
Definition: sheervideo.c:955
VLC_TYPE(* table)[2]
code, bits
Definition: vlc.h:28
static void decode_ybr(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
Definition: sheervideo.c:2092
int key_frame
1 -> keyframe, 0-> not
Definition: frame.h:253
static const uint8_t l_y_ybr[256]
Definition: sheervideo.c:114
#define MKTAG(a, b, c, d)
Definition: common.h:342
static const uint8_t l_y_byryi[256]
Definition: sheervideo.c:936
static void decode_ybyr(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
Definition: sheervideo.c:1784
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
Definition: bytestream.h:87
This structure stores compressed data.
Definition: avcodec.h:1557
void ff_free_vlc(VLC *vlc)
Definition: bitstream.c:360
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:956
static void decode_yry10i(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
Definition: sheervideo.c:1355
static const uint8_t l_u_ybyr[256]
Definition: sheervideo.c:171
for(j=16;j >0;--j)
static const uint8_t l_u_ybr10[1024]
Definition: sheervideo.c:429