2 * Interplay MVE Video Decoder
3 * Copyright (C) 2003 the ffmpeg project
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * @file interplayvideo.c
23 * Interplay MVE Video Decoder by Mike Melanson (melanson@pcisys.net)
24 * For more information about the Interplay MVE format, visit:
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.
29 * This decoder presently only supports a PAL8 output colorspace.
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.
45 #define PALETTE_COUNT 256
47 /* debugging support */
48 #define DEBUG_INTERPLAY 0
50 #define debug_interplay printf
52 static inline void debug_interplay(const char *format, ...) { }
55 typedef struct IpvideoContext {
57 AVCodecContext *avctx;
59 AVFrame second_last_frame;
61 AVFrame current_frame;
62 unsigned char *decoding_map;
63 int decoding_map_size;
68 unsigned char *stream_ptr;
69 unsigned char *stream_end;
70 unsigned char *pixel_ptr;
73 int upper_motion_limit_offset;
77 #define CHECK_STREAM_PTR(n) \
78 if ((s->stream_ptr + n) > s->stream_end) { \
79 av_log(s->avctx, AV_LOG_ERROR, "Interplay video warning: stream_ptr out of bounds (%p >= %p)\n", \
80 s->stream_ptr + n, s->stream_end); \
84 #define COPY_FROM_CURRENT() \
85 motion_offset = current_offset; \
86 motion_offset += y * s->stride; \
88 if (motion_offset < 0) { \
89 av_log(s->avctx, AV_LOG_ERROR, " Interplay video: motion offset < 0 (%d)\n", motion_offset); \
91 } else if (motion_offset > s->upper_motion_limit_offset) { \
92 av_log(s->avctx, AV_LOG_ERROR, " Interplay video: motion offset above limit (%d >= %d)\n", \
93 motion_offset, s->upper_motion_limit_offset); \
96 s->dsp.put_pixels_tab[0][0](s->pixel_ptr, \
97 s->current_frame.data[0] + motion_offset, s->stride, 8);
99 #define COPY_FROM_PREVIOUS() \
100 motion_offset = current_offset; \
101 motion_offset += y * s->stride; \
102 motion_offset += x; \
103 if (motion_offset < 0) { \
104 av_log(s->avctx, AV_LOG_ERROR, " Interplay video: motion offset < 0 (%d)\n", motion_offset); \
106 } else if (motion_offset > s->upper_motion_limit_offset) { \
107 av_log(s->avctx, AV_LOG_ERROR, " Interplay video: motion offset above limit (%d >= %d)\n", \
108 motion_offset, s->upper_motion_limit_offset); \
111 s->dsp.put_pixels_tab[0][0](s->pixel_ptr, \
112 s->last_frame.data[0] + motion_offset, s->stride, 8);
114 #define COPY_FROM_SECOND_LAST() \
115 motion_offset = current_offset; \
116 motion_offset += y * s->stride; \
117 motion_offset += x; \
118 if (motion_offset < 0) { \
119 av_log(s->avctx, AV_LOG_ERROR, " Interplay video: motion offset < 0 (%d)\n", motion_offset); \
121 } else if (motion_offset > s->upper_motion_limit_offset) { \
122 av_log(s->avctx, AV_LOG_ERROR, " Interplay video: motion offset above limit (%d >= %d)\n", \
123 motion_offset, s->upper_motion_limit_offset); \
126 s->dsp.put_pixels_tab[0][0](s->pixel_ptr, \
127 s->second_last_frame.data[0] + motion_offset, s->stride, 8);
129 static int ipvideo_decode_block_opcode_0x0(IpvideoContext *s)
133 int current_offset = s->pixel_ptr - s->current_frame.data[0];
135 /* copy a block from the previous frame */
137 COPY_FROM_PREVIOUS();
143 static int ipvideo_decode_block_opcode_0x1(IpvideoContext *s)
147 int current_offset = s->pixel_ptr - s->current_frame.data[0];
149 /* copy block from 2 frames ago */
151 COPY_FROM_SECOND_LAST();
157 static int ipvideo_decode_block_opcode_0x2(IpvideoContext *s)
162 int current_offset = s->pixel_ptr - s->current_frame.data[0];
164 /* copy block from 2 frames ago using a motion vector; need 1 more byte */
166 B = *s->stream_ptr++;
172 x = -14 + ((B - 56) % 29);
173 y = 8 + ((B - 56) / 29);
176 debug_interplay (" motion byte = %d, (x, y) = (%d, %d)\n", B, x, y);
177 COPY_FROM_SECOND_LAST();
183 static int ipvideo_decode_block_opcode_0x3(IpvideoContext *s)
188 int current_offset = s->pixel_ptr - s->current_frame.data[0];
190 /* copy 8x8 block from current frame from an up/left block */
192 /* need 1 more byte for motion */
194 B = *s->stream_ptr++;
200 x = -(-14 + ((B - 56) % 29));
201 y = -( 8 + ((B - 56) / 29));
204 debug_interplay (" motion byte = %d, (x, y) = (%d, %d)\n", B, x, y);
211 static int ipvideo_decode_block_opcode_0x4(IpvideoContext *s)
214 unsigned char B, BL, BH;
216 int current_offset = s->pixel_ptr - s->current_frame.data[0];
218 /* copy a block from the previous frame; need 1 more byte */
221 B = *s->stream_ptr++;
223 BH = (B >> 4) & 0x0F;
227 debug_interplay (" motion byte = %d, (x, y) = (%d, %d)\n", B, x, y);
228 COPY_FROM_PREVIOUS();
234 static int ipvideo_decode_block_opcode_0x5(IpvideoContext *s)
238 int current_offset = s->pixel_ptr - s->current_frame.data[0];
240 /* copy a block from the previous frame using an expanded range;
241 * need 2 more bytes */
244 x = *s->stream_ptr++;
245 y = *s->stream_ptr++;
247 debug_interplay (" motion bytes = %d, %d\n", x, y);
248 COPY_FROM_PREVIOUS();
254 static int ipvideo_decode_block_opcode_0x6(IpvideoContext *s)
256 /* mystery opcode? skip multiple blocks? */
257 av_log(s->avctx, AV_LOG_ERROR, " Interplay video: Help! Mystery opcode 0x6 seen\n");
263 static int ipvideo_decode_block_opcode_0x7(IpvideoContext *s)
266 unsigned char P0, P1;
271 /* 2-color encoding */
274 P0 = *s->stream_ptr++;
275 P1 = *s->stream_ptr++;
279 /* need 8 more bytes from the stream */
281 for (y = 0; y < 8; y++)
282 B[y] = *s->stream_ptr++;
284 for (y = 0; y < 8; y++) {
286 for (x = 0x01; x <= 0x80; x <<= 1) {
288 *s->pixel_ptr++ = P1;
290 *s->pixel_ptr++ = P0;
292 s->pixel_ptr += s->line_inc;
297 /* need 2 more bytes from the stream */
299 B[0] = *s->stream_ptr++;
300 B[1] = *s->stream_ptr++;
302 flags = (B[1] << 8) | B[0];
304 for (y = 0; y < 8; y += 2) {
305 for (x = 0; x < 8; x += 2, bitmask <<= 1) {
306 if (flags & bitmask) {
307 *(s->pixel_ptr + x) = P1;
308 *(s->pixel_ptr + x + 1) = P1;
309 *(s->pixel_ptr + s->stride + x) = P1;
310 *(s->pixel_ptr + s->stride + x + 1) = P1;
312 *(s->pixel_ptr + x) = P0;
313 *(s->pixel_ptr + x + 1) = P0;
314 *(s->pixel_ptr + s->stride + x) = P0;
315 *(s->pixel_ptr + s->stride + x + 1) = P0;
318 s->pixel_ptr += s->stride * 2;
326 static int ipvideo_decode_block_opcode_0x8(IpvideoContext *s)
331 unsigned int flags = 0;
332 unsigned int bitmask = 0;
333 unsigned char P0 = 0, P1 = 0;
336 /* 2-color encoding for each 4x4 quadrant, or 2-color encoding on
337 * either top and bottom or left and right halves */
340 P[0] = *s->stream_ptr++;
341 P[1] = *s->stream_ptr++;
345 /* need 12 more bytes */
346 CHECK_STREAM_PTR(12);
347 B[0] = *s->stream_ptr++; B[1] = *s->stream_ptr++;
348 P[2] = *s->stream_ptr++; P[3] = *s->stream_ptr++;
349 B[2] = *s->stream_ptr++; B[3] = *s->stream_ptr++;
350 P[4] = *s->stream_ptr++; P[5] = *s->stream_ptr++;
351 B[4] = *s->stream_ptr++; B[5] = *s->stream_ptr++;
352 P[6] = *s->stream_ptr++; P[7] = *s->stream_ptr++;
353 B[6] = *s->stream_ptr++; B[7] = *s->stream_ptr++;
355 for (y = 0; y < 8; y++) {
357 /* time to reload flags? */
360 ((B[0] & 0xF0) << 4) | ((B[4] & 0xF0) << 8) |
361 ((B[0] & 0x0F) ) | ((B[4] & 0x0F) << 4) |
362 ((B[1] & 0xF0) << 20) | ((B[5] & 0xF0) << 24) |
363 ((B[1] & 0x0F) << 16) | ((B[5] & 0x0F) << 20);
364 bitmask = 0x00000001;
365 lower_half = 0; /* still on top half */
368 ((B[2] & 0xF0) << 4) | ((B[6] & 0xF0) << 8) |
369 ((B[2] & 0x0F) ) | ((B[6] & 0x0F) << 4) |
370 ((B[3] & 0xF0) << 20) | ((B[7] & 0xF0) << 24) |
371 ((B[3] & 0x0F) << 16) | ((B[7] & 0x0F) << 20);
372 bitmask = 0x00000001;
376 for (x = 0; x < 8; x++, bitmask <<= 1) {
377 /* get the pixel values ready for this quadrant */
379 P0 = P[lower_half + 0];
380 P1 = P[lower_half + 1];
382 P0 = P[lower_half + 4];
383 P1 = P[lower_half + 5];
387 *s->pixel_ptr++ = P1;
389 *s->pixel_ptr++ = P0;
391 s->pixel_ptr += s->line_inc;
396 /* need 10 more bytes */
397 CHECK_STREAM_PTR(10);
398 B[0] = *s->stream_ptr++; B[1] = *s->stream_ptr++;
399 B[2] = *s->stream_ptr++; B[3] = *s->stream_ptr++;
400 P[2] = *s->stream_ptr++; P[3] = *s->stream_ptr++;
401 B[4] = *s->stream_ptr++; B[5] = *s->stream_ptr++;
402 B[6] = *s->stream_ptr++; B[7] = *s->stream_ptr++;
406 /* vertical split; left & right halves are 2-color encoded */
408 for (y = 0; y < 8; y++) {
410 /* time to reload flags? */
413 ((B[0] & 0xF0) << 4) | ((B[4] & 0xF0) << 8) |
414 ((B[0] & 0x0F) ) | ((B[4] & 0x0F) << 4) |
415 ((B[1] & 0xF0) << 20) | ((B[5] & 0xF0) << 24) |
416 ((B[1] & 0x0F) << 16) | ((B[5] & 0x0F) << 20);
417 bitmask = 0x00000001;
420 ((B[2] & 0xF0) << 4) | ((B[6] & 0xF0) << 8) |
421 ((B[2] & 0x0F) ) | ((B[6] & 0x0F) << 4) |
422 ((B[3] & 0xF0) << 20) | ((B[7] & 0xF0) << 24) |
423 ((B[3] & 0x0F) << 16) | ((B[7] & 0x0F) << 20);
424 bitmask = 0x00000001;
427 for (x = 0; x < 8; x++, bitmask <<= 1) {
428 /* get the pixel values ready for this half */
438 *s->pixel_ptr++ = P1;
440 *s->pixel_ptr++ = P0;
442 s->pixel_ptr += s->line_inc;
447 /* horizontal split; top & bottom halves are 2-color encoded */
449 for (y = 0; y < 8; y++) {
460 for (bitmask = 0x01; bitmask <= 0x80; bitmask <<= 1) {
463 *s->pixel_ptr++ = P1;
465 *s->pixel_ptr++ = P0;
467 s->pixel_ptr += s->line_inc;
476 static int ipvideo_decode_block_opcode_0x9(IpvideoContext *s)
481 unsigned int flags = 0;
485 /* 4-color encoding */
488 for (y = 0; y < 4; y++)
489 P[y] = *s->stream_ptr++;
491 if ((P[0] <= P[1]) && (P[2] <= P[3])) {
493 /* 1 of 4 colors for each pixel, need 16 more bytes */
494 CHECK_STREAM_PTR(16);
496 for (y = 0; y < 8; y++) {
497 /* get the next set of 8 2-bit flags */
498 flags = (s->stream_ptr[1] << 8) | s->stream_ptr[0];
500 for (x = 0, shifter = 0; x < 8; x++, shifter += 2) {
501 *s->pixel_ptr++ = P[(flags >> shifter) & 0x03];
503 s->pixel_ptr += s->line_inc;
506 } else if ((P[0] <= P[1]) && (P[2] > P[3])) {
508 /* 1 of 4 colors for each 2x2 block, need 4 more bytes */
511 B[0] = *s->stream_ptr++;
512 B[1] = *s->stream_ptr++;
513 B[2] = *s->stream_ptr++;
514 B[3] = *s->stream_ptr++;
515 flags = (B[3] << 24) | (B[2] << 16) | (B[1] << 8) | B[0];
518 for (y = 0; y < 8; y += 2) {
519 for (x = 0; x < 8; x += 2, shifter += 2) {
520 pix = P[(flags >> shifter) & 0x03];
521 *(s->pixel_ptr + x) = pix;
522 *(s->pixel_ptr + x + 1) = pix;
523 *(s->pixel_ptr + s->stride + x) = pix;
524 *(s->pixel_ptr + s->stride + x + 1) = pix;
526 s->pixel_ptr += s->stride * 2;
529 } else if ((P[0] > P[1]) && (P[2] <= P[3])) {
531 /* 1 of 4 colors for each 2x1 block, need 8 more bytes */
534 for (y = 0; y < 8; y++) {
535 /* time to reload flags? */
536 if ((y == 0) || (y == 4)) {
537 B[0] = *s->stream_ptr++;
538 B[1] = *s->stream_ptr++;
539 B[2] = *s->stream_ptr++;
540 B[3] = *s->stream_ptr++;
541 flags = (B[3] << 24) | (B[2] << 16) | (B[1] << 8) | B[0];
544 for (x = 0; x < 8; x += 2, shifter += 2) {
545 pix = P[(flags >> shifter) & 0x03];
546 *(s->pixel_ptr + x) = pix;
547 *(s->pixel_ptr + x + 1) = pix;
549 s->pixel_ptr += s->stride;
554 /* 1 of 4 colors for each 1x2 block, need 8 more bytes */
557 for (y = 0; y < 8; y += 2) {
558 /* time to reload flags? */
559 if ((y == 0) || (y == 4)) {
560 B[0] = *s->stream_ptr++;
561 B[1] = *s->stream_ptr++;
562 B[2] = *s->stream_ptr++;
563 B[3] = *s->stream_ptr++;
564 flags = (B[3] << 24) | (B[2] << 16) | (B[1] << 8) | B[0];
567 for (x = 0; x < 8; x++, shifter += 2) {
568 pix = P[(flags >> shifter) & 0x03];
569 *(s->pixel_ptr + x) = pix;
570 *(s->pixel_ptr + s->stride + x) = pix;
572 s->pixel_ptr += s->stride * 2;
580 static int ipvideo_decode_block_opcode_0xA(IpvideoContext *s)
591 /* 4-color encoding for each 4x4 quadrant, or 4-color encoding on
592 * either top and bottom or left and right halves */
595 for (y = 0; y < 4; y++)
596 P[y] = *s->stream_ptr++;
600 /* 4-color encoding for each quadrant; need 28 more bytes */
601 CHECK_STREAM_PTR(28);
603 for (y = 0; y < 4; y++)
604 B[y] = *s->stream_ptr++;
605 for (y = 4; y < 16; y += 4) {
606 for (x = y; x < y + 4; x++)
607 P[x] = *s->stream_ptr++;
608 for (x = y; x < y + 4; x++)
609 B[x] = *s->stream_ptr++;
612 for (y = 0; y < 8; y++) {
614 lower_half = (y >= 4) ? 4 : 0;
615 flags = (B[y + 8] << 8) | B[y];
617 for (x = 0, shifter = 0; x < 8; x++, shifter += 2) {
618 split = (x >= 4) ? 8 : 0;
619 index = split + lower_half + ((flags >> shifter) & 0x03);
620 *s->pixel_ptr++ = P[index];
623 s->pixel_ptr += s->line_inc;
628 /* 4-color encoding for either left and right or top and bottom
629 * halves; need 20 more bytes */
630 CHECK_STREAM_PTR(20);
632 for (y = 0; y < 8; y++)
633 B[y] = *s->stream_ptr++;
634 for (y = 4; y < 8; y++)
635 P[y] = *s->stream_ptr++;
636 for (y = 8; y < 16; y++)
637 B[y] = *s->stream_ptr++;
641 /* block is divided into left and right halves */
642 for (y = 0; y < 8; y++) {
644 flags = (B[y + 8] << 8) | B[y];
647 for (x = 0, shifter = 0; x < 8; x++, shifter += 2) {
650 *s->pixel_ptr++ = P[split + ((flags >> shifter) & 0x03)];
653 s->pixel_ptr += s->line_inc;
658 /* block is divided into top and bottom halves */
660 for (y = 0; y < 8; y++) {
662 flags = (B[y * 2 + 1] << 8) | B[y * 2];
666 for (x = 0, shifter = 0; x < 8; x++, shifter += 2)
667 *s->pixel_ptr++ = P[split + ((flags >> shifter) & 0x03)];
669 s->pixel_ptr += s->line_inc;
678 static int ipvideo_decode_block_opcode_0xB(IpvideoContext *s)
682 /* 64-color encoding (each pixel in block is a different color) */
683 CHECK_STREAM_PTR(64);
685 for (y = 0; y < 8; y++) {
686 for (x = 0; x < 8; x++) {
687 *s->pixel_ptr++ = *s->stream_ptr++;
689 s->pixel_ptr += s->line_inc;
696 static int ipvideo_decode_block_opcode_0xC(IpvideoContext *s)
701 /* 16-color block encoding: each 2x2 block is a different color */
702 CHECK_STREAM_PTR(16);
704 for (y = 0; y < 8; y += 2) {
705 for (x = 0; x < 8; x += 2) {
706 pix = *s->stream_ptr++;
707 *(s->pixel_ptr + x) = pix;
708 *(s->pixel_ptr + x + 1) = pix;
709 *(s->pixel_ptr + s->stride + x) = pix;
710 *(s->pixel_ptr + s->stride + x + 1) = pix;
712 s->pixel_ptr += s->stride * 2;
719 static int ipvideo_decode_block_opcode_0xD(IpvideoContext *s)
723 unsigned char index = 0;
725 /* 4-color block encoding: each 4x4 block is a different color */
728 for (y = 0; y < 4; y++)
729 P[y] = *s->stream_ptr++;
731 for (y = 0; y < 8; y++) {
737 for (x = 0; x < 8; x++) {
740 *s->pixel_ptr++ = P[index];
742 s->pixel_ptr += s->line_inc;
749 static int ipvideo_decode_block_opcode_0xE(IpvideoContext *s)
754 /* 1-color encoding: the whole block is 1 solid color */
756 pix = *s->stream_ptr++;
758 for (y = 0; y < 8; y++) {
759 for (x = 0; x < 8; x++) {
760 *s->pixel_ptr++ = pix;
762 s->pixel_ptr += s->line_inc;
769 static int ipvideo_decode_block_opcode_0xF(IpvideoContext *s)
772 unsigned char sample0, sample1;
774 /* dithered encoding */
776 sample0 = *s->stream_ptr++;
777 sample1 = *s->stream_ptr++;
779 for (y = 0; y < 8; y++) {
780 for (x = 0; x < 8; x += 2) {
782 *s->pixel_ptr++ = sample1;
783 *s->pixel_ptr++ = sample0;
785 *s->pixel_ptr++ = sample0;
786 *s->pixel_ptr++ = sample1;
789 s->pixel_ptr += s->line_inc;
796 static int (*ipvideo_decode_block[16])(IpvideoContext *s);
798 static void ipvideo_decode_opcodes(IpvideoContext *s)
802 unsigned char opcode;
805 static int frame = 0;
807 debug_interplay("------------------ frame %d\n", frame);
810 for (x = 0; x < 16; x++)
813 /* this is PAL8, so make the palette available */
814 memcpy(s->current_frame.data[1], s->avctx->palctrl->palette, PALETTE_COUNT * 4);
816 s->stride = s->current_frame.linesize[0];
817 s->stream_ptr = s->buf + 14; /* data starts 14 bytes in */
818 s->stream_end = s->buf + s->size;
819 s->line_inc = s->stride - 8;
820 s->upper_motion_limit_offset = (s->avctx->height - 8) * s->stride
821 + s->avctx->width - 8;
824 for (y = 0; y < (s->stride * s->avctx->height); y += s->stride * 8) {
825 for (x = y; x < y + s->avctx->width; x += 8) {
826 /* bottom nibble first, then top nibble (which makes it
827 * hard to use a GetBitcontext) */
829 opcode = s->decoding_map[index >> 1] >> 4;
831 opcode = s->decoding_map[index >> 1] & 0xF;
834 debug_interplay(" block @ (%3d, %3d): encoding 0x%X, data ptr @ %p\n",
835 x - y, y / s->stride, opcode, s->stream_ptr);
836 code_counts[opcode]++;
838 s->pixel_ptr = s->current_frame.data[0] + x;
839 ret = ipvideo_decode_block[opcode](s);
841 av_log(s->avctx, AV_LOG_ERROR, " Interplay video: decode problem on frame %d, @ block (%d, %d)\n",
842 frame, x - y, y / s->stride);
847 if ((s->stream_ptr != s->stream_end) &&
848 (s->stream_ptr + 1 != s->stream_end)) {
849 av_log(s->avctx, AV_LOG_ERROR, " Interplay video: decode finished with %d bytes left over\n",
850 s->stream_end - s->stream_ptr);
854 static int ipvideo_decode_init(AVCodecContext *avctx)
856 IpvideoContext *s = avctx->priv_data;
860 if (s->avctx->palctrl == NULL) {
861 av_log(avctx, AV_LOG_ERROR, " Interplay video: palette expected.\n");
865 avctx->pix_fmt = PIX_FMT_PAL8;
866 avctx->has_b_frames = 0;
867 dsputil_init(&s->dsp, avctx);
869 /* decoding map contains 4 bits of information per 8x8 block */
870 s->decoding_map_size = avctx->width * avctx->height / (8 * 8 * 2);
872 /* assign block decode functions */
873 ipvideo_decode_block[0x0] = ipvideo_decode_block_opcode_0x0;
874 ipvideo_decode_block[0x1] = ipvideo_decode_block_opcode_0x1;
875 ipvideo_decode_block[0x2] = ipvideo_decode_block_opcode_0x2;
876 ipvideo_decode_block[0x3] = ipvideo_decode_block_opcode_0x3;
877 ipvideo_decode_block[0x4] = ipvideo_decode_block_opcode_0x4;
878 ipvideo_decode_block[0x5] = ipvideo_decode_block_opcode_0x5;
879 ipvideo_decode_block[0x6] = ipvideo_decode_block_opcode_0x6;
880 ipvideo_decode_block[0x7] = ipvideo_decode_block_opcode_0x7;
881 ipvideo_decode_block[0x8] = ipvideo_decode_block_opcode_0x8;
882 ipvideo_decode_block[0x9] = ipvideo_decode_block_opcode_0x9;
883 ipvideo_decode_block[0xA] = ipvideo_decode_block_opcode_0xA;
884 ipvideo_decode_block[0xB] = ipvideo_decode_block_opcode_0xB;
885 ipvideo_decode_block[0xC] = ipvideo_decode_block_opcode_0xC;
886 ipvideo_decode_block[0xD] = ipvideo_decode_block_opcode_0xD;
887 ipvideo_decode_block[0xE] = ipvideo_decode_block_opcode_0xE;
888 ipvideo_decode_block[0xF] = ipvideo_decode_block_opcode_0xF;
890 s->current_frame.data[0] = s->last_frame.data[0] =
891 s->second_last_frame.data[0] = NULL;
896 static int ipvideo_decode_frame(AVCodecContext *avctx,
897 void *data, int *data_size,
898 uint8_t *buf, int buf_size)
900 IpvideoContext *s = avctx->priv_data;
901 AVPaletteControl *palette_control = avctx->palctrl;
903 /* compressed buffer needs to be large enough to at least hold an entire
905 if (buf_size < s->decoding_map_size)
908 s->decoding_map = buf;
909 s->buf = buf + s->decoding_map_size;
910 s->size = buf_size - s->decoding_map_size;
912 s->current_frame.reference = 3;
913 if (avctx->get_buffer(avctx, &s->current_frame)) {
914 av_log(avctx, AV_LOG_ERROR, " Interplay Video: get_buffer() failed\n");
918 ipvideo_decode_opcodes(s);
920 if (palette_control->palette_changed) {
921 palette_control->palette_changed = 0;
922 s->current_frame.palette_has_changed = 1;
925 *data_size = sizeof(AVFrame);
926 *(AVFrame*)data = s->current_frame;
929 if (s->second_last_frame.data[0])
930 avctx->release_buffer(avctx, &s->second_last_frame);
931 s->second_last_frame = s->last_frame;
932 s->last_frame = s->current_frame;
933 s->current_frame.data[0] = NULL; /* catch any access attempts */
935 /* report that the buffer was completely consumed */
939 static int ipvideo_decode_end(AVCodecContext *avctx)
941 IpvideoContext *s = avctx->priv_data;
943 /* release the last frame */
944 if (s->last_frame.data[0])
945 avctx->release_buffer(avctx, &s->last_frame);
946 if (s->second_last_frame.data[0])
947 avctx->release_buffer(avctx, &s->second_last_frame);
952 AVCodec interplay_video_decoder = {
955 CODEC_ID_INTERPLAY_VIDEO,
956 sizeof(IpvideoContext),
960 ipvideo_decode_frame,