37 #define KMVC_KEYFRAME 0x80
38 #define KMVC_PALETTE 0x40
39 #define KMVC_METHOD 0x0F
40 #define MAX_PALSIZE 256
61 #define BLK(data, x, y) data[av_clip((x) + (y) * 320, 0, 320 * 200 -1)]
63 #define kmvc_init_getbits(bb, g) bb.bits = 7; bb.bitbuf = bytestream2_get_byte(g);
65 #define kmvc_getbit(bb, g, res) {\
67 if (bb.bitbuf & (1 << bb.bits)) res = 1; \
70 bb.bitbuf = bytestream2_get_byte(g); \
81 int l0x, l1x, l0y, l1y;
86 for (by = 0; by <
h; by += 8)
87 for (bx = 0; bx <
w; bx += 8) {
94 val = bytestream2_get_byte(&
ctx->g);
95 for (
i = 0;
i < 64;
i++)
98 for (
i = 0;
i < 4;
i++) {
99 l0x = bx + (
i & 1) * 4;
100 l0y = by + (
i & 2) * 2;
105 val = bytestream2_get_byte(&
ctx->g);
106 for (j = 0; j < 16; j++)
107 BLK(
ctx->cur, l0x + (j & 3), l0y + (j >> 2)) =
val;
109 val = bytestream2_get_byte(&
ctx->g);
112 if ((l0x-mx) + 320*(l0y-my) < 0 || (l0x-mx) + 320*(l0y-my) > 320*197 - 4) {
116 for (j = 0; j < 16; j++)
117 BLK(
ctx->cur, l0x + (j & 3), l0y + (j >> 2)) =
118 BLK(
ctx->cur, l0x + (j & 3) - mx, l0y + (j >> 2) - my);
121 for (j = 0; j < 4; j++) {
122 l1x = l0x + (j & 1) * 2;
128 val = bytestream2_get_byte(&
ctx->g);
134 val = bytestream2_get_byte(&
ctx->g);
137 if ((l1x-mx) + 320*(l1y-my) < 0 || (l1x-mx) + 320*(l1y-my) > 320*199 - 2) {
141 BLK(
ctx->cur, l1x, l1y) =
BLK(
ctx->cur, l1x - mx, l1y - my);
142 BLK(
ctx->cur, l1x + 1, l1y) =
143 BLK(
ctx->cur, l1x + 1 - mx, l1y - my);
144 BLK(
ctx->cur, l1x, l1y + 1) =
145 BLK(
ctx->cur, l1x - mx, l1y + 1 - my);
146 BLK(
ctx->cur, l1x + 1, l1y + 1) =
147 BLK(
ctx->cur, l1x + 1 - mx, l1y + 1 - my);
150 BLK(
ctx->cur, l1x, l1y) = bytestream2_get_byte(&
ctx->g);
151 BLK(
ctx->cur, l1x + 1, l1y) = bytestream2_get_byte(&
ctx->g);
152 BLK(
ctx->cur, l1x, l1y + 1) = bytestream2_get_byte(&
ctx->g);
153 BLK(
ctx->cur, l1x + 1, l1y + 1) = bytestream2_get_byte(&
ctx->g);
170 int l0x, l1x, l0y, l1y;
175 for (by = 0; by <
h; by += 8)
176 for (bx = 0; bx <
w; bx += 8) {
185 val = bytestream2_get_byte(&
ctx->g);
186 for (
i = 0;
i < 64;
i++)
187 BLK(
ctx->cur, bx + (
i & 0x7), by + (
i >> 3)) =
val;
189 for (
i = 0;
i < 64;
i++)
190 BLK(
ctx->cur, bx + (
i & 0x7), by + (
i >> 3)) =
191 BLK(
ctx->prev, bx + (
i & 0x7), by + (
i >> 3));
198 for (
i = 0;
i < 4;
i++) {
199 l0x = bx + (
i & 1) * 4;
200 l0y = by + (
i & 2) * 2;
205 val = bytestream2_get_byte(&
ctx->g);
206 for (j = 0; j < 16; j++)
207 BLK(
ctx->cur, l0x + (j & 3), l0y + (j >> 2)) =
val;
209 val = bytestream2_get_byte(&
ctx->g);
210 mx = (
val & 0xF) - 8;
212 if ((l0x+mx) + 320*(l0y+my) < 0 || (l0x+mx) + 320*(l0y+my) > 320*197 - 4) {
216 for (j = 0; j < 16; j++)
217 BLK(
ctx->cur, l0x + (j & 3), l0y + (j >> 2)) =
218 BLK(
ctx->prev, l0x + (j & 3) + mx, l0y + (j >> 2) + my);
221 for (j = 0; j < 4; j++) {
222 l1x = l0x + (j & 1) * 2;
228 val = bytestream2_get_byte(&
ctx->g);
234 val = bytestream2_get_byte(&
ctx->g);
235 mx = (
val & 0xF) - 8;
237 if ((l1x+mx) + 320*(l1y+my) < 0 || (l1x+mx) + 320*(l1y+my) > 320*199 - 2) {
241 BLK(
ctx->cur, l1x, l1y) =
BLK(
ctx->prev, l1x + mx, l1y + my);
242 BLK(
ctx->cur, l1x + 1, l1y) =
243 BLK(
ctx->prev, l1x + 1 + mx, l1y + my);
244 BLK(
ctx->cur, l1x, l1y + 1) =
245 BLK(
ctx->prev, l1x + mx, l1y + 1 + my);
246 BLK(
ctx->cur, l1x + 1, l1y + 1) =
247 BLK(
ctx->prev, l1x + 1 + mx, l1y + 1 + my);
250 BLK(
ctx->cur, l1x, l1y) = bytestream2_get_byte(&
ctx->g);
251 BLK(
ctx->cur, l1x + 1, l1y) = bytestream2_get_byte(&
ctx->g);
252 BLK(
ctx->cur, l1x, l1y + 1) = bytestream2_get_byte(&
ctx->g);
253 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++) {