36 #define KMVC_KEYFRAME 0x80
37 #define KMVC_PALETTE 0x40
38 #define KMVC_METHOD 0x0F
39 #define MAX_PALSIZE 256
60 #define BLK(data, x, y) data[av_clip((x) + (y) * 320, 0, 320 * 200 -1)]
62 #define kmvc_init_getbits(bb, g) bb.bits = 7; bb.bitbuf = bytestream2_get_byte(g);
64 #define kmvc_getbit(bb, g, res) {\
66 if (bb.bitbuf & (1 << bb.bits)) res = 1; \
69 bb.bitbuf = bytestream2_get_byte(g); \
80 int l0x, l1x, l0y, l1y;
85 for (by = 0; by <
h; by += 8)
86 for (bx = 0; bx <
w; bx += 8) {
93 val = bytestream2_get_byte(&
ctx->g);
94 for (
i = 0;
i < 64;
i++)
97 for (
i = 0;
i < 4;
i++) {
98 l0x = bx + (
i & 1) * 4;
99 l0y = by + (
i & 2) * 2;
104 val = bytestream2_get_byte(&
ctx->g);
105 for (j = 0; j < 16; j++)
106 BLK(
ctx->cur, l0x + (j & 3), l0y + (j >> 2)) =
val;
108 val = bytestream2_get_byte(&
ctx->g);
111 if ((l0x-mx) + 320*(l0y-my) < 0 || (l0x-mx) + 320*(l0y-my) > 320*197 - 4) {
115 for (j = 0; j < 16; j++)
116 BLK(
ctx->cur, l0x + (j & 3), l0y + (j >> 2)) =
117 BLK(
ctx->cur, l0x + (j & 3) - mx, l0y + (j >> 2) - my);
120 for (j = 0; j < 4; j++) {
121 l1x = l0x + (j & 1) * 2;
127 val = bytestream2_get_byte(&
ctx->g);
133 val = bytestream2_get_byte(&
ctx->g);
136 if ((l1x-mx) + 320*(l1y-my) < 0 || (l1x-mx) + 320*(l1y-my) > 320*199 - 2) {
140 BLK(
ctx->cur, l1x, l1y) =
BLK(
ctx->cur, l1x - mx, l1y - my);
141 BLK(
ctx->cur, l1x + 1, l1y) =
142 BLK(
ctx->cur, l1x + 1 - mx, l1y - my);
143 BLK(
ctx->cur, l1x, l1y + 1) =
144 BLK(
ctx->cur, l1x - mx, l1y + 1 - my);
145 BLK(
ctx->cur, l1x + 1, l1y + 1) =
146 BLK(
ctx->cur, l1x + 1 - mx, l1y + 1 - my);
149 BLK(
ctx->cur, l1x, l1y) = bytestream2_get_byte(&
ctx->g);
150 BLK(
ctx->cur, l1x + 1, l1y) = bytestream2_get_byte(&
ctx->g);
151 BLK(
ctx->cur, l1x, l1y + 1) = bytestream2_get_byte(&
ctx->g);
152 BLK(
ctx->cur, l1x + 1, l1y + 1) = bytestream2_get_byte(&
ctx->g);
169 int l0x, l1x, l0y, l1y;
174 for (by = 0; by <
h; by += 8)
175 for (bx = 0; bx <
w; bx += 8) {
184 val = bytestream2_get_byte(&
ctx->g);
185 for (
i = 0;
i < 64;
i++)
186 BLK(
ctx->cur, bx + (
i & 0x7), by + (
i >> 3)) =
val;
188 for (
i = 0;
i < 64;
i++)
189 BLK(
ctx->cur, bx + (
i & 0x7), by + (
i >> 3)) =
190 BLK(
ctx->prev, bx + (
i & 0x7), by + (
i >> 3));
197 for (
i = 0;
i < 4;
i++) {
198 l0x = bx + (
i & 1) * 4;
199 l0y = by + (
i & 2) * 2;
204 val = bytestream2_get_byte(&
ctx->g);
205 for (j = 0; j < 16; j++)
206 BLK(
ctx->cur, l0x + (j & 3), l0y + (j >> 2)) =
val;
208 val = bytestream2_get_byte(&
ctx->g);
209 mx = (
val & 0xF) - 8;
211 if ((l0x+mx) + 320*(l0y+my) < 0 || (l0x+mx) + 320*(l0y+my) > 320*197 - 4) {
215 for (j = 0; j < 16; j++)
216 BLK(
ctx->cur, l0x + (j & 3), l0y + (j >> 2)) =
217 BLK(
ctx->prev, l0x + (j & 3) + mx, l0y + (j >> 2) + my);
220 for (j = 0; j < 4; j++) {
221 l1x = l0x + (j & 1) * 2;
227 val = bytestream2_get_byte(&
ctx->g);
233 val = bytestream2_get_byte(&
ctx->g);
234 mx = (
val & 0xF) - 8;
236 if ((l1x+mx) + 320*(l1y+my) < 0 || (l1x+mx) + 320*(l1y+my) > 320*199 - 2) {
240 BLK(
ctx->cur, l1x, l1y) =
BLK(
ctx->prev, l1x + mx, l1y + my);
241 BLK(
ctx->cur, l1x + 1, l1y) =
242 BLK(
ctx->prev, l1x + 1 + mx, l1y + my);
243 BLK(
ctx->cur, l1x, l1y + 1) =
244 BLK(
ctx->prev, l1x + mx, l1y + 1 + my);
245 BLK(
ctx->cur, l1x + 1, l1y + 1) =
246 BLK(
ctx->prev, l1x + 1 + mx, l1y + 1 + my);
249 BLK(
ctx->cur, l1x, l1y) = bytestream2_get_byte(&
ctx->g);
250 BLK(
ctx->cur, l1x + 1, l1y) = bytestream2_get_byte(&
ctx->g);
251 BLK(
ctx->cur, l1x, l1y + 1) = bytestream2_get_byte(&
ctx->g);
252 BLK(
ctx->cur, l1x + 1, l1y + 1) = bytestream2_get_byte(&
ctx->g);
283 if (bytestream2_peek_byte(&
ctx->g) == 127) {
285 for (
i = 0;
i < 127;
i++) {
286 ctx->pal[
i + (
header & 0x81)] = 0xFFU << 24 | bytestream2_get_be24(&
ctx->g);
293 frame->key_frame = 1;
296 frame->key_frame = 0;
301 frame->palette_has_changed = 1;
303 for (
i = 1;
i <=
ctx->palsize;
i++) {
304 ctx->pal[
i] = 0xFF
U << 24 | bytestream2_get_be24(&
ctx->g);
310 frame->palette_has_changed = 1;
314 memcpy(
frame->data[1],
ctx->pal, 1024);
316 blocksize = bytestream2_get_byte(&
ctx->g);
318 if (blocksize != 8 && blocksize != 127) {
322 memset(
ctx->cur, 0, 320 * 200);
326 memcpy(
ctx->cur,
ctx->prev, 320 * 200);
376 for (
i = 0;
i < 256;
i++) {
377 c->pal[
i] = 0xFF
U << 24 |
i * 0x10101;
382 "Extradata missing, decoding may not work properly...\n");
395 for (
i = 0;
i < 256;
i++) {