[SCM] libav/experimental: tiff: use a better name and enum values for PhotometricInterpretation

siretart at users.alioth.debian.org siretart at users.alioth.debian.org
Sun Aug 10 16:02:48 UTC 2014


The following commit has been merged in the experimental branch:
commit a9b046fb0ae5395c4d1d8a82cd0d3e354b5034ed
Author: Justin Ruggles <justin.ruggles at gmail.com>
Date:   Mon Sep 30 00:39:51 2013 -0400

    tiff: use a better name and enum values for PhotometricInterpretation
    
    Also add additional known values and log as missing features.

diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c
index e7f1866..b32435c 100644
--- a/libavcodec/tiff.c
+++ b/libavcodec/tiff.c
@@ -51,7 +51,7 @@ typedef struct TiffContext {
     int palette_is_set;
     int le;
     enum TiffCompr compr;
-    int invert;
+    enum TiffPhotometric photometric;
     int fax_opts;
     int predictor;
     int fill_order;
@@ -447,20 +447,31 @@ static int tiff_decode_tag(TiffContext *s)
     case TIFF_PREDICTOR:
         s->predictor = value;
         break;
-    case TIFF_INVERT:
+    case TIFF_PHOTOMETRIC:
         switch (value) {
-        case 0:
-            s->invert = 1;
-            break;
-        case 1:
-            s->invert = 0;
-            break;
-        case 2:
-        case 3:
+        case TIFF_PHOTOMETRIC_WHITE_IS_ZERO:
+        case TIFF_PHOTOMETRIC_BLACK_IS_ZERO:
+        case TIFF_PHOTOMETRIC_RGB:
+        case TIFF_PHOTOMETRIC_PALETTE:
+            s->photometric = value;
             break;
+        case TIFF_PHOTOMETRIC_ALPHA_MASK:
+        case TIFF_PHOTOMETRIC_SEPARATED:
+        case TIFF_PHOTOMETRIC_YCBCR:
+        case TIFF_PHOTOMETRIC_CIE_LAB:
+        case TIFF_PHOTOMETRIC_ICC_LAB:
+        case TIFF_PHOTOMETRIC_ITU_LAB:
+        case TIFF_PHOTOMETRIC_CFA:
+        case TIFF_PHOTOMETRIC_LOG_L:
+        case TIFF_PHOTOMETRIC_LOG_LUV:
+        case TIFF_PHOTOMETRIC_LINEAR_RAW:
+            avpriv_report_missing_feature(s->avctx,
+                                          "PhotometricInterpretation 0x%04X",
+                                          value);
+            return AVERROR_PATCHWELCOME;
         default:
-            av_log(s->avctx, AV_LOG_ERROR, "Color mode %d is not supported\n",
-                   value);
+            av_log(s->avctx, AV_LOG_ERROR, "PhotometricInterpretation %u is "
+                   "unknown\n", value);
             return AVERROR_INVALIDDATA;
         }
         break;
@@ -546,10 +557,10 @@ static int decode_frame(AVCodecContext *avctx,
         av_log(avctx, AV_LOG_ERROR, "TIFF header not found\n");
         return AVERROR_INVALIDDATA;
     }
-    s->le         = le;
-    s->invert     = 0;
-    s->compr      = TIFF_RAW;
-    s->fill_order = 0;
+    s->le          = le;
+    s->photometric = TIFF_PHOTOMETRIC_NONE;
+    s->compr       = TIFF_RAW;
+    s->fill_order  = 0;
     // As TIFF 6.0 specification puts it "An arbitrary but carefully chosen number
     // that further identifies the file as a TIFF file"
     if (tget_short(&s->gb, le) != 42) {
@@ -633,7 +644,7 @@ static int decode_frame(AVCodecContext *avctx,
         }
     }
 
-    if (s->invert) {
+    if (s->photometric == TIFF_PHOTOMETRIC_WHITE_IS_ZERO) {
         dst = p->data[0];
         for (i = 0; i < s->height; i++) {
             for (j = 0; j < p->linesize[0]; j++)
diff --git a/libavcodec/tiff.h b/libavcodec/tiff.h
index 9052d2f..8a3f7f7 100644
--- a/libavcodec/tiff.h
+++ b/libavcodec/tiff.h
@@ -37,7 +37,7 @@ enum TiffTags {
     TIFF_HEIGHT,
     TIFF_BPP,
     TIFF_COMPR,
-    TIFF_INVERT             = 0x106,
+    TIFF_PHOTOMETRIC        = 0x106,
     TIFF_FILL_ORDER         = 0x10A,
     TIFF_STRIP_OFFS         = 0x111,
     TIFF_SAMPLES_PER_PIXEL  = 0x115,
@@ -82,6 +82,24 @@ enum TiffTypes {
     TIFF_RATIONAL,
 };
 
+enum TiffPhotometric {
+    TIFF_PHOTOMETRIC_NONE       = -1,
+    TIFF_PHOTOMETRIC_WHITE_IS_ZERO,      /* mono or grayscale, 0 is white */
+    TIFF_PHOTOMETRIC_BLACK_IS_ZERO,      /* mono or grayscale, 0 is black */
+    TIFF_PHOTOMETRIC_RGB,                /* RGB or RGBA*/
+    TIFF_PHOTOMETRIC_PALETTE,            /* Uses a palette */
+    TIFF_PHOTOMETRIC_ALPHA_MASK,         /* Transparency mask */
+    TIFF_PHOTOMETRIC_SEPARATED,          /* CMYK or some other ink set */
+    TIFF_PHOTOMETRIC_YCBCR,              /* YCbCr */
+    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_LOG_L      = 32844, /* CIE Log2(L) */
+    TIFF_PHOTOMETRIC_LOG_LUV,            /* CIE Log L*u*v* */
+    TIFF_PHOTOMETRIC_LINEAR_RAW = 34892, /* Linear Raw (DNG) */
+};
+
 /** sizes of various TIFF field types (string size = 100)*/
 static const uint8_t type_sizes[6] = {
     0, 1, 100, 2, 4, 8
diff --git a/libavcodec/tiffenc.c b/libavcodec/tiffenc.c
index f12e0f4..ccfb07c 100644
--- a/libavcodec/tiffenc.c
+++ b/libavcodec/tiffenc.c
@@ -56,7 +56,7 @@ typedef struct TiffEncoderContext {
     unsigned int bpp;                       ///< bits per pixel
     int compr;                              ///< compression level
     int bpp_tab_size;                       ///< bpp_tab size
-    int photometric_interpretation;         ///< photometric interpretation
+    enum TiffPhotometric photometric_interpretation;  ///< photometric interpretation
     int strips;                             ///< number of strips
     int rps;                                ///< row per strip
     uint8_t entries[TIFF_MAX_ENTRY * 12];   ///< entries in header
@@ -237,23 +237,23 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
         pfd    = av_pix_fmt_desc_get(avctx->pix_fmt);
         s->bpp = av_get_bits_per_pixel(pfd);
         if (pfd->flags & AV_PIX_FMT_FLAG_PAL)
-            s->photometric_interpretation = 3;
+            s->photometric_interpretation = TIFF_PHOTOMETRIC_PALETTE;
         else if (pfd->flags & AV_PIX_FMT_FLAG_RGB)
-            s->photometric_interpretation = 2;
+            s->photometric_interpretation = TIFF_PHOTOMETRIC_RGB;
         else
-            s->photometric_interpretation = 1;
+            s->photometric_interpretation = TIFF_PHOTOMETRIC_BLACK_IS_ZERO;
         s->bpp_tab_size = pfd->nb_components;
         for (i = 0; i < s->bpp_tab_size; i++)
             bpp_tab[i] = s->bpp / s->bpp_tab_size;
         break;
     case AV_PIX_FMT_MONOBLACK:
         s->bpp                        = 1;
-        s->photometric_interpretation = 1;
+        s->photometric_interpretation = TIFF_PHOTOMETRIC_BLACK_IS_ZERO;
         s->bpp_tab_size               = 0;
         break;
     case AV_PIX_FMT_MONOWHITE:
         s->bpp                        = 1;
-        s->photometric_interpretation = 0;
+        s->photometric_interpretation = TIFF_PHOTOMETRIC_WHITE_IS_ZERO;
         s->bpp_tab_size               = 0;
         break;
     case AV_PIX_FMT_YUV420P:
@@ -262,7 +262,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
     case AV_PIX_FMT_YUV410P:
     case AV_PIX_FMT_YUV411P:
         av_pix_fmt_get_chroma_sub_sample(avctx->pix_fmt, &shift_h, &shift_v);
-        s->photometric_interpretation = 6;
+        s->photometric_interpretation = TIFF_PHOTOMETRIC_YCBCR;
         s->bpp                        = 8 + (16 >> (shift_h + shift_v));
         s->subsampling[0]             = 1 << shift_h;
         s->subsampling[1]             = 1 << shift_v;
@@ -410,9 +410,9 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
     if (s->bpp_tab_size)
         add_entry(s, TIFF_BPP, TIFF_SHORT, s->bpp_tab_size, bpp_tab);
 
-    add_entry1(s, TIFF_COMPR,      TIFF_SHORT, s->compr);
-    add_entry1(s, TIFF_INVERT,     TIFF_SHORT, s->photometric_interpretation);
-    add_entry(s,  TIFF_STRIP_OFFS, TIFF_LONG,  strips, strip_offsets);
+    add_entry1(s, TIFF_COMPR,       TIFF_SHORT, s->compr);
+    add_entry1(s, TIFF_PHOTOMETRIC, TIFF_SHORT, s->photometric_interpretation);
+    add_entry(s,  TIFF_STRIP_OFFS,  TIFF_LONG,  strips, strip_offsets);
 
     if (s->bpp_tab_size)
         add_entry1(s, TIFF_SAMPLES_PER_PIXEL, TIFF_SHORT, s->bpp_tab_size);

-- 
Libav/FFmpeg packaging



More information about the pkg-multimedia-commits mailing list