1 /*
2 * Copyright (c) 2008 Jaikrishnan Menon <realityman@gmx.net>
3 * Copyright (c) 2010 Peter Ross <pross@xvid.org>
4 * Copyright (c) 2010 Sebastian Vater <cdgs.basty@googlemail.com>
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
23 /**
24 * @file
25 * IFF file demuxer
26 * by Jaikrishnan Menon
27 * for more information on the .iff file format, visit:
28 * http://wiki.multimedia.cx/index.php?title=IFF
29 */
30
38
39 #define ID_8SVX MKTAG('8','S','V','X')
40 #define ID_16SV MKTAG('1','6','S','V')
41 #define ID_MAUD MKTAG('M','A','U','D')
42 #define ID_MHDR MKTAG('M','H','D','R')
43 #define ID_MDAT MKTAG('M','D','A','T')
44 #define ID_VHDR MKTAG('V','H','D','R')
45 #define ID_ATAK MKTAG('A','T','A','K')
46 #define ID_RLSE MKTAG('R','L','S','E')
47 #define ID_CHAN MKTAG('C','H','A','N')
48 #define ID_PBM MKTAG('P','B','M',' ')
49 #define ID_ILBM MKTAG('I','L','B','M')
50 #define ID_BMHD MKTAG('B','M','H','D')
51 #define ID_DGBL MKTAG('D','G','B','L')
52 #define ID_CAMG MKTAG('C','A','M','G')
53 #define ID_CMAP MKTAG('C','M','A','P')
54 #define ID_ACBM MKTAG('A','C','B','M')
55 #define ID_DEEP MKTAG('D','E','E','P')
56 #define ID_RGB8 MKTAG('R','G','B','8')
57 #define ID_RGBN MKTAG('R','G','B','N')
58
59 #define ID_FORM MKTAG('F','O','R','M')
60 #define ID_ANNO MKTAG('A','N','N','O')
61 #define ID_AUTH MKTAG('A','U','T','H')
62 #define ID_CHRS MKTAG('C','H','R','S')
63 #define ID_COPYRIGHT MKTAG('(','c',')',' ')
64 #define ID_CSET MKTAG('C','S','E','T')
65 #define ID_FVER MKTAG('F','V','E','R')
66 #define ID_NAME MKTAG('N','A','M','E')
67 #define ID_TEXT MKTAG('T','E','X','T')
68 #define ID_ABIT MKTAG('A','B','I','T')
69 #define ID_BODY MKTAG('B','O','D','Y')
70 #define ID_DBOD MKTAG('D','B','O','D')
71 #define ID_DPEL MKTAG('D','P','E','L')
72 #define ID_DLOC MKTAG('D','L','O','C')
73 #define ID_TVDC MKTAG('T','V','D','C')
74
78
79 /**
80 * This number of bytes if added at the beginning of each AVPacket
81 * which contain additional information about video properties
82 * which has to be shared between demuxer and decoder.
83 * This number may change between frames, e.g. the demuxer might
84 * set it to smallest possible size of 2 to indicate that there's
85 * no extradata changing in this frame.
86 */
87 #define IFF_EXTRA_VIDEO_SIZE 41
88
94
103 unsigned bpp;
///< bits per plane to decode (differs from bits_per_coded_sample if HAM)
104 unsigned ham;
///< 0 if non-HAM or number of hold bits (6 for bpp > 6, 4 otherwise)
105 unsigned flags;
///< 1 for EHB, 0 is no extra half darkening
110
111 /* Metadata string read */
113 const char *
const tag,
114 const unsigned data_size)
115 {
117
118 if (!buf)
120
124 }
125 buf[data_size] = 0;
127 return 0;
128 }
129
131 {
133
145 return 0;
146 }
147
148 static const uint8_t deep_rgb24[] = {0, 0, 0, 3, 0, 1, 0, 8, 0, 2, 0, 8, 0, 3, 0, 8};
149 static const uint8_t deep_rgba[] = {0, 0, 0, 4, 0, 1, 0, 8, 0, 2, 0, 8, 0, 3, 0, 8};
150 static const uint8_t deep_bgra[] = {0, 0, 0, 4, 0, 3, 0, 8, 0, 2, 0, 8, 0, 1, 0, 8};
151 static const uint8_t deep_argb[] = {0, 0, 0, 4, 0,17, 0, 8, 0, 1, 0, 8, 0, 2, 0, 8};
152 static const uint8_t deep_abgr[] = {0, 0, 0, 4, 0,17, 0, 8, 0, 3, 0, 8, 0, 2, 0, 8};
153
155 {
160 uint32_t chunk_id, data_size;
161 uint32_t screenmode = 0, num, den;
162 unsigned transparency = 0;
163 unsigned masking = 0; // no mask
165 int fmt_size;
166
168 if (!st)
170
174 // codec_tag used by ByteRun1 decoder to distinguish progressive (PBM) and interlaced (ILBM) content
180
182 uint64_t orig_pos;
184 const char *metadata_tag = NULL;
188
189 switch(chunk_id) {
192
193 if (data_size < 14)
197 if (data_size >= 16) {
200 }
201 break;
202
205
206 if (data_size < 32)
213 if (!den)
223 break;
224
232 break;
233
235 if (data_size < 4)
240 } else {
243 }
244 break;
245
247 if (data_size < 4)
250 break;
251
253 if (data_size < 3 || data_size > 768 || data_size % 3) {
255 data_size);
257 }
264 break;
265
268 if (data_size <= 8)
274 if (data_size >= 10)
276 if (data_size >= 11)
278 if (data_size >= 14) {
281 }
282 if (data_size >= 16) {
285 }
286 break;
287
289 if (data_size < 4 || (data_size & 3))
291 if ((fmt_size =
avio_read(pb, fmt,
sizeof(fmt))) < 0)
292 return fmt_size;
303 else {
306 }
307 break;
308
311 if (data_size < 8)
319 break;
320
322 if (data_size < 4)
326 break;
327
329 if (data_size <
sizeof(iff->
tvdc))
332 if (res < 0)
334 break;
335
337 case ID_TEXT: metadata_tag =
"comment";
break;
338 case ID_AUTH: metadata_tag =
"artist";
break;
340 case ID_NAME: metadata_tag =
"title";
break;
341 }
342
343 if (metadata_tag) {
344 if ((res =
get_metadata(s, metadata_tag, data_size)) < 0) {
347 }
348 }
350 }
351
353
357
369 } else {
372 }
373
376
379 } else {
383 break;
386 break;
389 break;
390 default:
393 return -1;
394 }
395 }
396
400 break;
401
404 if ((screenmode & 0x800
/* Hold And Modify */) && iff->
bpp <= 8) {
405 iff->
ham = iff->
bpp > 6 ? 6 : 4;
407 }
408 iff->
flags = (screenmode & 0x80
/* Extra HalfBrite */) && iff->
bpp <= 8;
411
417 }
422 bytestream_put_byte(&buf, iff->
bpp);
423 bytestream_put_byte(&buf, iff->
ham);
424 bytestream_put_byte(&buf, iff->
flags);
426 bytestream_put_byte(&buf, iff->
masking);
429 break;
430 default:
431 return -1;
432 }
433
434 return 0;
435 }
436
439 {
445
448
452 } else {
454 }
457
460 }
461
463 bytestream_put_be16(&buf, 2);
465 } else {
467 }
468
471 if (ret < 0)
475 }
476
485 };