diff mbox

[FFmpeg-devel] lavc/tiff: Support some CMYK samples

Message ID CAB0OVGqi5KF2FwdV1Ud5oem710fUfTFRRxjH5DfdMh9O+7G7og@mail.gmail.com
State Accepted
Headers show

Commit Message

Carl Eugen Hoyos Jan. 11, 2019, 2:54 p.m. UTC
Hi!

Attached patch that fixes the sample from ticket #3459 cannot be
factorized with the code in mjpegdec (and psd), the representation is
different.

Please comment, Carl Eugen

Comments

Derek Buitenhuis Jan. 11, 2019, 3:36 p.m. UTC | #1
On 11/01/2019 14:54, Carl Eugen Hoyos wrote:
> Hi!
> 
> Attached patch that fixes the sample from ticket #3459 cannot be
> factorized with the code in mjpegdec (and psd), the representation is
> different.

Is there a good reason this is RGB0 instead of RGB24?

Other than that, seems OK, if tested (is there a FATE sample we can add?)

- Derek
Carl Eugen Hoyos Jan. 12, 2019, 4:31 p.m. UTC | #2
2019-01-11 16:36 GMT+01:00, Derek Buitenhuis <derek.buitenhuis@gmail.com>:
> On 11/01/2019 14:54, Carl Eugen Hoyos wrote:

>> Attached patch that fixes the sample from ticket #3459 cannot be
>> factorized with the code in mjpegdec (and psd), the representation is
>> different.
>
> Is there a good reason this is RGB0 instead of RGB24?

It would make the code much more complicated for no obvious
benefit (imo). Once somebody implements 5-component cmyk
in tiff, this can be changed as well.

> Other than that, seems OK, if tested

Patch applied, thank you!

> (is there a FATE sample we can add?)

Will look into a test.

Thank you, Carl Eugen
diff mbox

Patch

From c4f9f6248af4b277695b90bf3d2efdc8687d70d3 Mon Sep 17 00:00:00 2001
From: Carl Eugen Hoyos <ceffmpeg@gmail.com>
Date: Fri, 11 Jan 2019 15:44:17 +0100
Subject: [PATCH] lavc/tiff: Support CMYK images.

Fixes ticket #3459.
---
 libavcodec/tiff.c |   22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c
index 570b3cb..5a4271c 100644
--- a/libavcodec/tiff.c
+++ b/libavcodec/tiff.c
@@ -825,7 +825,7 @@  static int init_image(TiffContext *s, ThreadFrame *frame)
         s->avctx->pix_fmt = s->le ? AV_PIX_FMT_YA16LE : AV_PIX_FMT_YA16BE;
         break;
     case 324:
-        s->avctx->pix_fmt = AV_PIX_FMT_RGBA;
+        s->avctx->pix_fmt = s->photometric == TIFF_PHOTOMETRIC_SEPARATED ? AV_PIX_FMT_RGB0 : AV_PIX_FMT_RGBA;
         break;
     case 483:
         s->avctx->pix_fmt = s->le ? AV_PIX_FMT_RGB48LE  : AV_PIX_FMT_RGB48BE;
@@ -1100,12 +1100,12 @@  static int tiff_decode_tag(TiffContext *s, AVFrame *frame)
         case TIFF_PHOTOMETRIC_BLACK_IS_ZERO:
         case TIFF_PHOTOMETRIC_RGB:
         case TIFF_PHOTOMETRIC_PALETTE:
+        case TIFF_PHOTOMETRIC_SEPARATED:
         case TIFF_PHOTOMETRIC_YCBCR:
         case TIFF_PHOTOMETRIC_CFA:
             s->photometric = value;
             break;
         case TIFF_PHOTOMETRIC_ALPHA_MASK:
-        case TIFF_PHOTOMETRIC_SEPARATED:
         case TIFF_PHOTOMETRIC_CIE_LAB:
         case TIFF_PHOTOMETRIC_ICC_LAB:
         case TIFF_PHOTOMETRIC_ITU_LAB:
@@ -1530,6 +1530,24 @@  again:
                 dst += stride;
             }
         }
+
+        if (s->photometric == TIFF_PHOTOMETRIC_SEPARATED &&
+            s->avctx->pix_fmt == AV_PIX_FMT_RGB0) {
+            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;
+                    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 += p->linesize[plane];
+            }
+        }
     }
 
     if (s->planar && s->bppcount > 2) {
-- 
1.7.10.4