[FFmpeg-devel,v10,11/13] lavc/tiff: Decode 14-bit DNG images

Submitted by velocityra@gmail.com on Aug. 7, 2019, 3:27 p.m.

Details

Message ID 20190807152723.18892-11-velocityra@gmail.com
State New
Headers show

Commit Message

velocityra@gmail.com Aug. 7, 2019, 3:27 p.m.
From: Nick Renieris <velocityra@gmail.com>

Sample file: https://drive.google.com/open?id=0B4JyRT3Lth5HVndyOTVOdWktM3J4TFEydTk1MnY3RWlpSzVB

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

Patch hide | download patch | download mbox

diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c
index 8a671538aa..a40bcfb3d7 100644
--- a/libavcodec/tiff.c
+++ b/libavcodec/tiff.c
@@ -309,14 +309,18 @@  static void av_always_inline horizontal_fill(TiffContext *s,
             dst[(width+offset)*2+0] = (usePtr ? src[width] : c) >> 4;
         }
         break;
-    case 12: {
-                 uint16_t *dst16 = (uint16_t *)dst;
-                 GetBitContext gb;
-                 init_get_bits8(&gb, src, width);
-                 for (int i = 0; i < s->width; i++) {
-                     dst16[i] = get_bits(&gb, 12) << 4;
-                 }
-             }
+    case 12:
+    case 14: {
+            uint16_t *dst16 = (uint16_t *)dst;
+            int is_dng = (s->tiff_type == TIFF_TYPE_DNG || s->tiff_type == TIFF_TYPE_CINEMADNG);
+            uint8_t shift = is_dng ? 0 : 16 - bpp;
+            GetBitContext gb;
+
+            init_get_bits8(&gb, src, width);
+            for (int i = 0; i < s->width; i++) {
+                dst16[i] = get_bits(&gb, bpp) << shift;
+            }
+        }
         break;
     default:
         if (usePtr) {
@@ -1058,6 +1062,7 @@  static int init_image(TiffContext *s, ThreadFrame *frame)
         }
         break;
     case 10121:
+    case 10141:
         switch (AV_RL32(s->pattern)) {
         case 0x02010100:
             s->avctx->pix_fmt = s->le ? AV_PIX_FMT_BAYER_RGGB16LE : AV_PIX_FMT_BAYER_RGGB16BE;