From a58e96be0e6f01721c5a3c26c42d08d6247dd682 Mon Sep 17 00:00:00 2001 From: Kostya Shishkov Date: Thu, 24 Sep 2009 18:30:28 +0000 Subject: [PATCH] Support both LSB and MSB orders for TIFF CCITT G.x compressed data. This fixes issue 1410. Originally committed as revision 20016 to svn://svn.ffmpeg.org/ffmpeg/trunk --- libavcodec/tiff.c | 17 +++++++++++++++-- libavcodec/tiff.h | 1 + 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c index 720a6cf622..af7b40e3ca 100644 --- a/libavcodec/tiff.c +++ b/libavcodec/tiff.c @@ -44,6 +44,7 @@ typedef struct TiffContext { int invert; int fax_opts; int predictor; + int fill_order; int strips, rps, sstype; int sot; @@ -113,8 +114,12 @@ static int tiff_unpack_strip(TiffContext *s, uint8_t* dst, int stride, const uin av_log(s->avctx, AV_LOG_ERROR, "Error allocating temporary buffer\n"); return -1; } - for(i = 0; i < size; i++) - src2[i] = ff_reverse[src[i]]; + if(!s->fill_order){ + memcpy(src2, src, size); + }else{ + for(i = 0; i < size; i++) + src2[i] = ff_reverse[src[i]]; + } memset(src2+size, 0, FF_INPUT_BUFFER_PADDING_SIZE); if(s->compr == TIFF_G3 && !(s->fax_opts & 1)) s->compr = TIFF_CCITT_RLE; @@ -375,6 +380,13 @@ static int tiff_decode_tag(TiffContext *s, const uint8_t *start, const uint8_t * return -1; } break; + case TIFF_FILL_ORDER: + if(value < 1 || value > 2){ + av_log(s->avctx, AV_LOG_ERROR, "Unknown FillOrder value %d, trying default one\n", value); + value = 1; + } + s->fill_order = value - 1; + break; case TIFF_PAL: if(s->avctx->pix_fmt != PIX_FMT_PAL8){ av_log(s->avctx, AV_LOG_ERROR, "Palette met but this is not palettized format\n"); @@ -433,6 +445,7 @@ static int decode_frame(AVCodecContext *avctx, s->le = le; s->invert = 0; s->compr = TIFF_RAW; + s->fill_order = 0; // As TIFF 6.0 specification puts it "An arbitrary but carefully chosen number // that further identifies the file as a TIFF file" if(tget_short(&buf, le) != 42){ diff --git a/libavcodec/tiff.h b/libavcodec/tiff.h index e53c6e85f3..17c65b921c 100644 --- a/libavcodec/tiff.h +++ b/libavcodec/tiff.h @@ -37,6 +37,7 @@ enum TiffTags{ TIFF_BPP, TIFF_COMPR, TIFF_INVERT = 0x106, + TIFF_FILL_ORDER = 0x10A, TIFF_STRIP_OFFS = 0x111, TIFF_SAMPLES_PER_PIXEL = 0x115, TIFF_ROWSPERSTRIP = 0x116,