1 /*
2 * Delphine Software International CIN video decoder
3 * Copyright (c) 2006 Gregory Montoir (cyx@users.sourceforge.net)
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 * Delphine Software International CIN video decoder
25 */
26
32
38
46
48 {
50
51 for (
i = 0;
i < 3; ++
i)
53 }
54
56 {
58
59 for (
i = 0;
i < 3; ++
i) {
64 }
65 }
66
67 return 0;
68 }
69
71 {
73
76
80
84
85 return 0;
86 }
87
90 {
93 }
94
96 unsigned char *
dst,
int dst_size)
97 {
99 unsigned char huff_code_table[15];
100 unsigned char *dst_cur =
dst;
101 unsigned char *dst_end =
dst + dst_size;
102 const unsigned char *src_end =
src + src_size;
103
104 memcpy(huff_code_table,
src, 15);
106
107 while (
src < src_end) {
109 if ((huff_code >> 4) == 15) {
112 *dst_cur++ =
b | (huff_code >> 4);
113 } else
114 *dst_cur++ = huff_code_table[huff_code >> 4];
115 if (dst_cur >= dst_end)
116 break;
117
118 huff_code &= 15;
119 if (huff_code == 15) {
121 } else
122 *dst_cur++ = huff_code_table[huff_code];
123 if (dst_cur >= dst_end)
124 break;
125 }
126
127 return dst_cur -
dst;
128 }
129
131 unsigned char *
dst,
int dst_size)
132 {
133 uint16_t cmd;
135 unsigned char *dst_end =
dst + dst_size, *dst_start =
dst;
136 const unsigned char *src_end =
src + src_size;
137
138 while (
src < src_end &&
dst < dst_end) {
140 for (
i = 0;
i < 8 &&
src < src_end &&
dst < dst_end; ++
i) {
141 if (
code & (1 <<
i)) {
143 } else {
149 sz = (cmd & 0xF) + 2;
150 /* don't use memcpy/memmove here as the decoding routine
151 * (ab)uses buffer overlappings to repeat bytes in the
152 * destination */
154 while (sz--) {
157 }
158 }
159 }
160 }
161
162 if (dst_end -
dst > dst_size - dst_size/10)
164
165 return 0;
166 }
167
169 unsigned char *
dst,
int dst_size)
170 {
172 unsigned char *dst_end =
dst + dst_size;
173 const unsigned char *src_end =
src + src_size;
174
175 while (
src + 1 < src_end &&
dst < dst_end) {
180 } else {
185 }
188 }
190 }
191
192 if (dst_end -
dst > dst_size - dst_size/10)
194
195 return 0;
196 }
197
200 {
201 const uint8_t *buf = avpkt->
data;
202 int buf_size = avpkt->
size;
204 int i, y, palette_type, palette_colors_count,
205 bitmap_frame_type, bitmap_frame_size, res = 0;
206
207 palette_type = buf[0];
208 palette_colors_count =
AV_RL16(buf + 1);
209 bitmap_frame_type = buf[3];
210 buf += 4;
211
212 bitmap_frame_size = buf_size - 4;
213
214 /* handle palette */
215 if (bitmap_frame_size < palette_colors_count * (3 + (palette_type != 0)))
217 if (palette_type == 0) {
218 if (palette_colors_count > 256)
220 for (
i = 0;
i < palette_colors_count; ++
i) {
221 cin->
palette[
i] = 0xFF
U << 24 | bytestream_get_le24(&buf);
222 bitmap_frame_size -= 3;
223 }
224 } else {
225 for (
i = 0;
i < palette_colors_count; ++
i) {
227 buf += 4;
228 bitmap_frame_size -= 4;
229 }
230 }
231
232 /* note: the decoding routines below assumes that
233 * surface.width = surface.pitch */
234 switch (bitmap_frame_type) {
235 case 9:
238 if (res < 0)
239 return res;
240 break;
241 case 34:
244 if (res < 0)
245 return res;
248 break;
249 case 35:
254 if (res < 0)
255 return res;
256 break;
257 case 36:
263 if (res < 0)
264 return res;
267 break;
268 case 37:
271
274 break;
275 case 38:
279 if (res < 0)
280 return res;
281 break;
282 case 39:
286 if (res < 0)
287 return res;
290 break;
291 }
292
294 return res;
295
301
304
306 return res;
307
308 *got_frame = 1;
309
310 return buf_size;
311 }
312
314 {
316
318
320
321 return 0;
322 }
323
325 .
p.
name =
"dsicinvideo",
335 };