00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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
00055
00056 typedef struct LclDecContext {
00057 AVFrame pic;
00058
00059
00060 int imgtype;
00061
00062 int compression;
00063
00064 int flags;
00065
00066 unsigned int decomp_size;
00067
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
00103
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
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;
00177 unsigned int height = avctx->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];
00195
00196
00197 switch (avctx->codec_id) {
00198 case AV_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 int bppx2;
00234 switch (c->imgtype) {
00235 case IMGTYPE_YUV111:
00236 case IMGTYPE_RGB24:
00237 bppx2 = 6;
00238 break;
00239 case IMGTYPE_YUV422:
00240 case IMGTYPE_YUV211:
00241 bppx2 = 4;
00242 break;
00243 case IMGTYPE_YUV411:
00244 case IMGTYPE_YUV420:
00245 bppx2 = 3;
00246 break;
00247 default:
00248 bppx2 = 0;
00249 break;
00250 }
00251 if (len < ((width * height * bppx2) >> 1))
00252 return AVERROR_INVALIDDATA;
00253 break;
00254 }
00255 default:
00256 av_log(avctx, AV_LOG_ERROR, "BUG! Unknown MSZH compression in frame decoder.\n");
00257 return -1;
00258 }
00259 break;
00260 #if CONFIG_ZLIB_DECODER
00261 case AV_CODEC_ID_ZLIB:
00262
00263
00264
00265 if (c->compression == COMP_ZLIB_NORMAL && c->imgtype == IMGTYPE_RGB24 &&
00266 len == width * height * 3) {
00267 if (c->flags & FLAG_PNGFILTER) {
00268 memcpy(c->decomp_buf, encoded, len);
00269 encoded = c->decomp_buf;
00270 } else {
00271 break;
00272 }
00273 } else if (c->flags & FLAG_MULTITHREAD) {
00274 int ret;
00275 mthread_inlen = AV_RL32(encoded);
00276 mthread_inlen = FFMIN(mthread_inlen, len - 8);
00277 mthread_outlen = AV_RL32(encoded+4);
00278 mthread_outlen = FFMIN(mthread_outlen, c->decomp_size);
00279 ret = zlib_decomp(avctx, encoded + 8, mthread_inlen, 0, mthread_outlen);
00280 if (ret < 0) return ret;
00281 ret = zlib_decomp(avctx, encoded + 8 + mthread_inlen, len - 8 - mthread_inlen,
00282 mthread_outlen, mthread_outlen);
00283 if (ret < 0) return ret;
00284 } else {
00285 int ret = zlib_decomp(avctx, encoded, len, 0, c->decomp_size);
00286 if (ret < 0) return ret;
00287 }
00288 encoded = c->decomp_buf;
00289 len = c->decomp_size;
00290 break;
00291 #endif
00292 default:
00293 av_log(avctx, AV_LOG_ERROR, "BUG! Unknown codec in frame decoder compression switch.\n");
00294 return -1;
00295 }
00296
00297
00298
00299 if (avctx->codec_id == AV_CODEC_ID_ZLIB && (c->flags & FLAG_PNGFILTER)) {
00300 switch (c->imgtype) {
00301 case IMGTYPE_YUV111:
00302 case IMGTYPE_RGB24:
00303 for (row = 0; row < height; row++) {
00304 pixel_ptr = row * width * 3;
00305 yq = encoded[pixel_ptr++];
00306 uqvq = AV_RL16(encoded+pixel_ptr);
00307 pixel_ptr += 2;
00308 for (col = 1; col < width; col++) {
00309 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
00310 uqvq -= AV_RL16(encoded+pixel_ptr+1);
00311 AV_WL16(encoded+pixel_ptr+1, uqvq);
00312 pixel_ptr += 3;
00313 }
00314 }
00315 break;
00316 case IMGTYPE_YUV422:
00317 for (row = 0; row < height; row++) {
00318 pixel_ptr = row * width * 2;
00319 yq = uq = vq =0;
00320 for (col = 0; col < width/4; col++) {
00321 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
00322 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
00323 encoded[pixel_ptr+2] = yq -= encoded[pixel_ptr+2];
00324 encoded[pixel_ptr+3] = yq -= encoded[pixel_ptr+3];
00325 encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4];
00326 encoded[pixel_ptr+5] = uq -= encoded[pixel_ptr+5];
00327 encoded[pixel_ptr+6] = vq -= encoded[pixel_ptr+6];
00328 encoded[pixel_ptr+7] = vq -= encoded[pixel_ptr+7];
00329 pixel_ptr += 8;
00330 }
00331 }
00332 break;
00333 case IMGTYPE_YUV411:
00334 for (row = 0; row < height; row++) {
00335 pixel_ptr = row * width / 2 * 3;
00336 yq = uq = vq =0;
00337 for (col = 0; col < width/4; col++) {
00338 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
00339 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
00340 encoded[pixel_ptr+2] = yq -= encoded[pixel_ptr+2];
00341 encoded[pixel_ptr+3] = yq -= encoded[pixel_ptr+3];
00342 encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4];
00343 encoded[pixel_ptr+5] = vq -= encoded[pixel_ptr+5];
00344 pixel_ptr += 6;
00345 }
00346 }
00347 break;
00348 case IMGTYPE_YUV211:
00349 for (row = 0; row < height; row++) {
00350 pixel_ptr = row * width * 2;
00351 yq = uq = vq =0;
00352 for (col = 0; col < width/2; col++) {
00353 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
00354 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
00355 encoded[pixel_ptr+2] = uq -= encoded[pixel_ptr+2];
00356 encoded[pixel_ptr+3] = vq -= encoded[pixel_ptr+3];
00357 pixel_ptr += 4;
00358 }
00359 }
00360 break;
00361 case IMGTYPE_YUV420:
00362 for (row = 0; row < height/2; row++) {
00363 pixel_ptr = row * width * 3;
00364 yq = y1q = uq = vq =0;
00365 for (col = 0; col < width/2; col++) {
00366 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
00367 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
00368 encoded[pixel_ptr+2] = y1q -= encoded[pixel_ptr+2];
00369 encoded[pixel_ptr+3] = y1q -= encoded[pixel_ptr+3];
00370 encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4];
00371 encoded[pixel_ptr+5] = vq -= encoded[pixel_ptr+5];
00372 pixel_ptr += 6;
00373 }
00374 }
00375 break;
00376 default:
00377 av_log(avctx, AV_LOG_ERROR, "BUG! Unknown imagetype in pngfilter switch.\n");
00378 return -1;
00379 }
00380 }
00381
00382
00383 y_out = c->pic.data[0] + (height - 1) * c->pic.linesize[0];
00384 u_out = c->pic.data[1] + (height - 1) * c->pic.linesize[1];
00385 v_out = c->pic.data[2] + (height - 1) * c->pic.linesize[2];
00386 switch (c->imgtype) {
00387 case IMGTYPE_YUV111:
00388 for (row = 0; row < height; row++) {
00389 for (col = 0; col < width; col++) {
00390 y_out[col] = *encoded++;
00391 u_out[col] = *encoded++ + 128;
00392 v_out[col] = *encoded++ + 128;
00393 }
00394 y_out -= c->pic.linesize[0];
00395 u_out -= c->pic.linesize[1];
00396 v_out -= c->pic.linesize[2];
00397 }
00398 break;
00399 case IMGTYPE_YUV422:
00400 for (row = 0; row < height; row++) {
00401 for (col = 0; col < width - 3; col += 4) {
00402 memcpy(y_out + col, encoded, 4);
00403 encoded += 4;
00404 u_out[ col >> 1 ] = *encoded++ + 128;
00405 u_out[(col >> 1) + 1] = *encoded++ + 128;
00406 v_out[ col >> 1 ] = *encoded++ + 128;
00407 v_out[(col >> 1) + 1] = *encoded++ + 128;
00408 }
00409 y_out -= c->pic.linesize[0];
00410 u_out -= c->pic.linesize[1];
00411 v_out -= c->pic.linesize[2];
00412 }
00413 break;
00414 case IMGTYPE_RGB24:
00415 for (row = height - 1; row >= 0; row--) {
00416 pixel_ptr = row * c->pic.linesize[0];
00417 memcpy(outptr + pixel_ptr, encoded, 3 * width);
00418 encoded += 3 * width;
00419 }
00420 break;
00421 case IMGTYPE_YUV411:
00422 for (row = 0; row < height; row++) {
00423 for (col = 0; col < width - 3; col += 4) {
00424 memcpy(y_out + col, encoded, 4);
00425 encoded += 4;
00426 u_out[col >> 2] = *encoded++ + 128;
00427 v_out[col >> 2] = *encoded++ + 128;
00428 }
00429 y_out -= c->pic.linesize[0];
00430 u_out -= c->pic.linesize[1];
00431 v_out -= c->pic.linesize[2];
00432 }
00433 break;
00434 case IMGTYPE_YUV211:
00435 for (row = 0; row < height; row++) {
00436 for (col = 0; col < width - 1; col += 2) {
00437 memcpy(y_out + col, encoded, 2);
00438 encoded += 2;
00439 u_out[col >> 1] = *encoded++ + 128;
00440 v_out[col >> 1] = *encoded++ + 128;
00441 }
00442 y_out -= c->pic.linesize[0];
00443 u_out -= c->pic.linesize[1];
00444 v_out -= c->pic.linesize[2];
00445 }
00446 break;
00447 case IMGTYPE_YUV420:
00448 u_out = c->pic.data[1] + ((height >> 1) - 1) * c->pic.linesize[1];
00449 v_out = c->pic.data[2] + ((height >> 1) - 1) * c->pic.linesize[2];
00450 for (row = 0; row < height - 1; row += 2) {
00451 for (col = 0; col < width - 1; col += 2) {
00452 memcpy(y_out + col, encoded, 2);
00453 encoded += 2;
00454 memcpy(y_out + col - c->pic.linesize[0], encoded, 2);
00455 encoded += 2;
00456 u_out[col >> 1] = *encoded++ + 128;
00457 v_out[col >> 1] = *encoded++ + 128;
00458 }
00459 y_out -= c->pic.linesize[0] << 1;
00460 u_out -= c->pic.linesize[1];
00461 v_out -= c->pic.linesize[2];
00462 }
00463 break;
00464 default:
00465 av_log(avctx, AV_LOG_ERROR, "BUG! Unknown imagetype in image decoder.\n");
00466 return -1;
00467 }
00468
00469 *data_size = sizeof(AVFrame);
00470 *(AVFrame*)data = c->pic;
00471
00472
00473 return buf_size;
00474 }
00475
00476
00477
00478
00479
00480
00481 static av_cold int decode_init(AVCodecContext *avctx)
00482 {
00483 LclDecContext * const c = avctx->priv_data;
00484 unsigned int basesize = avctx->width * avctx->height;
00485 unsigned int max_basesize = FFALIGN(avctx->width, 4) * FFALIGN(avctx->height, 4) + AV_LZO_OUTPUT_PADDING;
00486 unsigned int max_decomp_size;
00487
00488 avcodec_get_frame_defaults(&c->pic);
00489 if (avctx->extradata_size < 8) {
00490 av_log(avctx, AV_LOG_ERROR, "Extradata size too small.\n");
00491 return AVERROR_INVALIDDATA;
00492 }
00493
00494
00495 if ((avctx->codec_id == AV_CODEC_ID_MSZH && avctx->extradata[7] != CODEC_MSZH) ||
00496 (avctx->codec_id == AV_CODEC_ID_ZLIB && avctx->extradata[7] != CODEC_ZLIB)) {
00497 av_log(avctx, AV_LOG_ERROR, "Codec id and codec type mismatch. This should not happen.\n");
00498 }
00499
00500
00501 switch (c->imgtype = avctx->extradata[4]) {
00502 case IMGTYPE_YUV111:
00503 c->decomp_size = basesize * 3;
00504 max_decomp_size = max_basesize * 3;
00505 avctx->pix_fmt = PIX_FMT_YUV444P;
00506 av_log(avctx, AV_LOG_DEBUG, "Image type is YUV 1:1:1.\n");
00507 break;
00508 case IMGTYPE_YUV422:
00509 c->decomp_size = basesize * 2;
00510 max_decomp_size = max_basesize * 2;
00511 avctx->pix_fmt = PIX_FMT_YUV422P;
00512 av_log(avctx, AV_LOG_DEBUG, "Image type is YUV 4:2:2.\n");
00513 break;
00514 case IMGTYPE_RGB24:
00515 c->decomp_size = basesize * 3;
00516 max_decomp_size = max_basesize * 3;
00517 avctx->pix_fmt = PIX_FMT_BGR24;
00518 av_log(avctx, AV_LOG_DEBUG, "Image type is RGB 24.\n");
00519 break;
00520 case IMGTYPE_YUV411:
00521 c->decomp_size = basesize / 2 * 3;
00522 max_decomp_size = max_basesize / 2 * 3;
00523 avctx->pix_fmt = PIX_FMT_YUV411P;
00524 av_log(avctx, AV_LOG_DEBUG, "Image type is YUV 4:1:1.\n");
00525 break;
00526 case IMGTYPE_YUV211:
00527 c->decomp_size = basesize * 2;
00528 max_decomp_size = max_basesize * 2;
00529 avctx->pix_fmt = PIX_FMT_YUV422P;
00530 av_log(avctx, AV_LOG_DEBUG, "Image type is YUV 2:1:1.\n");
00531 break;
00532 case IMGTYPE_YUV420:
00533 c->decomp_size = basesize / 2 * 3;
00534 max_decomp_size = max_basesize / 2 * 3;
00535 avctx->pix_fmt = PIX_FMT_YUV420P;
00536 av_log(avctx, AV_LOG_DEBUG, "Image type is YUV 4:2:0.\n");
00537 break;
00538 default:
00539 av_log(avctx, AV_LOG_ERROR, "Unsupported image format %d.\n", c->imgtype);
00540 return AVERROR_INVALIDDATA;
00541 }
00542
00543
00544 c->compression = (int8_t)avctx->extradata[5];
00545 switch (avctx->codec_id) {
00546 case AV_CODEC_ID_MSZH:
00547 switch (c->compression) {
00548 case COMP_MSZH:
00549 av_log(avctx, AV_LOG_DEBUG, "Compression enabled.\n");
00550 break;
00551 case COMP_MSZH_NOCOMP:
00552 c->decomp_size = 0;
00553 av_log(avctx, AV_LOG_DEBUG, "No compression.\n");
00554 break;
00555 default:
00556 av_log(avctx, AV_LOG_ERROR, "Unsupported compression format for MSZH (%d).\n", c->compression);
00557 return AVERROR_INVALIDDATA;
00558 }
00559 break;
00560 #if CONFIG_ZLIB_DECODER
00561 case AV_CODEC_ID_ZLIB:
00562 switch (c->compression) {
00563 case COMP_ZLIB_HISPEED:
00564 av_log(avctx, AV_LOG_DEBUG, "High speed compression.\n");
00565 break;
00566 case COMP_ZLIB_HICOMP:
00567 av_log(avctx, AV_LOG_DEBUG, "High compression.\n");
00568 break;
00569 case COMP_ZLIB_NORMAL:
00570 av_log(avctx, AV_LOG_DEBUG, "Normal compression.\n");
00571 break;
00572 default:
00573 if (c->compression < Z_NO_COMPRESSION || c->compression > Z_BEST_COMPRESSION) {
00574 av_log(avctx, AV_LOG_ERROR, "Unsupported compression level for ZLIB: (%d).\n", c->compression);
00575 return AVERROR_INVALIDDATA;
00576 }
00577 av_log(avctx, AV_LOG_DEBUG, "Compression level for ZLIB: (%d).\n", c->compression);
00578 }
00579 break;
00580 #endif
00581 default:
00582 av_log(avctx, AV_LOG_ERROR, "BUG! Unknown codec in compression switch.\n");
00583 return AVERROR_INVALIDDATA;
00584 }
00585
00586
00587 if (c->decomp_size) {
00588 if ((c->decomp_buf = av_malloc(max_decomp_size)) == NULL) {
00589 av_log(avctx, AV_LOG_ERROR, "Can't allocate decompression buffer.\n");
00590 return AVERROR(ENOMEM);
00591 }
00592 }
00593
00594
00595 c->flags = avctx->extradata[6];
00596 if (c->flags & FLAG_MULTITHREAD)
00597 av_log(avctx, AV_LOG_DEBUG, "Multithread encoder flag set.\n");
00598 if (c->flags & FLAG_NULLFRAME)
00599 av_log(avctx, AV_LOG_DEBUG, "Nullframe insertion flag set.\n");
00600 if (avctx->codec_id == AV_CODEC_ID_ZLIB && (c->flags & FLAG_PNGFILTER))
00601 av_log(avctx, AV_LOG_DEBUG, "PNG filter flag set.\n");
00602 if (c->flags & FLAGMASK_UNUSED)
00603 av_log(avctx, AV_LOG_ERROR, "Unknown flag set (%d).\n", c->flags);
00604
00605
00606 #if CONFIG_ZLIB_DECODER
00607 if (avctx->codec_id == AV_CODEC_ID_ZLIB) {
00608 int zret;
00609 c->zstream.zalloc = Z_NULL;
00610 c->zstream.zfree = Z_NULL;
00611 c->zstream.opaque = Z_NULL;
00612 zret = inflateInit(&c->zstream);
00613 if (zret != Z_OK) {
00614 av_log(avctx, AV_LOG_ERROR, "Inflate init error: %d\n", zret);
00615 av_freep(&c->decomp_buf);
00616 return AVERROR_UNKNOWN;
00617 }
00618 }
00619 #endif
00620
00621 return 0;
00622 }
00623
00624
00625
00626
00627
00628
00629 static av_cold int decode_end(AVCodecContext *avctx)
00630 {
00631 LclDecContext * const c = avctx->priv_data;
00632
00633 av_freep(&c->decomp_buf);
00634 if (c->pic.data[0])
00635 avctx->release_buffer(avctx, &c->pic);
00636 #if CONFIG_ZLIB_DECODER
00637 if (avctx->codec_id == AV_CODEC_ID_ZLIB)
00638 inflateEnd(&c->zstream);
00639 #endif
00640
00641 return 0;
00642 }
00643
00644 #if CONFIG_MSZH_DECODER
00645 AVCodec ff_mszh_decoder = {
00646 .name = "mszh",
00647 .type = AVMEDIA_TYPE_VIDEO,
00648 .id = AV_CODEC_ID_MSZH,
00649 .priv_data_size = sizeof(LclDecContext),
00650 .init = decode_init,
00651 .close = decode_end,
00652 .decode = decode_frame,
00653 .capabilities = CODEC_CAP_DR1,
00654 .long_name = NULL_IF_CONFIG_SMALL("LCL (LossLess Codec Library) MSZH"),
00655 };
00656 #endif
00657
00658 #if CONFIG_ZLIB_DECODER
00659 AVCodec ff_zlib_decoder = {
00660 .name = "zlib",
00661 .type = AVMEDIA_TYPE_VIDEO,
00662 .id = AV_CODEC_ID_ZLIB,
00663 .priv_data_size = sizeof(LclDecContext),
00664 .init = decode_init,
00665 .close = decode_end,
00666 .decode = decode_frame,
00667 .capabilities = CODEC_CAP_DR1,
00668 .long_name = NULL_IF_CONFIG_SMALL("LCL (LossLess Codec Library) ZLIB"),
00669 };
00670 #endif