Mercurial > libavcodec.hg
annotate lcl.c @ 5131:757efe20a3c8 libavcodec
Blackfin dct_quantize_bfin routine
2x performance boost in performing quantization for mpeg encoding
author | mhoffman |
---|---|
date | Tue, 12 Jun 2007 19:13:50 +0000 |
parents | bff60ecc02f9 |
children | 2b72f9bc4f06 |
rev | line source |
---|---|
1743 | 1 /* |
2 * LCL (LossLess Codec Library) Codec | |
3 * Copyright (c) 2002-2004 Roberto Togni | |
4 * | |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3777
diff
changeset
|
5 * This file is part of FFmpeg. |
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3777
diff
changeset
|
6 * |
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3777
diff
changeset
|
7 * FFmpeg is free software; you can redistribute it and/or |
1743 | 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:
3777
diff
changeset
|
10 * version 2.1 of the License, or (at your option) any later version. |
1743 | 11 * |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3777
diff
changeset
|
12 * FFmpeg is distributed in the hope that it will be useful, |
1743 | 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:
3777
diff
changeset
|
18 * License along with FFmpeg; if not, write to the Free Software |
3036
0b546eab515d
Update licensing information: The FSF changed postal address.
diego
parents:
2979
diff
changeset
|
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
1743 | 20 * |
21 */ | |
22 | |
23 /** | |
24 * @file lcl.c | |
25 * LCL (LossLess Codec Library) Video Codec | |
26 * Decoder for MSZH and ZLIB codecs | |
27 * Experimental encoder for ZLIB RGB24 | |
28 * | |
29 * Fourcc: MSZH, ZLIB | |
30 * | |
31 * Original Win32 dll: | |
32 * Ver2.23 By Kenji Oshima 2000.09.20 | |
33 * avimszh.dll, avizlib.dll | |
34 * | |
35 * A description of the decoding algorithm can be found here: | |
36 * http://www.pcisys.net/~melanson/codecs | |
37 * | |
38 * Supports: BGR24 (RGB 24bpp) | |
39 * | |
40 */ | |
41 | |
42 #include <stdio.h> | |
43 #include <stdlib.h> | |
44 | |
4962
f99e40a7155b
Remove redundant #inclusion of common.h, avcodec.h already #includes it.
diego
parents:
4827
diff
changeset
|
45 #include "avcodec.h" |
2398
582e635cfa08
common.c -> bitstream.c (and the single non bitstream func -> utils.c)
michael
parents:
2250
diff
changeset
|
46 #include "bitstream.h" |
1743 | 47 |
48 #ifdef CONFIG_ZLIB | |
49 #include <zlib.h> | |
50 #endif | |
51 | |
52 | |
53 #define BMPTYPE_YUV 1 | |
54 #define BMPTYPE_RGB 2 | |
55 | |
56 #define IMGTYPE_YUV111 0 | |
57 #define IMGTYPE_YUV422 1 | |
58 #define IMGTYPE_RGB24 2 | |
59 #define IMGTYPE_YUV411 3 | |
60 #define IMGTYPE_YUV211 4 | |
61 #define IMGTYPE_YUV420 5 | |
62 | |
63 #define COMP_MSZH 0 | |
64 #define COMP_MSZH_NOCOMP 1 | |
65 #define COMP_ZLIB_HISPEED 1 | |
66 #define COMP_ZLIB_HICOMP 9 | |
67 #define COMP_ZLIB_NORMAL -1 | |
68 | |
69 #define FLAG_MULTITHREAD 1 | |
70 #define FLAG_NULLFRAME 2 | |
71 #define FLAG_PNGFILTER 4 | |
72 #define FLAGMASK_UNUSED 0xf8 | |
73 | |
74 #define CODEC_MSZH 1 | |
75 #define CODEC_ZLIB 3 | |
76 | |
77 #define FOURCC_MSZH mmioFOURCC('M','S','Z','H') | |
78 #define FOURCC_ZLIB mmioFOURCC('Z','L','I','B') | |
79 | |
80 /* | |
81 * Decoder context | |
82 */ | |
83 typedef struct LclContext { | |
84 | |
2979 | 85 AVCodecContext *avctx; |
86 AVFrame pic; | |
1743 | 87 PutBitContext pb; |
88 | |
89 // Image type | |
90 int imgtype; | |
91 // Compression type | |
92 int compression; | |
93 // Flags | |
94 int flags; | |
95 // Decompressed data size | |
96 unsigned int decomp_size; | |
97 // Decompression buffer | |
98 unsigned char* decomp_buf; | |
99 // Maximum compressed data size | |
100 unsigned int max_comp_size; | |
101 // Compression buffer | |
102 unsigned char* comp_buf; | |
103 #ifdef CONFIG_ZLIB | |
104 z_stream zstream; | |
105 #endif | |
106 } LclContext; | |
107 | |
108 | |
109 /* | |
110 * | |
111 * Helper functions | |
112 * | |
113 */ | |
114 static inline unsigned char fix (int pix14) | |
115 { | |
116 int tmp; | |
117 | |
118 tmp = (pix14 + 0x80000) >> 20; | |
119 if (tmp < 0) | |
120 return 0; | |
121 if (tmp > 255) | |
122 return 255; | |
123 return tmp; | |
124 } | |
125 | |
126 | |
127 | |
128 static inline unsigned char get_b (unsigned char yq, signed char bq) | |
129 { | |
130 return fix((yq << 20) + bq * 1858076); | |
131 } | |
132 | |
133 | |
134 | |
135 static inline unsigned char get_g (unsigned char yq, signed char bq, signed char rq) | |
136 { | |
137 return fix((yq << 20) - bq * 360857 - rq * 748830); | |
138 } | |
139 | |
140 | |
141 | |
142 static inline unsigned char get_r (unsigned char yq, signed char rq) | |
143 { | |
144 return fix((yq << 20) + rq * 1470103); | |
145 } | |
146 | |
147 | |
148 | |
2418
82af834636c2
Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents:
2398
diff
changeset
|
149 static unsigned int mszh_decomp(unsigned char * srcptr, int srclen, unsigned char * destptr, unsigned int destsize) |
1743 | 150 { |
151 unsigned char *destptr_bak = destptr; | |
2418
82af834636c2
Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents:
2398
diff
changeset
|
152 unsigned char *destptr_end = destptr + destsize; |
1743 | 153 unsigned char mask = 0; |
154 unsigned char maskbit = 0; | |
155 unsigned int ofs, cnt; | |
2967 | 156 |
2418
82af834636c2
Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents:
2398
diff
changeset
|
157 while ((srclen > 0) && (destptr < destptr_end)) { |
1743 | 158 if (maskbit == 0) { |
159 mask = *(srcptr++); | |
160 maskbit = 8; | |
161 srclen--; | |
162 continue; | |
163 } | |
164 if ((mask & (1 << (--maskbit))) == 0) { | |
2418
82af834636c2
Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents:
2398
diff
changeset
|
165 if (destptr + 4 > destptr_end) |
82af834636c2
Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents:
2398
diff
changeset
|
166 break; |
1743 | 167 *(int*)destptr = *(int*)srcptr; |
168 srclen -= 4; | |
169 destptr += 4; | |
170 srcptr += 4; | |
171 } else { | |
172 ofs = *(srcptr++); | |
173 cnt = *(srcptr++); | |
174 ofs += cnt * 256;; | |
175 cnt = ((cnt >> 3) & 0x1f) + 1; | |
176 ofs &= 0x7ff; | |
177 srclen -= 2; | |
178 cnt *= 4; | |
2418
82af834636c2
Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents:
2398
diff
changeset
|
179 if (destptr + cnt > destptr_end) { |
82af834636c2
Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents:
2398
diff
changeset
|
180 cnt = destptr_end - destptr; |
82af834636c2
Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents:
2398
diff
changeset
|
181 } |
1743 | 182 for (; cnt > 0; cnt--) { |
183 *(destptr) = *(destptr - ofs); | |
184 destptr++; | |
185 } | |
186 } | |
187 } | |
188 | |
189 return (destptr - destptr_bak); | |
190 } | |
191 | |
192 | |
193 | |
3777 | 194 #ifdef CONFIG_DECODERS |
1743 | 195 /* |
196 * | |
197 * Decode a frame | |
198 * | |
199 */ | |
200 static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8_t *buf, int buf_size) | |
201 { | |
4827 | 202 LclContext * const c = avctx->priv_data; |
2979 | 203 unsigned char *encoded = (unsigned char *)buf; |
2418
82af834636c2
Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents:
2398
diff
changeset
|
204 unsigned int pixel_ptr; |
1743 | 205 int row, col; |
206 unsigned char *outptr; | |
207 unsigned int width = avctx->width; // Real image width | |
208 unsigned int height = avctx->height; // Real image height | |
209 unsigned int mszh_dlen; | |
210 unsigned char yq, y1q, uq, vq; | |
211 int uqvq; | |
212 unsigned int mthread_inlen, mthread_outlen; | |
213 #ifdef CONFIG_ZLIB | |
214 int zret; // Zlib return code | |
215 #endif | |
2418
82af834636c2
Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents:
2398
diff
changeset
|
216 unsigned int len = buf_size; |
1743 | 217 |
2979 | 218 if(c->pic.data[0]) |
219 avctx->release_buffer(avctx, &c->pic); | |
1743 | 220 |
2979 | 221 c->pic.reference = 0; |
222 c->pic.buffer_hints = FF_BUFFER_HINTS_VALID; | |
223 if(avctx->get_buffer(avctx, &c->pic) < 0){ | |
224 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); | |
225 return -1; | |
226 } | |
1743 | 227 |
228 outptr = c->pic.data[0]; // Output image pointer | |
229 | |
230 /* Decompress frame */ | |
231 switch (avctx->codec_id) { | |
232 case CODEC_ID_MSZH: | |
233 switch (c->compression) { | |
234 case COMP_MSZH: | |
235 if (c->flags & FLAG_MULTITHREAD) { | |
236 mthread_inlen = *((unsigned int*)encoded); | |
237 mthread_outlen = *((unsigned int*)(encoded+4)); | |
2418
82af834636c2
Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents:
2398
diff
changeset
|
238 if (mthread_outlen > c->decomp_size) // this should not happen |
82af834636c2
Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents:
2398
diff
changeset
|
239 mthread_outlen = c->decomp_size; |
82af834636c2
Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents:
2398
diff
changeset
|
240 mszh_dlen = mszh_decomp(encoded + 8, mthread_inlen, c->decomp_buf, c->decomp_size); |
1743 | 241 if (mthread_outlen != mszh_dlen) { |
242 av_log(avctx, AV_LOG_ERROR, "Mthread1 decoded size differs (%d != %d)\n", | |
243 mthread_outlen, mszh_dlen); | |
2418
82af834636c2
Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents:
2398
diff
changeset
|
244 return -1; |
1743 | 245 } |
246 mszh_dlen = mszh_decomp(encoded + 8 + mthread_inlen, len - mthread_inlen, | |
2418
82af834636c2
Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents:
2398
diff
changeset
|
247 c->decomp_buf + mthread_outlen, c->decomp_size - mthread_outlen); |
82af834636c2
Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents:
2398
diff
changeset
|
248 if (mthread_outlen != mszh_dlen) { |
1743 | 249 av_log(avctx, AV_LOG_ERROR, "Mthread2 decoded size differs (%d != %d)\n", |
2418
82af834636c2
Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents:
2398
diff
changeset
|
250 mthread_outlen, mszh_dlen); |
82af834636c2
Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents:
2398
diff
changeset
|
251 return -1; |
1743 | 252 } |
253 encoded = c->decomp_buf; | |
254 len = c->decomp_size; | |
255 } else { | |
2418
82af834636c2
Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents:
2398
diff
changeset
|
256 mszh_dlen = mszh_decomp(encoded, len, c->decomp_buf, c->decomp_size); |
1743 | 257 if (c->decomp_size != mszh_dlen) { |
258 av_log(avctx, AV_LOG_ERROR, "Decoded size differs (%d != %d)\n", | |
259 c->decomp_size, mszh_dlen); | |
2418
82af834636c2
Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents:
2398
diff
changeset
|
260 return -1; |
1743 | 261 } |
262 encoded = c->decomp_buf; | |
263 len = mszh_dlen; | |
264 } | |
265 break; | |
266 case COMP_MSZH_NOCOMP: | |
267 break; | |
268 default: | |
269 av_log(avctx, AV_LOG_ERROR, "BUG! Unknown MSZH compression in frame decoder.\n"); | |
270 return -1; | |
271 } | |
272 break; | |
273 case CODEC_ID_ZLIB: | |
274 #ifdef CONFIG_ZLIB | |
275 /* Using the original dll with normal compression (-1) and RGB format | |
276 * gives a file with ZLIB fourcc, but frame is really uncompressed. | |
277 * To be sure that's true check also frame size */ | |
278 if ((c->compression == COMP_ZLIB_NORMAL) && (c->imgtype == IMGTYPE_RGB24) && | |
279 (len == width * height * 3)) | |
280 break; | |
281 zret = inflateReset(&(c->zstream)); | |
282 if (zret != Z_OK) { | |
283 av_log(avctx, AV_LOG_ERROR, "Inflate reset error: %d\n", zret); | |
284 return -1; | |
285 } | |
286 if (c->flags & FLAG_MULTITHREAD) { | |
287 mthread_inlen = *((unsigned int*)encoded); | |
288 mthread_outlen = *((unsigned int*)(encoded+4)); | |
2418
82af834636c2
Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents:
2398
diff
changeset
|
289 if (mthread_outlen > c->decomp_size) |
82af834636c2
Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents:
2398
diff
changeset
|
290 mthread_outlen = c->decomp_size; |
1743 | 291 c->zstream.next_in = encoded + 8; |
292 c->zstream.avail_in = mthread_inlen; | |
293 c->zstream.next_out = c->decomp_buf; | |
2967 | 294 c->zstream.avail_out = c->decomp_size; |
1743 | 295 zret = inflate(&(c->zstream), Z_FINISH); |
296 if ((zret != Z_OK) && (zret != Z_STREAM_END)) { | |
297 av_log(avctx, AV_LOG_ERROR, "Mthread1 inflate error: %d\n", zret); | |
298 return -1; | |
299 } | |
300 if (mthread_outlen != (unsigned int)(c->zstream.total_out)) { | |
301 av_log(avctx, AV_LOG_ERROR, "Mthread1 decoded size differs (%u != %lu)\n", | |
302 mthread_outlen, c->zstream.total_out); | |
2418
82af834636c2
Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents:
2398
diff
changeset
|
303 return -1; |
1743 | 304 } |
305 zret = inflateReset(&(c->zstream)); | |
306 if (zret != Z_OK) { | |
307 av_log(avctx, AV_LOG_ERROR, "Mthread2 inflate reset error: %d\n", zret); | |
308 return -1; | |
309 } | |
310 c->zstream.next_in = encoded + 8 + mthread_inlen; | |
311 c->zstream.avail_in = len - mthread_inlen; | |
312 c->zstream.next_out = c->decomp_buf + mthread_outlen; | |
2967 | 313 c->zstream.avail_out = c->decomp_size - mthread_outlen; |
1743 | 314 zret = inflate(&(c->zstream), Z_FINISH); |
315 if ((zret != Z_OK) && (zret != Z_STREAM_END)) { | |
316 av_log(avctx, AV_LOG_ERROR, "Mthread2 inflate error: %d\n", zret); | |
317 return -1; | |
318 } | |
2418
82af834636c2
Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents:
2398
diff
changeset
|
319 if (mthread_outlen != (unsigned int)(c->zstream.total_out)) { |
1743 | 320 av_log(avctx, AV_LOG_ERROR, "Mthread2 decoded size differs (%d != %lu)\n", |
2418
82af834636c2
Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents:
2398
diff
changeset
|
321 mthread_outlen, c->zstream.total_out); |
82af834636c2
Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents:
2398
diff
changeset
|
322 return -1; |
1743 | 323 } |
324 } else { | |
325 c->zstream.next_in = encoded; | |
326 c->zstream.avail_in = len; | |
327 c->zstream.next_out = c->decomp_buf; | |
328 c->zstream.avail_out = c->decomp_size; | |
329 zret = inflate(&(c->zstream), Z_FINISH); | |
330 if ((zret != Z_OK) && (zret != Z_STREAM_END)) { | |
331 av_log(avctx, AV_LOG_ERROR, "Inflate error: %d\n", zret); | |
332 return -1; | |
333 } | |
334 if (c->decomp_size != (unsigned int)(c->zstream.total_out)) { | |
335 av_log(avctx, AV_LOG_ERROR, "Decoded size differs (%d != %lu)\n", | |
336 c->decomp_size, c->zstream.total_out); | |
2418
82af834636c2
Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents:
2398
diff
changeset
|
337 return -1; |
1743 | 338 } |
339 } | |
340 encoded = c->decomp_buf; | |
341 len = c->decomp_size;; | |
342 #else | |
343 av_log(avctx, AV_LOG_ERROR, "BUG! Zlib support not compiled in frame decoder.\n"); | |
344 return -1; | |
345 #endif | |
346 break; | |
347 default: | |
348 av_log(avctx, AV_LOG_ERROR, "BUG! Unknown codec in frame decoder compression switch.\n"); | |
349 return -1; | |
350 } | |
351 | |
352 | |
353 /* Apply PNG filter */ | |
354 if ((avctx->codec_id == CODEC_ID_ZLIB) && (c->flags & FLAG_PNGFILTER)) { | |
355 switch (c->imgtype) { | |
356 case IMGTYPE_YUV111: | |
357 case IMGTYPE_RGB24: | |
358 for (row = 0; row < height; row++) { | |
359 pixel_ptr = row * width * 3; | |
360 yq = encoded[pixel_ptr++]; | |
5089 | 361 uqvq = AV_RL16(encoded+pixel_ptr); |
362 pixel_ptr += 2; | |
1743 | 363 for (col = 1; col < width; col++) { |
364 encoded[pixel_ptr] = yq -= encoded[pixel_ptr]; | |
5089 | 365 uqvq -= AV_RL16(encoded+pixel_ptr+1); |
366 AV_WL16(encoded+pixel_ptr+1, uqvq); | |
1743 | 367 pixel_ptr += 3; |
368 } | |
369 } | |
370 break; | |
371 case IMGTYPE_YUV422: | |
372 for (row = 0; row < height; row++) { | |
373 pixel_ptr = row * width * 2; | |
374 yq = uq = vq =0; | |
375 for (col = 0; col < width/4; col++) { | |
376 encoded[pixel_ptr] = yq -= encoded[pixel_ptr]; | |
377 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1]; | |
378 encoded[pixel_ptr+2] = yq -= encoded[pixel_ptr+2]; | |
379 encoded[pixel_ptr+3] = yq -= encoded[pixel_ptr+3]; | |
380 encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4]; | |
381 encoded[pixel_ptr+5] = uq -= encoded[pixel_ptr+5]; | |
382 encoded[pixel_ptr+6] = vq -= encoded[pixel_ptr+6]; | |
383 encoded[pixel_ptr+7] = vq -= encoded[pixel_ptr+7]; | |
384 pixel_ptr += 8; | |
385 } | |
386 } | |
387 break; | |
388 case IMGTYPE_YUV411: | |
389 for (row = 0; row < height; row++) { | |
390 pixel_ptr = row * width / 2 * 3; | |
391 yq = uq = vq =0; | |
392 for (col = 0; col < width/4; col++) { | |
393 encoded[pixel_ptr] = yq -= encoded[pixel_ptr]; | |
394 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1]; | |
395 encoded[pixel_ptr+2] = yq -= encoded[pixel_ptr+2]; | |
396 encoded[pixel_ptr+3] = yq -= encoded[pixel_ptr+3]; | |
397 encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4]; | |
398 encoded[pixel_ptr+5] = vq -= encoded[pixel_ptr+5]; | |
399 pixel_ptr += 6; | |
400 } | |
401 } | |
402 break; | |
403 case IMGTYPE_YUV211: | |
404 for (row = 0; row < height; row++) { | |
405 pixel_ptr = row * width * 2; | |
406 yq = uq = vq =0; | |
407 for (col = 0; col < width/2; col++) { | |
408 encoded[pixel_ptr] = yq -= encoded[pixel_ptr]; | |
409 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1]; | |
410 encoded[pixel_ptr+2] = uq -= encoded[pixel_ptr+2]; | |
411 encoded[pixel_ptr+3] = vq -= encoded[pixel_ptr+3]; | |
412 pixel_ptr += 4; | |
413 } | |
414 } | |
415 break; | |
416 case IMGTYPE_YUV420: | |
417 for (row = 0; row < height/2; row++) { | |
418 pixel_ptr = row * width * 3; | |
419 yq = y1q = uq = vq =0; | |
420 for (col = 0; col < width/2; col++) { | |
421 encoded[pixel_ptr] = yq -= encoded[pixel_ptr]; | |
422 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1]; | |
423 encoded[pixel_ptr+2] = y1q -= encoded[pixel_ptr+2]; | |
424 encoded[pixel_ptr+3] = y1q -= encoded[pixel_ptr+3]; | |
425 encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4]; | |
426 encoded[pixel_ptr+5] = vq -= encoded[pixel_ptr+5]; | |
427 pixel_ptr += 6; | |
428 } | |
429 } | |
430 break; | |
431 default: | |
432 av_log(avctx, AV_LOG_ERROR, "BUG! Unknown imagetype in pngfilter switch.\n"); | |
433 return -1; | |
434 } | |
435 } | |
436 | |
437 /* Convert colorspace */ | |
438 switch (c->imgtype) { | |
439 case IMGTYPE_YUV111: | |
440 for (row = height - 1; row >= 0; row--) { | |
441 pixel_ptr = row * c->pic.linesize[0]; | |
442 for (col = 0; col < width; col++) { | |
443 outptr[pixel_ptr++] = get_b(encoded[0], encoded[1]); | |
444 outptr[pixel_ptr++] = get_g(encoded[0], encoded[1], encoded[2]); | |
445 outptr[pixel_ptr++] = get_r(encoded[0], encoded[2]); | |
446 encoded += 3; | |
447 } | |
448 } | |
449 break; | |
450 case IMGTYPE_YUV422: | |
451 for (row = height - 1; row >= 0; row--) { | |
452 pixel_ptr = row * c->pic.linesize[0]; | |
453 for (col = 0; col < width/4; col++) { | |
454 outptr[pixel_ptr++] = get_b(encoded[0], encoded[4]); | |
455 outptr[pixel_ptr++] = get_g(encoded[0], encoded[4], encoded[6]); | |
456 outptr[pixel_ptr++] = get_r(encoded[0], encoded[6]); | |
457 outptr[pixel_ptr++] = get_b(encoded[1], encoded[4]); | |
458 outptr[pixel_ptr++] = get_g(encoded[1], encoded[4], encoded[6]); | |
459 outptr[pixel_ptr++] = get_r(encoded[1], encoded[6]); | |
460 outptr[pixel_ptr++] = get_b(encoded[2], encoded[5]); | |
461 outptr[pixel_ptr++] = get_g(encoded[2], encoded[5], encoded[7]); | |
462 outptr[pixel_ptr++] = get_r(encoded[2], encoded[7]); | |
463 outptr[pixel_ptr++] = get_b(encoded[3], encoded[5]); | |
464 outptr[pixel_ptr++] = get_g(encoded[3], encoded[5], encoded[7]); | |
465 outptr[pixel_ptr++] = get_r(encoded[3], encoded[7]); | |
466 encoded += 8; | |
467 } | |
468 } | |
469 break; | |
470 case IMGTYPE_RGB24: | |
471 for (row = height - 1; row >= 0; row--) { | |
472 pixel_ptr = row * c->pic.linesize[0]; | |
473 for (col = 0; col < width; col++) { | |
474 outptr[pixel_ptr++] = encoded[0]; | |
475 outptr[pixel_ptr++] = encoded[1]; | |
476 outptr[pixel_ptr++] = encoded[2]; | |
477 encoded += 3; | |
478 } | |
479 } | |
480 break; | |
481 case IMGTYPE_YUV411: | |
482 for (row = height - 1; row >= 0; row--) { | |
483 pixel_ptr = row * c->pic.linesize[0]; | |
484 for (col = 0; col < width/4; col++) { | |
485 outptr[pixel_ptr++] = get_b(encoded[0], encoded[4]); | |
486 outptr[pixel_ptr++] = get_g(encoded[0], encoded[4], encoded[5]); | |
487 outptr[pixel_ptr++] = get_r(encoded[0], encoded[5]); | |
488 outptr[pixel_ptr++] = get_b(encoded[1], encoded[4]); | |
489 outptr[pixel_ptr++] = get_g(encoded[1], encoded[4], encoded[5]); | |
490 outptr[pixel_ptr++] = get_r(encoded[1], encoded[5]); | |
491 outptr[pixel_ptr++] = get_b(encoded[2], encoded[4]); | |
492 outptr[pixel_ptr++] = get_g(encoded[2], encoded[4], encoded[5]); | |
493 outptr[pixel_ptr++] = get_r(encoded[2], encoded[5]); | |
494 outptr[pixel_ptr++] = get_b(encoded[3], encoded[4]); | |
495 outptr[pixel_ptr++] = get_g(encoded[3], encoded[4], encoded[5]); | |
496 outptr[pixel_ptr++] = get_r(encoded[3], encoded[5]); | |
497 encoded += 6; | |
498 } | |
499 } | |
500 break; | |
501 case IMGTYPE_YUV211: | |
502 for (row = height - 1; row >= 0; row--) { | |
503 pixel_ptr = row * c->pic.linesize[0]; | |
504 for (col = 0; col < width/2; col++) { | |
505 outptr[pixel_ptr++] = get_b(encoded[0], encoded[2]); | |
506 outptr[pixel_ptr++] = get_g(encoded[0], encoded[2], encoded[3]); | |
507 outptr[pixel_ptr++] = get_r(encoded[0], encoded[3]); | |
508 outptr[pixel_ptr++] = get_b(encoded[1], encoded[2]); | |
509 outptr[pixel_ptr++] = get_g(encoded[1], encoded[2], encoded[3]); | |
510 outptr[pixel_ptr++] = get_r(encoded[1], encoded[3]); | |
511 encoded += 4; | |
512 } | |
513 } | |
514 break; | |
515 case IMGTYPE_YUV420: | |
516 for (row = height / 2 - 1; row >= 0; row--) { | |
517 pixel_ptr = 2 * row * c->pic.linesize[0]; | |
518 for (col = 0; col < width/2; col++) { | |
519 outptr[pixel_ptr] = get_b(encoded[0], encoded[4]); | |
520 outptr[pixel_ptr+1] = get_g(encoded[0], encoded[4], encoded[5]); | |
521 outptr[pixel_ptr+2] = get_r(encoded[0], encoded[5]); | |
522 outptr[pixel_ptr+3] = get_b(encoded[1], encoded[4]); | |
523 outptr[pixel_ptr+4] = get_g(encoded[1], encoded[4], encoded[5]); | |
524 outptr[pixel_ptr+5] = get_r(encoded[1], encoded[5]); | |
525 outptr[pixel_ptr-c->pic.linesize[0]] = get_b(encoded[2], encoded[4]); | |
526 outptr[pixel_ptr-c->pic.linesize[0]+1] = get_g(encoded[2], encoded[4], encoded[5]); | |
527 outptr[pixel_ptr-c->pic.linesize[0]+2] = get_r(encoded[2], encoded[5]); | |
528 outptr[pixel_ptr-c->pic.linesize[0]+3] = get_b(encoded[3], encoded[4]); | |
529 outptr[pixel_ptr-c->pic.linesize[0]+4] = get_g(encoded[3], encoded[4], encoded[5]); | |
530 outptr[pixel_ptr-c->pic.linesize[0]+5] = get_r(encoded[3], encoded[5]); | |
531 pixel_ptr += 6; | |
532 encoded += 6; | |
533 } | |
534 } | |
535 break; | |
536 default: | |
537 av_log(avctx, AV_LOG_ERROR, "BUG! Unknown imagetype in image decoder.\n"); | |
538 return -1; | |
539 } | |
540 | |
541 *data_size = sizeof(AVFrame); | |
542 *(AVFrame*)data = c->pic; | |
543 | |
544 /* always report that the buffer was completely consumed */ | |
545 return buf_size; | |
546 } | |
3777 | 547 #endif |
1743 | 548 |
3777 | 549 #ifdef CONFIG_ENCODERS |
1743 | 550 /* |
551 * | |
552 * Encode a frame | |
553 * | |
554 */ | |
555 static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){ | |
556 LclContext *c = avctx->priv_data; | |
557 AVFrame *pict = data; | |
558 AVFrame * const p = &c->pic; | |
559 int i; | |
560 int zret; // Zlib return code | |
561 | |
562 #ifndef CONFIG_ZLIB | |
563 av_log(avctx, AV_LOG_ERROR, "Zlib support not compiled in.\n"); | |
564 return -1; | |
565 #else | |
566 | |
567 init_put_bits(&c->pb, buf, buf_size); | |
2967 | 568 |
1743 | 569 *p = *pict; |
570 p->pict_type= FF_I_TYPE; | |
571 p->key_frame= 1; | |
2967 | 572 |
1743 | 573 if(avctx->pix_fmt != PIX_FMT_BGR24){ |
574 av_log(avctx, AV_LOG_ERROR, "Format not supported!\n"); | |
575 return -1; | |
576 } | |
577 | |
578 zret = deflateReset(&(c->zstream)); | |
579 if (zret != Z_OK) { | |
580 av_log(avctx, AV_LOG_ERROR, "Deflate reset error: %d\n", zret); | |
581 return -1; | |
582 } | |
583 c->zstream.next_out = c->comp_buf; | |
584 c->zstream.avail_out = c->max_comp_size; | |
585 | |
2250
902caf560c43
Zlib encoder: fix image orientation (was flipped), 100l in deflate error
rtognimp
parents:
2248
diff
changeset
|
586 for(i = avctx->height - 1; i >= 0; i--) { |
902caf560c43
Zlib encoder: fix image orientation (was flipped), 100l in deflate error
rtognimp
parents:
2248
diff
changeset
|
587 c->zstream.next_in = p->data[0]+p->linesize[0]*i; |
902caf560c43
Zlib encoder: fix image orientation (was flipped), 100l in deflate error
rtognimp
parents:
2248
diff
changeset
|
588 c->zstream.avail_in = avctx->width*3; |
902caf560c43
Zlib encoder: fix image orientation (was flipped), 100l in deflate error
rtognimp
parents:
2248
diff
changeset
|
589 zret = deflate(&(c->zstream), Z_NO_FLUSH); |
902caf560c43
Zlib encoder: fix image orientation (was flipped), 100l in deflate error
rtognimp
parents:
2248
diff
changeset
|
590 if (zret != Z_OK) { |
2979 | 591 av_log(avctx, AV_LOG_ERROR, "Deflate error: %d\n", zret); |
592 return -1; | |
2250
902caf560c43
Zlib encoder: fix image orientation (was flipped), 100l in deflate error
rtognimp
parents:
2248
diff
changeset
|
593 } |
902caf560c43
Zlib encoder: fix image orientation (was flipped), 100l in deflate error
rtognimp
parents:
2248
diff
changeset
|
594 } |
1743 | 595 zret = deflate(&(c->zstream), Z_FINISH); |
2250
902caf560c43
Zlib encoder: fix image orientation (was flipped), 100l in deflate error
rtognimp
parents:
2248
diff
changeset
|
596 if (zret != Z_STREAM_END) { |
1743 | 597 av_log(avctx, AV_LOG_ERROR, "Deflate error: %d\n", zret); |
598 return -1; | |
599 } | |
600 | |
601 for (i = 0; i < c->zstream.total_out; i++) | |
602 put_bits(&c->pb, 8, c->comp_buf[i]); | |
603 flush_put_bits(&c->pb); | |
604 | |
605 return c->zstream.total_out; | |
606 #endif | |
607 } | |
3777 | 608 #endif /* CONFIG_ENCODERS */ |
1743 | 609 |
3777 | 610 #ifdef CONFIG_DECODERS |
1743 | 611 /* |
612 * | |
613 * Init lcl decoder | |
614 * | |
615 */ | |
616 static int decode_init(AVCodecContext *avctx) | |
617 { | |
4827 | 618 LclContext * const c = avctx->priv_data; |
2418
82af834636c2
Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents:
2398
diff
changeset
|
619 unsigned int basesize = avctx->width * avctx->height; |
82af834636c2
Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents:
2398
diff
changeset
|
620 unsigned int max_basesize = ((avctx->width + 3) & ~3) * ((avctx->height + 3) & ~3); |
82af834636c2
Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents:
2398
diff
changeset
|
621 unsigned int max_decomp_size; |
1743 | 622 int zret; // Zlib return code |
623 | |
624 c->avctx = avctx; | |
625 | |
626 c->pic.data[0] = NULL; | |
627 | |
628 #ifdef CONFIG_ZLIB | |
629 // Needed if zlib unused or init aborted before inflateInit | |
2967 | 630 memset(&(c->zstream), 0, sizeof(z_stream)); |
1743 | 631 #endif |
632 | |
633 if (avctx->extradata_size < 8) { | |
634 av_log(avctx, AV_LOG_ERROR, "Extradata size too small.\n"); | |
635 return 1; | |
636 } | |
637 | |
2429
4b350cc506a7
Use avcodec_check_dimensions instead of custom hack
rtognimp
parents:
2418
diff
changeset
|
638 if (avcodec_check_dimensions(avctx, avctx->width, avctx->height) < 0) { |
2418
82af834636c2
Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents:
2398
diff
changeset
|
639 return 1; |
82af834636c2
Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents:
2398
diff
changeset
|
640 } |
82af834636c2
Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents:
2398
diff
changeset
|
641 |
2967 | 642 /* Check codec type */ |
1743 | 643 if (((avctx->codec_id == CODEC_ID_MSZH) && (*((char *)avctx->extradata + 7) != CODEC_MSZH)) || |
644 ((avctx->codec_id == CODEC_ID_ZLIB) && (*((char *)avctx->extradata + 7) != CODEC_ZLIB))) { | |
645 av_log(avctx, AV_LOG_ERROR, "Codec id and codec type mismatch. This should not happen.\n"); | |
646 } | |
647 | |
648 /* Detect image type */ | |
649 switch (c->imgtype = *((char *)avctx->extradata + 4)) { | |
650 case IMGTYPE_YUV111: | |
651 c->decomp_size = basesize * 3; | |
2418
82af834636c2
Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents:
2398
diff
changeset
|
652 max_decomp_size = max_basesize * 3; |
1743 | 653 av_log(avctx, AV_LOG_INFO, "Image type is YUV 1:1:1.\n"); |
654 break; | |
655 case IMGTYPE_YUV422: | |
656 c->decomp_size = basesize * 2; | |
2418
82af834636c2
Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents:
2398
diff
changeset
|
657 max_decomp_size = max_basesize * 2; |
1743 | 658 av_log(avctx, AV_LOG_INFO, "Image type is YUV 4:2:2.\n"); |
659 break; | |
660 case IMGTYPE_RGB24: | |
661 c->decomp_size = basesize * 3; | |
2418
82af834636c2
Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents:
2398
diff
changeset
|
662 max_decomp_size = max_basesize * 3; |
1743 | 663 av_log(avctx, AV_LOG_INFO, "Image type is RGB 24.\n"); |
664 break; | |
665 case IMGTYPE_YUV411: | |
666 c->decomp_size = basesize / 2 * 3; | |
2418
82af834636c2
Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents:
2398
diff
changeset
|
667 max_decomp_size = max_basesize / 2 * 3; |
1743 | 668 av_log(avctx, AV_LOG_INFO, "Image type is YUV 4:1:1.\n"); |
669 break; | |
670 case IMGTYPE_YUV211: | |
671 c->decomp_size = basesize * 2; | |
2418
82af834636c2
Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents:
2398
diff
changeset
|
672 max_decomp_size = max_basesize * 2; |
1743 | 673 av_log(avctx, AV_LOG_INFO, "Image type is YUV 2:1:1.\n"); |
674 break; | |
675 case IMGTYPE_YUV420: | |
676 c->decomp_size = basesize / 2 * 3; | |
2418
82af834636c2
Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents:
2398
diff
changeset
|
677 max_decomp_size = max_basesize / 2 * 3; |
1743 | 678 av_log(avctx, AV_LOG_INFO, "Image type is YUV 4:2:0.\n"); |
679 break; | |
680 default: | |
681 av_log(avctx, AV_LOG_ERROR, "Unsupported image format %d.\n", c->imgtype); | |
682 return 1; | |
683 } | |
684 | |
685 /* Detect compression method */ | |
686 c->compression = *((char *)avctx->extradata + 5); | |
687 switch (avctx->codec_id) { | |
688 case CODEC_ID_MSZH: | |
689 switch (c->compression) { | |
690 case COMP_MSZH: | |
691 av_log(avctx, AV_LOG_INFO, "Compression enabled.\n"); | |
692 break; | |
693 case COMP_MSZH_NOCOMP: | |
694 c->decomp_size = 0; | |
695 av_log(avctx, AV_LOG_INFO, "No compression.\n"); | |
696 break; | |
697 default: | |
698 av_log(avctx, AV_LOG_ERROR, "Unsupported compression format for MSZH (%d).\n", c->compression); | |
699 return 1; | |
700 } | |
701 break; | |
702 case CODEC_ID_ZLIB: | |
703 #ifdef CONFIG_ZLIB | |
704 switch (c->compression) { | |
705 case COMP_ZLIB_HISPEED: | |
706 av_log(avctx, AV_LOG_INFO, "High speed compression.\n"); | |
707 break; | |
708 case COMP_ZLIB_HICOMP: | |
709 av_log(avctx, AV_LOG_INFO, "High compression.\n"); | |
710 break; | |
711 case COMP_ZLIB_NORMAL: | |
712 av_log(avctx, AV_LOG_INFO, "Normal compression.\n"); | |
713 break; | |
714 default: | |
715 if ((c->compression < Z_NO_COMPRESSION) || (c->compression > Z_BEST_COMPRESSION)) { | |
2979 | 716 av_log(avctx, AV_LOG_ERROR, "Unsupported compression level for ZLIB: (%d).\n", c->compression); |
1743 | 717 return 1; |
718 } | |
719 av_log(avctx, AV_LOG_INFO, "Compression level for ZLIB: (%d).\n", c->compression); | |
720 } | |
721 #else | |
722 av_log(avctx, AV_LOG_ERROR, "Zlib support not compiled.\n"); | |
723 return 1; | |
724 #endif | |
725 break; | |
726 default: | |
727 av_log(avctx, AV_LOG_ERROR, "BUG! Unknown codec in compression switch.\n"); | |
728 return 1; | |
729 } | |
730 | |
731 /* Allocate decompression buffer */ | |
732 if (c->decomp_size) { | |
2418
82af834636c2
Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents:
2398
diff
changeset
|
733 if ((c->decomp_buf = av_malloc(max_decomp_size)) == NULL) { |
1743 | 734 av_log(avctx, AV_LOG_ERROR, "Can't allocate decompression buffer.\n"); |
735 return 1; | |
736 } | |
737 } | |
2967 | 738 |
739 /* Detect flags */ | |
1743 | 740 c->flags = *((char *)avctx->extradata + 6); |
741 if (c->flags & FLAG_MULTITHREAD) | |
742 av_log(avctx, AV_LOG_INFO, "Multithread encoder flag set.\n"); | |
743 if (c->flags & FLAG_NULLFRAME) | |
744 av_log(avctx, AV_LOG_INFO, "Nullframe insertion flag set.\n"); | |
745 if ((avctx->codec_id == CODEC_ID_ZLIB) && (c->flags & FLAG_PNGFILTER)) | |
746 av_log(avctx, AV_LOG_INFO, "PNG filter flag set.\n"); | |
747 if (c->flags & FLAGMASK_UNUSED) | |
748 av_log(avctx, AV_LOG_ERROR, "Unknown flag set (%d).\n", c->flags); | |
749 | |
750 /* If needed init zlib */ | |
751 if (avctx->codec_id == CODEC_ID_ZLIB) { | |
752 #ifdef CONFIG_ZLIB | |
753 c->zstream.zalloc = Z_NULL; | |
754 c->zstream.zfree = Z_NULL; | |
755 c->zstream.opaque = Z_NULL; | |
756 zret = inflateInit(&(c->zstream)); | |
757 if (zret != Z_OK) { | |
758 av_log(avctx, AV_LOG_ERROR, "Inflate init error: %d\n", zret); | |
759 return 1; | |
760 } | |
761 #else | |
762 av_log(avctx, AV_LOG_ERROR, "Zlib support not compiled.\n"); | |
763 return 1; | |
764 #endif | |
765 } | |
766 | |
767 avctx->pix_fmt = PIX_FMT_BGR24; | |
768 | |
769 return 0; | |
770 } | |
3777 | 771 #endif /* CONFIG_DECODERS */ |
1743 | 772 |
3777 | 773 #ifdef CONFIG_ENCODERS |
1743 | 774 /* |
775 * | |
776 * Init lcl encoder | |
777 * | |
778 */ | |
779 static int encode_init(AVCodecContext *avctx) | |
780 { | |
781 LclContext *c = avctx->priv_data; | |
782 int zret; // Zlib return code | |
783 | |
784 #ifndef CONFIG_ZLIB | |
785 av_log(avctx, AV_LOG_ERROR, "Zlib support not compiled.\n"); | |
786 return 1; | |
787 #else | |
788 | |
789 c->avctx= avctx; | |
2967 | 790 |
1743 | 791 assert(avctx->width && avctx->height); |
2967 | 792 |
1743 | 793 avctx->extradata= av_mallocz(8); |
794 avctx->coded_frame= &c->pic; | |
795 | |
796 // Will be user settable someday | |
797 c->compression = 6; | |
798 c->flags = 0; | |
799 | |
800 switch(avctx->pix_fmt){ | |
801 case PIX_FMT_BGR24: | |
802 c->imgtype = IMGTYPE_RGB24; | |
803 c->decomp_size = avctx->width * avctx->height * 3; | |
804 avctx->bits_per_sample= 24; | |
805 break; | |
806 default: | |
807 av_log(avctx, AV_LOG_ERROR, "Format %d not supported\n", avctx->pix_fmt); | |
808 return -1; | |
809 } | |
810 | |
811 ((uint8_t*)avctx->extradata)[0]= 4; | |
812 ((uint8_t*)avctx->extradata)[1]= 0; | |
813 ((uint8_t*)avctx->extradata)[2]= 0; | |
814 ((uint8_t*)avctx->extradata)[3]= 0; | |
815 ((uint8_t*)avctx->extradata)[4]= c->imgtype; | |
816 ((uint8_t*)avctx->extradata)[5]= c->compression; | |
817 ((uint8_t*)avctx->extradata)[6]= c->flags; | |
2250
902caf560c43
Zlib encoder: fix image orientation (was flipped), 100l in deflate error
rtognimp
parents:
2248
diff
changeset
|
818 ((uint8_t*)avctx->extradata)[7]= CODEC_ZLIB; |
1743 | 819 c->avctx->extradata_size= 8; |
2967 | 820 |
1743 | 821 c->zstream.zalloc = Z_NULL; |
822 c->zstream.zfree = Z_NULL; | |
823 c->zstream.opaque = Z_NULL; | |
824 zret = deflateInit(&(c->zstream), c->compression); | |
825 if (zret != Z_OK) { | |
826 av_log(avctx, AV_LOG_ERROR, "Deflate init error: %d\n", zret); | |
827 return 1; | |
828 } | |
829 | |
830 /* Conservative upper bound taken from zlib v1.2.1 source */ | |
831 c->max_comp_size = c->decomp_size + ((c->decomp_size + 7) >> 3) + | |
832 ((c->decomp_size + 63) >> 6) + 11; | |
833 if ((c->comp_buf = av_malloc(c->max_comp_size)) == NULL) { | |
834 av_log(avctx, AV_LOG_ERROR, "Can't allocate compression buffer.\n"); | |
835 return 1; | |
836 } | |
837 | |
838 return 0; | |
839 #endif | |
840 } | |
3777 | 841 #endif /* CONFIG_ENCODERS */ |
1743 | 842 |
843 | |
844 | |
3777 | 845 #ifdef CONFIG_DECODERS |
1743 | 846 /* |
847 * | |
848 * Uninit lcl decoder | |
849 * | |
850 */ | |
851 static int decode_end(AVCodecContext *avctx) | |
852 { | |
4827 | 853 LclContext * const c = avctx->priv_data; |
1743 | 854 |
2979 | 855 if (c->pic.data[0]) |
856 avctx->release_buffer(avctx, &c->pic); | |
1743 | 857 #ifdef CONFIG_ZLIB |
858 inflateEnd(&(c->zstream)); | |
859 #endif | |
860 | |
2979 | 861 return 0; |
1743 | 862 } |
3777 | 863 #endif |
1743 | 864 |
3777 | 865 #ifdef CONFIG_ENCODERS |
1743 | 866 /* |
867 * | |
868 * Uninit lcl encoder | |
869 * | |
870 */ | |
871 static int encode_end(AVCodecContext *avctx) | |
872 { | |
873 LclContext *c = avctx->priv_data; | |
874 | |
875 av_freep(&avctx->extradata); | |
2248
e4e1b4f31db6
segfault fix by (Kostya <cannonball at bw-team dot com>)
michael
parents:
1744
diff
changeset
|
876 av_freep(&c->comp_buf); |
1743 | 877 #ifdef CONFIG_ZLIB |
878 deflateEnd(&(c->zstream)); | |
879 #endif | |
2967 | 880 |
1743 | 881 return 0; |
882 } | |
3777 | 883 #endif |
1743 | 884 |
3777 | 885 #ifdef CONFIG_MSZH_DECODER |
1743 | 886 AVCodec mszh_decoder = { |
2979 | 887 "mszh", |
888 CODEC_TYPE_VIDEO, | |
889 CODEC_ID_MSZH, | |
890 sizeof(LclContext), | |
891 decode_init, | |
892 NULL, | |
893 decode_end, | |
894 decode_frame, | |
895 CODEC_CAP_DR1, | |
1743 | 896 }; |
3777 | 897 #endif |
1743 | 898 |
3777 | 899 #ifdef CONFIG_ZLIB_DECODER |
1743 | 900 AVCodec zlib_decoder = { |
2979 | 901 "zlib", |
902 CODEC_TYPE_VIDEO, | |
903 CODEC_ID_ZLIB, | |
904 sizeof(LclContext), | |
905 decode_init, | |
906 NULL, | |
907 decode_end, | |
908 decode_frame, | |
909 CODEC_CAP_DR1, | |
1743 | 910 }; |
3777 | 911 #endif |
1743 | 912 |
913 #ifdef CONFIG_ENCODERS | |
914 | |
915 AVCodec zlib_encoder = { | |
916 "zlib", | |
917 CODEC_TYPE_VIDEO, | |
918 CODEC_ID_ZLIB, | |
919 sizeof(LclContext), | |
920 encode_init, | |
921 encode_frame, | |
922 encode_end, | |
923 }; | |
924 | |
925 #endif //CONFIG_ENCODERS |