• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • Examples
  • File List
  • Globals

libavcodec/lcldec.c

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

Generated on Fri Feb 22 2013 07:24:27 for FFmpeg by  doxygen 1.7.1