]> git.sesse.net Git - ffmpeg/commitdiff
avcodec/tiff: Recognize DNG/CinemaDNG images
authorNick Renieris <velocityra@gmail.com>
Thu, 30 May 2019 10:42:42 +0000 (13:42 +0300)
committerPaul B Mahol <onemda@gmail.com>
Thu, 30 May 2019 17:27:05 +0000 (19:27 +0200)
Additionally:
- Renamed TIFF_WHITE_LEVEL to DNG_WHITE_LEVEL since it is specified
  in the DNG spec.
- Added/changed some comments to be more precise in differentiating
  between TIFF, TIFF/EP and DNG values.

Related to ticket: https://trac.ffmpeg.org/ticket/4364

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

index 3a3f68fa94d706fc3301d4d73031777cd1da3b7c..c520d7df8358507d0f6250f7fa3eb426fda3e25a 100644 (file)
@@ -58,6 +58,7 @@ typedef struct TiffContext {
     uint16_t get_page;
     int get_thumbnail;
 
+    enum TiffType tiff_type;
     int width, height;
     unsigned int bpp, bppcount;
     uint32_t palette[256];
@@ -96,6 +97,11 @@ typedef struct TiffContext {
     TiffGeoTag *geotags;
 } TiffContext;
 
+static void tiff_set_type(TiffContext *s, enum TiffType tiff_type) {
+    if (s->tiff_type < tiff_type) // Prioritize higher-valued entries
+        s->tiff_type = tiff_type;
+}
+
 static void free_geotags(TiffContext *const s)
 {
     int i;
@@ -1095,7 +1101,7 @@ static int tiff_decode_tag(TiffContext *s, AVFrame *frame)
         else if (count > 1)
             s->sub_ifd = ff_tget(&s->gb, TIFF_LONG, s->le); /** Only get the first SubIFD */
         break;
-    case TIFF_WHITE_LEVEL:
+    case DNG_WHITE_LEVEL:
         s->white_level = value;
         break;
     case TIFF_CFA_PATTERN_DIM:
@@ -1346,6 +1352,27 @@ static int tiff_decode_tag(TiffContext *s, AVFrame *frame)
     case TIFF_SOFTWARE_NAME:
         ADD_METADATA(count, "software", NULL);
         break;
+    case DNG_VERSION:
+        if (count == 4) {
+            unsigned int ver[4];
+            ver[0] = ff_tget(&s->gb, type, s->le);
+            ver[1] = ff_tget(&s->gb, type, s->le);
+            ver[2] = ff_tget(&s->gb, type, s->le);
+            ver[3] = ff_tget(&s->gb, type, s->le);
+
+            av_log(s->avctx, AV_LOG_DEBUG, "DNG file, version %u.%u.%u.%u\n",
+                ver[0], ver[1], ver[2], ver[3]);
+
+            tiff_set_type(s, TIFF_TYPE_DNG);
+        }
+        break;
+    case CINEMADNG_TIME_CODES:
+    case CINEMADNG_FRAME_RATE:
+    case CINEMADNG_T_STOP:
+    case CINEMADNG_REEL_NAME:
+    case CINEMADNG_CAMERA_LABEL:
+        tiff_set_type(s, TIFF_TYPE_CINEMADNG);
+        break;
     default:
         if (s->avctx->err_recognition & AV_EF_EXPLODE) {
             av_log(s->avctx, AV_LOG_ERROR,
@@ -1402,6 +1429,7 @@ again:
     s->white_level = 0;
     s->is_bayer    = 0;
     s->cur_page    = 0;
+    s->tiff_type   = TIFF_TYPE_TIFF;
     free_geotags(s);
 
     // Reset these offsets so we can tell if they were set this frame
index 4b08650108883ef642304bcd54d6e43a76ed1f44..81913c6b1ae07acb2b072ad10285e10808cea206 100644 (file)
@@ -20,7 +20,7 @@
 
 /**
  * @file
- * TIFF tables
+ * TIFF constants & data structures
  *
  * For more information about the TIFF format, check the official docs at:
  * http://partners.adobe.com/public/developer/tiff/index.html
 #include <stdint.h>
 #include "tiff_common.h"
 
-/** abridged list of TIFF tags */
+/** TIFF types in ascenting priority (last in the list is highest) */
+enum TiffType {
+    /** TIFF image based on the TIFF 6.0 or TIFF/EP (ISO 12234-2) specifications */
+    TIFF_TYPE_TIFF,
+    /** Digital Negative (DNG) image */
+    TIFF_TYPE_DNG,
+    /** Digital Negative (DNG) image part of an CinemaDNG image sequence */
+    TIFF_TYPE_CINEMADNG,
+};
+
+/** abridged list of TIFF and TIFF/EP tags */
 enum TiffTags {
     TIFF_SUBFILE            = 0xfe,
     TIFF_WIDTH              = 0x100,
@@ -85,10 +95,25 @@ enum TiffTags {
     TIFF_GEO_KEY_DIRECTORY  = 0x87AF,
     TIFF_GEO_DOUBLE_PARAMS  = 0x87B0,
     TIFF_GEO_ASCII_PARAMS   = 0x87B1,
-    TIFF_WHITE_LEVEL        = 0xC61D,
 };
 
-/** list of TIFF compression types */
+/** abridged list of DNG tags */
+enum DngTags {
+    DNG_VERSION             = 0xC612,
+    DNG_BACKWARD_VERSION    = 0xC613,
+    DNG_WHITE_LEVEL         = 0xC61D,
+};
+
+/** list of CinemaDNG tags */
+enum CinemaDngTags {
+    CINEMADNG_TIME_CODES    = 0xC763,
+    CINEMADNG_FRAME_RATE    = 0xC764,
+    CINEMADNG_T_STOP        = 0xC772,
+    CINEMADNG_REEL_NAME     = 0xC789,
+    CINEMADNG_CAMERA_LABEL  = 0xC7A1,
+};
+
+/** list of TIFF, TIFF/EP and DNG compression types */
 enum TiffCompr {
     TIFF_RAW = 1,
     TIFF_CCITT_RLE,
@@ -151,6 +176,7 @@ enum TiffGeoTagKey {
     TIFF_VERTICAL_UNITS_GEOKEY               = 4099
 };
 
+/** list of TIFF, TIFF/AP and DNG PhotometricInterpretation (TIFF_PHOTOMETRIC) values */
 enum TiffPhotometric {
     TIFF_PHOTOMETRIC_NONE       = -1,
     TIFF_PHOTOMETRIC_WHITE_IS_ZERO,      /* mono or grayscale, 0 is white */
@@ -163,7 +189,7 @@ enum TiffPhotometric {
     TIFF_PHOTOMETRIC_CIE_LAB    = 8,     /* 1976 CIE L*a*b* */
     TIFF_PHOTOMETRIC_ICC_LAB,            /* ICC L*a*b* */
     TIFF_PHOTOMETRIC_ITU_LAB,            /* ITU L*a*b* */
-    TIFF_PHOTOMETRIC_CFA        = 32803, /* Color Filter Array (DNG) */
+    TIFF_PHOTOMETRIC_CFA        = 32803, /* Color Filter Array (TIFF/AP and DNG) */
     TIFF_PHOTOMETRIC_LOG_L      = 32844, /* CIE Log2(L) */
     TIFF_PHOTOMETRIC_LOG_LUV,            /* CIE Log L*u*v* */
     TIFF_PHOTOMETRIC_LINEAR_RAW = 34892, /* Linear Raw (DNG) */
index 8432cc09554db2f9e2b46422e7ae292ca2d20296..16bc9d2abd8c68a64b8c6f0d551a7dda8d7cd3f8 100644 (file)
@@ -51,6 +51,7 @@ const IdStrMap ff_img_tags[] = {
     { AV_CODEC_ID_TARGA,      "tga"      },
     { AV_CODEC_ID_TIFF,       "tiff"     },
     { AV_CODEC_ID_TIFF,       "tif"      },
+    { AV_CODEC_ID_TIFF,       "dng"      },
     { AV_CODEC_ID_SGI,        "sgi"      },
     { AV_CODEC_ID_PTX,        "ptx"      },
     { AV_CODEC_ID_PCX,        "pcx"      },