[FFmpeg-devel] [PATCH] tiff: planar rgb
Paul B Mahol
onemda at gmail.com
Thu May 9 21:52:40 CEST 2013
Signed-off-by: Paul B Mahol <onemda at gmail.com>
---
libavcodec/tiff.c | 30 ++++++++++++++++++++----------
1 file changed, 20 insertions(+), 10 deletions(-)
diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c
index 6c2dc23..c8ab0ab 100644
--- a/libavcodec/tiff.c
+++ b/libavcodec/tiff.c
@@ -52,6 +52,7 @@ typedef struct TiffContext {
int le;
enum TiffCompr compr;
int invert;
+ int planar;
int fax_opts;
int predictor;
int fill_order;
@@ -416,7 +417,7 @@ static int tiff_unpack_strip(TiffContext *s, uint8_t *dst, int stride,
{
int c, line, pixels, code, ret;
const uint8_t *ssrc = src;
- int width = ((s->width * s->bpp) + 7) >> 3;
+ int width = s->planar ? s->width : ((s->width * s->bpp) + 7) >> 3;
if (size <= 0)
return AVERROR_INVALIDDATA;
@@ -613,7 +614,7 @@ static int init_image(TiffContext *s, AVFrame *frame)
s->avctx->pix_fmt = AV_PIX_FMT_PAL8;
break;
case 243:
- s->avctx->pix_fmt = AV_PIX_FMT_RGB24;
+ s->avctx->pix_fmt = s->planar ? AV_PIX_FMT_GBRP : AV_PIX_FMT_RGB24;
break;
case 161:
s->avctx->pix_fmt = s->le ? AV_PIX_FMT_GRAY16LE : AV_PIX_FMT_GRAY16BE;
@@ -622,7 +623,7 @@ static int init_image(TiffContext *s, AVFrame *frame)
s->avctx->pix_fmt = AV_PIX_FMT_GRAY8A;
break;
case 324:
- s->avctx->pix_fmt = AV_PIX_FMT_RGBA;
+ s->avctx->pix_fmt = s->planar ? AV_PIX_FMT_GBRAP : AV_PIX_FMT_RGBA;
break;
case 483:
s->avctx->pix_fmt = s->le ? AV_PIX_FMT_RGB48LE : AV_PIX_FMT_RGB48BE;
@@ -880,10 +881,7 @@ static int tiff_decode_tag(TiffContext *s, AVFrame *frame)
s->palette_is_set = 1;
break;
case TIFF_PLANAR:
- if (value == 2) {
- av_log(s->avctx, AV_LOG_ERROR, "Planar format is not supported\n");
- return AVERROR_PATCHWELCOME;
- }
+ s->planar = value == 2;
break;
case TIFF_T4OPTIONS:
if (s->compr == TIFF_G3)
@@ -1038,7 +1036,7 @@ static int decode_frame(AVCodecContext *avctx,
TiffContext *const s = avctx->priv_data;
AVFrame *const p = data;
unsigned off;
- int id, le, ret;
+ int id, le, ret, plane, planes;
int i, j, entries;
int stride;
unsigned soff, ssize;
@@ -1121,8 +1119,6 @@ static int decode_frame(AVCodecContext *avctx,
av_log(avctx, AV_LOG_WARNING, "Image data size missing\n");
s->stripsize = avpkt->size - s->stripoff;
}
- stride = p->linesize[0];
- dst = p->data[0];
if (s->stripsizesoff) {
if (s->stripsizesoff >= (unsigned)avpkt->size)
@@ -1140,6 +1136,10 @@ static int decode_frame(AVCodecContext *avctx,
return AVERROR_INVALIDDATA;
}
+ planes = s->planar ? s->bpp >> 3 : 1;
+ for (plane = 0; plane < planes; plane++) {
+ stride = p->linesize[plane];
+ dst = p->data[plane];
for (i = 0; i < s->height; i += s->rps) {
if (s->stripsizesoff)
ssize = tget(&stripsizes, s->sstype, s->le);
@@ -1160,6 +1160,7 @@ static int decode_frame(AVCodecContext *avctx,
break;
dst += s->rps * stride;
}
+ }
if (s->predictor == 2) {
dst = p->data[0];
soff = s->bpp >> 3;
@@ -1195,6 +1196,15 @@ static int decode_frame(AVCodecContext *avctx,
dst += p->linesize[0];
}
}
+
+ if (avctx->pix_fmt == AV_PIX_FMT_GBRP ||
+ avctx->pix_fmt == AV_PIX_FMT_GBRAP) {
+ FFSWAP(uint8_t*, p->data[0], p->data[2]);
+ FFSWAP(int, p->linesize[0], p->linesize[2]);
+ FFSWAP(uint8_t*, p->data[0], p->data[1]);
+ FFSWAP(int, p->linesize[0], p->linesize[1]);
+ }
+
*got_frame = 1;
return avpkt->size;
--
1.7.11.2
More information about the ffmpeg-devel
mailing list