annotate kmvc.c @ 3279:647a677c00a4 libavcodec

Remove unused and unsupported Cyrix's "Extended MMX", Add SSE3 support. Patch by Zuxy Meng < zuxy POIS meng AH gmail POIS com > Original thread: 04/26/06 13:13: [Ffmpeg-devel] [PATCH] Bug fix, SSE3 support in i386/cputest.c and dsputil.h
author gpoirier
date Fri, 28 Apr 2006 07:46:13 +0000
parents 226ffbb6fd02
children 1eb35b97c056
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3253
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
1 /*
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
2 * KMVC decoder
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
3 * Copyright (c) 2006 Konstantin Shishkov
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
4 *
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
8 * version 2 of the License, or (at your option) any later version.
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
9 *
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
13 * Lesser General Public License for more details.
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
14 *
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
16 * License along with this library; if not, write to the Free Software
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
18 *
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
19 */
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
20
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
21 /**
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
22 * @file kmvc.c
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
23 * Karl Morton's Video Codec decoder
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
24 */
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
25
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
26 #include <stdio.h>
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
27 #include <stdlib.h>
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
28
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
29 #include "common.h"
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
30 #include "avcodec.h"
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
31
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
32 #define KMVC_KEYFRAME 0x80
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
33 #define KMVC_PALETTE 0x40
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
34 #define KMVC_METHOD 0x0F
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
35
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
36 /*
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
37 * Decoder context
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
38 */
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
39 typedef struct KmvcContext {
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
40 AVCodecContext *avctx;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
41 AVFrame pic;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
42
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
43 int setpal;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
44 int palsize;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
45 uint32_t pal[256];
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
46 uint8_t *cur, *prev;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
47 uint8_t *frm0, *frm1;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
48 } KmvcContext;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
49
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
50 typedef struct BitBuf {
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
51 int bits;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
52 int bitbuf;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
53 } BitBuf;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
54
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
55 #define BLK(data, x, y) data[(x) + (y) * 320]
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
56
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
57 #define kmvc_init_getbits(bb, src) bb.bits = 7; bb.bitbuf = *src++;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
58
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
59 #define kmvc_getbit(bb, src, res) {\
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
60 res = 0; \
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
61 if (bb.bitbuf & (1 << bb.bits)) res = 1; \
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
62 bb.bits--; \
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
63 if(bb.bits == -1) { \
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
64 bb.bitbuf = *src++; \
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
65 bb.bits = 7; \
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
66 } \
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
67 }
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
68
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
69 static void kmvc_decode_intra_8x8(KmvcContext * ctx, uint8_t * src, int w, int h)
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
70 {
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
71 BitBuf bb;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
72 int res, val;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
73 int i, j;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
74 int bx, by;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
75 int l0x, l1x, l0y, l1y;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
76 int mx, my;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
77
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
78 kmvc_init_getbits(bb, src);
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
79
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
80 for (by = 0; by < h; by += 8)
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
81 for (bx = 0; bx < w; bx += 8) {
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
82 kmvc_getbit(bb, src, res);
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
83 if (!res) { // fill whole 8x8 block
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
84 val = *src++;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
85 for (i = 0; i < 64; i++)
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
86 BLK(ctx->cur, bx + (i & 0x7), by + (i >> 3)) = val;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
87 } else { // handle four 4x4 subblocks
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
88 for (i = 0; i < 4; i++) {
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
89 l0x = bx + (i & 1) * 4;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
90 l0y = by + (i & 2) * 2;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
91 kmvc_getbit(bb, src, res);
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
92 if (!res) {
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
93 kmvc_getbit(bb, src, res);
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
94 if (!res) { // fill whole 4x4 block
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
95 val = *src++;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
96 for (j = 0; j < 16; j++)
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
97 BLK(ctx->cur, l0x + (j & 3), l0y + (j >> 2)) = val;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
98 } else { // copy block from already decoded place
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
99 val = *src++;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
100 mx = val & 0xF;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
101 my = val >> 4;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
102 for (j = 0; j < 16; j++)
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
103 BLK(ctx->cur, l0x + (j & 3), l0y + (j >> 2)) =
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
104 BLK(ctx->cur, l0x + (j & 3) - mx, l0y + (j >> 2) - my);
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
105 }
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
106 } else { // descend to 2x2 sub-sub-blocks
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
107 for (j = 0; j < 4; j++) {
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
108 l1x = l0x + (j & 1) * 2;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
109 l1y = l0y + (j & 2);
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
110 kmvc_getbit(bb, src, res);
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
111 if (!res) {
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
112 kmvc_getbit(bb, src, res);
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
113 if (!res) { // fill whole 2x2 block
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
114 val = *src++;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
115 BLK(ctx->cur, l1x, l1y) = val;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
116 BLK(ctx->cur, l1x + 1, l1y) = val;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
117 BLK(ctx->cur, l1x, l1y + 1) = val;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
118 BLK(ctx->cur, l1x + 1, l1y + 1) = val;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
119 } else { // copy block from already decoded place
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
120 val = *src++;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
121 mx = val & 0xF;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
122 my = val >> 4;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
123 BLK(ctx->cur, l1x, l1y) = BLK(ctx->cur, l1x - mx, l1y - my);
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
124 BLK(ctx->cur, l1x + 1, l1y) =
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
125 BLK(ctx->cur, l1x + 1 - mx, l1y - my);
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
126 BLK(ctx->cur, l1x, l1y + 1) =
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
127 BLK(ctx->cur, l1x - mx, l1y + 1 - my);
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
128 BLK(ctx->cur, l1x + 1, l1y + 1) =
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
129 BLK(ctx->cur, l1x + 1 - mx, l1y + 1 - my);
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
130 }
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
131 } else { // read values for block
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
132 BLK(ctx->cur, l1x, l1y) = *src++;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
133 BLK(ctx->cur, l1x + 1, l1y) = *src++;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
134 BLK(ctx->cur, l1x, l1y + 1) = *src++;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
135 BLK(ctx->cur, l1x + 1, l1y + 1) = *src++;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
136 }
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
137 }
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
138 }
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
139 }
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
140 }
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
141 }
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
142 }
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
143
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
144 static void kmvc_decode_inter_8x8(KmvcContext * ctx, uint8_t * src, int w, int h)
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
145 {
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
146 BitBuf bb;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
147 int res, val;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
148 int i, j;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
149 int bx, by;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
150 int l0x, l1x, l0y, l1y;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
151 int mx, my;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
152
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
153 kmvc_init_getbits(bb, src);
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
154
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
155 for (by = 0; by < h; by += 8)
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
156 for (bx = 0; bx < w; bx += 8) {
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
157 kmvc_getbit(bb, src, res);
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
158 if (!res) {
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
159 kmvc_getbit(bb, src, res);
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
160 if (!res) { // fill whole 8x8 block
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
161 val = *src++;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
162 for (i = 0; i < 64; i++)
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
163 BLK(ctx->cur, bx + (i & 0x7), by + (i >> 3)) = val;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
164 } else { // copy block from previous frame
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
165 for (i = 0; i < 64; i++)
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
166 BLK(ctx->cur, bx + (i & 0x7), by + (i >> 3)) =
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
167 BLK(ctx->prev, bx + (i & 0x7), by + (i >> 3));
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
168 }
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
169 } else { // handle four 4x4 subblocks
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
170 for (i = 0; i < 4; i++) {
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
171 l0x = bx + (i & 1) * 4;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
172 l0y = by + (i & 2) * 2;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
173 kmvc_getbit(bb, src, res);
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
174 if (!res) {
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
175 kmvc_getbit(bb, src, res);
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
176 if (!res) { // fill whole 4x4 block
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
177 val = *src++;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
178 for (j = 0; j < 16; j++)
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
179 BLK(ctx->cur, l0x + (j & 3), l0y + (j >> 2)) = val;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
180 } else { // copy block
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
181 val = *src++;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
182 mx = (val & 0xF) - 8;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
183 my = (val >> 4) - 8;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
184 for (j = 0; j < 16; j++)
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
185 BLK(ctx->cur, l0x + (j & 3), l0y + (j >> 2)) =
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
186 BLK(ctx->prev, l0x + (j & 3) + mx, l0y + (j >> 2) + my);
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
187 }
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
188 } else { // descend to 2x2 sub-sub-blocks
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
189 for (j = 0; j < 4; j++) {
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
190 l1x = l0x + (j & 1) * 2;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
191 l1y = l0y + (j & 2);
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
192 kmvc_getbit(bb, src, res);
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
193 if (!res) {
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
194 kmvc_getbit(bb, src, res);
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
195 if (!res) { // fill whole 2x2 block
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
196 val = *src++;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
197 BLK(ctx->cur, l1x, l1y) = val;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
198 BLK(ctx->cur, l1x + 1, l1y) = val;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
199 BLK(ctx->cur, l1x, l1y + 1) = val;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
200 BLK(ctx->cur, l1x + 1, l1y + 1) = val;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
201 } else { // copy block
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
202 val = *src++;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
203 mx = (val & 0xF) - 8;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
204 my = (val >> 4) - 8;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
205 BLK(ctx->cur, l1x, l1y) = BLK(ctx->prev, l1x + mx, l1y + my);
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
206 BLK(ctx->cur, l1x + 1, l1y) =
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
207 BLK(ctx->prev, l1x + 1 + mx, l1y + my);
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
208 BLK(ctx->cur, l1x, l1y + 1) =
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
209 BLK(ctx->prev, l1x + mx, l1y + 1 + my);
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
210 BLK(ctx->cur, l1x + 1, l1y + 1) =
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
211 BLK(ctx->prev, l1x + 1 + mx, l1y + 1 + my);
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
212 }
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
213 } else { // read values for block
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
214 BLK(ctx->cur, l1x, l1y) = *src++;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
215 BLK(ctx->cur, l1x + 1, l1y) = *src++;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
216 BLK(ctx->cur, l1x, l1y + 1) = *src++;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
217 BLK(ctx->cur, l1x + 1, l1y + 1) = *src++;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
218 }
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
219 }
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
220 }
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
221 }
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
222 }
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
223 }
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
224 }
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
225
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
226 static int decode_frame(AVCodecContext * avctx, void *data, int *data_size, uint8_t * buf,
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
227 int buf_size)
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
228 {
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
229 KmvcContext *const ctx = (KmvcContext *) avctx->priv_data;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
230 uint8_t *out, *src;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
231 int i;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
232 int header;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
233 int blocksize;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
234
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
235 if (ctx->pic.data[0])
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
236 avctx->release_buffer(avctx, &ctx->pic);
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
237
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
238 ctx->pic.reference = 1;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
239 ctx->pic.buffer_hints = FF_BUFFER_HINTS_VALID;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
240 if (avctx->get_buffer(avctx, &ctx->pic) < 0) {
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
241 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
242 return -1;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
243 }
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
244
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
245 header = buf[0];
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
246 buf++;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
247
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
248 if (header & KMVC_KEYFRAME) {
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
249 ctx->pic.key_frame = 1;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
250 ctx->pic.pict_type = FF_I_TYPE;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
251 } else {
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
252 ctx->pic.key_frame = 0;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
253 ctx->pic.pict_type = FF_P_TYPE;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
254 }
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
255
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
256 if (header & KMVC_PALETTE) {
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
257 ctx->pic.palette_has_changed = 1;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
258 // palette starts from index 1 and has 127 entries
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
259 for (i = 1; i <= ctx->palsize; i++) {
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
260 ctx->pal[i] = (buf[0] << 16) | (buf[1] << 8) | buf[2];
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
261 buf += 3;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
262 }
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
263 }
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
264
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
265 if (ctx->setpal) {
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
266 ctx->setpal = 0;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
267 ctx->pic.palette_has_changed = 1;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
268 }
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
269
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
270 /* make the palette available on the way out */
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
271 memcpy(ctx->pic.data[1], ctx->pal, 1024);
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
272
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
273 blocksize = *buf++;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
274
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
275 if (blocksize != 8) {
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
276 av_log(avctx, AV_LOG_ERROR, "Block size = %i\n", blocksize);
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
277 return -1;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
278 }
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
279 memset(ctx->cur, 0, 320 * 200);
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
280 switch (header & KMVC_METHOD) {
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
281 case 3:
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
282 kmvc_decode_intra_8x8(ctx, buf, avctx->width, avctx->height);
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
283 break;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
284 case 4:
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
285 kmvc_decode_inter_8x8(ctx, buf, avctx->width, avctx->height);
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
286 break;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
287 default:
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
288 av_log(avctx, AV_LOG_ERROR, "Unknown compression method %i\n", header & KMVC_METHOD);
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
289 return -1;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
290 }
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
291
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
292 out = ctx->pic.data[0];
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
293 src = ctx->cur;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
294 for (i = 0; i < avctx->height; i++) {
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
295 memcpy(out, src, avctx->width);
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
296 src += 320;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
297 out += ctx->pic.linesize[0];
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
298 }
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
299
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
300 /* flip buffers */
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
301 if (ctx->cur == ctx->frm0) {
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
302 ctx->cur = ctx->frm1;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
303 ctx->prev = ctx->frm0;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
304 } else {
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
305 ctx->cur = ctx->frm0;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
306 ctx->prev = ctx->frm1;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
307 }
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
308
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
309 *data_size = sizeof(AVFrame);
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
310 *(AVFrame *) data = ctx->pic;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
311
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
312 /* always report that the buffer was completely consumed */
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
313 return buf_size;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
314 }
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
315
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
316
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
317
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
318 /*
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
319 * Init kmvc decoder
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
320 */
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
321 static int decode_init(AVCodecContext * avctx)
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
322 {
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
323 KmvcContext *const c = (KmvcContext *) avctx->priv_data;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
324 int i;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
325
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
326 c->avctx = avctx;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
327 avctx->has_b_frames = 0;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
328
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
329 c->pic.data[0] = NULL;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
330
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
331 if (avctx->width > 320 || avctx->height > 200) {
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
332 av_log(avctx, AV_LOG_ERROR, "KMVC supports frames <= 320x200\n");
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
333 return -1;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
334 }
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
335
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
336 c->frm0 = av_mallocz(320 * 200);
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
337 c->frm1 = av_mallocz(320 * 200);
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
338 c->cur = c->frm0;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
339 c->prev = c->frm1;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
340
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
341 for (i = 0; i < 256; i++) {
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
342 c->pal[i] = i * 0x10101;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
343 }
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
344
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
345 if (avctx->extradata_size < 12) {
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
346 av_log(NULL, 0, "Extradata missing, decoding may not work properly...\n");
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
347 c->palsize = 127;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
348 } else {
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
349 c->palsize = LE_16(avctx->extradata + 10);
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
350 }
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
351
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
352 if (avctx->extradata_size == 1036) { // palette in extradata
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
353 uint8_t *src = avctx->extradata + 12;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
354 for (i = 0; i < c->palsize; i++) {
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
355 c->pal[i] = LE_32(src);
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
356 src += 4;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
357 }
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
358 c->setpal = 1;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
359 }
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
360
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
361 avctx->pix_fmt = PIX_FMT_PAL8;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
362
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
363 return 0;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
364 }
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
365
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
366
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
367
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
368 /*
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
369 * Uninit kmvc decoder
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
370 */
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
371 static int decode_end(AVCodecContext * avctx)
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
372 {
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
373 KmvcContext *const c = (KmvcContext *) avctx->priv_data;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
374
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
375 if (c->frm0)
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
376 av_free(c->frm0);
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
377 if (c->frm1)
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
378 av_free(c->frm1);
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
379 if (c->pic.data[0])
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
380 avctx->release_buffer(avctx, &c->pic);
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
381
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
382 return 0;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
383 }
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
384
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
385 AVCodec kmvc_decoder = {
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
386 "kmvc",
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
387 CODEC_TYPE_VIDEO,
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
388 CODEC_ID_KMVC,
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
389 sizeof(KmvcContext),
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
390 decode_init,
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
391 NULL,
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
392 decode_end,
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
393 decode_frame
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
394 };