[FFmpeg-cvslog] tiff: refactor deflate support in a separate function

Luca Barbato git at videolan.org
Sat Jun 8 11:28:19 CEST 2013


ffmpeg | branch: master | Luca Barbato <lu_zero at gentoo.org> | Mon Jun  3 03:51:05 2013 +0200| [103937681d7e6afd3e8caf8937272575e450fb55] | committer: Luca Barbato

tiff: refactor deflate support in a separate function

Report when zlib support is missing.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=103937681d7e6afd3e8caf8937272575e450fb55
---

 libavcodec/tiff.c |   62 ++++++++++++++++++++++++++++++++---------------------
 1 file changed, 37 insertions(+), 25 deletions(-)

diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c
index a2fae32..e4ea0ba 100644
--- a/libavcodec/tiff.c
+++ b/libavcodec/tiff.c
@@ -111,6 +111,35 @@ static int tiff_uncompress(uint8_t *dst, unsigned long *len, const uint8_t *src,
     *len = zstream.total_out;
     return zret == Z_STREAM_END ? Z_OK : zret;
 }
+
+static int tiff_unpack_zlib(TiffContext *s, uint8_t *dst, int stride,
+                            const uint8_t *src, int size,
+                            int width, int lines)
+{
+    uint8_t *zbuf;
+    unsigned long outlen;
+    int ret, line;
+    outlen = width * lines;
+    zbuf   = av_malloc(outlen);
+    if (!zbuf)
+        return AVERROR(ENOMEM);
+    ret = tiff_uncompress(zbuf, &outlen, src, size);
+    if (ret != Z_OK) {
+        av_log(s->avctx, AV_LOG_ERROR,
+               "Uncompressing failed (%lu of %lu) with error %d\n", outlen,
+               (unsigned long)width * lines, ret);
+        av_free(zbuf);
+        return AVERROR_UNKNOWN;
+    }
+    src = zbuf;
+    for (line = 0; line < lines; line++) {
+        memcpy(dst, src, width);
+        dst += stride;
+        src += width;
+    }
+    av_free(zbuf);
+    return 0;
+}
 #endif
 
 static int tiff_unpack_strip(TiffContext *s, uint8_t *dst, int stride,
@@ -123,33 +152,16 @@ static int tiff_unpack_strip(TiffContext *s, uint8_t *dst, int stride,
     if (size <= 0)
         return AVERROR_INVALIDDATA;
 
-#if CONFIG_ZLIB
     if (s->compr == TIFF_DEFLATE || s->compr == TIFF_ADOBE_DEFLATE) {
-        uint8_t *zbuf;
-        unsigned long outlen;
-        int ret;
-        outlen = width * lines;
-        zbuf   = av_malloc(outlen);
-        if (!zbuf)
-            return AVERROR(ENOMEM);
-        ret = tiff_uncompress(zbuf, &outlen, src, size);
-        if (ret != Z_OK) {
-            av_log(s->avctx, AV_LOG_ERROR,
-                   "Uncompressing failed (%lu of %lu) with error %d\n", outlen,
-                   (unsigned long)width * lines, ret);
-            av_free(zbuf);
-            return AVERROR_UNKNOWN;
-        }
-        src = zbuf;
-        for (line = 0; line < lines; line++) {
-            memcpy(dst, src, width);
-            dst += stride;
-            src += width;
-        }
-        av_free(zbuf);
-        return 0;
-    }
+#if CONFIG_ZLIB
+        return tiff_unpack_zlib(s, dst, stride, src, size, width, lines);
+#else
+        av_log(s->avctx, AV_LOG_ERROR,
+               "zlib support not enabled, "
+               "deflate compression not supported\n");
+        return AVERROR(ENOSYS);
 #endif
+    }
     if (s->compr == TIFF_LZW) {
         if ((ret = ff_lzw_decode_init(s->lzw, 8, src, size, FF_LZW_TIFF)) < 0) {
             av_log(s->avctx, AV_LOG_ERROR, "Error initializing LZW decoder\n");



More information about the ffmpeg-cvslog mailing list