#include "tiff.h"
#include "tiff_data.h"
#include "faxcompr.h"
+#include "internal.h"
#include "mathops.h"
#include "libavutil/attributes.h"
#include "libavutil/intreadwrite.h"
int stripsizesoff, stripsize, stripoff, strippos;
LZWState *lzw;
+ uint8_t *deinvert_buf;
+ int deinvert_buf_size;
+
int geotag_count;
TiffGeoTag *geotags;
} TiffContext;
#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;
}
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;
}
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;
}
}
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;
}
}
*picture = s->picture;
- *data_size = sizeof(AVPicture);
+ *got_frame = 1;
return avpkt->size;
}
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;