Libav
|
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 av_memcpy_backptr(destptr, ofs, cnt); 00100 destptr += cnt; 00101 } 00102 maskbit >>= 1; 00103 if (!maskbit) { 00104 mask = *srcptr++; 00105 while (!mask) { 00106 if (destptr_end - destptr < 32 || srcptr_end - srcptr < 32) break; 00107 memcpy(destptr, srcptr, 32); 00108 destptr += 32; 00109 srcptr += 32; 00110 mask = *srcptr++; 00111 } 00112 maskbit = 0x80; 00113 } 00114 } 00115 00116 return destptr - destptr_bak; 00117 } 00118 00119 00127 #if CONFIG_ZLIB_DECODER 00128 static int zlib_decomp(AVCodecContext *avctx, const uint8_t *src, int src_len, int offset, int expected) 00129 { 00130 LclDecContext *c = avctx->priv_data; 00131 int zret = inflateReset(&c->zstream); 00132 if (zret != Z_OK) { 00133 av_log(avctx, AV_LOG_ERROR, "Inflate reset error: %d\n", zret); 00134 return -1; 00135 } 00136 c->zstream.next_in = src; 00137 c->zstream.avail_in = src_len; 00138 c->zstream.next_out = c->decomp_buf + offset; 00139 c->zstream.avail_out = c->decomp_size - offset; 00140 zret = inflate(&c->zstream, Z_FINISH); 00141 if (zret != Z_OK && zret != Z_STREAM_END) { 00142 av_log(avctx, AV_LOG_ERROR, "Inflate error: %d\n", zret); 00143 return -1; 00144 } 00145 if (expected != (unsigned int)c->zstream.total_out) { 00146 av_log(avctx, AV_LOG_ERROR, "Decoded size differs (%d != %lu)\n", 00147 expected, c->zstream.total_out); 00148 return -1; 00149 } 00150 return c->zstream.total_out; 00151 } 00152 #endif 00153 00154 00155 /* 00156 * 00157 * Decode a frame 00158 * 00159 */ 00160 static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt) 00161 { 00162 const uint8_t *buf = avpkt->data; 00163 int buf_size = avpkt->size; 00164 LclDecContext * const c = avctx->priv_data; 00165 unsigned char *encoded = (unsigned char *)buf; 00166 unsigned int pixel_ptr; 00167 int row, col; 00168 unsigned char *outptr; 00169 uint8_t *y_out, *u_out, *v_out; 00170 unsigned int width = avctx->width; // Real image width 00171 unsigned int height = avctx->height; // Real image height 00172 unsigned int mszh_dlen; 00173 unsigned char yq, y1q, uq, vq; 00174 int uqvq; 00175 unsigned int mthread_inlen, mthread_outlen; 00176 unsigned int len = buf_size; 00177 00178 if(c->pic.data[0]) 00179 avctx->release_buffer(avctx, &c->pic); 00180 00181 c->pic.reference = 0; 00182 c->pic.buffer_hints = FF_BUFFER_HINTS_VALID; 00183 if(avctx->get_buffer(avctx, &c->pic) < 0){ 00184 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); 00185 return -1; 00186 } 00187 00188 outptr = c->pic.data[0]; // Output image pointer 00189 00190 /* Decompress frame */ 00191 switch (avctx->codec_id) { 00192 case CODEC_ID_MSZH: 00193 switch (c->compression) { 00194 case COMP_MSZH: 00195 if (c->flags & FLAG_MULTITHREAD) { 00196 mthread_inlen = AV_RL32(encoded); 00197 mthread_inlen = FFMIN(mthread_inlen, len - 8); 00198 mthread_outlen = AV_RL32(encoded+4); 00199 mthread_outlen = FFMIN(mthread_outlen, c->decomp_size); 00200 mszh_dlen = mszh_decomp(encoded + 8, mthread_inlen, c->decomp_buf, c->decomp_size); 00201 if (mthread_outlen != mszh_dlen) { 00202 av_log(avctx, AV_LOG_ERROR, "Mthread1 decoded size differs (%d != %d)\n", 00203 mthread_outlen, mszh_dlen); 00204 return -1; 00205 } 00206 mszh_dlen = mszh_decomp(encoded + 8 + mthread_inlen, len - 8 - mthread_inlen, 00207 c->decomp_buf + mthread_outlen, c->decomp_size - mthread_outlen); 00208 if (mthread_outlen != mszh_dlen) { 00209 av_log(avctx, AV_LOG_ERROR, "Mthread2 decoded size differs (%d != %d)\n", 00210 mthread_outlen, mszh_dlen); 00211 return -1; 00212 } 00213 encoded = c->decomp_buf; 00214 len = c->decomp_size; 00215 } else { 00216 mszh_dlen = mszh_decomp(encoded, len, c->decomp_buf, c->decomp_size); 00217 if (c->decomp_size != mszh_dlen) { 00218 av_log(avctx, AV_LOG_ERROR, "Decoded size differs (%d != %d)\n", 00219 c->decomp_size, mszh_dlen); 00220 return -1; 00221 } 00222 encoded = c->decomp_buf; 00223 len = mszh_dlen; 00224 } 00225 break; 00226 case COMP_MSZH_NOCOMP: 00227 break; 00228 default: 00229 av_log(avctx, AV_LOG_ERROR, "BUG! Unknown MSZH compression in frame decoder.\n"); 00230 return -1; 00231 } 00232 break; 00233 #if CONFIG_ZLIB_DECODER 00234 case CODEC_ID_ZLIB: 00235 /* Using the original dll with normal compression (-1) and RGB format 00236 * gives a file with ZLIB fourcc, but frame is really uncompressed. 00237 * To be sure that's true check also frame size */ 00238 if (c->compression == COMP_ZLIB_NORMAL && c->imgtype == IMGTYPE_RGB24 && 00239 len == width * height * 3) 00240 break; 00241 if (c->flags & FLAG_MULTITHREAD) { 00242 int ret; 00243 mthread_inlen = AV_RL32(encoded); 00244 mthread_inlen = FFMIN(mthread_inlen, len - 8); 00245 mthread_outlen = AV_RL32(encoded+4); 00246 mthread_outlen = FFMIN(mthread_outlen, c->decomp_size); 00247 ret = zlib_decomp(avctx, encoded + 8, mthread_inlen, 0, mthread_outlen); 00248 if (ret < 0) return ret; 00249 ret = zlib_decomp(avctx, encoded + 8 + mthread_inlen, len - 8 - mthread_inlen, 00250 mthread_outlen, mthread_outlen); 00251 if (ret < 0) return ret; 00252 } else { 00253 int ret = zlib_decomp(avctx, encoded, len, 0, c->decomp_size); 00254 if (ret < 0) return ret; 00255 } 00256 encoded = c->decomp_buf; 00257 len = c->decomp_size; 00258 break; 00259 #endif 00260 default: 00261 av_log(avctx, AV_LOG_ERROR, "BUG! Unknown codec in frame decoder compression switch.\n"); 00262 return -1; 00263 } 00264 00265 00266 /* Apply PNG filter */ 00267 if (avctx->codec_id == CODEC_ID_ZLIB && (c->flags & FLAG_PNGFILTER)) { 00268 switch (c->imgtype) { 00269 case IMGTYPE_YUV111: 00270 case IMGTYPE_RGB24: 00271 for (row = 0; row < height; row++) { 00272 pixel_ptr = row * width * 3; 00273 yq = encoded[pixel_ptr++]; 00274 uqvq = AV_RL16(encoded+pixel_ptr); 00275 pixel_ptr += 2; 00276 for (col = 1; col < width; col++) { 00277 encoded[pixel_ptr] = yq -= encoded[pixel_ptr]; 00278 uqvq -= AV_RL16(encoded+pixel_ptr+1); 00279 AV_WL16(encoded+pixel_ptr+1, uqvq); 00280 pixel_ptr += 3; 00281 } 00282 } 00283 break; 00284 case IMGTYPE_YUV422: 00285 for (row = 0; row < height; row++) { 00286 pixel_ptr = row * width * 2; 00287 yq = uq = vq =0; 00288 for (col = 0; col < width/4; col++) { 00289 encoded[pixel_ptr] = yq -= encoded[pixel_ptr]; 00290 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1]; 00291 encoded[pixel_ptr+2] = yq -= encoded[pixel_ptr+2]; 00292 encoded[pixel_ptr+3] = yq -= encoded[pixel_ptr+3]; 00293 encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4]; 00294 encoded[pixel_ptr+5] = uq -= encoded[pixel_ptr+5]; 00295 encoded[pixel_ptr+6] = vq -= encoded[pixel_ptr+6]; 00296 encoded[pixel_ptr+7] = vq -= encoded[pixel_ptr+7]; 00297 pixel_ptr += 8; 00298 } 00299 } 00300 break; 00301 case IMGTYPE_YUV411: 00302 for (row = 0; row < height; row++) { 00303 pixel_ptr = row * width / 2 * 3; 00304 yq = uq = vq =0; 00305 for (col = 0; col < width/4; col++) { 00306 encoded[pixel_ptr] = yq -= encoded[pixel_ptr]; 00307 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1]; 00308 encoded[pixel_ptr+2] = yq -= encoded[pixel_ptr+2]; 00309 encoded[pixel_ptr+3] = yq -= encoded[pixel_ptr+3]; 00310 encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4]; 00311 encoded[pixel_ptr+5] = vq -= encoded[pixel_ptr+5]; 00312 pixel_ptr += 6; 00313 } 00314 } 00315 break; 00316 case IMGTYPE_YUV211: 00317 for (row = 0; row < height; row++) { 00318 pixel_ptr = row * width * 2; 00319 yq = uq = vq =0; 00320 for (col = 0; col < width/2; col++) { 00321 encoded[pixel_ptr] = yq -= encoded[pixel_ptr]; 00322 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1]; 00323 encoded[pixel_ptr+2] = uq -= encoded[pixel_ptr+2]; 00324 encoded[pixel_ptr+3] = vq -= encoded[pixel_ptr+3]; 00325 pixel_ptr += 4; 00326 } 00327 } 00328 break; 00329 case IMGTYPE_YUV420: 00330 for (row = 0; row < height/2; row++) { 00331 pixel_ptr = row * width * 3; 00332 yq = y1q = uq = vq =0; 00333 for (col = 0; col < width/2; col++) { 00334 encoded[pixel_ptr] = yq -= encoded[pixel_ptr]; 00335 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1]; 00336 encoded[pixel_ptr+2] = y1q -= encoded[pixel_ptr+2]; 00337 encoded[pixel_ptr+3] = y1q -= encoded[pixel_ptr+3]; 00338 encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4]; 00339 encoded[pixel_ptr+5] = vq -= encoded[pixel_ptr+5]; 00340 pixel_ptr += 6; 00341 } 00342 } 00343 break; 00344 default: 00345 av_log(avctx, AV_LOG_ERROR, "BUG! Unknown imagetype in pngfilter switch.\n"); 00346 return -1; 00347 } 00348 } 00349 00350 /* Convert colorspace */ 00351 y_out = c->pic.data[0] + (height - 1) * c->pic.linesize[0]; 00352 u_out = c->pic.data[1] + (height - 1) * c->pic.linesize[1]; 00353 v_out = c->pic.data[2] + (height - 1) * c->pic.linesize[2]; 00354 switch (c->imgtype) { 00355 case IMGTYPE_YUV111: 00356 for (row = 0; row < height; row++) { 00357 for (col = 0; col < width; col++) { 00358 y_out[col] = *encoded++; 00359 u_out[col] = *encoded++ + 128; 00360 v_out[col] = *encoded++ + 128; 00361 } 00362 y_out -= c->pic.linesize[0]; 00363 u_out -= c->pic.linesize[1]; 00364 v_out -= c->pic.linesize[2]; 00365 } 00366 break; 00367 case IMGTYPE_YUV422: 00368 for (row = 0; row < height; row++) { 00369 for (col = 0; col < width - 3; col += 4) { 00370 memcpy(y_out + col, encoded, 4); 00371 encoded += 4; 00372 u_out[ col >> 1 ] = *encoded++ + 128; 00373 u_out[(col >> 1) + 1] = *encoded++ + 128; 00374 v_out[ col >> 1 ] = *encoded++ + 128; 00375 v_out[(col >> 1) + 1] = *encoded++ + 128; 00376 } 00377 y_out -= c->pic.linesize[0]; 00378 u_out -= c->pic.linesize[1]; 00379 v_out -= c->pic.linesize[2]; 00380 } 00381 break; 00382 case IMGTYPE_RGB24: 00383 for (row = height - 1; row >= 0; row--) { 00384 pixel_ptr = row * c->pic.linesize[0]; 00385 memcpy(outptr + pixel_ptr, encoded, 3 * width); 00386 encoded += 3 * width; 00387 } 00388 break; 00389 case IMGTYPE_YUV411: 00390 for (row = 0; row < height; row++) { 00391 for (col = 0; col < width - 3; col += 4) { 00392 memcpy(y_out + col, encoded, 4); 00393 encoded += 4; 00394 u_out[col >> 2] = *encoded++ + 128; 00395 v_out[col >> 2] = *encoded++ + 128; 00396 } 00397 y_out -= c->pic.linesize[0]; 00398 u_out -= c->pic.linesize[1]; 00399 v_out -= c->pic.linesize[2]; 00400 } 00401 break; 00402 case IMGTYPE_YUV211: 00403 for (row = 0; row < height; row++) { 00404 for (col = 0; col < width - 1; col += 2) { 00405 memcpy(y_out + col, encoded, 2); 00406 encoded += 2; 00407 u_out[col >> 1] = *encoded++ + 128; 00408 v_out[col >> 1] = *encoded++ + 128; 00409 } 00410 y_out -= c->pic.linesize[0]; 00411 u_out -= c->pic.linesize[1]; 00412 v_out -= c->pic.linesize[2]; 00413 } 00414 break; 00415 case IMGTYPE_YUV420: 00416 u_out = c->pic.data[1] + ((height >> 1) - 1) * c->pic.linesize[1]; 00417 v_out = c->pic.data[2] + ((height >> 1) - 1) * c->pic.linesize[2]; 00418 for (row = 0; row < height - 1; row += 2) { 00419 for (col = 0; col < width - 1; col += 2) { 00420 memcpy(y_out + col, encoded, 2); 00421 encoded += 2; 00422 memcpy(y_out + col - c->pic.linesize[0], encoded, 2); 00423 encoded += 2; 00424 u_out[col >> 1] = *encoded++ + 128; 00425 v_out[col >> 1] = *encoded++ + 128; 00426 } 00427 y_out -= c->pic.linesize[0] << 1; 00428 u_out -= c->pic.linesize[1]; 00429 v_out -= c->pic.linesize[2]; 00430 } 00431 break; 00432 default: 00433 av_log(avctx, AV_LOG_ERROR, "BUG! Unknown imagetype in image decoder.\n"); 00434 return -1; 00435 } 00436 00437 *data_size = sizeof(AVFrame); 00438 *(AVFrame*)data = c->pic; 00439 00440 /* always report that the buffer was completely consumed */ 00441 return buf_size; 00442 } 00443 00444 /* 00445 * 00446 * Init lcl decoder 00447 * 00448 */ 00449 static av_cold int decode_init(AVCodecContext *avctx) 00450 { 00451 LclDecContext * const c = avctx->priv_data; 00452 unsigned int basesize = avctx->width * avctx->height; 00453 unsigned int max_basesize = FFALIGN(avctx->width, 4) * FFALIGN(avctx->height, 4) + AV_LZO_OUTPUT_PADDING; 00454 unsigned int max_decomp_size; 00455 00456 if (avctx->extradata_size < 8) { 00457 av_log(avctx, AV_LOG_ERROR, "Extradata size too small.\n"); 00458 return 1; 00459 } 00460 00461 /* Check codec type */ 00462 if ((avctx->codec_id == CODEC_ID_MSZH && avctx->extradata[7] != CODEC_MSZH) || 00463 (avctx->codec_id == CODEC_ID_ZLIB && avctx->extradata[7] != CODEC_ZLIB)) { 00464 av_log(avctx, AV_LOG_ERROR, "Codec id and codec type mismatch. This should not happen.\n"); 00465 } 00466 00467 /* Detect image type */ 00468 switch (c->imgtype = avctx->extradata[4]) { 00469 case IMGTYPE_YUV111: 00470 c->decomp_size = basesize * 3; 00471 max_decomp_size = max_basesize * 3; 00472 avctx->pix_fmt = PIX_FMT_YUV444P; 00473 av_log(avctx, AV_LOG_DEBUG, "Image type is YUV 1:1:1.\n"); 00474 break; 00475 case IMGTYPE_YUV422: 00476 c->decomp_size = basesize * 2; 00477 max_decomp_size = max_basesize * 2; 00478 avctx->pix_fmt = PIX_FMT_YUV422P; 00479 av_log(avctx, AV_LOG_DEBUG, "Image type is YUV 4:2:2.\n"); 00480 break; 00481 case IMGTYPE_RGB24: 00482 c->decomp_size = basesize * 3; 00483 max_decomp_size = max_basesize * 3; 00484 avctx->pix_fmt = PIX_FMT_BGR24; 00485 av_log(avctx, AV_LOG_DEBUG, "Image type is RGB 24.\n"); 00486 break; 00487 case IMGTYPE_YUV411: 00488 c->decomp_size = basesize / 2 * 3; 00489 max_decomp_size = max_basesize / 2 * 3; 00490 avctx->pix_fmt = PIX_FMT_YUV411P; 00491 av_log(avctx, AV_LOG_DEBUG, "Image type is YUV 4:1:1.\n"); 00492 break; 00493 case IMGTYPE_YUV211: 00494 c->decomp_size = basesize * 2; 00495 max_decomp_size = max_basesize * 2; 00496 avctx->pix_fmt = PIX_FMT_YUV422P; 00497 av_log(avctx, AV_LOG_DEBUG, "Image type is YUV 2:1:1.\n"); 00498 break; 00499 case IMGTYPE_YUV420: 00500 c->decomp_size = basesize / 2 * 3; 00501 max_decomp_size = max_basesize / 2 * 3; 00502 avctx->pix_fmt = PIX_FMT_YUV420P; 00503 av_log(avctx, AV_LOG_DEBUG, "Image type is YUV 4:2:0.\n"); 00504 break; 00505 default: 00506 av_log(avctx, AV_LOG_ERROR, "Unsupported image format %d.\n", c->imgtype); 00507 return 1; 00508 } 00509 00510 /* Detect compression method */ 00511 c->compression = (int8_t)avctx->extradata[5]; 00512 switch (avctx->codec_id) { 00513 case CODEC_ID_MSZH: 00514 switch (c->compression) { 00515 case COMP_MSZH: 00516 av_log(avctx, AV_LOG_DEBUG, "Compression enabled.\n"); 00517 break; 00518 case COMP_MSZH_NOCOMP: 00519 c->decomp_size = 0; 00520 av_log(avctx, AV_LOG_DEBUG, "No compression.\n"); 00521 break; 00522 default: 00523 av_log(avctx, AV_LOG_ERROR, "Unsupported compression format for MSZH (%d).\n", c->compression); 00524 return 1; 00525 } 00526 break; 00527 #if CONFIG_ZLIB_DECODER 00528 case CODEC_ID_ZLIB: 00529 switch (c->compression) { 00530 case COMP_ZLIB_HISPEED: 00531 av_log(avctx, AV_LOG_DEBUG, "High speed compression.\n"); 00532 break; 00533 case COMP_ZLIB_HICOMP: 00534 av_log(avctx, AV_LOG_DEBUG, "High compression.\n"); 00535 break; 00536 case COMP_ZLIB_NORMAL: 00537 av_log(avctx, AV_LOG_DEBUG, "Normal compression.\n"); 00538 break; 00539 default: 00540 if (c->compression < Z_NO_COMPRESSION || c->compression > Z_BEST_COMPRESSION) { 00541 av_log(avctx, AV_LOG_ERROR, "Unsupported compression level for ZLIB: (%d).\n", c->compression); 00542 return 1; 00543 } 00544 av_log(avctx, AV_LOG_DEBUG, "Compression level for ZLIB: (%d).\n", c->compression); 00545 } 00546 break; 00547 #endif 00548 default: 00549 av_log(avctx, AV_LOG_ERROR, "BUG! Unknown codec in compression switch.\n"); 00550 return 1; 00551 } 00552 00553 /* Allocate decompression buffer */ 00554 if (c->decomp_size) { 00555 if ((c->decomp_buf = av_malloc(max_decomp_size)) == NULL) { 00556 av_log(avctx, AV_LOG_ERROR, "Can't allocate decompression buffer.\n"); 00557 return 1; 00558 } 00559 } 00560 00561 /* Detect flags */ 00562 c->flags = avctx->extradata[6]; 00563 if (c->flags & FLAG_MULTITHREAD) 00564 av_log(avctx, AV_LOG_DEBUG, "Multithread encoder flag set.\n"); 00565 if (c->flags & FLAG_NULLFRAME) 00566 av_log(avctx, AV_LOG_DEBUG, "Nullframe insertion flag set.\n"); 00567 if (avctx->codec_id == CODEC_ID_ZLIB && (c->flags & FLAG_PNGFILTER)) 00568 av_log(avctx, AV_LOG_DEBUG, "PNG filter flag set.\n"); 00569 if (c->flags & FLAGMASK_UNUSED) 00570 av_log(avctx, AV_LOG_ERROR, "Unknown flag set (%d).\n", c->flags); 00571 00572 /* If needed init zlib */ 00573 #if CONFIG_ZLIB_DECODER 00574 if (avctx->codec_id == CODEC_ID_ZLIB) { 00575 int zret; 00576 c->zstream.zalloc = Z_NULL; 00577 c->zstream.zfree = Z_NULL; 00578 c->zstream.opaque = Z_NULL; 00579 zret = inflateInit(&c->zstream); 00580 if (zret != Z_OK) { 00581 av_log(avctx, AV_LOG_ERROR, "Inflate init error: %d\n", zret); 00582 av_freep(&c->decomp_buf); 00583 return 1; 00584 } 00585 } 00586 #endif 00587 00588 return 0; 00589 } 00590 00591 /* 00592 * 00593 * Uninit lcl decoder 00594 * 00595 */ 00596 static av_cold int decode_end(AVCodecContext *avctx) 00597 { 00598 LclDecContext * const c = avctx->priv_data; 00599 00600 av_freep(&c->decomp_buf); 00601 if (c->pic.data[0]) 00602 avctx->release_buffer(avctx, &c->pic); 00603 #if CONFIG_ZLIB_DECODER 00604 if (avctx->codec_id == CODEC_ID_ZLIB) 00605 inflateEnd(&c->zstream); 00606 #endif 00607 00608 return 0; 00609 } 00610 00611 #if CONFIG_MSZH_DECODER 00612 AVCodec mszh_decoder = { 00613 "mszh", 00614 AVMEDIA_TYPE_VIDEO, 00615 CODEC_ID_MSZH, 00616 sizeof(LclDecContext), 00617 decode_init, 00618 NULL, 00619 decode_end, 00620 decode_frame, 00621 CODEC_CAP_DR1, 00622 .long_name = NULL_IF_CONFIG_SMALL("LCL (LossLess Codec Library) MSZH"), 00623 }; 00624 #endif 00625 00626 #if CONFIG_ZLIB_DECODER 00627 AVCodec zlib_decoder = { 00628 "zlib", 00629 AVMEDIA_TYPE_VIDEO, 00630 CODEC_ID_ZLIB, 00631 sizeof(LclDecContext), 00632 decode_init, 00633 NULL, 00634 decode_end, 00635 decode_frame, 00636 CODEC_CAP_DR1, 00637 .long_name = NULL_IF_CONFIG_SMALL("LCL (LossLess Codec Library) ZLIB"), 00638 }; 00639 #endif