[FFmpeg-devel,v12,14/14] lavc/tiff: Initialize WhiteLevel DNG tag value

Submitted by velocityra@gmail.com on Aug. 9, 2019, 4:29 p.m.

Details

Message ID 20190809162959.17924-14-velocityra@gmail.com
State New
Headers show

Commit Message

velocityra@gmail.com Aug. 9, 2019, 4:29 p.m.
From: Nick Renieris <velocityra@gmail.com>

Inited to (2^BitsPerSample)-1 as per the DNG Specification

This fixes decoding for "X7 CinemaDNG" samples here:
- https://www.dji.com/gr/zenmuse-x7/info#downloads

Signed-off-by: Nick Renieris <velocityra@gmail.com>
---
 libavcodec/tiff.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

Patch hide | download patch | download mbox

diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c
index b9aa4efd02..aeb80a70a9 100644
--- a/libavcodec/tiff.c
+++ b/libavcodec/tiff.c
@@ -1773,6 +1773,7 @@  static int decode_frame(AVCodecContext *avctx,
     GetByteContext stripsizes;
     GetByteContext stripdata;
     int retry_for_subifd, retry_for_page;
+    int is_dng;
 
     bytestream2_init(&s->gb, avpkt->data, avpkt->size);
 
@@ -1841,6 +1842,10 @@  again:
         goto again;
     }
 
+    /* At this point we've decided on which (Sub)IFD to process */
+
+    is_dng = (s->tiff_type == TIFF_TYPE_DNG || s->tiff_type == TIFF_TYPE_CINEMADNG);
+
     for (i = 0; i<s->geotag_count; i++) {
         const char *keyname = get_geokey_name(s->geotags[i].key);
         if (!keyname) {
@@ -1858,10 +1863,13 @@  again:
         }
     }
 
+    s->white_level = (1 << s->bpp) - 1; /* Default value as per the spec */
+
     if (!s->is_tiled && !s->strippos && !s->stripoff) {
         av_log(avctx, AV_LOG_ERROR, "Image data is missing\n");
         return AVERROR_INVALIDDATA;
     }
+
     /* now we have the data and may start decoding */
     if ((ret = init_image(s, &frame)) < 0)
         return ret;
@@ -1893,7 +1901,7 @@  again:
 
     /* Handle DNG images with JPEG-compressed tiles */
 
-    if ((s->tiff_type == TIFF_TYPE_DNG || s->tiff_type == TIFF_TYPE_CINEMADNG) && s->is_tiled) {
+    if (is_dng && s->is_tiled) {
         if (!s->is_jpeg) {
             avpriv_report_missing_feature(avctx, "DNG uncompressed tiled images");
             return AVERROR_PATCHWELCOME;
@@ -2051,8 +2059,7 @@  again:
         FFSWAP(int,      p->linesize[0], p->linesize[1]);
     }
 
-    if (s->is_bayer && s->white_level && s->bpp == 16 &&
-        !(s->tiff_type == TIFF_TYPE_DNG || s->tiff_type == TIFF_TYPE_CINEMADNG)) {
+    if (s->is_bayer && s->bpp == 16 && !is_dng && (s->white_level != (1 << s->bpp) - 1)) {
         uint16_t *dst = (uint16_t *)p->data[0];
         for (i = 0; i < s->height; i++) {
             for (j = 0; j < s->width; j++)