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