]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/tscc.c
Reindent
[ffmpeg] / libavcodec / tscc.c
index d404719b7ecf8a01b6d6a6f6c154a19632413422..2b717c1481d5688fb96b3722cb34fef5eeb49326 100644 (file)
@@ -20,7 +20,7 @@
  */
 
 /**
- * @file tscc.c
+ * @file
  * TechSmith Camtasia decoder
  *
  * Fourcc: TSCC
@@ -41,9 +41,7 @@
 #include "avcodec.h"
 #include "msrledec.h"
 
-#ifdef CONFIG_ZLIB
 #include <zlib.h>
-#endif
 
 
 /*
@@ -61,9 +59,7 @@ typedef struct TsccContext {
     // Decompression buffer
     unsigned char* decomp_buf;
     int height;
-#ifdef CONFIG_ZLIB
     z_stream zstream;
-#endif
 } CamtasiaContext;
 
 /*
@@ -71,14 +67,14 @@ typedef struct TsccContext {
  * Decode a frame
  *
  */
-static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, const uint8_t *buf, int buf_size)
+static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt)
 {
+    const uint8_t *buf = avpkt->data;
+    int buf_size = avpkt->size;
     CamtasiaContext * const c = avctx->priv_data;
     const unsigned char *encoded = buf;
     unsigned char *outptr;
-#ifdef CONFIG_ZLIB
     int zret; // Zlib return code
-#endif
     int len = buf_size;
 
     if(c->pic.data[0])
@@ -93,7 +89,6 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, const
 
     outptr = c->pic.data[0]; // Output image pointer
 
-#ifdef CONFIG_ZLIB
     zret = inflateReset(&(c->zstream));
     if (zret != Z_OK) {
         av_log(avctx, AV_LOG_ERROR, "Inflate reset error: %d\n", zret);
@@ -112,7 +107,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, const
 
 
     if(zret != Z_DATA_ERROR)
-        ff_msrle_decode(avctx, &c->pic, c->bpp, c->decomp_buf, c->zstream.avail_out);
+        ff_msrle_decode(avctx, (AVPicture*)&c->pic, c->bpp, c->decomp_buf, c->decomp_size - c->zstream.avail_out);
 
     /* make the palette available on the way out */
     if (c->avctx->pix_fmt == PIX_FMT_PAL8) {
@@ -123,11 +118,6 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, const
         }
     }
 
-#else
-    av_log(avctx, AV_LOG_ERROR, "BUG! Zlib support not compiled in frame decoder.\n");
-    return -1;
-#endif
-
     *data_size = sizeof(AVFrame);
     *(AVFrame*)data = c->pic;
 
@@ -149,20 +139,10 @@ static av_cold int decode_init(AVCodecContext *avctx)
 
     c->avctx = avctx;
 
-    c->pic.data[0] = NULL;
     c->height = avctx->height;
 
-    if (avcodec_check_dimensions(avctx, avctx->width, avctx->height) < 0) {
-        return 1;
-    }
-
-#ifdef CONFIG_ZLIB
     // Needed if zlib unused or init aborted before inflateInit
     memset(&(c->zstream), 0, sizeof(z_stream));
-#else
-    av_log(avctx, AV_LOG_ERROR, "Zlib support not compiled.\n");
-    return 1;
-#endif
     switch(avctx->bits_per_coded_sample){
     case  8: avctx->pix_fmt = PIX_FMT_PAL8; break;
     case 16: avctx->pix_fmt = PIX_FMT_RGB555; break;
@@ -174,7 +154,8 @@ static av_cold int decode_init(AVCodecContext *avctx)
              return -1;
     }
     c->bpp = avctx->bits_per_coded_sample;
-    c->decomp_size = (avctx->width * c->bpp + (avctx->width + 254) / 255 + 2) * avctx->height + 2;//RLE in the 'best' case
+    // buffer size for RLE 'best' case when 2-byte code preceeds each pixel and there may be padding after it too
+    c->decomp_size = (((avctx->width * c->bpp + 7) >> 3) + 3 * avctx->width + 2) * avctx->height + 2;
 
     /* Allocate decompression buffer */
     if (c->decomp_size) {
@@ -184,7 +165,6 @@ static av_cold int decode_init(AVCodecContext *avctx)
         }
     }
 
-#ifdef CONFIG_ZLIB
     c->zstream.zalloc = Z_NULL;
     c->zstream.zfree = Z_NULL;
     c->zstream.opaque = Z_NULL;
@@ -193,7 +173,6 @@ static av_cold int decode_init(AVCodecContext *avctx)
         av_log(avctx, AV_LOG_ERROR, "Inflate init error: %d\n", zret);
         return 1;
     }
-#endif
 
     return 0;
 }
@@ -213,16 +192,14 @@ static av_cold int decode_end(AVCodecContext *avctx)
 
     if (c->pic.data[0])
         avctx->release_buffer(avctx, &c->pic);
-#ifdef CONFIG_ZLIB
     inflateEnd(&(c->zstream));
-#endif
 
     return 0;
 }
 
 AVCodec tscc_decoder = {
         "camtasia",
-        CODEC_TYPE_VIDEO,
+        AVMEDIA_TYPE_VIDEO,
         CODEC_ID_TSCC,
         sizeof(CamtasiaContext),
         decode_init,