Mercurial > libavcodec.hg
annotate interplayvideo.c @ 1473:873100cd2108 libavcodec
wrong, wrong, wrong...coded bits are read in the opposite direction
author | tmmm |
---|---|
date | Wed, 17 Sep 2003 05:17:31 +0000 |
parents | 92c1f24f7754 |
children | 94c7f7c23dd9 |
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; |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
59 AVFrame last_frame; |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
60 AVFrame current_frame; |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
61 int first_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; | |
108 static int sg_line_inc; | |
109 static int sg_stride; | |
110 static int sg_upper_motion_limit_offset; | |
111 static DSPContext sg_dsp; | |
112 | |
113 static int ipvideo_decode_block_opcode_0x0_0x1(void) | |
114 { | |
115 int x, y; | |
116 unsigned char *src_block; | |
117 | |
118 /* skip block, which actually means to copy from previous frame */ | |
119 src_block = sg_last_plane + (sg_output_plane - sg_current_plane); | |
120 for (y = 0; y < 8; y++) { | |
121 for (x = 0; x < 8; x++) { | |
122 *sg_output_plane++ = *src_block++; | |
123 } | |
124 sg_output_plane += sg_line_inc; | |
125 src_block += sg_line_inc; | |
126 } | |
127 | |
128 /* report success */ | |
129 return 0; | |
130 } | |
131 | |
132 #define COPY_FROM_CURRENT() \ | |
133 motion_offset = current_offset; \ | |
134 motion_offset += y * sg_stride; \ | |
135 motion_offset += x; \ | |
136 if (motion_offset < 0) { \ | |
137 printf (" Interplay video: motion offset < 0 (%d)\n", motion_offset); \ | |
138 return -1; \ | |
139 } else if (motion_offset > sg_upper_motion_limit_offset) { \ | |
140 printf (" Interplay video: motion offset above limit (%d >= %d)\n", \ | |
141 motion_offset, sg_upper_motion_limit_offset); \ | |
142 return -1; \ | |
143 } \ | |
144 sg_dsp.put_pixels_tab[0][0](sg_output_plane, \ | |
145 sg_current_plane + motion_offset, sg_stride, 8); | |
146 | |
147 #define COPY_FROM_PREVIOUS() \ | |
148 motion_offset = current_offset; \ | |
149 motion_offset += y * sg_stride; \ | |
150 motion_offset += x; \ | |
151 if (motion_offset < 0) { \ | |
152 printf (" Interplay video: motion offset < 0 (%d)\n", motion_offset); \ | |
153 return -1; \ | |
154 } else if (motion_offset > sg_upper_motion_limit_offset) { \ | |
155 printf (" Interplay video: motion offset above limit (%d >= %d)\n", \ | |
156 motion_offset, sg_upper_motion_limit_offset); \ | |
157 return -1; \ | |
158 } \ | |
159 sg_dsp.put_pixels_tab[0][0](sg_output_plane, \ | |
160 sg_last_plane + motion_offset, sg_stride, 8); | |
161 | |
162 static int ipvideo_decode_block_opcode_0x2(void) | |
163 { | |
164 unsigned char B; | |
165 int x, y; | |
166 int motion_offset; | |
167 int current_offset = sg_output_plane - sg_current_plane; | |
168 | |
169 /* This is the opcode which claims to copy data from within the same | |
170 * frame at a coordinate which has not been rendered yet. Assume that | |
171 * it is supposed to be copied from the previous frame. */ | |
172 | |
173 /* need 1 more byte for motion */ | |
174 CHECK_STREAM_PTR(1); | |
175 B = *sg_stream_ptr++; | |
176 | |
177 if (B < 56) { | |
178 x = 8 + (B % 7); | |
179 y = B / 7; | |
180 } else { | |
181 x = -14 + ((B - 56) % 29); | |
182 y = 8 + ((B - 56) / 29); | |
183 } | |
184 | |
185 debug_interplay (" motion byte = %d, (x, y) = (%d, %d)\n", B, x, y); | |
186 COPY_FROM_PREVIOUS(); | |
187 | |
188 /* report success */ | |
189 return 0; | |
190 } | |
191 | |
192 static int ipvideo_decode_block_opcode_0x3(void) | |
193 { | |
194 unsigned char B; | |
195 int x, y; | |
196 int motion_offset; | |
197 int current_offset = sg_output_plane - sg_current_plane; | |
198 | |
199 /* copy 8x8 block from current frame from an up/left block */ | |
200 | |
201 /* need 1 more byte for motion */ | |
202 CHECK_STREAM_PTR(1); | |
203 B = *sg_stream_ptr++; | |
204 | |
205 if (B < 56) { | |
206 x = -(8 + (B % 7)); | |
207 y = -(B / 7); | |
208 } else { | |
209 x = -(-14 + ((B - 56) % 29)); | |
210 y = -( 8 + ((B - 56) / 29)); | |
211 } | |
212 | |
213 debug_interplay (" motion byte = %d, (x, y) = (%d, %d)\n", B, x, y); | |
214 COPY_FROM_CURRENT(); | |
215 | |
216 /* report success */ | |
217 return 0; | |
218 } | |
219 | |
220 static int ipvideo_decode_block_opcode_0x4(void) | |
221 { | |
222 int x, y; | |
223 unsigned char B, BL, BH; | |
224 int motion_offset; | |
225 int current_offset = sg_output_plane - sg_current_plane; | |
226 | |
227 /* copy a block from the previous frame; need 1 more byte */ | |
228 CHECK_STREAM_PTR(1); | |
229 | |
230 B = *sg_stream_ptr++; | |
231 BL = B & 0x0F; | |
232 BH = (B >> 4) & 0x0F; | |
233 x = -8 + BL; | |
234 y = -8 + BH; | |
235 | |
236 debug_interplay (" motion byte = %d, (x, y) = (%d, %d)\n", B, x, y); | |
237 COPY_FROM_PREVIOUS(); | |
238 | |
239 /* report success */ | |
240 return 0; | |
241 } | |
242 | |
243 static int ipvideo_decode_block_opcode_0x5(void) | |
244 { | |
245 signed char x, y; | |
246 int motion_offset; | |
247 int current_offset = sg_output_plane - sg_current_plane; | |
248 | |
249 /* copy a block from the previous frame using an expanded range; | |
250 * need 2 more bytes */ | |
251 CHECK_STREAM_PTR(2); | |
252 | |
253 x = *sg_stream_ptr++; | |
254 y = *sg_stream_ptr++; | |
255 | |
256 debug_interplay (" motion bytes = %d, %d\n", x, y); | |
257 COPY_FROM_PREVIOUS(); | |
258 | |
259 /* report success */ | |
260 return 0; | |
261 } | |
262 | |
263 static int ipvideo_decode_block_opcode_0x6(void) | |
264 { | |
265 /* mystery opcode? skip multiple blocks? */ | |
266 printf (" Interplay video: Help! Mystery opcode 0x6 seen\n"); | |
267 | |
268 /* report success */ | |
269 return 0; | |
270 } | |
271 | |
272 static int ipvideo_decode_block_opcode_0x7(void) | |
273 { | |
274 int x, y; | |
275 unsigned char P0, P1; | |
276 unsigned char B[8]; | |
277 unsigned int flags; | |
278 int bitmask; | |
279 | |
280 /* 2-color encoding */ | |
281 CHECK_STREAM_PTR(2); | |
282 | |
283 P0 = *sg_stream_ptr++; | |
284 P1 = *sg_stream_ptr++; | |
285 | |
286 if (P0 <= P1) { | |
287 | |
288 /* need 8 more bytes from the stream */ | |
289 CHECK_STREAM_PTR(8); | |
290 for (y = 0; y < 8; y++) | |
291 B[y] = *sg_stream_ptr++; | |
292 | |
293 for (y = 0; y < 8; y++) { | |
294 flags = B[y]; | |
1473
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
295 for (x = 0x01; x <= 0x80; x <<= 1) { |
1468 | 296 if (flags & x) |
297 *sg_output_plane++ = P1; | |
298 else | |
299 *sg_output_plane++ = P0; | |
300 } | |
301 sg_output_plane += sg_line_inc; | |
302 } | |
303 | |
304 } else { | |
305 | |
306 /* need 2 more bytes from the stream */ | |
307 CHECK_STREAM_PTR(2); | |
308 B[0] = *sg_stream_ptr++; | |
309 B[1] = *sg_stream_ptr++; | |
310 | |
1473
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
311 flags = (B[1] << 8) | B[0]; |
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
312 bitmask = 0x0001; |
1468 | 313 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
|
314 for (x = 0; x < 8; x += 2, bitmask <<= 1) { |
1468 | 315 if (flags & bitmask) { |
316 *(sg_output_plane + x) = P0; | |
317 *(sg_output_plane + x + 1) = P0; | |
318 *(sg_output_plane + sg_stride + x) = P0; | |
319 *(sg_output_plane + sg_stride + x + 1) = P0; | |
320 } else { | |
321 *(sg_output_plane + x) = P1; | |
322 *(sg_output_plane + x + 1) = P1; | |
323 *(sg_output_plane + sg_stride + x) = P1; | |
324 *(sg_output_plane + sg_stride + x + 1) = P1; | |
325 } | |
326 } | |
327 sg_output_plane += sg_stride * 2; | |
328 } | |
329 } | |
330 | |
331 /* report success */ | |
332 return 0; | |
333 } | |
334 | |
335 static int ipvideo_decode_block_opcode_0x8(void) | |
336 { | |
337 int x, y; | |
338 unsigned char P[8]; | |
339 unsigned char B[8]; | |
340 unsigned int flags = 0; | |
341 unsigned int bitmask = 0; | |
342 unsigned char P0 = 0, P1 = 0; | |
343 int lower_half = 0; | |
344 | |
345 /* 2-color encoding for each 4x4 quadrant, or 2-color encoding on | |
346 * either top and bottom or left and right halves */ | |
347 CHECK_STREAM_PTR(2); | |
348 | |
349 P[0] = *sg_stream_ptr++; | |
350 P[1] = *sg_stream_ptr++; | |
351 | |
352 if (P[0] <= P[1]) { | |
353 | |
354 /* need 12 more bytes */ | |
355 CHECK_STREAM_PTR(12); | |
356 B[0] = *sg_stream_ptr++; B[1] = *sg_stream_ptr++; | |
357 P[2] = *sg_stream_ptr++; P[3] = *sg_stream_ptr++; | |
358 B[2] = *sg_stream_ptr++; B[3] = *sg_stream_ptr++; | |
359 P[4] = *sg_stream_ptr++; P[5] = *sg_stream_ptr++; | |
360 B[4] = *sg_stream_ptr++; B[5] = *sg_stream_ptr++; | |
361 P[6] = *sg_stream_ptr++; P[7] = *sg_stream_ptr++; | |
362 B[6] = *sg_stream_ptr++; B[7] = *sg_stream_ptr++; | |
363 | |
364 for (y = 0; y < 8; y++) { | |
365 | |
366 /* time to reload flags? */ | |
367 if (y == 0) { | |
368 flags = | |
1473
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
369 ((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
|
370 ((B[0] & 0x0F) ) | ((B[4] & 0x0F) << 4) | |
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
371 ((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
|
372 ((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
|
373 bitmask = 0x00000001; |
1468 | 374 lower_half = 0; /* still on top half */ |
375 } else if (y == 4) { | |
376 flags = | |
1473
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
377 ((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
|
378 ((B[2] & 0x0F) ) | ((B[6] & 0x0F) << 4) | |
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
379 ((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
|
380 ((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
|
381 bitmask = 0x00000001; |
1468 | 382 lower_half = 4; |
383 } | |
384 | |
1473
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
385 for (x = 0; x < 8; x++, bitmask <<= 1) { |
1468 | 386 /* get the pixel values ready for this quadrant */ |
387 if (x == 0) { | |
388 P0 = P[lower_half + 0]; | |
389 P1 = P[lower_half + 1]; | |
390 } else if (x == 4) { | |
391 P0 = P[lower_half + 2]; | |
392 P1 = P[lower_half + 3]; | |
393 } | |
394 | |
395 if (flags & bitmask) | |
396 *sg_output_plane++ = P1; | |
397 else | |
398 *sg_output_plane++ = P0; | |
399 } | |
400 sg_output_plane += sg_line_inc; | |
401 } | |
402 | |
403 } else { | |
404 | |
405 /* need 10 more bytes */ | |
406 CHECK_STREAM_PTR(10); | |
407 B[0] = *sg_stream_ptr++; B[1] = *sg_stream_ptr++; | |
408 B[2] = *sg_stream_ptr++; B[3] = *sg_stream_ptr++; | |
409 P[2] = *sg_stream_ptr++; P[3] = *sg_stream_ptr++; | |
410 B[4] = *sg_stream_ptr++; B[5] = *sg_stream_ptr++; | |
411 B[6] = *sg_stream_ptr++; B[7] = *sg_stream_ptr++; | |
412 | |
413 if (P[2] <= P[3]) { | |
414 | |
415 /* vertical split; left & right halves are 2-color encoded */ | |
416 | |
417 for (y = 0; y < 8; y++) { | |
418 | |
419 /* time to reload flags? */ | |
420 if (y == 0) { | |
421 flags = | |
1473
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
422 ((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
|
423 ((B[0] & 0x0F) ) | ((B[4] & 0x0F) << 4) | |
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
424 ((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
|
425 ((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
|
426 bitmask = 0x00000001; |
1468 | 427 } else if (y == 4) { |
428 flags = | |
1473
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
429 ((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
|
430 ((B[2] & 0x0F) ) | ((B[6] & 0x0F) << 4) | |
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
431 ((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
|
432 ((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
|
433 bitmask = 0x00000001; |
1468 | 434 } |
435 | |
1473
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
436 for (x = 0; x < 8; x++, bitmask <<= 1) { |
1468 | 437 /* get the pixel values ready for this half */ |
438 if (x == 0) { | |
439 P0 = P[0]; | |
440 P1 = P[1]; | |
441 } else if (x == 4) { | |
442 P0 = P[2]; | |
443 P1 = P[3]; | |
444 } | |
445 | |
446 if (flags & bitmask) | |
447 *sg_output_plane++ = P0; | |
448 else | |
449 *sg_output_plane++ = P1; | |
450 } | |
451 sg_output_plane += sg_line_inc; | |
452 } | |
453 | |
454 } else { | |
455 | |
456 /* horizontal split; top & bottom halves are 2-color encoded */ | |
457 | |
458 for (y = 0; y < 8; y++) { | |
459 | |
460 flags = B[y]; | |
461 if (y == 0) { | |
462 P0 = P[0]; | |
463 P1 = P[1]; | |
464 } else if (y == 4) { | |
465 P0 = P[2]; | |
466 P1 = P[3]; | |
467 } | |
468 | |
1473
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
469 for (bitmask = 0x01; bitmask <= 0x80; bitmask <<= 1) { |
1468 | 470 |
471 if (flags & bitmask) | |
472 *sg_output_plane++ = P0; | |
473 else | |
474 *sg_output_plane++ = P1; | |
475 } | |
476 sg_output_plane += sg_line_inc; | |
477 } | |
478 } | |
479 } | |
480 | |
481 /* report success */ | |
482 return 0; | |
483 } | |
484 | |
485 static int ipvideo_decode_block_opcode_0x9(void) | |
486 { | |
487 int x, y; | |
488 unsigned char P[4]; | |
1473
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
489 unsigned char B[4]; |
1468 | 490 unsigned int flags = 0; |
491 int shifter = 0; | |
492 unsigned char pix; | |
493 | |
494 /* 4-color encoding */ | |
495 CHECK_STREAM_PTR(4); | |
496 | |
497 for (y = 0; y < 4; y++) | |
498 P[y] = *sg_stream_ptr++; | |
499 | |
500 if ((P[0] <= P[1]) && (P[2] <= P[3])) { | |
501 | |
502 /* 1 of 4 colors for each pixel, need 16 more bytes */ | |
503 CHECK_STREAM_PTR(16); | |
504 | |
505 for (y = 0; y < 8; y++) { | |
506 /* 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
|
507 flags = (sg_stream_ptr[1] << 8) | sg_stream_ptr[0]; |
1468 | 508 sg_stream_ptr += 2; |
1473
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
509 for (x = 0, shifter = 0; x < 8; x++, shifter += 2) { |
1468 | 510 *sg_output_plane++ = P[(flags >> shifter) & 0x03]; |
511 } | |
512 sg_output_plane += sg_line_inc; | |
513 } | |
514 | |
515 } else if ((P[0] <= P[1]) && (P[2] > P[3])) { | |
516 | |
517 /* 1 of 4 colors for each 2x2 block, need 4 more bytes */ | |
518 CHECK_STREAM_PTR(4); | |
519 | |
1473
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
520 B[0] = *sg_stream_ptr++; |
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
521 B[1] = *sg_stream_ptr++; |
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
522 B[2] = *sg_stream_ptr++; |
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
523 B[3] = *sg_stream_ptr++; |
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
524 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
|
525 shifter = 0; |
1468 | 526 |
527 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
|
528 for (x = 0; x < 8; x += 2, shifter += 2) { |
1468 | 529 pix = P[(flags >> shifter) & 0x03]; |
530 *(sg_output_plane + x) = pix; | |
531 *(sg_output_plane + x + 1) = pix; | |
532 *(sg_output_plane + sg_stride + x) = pix; | |
533 *(sg_output_plane + sg_stride + x + 1) = pix; | |
534 } | |
535 sg_output_plane += sg_stride * 2; | |
536 } | |
537 | |
538 } else if ((P[0] > P[1]) && (P[2] <= P[3])) { | |
539 | |
540 /* 1 of 4 colors for each 2x1 block, need 8 more bytes */ | |
541 CHECK_STREAM_PTR(8); | |
542 | |
543 for (y = 0; y < 8; y++) { | |
544 /* time to reload flags? */ | |
545 if ((y == 0) || (y == 4)) { | |
1473
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
546 B[0] = *sg_stream_ptr++; |
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
547 B[1] = *sg_stream_ptr++; |
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
548 B[2] = *sg_stream_ptr++; |
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
549 B[3] = *sg_stream_ptr++; |
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
550 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
|
551 shifter = 0; |
1468 | 552 } |
1473
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
553 for (x = 0; x < 8; x += 2, shifter += 2) { |
1468 | 554 pix = P[(flags >> shifter) & 0x03]; |
555 *(sg_output_plane + x) = pix; | |
556 *(sg_output_plane + x + 1) = pix; | |
557 } | |
558 sg_output_plane += sg_stride; | |
559 } | |
560 | |
561 } else { | |
562 | |
563 /* 1 of 4 colors for each 1x2 block, need 8 more bytes */ | |
564 CHECK_STREAM_PTR(8); | |
565 | |
566 for (y = 0; y < 8; y += 2) { | |
567 /* time to reload flags? */ | |
568 if ((y == 0) || (y == 4)) { | |
1473
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
569 B[0] = *sg_stream_ptr++; |
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
570 B[1] = *sg_stream_ptr++; |
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
571 B[2] = *sg_stream_ptr++; |
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
572 B[3] = *sg_stream_ptr++; |
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
573 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
|
574 shifter = 0; |
1468 | 575 } |
1473
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
576 for (x = 0; x < 8; x++, shifter += 2) { |
1468 | 577 pix = P[(flags >> shifter) & 0x03]; |
578 *(sg_output_plane + x) = pix; | |
579 *(sg_output_plane + sg_stride + x) = pix; | |
580 } | |
581 sg_output_plane += sg_stride * 2; | |
582 } | |
583 } | |
584 | |
585 /* report success */ | |
586 return 0; | |
587 } | |
588 | |
589 static int ipvideo_decode_block_opcode_0xA(void) | |
590 { | |
591 int x, y; | |
592 unsigned char P[16]; | |
593 unsigned char B[16]; | |
594 int flags = 0; | |
595 int shifter = 0; | |
596 int index; | |
597 int split; | |
598 int lower_half; | |
599 | |
600 /* 4-color encoding for each 4x4 quadrant, or 4-color encoding on | |
601 * either top and bottom or left and right halves */ | |
602 CHECK_STREAM_PTR(4); | |
603 | |
604 for (y = 0; y < 4; y++) | |
605 P[y] = *sg_stream_ptr++; | |
606 | |
607 if (P[0] <= P[1]) { | |
608 | |
609 /* 4-color encoding for each quadrant; need 28 more bytes */ | |
610 CHECK_STREAM_PTR(28); | |
611 | |
612 for (y = 0; y < 4; y++) | |
613 B[y] = *sg_stream_ptr++; | |
614 for (y = 4; y < 16; y += 4) { | |
615 for (x = y; x < y + 4; x++) | |
616 P[x] = *sg_stream_ptr++; | |
617 for (x = y; x < y + 4; x++) | |
618 B[x] = *sg_stream_ptr++; | |
619 } | |
620 | |
621 for (y = 0; y < 8; y++) { | |
622 | |
623 lower_half = (y >= 4) ? 4 : 0; | |
1473
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
624 flags = (B[y + 8] << 8) | B[y]; |
1468 | 625 |
1473
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
626 for (x = 0, shifter = 0; x < 8; x++, shifter += 2) { |
1468 | 627 split = (x >= 4) ? 8 : 0; |
628 index = split + lower_half + ((flags >> shifter) & 0x03); | |
629 *sg_output_plane++ = P[index]; | |
630 } | |
631 | |
632 sg_output_plane += sg_line_inc; | |
633 } | |
634 | |
635 } else { | |
636 | |
637 /* 4-color encoding for either left and right or top and bottom | |
638 * halves; need 20 more bytes */ | |
639 CHECK_STREAM_PTR(20); | |
640 | |
641 for (y = 0; y < 8; y++) | |
642 B[y] = *sg_stream_ptr++; | |
643 for (y = 4; y < 8; y++) | |
644 P[y] = *sg_stream_ptr++; | |
645 for (y = 8; y < 16; y++) | |
646 B[y] = *sg_stream_ptr++; | |
647 | |
648 if (P[4] <= P[5]) { | |
649 | |
650 /* block is divided into left and right halves */ | |
651 for (y = 0; y < 8; y++) { | |
652 | |
1473
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
653 flags = (B[y + 8] << 8) | B[y]; |
1468 | 654 split = 0; |
655 | |
1473
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
656 for (x = 0, shifter = 0; x < 8; x++, shifter += 2) { |
1468 | 657 if (x == 4) |
658 split = 4; | |
659 *sg_output_plane++ = P[split + ((flags >> shifter) & 0x03)]; | |
660 } | |
661 | |
662 sg_output_plane += sg_line_inc; | |
663 } | |
664 | |
665 } else { | |
666 | |
667 /* block is divided into top and bottom halves */ | |
668 split = 0; | |
669 for (y = 0; y < 8; y++) { | |
670 | |
1473
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
671 flags = (B[y * 2 + 1] << 8) | B[y * 2]; |
1468 | 672 if (y == 4) |
673 split = 4; | |
674 | |
1473
873100cd2108
wrong, wrong, wrong...coded bits are read in the opposite direction
tmmm
parents:
1468
diff
changeset
|
675 for (x = 0, shifter = 0; x < 8; x++, shifter += 2) |
1468 | 676 *sg_output_plane++ = P[split + ((flags >> shifter) & 0x03)]; |
677 | |
678 sg_output_plane += sg_line_inc; | |
679 } | |
680 } | |
681 } | |
682 | |
683 /* report success */ | |
684 return 0; | |
685 } | |
686 | |
687 static int ipvideo_decode_block_opcode_0xB(void) | |
688 { | |
689 int x, y; | |
690 | |
691 /* 64-color encoding (each pixel in block is a different color) */ | |
692 CHECK_STREAM_PTR(64); | |
693 | |
694 for (y = 0; y < 8; y++) { | |
695 for (x = 0; x < 8; x++) { | |
696 *sg_output_plane++ = *sg_stream_ptr++; | |
697 } | |
698 sg_output_plane += sg_line_inc; | |
699 } | |
700 | |
701 /* report success */ | |
702 return 0; | |
703 } | |
704 | |
705 static int ipvideo_decode_block_opcode_0xC(void) | |
706 { | |
707 int x, y; | |
708 unsigned char pix; | |
709 | |
710 /* 16-color block encoding: each 2x2 block is a different color */ | |
711 CHECK_STREAM_PTR(16); | |
712 | |
713 for (y = 0; y < 8; y += 2) { | |
714 for (x = 0; x < 8; x += 2) { | |
715 pix = *sg_stream_ptr++; | |
716 *(sg_output_plane + x) = pix; | |
717 *(sg_output_plane + x + 1) = pix; | |
718 *(sg_output_plane + sg_stride + x) = pix; | |
719 *(sg_output_plane + sg_stride + x + 1) = pix; | |
720 } | |
721 sg_output_plane += sg_stride * 2; | |
722 } | |
723 | |
724 /* report success */ | |
725 return 0; | |
726 } | |
727 | |
728 static int ipvideo_decode_block_opcode_0xD(void) | |
729 { | |
730 int x, y; | |
731 unsigned char P[4]; | |
732 unsigned char index = 0; | |
733 | |
734 /* 4-color block encoding: each 4x4 block is a different color */ | |
735 CHECK_STREAM_PTR(4); | |
736 | |
737 for (y = 0; y < 4; y++) | |
738 P[y] = *sg_stream_ptr++; | |
739 | |
740 for (y = 0; y < 8; y++) { | |
741 if (y < 4) | |
742 index = 0; | |
743 else | |
744 index = 2; | |
745 | |
746 for (x = 0; x < 8; x++) { | |
747 if (x == 4) | |
748 index++; | |
749 *sg_output_plane++ = P[index]; | |
750 } | |
751 sg_output_plane += sg_line_inc; | |
752 } | |
753 | |
754 /* report success */ | |
755 return 0; | |
756 } | |
757 | |
758 static int ipvideo_decode_block_opcode_0xE(void) | |
759 { | |
760 int x, y; | |
761 unsigned char pix; | |
762 | |
763 /* 1-color encoding: the whole block is 1 solid color */ | |
764 CHECK_STREAM_PTR(1); | |
765 pix = *sg_stream_ptr++; | |
766 | |
767 for (y = 0; y < 8; y++) { | |
768 for (x = 0; x < 8; x++) { | |
769 *sg_output_plane++ = pix; | |
770 } | |
771 sg_output_plane += sg_line_inc; | |
772 } | |
773 | |
774 /* report success */ | |
775 return 0; | |
776 } | |
777 | |
778 static int ipvideo_decode_block_opcode_0xF(void) | |
779 { | |
780 int x, y; | |
781 unsigned char sample0, sample1; | |
782 | |
783 /* dithered encoding */ | |
784 CHECK_STREAM_PTR(2); | |
785 sample0 = *sg_stream_ptr++; | |
786 sample1 = *sg_stream_ptr++; | |
787 | |
788 for (y = 0; y < 8; y++) { | |
789 for (x = 0; x < 8; x += 2) { | |
790 if (y & 1) { | |
791 *sg_output_plane++ = sample1; | |
792 *sg_output_plane++ = sample0; | |
793 } else { | |
794 *sg_output_plane++ = sample0; | |
795 *sg_output_plane++ = sample1; | |
796 } | |
797 } | |
798 sg_output_plane += sg_line_inc; | |
799 } | |
800 | |
801 /* report success */ | |
802 return 0; | |
803 } | |
804 | |
805 static int (*ipvideo_decode_block[16])(void); | |
806 | |
807 static void ipvideo_decode_opcodes(IpvideoContext *s) | |
808 { | |
809 int x, y; | |
810 int index = 0; | |
811 unsigned char opcode; | |
812 int ret; | |
813 int code_counts[16]; | |
814 static int frame = 0; | |
815 | |
816 debug_interplay("------------------ frame %d\n", frame); | |
817 frame++; | |
818 | |
819 for (x = 0; x < 16; x++) | |
820 code_counts[x] = 0; | |
821 | |
822 /* this is PAL8, so make the palette available */ | |
823 if (s->avctx->pix_fmt == PIX_FMT_PAL8) | |
824 memcpy(s->current_frame.data[1], s->palette, PALETTE_COUNT * 4); | |
825 | |
826 switch (s->avctx->pix_fmt) { | |
827 | |
828 case PIX_FMT_PAL8: | |
829 sg_stride = s->current_frame.linesize[0]; | |
830 sg_stream_ptr = s->buf + 14; /* data starts 14 bytes in */ | |
831 sg_stream_end = s->buf + s->size; | |
832 sg_line_inc = sg_stride - 8; | |
833 sg_current_plane = s->current_frame.data[0]; | |
834 sg_last_plane = s->last_frame.data[0]; | |
835 sg_upper_motion_limit_offset = (s->avctx->height - 8) * sg_stride | |
836 + s->avctx->width - 8; | |
837 sg_dsp = s->dsp; | |
838 | |
839 for (y = 0; y < (sg_stride * s->avctx->height); y += sg_stride * 8) { | |
840 for (x = y; x < y + s->avctx->width; x += 8) { | |
841 /* bottom nibble first, then top nibble (which makes it | |
842 * hard to use a GetBitcontext) */ | |
843 if (index & 1) | |
844 opcode = s->decoding_map[index >> 1] >> 4; | |
845 else | |
846 opcode = s->decoding_map[index >> 1] & 0xF; | |
847 index++; | |
848 | |
849 debug_interplay(" block @ (%3d, %3d): encoding 0x%X, data ptr @ %p\n", | |
850 x - y, y / sg_stride, opcode, sg_stream_ptr); | |
851 code_counts[opcode]++; | |
852 | |
853 sg_output_plane = sg_current_plane + x; | |
854 ret = ipvideo_decode_block[opcode](); | |
855 if (ret != 0) { | |
856 printf(" Interplay video: decode problem on frame %d, @ block (%d, %d)\n", | |
857 frame, x - y, y / sg_stride); | |
858 return; | |
859 } | |
860 } | |
861 } | |
862 if ((sg_stream_ptr != sg_stream_end) && | |
863 (sg_stream_ptr + 1 != sg_stream_end)) { | |
864 printf (" Interplay video: decode finished with %d bytes left over\n", | |
865 sg_stream_end - sg_stream_ptr); | |
866 } | |
867 break; | |
868 | |
869 default: | |
870 printf ("Interplay video: Unhandled video format\n"); | |
871 break; | |
872 } | |
873 | |
874 } | |
875 | |
1439
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
876 static int ipvideo_decode_init(AVCodecContext *avctx) |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
877 { |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
878 IpvideoContext *s = avctx->priv_data; |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
879 |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
880 s->avctx = avctx; |
1468 | 881 |
882 if (s->avctx->extradata_size != sizeof(AVPaletteControl)) { | |
883 printf (" Interplay video: expected extradata_size of %d\n", | |
884 sizeof(AVPaletteControl)); | |
885 return -1; | |
886 } | |
887 | |
888 avctx->pix_fmt = PIX_FMT_PAL8; | |
1439
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
889 avctx->has_b_frames = 0; |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
890 dsputil_init(&s->dsp, avctx); |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
891 |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
892 s->first_frame = 1; |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
893 |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
894 /* 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
|
895 s->decoding_map_size = avctx->width * avctx->height / (8 * 8 * 2); |
1468 | 896 |
897 /* assign block decode functions */ | |
898 ipvideo_decode_block[0x0] = ipvideo_decode_block_opcode_0x0_0x1; | |
899 ipvideo_decode_block[0x1] = ipvideo_decode_block_opcode_0x0_0x1; | |
900 ipvideo_decode_block[0x2] = ipvideo_decode_block_opcode_0x2; | |
901 ipvideo_decode_block[0x3] = ipvideo_decode_block_opcode_0x3; | |
902 ipvideo_decode_block[0x4] = ipvideo_decode_block_opcode_0x4; | |
903 ipvideo_decode_block[0x5] = ipvideo_decode_block_opcode_0x5; | |
904 ipvideo_decode_block[0x6] = ipvideo_decode_block_opcode_0x6; | |
905 ipvideo_decode_block[0x7] = ipvideo_decode_block_opcode_0x7; | |
906 ipvideo_decode_block[0x8] = ipvideo_decode_block_opcode_0x8; | |
907 ipvideo_decode_block[0x9] = ipvideo_decode_block_opcode_0x9; | |
908 ipvideo_decode_block[0xA] = ipvideo_decode_block_opcode_0xA; | |
909 ipvideo_decode_block[0xB] = ipvideo_decode_block_opcode_0xB; | |
910 ipvideo_decode_block[0xC] = ipvideo_decode_block_opcode_0xC; | |
911 ipvideo_decode_block[0xD] = ipvideo_decode_block_opcode_0xD; | |
912 ipvideo_decode_block[0xE] = ipvideo_decode_block_opcode_0xE; | |
913 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
|
914 |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
915 return 0; |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
916 } |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
917 |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
918 static int ipvideo_decode_frame(AVCodecContext *avctx, |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
919 void *data, int *data_size, |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
920 uint8_t *buf, int buf_size) |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
921 { |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
922 IpvideoContext *s = avctx->priv_data; |
1468 | 923 AVPaletteControl *palette_control = (AVPaletteControl *)avctx->extradata; |
1439
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
924 |
1468 | 925 if (palette_control->palette_changed) { |
926 /* load the new palette and reset the palette control */ | |
927 ipvideo_new_palette(s, palette_control->palette); | |
928 palette_control->palette_changed = 0; | |
1439
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
929 } |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
930 |
1468 | 931 s->decoding_map = buf; |
932 s->buf = buf + s->decoding_map_size; | |
933 s->size = buf_size - s->decoding_map_size; | |
934 | |
935 if (avctx->get_buffer(avctx, &s->current_frame)) { | |
936 printf (" Interplay Video: get_buffer() failed\n"); | |
937 return -1; | |
938 } | |
939 | |
940 ipvideo_decode_opcodes(s); | |
941 | |
942 /* release the last frame if it is allocated */ | |
943 if (s->first_frame) | |
944 s->first_frame = 0; | |
945 else | |
946 avctx->release_buffer(avctx, &s->last_frame); | |
947 | |
948 /* shuffle frames */ | |
949 s->last_frame = s->current_frame; | |
950 | |
951 *data_size = sizeof(AVFrame); | |
952 *(AVFrame*)data = s->current_frame; | |
953 | |
954 /* report that the buffer was completely consumed */ | |
1439
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
955 return buf_size; |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
956 } |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
957 |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
958 static int ipvideo_decode_end(AVCodecContext *avctx) |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
959 { |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
960 IpvideoContext *s = avctx->priv_data; |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
961 |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
962 /* release the last frame */ |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
963 avctx->release_buffer(avctx, &s->last_frame); |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
964 |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
965 return 0; |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
966 } |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
967 |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
968 AVCodec interplay_video_decoder = { |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
969 "interplayvideo", |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
970 CODEC_TYPE_VIDEO, |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
971 CODEC_ID_INTERPLAY_VIDEO, |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
972 sizeof(IpvideoContext), |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
973 ipvideo_decode_init, |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
974 NULL, |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
975 ipvideo_decode_end, |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
976 ipvideo_decode_frame, |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
977 CODEC_CAP_DR1, |
a4d00b1f0271
initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff
changeset
|
978 }; |