Mercurial > libavcodec.hg
annotate interplayvideo.c @ 1474:94c7f7c23dd9 libavcodec
video looks beautiful now, many thanks to Alexander Belyakov
<abel at krasu.ru> for squishing bunches of bugs
author | tmmm |
---|---|
date | Thu, 18 Sep 2003 03:30:08 +0000 |
parents | 873100cd2108 |
children | 26eb7678cb46 |
rev | line source |
---|---|
1439
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
1 /* |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
2 * Interplay MVE Video Decoder |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
3 * Copyright (C) 2003 the ffmpeg project |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
4 * |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
5 * This library is free software; you can redistribute it and/or |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
6 * modify it under the terms of the GNU Lesser General Public |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
7 * License as published by the Free Software Foundation; either |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
8 * version 2 of the License, or (at your option) any later version. |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
9 * |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
10 * This library is distributed in the hope that it will be useful, |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
13 * Lesser General Public License for more details. |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
14 * |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
15 * You should have received a copy of the GNU Lesser General Public |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
16 * License along with this library; if not, write to the Free Software |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
18 * |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
19 */ |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
20 |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
21 /** |
1468 | 22 * @file interplayvideo.c |
23 * Interplay MVE Video Decoder by Mike Melanson (melanson@pcisys.net) | |
1439
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
24 * For more information about the Interplay MVE format, visit: |
1468 | 25 * http://www.pcisys.net/~melanson/codecs/interplay-mve.txt |
26 * This code is written in such a way that the identifiers match up | |
27 * with the encoding descriptions in the document. | |
28 * | |
29 * This decoder presently only supports a PAL8 output colorspace. | |
30 * | |
31 * An Interplay video frame consists of 2 parts: The decoding map and | |
32 * the video data. A demuxer must load these 2 parts together in a single | |
33 * buffer before sending it through the stream to this decoder. | |
1439
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
34 */ |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
35 |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
36 #include <stdio.h> |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
37 #include <stdlib.h> |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
38 #include <string.h> |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
39 #include <unistd.h> |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
40 |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
41 #include "common.h" |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
42 #include "avcodec.h" |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
43 #include "dsputil.h" |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
44 |
1468 | 45 #define PALETTE_COUNT 256 |
46 | |
47 /* debugging support */ | |
48 #define DEBUG_INTERPLAY 0 | |
49 #if DEBUG_INTERPLAY | |
50 #define debug_interplay printf | |
51 #else | |
52 static inline void debug_interplay(const char *format, ...) { } | |
53 #endif | |
54 | |
1439
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
55 typedef struct IpvideoContext { |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
56 |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
57 AVCodecContext *avctx; |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
58 DSPContext dsp; |
1474
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
59 AVFrame second_last_frame; |
1439
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
60 AVFrame last_frame; |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
61 AVFrame current_frame; |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
62 unsigned char *decoding_map; |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
63 int decoding_map_size; |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
64 |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
65 unsigned char *buf; |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
66 int size; |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
67 |
1468 | 68 unsigned char palette[PALETTE_COUNT * 4]; |
69 | |
1439
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
70 } IpvideoContext; |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
71 |
1468 | 72 #define CHECK_STREAM_PTR(n) \ |
73 if ((sg_stream_ptr + n) > sg_stream_end) { \ | |
74 printf ("Interplay video warning: stream_ptr out of bounds (%p >= %p)\n", \ | |
75 sg_stream_ptr + n, sg_stream_end); \ | |
76 return -1; \ | |
77 } | |
78 | |
79 static void ipvideo_new_palette(IpvideoContext *s, unsigned char *palette) { | |
80 | |
81 int i; | |
82 unsigned char r, g, b; | |
83 unsigned int *palette32; | |
84 | |
85 switch (s->avctx->pix_fmt) { | |
86 | |
87 case PIX_FMT_PAL8: | |
88 palette32 = (unsigned int *)s->palette; | |
89 for (i = 0; i < PALETTE_COUNT; i++) { | |
90 r = *palette++; | |
91 g = *palette++; | |
92 b = *palette++; | |
93 palette32[i] = (r << 16) | (g << 8) | (b); | |
94 } | |
95 break; | |
96 | |
97 default: | |
98 printf ("Interplay video: Unhandled video format\n"); | |
99 break; | |
100 } | |
101 } | |
102 | |
103 static unsigned char *sg_stream_ptr; | |
104 static unsigned char *sg_stream_end; | |
105 static unsigned char *sg_current_plane; | |
106 static unsigned char *sg_output_plane; | |
107 static unsigned char *sg_last_plane; | |
1474
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
108 static unsigned char *sg_second_last_plane; |
1468 | 109 static int sg_line_inc; |
110 static int sg_stride; | |
111 static int sg_upper_motion_limit_offset; | |
112 static DSPContext sg_dsp; | |
113 | |
1474
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
114 static int ipvideo_decode_block_opcode_0x0(void) |
1468 | 115 { |
116 int x, y; | |
117 unsigned char *src_block; | |
118 | |
119 /* skip block, which actually means to copy from previous frame */ | |
120 src_block = sg_last_plane + (sg_output_plane - sg_current_plane); | |
121 for (y = 0; y < 8; y++) { | |
122 for (x = 0; x < 8; x++) { | |
123 *sg_output_plane++ = *src_block++; | |
124 } | |
125 sg_output_plane += sg_line_inc; | |
126 src_block += sg_line_inc; | |
127 } | |
128 | |
129 /* report success */ | |
130 return 0; | |
131 } | |
132 | |
1474
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
133 static int ipvideo_decode_block_opcode_0x1(void) |
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
134 { |
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
135 int x, y; |
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
136 unsigned char *src_block; |
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
137 |
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
138 /* copy block from two frames behind */ |
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
139 src_block = sg_second_last_plane + (sg_output_plane - sg_current_plane); |
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
140 for (y = 0; y < 8; y++) { |
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
141 for (x = 0; x < 8; x++) { |
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
142 *sg_output_plane++ = *src_block++; |
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
143 } |
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
144 sg_output_plane += sg_line_inc; |
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
145 src_block += sg_line_inc; |
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
146 } |
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
147 |
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
148 /* report success */ |
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
149 return 0; |
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
150 } |
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
151 |
1468 | 152 #define COPY_FROM_CURRENT() \ |
153 motion_offset = current_offset; \ | |
154 motion_offset += y * sg_stride; \ | |
155 motion_offset += x; \ | |
156 if (motion_offset < 0) { \ | |
157 printf (" Interplay video: motion offset < 0 (%d)\n", motion_offset); \ | |
158 return -1; \ | |
159 } else if (motion_offset > sg_upper_motion_limit_offset) { \ | |
160 printf (" Interplay video: motion offset above limit (%d >= %d)\n", \ | |
161 motion_offset, sg_upper_motion_limit_offset); \ | |
162 return -1; \ | |
163 } \ | |
164 sg_dsp.put_pixels_tab[0][0](sg_output_plane, \ | |
165 sg_current_plane + motion_offset, sg_stride, 8); | |
166 | |
167 #define COPY_FROM_PREVIOUS() \ | |
168 motion_offset = current_offset; \ | |
169 motion_offset += y * sg_stride; \ | |
170 motion_offset += x; \ | |
171 if (motion_offset < 0) { \ | |
172 printf (" Interplay video: motion offset < 0 (%d)\n", motion_offset); \ | |
173 return -1; \ | |
174 } else if (motion_offset > sg_upper_motion_limit_offset) { \ | |
175 printf (" Interplay video: motion offset above limit (%d >= %d)\n", \ | |
176 motion_offset, sg_upper_motion_limit_offset); \ | |
177 return -1; \ | |
178 } \ | |
179 sg_dsp.put_pixels_tab[0][0](sg_output_plane, \ | |
180 sg_last_plane + motion_offset, sg_stride, 8); | |
181 | |
1474
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
182 #define COPY_FROM_SECOND_LAST() \ |
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
183 motion_offset = current_offset; \ |
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
184 motion_offset += y * sg_stride; \ |
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
185 motion_offset += x; \ |
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
186 if (motion_offset < 0) { \ |
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
187 printf (" Interplay video: motion offset < 0 (%d)\n", motion_offset); \ |
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
188 return -1; \ |
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
189 } else if (motion_offset > sg_upper_motion_limit_offset) { \ |
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
190 printf (" Interplay video: motion offset above limit (%d >= %d)\n", \ |
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
191 motion_offset, sg_upper_motion_limit_offset); \ |
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
192 return -1; \ |
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
193 } \ |
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
194 sg_dsp.put_pixels_tab[0][0](sg_output_plane, \ |
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
195 sg_second_last_plane + motion_offset, sg_stride, 8); |
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
196 |
1468 | 197 static int ipvideo_decode_block_opcode_0x2(void) |
198 { | |
199 unsigned char B; | |
200 int x, y; | |
201 int motion_offset; | |
202 int current_offset = sg_output_plane - sg_current_plane; | |
203 | |
204 /* need 1 more byte for motion */ | |
205 CHECK_STREAM_PTR(1); | |
206 B = *sg_stream_ptr++; | |
207 | |
208 if (B < 56) { | |
209 x = 8 + (B % 7); | |
210 y = B / 7; | |
211 } else { | |
212 x = -14 + ((B - 56) % 29); | |
213 y = 8 + ((B - 56) / 29); | |
214 } | |
215 | |
216 debug_interplay (" motion byte = %d, (x, y) = (%d, %d)\n", B, x, y); | |
1474
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
217 COPY_FROM_SECOND_LAST(); |
1468 | 218 |
219 /* report success */ | |
220 return 0; | |
221 } | |
222 | |
223 static int ipvideo_decode_block_opcode_0x3(void) | |
224 { | |
225 unsigned char B; | |
226 int x, y; | |
227 int motion_offset; | |
228 int current_offset = sg_output_plane - sg_current_plane; | |
229 | |
230 /* copy 8x8 block from current frame from an up/left block */ | |
231 | |
232 /* need 1 more byte for motion */ | |
233 CHECK_STREAM_PTR(1); | |
234 B = *sg_stream_ptr++; | |
235 | |
236 if (B < 56) { | |
237 x = -(8 + (B % 7)); | |
238 y = -(B / 7); | |
239 } else { | |
240 x = -(-14 + ((B - 56) % 29)); | |
241 y = -( 8 + ((B - 56) / 29)); | |
242 } | |
243 | |
244 debug_interplay (" motion byte = %d, (x, y) = (%d, %d)\n", B, x, y); | |
245 COPY_FROM_CURRENT(); | |
246 | |
247 /* report success */ | |
248 return 0; | |
249 } | |
250 | |
251 static int ipvideo_decode_block_opcode_0x4(void) | |
252 { | |
253 int x, y; | |
254 unsigned char B, BL, BH; | |
255 int motion_offset; | |
256 int current_offset = sg_output_plane - sg_current_plane; | |
257 | |
258 /* copy a block from the previous frame; need 1 more byte */ | |
259 CHECK_STREAM_PTR(1); | |
260 | |
261 B = *sg_stream_ptr++; | |
262 BL = B & 0x0F; | |
263 BH = (B >> 4) & 0x0F; | |
264 x = -8 + BL; | |
265 y = -8 + BH; | |
266 | |
267 debug_interplay (" motion byte = %d, (x, y) = (%d, %d)\n", B, x, y); | |
268 COPY_FROM_PREVIOUS(); | |
269 | |
270 /* report success */ | |
271 return 0; | |
272 } | |
273 | |
274 static int ipvideo_decode_block_opcode_0x5(void) | |
275 { | |
276 signed char x, y; | |
277 int motion_offset; | |
278 int current_offset = sg_output_plane - sg_current_plane; | |
279 | |
280 /* copy a block from the previous frame using an expanded range; | |
281 * need 2 more bytes */ | |
282 CHECK_STREAM_PTR(2); | |
283 | |
284 x = *sg_stream_ptr++; | |
285 y = *sg_stream_ptr++; | |
286 | |
287 debug_interplay (" motion bytes = %d, %d\n", x, y); | |
288 COPY_FROM_PREVIOUS(); | |
289 | |
290 /* report success */ | |
291 return 0; | |
292 } | |
293 | |
294 static int ipvideo_decode_block_opcode_0x6(void) | |
295 { | |
296 /* mystery opcode? skip multiple blocks? */ | |
297 printf (" Interplay video: Help! Mystery opcode 0x6 seen\n"); | |
298 | |
299 /* report success */ | |
300 return 0; | |
301 } | |
302 | |
303 static int ipvideo_decode_block_opcode_0x7(void) | |
304 { | |
305 int x, y; | |
306 unsigned char P0, P1; | |
307 unsigned char B[8]; | |
308 unsigned int flags; | |
309 int bitmask; | |
310 | |
311 /* 2-color encoding */ | |
312 CHECK_STREAM_PTR(2); | |
313 | |
314 P0 = *sg_stream_ptr++; | |
315 P1 = *sg_stream_ptr++; | |
316 | |
317 if (P0 <= P1) { | |
318 | |
319 /* need 8 more bytes from the stream */ | |
320 CHECK_STREAM_PTR(8); | |
321 for (y = 0; y < 8; y++) | |
322 B[y] = *sg_stream_ptr++; | |
323 | |
324 for (y = 0; y < 8; y++) { | |
325 flags = B[y]; | |
1473
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
326 for (x = 0x01; x <= 0x80; x <<= 1) { |
1468 | 327 if (flags & x) |
328 *sg_output_plane++ = P1; | |
329 else | |
330 *sg_output_plane++ = P0; | |
331 } | |
332 sg_output_plane += sg_line_inc; | |
333 } | |
334 | |
335 } else { | |
336 | |
337 /* need 2 more bytes from the stream */ | |
338 CHECK_STREAM_PTR(2); | |
339 B[0] = *sg_stream_ptr++; | |
340 B[1] = *sg_stream_ptr++; | |
341 | |
1473
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
342 flags = (B[1] << 8) | B[0]; |
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
343 bitmask = 0x0001; |
1468 | 344 for (y = 0; y < 8; y += 2) { |
1473
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
345 for (x = 0; x < 8; x += 2, bitmask <<= 1) { |
1468 | 346 if (flags & bitmask) { |
1474
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
347 *(sg_output_plane + x) = P1; |
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
348 *(sg_output_plane + x + 1) = P1; |
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
349 *(sg_output_plane + sg_stride + x) = P1; |
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
350 *(sg_output_plane + sg_stride + x + 1) = P1; |
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
351 } else { |
1468 | 352 *(sg_output_plane + x) = P0; |
353 *(sg_output_plane + x + 1) = P0; | |
354 *(sg_output_plane + sg_stride + x) = P0; | |
355 *(sg_output_plane + sg_stride + x + 1) = P0; | |
356 } | |
357 } | |
358 sg_output_plane += sg_stride * 2; | |
359 } | |
360 } | |
361 | |
362 /* report success */ | |
363 return 0; | |
364 } | |
365 | |
366 static int ipvideo_decode_block_opcode_0x8(void) | |
367 { | |
368 int x, y; | |
369 unsigned char P[8]; | |
370 unsigned char B[8]; | |
371 unsigned int flags = 0; | |
372 unsigned int bitmask = 0; | |
373 unsigned char P0 = 0, P1 = 0; | |
374 int lower_half = 0; | |
375 | |
376 /* 2-color encoding for each 4x4 quadrant, or 2-color encoding on | |
377 * either top and bottom or left and right halves */ | |
378 CHECK_STREAM_PTR(2); | |
379 | |
380 P[0] = *sg_stream_ptr++; | |
381 P[1] = *sg_stream_ptr++; | |
382 | |
383 if (P[0] <= P[1]) { | |
384 | |
385 /* need 12 more bytes */ | |
386 CHECK_STREAM_PTR(12); | |
387 B[0] = *sg_stream_ptr++; B[1] = *sg_stream_ptr++; | |
388 P[2] = *sg_stream_ptr++; P[3] = *sg_stream_ptr++; | |
389 B[2] = *sg_stream_ptr++; B[3] = *sg_stream_ptr++; | |
390 P[4] = *sg_stream_ptr++; P[5] = *sg_stream_ptr++; | |
391 B[4] = *sg_stream_ptr++; B[5] = *sg_stream_ptr++; | |
392 P[6] = *sg_stream_ptr++; P[7] = *sg_stream_ptr++; | |
393 B[6] = *sg_stream_ptr++; B[7] = *sg_stream_ptr++; | |
394 | |
395 for (y = 0; y < 8; y++) { | |
396 | |
397 /* time to reload flags? */ | |
398 if (y == 0) { | |
399 flags = | |
1473
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
400 ((B[0] & 0xF0) << 4) | ((B[4] & 0xF0) << 8) | |
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
401 ((B[0] & 0x0F) ) | ((B[4] & 0x0F) << 4) | |
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
402 ((B[1] & 0xF0) << 20) | ((B[5] & 0xF0) << 24) | |
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
403 ((B[1] & 0x0F) << 16) | ((B[5] & 0x0F) << 20); |
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
404 bitmask = 0x00000001; |
1468 | 405 lower_half = 0; /* still on top half */ |
406 } else if (y == 4) { | |
407 flags = | |
1473
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
408 ((B[2] & 0xF0) << 4) | ((B[6] & 0xF0) << 8) | |
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
409 ((B[2] & 0x0F) ) | ((B[6] & 0x0F) << 4) | |
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
410 ((B[3] & 0xF0) << 20) | ((B[7] & 0xF0) << 24) | |
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
411 ((B[3] & 0x0F) << 16) | ((B[7] & 0x0F) << 20); |
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
412 bitmask = 0x00000001; |
1474
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
413 lower_half = 2; |
1468 | 414 } |
415 | |
1473
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
416 for (x = 0; x < 8; x++, bitmask <<= 1) { |
1468 | 417 /* get the pixel values ready for this quadrant */ |
418 if (x == 0) { | |
419 P0 = P[lower_half + 0]; | |
420 P1 = P[lower_half + 1]; | |
421 } else if (x == 4) { | |
1474
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
422 P0 = P[lower_half + 4]; |
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
423 P1 = P[lower_half + 5]; |
1468 | 424 } |
425 | |
426 if (flags & bitmask) | |
427 *sg_output_plane++ = P1; | |
428 else | |
429 *sg_output_plane++ = P0; | |
430 } | |
431 sg_output_plane += sg_line_inc; | |
432 } | |
433 | |
434 } else { | |
435 | |
436 /* need 10 more bytes */ | |
437 CHECK_STREAM_PTR(10); | |
438 B[0] = *sg_stream_ptr++; B[1] = *sg_stream_ptr++; | |
439 B[2] = *sg_stream_ptr++; B[3] = *sg_stream_ptr++; | |
440 P[2] = *sg_stream_ptr++; P[3] = *sg_stream_ptr++; | |
441 B[4] = *sg_stream_ptr++; B[5] = *sg_stream_ptr++; | |
442 B[6] = *sg_stream_ptr++; B[7] = *sg_stream_ptr++; | |
443 | |
444 if (P[2] <= P[3]) { | |
445 | |
446 /* vertical split; left & right halves are 2-color encoded */ | |
447 | |
448 for (y = 0; y < 8; y++) { | |
449 | |
450 /* time to reload flags? */ | |
451 if (y == 0) { | |
452 flags = | |
1473
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
453 ((B[0] & 0xF0) << 4) | ((B[4] & 0xF0) << 8) | |
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
454 ((B[0] & 0x0F) ) | ((B[4] & 0x0F) << 4) | |
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
455 ((B[1] & 0xF0) << 20) | ((B[5] & 0xF0) << 24) | |
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
456 ((B[1] & 0x0F) << 16) | ((B[5] & 0x0F) << 20); |
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
457 bitmask = 0x00000001; |
1468 | 458 } else if (y == 4) { |
459 flags = | |
1473
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
460 ((B[2] & 0xF0) << 4) | ((B[6] & 0xF0) << 8) | |
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
461 ((B[2] & 0x0F) ) | ((B[6] & 0x0F) << 4) | |
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
462 ((B[3] & 0xF0) << 20) | ((B[7] & 0xF0) << 24) | |
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
463 ((B[3] & 0x0F) << 16) | ((B[7] & 0x0F) << 20); |
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
464 bitmask = 0x00000001; |
1468 | 465 } |
466 | |
1473
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
467 for (x = 0; x < 8; x++, bitmask <<= 1) { |
1468 | 468 /* get the pixel values ready for this half */ |
469 if (x == 0) { | |
470 P0 = P[0]; | |
471 P1 = P[1]; | |
472 } else if (x == 4) { | |
473 P0 = P[2]; | |
474 P1 = P[3]; | |
475 } | |
476 | |
477 if (flags & bitmask) | |
1474
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
478 *sg_output_plane++ = P1; |
1468 | 479 else |
1474
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
480 *sg_output_plane++ = P0; |
1468 | 481 } |
482 sg_output_plane += sg_line_inc; | |
483 } | |
484 | |
485 } else { | |
486 | |
487 /* horizontal split; top & bottom halves are 2-color encoded */ | |
488 | |
489 for (y = 0; y < 8; y++) { | |
490 | |
491 flags = B[y]; | |
492 if (y == 0) { | |
493 P0 = P[0]; | |
494 P1 = P[1]; | |
495 } else if (y == 4) { | |
496 P0 = P[2]; | |
497 P1 = P[3]; | |
498 } | |
499 | |
1473
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
500 for (bitmask = 0x01; bitmask <= 0x80; bitmask <<= 1) { |
1468 | 501 |
502 if (flags & bitmask) | |
1474
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
503 *sg_output_plane++ = P1; |
1468 | 504 else |
1474
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
505 *sg_output_plane++ = P0; |
1468 | 506 } |
507 sg_output_plane += sg_line_inc; | |
508 } | |
509 } | |
510 } | |
511 | |
512 /* report success */ | |
513 return 0; | |
514 } | |
515 | |
516 static int ipvideo_decode_block_opcode_0x9(void) | |
517 { | |
518 int x, y; | |
519 unsigned char P[4]; | |
1473
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
520 unsigned char B[4]; |
1468 | 521 unsigned int flags = 0; |
522 int shifter = 0; | |
523 unsigned char pix; | |
524 | |
525 /* 4-color encoding */ | |
526 CHECK_STREAM_PTR(4); | |
527 | |
528 for (y = 0; y < 4; y++) | |
529 P[y] = *sg_stream_ptr++; | |
530 | |
531 if ((P[0] <= P[1]) && (P[2] <= P[3])) { | |
532 | |
533 /* 1 of 4 colors for each pixel, need 16 more bytes */ | |
534 CHECK_STREAM_PTR(16); | |
535 | |
536 for (y = 0; y < 8; y++) { | |
537 /* get the next set of 8 2-bit flags */ | |
1473
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
538 flags = (sg_stream_ptr[1] << 8) | sg_stream_ptr[0]; |
1468 | 539 sg_stream_ptr += 2; |
1473
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
540 for (x = 0, shifter = 0; x < 8; x++, shifter += 2) { |
1468 | 541 *sg_output_plane++ = P[(flags >> shifter) & 0x03]; |
542 } | |
543 sg_output_plane += sg_line_inc; | |
544 } | |
545 | |
546 } else if ((P[0] <= P[1]) && (P[2] > P[3])) { | |
547 | |
548 /* 1 of 4 colors for each 2x2 block, need 4 more bytes */ | |
549 CHECK_STREAM_PTR(4); | |
550 | |
1473
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
551 B[0] = *sg_stream_ptr++; |
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
552 B[1] = *sg_stream_ptr++; |
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
553 B[2] = *sg_stream_ptr++; |
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
554 B[3] = *sg_stream_ptr++; |
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
555 flags = (B[3] << 24) | (B[2] << 16) | (B[1] << 8) | B[0]; |
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
556 shifter = 0; |
1468 | 557 |
558 for (y = 0; y < 8; y += 2) { | |
1473
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
559 for (x = 0; x < 8; x += 2, shifter += 2) { |
1468 | 560 pix = P[(flags >> shifter) & 0x03]; |
561 *(sg_output_plane + x) = pix; | |
562 *(sg_output_plane + x + 1) = pix; | |
563 *(sg_output_plane + sg_stride + x) = pix; | |
564 *(sg_output_plane + sg_stride + x + 1) = pix; | |
565 } | |
566 sg_output_plane += sg_stride * 2; | |
567 } | |
568 | |
569 } else if ((P[0] > P[1]) && (P[2] <= P[3])) { | |
570 | |
571 /* 1 of 4 colors for each 2x1 block, need 8 more bytes */ | |
572 CHECK_STREAM_PTR(8); | |
573 | |
574 for (y = 0; y < 8; y++) { | |
575 /* time to reload flags? */ | |
576 if ((y == 0) || (y == 4)) { | |
1473
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
577 B[0] = *sg_stream_ptr++; |
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
578 B[1] = *sg_stream_ptr++; |
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
579 B[2] = *sg_stream_ptr++; |
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
580 B[3] = *sg_stream_ptr++; |
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
581 flags = (B[3] << 24) | (B[2] << 16) | (B[1] << 8) | B[0]; |
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
582 shifter = 0; |
1468 | 583 } |
1473
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
584 for (x = 0; x < 8; x += 2, shifter += 2) { |
1468 | 585 pix = P[(flags >> shifter) & 0x03]; |
586 *(sg_output_plane + x) = pix; | |
587 *(sg_output_plane + x + 1) = pix; | |
588 } | |
589 sg_output_plane += sg_stride; | |
590 } | |
591 | |
592 } else { | |
593 | |
594 /* 1 of 4 colors for each 1x2 block, need 8 more bytes */ | |
595 CHECK_STREAM_PTR(8); | |
596 | |
597 for (y = 0; y < 8; y += 2) { | |
598 /* time to reload flags? */ | |
599 if ((y == 0) || (y == 4)) { | |
1473
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
600 B[0] = *sg_stream_ptr++; |
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
601 B[1] = *sg_stream_ptr++; |
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
602 B[2] = *sg_stream_ptr++; |
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
603 B[3] = *sg_stream_ptr++; |
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
604 flags = (B[3] << 24) | (B[2] << 16) | (B[1] << 8) | B[0]; |
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
605 shifter = 0; |
1468 | 606 } |
1473
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
607 for (x = 0; x < 8; x++, shifter += 2) { |
1468 | 608 pix = P[(flags >> shifter) & 0x03]; |
609 *(sg_output_plane + x) = pix; | |
610 *(sg_output_plane + sg_stride + x) = pix; | |
611 } | |
612 sg_output_plane += sg_stride * 2; | |
613 } | |
614 } | |
615 | |
616 /* report success */ | |
617 return 0; | |
618 } | |
619 | |
620 static int ipvideo_decode_block_opcode_0xA(void) | |
621 { | |
622 int x, y; | |
623 unsigned char P[16]; | |
624 unsigned char B[16]; | |
625 int flags = 0; | |
626 int shifter = 0; | |
627 int index; | |
628 int split; | |
629 int lower_half; | |
630 | |
631 /* 4-color encoding for each 4x4 quadrant, or 4-color encoding on | |
632 * either top and bottom or left and right halves */ | |
633 CHECK_STREAM_PTR(4); | |
634 | |
635 for (y = 0; y < 4; y++) | |
636 P[y] = *sg_stream_ptr++; | |
637 | |
638 if (P[0] <= P[1]) { | |
639 | |
640 /* 4-color encoding for each quadrant; need 28 more bytes */ | |
641 CHECK_STREAM_PTR(28); | |
642 | |
643 for (y = 0; y < 4; y++) | |
644 B[y] = *sg_stream_ptr++; | |
645 for (y = 4; y < 16; y += 4) { | |
646 for (x = y; x < y + 4; x++) | |
647 P[x] = *sg_stream_ptr++; | |
648 for (x = y; x < y + 4; x++) | |
649 B[x] = *sg_stream_ptr++; | |
650 } | |
651 | |
652 for (y = 0; y < 8; y++) { | |
653 | |
654 lower_half = (y >= 4) ? 4 : 0; | |
1473
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
655 flags = (B[y + 8] << 8) | B[y]; |
1468 | 656 |
1473
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
657 for (x = 0, shifter = 0; x < 8; x++, shifter += 2) { |
1468 | 658 split = (x >= 4) ? 8 : 0; |
659 index = split + lower_half + ((flags >> shifter) & 0x03); | |
660 *sg_output_plane++ = P[index]; | |
661 } | |
662 | |
663 sg_output_plane += sg_line_inc; | |
664 } | |
665 | |
666 } else { | |
667 | |
668 /* 4-color encoding for either left and right or top and bottom | |
669 * halves; need 20 more bytes */ | |
670 CHECK_STREAM_PTR(20); | |
671 | |
672 for (y = 0; y < 8; y++) | |
673 B[y] = *sg_stream_ptr++; | |
674 for (y = 4; y < 8; y++) | |
675 P[y] = *sg_stream_ptr++; | |
676 for (y = 8; y < 16; y++) | |
677 B[y] = *sg_stream_ptr++; | |
678 | |
679 if (P[4] <= P[5]) { | |
680 | |
681 /* block is divided into left and right halves */ | |
682 for (y = 0; y < 8; y++) { | |
683 | |
1473
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
684 flags = (B[y + 8] << 8) | B[y]; |
1468 | 685 split = 0; |
686 | |
1473
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
687 for (x = 0, shifter = 0; x < 8; x++, shifter += 2) { |
1468 | 688 if (x == 4) |
689 split = 4; | |
690 *sg_output_plane++ = P[split + ((flags >> shifter) & 0x03)]; | |
691 } | |
692 | |
693 sg_output_plane += sg_line_inc; | |
694 } | |
695 | |
696 } else { | |
697 | |
698 /* block is divided into top and bottom halves */ | |
699 split = 0; | |
700 for (y = 0; y < 8; y++) { | |
701 | |
1473
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
702 flags = (B[y * 2 + 1] << 8) | B[y * 2]; |
1468 | 703 if (y == 4) |
704 split = 4; | |
705 | |
1473
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
706 for (x = 0, shifter = 0; x < 8; x++, shifter += 2) |
1468 | 707 *sg_output_plane++ = P[split + ((flags >> shifter) & 0x03)]; |
708 | |
709 sg_output_plane += sg_line_inc; | |
710 } | |
711 } | |
712 } | |
713 | |
714 /* report success */ | |
715 return 0; | |
716 } | |
717 | |
718 static int ipvideo_decode_block_opcode_0xB(void) | |
719 { | |
720 int x, y; | |
721 | |
722 /* 64-color encoding (each pixel in block is a different color) */ | |
723 CHECK_STREAM_PTR(64); | |
724 | |
725 for (y = 0; y < 8; y++) { | |
726 for (x = 0; x < 8; x++) { | |
727 *sg_output_plane++ = *sg_stream_ptr++; | |
728 } | |
729 sg_output_plane += sg_line_inc; | |
730 } | |
731 | |
732 /* report success */ | |
733 return 0; | |
734 } | |
735 | |
736 static int ipvideo_decode_block_opcode_0xC(void) | |
737 { | |
738 int x, y; | |
739 unsigned char pix; | |
740 | |
741 /* 16-color block encoding: each 2x2 block is a different color */ | |
742 CHECK_STREAM_PTR(16); | |
743 | |
744 for (y = 0; y < 8; y += 2) { | |
745 for (x = 0; x < 8; x += 2) { | |
746 pix = *sg_stream_ptr++; | |
747 *(sg_output_plane + x) = pix; | |
748 *(sg_output_plane + x + 1) = pix; | |
749 *(sg_output_plane + sg_stride + x) = pix; | |
750 *(sg_output_plane + sg_stride + x + 1) = pix; | |
751 } | |
752 sg_output_plane += sg_stride * 2; | |
753 } | |
754 | |
755 /* report success */ | |
756 return 0; | |
757 } | |
758 | |
759 static int ipvideo_decode_block_opcode_0xD(void) | |
760 { | |
761 int x, y; | |
762 unsigned char P[4]; | |
763 unsigned char index = 0; | |
764 | |
765 /* 4-color block encoding: each 4x4 block is a different color */ | |
766 CHECK_STREAM_PTR(4); | |
767 | |
768 for (y = 0; y < 4; y++) | |
769 P[y] = *sg_stream_ptr++; | |
770 | |
771 for (y = 0; y < 8; y++) { | |
772 if (y < 4) | |
773 index = 0; | |
774 else | |
775 index = 2; | |
776 | |
777 for (x = 0; x < 8; x++) { | |
778 if (x == 4) | |
779 index++; | |
780 *sg_output_plane++ = P[index]; | |
781 } | |
782 sg_output_plane += sg_line_inc; | |
783 } | |
784 | |
785 /* report success */ | |
786 return 0; | |
787 } | |
788 | |
789 static int ipvideo_decode_block_opcode_0xE(void) | |
790 { | |
791 int x, y; | |
792 unsigned char pix; | |
793 | |
794 /* 1-color encoding: the whole block is 1 solid color */ | |
795 CHECK_STREAM_PTR(1); | |
796 pix = *sg_stream_ptr++; | |
797 | |
798 for (y = 0; y < 8; y++) { | |
799 for (x = 0; x < 8; x++) { | |
800 *sg_output_plane++ = pix; | |
801 } | |
802 sg_output_plane += sg_line_inc; | |
803 } | |
804 | |
805 /* report success */ | |
806 return 0; | |
807 } | |
808 | |
809 static int ipvideo_decode_block_opcode_0xF(void) | |
810 { | |
811 int x, y; | |
812 unsigned char sample0, sample1; | |
813 | |
814 /* dithered encoding */ | |
815 CHECK_STREAM_PTR(2); | |
816 sample0 = *sg_stream_ptr++; | |
817 sample1 = *sg_stream_ptr++; | |
818 | |
819 for (y = 0; y < 8; y++) { | |
820 for (x = 0; x < 8; x += 2) { | |
821 if (y & 1) { | |
822 *sg_output_plane++ = sample1; | |
823 *sg_output_plane++ = sample0; | |
824 } else { | |
825 *sg_output_plane++ = sample0; | |
826 *sg_output_plane++ = sample1; | |
827 } | |
828 } | |
829 sg_output_plane += sg_line_inc; | |
830 } | |
831 | |
832 /* report success */ | |
833 return 0; | |
834 } | |
835 | |
836 static int (*ipvideo_decode_block[16])(void); | |
837 | |
838 static void ipvideo_decode_opcodes(IpvideoContext *s) | |
839 { | |
840 int x, y; | |
841 int index = 0; | |
842 unsigned char opcode; | |
843 int ret; | |
844 int code_counts[16]; | |
845 static int frame = 0; | |
846 | |
847 debug_interplay("------------------ frame %d\n", frame); | |
848 frame++; | |
849 | |
850 for (x = 0; x < 16; x++) | |
851 code_counts[x] = 0; | |
852 | |
853 /* this is PAL8, so make the palette available */ | |
854 if (s->avctx->pix_fmt == PIX_FMT_PAL8) | |
855 memcpy(s->current_frame.data[1], s->palette, PALETTE_COUNT * 4); | |
856 | |
857 switch (s->avctx->pix_fmt) { | |
858 | |
859 case PIX_FMT_PAL8: | |
860 sg_stride = s->current_frame.linesize[0]; | |
861 sg_stream_ptr = s->buf + 14; /* data starts 14 bytes in */ | |
862 sg_stream_end = s->buf + s->size; | |
863 sg_line_inc = sg_stride - 8; | |
864 sg_current_plane = s->current_frame.data[0]; | |
865 sg_last_plane = s->last_frame.data[0]; | |
1474
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
866 sg_second_last_plane = s->second_last_frame.data[0]; |
1468 | 867 sg_upper_motion_limit_offset = (s->avctx->height - 8) * sg_stride |
868 + s->avctx->width - 8; | |
869 sg_dsp = s->dsp; | |
870 | |
871 for (y = 0; y < (sg_stride * s->avctx->height); y += sg_stride * 8) { | |
872 for (x = y; x < y + s->avctx->width; x += 8) { | |
873 /* bottom nibble first, then top nibble (which makes it | |
874 * hard to use a GetBitcontext) */ | |
875 if (index & 1) | |
876 opcode = s->decoding_map[index >> 1] >> 4; | |
877 else | |
878 opcode = s->decoding_map[index >> 1] & 0xF; | |
879 index++; | |
880 | |
881 debug_interplay(" block @ (%3d, %3d): encoding 0x%X, data ptr @ %p\n", | |
882 x - y, y / sg_stride, opcode, sg_stream_ptr); | |
883 code_counts[opcode]++; | |
884 | |
885 sg_output_plane = sg_current_plane + x; | |
886 ret = ipvideo_decode_block[opcode](); | |
887 if (ret != 0) { | |
888 printf(" Interplay video: decode problem on frame %d, @ block (%d, %d)\n", | |
889 frame, x - y, y / sg_stride); | |
890 return; | |
891 } | |
892 } | |
893 } | |
894 if ((sg_stream_ptr != sg_stream_end) && | |
895 (sg_stream_ptr + 1 != sg_stream_end)) { | |
896 printf (" Interplay video: decode finished with %d bytes left over\n", | |
897 sg_stream_end - sg_stream_ptr); | |
898 } | |
899 break; | |
900 | |
901 default: | |
902 printf ("Interplay video: Unhandled video format\n"); | |
903 break; | |
904 } | |
905 | |
906 } | |
907 | |
1439
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
908 static int ipvideo_decode_init(AVCodecContext *avctx) |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
909 { |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
910 IpvideoContext *s = avctx->priv_data; |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
911 |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
912 s->avctx = avctx; |
1468 | 913 |
914 if (s->avctx->extradata_size != sizeof(AVPaletteControl)) { | |
915 printf (" Interplay video: expected extradata_size of %d\n", | |
916 sizeof(AVPaletteControl)); | |
917 return -1; | |
918 } | |
919 | |
920 avctx->pix_fmt = PIX_FMT_PAL8; | |
1439
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
921 avctx->has_b_frames = 0; |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
922 dsputil_init(&s->dsp, avctx); |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
923 |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
924 /* decoding map contains 4 bits of information per 8x8 block */ |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
925 s->decoding_map_size = avctx->width * avctx->height / (8 * 8 * 2); |
1468 | 926 |
927 /* assign block decode functions */ | |
1474
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
928 ipvideo_decode_block[0x0] = ipvideo_decode_block_opcode_0x0; |
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
929 ipvideo_decode_block[0x1] = ipvideo_decode_block_opcode_0x1; |
1468 | 930 ipvideo_decode_block[0x2] = ipvideo_decode_block_opcode_0x2; |
931 ipvideo_decode_block[0x3] = ipvideo_decode_block_opcode_0x3; | |
932 ipvideo_decode_block[0x4] = ipvideo_decode_block_opcode_0x4; | |
933 ipvideo_decode_block[0x5] = ipvideo_decode_block_opcode_0x5; | |
934 ipvideo_decode_block[0x6] = ipvideo_decode_block_opcode_0x6; | |
935 ipvideo_decode_block[0x7] = ipvideo_decode_block_opcode_0x7; | |
936 ipvideo_decode_block[0x8] = ipvideo_decode_block_opcode_0x8; | |
937 ipvideo_decode_block[0x9] = ipvideo_decode_block_opcode_0x9; | |
938 ipvideo_decode_block[0xA] = ipvideo_decode_block_opcode_0xA; | |
939 ipvideo_decode_block[0xB] = ipvideo_decode_block_opcode_0xB; | |
940 ipvideo_decode_block[0xC] = ipvideo_decode_block_opcode_0xC; | |
941 ipvideo_decode_block[0xD] = ipvideo_decode_block_opcode_0xD; | |
942 ipvideo_decode_block[0xE] = ipvideo_decode_block_opcode_0xE; | |
943 ipvideo_decode_block[0xF] = ipvideo_decode_block_opcode_0xF; | |
1439
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
944 |
1474
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
945 s->current_frame.data[0] = s->last_frame.data[0] = |
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
946 s->second_last_frame.data[0] = NULL; |
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
947 |
1439
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
948 return 0; |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
949 } |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
950 |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
951 static int ipvideo_decode_frame(AVCodecContext *avctx, |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
952 void *data, int *data_size, |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
953 uint8_t *buf, int buf_size) |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
954 { |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
955 IpvideoContext *s = avctx->priv_data; |
1468 | 956 AVPaletteControl *palette_control = (AVPaletteControl *)avctx->extradata; |
1439
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
957 |
1468 | 958 if (palette_control->palette_changed) { |
959 /* load the new palette and reset the palette control */ | |
960 ipvideo_new_palette(s, palette_control->palette); | |
961 palette_control->palette_changed = 0; | |
1439
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
962 } |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
963 |
1468 | 964 s->decoding_map = buf; |
965 s->buf = buf + s->decoding_map_size; | |
966 s->size = buf_size - s->decoding_map_size; | |
967 | |
1474
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
968 s->current_frame.reference = 3; |
1468 | 969 if (avctx->get_buffer(avctx, &s->current_frame)) { |
970 printf (" Interplay Video: get_buffer() failed\n"); | |
971 return -1; | |
972 } | |
973 | |
974 ipvideo_decode_opcodes(s); | |
975 | |
1474
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
976 *data_size = sizeof(AVFrame); |
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
977 *(AVFrame*)data = s->current_frame; |
1468 | 978 |
979 /* shuffle frames */ | |
1474
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
980 if (s->second_last_frame.data[0]) |
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
981 avctx->release_buffer(avctx, &s->second_last_frame); |
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
982 s->second_last_frame = s->last_frame; |
1468 | 983 s->last_frame = s->current_frame; |
1474
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
984 s->current_frame.data[0] = NULL; /* catch any access attempts */ |
1468 | 985 |
986 /* report that the buffer was completely consumed */ | |
1439
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
987 return buf_size; |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
988 } |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
989 |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
990 static int ipvideo_decode_end(AVCodecContext *avctx) |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
991 { |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
992 IpvideoContext *s = avctx->priv_data; |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
993 |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
994 /* release the last frame */ |
1474
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
995 if (s->last_frame.data[0]) |
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
996 avctx->release_buffer(avctx, &s->last_frame); |
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
997 if (s->second_last_frame.data[0]) |
94c7f7c23dd9
video looks beautiful now, many thanks to Alexander Belyakov
tmmm
parents:
1473
diff
changeset
|
998 avctx->release_buffer(avctx, &s->second_last_frame); |
1439
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
999 |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
1000 return 0; |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
1001 } |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
1002 |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
1003 AVCodec interplay_video_decoder = { |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
1004 "interplayvideo", |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
1005 CODEC_TYPE_VIDEO, |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
1006 CODEC_ID_INTERPLAY_VIDEO, |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
1007 sizeof(IpvideoContext), |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
1008 ipvideo_decode_init, |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
1009 NULL, |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
1010 ipvideo_decode_end, |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
1011 ipvideo_decode_frame, |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
1012 CODEC_CAP_DR1, |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
1013 }; |