annotate zmbv.c @ 3296:d185908c71cb libavcodec

allow insane gop sizes if the user doesnt care about playable streams (doesnt want compliance to any standard)
author michael
date Tue, 09 May 2006 08:40:38 +0000
parents 03af25454cc3
children 8765ee4eaa45
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3120
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
1 /*
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
2 * Zip Motion Blocks Video (ZMBV) decoder
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
3 * Copyright (c) 2006 Konstantin Shishkov
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
4 *
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
8 * version 2 of the License, or (at your option) any later version.
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
9 *
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
13 * Lesser General Public License for more details.
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
14 *
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
16 * License along with this library; if not, write to the Free Software
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
18 *
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
19 */
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
20
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
21 /**
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
22 * @file zmbv.c
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
23 * Zip Motion Blocks Video decoder
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
24 */
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
25
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
26 #include <stdio.h>
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
27 #include <stdlib.h>
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
28
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
29 #include "common.h"
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
30 #include "avcodec.h"
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
31
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
32 #ifdef CONFIG_ZLIB
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
33 #include <zlib.h>
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
34 #endif
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
35
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
36 #define ZMBV_KEYFRAME 1
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
37 #define ZMBV_DELTAPAL 2
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
38
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
39 enum ZmbvFormat {
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
40 ZMBV_FMT_NONE = 0,
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
41 ZMBV_FMT_1BPP = 1,
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
42 ZMBV_FMT_2BPP = 2,
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
43 ZMBV_FMT_4BPP = 3,
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
44 ZMBV_FMT_8BPP = 4,
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
45 ZMBV_FMT_15BPP = 5,
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
46 ZMBV_FMT_16BPP = 6,
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
47 ZMBV_FMT_24BPP = 7,
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
48 ZMBV_FMT_32BPP = 8
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
49 };
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
50
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
51 /*
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
52 * Decoder context
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
53 */
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
54 typedef struct ZmbvContext {
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
55 AVCodecContext *avctx;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
56 AVFrame pic;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
57
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
58 int bpp;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
59 unsigned int decomp_size;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
60 uint8_t* decomp_buf;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
61 uint8_t pal[768];
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
62 uint8_t *prev, *cur;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
63 int width, height;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
64 int fmt;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
65 int comp;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
66 int flags;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
67 int bw, bh, bx, by;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
68 int decomp_len;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
69 #ifdef CONFIG_ZLIB
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
70 z_stream zstream;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
71 #endif
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
72 int (*decode_intra)(struct ZmbvContext *c);
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
73 int (*decode_xor)(struct ZmbvContext *c);
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
74 } ZmbvContext;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
75
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
76 /**
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
77 * Decode XOR'ed frame - 8bpp version
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
78 */
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
79
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
80 static int zmbv_decode_xor_8(ZmbvContext *c)
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
81 {
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
82 uint8_t *src = c->decomp_buf;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
83 uint8_t *output, *prev;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
84 int8_t *mvec;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
85 int x, y;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
86 int d, dx, dy, bw2, bh2;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
87 int block;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
88 int i, j;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
89 int mx, my;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
90
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
91 output = c->cur;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
92 prev = c->prev;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
93
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
94 if(c->flags & ZMBV_DELTAPAL){
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
95 for(i = 0; i < 768; i++)
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
96 c->pal[i] ^= *src++;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
97 }
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
98
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
99 mvec = (int8_t*)src;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
100 src += ((c->bx * c->by * 2 + 3) & ~3);
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
101
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
102 block = 0;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
103 for(y = 0; y < c->height; y += c->bh) {
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
104 bh2 = ((c->height - y) > c->bh) ? c->bh : (c->height - y);
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
105 for(x = 0; x < c->width; x += c->bw) {
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
106 uint8_t *out, *tprev;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
107
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
108 d = mvec[block] & 1;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
109 dx = mvec[block] >> 1;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
110 dy = mvec[block + 1] >> 1;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
111 block += 2;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
112
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
113 bw2 = ((c->width - x) > c->bw) ? c->bw : (c->width - x);
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
114
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
115 /* copy block - motion vectors out of bounds are used to zero blocks */
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
116 out = output + x;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
117 tprev = prev + x + dx + dy * c->width;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
118 mx = x + dx;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
119 my = y + dy;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
120 for(j = 0; j < bh2; j++){
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
121 if((my + j < 0) || (my + j >= c->height)) {
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
122 memset(out, 0, bw2);
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
123 } else {
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
124 for(i = 0; i < bw2; i++){
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
125 if((mx + i < 0) || (mx + i >= c->width))
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
126 out[i] = 0;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
127 else
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
128 out[i] = tprev[i];
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
129 }
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
130 }
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
131 out += c->width;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
132 tprev += c->width;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
133 }
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
134
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
135 if(d) { /* apply XOR'ed difference */
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
136 out = output + x;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
137 for(j = 0; j < bh2; j++){
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
138 for(i = 0; i < bw2; i++)
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
139 out[i] ^= *src++;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
140 out += c->width;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
141 }
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
142 }
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
143 }
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
144 output += c->width * c->bh;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
145 prev += c->width * c->bh;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
146 }
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
147 if(src - c->decomp_buf != c->decomp_len)
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
148 av_log(c->avctx, AV_LOG_ERROR, "Used %i of %i bytes\n", src-c->decomp_buf, c->decomp_len);
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
149 return 0;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
150 }
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
151
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
152 /**
3134
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
153 * Decode XOR'ed frame - 15bpp and 16bpp version
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
154 */
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
155
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
156 static int zmbv_decode_xor_16(ZmbvContext *c)
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
157 {
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
158 uint8_t *src = c->decomp_buf;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
159 uint16_t *output, *prev;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
160 int8_t *mvec;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
161 int x, y;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
162 int d, dx, dy, bw2, bh2;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
163 int block;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
164 int i, j;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
165 int mx, my;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
166
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
167 output = (uint16_t*)c->cur;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
168 prev = (uint16_t*)c->prev;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
169
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
170 mvec = (int8_t*)src;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
171 src += ((c->bx * c->by * 2 + 3) & ~3);
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
172
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
173 block = 0;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
174 for(y = 0; y < c->height; y += c->bh) {
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
175 bh2 = ((c->height - y) > c->bh) ? c->bh : (c->height - y);
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
176 for(x = 0; x < c->width; x += c->bw) {
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
177 uint16_t *out, *tprev;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
178
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
179 d = mvec[block] & 1;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
180 dx = mvec[block] >> 1;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
181 dy = mvec[block + 1] >> 1;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
182 block += 2;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
183
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
184 bw2 = ((c->width - x) > c->bw) ? c->bw : (c->width - x);
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
185
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
186 /* copy block - motion vectors out of bounds are used to zero blocks */
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
187 out = output + x;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
188 tprev = prev + x + dx + dy * c->width;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
189 mx = x + dx;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
190 my = y + dy;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
191 for(j = 0; j < bh2; j++){
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
192 if((my + j < 0) || (my + j >= c->height)) {
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
193 memset(out, 0, bw2 * 2);
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
194 } else {
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
195 for(i = 0; i < bw2; i++){
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
196 if((mx + i < 0) || (mx + i >= c->width))
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
197 out[i] = 0;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
198 else
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
199 out[i] = tprev[i];
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
200 }
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
201 }
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
202 out += c->width;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
203 tprev += c->width;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
204 }
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
205
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
206 if(d) { /* apply XOR'ed difference */
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
207 out = output + x;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
208 for(j = 0; j < bh2; j++){
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
209 for(i = 0; i < bw2; i++) {
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
210 out[i] ^= *((uint16_t*)src);
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
211 src += 2;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
212 }
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
213 out += c->width;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
214 }
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
215 }
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
216 }
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
217 output += c->width * c->bh;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
218 prev += c->width * c->bh;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
219 }
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
220 if(src - c->decomp_buf != c->decomp_len)
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
221 av_log(c->avctx, AV_LOG_ERROR, "Used %i of %i bytes\n", src-c->decomp_buf, c->decomp_len);
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
222 return 0;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
223 }
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
224
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
225 #ifdef ZMBV_ENABLE_24BPP
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
226 /**
3120
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
227 * Decode XOR'ed frame - 24bpp version
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
228 */
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
229
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
230 static int zmbv_decode_xor_24(ZmbvContext *c)
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
231 {
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
232 uint8_t *src = c->decomp_buf;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
233 uint8_t *output, *prev;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
234 int8_t *mvec;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
235 int x, y;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
236 int d, dx, dy, bw2, bh2;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
237 int block;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
238 int i, j;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
239 int mx, my;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
240 int stride;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
241
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
242 output = c->cur;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
243 prev = c->prev;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
244
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
245 stride = c->width * 3;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
246 mvec = (int8_t*)src;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
247 src += ((c->bx * c->by * 2 + 3) & ~3);
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
248
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
249 block = 0;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
250 for(y = 0; y < c->height; y += c->bh) {
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
251 bh2 = ((c->height - y) > c->bh) ? c->bh : (c->height - y);
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
252 for(x = 0; x < c->width; x += c->bw) {
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
253 uint8_t *out, *tprev;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
254
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
255 d = mvec[block] & 1;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
256 dx = mvec[block] >> 1;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
257 dy = mvec[block + 1] >> 1;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
258 block += 2;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
259
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
260 bw2 = ((c->width - x) > c->bw) ? c->bw : (c->width - x);
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
261
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
262 /* copy block - motion vectors out of bounds are used to zero blocks */
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
263 out = output + x * 3;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
264 tprev = prev + (x + dx) * 3 + dy * stride;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
265 mx = x + dx;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
266 my = y + dy;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
267 for(j = 0; j < bh2; j++){
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
268 if((my + j < 0) || (my + j >= c->height)) {
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
269 memset(out, 0, bw2 * 3);
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
270 } else {
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
271 for(i = 0; i < bw2; i++){
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
272 if((mx + i < 0) || (mx + i >= c->width)) {
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
273 out[i * 3 + 0] = 0;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
274 out[i * 3 + 1] = 0;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
275 out[i * 3 + 2] = 0;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
276 } else {
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
277 out[i * 3 + 0] = tprev[i * 3 + 0];
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
278 out[i * 3 + 1] = tprev[i * 3 + 1];
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
279 out[i * 3 + 2] = tprev[i * 3 + 2];
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
280 }
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
281 }
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
282 }
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
283 out += stride;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
284 tprev += stride;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
285 }
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
286
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
287 if(d) { /* apply XOR'ed difference */
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
288 out = output + x * 3;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
289 for(j = 0; j < bh2; j++){
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
290 for(i = 0; i < bw2; i++) {
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
291 out[i * 3 + 0] ^= *src++;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
292 out[i * 3 + 1] ^= *src++;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
293 out[i * 3 + 2] ^= *src++;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
294 }
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
295 out += stride;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
296 }
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
297 }
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
298 }
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
299 output += stride * c->bh;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
300 prev += stride * c->bh;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
301 }
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
302 if(src - c->decomp_buf != c->decomp_len)
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
303 av_log(c->avctx, AV_LOG_ERROR, "Used %i of %i bytes\n", src-c->decomp_buf, c->decomp_len);
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
304 return 0;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
305 }
3134
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
306 #endif //ZMBV_ENABLE_24BPP
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
307
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
308 /**
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
309 * Decode XOR'ed frame - 32bpp version
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
310 */
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
311
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
312 static int zmbv_decode_xor_32(ZmbvContext *c)
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
313 {
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
314 uint8_t *src = c->decomp_buf;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
315 uint32_t *output, *prev;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
316 int8_t *mvec;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
317 int x, y;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
318 int d, dx, dy, bw2, bh2;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
319 int block;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
320 int i, j;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
321 int mx, my;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
322
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
323 output = (uint32_t*)c->cur;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
324 prev = (uint32_t*)c->prev;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
325
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
326 mvec = (int8_t*)src;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
327 src += ((c->bx * c->by * 2 + 3) & ~3);
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
328
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
329 block = 0;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
330 for(y = 0; y < c->height; y += c->bh) {
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
331 bh2 = ((c->height - y) > c->bh) ? c->bh : (c->height - y);
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
332 for(x = 0; x < c->width; x += c->bw) {
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
333 uint32_t *out, *tprev;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
334
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
335 d = mvec[block] & 1;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
336 dx = mvec[block] >> 1;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
337 dy = mvec[block + 1] >> 1;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
338 block += 2;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
339
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
340 bw2 = ((c->width - x) > c->bw) ? c->bw : (c->width - x);
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
341
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
342 /* copy block - motion vectors out of bounds are used to zero blocks */
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
343 out = output + x;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
344 tprev = prev + x + dx + dy * c->width;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
345 mx = x + dx;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
346 my = y + dy;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
347 for(j = 0; j < bh2; j++){
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
348 if((my + j < 0) || (my + j >= c->height)) {
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
349 memset(out, 0, bw2 * 4);
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
350 } else {
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
351 for(i = 0; i < bw2; i++){
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
352 if((mx + i < 0) || (mx + i >= c->width))
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
353 out[i] = 0;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
354 else
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
355 out[i] = tprev[i];
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
356 }
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
357 }
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
358 out += c->width;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
359 tprev += c->width;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
360 }
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
361
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
362 if(d) { /* apply XOR'ed difference */
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
363 out = output + x;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
364 for(j = 0; j < bh2; j++){
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
365 for(i = 0; i < bw2; i++) {
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
366 out[i] ^= *((uint32_t*)src);
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
367 src += 4;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
368 }
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
369 out += c->width;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
370 }
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
371 }
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
372 }
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
373 output += c->width * c->bh;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
374 prev += c->width * c->bh;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
375 }
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
376 if(src - c->decomp_buf != c->decomp_len)
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
377 av_log(c->avctx, AV_LOG_ERROR, "Used %i of %i bytes\n", src-c->decomp_buf, c->decomp_len);
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
378 return 0;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
379 }
3120
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
380
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
381 /**
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
382 * Decode intraframe
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
383 */
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
384 static int zmbv_decode_intra(ZmbvContext *c)
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
385 {
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
386 uint8_t *src = c->decomp_buf;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
387
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
388 /* make the palette available on the way out */
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
389 if (c->fmt == ZMBV_FMT_8BPP) {
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
390 memcpy(c->pal, src, 768);
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
391 src += 768;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
392 }
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
393
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
394 memcpy(c->cur, src, c->width * c->height * (c->bpp / 8));
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
395 return 0;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
396 }
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
397
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
398 static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8_t *buf, int buf_size)
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
399 {
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
400 ZmbvContext * const c = (ZmbvContext *)avctx->priv_data;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
401 uint8_t *outptr;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
402 #ifdef CONFIG_ZLIB
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
403 int zret = Z_OK; // Zlib return code
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
404 #endif
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
405 int len = buf_size;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
406 int hi_ver, lo_ver;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
407
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
408 if(c->pic.data[0])
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
409 avctx->release_buffer(avctx, &c->pic);
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
410
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
411 c->pic.reference = 1;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
412 c->pic.buffer_hints = FF_BUFFER_HINTS_VALID;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
413 if(avctx->get_buffer(avctx, &c->pic) < 0){
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
414 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
415 return -1;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
416 }
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
417
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
418 outptr = c->pic.data[0]; // Output image pointer
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
419
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
420 /* parse header */
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
421 c->flags = buf[0];
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
422 buf++; len--;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
423 if(c->flags & ZMBV_KEYFRAME) {
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
424 hi_ver = buf[0];
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
425 lo_ver = buf[1];
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
426 c->comp = buf[2];
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
427 c->fmt = buf[3];
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
428 c->bw = buf[4];
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
429 c->bh = buf[5];
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
430
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
431 buf += 6;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
432 len -= 6;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
433 av_log(avctx, AV_LOG_DEBUG, "Flags=%X ver=%i.%i comp=%i fmt=%i blk=%ix%i\n",c->flags,hi_ver,lo_ver,c->comp,c->fmt,c->bw,c->bh);
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
434 if(hi_ver != 0 || lo_ver != 1) {
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
435 av_log(avctx, AV_LOG_ERROR, "Unsupported version %i.%i\n", hi_ver, lo_ver);
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
436 return -1;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
437 }
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
438 if(c->bw == 0 || c->bh == 0) {
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
439 av_log(avctx, AV_LOG_ERROR, "Unsupported block size %ix%i\n", c->bw, c->bh);
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
440 }
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
441 if(c->comp != 0 && c->comp != 1) {
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
442 av_log(avctx, AV_LOG_ERROR, "Unsupported compression type %i\n", c->comp);
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
443 return -1;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
444 }
3134
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
445
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
446 switch(c->fmt) {
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
447 case ZMBV_FMT_8BPP:
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
448 c->bpp = 8;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
449 c->decode_intra = zmbv_decode_intra;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
450 c->decode_xor = zmbv_decode_xor_8;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
451 break;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
452 case ZMBV_FMT_15BPP:
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
453 case ZMBV_FMT_16BPP:
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
454 c->bpp = 16;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
455 c->decode_intra = zmbv_decode_intra;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
456 c->decode_xor = zmbv_decode_xor_16;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
457 break;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
458 #ifdef ZMBV_ENABLE_24BPP
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
459 case ZMBV_FMT_24BPP:
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
460 c->bpp = 24;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
461 c->decode_intra = zmbv_decode_intra;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
462 c->decode_xor = zmbv_decode_xor_24;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
463 break;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
464 #endif //ZMBV_ENABLE_24BPP
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
465 case ZMBV_FMT_32BPP:
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
466 c->bpp = 32;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
467 c->decode_intra = zmbv_decode_intra;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
468 c->decode_xor = zmbv_decode_xor_32;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
469 break;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
470 default:
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
471 c->decode_intra = NULL;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
472 c->decode_xor = NULL;
3120
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
473 av_log(avctx, AV_LOG_ERROR, "Unsupported (for now) format %i\n", c->fmt);
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
474 return -1;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
475 }
3122
d57bf6a15b04 add another set of zlib guards
melanson
parents: 3120
diff changeset
476 #ifdef CONFIG_ZLIB
3120
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
477 zret = inflateReset(&c->zstream);
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
478 if (zret != Z_OK) {
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
479 av_log(avctx, AV_LOG_ERROR, "Inflate reset error: %d\n", zret);
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
480 return -1;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
481 }
3122
d57bf6a15b04 add another set of zlib guards
melanson
parents: 3120
diff changeset
482 #else
d57bf6a15b04 add another set of zlib guards
melanson
parents: 3120
diff changeset
483 av_log(avctx, AV_LOG_ERROR, "BUG! Zlib support not compiled in frame decoder.\n");
d57bf6a15b04 add another set of zlib guards
melanson
parents: 3120
diff changeset
484 return -1;
d57bf6a15b04 add another set of zlib guards
melanson
parents: 3120
diff changeset
485 #endif /* CONFIG_ZLIB */
3120
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
486 c->cur = av_realloc(c->cur, avctx->width * avctx->height * (c->bpp / 8));
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
487 c->prev = av_realloc(c->prev, avctx->width * avctx->height * (c->bpp / 8));
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
488 c->bx = (c->width + c->bw - 1) / c->bw;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
489 c->by = (c->height+ c->bh - 1) / c->bh;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
490 }
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
491
3134
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
492 if(c->decode_intra == NULL) {
3120
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
493 av_log(avctx, AV_LOG_ERROR, "Error! Got no format or no keyframe!\n");
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
494 return -1;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
495 }
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
496
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
497 if(c->comp == 0) { //Uncompressed data
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
498 memcpy(c->decomp_buf, buf, len);
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
499 c->decomp_size = 1;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
500 } else { // ZLIB-compressed data
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
501 #ifdef CONFIG_ZLIB
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
502 c->zstream.total_in = c->zstream.total_out = 0;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
503 c->zstream.next_in = buf;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
504 c->zstream.avail_in = len;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
505 c->zstream.next_out = c->decomp_buf;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
506 c->zstream.avail_out = c->decomp_size;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
507 inflate(&c->zstream, Z_FINISH);
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
508 c->decomp_len = c->zstream.total_out;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
509 #else
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
510 av_log(avctx, AV_LOG_ERROR, "BUG! Zlib support not compiled in frame decoder.\n");
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
511 return -1;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
512 #endif
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
513 }
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
514 if(c->flags & ZMBV_KEYFRAME) {
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
515 c->pic.key_frame = 1;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
516 c->pic.pict_type = FF_I_TYPE;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
517 c->decode_intra(c);
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
518 } else {
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
519 c->pic.key_frame = 0;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
520 c->pic.pict_type = FF_P_TYPE;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
521 c->decode_xor(c);
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
522 }
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
523
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
524 /* update frames */
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
525 {
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
526 uint8_t *out, *src;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
527 int i, j;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
528
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
529 out = c->pic.data[0];
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
530 src = c->cur;
3134
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
531 switch(c->fmt) {
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
532 case ZMBV_FMT_8BPP:
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
533 for(j = 0; j < c->height; j++) {
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
534 for(i = 0; i < c->width; i++) {
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
535 out[i * 3 + 0] = c->pal[(*src) * 3 + 0];
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
536 out[i * 3 + 1] = c->pal[(*src) * 3 + 1];
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
537 out[i * 3 + 2] = c->pal[(*src) * 3 + 2];
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
538 *src++;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
539 }
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
540 out += c->pic.linesize[0];
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
541 }
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
542 break;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
543 case ZMBV_FMT_15BPP:
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
544 for(j = 0; j < c->height; j++) {
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
545 for(i = 0; i < c->width; i++) {
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
546 uint16_t tmp = LE_16(src);
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
547 src += 2;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
548 out[i * 3 + 0] = (tmp & 0x7C00) >> 7;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
549 out[i * 3 + 1] = (tmp & 0x03E0) >> 2;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
550 out[i * 3 + 2] = (tmp & 0x001F) << 3;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
551 }
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
552 out += c->pic.linesize[0];
3120
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
553 }
3134
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
554 break;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
555 case ZMBV_FMT_16BPP:
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
556 for(j = 0; j < c->height; j++) {
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
557 for(i = 0; i < c->width; i++) {
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
558 uint16_t tmp = LE_16(src);
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
559 src += 2;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
560 out[i * 3 + 0] = (tmp & 0xF800) >> 8;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
561 out[i * 3 + 1] = (tmp & 0x07E0) >> 3;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
562 out[i * 3 + 2] = (tmp & 0x001F) << 3;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
563 }
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
564 out += c->pic.linesize[0];
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
565 }
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
566 break;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
567 #ifdef ZMBV_ENABLE_24BPP
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
568 case ZMBV_FMT_24BPP:
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
569 for(j = 0; j < c->height; j++) {
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
570 memcpy(out, src, c->width * 3);
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
571 src += c->width * 3;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
572 out += c->pic.linesize[0];
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
573 }
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
574 break;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
575 #endif //ZMBV_ENABLE_24BPP
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
576 case ZMBV_FMT_32BPP:
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
577 for(j = 0; j < c->height; j++) {
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
578 for(i = 0; i < c->width; i++) {
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
579 uint32_t tmp = LE_32(src);
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
580 src += 4;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
581 out[i * 3 + 0] = tmp >> 16;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
582 out[i * 3 + 1] = tmp >> 8;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
583 out[i * 3 + 2] = tmp >> 0;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
584 }
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
585 out += c->pic.linesize[0];
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
586 }
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
587 break;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
588 default:
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
589 av_log(avctx, AV_LOG_ERROR, "Cannot handle format %i\n", c->fmt);
3120
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
590 }
3134
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
591 memcpy(c->prev, c->cur, c->width * c->height * (c->bpp / 8));
3120
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
592 }
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
593 *data_size = sizeof(AVFrame);
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
594 *(AVFrame*)data = c->pic;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
595
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
596 /* always report that the buffer was completely consumed */
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
597 return buf_size;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
598 }
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
599
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
600
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
601
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
602 /*
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
603 *
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
604 * Init zmbv decoder
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
605 *
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
606 */
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
607 static int decode_init(AVCodecContext *avctx)
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
608 {
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
609 ZmbvContext * const c = (ZmbvContext *)avctx->priv_data;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
610 int zret; // Zlib return code
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
611
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
612 c->avctx = avctx;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
613 avctx->has_b_frames = 0;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
614
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
615 c->pic.data[0] = NULL;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
616 c->width = avctx->width;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
617 c->height = avctx->height;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
618
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
619 if (avcodec_check_dimensions(avctx, avctx->height, avctx->width) < 0) {
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
620 return 1;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
621 }
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
622 c->bpp = avctx->bits_per_sample;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
623
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
624 #ifdef CONFIG_ZLIB
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
625 // Needed if zlib unused or init aborted before inflateInit
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
626 memset(&(c->zstream), 0, sizeof(z_stream));
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
627 #else
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
628 av_log(avctx, AV_LOG_ERROR, "Zlib support not compiled.\n");
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
629 return 1;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
630 #endif
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
631 avctx->pix_fmt = PIX_FMT_RGB24;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
632 c->decomp_size = (avctx->width + 255) * 4 * (avctx->height + 64);
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
633
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
634 /* Allocate decompression buffer */
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
635 if (c->decomp_size) {
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
636 if ((c->decomp_buf = av_malloc(c->decomp_size)) == NULL) {
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
637 av_log(avctx, AV_LOG_ERROR, "Can't allocate decompression buffer.\n");
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
638 return 1;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
639 }
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
640 }
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
641
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
642 #ifdef CONFIG_ZLIB
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
643 c->zstream.zalloc = Z_NULL;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
644 c->zstream.zfree = Z_NULL;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
645 c->zstream.opaque = Z_NULL;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
646 zret = inflateInit(&(c->zstream));
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
647 if (zret != Z_OK) {
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
648 av_log(avctx, AV_LOG_ERROR, "Inflate init error: %d\n", zret);
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
649 return 1;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
650 }
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
651 #endif
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
652
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
653 return 0;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
654 }
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
655
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
656
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
657
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
658 /*
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
659 *
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
660 * Uninit zmbv decoder
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
661 *
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
662 */
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
663 static int decode_end(AVCodecContext *avctx)
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
664 {
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
665 ZmbvContext * const c = (ZmbvContext *)avctx->priv_data;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
666
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
667 av_freep(&c->decomp_buf);
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
668
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
669 if (c->pic.data[0])
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
670 avctx->release_buffer(avctx, &c->pic);
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
671 #ifdef CONFIG_ZLIB
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
672 inflateEnd(&(c->zstream));
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
673 #endif
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
674 if(c->cur)
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
675 av_freep(&c->cur);
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
676 if(c->prev)
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
677 av_freep(&c->prev);
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
678
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
679 return 0;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
680 }
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
681
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
682 AVCodec zmbv_decoder = {
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
683 "zmbv",
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
684 CODEC_TYPE_VIDEO,
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
685 CODEC_ID_ZMBV,
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
686 sizeof(ZmbvContext),
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
687 decode_init,
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
688 NULL,
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
689 decode_end,
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
690 decode_frame
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
691 };
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
692