[FFmpeg-devel] [PATCH] tiffdec: use av_fast_padded_malloc
Paul B Mahol
onemda at gmail.com
Thu Dec 20 18:25:22 CET 2012
Signed-off-by: Paul B Mahol <onemda at gmail.com>
---
libavcodec/tiff.c | 35 +++++++++++++----------------------
1 file changed, 13 insertions(+), 22 deletions(-)
diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c
index e92967d..0ecd270 100644
--- a/libavcodec/tiff.c
+++ b/libavcodec/tiff.c
@@ -408,7 +408,7 @@ 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 *src2 = NULL, *zbuf;
+ uint8_t *src2, *zbuf;
unsigned long outlen;
int i, ret;
outlen = width * lines;
@@ -416,15 +416,14 @@ static int tiff_unpack_strip(TiffContext *s, uint8_t *dst, int stride,
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_fast_padded_malloc(&s->deinvert_buf, &s->deinvert_buf_size, size);
+ if (!s->deinvert_buf) {
av_free(zbuf);
return AVERROR(ENOMEM);
}
+ src2 = s->deinvert_buf;
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);
@@ -432,7 +431,6 @@ static int tiff_unpack_strip(TiffContext *s, uint8_t *dst, int stride,
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;
}
@@ -446,7 +444,6 @@ static int tiff_unpack_strip(TiffContext *s, uint8_t *dst, int stride,
dst += stride;
src += width;
}
- av_free(src2);
av_free(zbuf);
return 0;
}
@@ -470,32 +467,27 @@ static int tiff_unpack_strip(TiffContext *s, uint8_t *dst, int stride,
if (s->compr == TIFF_CCITT_RLE || s->compr == TIFF_G3
|| s->compr == TIFF_G4) {
int i, ret = 0;
- uint8_t *src2 = av_malloc((unsigned)size +
- FF_INPUT_BUFFER_PADDING_SIZE);
- if (!src2) {
- av_log(s->avctx, AV_LOG_ERROR,
- "Error allocating temporary buffer\n");
- return AVERROR(ENOMEM);
- }
if (s->fax_opts & 2) {
av_log(s->avctx, AV_LOG_ERROR,
"Uncompressed fax mode is not supported (yet)\n");
- av_free(src2);
return -1;
}
- if (!s->fill_order) {
- memcpy(src2, src, size);
- } else {
+
+ if (s->fill_order) {
+ 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++)
- src2[i] = ff_reverse[src[i]];
+ s->deinvert_buf[i] = ff_reverse[src[i]];
+ src = s->deinvert_buf;
}
- memset(src2 + size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
+
switch (s->compr) {
case TIFF_CCITT_RLE:
case TIFF_G3:
case TIFF_G4:
- ret = ff_ccitt_unpack(s->avctx, src2, size, dst, lines, stride,
+ ret = ff_ccitt_unpack(s->avctx, src, size, dst, lines, stride,
s->compr, s->fax_opts);
break;
}
@@ -504,7 +496,6 @@ static int tiff_unpack_strip(TiffContext *s, uint8_t *dst, int stride,
horizontal_fill(s->bpp, dst, 1, dst, 0, width, 0);
dst += stride;
}
- av_free(src2);
return ret;
}
for (line = 0; line < lines; line++) {
--
1.7.11.4
More information about the ffmpeg-devel
mailing list