diff mbox

[FFmpeg-devel] lavc/tiff: Support decoding 16bit cmyk

Message ID CAB0OVGr_zAO54GXV0D7VtMNyEU_xFhw2yhsPjvQNSD-+iUf95A@mail.gmail.com
State Accepted
Headers show

Commit Message

Carl Eugen Hoyos March 9, 2019, 10:08 a.m. UTC
Hi!

Attached patch improves decoding this image, reported by Ulf Zibis:
http://samples.ffmpeg.org/image-samples/flower-separated-contig-16.tif

Please comment, Carl Eugen

Comments

Carl Eugen Hoyos March 20, 2019, 4:10 p.m. UTC | #1
2019-03-09 11:08 GMT+01:00, Carl Eugen Hoyos <ceffmpeg@gmail.com>:

> Attached patch improves decoding this image, reported by Ulf Zibis:
> http://samples.ffmpeg.org/image-samples/flower-separated-contig-16.tif

Patch applied.

Carl Eugen
diff mbox

Patch

From 7e98c7167f62506ed726780a1f32216515f4e29f Mon Sep 17 00:00:00 2001
From: Carl Eugen Hoyos <ceffmpeg@gmail.com>
Date: Sat, 9 Mar 2019 11:05:36 +0100
Subject: [PATCH] lavc/tiff: Support decoding 16bit cmyk.

---
 libavcodec/tiff.c |   16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c
index 112f5b5..828ed9e 100644
--- a/libavcodec/tiff.c
+++ b/libavcodec/tiff.c
@@ -1547,6 +1547,22 @@  again:
                 }
                 dst += p->linesize[plane];
             }
+        } else if (s->photometric == TIFF_PHOTOMETRIC_SEPARATED &&
+            s->avctx->pix_fmt == AV_PIX_FMT_RGBA64BE) {
+            dst = p->data[plane];
+            for (i = 0; i < s->height; i++) {
+                for (j = 0; j < s->width; j++) {
+                    uint64_t k =  65535 - AV_RB16(dst + 8 * j + 6);
+                    uint64_t r = (65535 - AV_RB16(dst + 8 * j    )) * k;
+                    uint64_t g = (65535 - AV_RB16(dst + 8 * j + 2)) * k;
+                    uint64_t b = (65535 - AV_RB16(dst + 8 * j + 4)) * k;
+                    AV_WB16(dst + 8 * j    , r * 65537 >> 32);
+                    AV_WB16(dst + 8 * j + 2, g * 65537 >> 32);
+                    AV_WB16(dst + 8 * j + 4, b * 65537 >> 32);
+                    AV_WB16(dst + 8 * j + 6, 65535);
+                }
+                dst += p->linesize[plane];
+            }
         }
     }
 
-- 
1.7.10.4