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
30
36
44
46 {
47 int i;
48
49 for (i = 0; i < 3; ++i)
51 }
52
54 {
55 int i;
56
57 for (i = 0; i < 3; ++i) {
63 }
64 }
65
66 return 0;
67 }
68
70 {
72
75
79
83
84 return 0;
85 }
86
89 {
90 while (size--)
91 *dst++ += *src++;
92 }
93
95 unsigned char *dst, int dst_size)
96 {
98 unsigned char huff_code_table[15];
99 unsigned char *dst_cur = dst;
100 unsigned char *dst_end = dst + dst_size;
101 const unsigned char *src_end = src + src_size;
102
103 memcpy(huff_code_table, src, 15);
104 src += 15;
105
106 while (src < src_end) {
107 huff_code = *src++;
108 if ((huff_code >> 4) == 15) {
109 b = huff_code << 4;
110 huff_code = *src++;
111 *dst_cur++ = b | (huff_code >> 4);
112 } else
113 *dst_cur++ = huff_code_table[huff_code >> 4];
114 if (dst_cur >= dst_end)
115 break;
116
117 huff_code &= 15;
118 if (huff_code == 15) {
119 *dst_cur++ = *src++;
120 } else
121 *dst_cur++ = huff_code_table[huff_code];
122 if (dst_cur >= dst_end)
123 break;
124 }
125
126 return dst_cur - dst;
127 }
128
130 unsigned char *dst, int dst_size)
131 {
132 uint16_t cmd;
134 unsigned char *dst_end = dst + dst_size, *dst_start = dst;
135 const unsigned char *src_end = src + src_size;
136
137 while (src < src_end && dst < dst_end) {
138 code = *src++;
139 for (i = 0; i < 8 && src < src_end && dst < dst_end; ++i) {
140 if (code & (1 << i)) {
141 *dst++ = *src++;
142 } else {
144 src += 2;
145 offset = cmd >> 4;
146 if ((int)(dst - dst_start) < offset + 1)
148 sz = (cmd & 0xF) + 2;
149 /* don't use memcpy/memmove here as the decoding routine
150 * (ab)uses buffer overlappings to repeat bytes in the
151 * destination */
152 sz =
FFMIN(sz, dst_end - dst);
153 while (sz--) {
154 *dst = *(dst - offset - 1);
155 ++dst;
156 }
157 }
158 }
159 }
160
161 return 0;
162 }
163
165 unsigned char *dst, int dst_size)
166 {
168 unsigned char *dst_end = dst + dst_size;
169 const unsigned char *src_end = src + src_size;
170
171 while (src + 1 < src_end && dst < dst_end) {
172 code = *src++;
173 if (code & 0x80) {
174 len = code - 0x7F;
175 memset(dst, *src++,
FFMIN(len, dst_end - dst));
176 } else {
177 len = code + 1;
178 if (len > src_end-src) {
181 }
182 memcpy(dst, src,
FFMIN3(len, dst_end - dst, src_end - src));
184 }
186 }
187 return 0;
188 }
189
191 void *
data,
int *got_frame,
193 {
195 int buf_size = avpkt->
size;
197 int i,
y, palette_type, palette_colors_count,
198 bitmap_frame_type, bitmap_frame_size, res = 0;
199
200 palette_type = buf[0];
201 palette_colors_count =
AV_RL16(buf + 1);
202 bitmap_frame_type = buf[3];
203 buf += 4;
204
205 bitmap_frame_size = buf_size - 4;
206
207 /* handle palette */
208 if (bitmap_frame_size < palette_colors_count * (3 + (palette_type != 0)))
210 if (palette_type == 0) {
211 if (palette_colors_count > 256)
213 for (i = 0; i < palette_colors_count; ++i) {
214 cin->
palette[i] = 0xFF
U << 24 | bytestream_get_le24(&buf);
215 bitmap_frame_size -= 3;
216 }
217 } else {
218 for (i = 0; i < palette_colors_count; ++i) {
220 buf += 4;
221 bitmap_frame_size -= 4;
222 }
223 }
224
225 /* note: the decoding routines below assumes that
226 * surface.width = surface.pitch */
227 switch (bitmap_frame_type) {
228 case 9:
231 break;
232 case 34:
237 break;
238 case 35:
243 break;
244 case 36:
252 break;
253 case 37:
256 break;
257 case 38:
261 if (res < 0)
262 return res;
263 break;
264 case 39:
268 if (res < 0)
269 return res;
272 break;
273 }
274
276 return res;
277
284
287
289 return res;
290
291 *got_frame = 1;
292
293 return buf_size;
294 }
295
297 {
299
301
303
304 return 0;
305 }
306
308 .
name =
"dsicinvideo",
317 };