1 /*
2 * Chronomaster DFA Video Decoder
3 * Copyright (c) 2011 Konstantin Shishkov
4 * based on work by Vladimir "VAG" Gneushev
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
27
30
35
37 {
39
41
44
46
50
51 return 0;
52 }
53
55 {
57
60 return 0;
61 }
62
64 {
67 int mask = 0x10000, bitbuf = 0;
70
71 segments = bytestream2_get_le32(gb);
72 offset = bytestream2_get_le32(gb);
73 if (segments == 0 && offset == frame_end - frame)
74 return 0; // skip frame
75 if (frame_end - frame <= offset)
78 while (segments--) {
81 if (mask == 0x10000) {
82 bitbuf = bytestream2_get_le16u(gb);
83 mask = 1;
84 }
85 if (frame_end - frame < 2)
87 if (bitbuf & mask) {
88 v = bytestream2_get_le16(gb);
89 offset = (v & 0x1FFF) << 1;
90 count = ((v >> 13) + 2) << 1;
91 if (frame - frame_start < offset || frame_end - frame < count)
95 } else {
96 *frame++ = bytestream2_get_byte(gb);
97 *frame++ = bytestream2_get_byte(gb);
98 }
99 mask <<= 1;
100 }
101
102 return 0;
103 }
104
106 {
109 int mask = 0x10000, bitbuf = 0;
111
112 segments = bytestream2_get_le16(gb);
113 while (segments--) {
116 if (mask == 0x10000) {
117 bitbuf = bytestream2_get_le16u(gb);
118 mask = 1;
119 }
120 if (frame_end - frame < 2)
122 if (bitbuf & mask) {
123 v = bytestream2_get_le16(gb);
124 offset = (v & 0x1FFF) << 1;
125 count = ((v >> 13) + 2) << 1;
126 if (frame - frame_start < offset || frame_end - frame < count)
130 } else if (bitbuf & (mask << 1)) {
131 frame += bytestream2_get_le16(gb);
132 } else {
133 *frame++ = bytestream2_get_byte(gb);
134 *frame++ = bytestream2_get_byte(gb);
135 }
136 mask <<= 2;
137 }
138
139 return 0;
140 }
141
143 {
146 int mask = 0x10000, bitbuf = 0;
148
149 segments = bytestream2_get_le16(gb);
150 while (segments--) {
153 if (mask == 0x10000) {
154 bitbuf = bytestream2_get_le16u(gb);
155 mask = 1;
156 }
157
158 if (bitbuf & mask) {
159 v = bytestream2_get_le16(gb);
160 offset = (v & 0x1FFF) << 2;
161 count = ((v >> 13) + 2) << 1;
162 if (frame - frame_start < offset || frame_end - frame < count*2 + width)
164 for (i = 0; i <
count; i++) {
165 frame[0] = frame[1] =
167
168 frame += 2;
169 }
170 } else if (bitbuf & (mask << 1)) {
171 v = bytestream2_get_le16(gb)*2;
172 if (frame - frame_end < v)
175 } else {
176 if (frame_end - frame < width + 3)
178 frame[0] = frame[1] =
179 frame[
width] = frame[width + 1] = bytestream2_get_byte(gb);
180 frame += 2;
181 frame[0] = frame[1] =
182 frame[
width] = frame[width + 1] = bytestream2_get_byte(gb);
183 frame += 2;
184 }
185 mask <<= 2;
186 }
187
188 return 0;
189 }
190
192 {
194 int count, lines, segments;
195
196 count = bytestream2_get_le16(gb);
197 if (count >= height)
199 frame += width *
count;
200 lines = bytestream2_get_le16(gb);
201 if (count + lines > height)
203
204 while (lines--) {
209 segments = bytestream2_get_byteu(gb);
210 while (segments--) {
211 if (frame - line_ptr <= bytestream2_peek_byte(gb))
213 line_ptr += bytestream2_get_byte(gb);
214 count = (int8_t)bytestream2_get_byte(gb);
215 if (count >= 0) {
216 if (frame - line_ptr < count)
220 } else {
222 if (frame - line_ptr < count)
224 memset(line_ptr, bytestream2_get_byte(gb), count);
225 }
227 }
228 }
229
230 return 0;
231 }
232
234 {
237 int count, i,
v, lines, segments;
239
240 lines = bytestream2_get_le16(gb);
241 if (lines > height)
243
244 while (lines--) {
247 segments = bytestream2_get_le16u(gb);
248 while ((segments & 0xC000) == 0xC000) {
249 unsigned skip_lines = -(int16_t)segments;
250 unsigned delta = -((int16_t)segments * width);
251 if (frame_end - frame <= delta || y + lines + skip_lines > height)
254 y += skip_lines;
255 segments = bytestream2_get_le16(gb);
256 }
257
258 if (frame_end <= frame)
260 if (segments & 0x8000) {
261 frame[width - 1] = segments & 0xFF;
262 segments = bytestream2_get_le16(gb);
263 }
265 if (frame_end - frame < width)
268 y++;
269 while (segments--) {
270 if (frame - line_ptr <= bytestream2_peek_byte(gb))
272 line_ptr += bytestream2_get_byte(gb);
273 count = (int8_t)bytestream2_get_byte(gb);
274 if (count >= 0) {
275 if (frame - line_ptr < count * 2)
279 line_ptr += count * 2;
280 } else {
282 if (frame - line_ptr < count * 2)
284 v = bytestream2_get_le16(gb);
285 for (i = 0; i <
count; i++)
286 bytestream_put_le16(&line_ptr, v);
287 }
288 }
289 }
290
291 return 0;
292 }
293
295 {
297 uint32_t segments = bytestream2_get_le32(gb);
299
300 while (segments--) {
303 copy = bytestream2_get_byteu(gb) * 2;
304 skip = bytestream2_get_byteu(gb) * 2;
305 if (frame_end - frame < copy + skip ||
308 frame += skip;
311 }
312
313 return 0;
314 }
315
317 {
318 memset(frame, 0, width * height);
319 return 0;
320 }
321
322
324
328 };
329
331 "COPY", "TSW1", "BDLT", "WDLT", "TDLT", "DSW1", "BLCK", "DDS1"
332 };
333
335 void *
data,
int *got_frame,
337 {
342 uint32_t chunk_type, chunk_size;
345 int i, pal_elems;
347
350
354 chunk_size = bytestream2_get_le32(&gb);
355 chunk_type = bytestream2_get_le32(&gb);
356 if (!chunk_type)
357 break;
358 if (chunk_type == 1) {
359 pal_elems =
FFMIN(chunk_size / 3, 256);
360 for (i = 0; i < pal_elems; i++) {
361 s->
pal[i] = bytestream2_get_be24(&gb) << 2;
362 s->
pal[i] |= 0xFF
U << 24 | (s->
pal[i] >> 6) & 0x30303;
363 }
365 } else if (chunk_type <= 9) {
370 }
371 } else {
373 chunk_type);
374 }
375 buf += chunk_size;
376 }
377
379 dst = frame->
data[0];
380 for (i = 0; i < avctx->
height; i++) {
381 if(version == 0x100) {
382 int j;
383 for(j = 0; j < avctx->
width; j++) {
384 dst[j] = buf[ (i&3)*(avctx->
width /4) + (j/4) +
386 }
387 } else {
388 memcpy(dst, buf, avctx->
width);
390 }
392 }
393 memcpy(frame->
data[1], s->
pal,
sizeof(s->
pal));
394
395 *got_frame = 1;
396
398 }
399
401 {
403
405
406 return 0;
407 }
408
419 };