1 /*
2 * CDXL video decoder
3 * Copyright (c) 2011-2012 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 #define UNCHECKED_BITSTREAM_READER 1
23
29
30 #define BIT_PLANAR 0x00
32 #define BYTE_PLANAR 0x40
34 #define BYTE_LINE 0xC0
35
49
51 {
53
57
58 return 0;
59 }
60
62 {
63 int i;
64
67 unsigned r = ((rgb >> 8) & 0xF) * 0x11;
68 unsigned g = ((rgb >> 4) & 0xF) * 0x11;
69 unsigned b = (rgb & 0xF) * 0x11;
70 AV_WN32(&new_palette[i], (0xFFU << 24) | (r << 16) | (g << 8) | b);
71 }
72 }
73
75 {
77 int x, y, plane;
78
80 for (plane = 0; plane < c->
bpp; plane++) {
83 out[linesize * y + x] |=
get_bits1(&gb) << plane;
85 }
86 }
87 }
88
90 {
92 int x, y, plane;
93
96 for (plane = 0; plane < c->
bpp; plane++) {
98 out[linesize * y + x] |=
get_bits1(&gb) << plane;
100 }
101 }
102 }
103
105 {
107
111 break;
114 break;
115 }
116 }
117
119 {
120 uint32_t *new_palette = (uint32_t *)c->
frame.
data[1];
121
124 }
125
127 {
129 uint32_t new_palette[16],
r,
g,
b;
131 int x, y;
132
135
138
139 for (y = 0; y < avctx->
height; y++) {
140 r = new_palette[0] & 0xFF0000;
141 g = new_palette[0] & 0xFF00;
142 b = new_palette[0] & 0xFF;
143 for (x = 0; x < avctx->
width; x++) {
144 index = *ptr++;
145 op = index >> 4;
146 index &= 15;
147 switch (op) {
148 case 0:
149 r = new_palette[
index] & 0xFF0000;
150 g = new_palette[
index] & 0xFF00;
151 b = new_palette[
index] & 0xFF;
152 break;
153 case 1:
154 b = index * 0x11;
155 break;
156 case 2:
157 r = index * 0x11 << 16;
158 break;
159 case 3:
160 g = index * 0x11 << 8;
161 break;
162 }
163 AV_WL24(out + x * 3, r | g | b);
164 }
166 }
167 }
168
170 {
172 uint32_t new_palette[64],
r,
g,
b;
174 int x, y;
175
178
181
182 for (y = 0; y < avctx->
height; y++) {
183 r = new_palette[0] & 0xFF0000;
184 g = new_palette[0] & 0xFF00;
185 b = new_palette[0] & 0xFF;
186 for (x = 0; x < avctx->
width; x++) {
187 index = *ptr++;
188 op = index >> 6;
189 index &= 63;
190 switch (op) {
191 case 0:
192 r = new_palette[
index] & 0xFF0000;
193 g = new_palette[
index] & 0xFF00;
194 b = new_palette[
index] & 0xFF;
195 break;
196 case 1:
197 b = (index << 2) | (b & 3);
198 break;
199 case 2:
200 r = (index << 18) | (r & (3 << 16));
201 break;
202 case 3:
203 g = (index << 10) | (g & (3 << 8));
204 break;
205 }
206 AV_WL24(out + x * 3, r | g | b);
207 }
209 }
210 }
211
214 {
217 int ret, w, h, encoding, aligned_width, buf_size = pkt->
size;
219
220 if (buf_size < 32)
222 encoding = buf[1] & 7;
223 c->
format = buf[1] & 0xE0;
231
234 if (buf_size < c->palette_size + 32)
241 }
242
244 return ret;
247
254 }
else if (encoding == 1 && (c->
bpp == 6 || c->
bpp == 8)) {
258 } else {
262 }
263
266
270 return ret;
271 }
273
274 if (encoding) {
281 else
283 } else {
285 }
286 *got_frame = 1;
288
289 return buf_size;
290 }
291
293 {
295
299
300 return 0;
301 }
302
313 };