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 for (plane = 0; plane < c->
bpp; plane++) {
87 out[linesize * y + x] |=
get_bits1(&gb) << plane;
89 }
90 }
91 }
92
94 {
97
100 for (plane = 0; plane < c->
bpp; plane++) {
102 out[linesize * y + x] |=
get_bits1(&gb) << plane;
104 }
105 }
106 }
107
109 {
111
115 break;
118 break;
119 }
120 }
121
123 {
124 uint32_t *new_palette = (uint32_t *)frame->
data[1];
125
129 }
130
132 {
134 uint32_t new_palette[16],
r,
g,
b;
137
139 out = frame->
data[0];
140
143
144 for (y = 0; y < avctx->
height; y++) {
145 r = new_palette[0] & 0xFF0000;
146 g = new_palette[0] & 0xFF00;
147 b = new_palette[0] & 0xFF;
148 for (x = 0; x < avctx->
width; x++) {
149 index = *ptr++;
150 op = index >> 4;
151 index &= 15;
152 switch (op) {
153 case 0:
154 r = new_palette[
index] & 0xFF0000;
155 g = new_palette[
index] & 0xFF00;
156 b = new_palette[
index] & 0xFF;
157 break;
158 case 1:
159 b = index * 0x11;
160 break;
161 case 2:
162 r = index * 0x11 << 16;
163 break;
164 case 3:
165 g = index * 0x11 << 8;
166 break;
167 }
168 AV_WL24(out + x * 3, r | g | b);
169 }
171 }
172 }
173
175 {
177 uint32_t new_palette[64],
r,
g,
b;
180
182 out = frame->
data[0];
183
186
187 for (y = 0; y < avctx->
height; y++) {
188 r = new_palette[0] & 0xFF0000;
189 g = new_palette[0] & 0xFF00;
190 b = new_palette[0] & 0xFF;
191 for (x = 0; x < avctx->
width; x++) {
192 index = *ptr++;
193 op = index >> 6;
194 index &= 63;
195 switch (op) {
196 case 0:
197 r = new_palette[
index] & 0xFF0000;
198 g = new_palette[
index] & 0xFF00;
199 b = new_palette[
index] & 0xFF;
200 break;
201 case 1:
202 b = (index << 2) | (b & 3);
203 break;
204 case 2:
205 r = (index << 18) | (r & (3 << 16));
206 break;
207 case 3:
208 g = (index << 10) | (g & (3 << 8));
209 break;
210 }
211 AV_WL24(out + x * 3, r | g | b);
212 }
214 }
215 }
216
219 {
222 int ret, w, h, encoding, aligned_width, buf_size = pkt->
size;
224
225 if (buf_size < 32)
227 encoding = buf[1] & 7;
228 c->
format = buf[1] & 0xE0;
236
239 if (buf_size < c->palette_size + 32)
246 }
247
250
257 }
else if (encoding == 1 && (c->
bpp == 6 || c->
bpp == 8)) {
261 } else {
265 }
266
270
271 if (encoding) {
278 else
280 } else {
282 }
283 *got_frame = 1;
284
285 return buf_size;
286 }
287
289 {
291
293
294 return 0;
295 }
296
307 };