annotate kmvc.c @ 11762:91b9bd17e79c libavcodec

aacenc: Trellis over scalefactors using an estimated codebook rather than every codebook. The minimal codebook to encode the band without clipping is used (as is done in the TLS).
author alexc
date Tue, 25 May 2010 18:31:55 +0000
parents 7dd2a45249a9
children
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 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3694
diff changeset
5 * This file is part of FFmpeg.
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3694
diff changeset
6 *
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3694
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
3253
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
8 * 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
9 * License as published by the Free Software Foundation; either
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3694
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
3253
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
11 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3694
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
3253
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
13 * 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
14 * 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
15 * Lesser General Public License for more details.
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
16 *
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3694
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
3253
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
19 * 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
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 /**
11644
7dd2a45249a9 Remove explicit filename from Doxygen @file commands.
diego
parents: 11560
diff changeset
23 * @file
3253
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
24 * Karl Morton's Video Codec decoder
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
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
27 #include <stdio.h>
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
28 #include <stdlib.h>
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
29
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
30 #include "avcodec.h"
5089
bff60ecc02f9 Use AV_xx throughout libavcodec
ramiro
parents: 4962
diff changeset
31 #include "bytestream.h"
3253
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
32
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
33 #define KMVC_KEYFRAME 0x80
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
34 #define KMVC_PALETTE 0x40
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
35 #define KMVC_METHOD 0x0F
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 /*
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
38 * Decoder context
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
39 */
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
40 typedef struct KmvcContext {
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
41 AVCodecContext *avctx;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
42 AVFrame pic;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
43
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
44 int setpal;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
45 int palsize;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
46 uint32_t pal[256];
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
47 uint8_t *cur, *prev;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
48 uint8_t *frm0, *frm1;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
49 } KmvcContext;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
50
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
51 typedef struct BitBuf {
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
52 int bits;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
53 int bitbuf;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
54 } BitBuf;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
55
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
56 #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
57
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
58 #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
59
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
60 #define kmvc_getbit(bb, src, res) {\
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
61 res = 0; \
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
62 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
63 bb.bits--; \
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
64 if(bb.bits == -1) { \
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
65 bb.bitbuf = *src++; \
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
66 bb.bits = 7; \
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
6218
michael
parents: 5215
diff changeset
70 static void kmvc_decode_intra_8x8(KmvcContext * ctx, const uint8_t * src, int w, int h)
3253
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
71 {
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
72 BitBuf bb;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
73 int res, val;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
74 int i, j;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
75 int bx, by;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
76 int l0x, l1x, l0y, l1y;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
77 int mx, my;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
78
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
79 kmvc_init_getbits(bb, src);
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
80
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
81 for (by = 0; by < h; by += 8)
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
82 for (bx = 0; bx < w; bx += 8) {
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
83 kmvc_getbit(bb, src, res);
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
84 if (!res) { // fill whole 8x8 block
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
85 val = *src++;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
86 for (i = 0; i < 64; i++)
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
87 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
88 } else { // handle four 4x4 subblocks
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
89 for (i = 0; i < 4; i++) {
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
90 l0x = bx + (i & 1) * 4;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
91 l0y = by + (i & 2) * 2;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
92 kmvc_getbit(bb, src, res);
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
93 if (!res) {
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
94 kmvc_getbit(bb, src, res);
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
95 if (!res) { // fill whole 4x4 block
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
96 val = *src++;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
97 for (j = 0; j < 16; j++)
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
98 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
99 } else { // copy block from already decoded place
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
100 val = *src++;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
101 mx = val & 0xF;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
102 my = val >> 4;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
103 for (j = 0; j < 16; j++)
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
104 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
105 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
106 }
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
107 } else { // descend to 2x2 sub-sub-blocks
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
108 for (j = 0; j < 4; j++) {
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
109 l1x = l0x + (j & 1) * 2;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
110 l1y = l0y + (j & 2);
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
111 kmvc_getbit(bb, src, res);
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
112 if (!res) {
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
113 kmvc_getbit(bb, src, res);
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
114 if (!res) { // fill whole 2x2 block
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
115 val = *src++;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
116 BLK(ctx->cur, l1x, l1y) = val;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
117 BLK(ctx->cur, l1x + 1, l1y) = val;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
118 BLK(ctx->cur, l1x, l1y + 1) = val;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
119 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
120 } else { // copy block from already decoded place
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
121 val = *src++;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
122 mx = val & 0xF;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
123 my = val >> 4;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
124 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
125 BLK(ctx->cur, l1x + 1, l1y) =
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
126 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
127 BLK(ctx->cur, l1x, l1y + 1) =
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
128 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
129 BLK(ctx->cur, l1x + 1, l1y + 1) =
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
130 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
131 }
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
132 } else { // read values for block
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
133 BLK(ctx->cur, l1x, l1y) = *src++;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
134 BLK(ctx->cur, l1x + 1, l1y) = *src++;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
135 BLK(ctx->cur, l1x, l1y + 1) = *src++;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
136 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
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
6218
michael
parents: 5215
diff changeset
145 static void kmvc_decode_inter_8x8(KmvcContext * ctx, const uint8_t * src, int w, int h)
3253
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
146 {
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
147 BitBuf bb;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
148 int res, val;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
149 int i, j;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
150 int bx, by;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
151 int l0x, l1x, l0y, l1y;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
152 int mx, my;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
153
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
154 kmvc_init_getbits(bb, src);
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
155
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
156 for (by = 0; by < h; by += 8)
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
157 for (bx = 0; bx < w; bx += 8) {
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
158 kmvc_getbit(bb, src, res);
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
159 if (!res) {
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
160 kmvc_getbit(bb, src, res);
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
161 if (!res) { // fill whole 8x8 block
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
162 val = *src++;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
163 for (i = 0; i < 64; i++)
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
164 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
165 } else { // copy block from previous frame
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
166 for (i = 0; i < 64; i++)
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
167 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
168 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
169 }
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
170 } else { // handle four 4x4 subblocks
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
171 for (i = 0; i < 4; i++) {
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
172 l0x = bx + (i & 1) * 4;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
173 l0y = by + (i & 2) * 2;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
174 kmvc_getbit(bb, src, res);
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
175 if (!res) {
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
176 kmvc_getbit(bb, src, res);
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
177 if (!res) { // fill whole 4x4 block
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
178 val = *src++;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
179 for (j = 0; j < 16; j++)
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
180 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
181 } else { // copy block
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
182 val = *src++;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
183 mx = (val & 0xF) - 8;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
184 my = (val >> 4) - 8;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
185 for (j = 0; j < 16; j++)
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
186 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
187 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
188 }
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
189 } else { // descend to 2x2 sub-sub-blocks
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
190 for (j = 0; j < 4; j++) {
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
191 l1x = l0x + (j & 1) * 2;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
192 l1y = l0y + (j & 2);
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
193 kmvc_getbit(bb, src, res);
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
194 if (!res) {
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
195 kmvc_getbit(bb, src, res);
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
196 if (!res) { // fill whole 2x2 block
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
197 val = *src++;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
198 BLK(ctx->cur, l1x, l1y) = val;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
199 BLK(ctx->cur, l1x + 1, l1y) = val;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
200 BLK(ctx->cur, l1x, l1y + 1) = val;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
201 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
202 } else { // copy block
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
203 val = *src++;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
204 mx = (val & 0xF) - 8;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
205 my = (val >> 4) - 8;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
206 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
207 BLK(ctx->cur, l1x + 1, l1y) =
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
208 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
209 BLK(ctx->cur, l1x, l1y + 1) =
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
210 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
211 BLK(ctx->cur, l1x + 1, l1y + 1) =
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
212 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
213 }
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
214 } else { // read values for block
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
215 BLK(ctx->cur, l1x, l1y) = *src++;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
216 BLK(ctx->cur, l1x + 1, l1y) = *src++;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
217 BLK(ctx->cur, l1x, l1y + 1) = *src++;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
218 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
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
9355
54bc8a2727b0 Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents: 8718
diff changeset
227 static int decode_frame(AVCodecContext * avctx, void *data, int *data_size, AVPacket *avpkt)
3253
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
228 {
9355
54bc8a2727b0 Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents: 8718
diff changeset
229 const uint8_t *buf = avpkt->data;
54bc8a2727b0 Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents: 8718
diff changeset
230 int buf_size = avpkt->size;
4827
b3ee9a1526b0 Get rid of unnecessary pointer casts.
diego
parents: 4740
diff changeset
231 KmvcContext *const ctx = avctx->priv_data;
3253
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
232 uint8_t *out, *src;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
233 int i;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
234 int header;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
235 int blocksize;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
236
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
237 if (ctx->pic.data[0])
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
238 avctx->release_buffer(avctx, &ctx->pic);
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
239
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
240 ctx->pic.reference = 1;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
241 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
242 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
243 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
244 return -1;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
245 }
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
246
3328
1eb35b97c056 Palette support for newer KMVC
kostya
parents: 3253
diff changeset
247 header = *buf++;
1eb35b97c056 Palette support for newer KMVC
kostya
parents: 3253
diff changeset
248
1eb35b97c056 Palette support for newer KMVC
kostya
parents: 3253
diff changeset
249 /* blocksize 127 is really palette change event */
1eb35b97c056 Palette support for newer KMVC
kostya
parents: 3253
diff changeset
250 if (buf[0] == 127) {
1eb35b97c056 Palette support for newer KMVC
kostya
parents: 3253
diff changeset
251 buf += 3;
1eb35b97c056 Palette support for newer KMVC
kostya
parents: 3253
diff changeset
252 for (i = 0; i < 127; i++) {
5089
bff60ecc02f9 Use AV_xx throughout libavcodec
ramiro
parents: 4962
diff changeset
253 ctx->pal[i + (header & 0x81)] = AV_RB24(buf);
3328
1eb35b97c056 Palette support for newer KMVC
kostya
parents: 3253
diff changeset
254 buf += 4;
1eb35b97c056 Palette support for newer KMVC
kostya
parents: 3253
diff changeset
255 }
1eb35b97c056 Palette support for newer KMVC
kostya
parents: 3253
diff changeset
256 buf -= 127 * 4 + 3;
1eb35b97c056 Palette support for newer KMVC
kostya
parents: 3253
diff changeset
257 }
3253
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
258
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
259 if (header & KMVC_KEYFRAME) {
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
260 ctx->pic.key_frame = 1;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
261 ctx->pic.pict_type = FF_I_TYPE;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
262 } else {
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
263 ctx->pic.key_frame = 0;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
264 ctx->pic.pict_type = FF_P_TYPE;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
265 }
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
266
3328
1eb35b97c056 Palette support for newer KMVC
kostya
parents: 3253
diff changeset
267 /* if palette has been changed, copy it from palctrl */
1eb35b97c056 Palette support for newer KMVC
kostya
parents: 3253
diff changeset
268 if (ctx->avctx->palctrl && ctx->avctx->palctrl->palette_changed) {
1eb35b97c056 Palette support for newer KMVC
kostya
parents: 3253
diff changeset
269 memcpy(ctx->pal, ctx->avctx->palctrl->palette, AVPALETTE_SIZE);
1eb35b97c056 Palette support for newer KMVC
kostya
parents: 3253
diff changeset
270 ctx->setpal = 1;
1eb35b97c056 Palette support for newer KMVC
kostya
parents: 3253
diff changeset
271 ctx->avctx->palctrl->palette_changed = 0;
1eb35b97c056 Palette support for newer KMVC
kostya
parents: 3253
diff changeset
272 }
1eb35b97c056 Palette support for newer KMVC
kostya
parents: 3253
diff changeset
273
3253
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
274 if (header & KMVC_PALETTE) {
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
275 ctx->pic.palette_has_changed = 1;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
276 // 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
277 for (i = 1; i <= ctx->palsize; i++) {
5089
bff60ecc02f9 Use AV_xx throughout libavcodec
ramiro
parents: 4962
diff changeset
278 ctx->pal[i] = bytestream_get_be24(&buf);
3253
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
279 }
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
280 }
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
281
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
282 if (ctx->setpal) {
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
283 ctx->setpal = 0;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
284 ctx->pic.palette_has_changed = 1;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
285 }
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
286
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
287 /* 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
288 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
289
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
290 blocksize = *buf++;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
291
3328
1eb35b97c056 Palette support for newer KMVC
kostya
parents: 3253
diff changeset
292 if (blocksize != 8 && blocksize != 127) {
3253
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
293 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
294 return -1;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
295 }
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
296 memset(ctx->cur, 0, 320 * 200);
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
297 switch (header & KMVC_METHOD) {
3328
1eb35b97c056 Palette support for newer KMVC
kostya
parents: 3253
diff changeset
298 case 0:
1eb35b97c056 Palette support for newer KMVC
kostya
parents: 3253
diff changeset
299 case 1: // used in palette changed event
1eb35b97c056 Palette support for newer KMVC
kostya
parents: 3253
diff changeset
300 memcpy(ctx->cur, ctx->prev, 320 * 200);
1eb35b97c056 Palette support for newer KMVC
kostya
parents: 3253
diff changeset
301 break;
3253
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
302 case 3:
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
303 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
304 break;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
305 case 4:
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
306 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
307 break;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
308 default:
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
309 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
310 return -1;
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
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
313 out = ctx->pic.data[0];
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
314 src = ctx->cur;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
315 for (i = 0; i < avctx->height; i++) {
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
316 memcpy(out, src, avctx->width);
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
317 src += 320;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
318 out += ctx->pic.linesize[0];
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
319 }
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 /* flip buffers */
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
322 if (ctx->cur == ctx->frm0) {
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
323 ctx->cur = ctx->frm1;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
324 ctx->prev = ctx->frm0;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
325 } else {
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
326 ctx->cur = ctx->frm0;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
327 ctx->prev = ctx->frm1;
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
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
330 *data_size = sizeof(AVFrame);
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
331 *(AVFrame *) data = ctx->pic;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
332
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
333 /* 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
334 return buf_size;
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
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
337
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
338
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
339 /*
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
340 * Init kmvc decoder
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
341 */
6517
48759bfbd073 Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents: 6218
diff changeset
342 static av_cold int decode_init(AVCodecContext * avctx)
3253
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
343 {
4827
b3ee9a1526b0 Get rid of unnecessary pointer casts.
diego
parents: 4740
diff changeset
344 KmvcContext *const c = avctx->priv_data;
3253
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
345 int i;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
346
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
347 c->avctx = avctx;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
348
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
349 if (avctx->width > 320 || avctx->height > 200) {
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
350 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
351 return -1;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
352 }
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
353
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
354 c->frm0 = av_mallocz(320 * 200);
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
355 c->frm1 = av_mallocz(320 * 200);
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
356 c->cur = c->frm0;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
357 c->prev = c->frm1;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
358
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
359 for (i = 0; i < 256; i++) {
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
360 c->pal[i] = i * 0x10101;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
361 }
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 if (avctx->extradata_size < 12) {
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
364 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
365 c->palsize = 127;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
366 } else {
4364
05e932ddaaa9 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 3947
diff changeset
367 c->palsize = AV_RL16(avctx->extradata + 10);
3253
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
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
370 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
371 uint8_t *src = avctx->extradata + 12;
3328
1eb35b97c056 Palette support for newer KMVC
kostya
parents: 3253
diff changeset
372 for (i = 0; i < 256; i++) {
4364
05e932ddaaa9 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 3947
diff changeset
373 c->pal[i] = AV_RL32(src);
3253
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
374 src += 4;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
375 }
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
376 c->setpal = 1;
3328
1eb35b97c056 Palette support for newer KMVC
kostya
parents: 3253
diff changeset
377 if (c->avctx->palctrl) {
1eb35b97c056 Palette support for newer KMVC
kostya
parents: 3253
diff changeset
378 c->avctx->palctrl->palette_changed = 0;
1eb35b97c056 Palette support for newer KMVC
kostya
parents: 3253
diff changeset
379 }
3253
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
380 }
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 avctx->pix_fmt = PIX_FMT_PAL8;
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 return 0;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
385 }
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
386
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
387
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
388
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
389 /*
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
390 * Uninit kmvc decoder
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
391 */
6517
48759bfbd073 Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents: 6218
diff changeset
392 static av_cold int decode_end(AVCodecContext * avctx)
3253
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
393 {
4827
b3ee9a1526b0 Get rid of unnecessary pointer casts.
diego
parents: 4740
diff changeset
394 KmvcContext *const c = avctx->priv_data;
3253
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
395
3694
8765ee4eaa45 Drop unneeded checks before av_free() and change to av_freep() where it's more suitable.
kostya
parents: 3328
diff changeset
396 av_freep(&c->frm0);
8765ee4eaa45 Drop unneeded checks before av_free() and change to av_freep() where it's more suitable.
kostya
parents: 3328
diff changeset
397 av_freep(&c->frm1);
3253
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
398 if (c->pic.data[0])
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
399 avctx->release_buffer(avctx, &c->pic);
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
400
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
401 return 0;
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
402 }
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
403
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
404 AVCodec kmvc_decoder = {
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
405 "kmvc",
11560
8a4984c5cacc Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 9806
diff changeset
406 AVMEDIA_TYPE_VIDEO,
3253
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
407 CODEC_ID_KMVC,
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
408 sizeof(KmvcContext),
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
409 decode_init,
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
410 NULL,
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
411 decode_end,
6712
5b3acf9fd50a Add long names to AVCodec declarations.
diego
parents: 6517
diff changeset
412 decode_frame,
9806
9ab7ba20202c kmvc decoder uses get_buffer, set CODEC_CAP_DR1
bcoudurier
parents: 9553
diff changeset
413 CODEC_CAP_DR1,
7040
e943e1409077 Make AVCodec long_names definition conditional depending on CONFIG_SMALL.
stefano
parents: 6712
diff changeset
414 .long_name = NULL_IF_CONFIG_SMALL("Karl Morton's video codec"),
3253
226ffbb6fd02 KMVC (used in Worms games) decoder. Works fine with samples from MPHQ
kostya
parents:
diff changeset
415 };