]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/tiff.c
hpel_motion_search: move code used for asserts under correct #if
[ffmpeg] / libavcodec / tiff.c
index 34fb10999dacb83b55bd8ea2861c81baba7de5a9..e92967d01e9e6e8f1a0766e068e730231797b958 100644 (file)
@@ -34,6 +34,7 @@
 #include "tiff.h"
 #include "tiff_data.h"
 #include "faxcompr.h"
+#include "internal.h"
 #include "mathops.h"
 #include "libavutil/attributes.h"
 #include "libavutil/intreadwrite.h"
@@ -61,6 +62,9 @@ typedef struct TiffContext {
     int stripsizesoff, stripsize, stripoff, strippos;
     LZWState *lzw;
 
+    uint8_t *deinvert_buf;
+    int deinvert_buf_size;
+
     int geotag_count;
     TiffGeoTag *geotags;
 } TiffContext;
@@ -404,18 +408,31 @@ static int tiff_unpack_strip(TiffContext *s, uint8_t *dst, int stride,
 
 #if CONFIG_ZLIB
     if (s->compr == TIFF_DEFLATE || s->compr == TIFF_ADOBE_DEFLATE) {
-        uint8_t *zbuf;
+        uint8_t *src2 = NULL, *zbuf;
         unsigned long outlen;
-        int ret;
+        int i, ret;
         outlen = width * lines;
         zbuf = av_malloc(outlen);
         if (!zbuf)
             return AVERROR(ENOMEM);
+        if (s->fill_order) {
+            src2 = av_malloc((unsigned)size + FF_INPUT_BUFFER_PADDING_SIZE);
+            if (!src2) {
+                av_log(s->avctx, AV_LOG_ERROR, "Error allocating temporary buffer\n");
+                av_free(zbuf);
+                return AVERROR(ENOMEM);
+            }
+            for (i = 0; i < size; i++)
+                src2[i] = ff_reverse[src[i]];
+            memset(src2 + size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
+            src = src2;
+        }
         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(src2);
             av_free(zbuf);
             return -1;
         }
@@ -429,11 +446,22 @@ static int tiff_unpack_strip(TiffContext *s, uint8_t *dst, int stride,
             dst += stride;
             src += width;
         }
+        av_free(src2);
         av_free(zbuf);
         return 0;
     }
 #endif
     if (s->compr == TIFF_LZW) {
+        if (s->fill_order) {
+            int i;
+            av_fast_padded_malloc(&s->deinvert_buf, &s->deinvert_buf_size, size);
+            if (!s->deinvert_buf)
+                return AVERROR(ENOMEM);
+            for (i = 0; i < size; i++)
+                s->deinvert_buf[i] = ff_reverse[src[i]];
+            src = s->deinvert_buf;
+            ssrc = src;
+        }
         if (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");
             return -1;
@@ -597,7 +625,7 @@ static int init_image(TiffContext *s)
     }
     if (s->picture.data[0])
         s->avctx->release_buffer(s->avctx, &s->picture);
-    if ((ret = s->avctx->get_buffer(s->avctx, &s->picture)) < 0) {
+    if ((ret = ff_get_buffer(s->avctx, &s->picture)) < 0) {
         av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n");
         return ret;
     }
@@ -983,7 +1011,7 @@ static int tiff_decode_tag(TiffContext *s)
 }
 
 static int decode_frame(AVCodecContext *avctx,
-                        void *data, int *data_size, AVPacket *avpkt)
+                        void *data, int *got_frame, AVPacket *avpkt)
 {
     TiffContext *const s = avctx->priv_data;
     AVFrame *picture = data;
@@ -1150,7 +1178,7 @@ static int decode_frame(AVCodecContext *avctx,
         }
     }
     *picture   = s->picture;
-    *data_size = sizeof(AVPicture);
+    *got_frame = 1;
 
     return avpkt->size;
 }
@@ -1177,6 +1205,7 @@ static av_cold int tiff_end(AVCodecContext *avctx)
     free_geotags(s);
 
     ff_lzw_decode_close(&s->lzw);
+    av_freep(&s->deinvert_buf);
     if (s->picture.data[0])
         avctx->release_buffer(avctx, &s->picture);
     return 0;