00001 /* 00002 * LCL (LossLess Codec Library) Codec 00003 * Copyright (c) 2002-2004 Roberto Togni 00004 * 00005 * This file is part of FFmpeg. 00006 * 00007 * FFmpeg is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public 00009 * License as published by the Free Software Foundation; either 00010 * version 2.1 of the License, or (at your option) any later version. 00011 * 00012 * FFmpeg is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with FFmpeg; if not, write to the Free Software 00019 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00020 */ 00021 00041 #include <stdio.h> 00042 #include <stdlib.h> 00043 00044 #include "avcodec.h" 00045 #include "bytestream.h" 00046 #include "lcl.h" 00047 #include "libavutil/lzo.h" 00048 00049 #if CONFIG_ZLIB_DECODER 00050 #include <zlib.h> 00051 #endif 00052 00053 /* 00054 * Decoder context 00055 */ 00056 typedef struct LclDecContext { 00057 AVFrame pic; 00058 00059 // Image type 00060 int imgtype; 00061 // Compression type 00062 int compression; 00063 // Flags 00064 int flags; 00065 // Decompressed data size 00066 unsigned int decomp_size; 00067 // Decompression buffer 00068 unsigned char* decomp_buf; 00069 #if CONFIG_ZLIB_DECODER 00070 z_stream zstream; 00071 #endif 00072 } LclDecContext; 00073 00074 00079 static unsigned int mszh_decomp(const unsigned char * srcptr, int srclen, unsigned char * destptr, unsigned int destsize) 00080 { 00081 unsigned char *destptr_bak = destptr; 00082 unsigned char *destptr_end = destptr + destsize; 00083 const unsigned char *srcptr_end = srcptr + srclen; 00084 unsigned mask = *srcptr++; 00085 unsigned maskbit = 0x80; 00086 00087 while (srcptr < srcptr_end && destptr < destptr_end) { 00088 if (!(mask & maskbit)) { 00089 memcpy(destptr, srcptr, 4); 00090 destptr += 4; 00091 srcptr += 4; 00092 } else { 00093 unsigned ofs = bytestream_get_le16(&srcptr); 00094 unsigned cnt = (ofs >> 11) + 1; 00095 ofs &= 0x7ff; 00096 ofs = FFMIN(ofs, destptr - destptr_bak); 00097 cnt *= 4; 00098 cnt = FFMIN(cnt, destptr_end - destptr); 00099 if (ofs) { 00100 av_memcpy_backptr(destptr, ofs, cnt); 00101 } else { 00102 // Not known what the correct behaviour is, but 00103 // this at least avoids uninitialized data. 00104 memset(destptr, 0, cnt); 00105 } 00106 destptr += cnt; 00107 } 00108 maskbit >>= 1; 00109 if (!maskbit) { 00110 mask = *srcptr++; 00111 while (!mask) { 00112 if (destptr_end - destptr < 32 || srcptr_end - srcptr < 32) break; 00113 memcpy(destptr, srcptr, 32); 00114 destptr += 32; 00115 srcptr += 32; 00116 mask = *srcptr++; 00117 } 00118 maskbit = 0x80; 00119 } 00120 } 00121 00122 return destptr - destptr_bak; 00123 } 00124 00125 00126 #if CONFIG_ZLIB_DECODER 00127 00134 static int zlib_decomp(AVCodecContext *avctx, const uint8_t *src, int src_len, int offset, int expected) 00135 { 00136 LclDecContext *c = avctx->priv_data; 00137 int zret = inflateReset(&c->zstream); 00138 if (zret != Z_OK) { 00139 av_log(avctx, AV_LOG_ERROR, "Inflate reset error: %d\n", zret); 00140 return -1; 00141 } 00142 c->zstream.next_in = src; 00143 c->zstream.avail_in = src_len; 00144 c->zstream.next_out = c->decomp_buf + offset; 00145 c->zstream.avail_out = c->decomp_size - offset; 00146 zret = inflate(&c->zstream, Z_FINISH); 00147 if (zret != Z_OK && zret != Z_STREAM_END) { 00148 av_log(avctx, AV_LOG_ERROR, "Inflate error: %d\n", zret); 00149 return -1; 00150 } 00151 if (expected != (unsigned int)c->zstream.total_out) { 00152 av_log(avctx, AV_LOG_ERROR, "Decoded size differs (%d != %lu)\n", 00153 expected, c->zstream.total_out); 00154 return -1; 00155 } 00156 return c->zstream.total_out; 00157 } 00158 #endif 00159 00160 00161 /* 00162 * 00163 * Decode a frame 00164 * 00165 */ 00166 static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt) 00167 { 00168 const uint8_t *buf = avpkt->data; 00169 int buf_size = avpkt->size; 00170 LclDecContext * const c = avctx->priv_data; 00171 unsigned char *encoded = (unsigned char *)buf; 00172 unsigned int pixel_ptr; 00173 int row, col; 00174 unsigned char *outptr; 00175 uint8_t *y_out, *u_out, *v_out; 00176 unsigned int width = avctx->width; // Real image width 00177 unsigned int height = avctx->height; // Real image height 00178 unsigned int mszh_dlen; 00179 unsigned char yq, y1q, uq, vq; 00180 int uqvq; 00181 unsigned int mthread_inlen, mthread_outlen; 00182 unsigned int len = buf_size; 00183 00184 if(c->pic.data[0]) 00185 avctx->release_buffer(avctx, &c->pic); 00186 00187 c->pic.reference = 0; 00188 c->pic.buffer_hints = FF_BUFFER_HINTS_VALID; 00189 if(avctx->get_buffer(avctx, &c->pic) < 0){ 00190 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); 00191 return -1; 00192 } 00193 00194 outptr = c->pic.data[0]; // Output image pointer 00195 00196 /* Decompress frame */ 00197 switch (avctx->codec_id) { 00198 case CODEC_ID_MSZH: 00199 switch (c->compression) { 00200 case COMP_MSZH: 00201 if (c->flags & FLAG_MULTITHREAD) { 00202 mthread_inlen = AV_RL32(encoded); 00203 mthread_inlen = FFMIN(mthread_inlen, len - 8); 00204 mthread_outlen = AV_RL32(encoded+4); 00205 mthread_outlen = FFMIN(mthread_outlen, c->decomp_size); 00206 mszh_dlen = mszh_decomp(encoded + 8, mthread_inlen, c->decomp_buf, c->decomp_size); 00207 if (mthread_outlen != mszh_dlen) { 00208 av_log(avctx, AV_LOG_ERROR, "Mthread1 decoded size differs (%d != %d)\n", 00209 mthread_outlen, mszh_dlen); 00210 return -1; 00211 } 00212 mszh_dlen = mszh_decomp(encoded + 8 + mthread_inlen, len - 8 - mthread_inlen, 00213 c->decomp_buf + mthread_outlen, c->decomp_size - mthread_outlen); 00214 if (mthread_outlen != mszh_dlen) { 00215 av_log(avctx, AV_LOG_ERROR, "Mthread2 decoded size differs (%d != %d)\n", 00216 mthread_outlen, mszh_dlen); 00217 return -1; 00218 } 00219 encoded = c->decomp_buf; 00220 len = c->decomp_size; 00221 } else { 00222 mszh_dlen = mszh_decomp(encoded, len, c->decomp_buf, c->decomp_size); 00223 if (c->decomp_size != mszh_dlen) { 00224 av_log(avctx, AV_LOG_ERROR, "Decoded size differs (%d != %d)\n", 00225 c->decomp_size, mszh_dlen); 00226 return -1; 00227 } 00228 encoded = c->decomp_buf; 00229 len = mszh_dlen; 00230 } 00231 break; 00232 case COMP_MSZH_NOCOMP: 00233 break; 00234 default: 00235 av_log(avctx, AV_LOG_ERROR, "BUG! Unknown MSZH compression in frame decoder.\n"); 00236 return -1; 00237 } 00238 break; 00239 #if CONFIG_ZLIB_DECODER 00240 case CODEC_ID_ZLIB: 00241 /* Using the original dll with normal compression (-1) and RGB format 00242 * gives a file with ZLIB fourcc, but frame is really uncompressed. 00243 * To be sure that's true check also frame size */ 00244 if (c->compression == COMP_ZLIB_NORMAL && c->imgtype == IMGTYPE_RGB24 && 00245 len == width * height * 3) 00246 break; 00247 if (c->flags & FLAG_MULTITHREAD) { 00248 int ret; 00249 mthread_inlen = AV_RL32(encoded); 00250 mthread_inlen = FFMIN(mthread_inlen, len - 8); 00251 mthread_outlen = AV_RL32(encoded+4); 00252 mthread_outlen = FFMIN(mthread_outlen, c->decomp_size); 00253 ret = zlib_decomp(avctx, encoded + 8, mthread_inlen, 0, mthread_outlen); 00254 if (ret < 0) return ret; 00255 ret = zlib_decomp(avctx, encoded + 8 + mthread_inlen, len - 8 - mthread_inlen, 00256 mthread_outlen, mthread_outlen); 00257 if (ret < 0) return ret; 00258 } else { 00259 int ret = zlib_decomp(avctx, encoded, len, 0, c->decomp_size); 00260 if (ret < 0) return ret; 00261 } 00262 encoded = c->decomp_buf; 00263 len = c->decomp_size; 00264 break; 00265 #endif 00266 default: 00267 av_log(avctx, AV_LOG_ERROR, "BUG! Unknown codec in frame decoder compression switch.\n"); 00268 return -1; 00269 } 00270 00271 00272 /* Apply PNG filter */ 00273 if (avctx->codec_id == CODEC_ID_ZLIB && (c->flags & FLAG_PNGFILTER)) { 00274 switch (c->imgtype) { 00275 case IMGTYPE_YUV111: 00276 case IMGTYPE_RGB24: 00277 for (row = 0; row < height; row++) { 00278 pixel_ptr = row * width * 3; 00279 yq = encoded[pixel_ptr++]; 00280 uqvq = AV_RL16(encoded+pixel_ptr); 00281 pixel_ptr += 2; 00282 for (col = 1; col < width; col++) { 00283 encoded[pixel_ptr] = yq -= encoded[pixel_ptr]; 00284 uqvq -= AV_RL16(encoded+pixel_ptr+1); 00285 AV_WL16(encoded+pixel_ptr+1, uqvq); 00286 pixel_ptr += 3; 00287 } 00288 } 00289 break; 00290 case IMGTYPE_YUV422: 00291 for (row = 0; row < height; row++) { 00292 pixel_ptr = row * width * 2; 00293 yq = uq = vq =0; 00294 for (col = 0; col < width/4; col++) { 00295 encoded[pixel_ptr] = yq -= encoded[pixel_ptr]; 00296 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1]; 00297 encoded[pixel_ptr+2] = yq -= encoded[pixel_ptr+2]; 00298 encoded[pixel_ptr+3] = yq -= encoded[pixel_ptr+3]; 00299 encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4]; 00300 encoded[pixel_ptr+5] = uq -= encoded[pixel_ptr+5]; 00301 encoded[pixel_ptr+6] = vq -= encoded[pixel_ptr+6]; 00302 encoded[pixel_ptr+7] = vq -= encoded[pixel_ptr+7]; 00303 pixel_ptr += 8; 00304 } 00305 } 00306 break; 00307 case IMGTYPE_YUV411: 00308 for (row = 0; row < height; row++) { 00309 pixel_ptr = row * width / 2 * 3; 00310 yq = uq = vq =0; 00311 for (col = 0; col < width/4; col++) { 00312 encoded[pixel_ptr] = yq -= encoded[pixel_ptr]; 00313 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1]; 00314 encoded[pixel_ptr+2] = yq -= encoded[pixel_ptr+2]; 00315 encoded[pixel_ptr+3] = yq -= encoded[pixel_ptr+3]; 00316 encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4]; 00317 encoded[pixel_ptr+5] = vq -= encoded[pixel_ptr+5]; 00318 pixel_ptr += 6; 00319 } 00320 } 00321 break; 00322 case IMGTYPE_YUV211: 00323 for (row = 0; row < height; row++) { 00324 pixel_ptr = row * width * 2; 00325 yq = uq = vq =0; 00326 for (col = 0; col < width/2; col++) { 00327 encoded[pixel_ptr] = yq -= encoded[pixel_ptr]; 00328 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1]; 00329 encoded[pixel_ptr+2] = uq -= encoded[pixel_ptr+2]; 00330 encoded[pixel_ptr+3] = vq -= encoded[pixel_ptr+3]; 00331 pixel_ptr += 4; 00332 } 00333 } 00334 break; 00335 case IMGTYPE_YUV420: 00336 for (row = 0; row < height/2; row++) { 00337 pixel_ptr = row * width * 3; 00338 yq = y1q = uq = vq =0; 00339 for (col = 0; col < width/2; col++) { 00340 encoded[pixel_ptr] = yq -= encoded[pixel_ptr]; 00341 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1]; 00342 encoded[pixel_ptr+2] = y1q -= encoded[pixel_ptr+2]; 00343 encoded[pixel_ptr+3] = y1q -= encoded[pixel_ptr+3]; 00344 encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4]; 00345 encoded[pixel_ptr+5] = vq -= encoded[pixel_ptr+5]; 00346 pixel_ptr += 6; 00347 } 00348 } 00349 break; 00350 default: 00351 av_log(avctx, AV_LOG_ERROR, "BUG! Unknown imagetype in pngfilter switch.\n"); 00352 return -1; 00353 } 00354 } 00355 00356 /* Convert colorspace */ 00357 y_out = c->pic.data[0] + (height - 1) * c->pic.linesize[0]; 00358 u_out = c->pic.data[1] + (height - 1) * c->pic.linesize[1]; 00359 v_out = c->pic.data[2] + (height - 1) * c->pic.linesize[2]; 00360 switch (c->imgtype) { 00361 case IMGTYPE_YUV111: 00362 for (row = 0; row < height; row++) { 00363 for (col = 0; col < width; col++) { 00364 y_out[col] = *encoded++; 00365 u_out[col] = *encoded++ + 128; 00366 v_out[col] = *encoded++ + 128; 00367 } 00368 y_out -= c->pic.linesize[0]; 00369 u_out -= c->pic.linesize[1]; 00370 v_out -= c->pic.linesize[2]; 00371 } 00372 break; 00373 case IMGTYPE_YUV422: 00374 for (row = 0; row < height; row++) { 00375 for (col = 0; col < width - 3; col += 4) { 00376 memcpy(y_out + col, encoded, 4); 00377 encoded += 4; 00378 u_out[ col >> 1 ] = *encoded++ + 128; 00379 u_out[(col >> 1) + 1] = *encoded++ + 128; 00380 v_out[ col >> 1 ] = *encoded++ + 128; 00381 v_out[(col >> 1) + 1] = *encoded++ + 128; 00382 } 00383 y_out -= c->pic.linesize[0]; 00384 u_out -= c->pic.linesize[1]; 00385 v_out -= c->pic.linesize[2]; 00386 } 00387 break; 00388 case IMGTYPE_RGB24: 00389 for (row = height - 1; row >= 0; row--) { 00390 pixel_ptr = row * c->pic.linesize[0]; 00391 memcpy(outptr + pixel_ptr, encoded, 3 * width); 00392 encoded += 3 * width; 00393 } 00394 break; 00395 case IMGTYPE_YUV411: 00396 for (row = 0; row < height; row++) { 00397 for (col = 0; col < width - 3; col += 4) { 00398 memcpy(y_out + col, encoded, 4); 00399 encoded += 4; 00400 u_out[col >> 2] = *encoded++ + 128; 00401 v_out[col >> 2] = *encoded++ + 128; 00402 } 00403 y_out -= c->pic.linesize[0]; 00404 u_out -= c->pic.linesize[1]; 00405 v_out -= c->pic.linesize[2]; 00406 } 00407 break; 00408 case IMGTYPE_YUV211: 00409 for (row = 0; row < height; row++) { 00410 for (col = 0; col < width - 1; col += 2) { 00411 memcpy(y_out + col, encoded, 2); 00412 encoded += 2; 00413 u_out[col >> 1] = *encoded++ + 128; 00414 v_out[col >> 1] = *encoded++ + 128; 00415 } 00416 y_out -= c->pic.linesize[0]; 00417 u_out -= c->pic.linesize[1]; 00418 v_out -= c->pic.linesize[2]; 00419 } 00420 break; 00421 case IMGTYPE_YUV420: 00422 u_out = c->pic.data[1] + ((height >> 1) - 1) * c->pic.linesize[1]; 00423 v_out = c->pic.data[2] + ((height >> 1) - 1) * c->pic.linesize[2]; 00424 for (row = 0; row < height - 1; row += 2) { 00425 for (col = 0; col < width - 1; col += 2) { 00426 memcpy(y_out + col, encoded, 2); 00427 encoded += 2; 00428 memcpy(y_out + col - c->pic.linesize[0], encoded, 2); 00429 encoded += 2; 00430 u_out[col >> 1] = *encoded++ + 128; 00431 v_out[col >> 1] = *encoded++ + 128; 00432 } 00433 y_out -= c->pic.linesize[0] << 1; 00434 u_out -= c->pic.linesize[1]; 00435 v_out -= c->pic.linesize[2]; 00436 } 00437 break; 00438 default: 00439 av_log(avctx, AV_LOG_ERROR, "BUG! Unknown imagetype in image decoder.\n"); 00440 return -1; 00441 } 00442 00443 *data_size = sizeof(AVFrame); 00444 *(AVFrame*)data = c->pic; 00445 00446 /* always report that the buffer was completely consumed */ 00447 return buf_size; 00448 } 00449 00450 /* 00451 * 00452 * Init lcl decoder 00453 * 00454 */ 00455 static av_cold int decode_init(AVCodecContext *avctx) 00456 { 00457 LclDecContext * const c = avctx->priv_data; 00458 unsigned int basesize = avctx->width * avctx->height; 00459 unsigned int max_basesize = FFALIGN(avctx->width, 4) * FFALIGN(avctx->height, 4) + AV_LZO_OUTPUT_PADDING; 00460 unsigned int max_decomp_size; 00461 00462 avcodec_get_frame_defaults(&c->pic); 00463 if (avctx->extradata_size < 8) { 00464 av_log(avctx, AV_LOG_ERROR, "Extradata size too small.\n"); 00465 return 1; 00466 } 00467 00468 /* Check codec type */ 00469 if ((avctx->codec_id == CODEC_ID_MSZH && avctx->extradata[7] != CODEC_MSZH) || 00470 (avctx->codec_id == CODEC_ID_ZLIB && avctx->extradata[7] != CODEC_ZLIB)) { 00471 av_log(avctx, AV_LOG_ERROR, "Codec id and codec type mismatch. This should not happen.\n"); 00472 } 00473 00474 /* Detect image type */ 00475 switch (c->imgtype = avctx->extradata[4]) { 00476 case IMGTYPE_YUV111: 00477 c->decomp_size = basesize * 3; 00478 max_decomp_size = max_basesize * 3; 00479 avctx->pix_fmt = PIX_FMT_YUV444P; 00480 av_log(avctx, AV_LOG_DEBUG, "Image type is YUV 1:1:1.\n"); 00481 break; 00482 case IMGTYPE_YUV422: 00483 c->decomp_size = basesize * 2; 00484 max_decomp_size = max_basesize * 2; 00485 avctx->pix_fmt = PIX_FMT_YUV422P; 00486 av_log(avctx, AV_LOG_DEBUG, "Image type is YUV 4:2:2.\n"); 00487 break; 00488 case IMGTYPE_RGB24: 00489 c->decomp_size = basesize * 3; 00490 max_decomp_size = max_basesize * 3; 00491 avctx->pix_fmt = PIX_FMT_BGR24; 00492 av_log(avctx, AV_LOG_DEBUG, "Image type is RGB 24.\n"); 00493 break; 00494 case IMGTYPE_YUV411: 00495 c->decomp_size = basesize / 2 * 3; 00496 max_decomp_size = max_basesize / 2 * 3; 00497 avctx->pix_fmt = PIX_FMT_YUV411P; 00498 av_log(avctx, AV_LOG_DEBUG, "Image type is YUV 4:1:1.\n"); 00499 break; 00500 case IMGTYPE_YUV211: 00501 c->decomp_size = basesize * 2; 00502 max_decomp_size = max_basesize * 2; 00503 avctx->pix_fmt = PIX_FMT_YUV422P; 00504 av_log(avctx, AV_LOG_DEBUG, "Image type is YUV 2:1:1.\n"); 00505 break; 00506 case IMGTYPE_YUV420: 00507 c->decomp_size = basesize / 2 * 3; 00508 max_decomp_size = max_basesize / 2 * 3; 00509 avctx->pix_fmt = PIX_FMT_YUV420P; 00510 av_log(avctx, AV_LOG_DEBUG, "Image type is YUV 4:2:0.\n"); 00511 break; 00512 default: 00513 av_log(avctx, AV_LOG_ERROR, "Unsupported image format %d.\n", c->imgtype); 00514 return 1; 00515 } 00516 00517 /* Detect compression method */ 00518 c->compression = (int8_t)avctx->extradata[5]; 00519 switch (avctx->codec_id) { 00520 case CODEC_ID_MSZH: 00521 switch (c->compression) { 00522 case COMP_MSZH: 00523 av_log(avctx, AV_LOG_DEBUG, "Compression enabled.\n"); 00524 break; 00525 case COMP_MSZH_NOCOMP: 00526 c->decomp_size = 0; 00527 av_log(avctx, AV_LOG_DEBUG, "No compression.\n"); 00528 break; 00529 default: 00530 av_log(avctx, AV_LOG_ERROR, "Unsupported compression format for MSZH (%d).\n", c->compression); 00531 return 1; 00532 } 00533 break; 00534 #if CONFIG_ZLIB_DECODER 00535 case CODEC_ID_ZLIB: 00536 switch (c->compression) { 00537 case COMP_ZLIB_HISPEED: 00538 av_log(avctx, AV_LOG_DEBUG, "High speed compression.\n"); 00539 break; 00540 case COMP_ZLIB_HICOMP: 00541 av_log(avctx, AV_LOG_DEBUG, "High compression.\n"); 00542 break; 00543 case COMP_ZLIB_NORMAL: 00544 av_log(avctx, AV_LOG_DEBUG, "Normal compression.\n"); 00545 break; 00546 default: 00547 if (c->compression < Z_NO_COMPRESSION || c->compression > Z_BEST_COMPRESSION) { 00548 av_log(avctx, AV_LOG_ERROR, "Unsupported compression level for ZLIB: (%d).\n", c->compression); 00549 return 1; 00550 } 00551 av_log(avctx, AV_LOG_DEBUG, "Compression level for ZLIB: (%d).\n", c->compression); 00552 } 00553 break; 00554 #endif 00555 default: 00556 av_log(avctx, AV_LOG_ERROR, "BUG! Unknown codec in compression switch.\n"); 00557 return 1; 00558 } 00559 00560 /* Allocate decompression buffer */ 00561 if (c->decomp_size) { 00562 if ((c->decomp_buf = av_malloc(max_decomp_size)) == NULL) { 00563 av_log(avctx, AV_LOG_ERROR, "Can't allocate decompression buffer.\n"); 00564 return 1; 00565 } 00566 } 00567 00568 /* Detect flags */ 00569 c->flags = avctx->extradata[6]; 00570 if (c->flags & FLAG_MULTITHREAD) 00571 av_log(avctx, AV_LOG_DEBUG, "Multithread encoder flag set.\n"); 00572 if (c->flags & FLAG_NULLFRAME) 00573 av_log(avctx, AV_LOG_DEBUG, "Nullframe insertion flag set.\n"); 00574 if (avctx->codec_id == CODEC_ID_ZLIB && (c->flags & FLAG_PNGFILTER)) 00575 av_log(avctx, AV_LOG_DEBUG, "PNG filter flag set.\n"); 00576 if (c->flags & FLAGMASK_UNUSED) 00577 av_log(avctx, AV_LOG_ERROR, "Unknown flag set (%d).\n", c->flags); 00578 00579 /* If needed init zlib */ 00580 #if CONFIG_ZLIB_DECODER 00581 if (avctx->codec_id == CODEC_ID_ZLIB) { 00582 int zret; 00583 c->zstream.zalloc = Z_NULL; 00584 c->zstream.zfree = Z_NULL; 00585 c->zstream.opaque = Z_NULL; 00586 zret = inflateInit(&c->zstream); 00587 if (zret != Z_OK) { 00588 av_log(avctx, AV_LOG_ERROR, "Inflate init error: %d\n", zret); 00589 av_freep(&c->decomp_buf); 00590 return 1; 00591 } 00592 } 00593 #endif 00594 00595 return 0; 00596 } 00597 00598 /* 00599 * 00600 * Uninit lcl decoder 00601 * 00602 */ 00603 static av_cold int decode_end(AVCodecContext *avctx) 00604 { 00605 LclDecContext * const c = avctx->priv_data; 00606 00607 av_freep(&c->decomp_buf); 00608 if (c->pic.data[0]) 00609 avctx->release_buffer(avctx, &c->pic); 00610 #if CONFIG_ZLIB_DECODER 00611 if (avctx->codec_id == CODEC_ID_ZLIB) 00612 inflateEnd(&c->zstream); 00613 #endif 00614 00615 return 0; 00616 } 00617 00618 #if CONFIG_MSZH_DECODER 00619 AVCodec ff_mszh_decoder = { 00620 .name = "mszh", 00621 .type = AVMEDIA_TYPE_VIDEO, 00622 .id = CODEC_ID_MSZH, 00623 .priv_data_size = sizeof(LclDecContext), 00624 .init = decode_init, 00625 .close = decode_end, 00626 .decode = decode_frame, 00627 .capabilities = CODEC_CAP_DR1, 00628 .long_name = NULL_IF_CONFIG_SMALL("LCL (LossLess Codec Library) MSZH"), 00629 }; 00630 #endif 00631 00632 #if CONFIG_ZLIB_DECODER 00633 AVCodec ff_zlib_decoder = { 00634 .name = "zlib", 00635 .type = AVMEDIA_TYPE_VIDEO, 00636 .id = CODEC_ID_ZLIB, 00637 .priv_data_size = sizeof(LclDecContext), 00638 .init = decode_init, 00639 .close = decode_end, 00640 .decode = decode_frame, 00641 .capabilities = CODEC_CAP_DR1, 00642 .long_name = NULL_IF_CONFIG_SMALL("LCL (LossLess Codec Library) ZLIB"), 00643 }; 00644 #endif