]> git.sesse.net Git - ffmpeg/commitdiff
lavc/tiff: Force DNG pixel data endianness on an edge case
authorNick Renieris <velocityra@gmail.com>
Thu, 29 Aug 2019 13:10:47 +0000 (16:10 +0300)
committerPaul B Mahol <onemda@gmail.com>
Mon, 2 Sep 2019 07:26:52 +0000 (09:26 +0200)
This fixes "X7 RAW" and "X7 CinemaDNG" samples here:
- https://www.dji.com/gr/zenmuse-x7/info#downloads

Signed-off-by: Nick Renieris <velocityra@gmail.com>
libavcodec/tiff.c

index b4015178f2e34a3b60c7d58b95f49b5d62b46064..8cbcbdf7a5600879a6b826db930ee42f6d680217 100644 (file)
@@ -1038,6 +1038,18 @@ static int init_image(TiffContext *s, ThreadFrame *frame)
                    AV_RL32(s->pattern));
             return AVERROR_PATCHWELCOME;
         }
+        /* Force endianness as mentioned in 'DNG Specification: Chapter 3: BitsPerSample'
+           NOTE: The spec actually specifies big-endian, not sure why we need little-endian, but
+                 such images don't work otherwise. Examples are images produced by Zenmuse X7. */
+        if ((s->tiff_type == TIFF_TYPE_DNG || s->tiff_type == TIFF_TYPE_CINEMADNG)
+            && (s->bpp != 8 && s->bpp != 16 && s->bpp != 32)) {
+            switch (s->avctx->pix_fmt) {
+            case AV_PIX_FMT_BAYER_RGGB16BE: s->avctx->pix_fmt = AV_PIX_FMT_BAYER_RGGB16LE; break;
+            case AV_PIX_FMT_BAYER_BGGR16BE: s->avctx->pix_fmt = AV_PIX_FMT_BAYER_BGGR16LE; break;
+            case AV_PIX_FMT_BAYER_GBRG16BE: s->avctx->pix_fmt = AV_PIX_FMT_BAYER_GBRG16LE; break;
+            case AV_PIX_FMT_BAYER_GRBG16BE: s->avctx->pix_fmt = AV_PIX_FMT_BAYER_GRBG16LE; break;
+            }
+        }
         break;
     case 10161:
         switch (AV_RL32(s->pattern)) {