[FFmpeg-devel,v15,08/15] lavc/tiff: Force DNG pixel data endianness on an edge case

Submitted by velocityra@gmail.com on Aug. 20, 2019, 1:37 p.m.

Details

Message ID 20190820133747.30983-8-velocityra@gmail.com
State New
Headers show

Commit Message

velocityra@gmail.com Aug. 20, 2019, 1:37 p.m.
Signed-off-by: Nick Renieris <velocityra@gmail.com>
---
 libavcodec/tiff.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

Comments

Moritz Barsnick Aug. 22, 2019, 12:56 p.m.
On Tue, Aug 20, 2019 at 16:37:40 +0300, Nick Renieris wrote:
> +        /* 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. */

Were there certain samples which exposed this need? Do you want to
share a link? Are you sure the samples are correctly encoded?

Cheers,
Moritz

Patch hide | download patch | download mbox

diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c
index 1ca9a59dbf..d9750891d4 100644
--- a/libavcodec/tiff.c
+++ b/libavcodec/tiff.c
@@ -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. */
+        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)) {