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