Re: [FFmpeg-devel] [PATCH]lavc/tiff: Allow decoding of cmyka (five components)

2019-03-20 Thread Carl Eugen Hoyos
2019-02-07 20:07 GMT+01:00, Carl Eugen Hoyos :

> Attached patch fixes ticket #7675.

Patch applied.

Carl Eugen
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH]lavc/tiff: Allow decoding of cmyka (five components)

2019-02-14 Thread Carl Eugen Hoyos
2019-02-07 20:07 GMT+01:00, Carl Eugen Hoyos :
> Hi!
>
> Attached patch fixes ticket #7675.

Ping.

Carl Eugen
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH]lavc/tiff: Allow decoding of cmyka (five components)

2019-02-07 Thread Carl Eugen Hoyos
Hi!

Attached patch fixes ticket #7675.

Please comment, Carl Eugen
From 7c1f5eeb2c266c33f57d8e2b78bacfba3b30a471 Mon Sep 17 00:00:00 2001
From: Carl Eugen Hoyos 
Date: Thu, 7 Feb 2019 20:05:10 +0100
Subject: [PATCH] lavc/tiff: Allow decoding of cmyka (five components).

Fixes ticket #7675.
---
 libavcodec/tiff.c |   35 ++-
 1 file changed, 26 insertions(+), 9 deletions(-)

diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c
index 112f5b5..aad3934 100644
--- a/libavcodec/tiff.c
+++ b/libavcodec/tiff.c
@@ -827,6 +827,10 @@ static int init_image(TiffContext *s, ThreadFrame *frame)
 case 324:
 s->avctx->pix_fmt = s->photometric == TIFF_PHOTOMETRIC_SEPARATED ? AV_PIX_FMT_RGB0 : AV_PIX_FMT_RGBA;
 break;
+case 405:
+if (s->photometric == TIFF_PHOTOMETRIC_SEPARATED)
+s->avctx->pix_fmt = AV_PIX_FMT_RGBA;
+break;
 case 483:
 s->avctx->pix_fmt = s->le ? AV_PIX_FMT_RGB48LE  : AV_PIX_FMT_RGB48BE;
 break;
@@ -944,7 +948,7 @@ static int tiff_decode_tag(TiffContext *s, AVFrame *frame)
 s->height = value;
 break;
 case TIFF_BPP:
-if (count > 4U) {
+if (count > 5U) {
 av_log(s->avctx, AV_LOG_ERROR,
"This format is not supported (bpp=%d, %d components)\n",
value, count);
@@ -975,7 +979,7 @@ static int tiff_decode_tag(TiffContext *s, AVFrame *frame)
"Samples per pixel requires a single value, many provided\n");
 return AVERROR_INVALIDDATA;
 }
-if (value > 4U) {
+if (value > 5U) {
 av_log(s->avctx, AV_LOG_ERROR,
"Samples per pixel %d is too large\n", value);
 return AVERROR_INVALIDDATA;
@@ -1449,10 +1453,19 @@ again:
 
 planes = s->planar ? s->bppcount : 1;
 for (plane = 0; plane < planes; plane++) {
+uint8_t *five_planes = NULL;
 int remaining = avpkt->size;
 int decoded_height;
 stride = p->linesize[plane];
 dst = p->data[plane];
+if (s->photometric == TIFF_PHOTOMETRIC_SEPARATED &&
+s->avctx->pix_fmt == AV_PIX_FMT_RGBA) {
+stride = stride * 5 / 4;
+five_planes =
+dst = av_malloc(stride * s->height);
+if (!dst)
+return AVERROR(ENOMEM);
+}
 for (i = 0; i < s->height; i += s->rps) {
 if (i)
 dst += s->rps * stride;
@@ -1485,7 +1498,7 @@ again:
 av_log(s->avctx, AV_LOG_ERROR, "predictor == 2 with YUV is unsupported");
 return AVERROR_PATCHWELCOME;
 }
-dst   = p->data[plane];
+dst   = five_planes ? five_planes : p->data[plane];
 soff  = s->bpp >> 3;
 if (s->planar)
 soff  = FFMAX(soff / s->bppcount, 1);
@@ -1532,21 +1545,25 @@ again:
 }
 
 if (s->photometric == TIFF_PHOTOMETRIC_SEPARATED &&
-s->avctx->pix_fmt == AV_PIX_FMT_RGB0) {
+(s->avctx->pix_fmt == AV_PIX_FMT_RGB0 || s->avctx->pix_fmt == AV_PIX_FMT_RGBA)) {
+int x = s->avctx->pix_fmt == AV_PIX_FMT_RGB0 ? 4 : 5;
+uint8_t *src = five_planes ? five_planes : p->data[plane];
 dst = p->data[plane];
 for (i = 0; i < s->height; i++) {
 for (j = 0; j < s->width; j++) {
-int k =  255 - dst[4 * j + 3];
-int r = (255 - dst[4 * j]) * k;
-int g = (255 - dst[4 * j + 1]) * k;
-int b = (255 - dst[4 * j + 2]) * k;
+int k =  255 - src[x * j + 3];
+int r = (255 - src[x * j]) * k;
+int g = (255 - src[x * j + 1]) * k;
+int b = (255 - src[x * j + 2]) * k;
 dst[4 * j] = r * 257 >> 16;
 dst[4 * j + 1] = g * 257 >> 16;
 dst[4 * j + 2] = b * 257 >> 16;
-dst[4 * j + 3] = 255;
+dst[4 * j + 3] = s->avctx->pix_fmt == AV_PIX_FMT_RGBA ? src[x * j + 4] : 255;
 }
+src += stride;
 dst += p->linesize[plane];
 }
+av_freep(_planes);
 }
 }
 
-- 
1.7.10.4

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel