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 /**
23 * @file
24 * Commodore CDXL video decoder
25 * @author Paul B Mahol
26 */
27
28 #define UNCHECKED_BITSTREAM_READER 1
29
35
36 #define BIT_PLANAR 0x00
38 #define BYTE_PLANAR 0x40
40 #define BYTE_LINE 0xC0
41
54
56 {
58
61
62 return 0;
63 }
64
66 {
67 int i;
68
71 unsigned r = ((rgb >> 8) & 0xF) * 0x11;
72 unsigned g = ((rgb >> 4) & 0xF) * 0x11;
73 unsigned b = (rgb & 0xF) * 0x11;
74 AV_WN32(&new_palette[i], (0xFFU << 24) | (r << 16) | (g << 8) | b);
75 }
76 }
77
79 {
82
84 return;
85 for (plane = 0; plane < c->
bpp; plane++) {
88 out[linesize * y + x] |=
get_bits1(&gb) << plane;
90 }
91 }
92 }
93
95 {
98
100 return;
102 for (plane = 0; plane < c->
bpp; plane++) {
104 out[linesize * y + x] |=
get_bits1(&gb) << plane;
106 }
107 }
108 }
109
111 {
113
117 break;
120 break;
121 }
122 }
123
125 {
126 uint32_t *new_palette = (uint32_t *)frame->
data[1];
127
131 }
132
134 {
136 uint32_t new_palette[16],
r,
g,
b;
139
141 out = frame->
data[0];
142
145
146 for (y = 0; y < avctx->
height; y++) {
147 r = new_palette[0] & 0xFF0000;
148 g = new_palette[0] & 0xFF00;
149 b = new_palette[0] & 0xFF;
150 for (x = 0; x < avctx->
width; x++) {
151 index = *ptr++;
152 op = index >> 4;
153 index &= 15;
154 switch (op) {
155 case 0:
156 r = new_palette[
index] & 0xFF0000;
157 g = new_palette[
index] & 0xFF00;
158 b = new_palette[
index] & 0xFF;
159 break;
160 case 1:
161 b = index * 0x11;
162 break;
163 case 2:
164 r = index * 0x11 << 16;
165 break;
166 case 3:
167 g = index * 0x11 << 8;
168 break;
169 }
170 AV_WL24(out + x * 3, r | g | b);
171 }
173 }
174 }
175
177 {
179 uint32_t new_palette[64],
r,
g,
b;
182
184 out = frame->
data[0];
185
188
189 for (y = 0; y < avctx->
height; y++) {
190 r = new_palette[0] & 0xFF0000;
191 g = new_palette[0] & 0xFF00;
192 b = new_palette[0] & 0xFF;
193 for (x = 0; x < avctx->
width; x++) {
194 index = *ptr++;
195 op = index >> 6;
196 index &= 63;
197 switch (op) {
198 case 0:
199 r = new_palette[
index] & 0xFF0000;
200 g = new_palette[
index] & 0xFF00;
201 b = new_palette[
index] & 0xFF;
202 break;
203 case 1:
204 b = (index << 2) | (b & 3);
205 break;
206 case 2:
207 r = (index << 18) | (r & (3 << 16));
208 break;
209 case 3:
210 g = (index << 10) | (g & (3 << 8));
211 break;
212 }
213 AV_WL24(out + x * 3, r | g | b);
214 }
216 }
217 }
218
221 {
224 int ret, w, h, encoding, aligned_width, buf_size = pkt->
size;
226
227 if (buf_size < 32)
229 encoding = buf[1] & 7;
230 c->
format = buf[1] & 0xE0;
238
241 if (buf_size < c->palette_size + 32)
248 }
249
252
259 }
else if (encoding == 1 && (c->
bpp == 6 || c->
bpp == 8)) {
263 } else {
267 }
268
272
273 if (encoding) {
280 else
282 } else {
284 }
285 *got_frame = 1;
286
287 return buf_size;
288 }
289
291 {
293
295
296 return 0;
297 }
298
309 };