Mercurial > libavcodec.hg
annotate msvideo1.c @ 1625:c910ff78ef80 libavcodec
av_d2q() documentation
author | michael |
---|---|
date | Sun, 16 Nov 2003 19:23:39 +0000 |
parents | 9ef0d51e809b |
children | 586b5c08863c |
rev | line source |
---|---|
1491
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
1 /* |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
2 * Microsoft Video-1 Decoder |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
3 * Copyright (C) 2003 the ffmpeg project |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
4 * |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
5 * This library is free software; you can redistribute it and/or |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
6 * modify it under the terms of the GNU Lesser General Public |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
7 * License as published by the Free Software Foundation; either |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
8 * version 2 of the License, or (at your option) any later version. |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
9 * |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
10 * This library is distributed in the hope that it will be useful, |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
13 * Lesser General Public License for more details. |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
14 * |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
15 * You should have received a copy of the GNU Lesser General Public |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
16 * License along with this library; if not, write to the Free Software |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
18 * |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
19 */ |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
20 |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
21 /** |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
22 * @file msvideo1.c |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
23 * Microsoft Video-1 Decoder by Mike Melanson (melanson@pcisys.net) |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
24 * For more information about the MS Video-1 format, visit: |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
25 * http://www.pcisys.net/~melanson/codecs/ |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
26 * |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
27 * This decoder outputs either PAL8 or RGB555 data, depending on the |
1595 | 28 * whether a RGB palette was passed through palctrl; |
29 * if it's present, then the data is PAL8; RGB555 otherwise. | |
1491
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
30 */ |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
31 |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
32 #include <stdio.h> |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
33 #include <stdlib.h> |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
34 #include <string.h> |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
35 #include <unistd.h> |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
36 |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
37 #include "common.h" |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
38 #include "avcodec.h" |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
39 #include "dsputil.h" |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
40 |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
41 #define PALETTE_COUNT 256 |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
42 #define LE_16(x) ((((uint8_t*)(x))[1] << 8) | ((uint8_t*)(x))[0]) |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
43 #define CHECK_STREAM_PTR(n) \ |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
44 if ((stream_ptr + n) > s->size ) { \ |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1595
diff
changeset
|
45 av_log(s->avctx, AV_LOG_ERROR, " MS Video-1 warning: stream_ptr out of bounds (%d >= %d)\n", \ |
1491
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
46 stream_ptr + n, s->size); \ |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
47 return; \ |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
48 } |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
49 |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
50 #define COPY_PREV_BLOCK() \ |
1607 | 51 if (!s->avctx->cr_available) {\ |
1491
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
52 pixel_ptr = block_ptr; \ |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
53 for (pixel_y = 0; pixel_y < 4; pixel_y++) { \ |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
54 for (pixel_x = 0; pixel_x < 4; pixel_x++, pixel_ptr++) \ |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
55 pixels[pixel_ptr] = prev_pixels[pixel_ptr]; \ |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
56 pixel_ptr -= row_dec; \ |
1607 | 57 } \ |
58 } | |
1491
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
59 |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
60 typedef struct Msvideo1Context { |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
61 |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
62 AVCodecContext *avctx; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
63 DSPContext dsp; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
64 AVFrame frame; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
65 AVFrame prev_frame; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
66 |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
67 unsigned char *buf; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
68 int size; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
69 |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
70 int mode_8bit; /* if it's not 8-bit, it's 16-bit */ |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
71 |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
72 } Msvideo1Context; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
73 |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
74 static int msvideo1_decode_init(AVCodecContext *avctx) |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
75 { |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
76 Msvideo1Context *s = (Msvideo1Context *)avctx->priv_data; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
77 |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
78 s->avctx = avctx; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
79 |
1595 | 80 /* figure out the colorspace based on the presence of a palette */ |
81 if (s->avctx->palctrl) { | |
1491
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
82 s->mode_8bit = 1; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
83 avctx->pix_fmt = PIX_FMT_PAL8; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
84 } else { |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
85 s->mode_8bit = 0; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
86 avctx->pix_fmt = PIX_FMT_RGB555; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
87 } |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
88 |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
89 avctx->has_b_frames = 0; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
90 dsputil_init(&s->dsp, avctx); |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
91 |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
92 s->frame.data[0] = s->prev_frame.data[0] = NULL; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
93 |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
94 return 0; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
95 } |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
96 |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
97 static void msvideo1_decode_8bit(Msvideo1Context *s) |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
98 { |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
99 int block_ptr, pixel_ptr; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
100 int total_blocks; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
101 int pixel_x, pixel_y; /* pixel width and height iterators */ |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
102 int block_x, block_y; /* block width and height iterators */ |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
103 int blocks_wide, blocks_high; /* width and height in 4x4 blocks */ |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
104 int block_inc; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
105 int row_dec; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
106 |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
107 /* decoding parameters */ |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
108 int stream_ptr; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
109 unsigned char byte_a, byte_b; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
110 unsigned short flags; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
111 int skip_blocks; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
112 unsigned char colors[8]; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
113 unsigned char *pixels = s->frame.data[0]; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
114 unsigned char *prev_pixels = s->prev_frame.data[0]; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
115 int stride = s->frame.linesize[0]; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
116 |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
117 stream_ptr = 0; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
118 skip_blocks = 0; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
119 blocks_wide = s->avctx->width / 4; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
120 blocks_high = s->avctx->height / 4; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
121 total_blocks = blocks_wide * blocks_high; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
122 block_inc = 4; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
123 row_dec = stride + 4; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
124 |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
125 for (block_y = blocks_high; block_y > 0; block_y--) { |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
126 block_ptr = ((block_y * 4) - 1) * stride; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
127 for (block_x = blocks_wide; block_x > 0; block_x--) { |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
128 /* check if this block should be skipped */ |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
129 if (skip_blocks) { |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
130 COPY_PREV_BLOCK(); |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
131 block_ptr += block_inc; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
132 skip_blocks--; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
133 total_blocks--; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
134 continue; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
135 } |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
136 |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
137 pixel_ptr = block_ptr; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
138 |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
139 /* get the next two bytes in the encoded data stream */ |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
140 CHECK_STREAM_PTR(2); |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
141 byte_a = s->buf[stream_ptr++]; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
142 byte_b = s->buf[stream_ptr++]; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
143 |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
144 /* check if the decode is finished */ |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
145 if ((byte_a == 0) && (byte_b == 0) && (total_blocks == 0)) |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
146 return; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
147 else if ((byte_b & 0xFC) == 0x84) { |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
148 /* skip code, but don't count the current block */ |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
149 skip_blocks = ((byte_b - 0x84) << 8) + byte_a - 1; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
150 COPY_PREV_BLOCK(); |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
151 } else if (byte_b < 0x80) { |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
152 /* 2-color encoding */ |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
153 flags = (byte_b << 8) | byte_a; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
154 |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
155 CHECK_STREAM_PTR(2); |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
156 colors[0] = s->buf[stream_ptr++]; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
157 colors[1] = s->buf[stream_ptr++]; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
158 |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
159 for (pixel_y = 0; pixel_y < 4; pixel_y++) { |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
160 for (pixel_x = 0; pixel_x < 4; pixel_x++, flags >>= 1) |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
161 pixels[pixel_ptr++] = colors[(flags & 0x1) ^ 1]; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
162 pixel_ptr -= row_dec; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
163 } |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
164 } else if (byte_b >= 0x90) { |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
165 /* 8-color encoding */ |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
166 flags = (byte_b << 8) | byte_a; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
167 |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
168 CHECK_STREAM_PTR(8); |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
169 memcpy(colors, &s->buf[stream_ptr], 8); |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
170 stream_ptr += 8; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
171 |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
172 for (pixel_y = 0; pixel_y < 4; pixel_y++) { |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
173 for (pixel_x = 0; pixel_x < 4; pixel_x++, flags >>= 1) |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
174 pixels[pixel_ptr++] = |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
175 colors[((pixel_y & 0x2) << 1) + |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
176 (pixel_x & 0x2) + ((flags & 0x1) ^ 1)]; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
177 pixel_ptr -= row_dec; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
178 } |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
179 } else { |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
180 /* 1-color encoding */ |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
181 colors[0] = byte_a; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
182 |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
183 for (pixel_y = 0; pixel_y < 4; pixel_y++) { |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
184 for (pixel_x = 0; pixel_x < 4; pixel_x++) |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
185 pixels[pixel_ptr++] = colors[0]; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
186 pixel_ptr -= row_dec; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
187 } |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
188 } |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
189 |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
190 block_ptr += block_inc; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
191 total_blocks--; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
192 } |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
193 } |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
194 |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
195 /* make the palette available on the way out */ |
1595 | 196 if (s->avctx->pix_fmt == PIX_FMT_PAL8) { |
197 memcpy(s->frame.data[1], s->avctx->palctrl->palette, AVPALETTE_SIZE); | |
198 if (s->avctx->palctrl->palette_changed) { | |
199 s->frame.palette_has_changed = 1; | |
200 s->avctx->palctrl->palette_changed = 0; | |
201 } | |
202 } | |
1491
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
203 } |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
204 |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
205 static void msvideo1_decode_16bit(Msvideo1Context *s) |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
206 { |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
207 int block_ptr, pixel_ptr; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
208 int total_blocks; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
209 int pixel_x, pixel_y; /* pixel width and height iterators */ |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
210 int block_x, block_y; /* block width and height iterators */ |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
211 int blocks_wide, blocks_high; /* width and height in 4x4 blocks */ |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
212 int block_inc; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
213 int row_dec; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
214 |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
215 /* decoding parameters */ |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
216 int stream_ptr; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
217 unsigned char byte_a, byte_b; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
218 unsigned short flags; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
219 int skip_blocks; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
220 unsigned short colors[8]; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
221 unsigned short *pixels = (unsigned short *)s->frame.data[0]; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
222 unsigned short *prev_pixels = (unsigned short *)s->prev_frame.data[0]; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
223 int stride = s->frame.linesize[0] / 2; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
224 |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
225 stream_ptr = 0; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
226 skip_blocks = 0; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
227 blocks_wide = s->avctx->width / 4; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
228 blocks_high = s->avctx->height / 4; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
229 total_blocks = blocks_wide * blocks_high; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
230 block_inc = 4; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
231 row_dec = stride + 4; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
232 |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
233 for (block_y = blocks_high; block_y > 0; block_y--) { |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
234 block_ptr = ((block_y * 4) - 1) * stride; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
235 for (block_x = blocks_wide; block_x > 0; block_x--) { |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
236 /* check if this block should be skipped */ |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
237 if (skip_blocks) { |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
238 COPY_PREV_BLOCK(); |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
239 block_ptr += block_inc; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
240 skip_blocks--; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
241 total_blocks--; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
242 continue; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
243 } |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
244 |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
245 pixel_ptr = block_ptr; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
246 |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
247 /* get the next two bytes in the encoded data stream */ |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
248 CHECK_STREAM_PTR(2); |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
249 byte_a = s->buf[stream_ptr++]; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
250 byte_b = s->buf[stream_ptr++]; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
251 |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
252 /* check if the decode is finished */ |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
253 if ((byte_a == 0) && (byte_b == 0) && (total_blocks == 0)) { |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
254 return; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
255 } else if ((byte_b & 0xFC) == 0x84) { |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
256 /* skip code, but don't count the current block */ |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
257 skip_blocks = ((byte_b - 0x84) << 8) + byte_a - 1; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
258 COPY_PREV_BLOCK(); |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
259 } else if (byte_b < 0x80) { |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
260 /* 2- or 8-color encoding modes */ |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
261 flags = (byte_b << 8) | byte_a; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
262 |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
263 CHECK_STREAM_PTR(4); |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
264 colors[0] = LE_16(&s->buf[stream_ptr]); |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
265 stream_ptr += 2; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
266 colors[1] = LE_16(&s->buf[stream_ptr]); |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
267 stream_ptr += 2; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
268 |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
269 if (colors[0] & 0x8000) { |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
270 /* 8-color encoding */ |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
271 CHECK_STREAM_PTR(12); |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
272 colors[2] = LE_16(&s->buf[stream_ptr]); |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
273 stream_ptr += 2; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
274 colors[3] = LE_16(&s->buf[stream_ptr]); |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
275 stream_ptr += 2; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
276 colors[4] = LE_16(&s->buf[stream_ptr]); |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
277 stream_ptr += 2; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
278 colors[5] = LE_16(&s->buf[stream_ptr]); |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
279 stream_ptr += 2; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
280 colors[6] = LE_16(&s->buf[stream_ptr]); |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
281 stream_ptr += 2; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
282 colors[7] = LE_16(&s->buf[stream_ptr]); |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
283 stream_ptr += 2; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
284 |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
285 for (pixel_y = 0; pixel_y < 4; pixel_y++) { |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
286 for (pixel_x = 0; pixel_x < 4; pixel_x++, flags >>= 1) |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
287 pixels[pixel_ptr++] = |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
288 colors[((pixel_y & 0x2) << 1) + |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
289 (pixel_x & 0x2) + ((flags & 0x1) ^ 1)]; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
290 pixel_ptr -= row_dec; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
291 } |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
292 } else { |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
293 /* 2-color encoding */ |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
294 for (pixel_y = 0; pixel_y < 4; pixel_y++) { |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
295 for (pixel_x = 0; pixel_x < 4; pixel_x++, flags >>= 1) |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
296 pixels[pixel_ptr++] = colors[(flags & 0x1) ^ 1]; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
297 pixel_ptr -= row_dec; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
298 } |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
299 } |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
300 } else { |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
301 /* otherwise, it's a 1-color block */ |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
302 colors[0] = (byte_b << 8) | byte_a; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
303 |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
304 for (pixel_y = 0; pixel_y < 4; pixel_y++) { |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
305 for (pixel_x = 0; pixel_x < 4; pixel_x++) |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
306 pixels[pixel_ptr++] = colors[0]; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
307 pixel_ptr -= row_dec; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
308 } |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
309 } |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
310 |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
311 block_ptr += block_inc; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
312 total_blocks--; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
313 } |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
314 } |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
315 } |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
316 |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
317 static int msvideo1_decode_frame(AVCodecContext *avctx, |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
318 void *data, int *data_size, |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
319 uint8_t *buf, int buf_size) |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
320 { |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
321 Msvideo1Context *s = (Msvideo1Context *)avctx->priv_data; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
322 |
1607 | 323 /* no supplementary picture */ |
324 if (buf_size == 0) | |
325 return 0; | |
326 | |
1491
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
327 s->buf = buf; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
328 s->size = buf_size; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
329 |
1607 | 330 s->frame.reference = 1; |
331 s->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE; | |
332 if (avctx->cr_available) | |
333 s->frame.buffer_hints |= FF_BUFFER_HINTS_REUSABLE; | |
334 else | |
335 s->frame.buffer_hints |= FF_BUFFER_HINTS_READABLE; | |
1491
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
336 if (avctx->get_buffer(avctx, &s->frame)) { |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1595
diff
changeset
|
337 av_log(s->avctx, AV_LOG_ERROR, " MS Video-1 Video: get_buffer() failed\n"); |
1491
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
338 return -1; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
339 } |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
340 |
1595 | 341 if (s->prev_frame.data[0] &&(s->frame.linesize[0] != s->prev_frame.linesize[0])) |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1595
diff
changeset
|
342 av_log(avctx, AV_LOG_ERROR, " MS Video-1: Buffer linesize changed: current %u, previous %u.\n" |
1595 | 343 " Expect wrong image and/or crash!\n", |
344 s->frame.linesize[0], s->prev_frame.linesize[0]); | |
345 | |
1491
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
346 if (s->mode_8bit) |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
347 msvideo1_decode_8bit(s); |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
348 else |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
349 msvideo1_decode_16bit(s); |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
350 |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
351 if (s->prev_frame.data[0]) |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
352 avctx->release_buffer(avctx, &s->prev_frame); |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
353 |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
354 /* shuffle frames */ |
1607 | 355 if (!avctx->cr_available) |
1491
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
356 s->prev_frame = s->frame; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
357 |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
358 *data_size = sizeof(AVFrame); |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
359 *(AVFrame*)data = s->frame; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
360 |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
361 /* report that the buffer was completely consumed */ |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
362 return buf_size; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
363 } |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
364 |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
365 static int msvideo1_decode_end(AVCodecContext *avctx) |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
366 { |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
367 Msvideo1Context *s = (Msvideo1Context *)avctx->priv_data; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
368 |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
369 if (s->prev_frame.data[0]) |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
370 avctx->release_buffer(avctx, &s->prev_frame); |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
371 |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
372 return 0; |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
373 } |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
374 |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
375 AVCodec msvideo1_decoder = { |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
376 "msvideo1", |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
377 CODEC_TYPE_VIDEO, |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
378 CODEC_ID_MSVIDEO1, |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
379 sizeof(Msvideo1Context), |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
380 msvideo1_decode_init, |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
381 NULL, |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
382 msvideo1_decode_end, |
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
383 msvideo1_decode_frame, |
1607 | 384 CODEC_CAP_DR1 | CODEC_CAP_CR, |
1491
222643544cf1
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
385 }; |