added support for TIFF Photometric Tag

Mon, 14 Dec 2009 16:15:04 +0000

author
Philip Pemberton <philpem@philpem.me.uk>
date
Mon, 14 Dec 2009 16:15:04 +0000
changeset 168
ad0b9a8990ac
parent 167
88aafe900928
child 169
da28fb586984

added support for TIFF Photometric Tag

tumble_input.h file | annotate | diff | revisions
tumble_tiff.c file | annotate | diff | revisions
     1.1 --- a/tumble_input.h	Mon Dec 14 16:00:58 2009 +0000
     1.2 +++ b/tumble_input.h	Mon Dec 14 16:15:04 2009 +0000
     1.3 @@ -27,6 +27,7 @@
     1.4    uint32_t width_samples, height_samples;
     1.5    double width_points, height_points;
     1.6    double x_resolution, y_resolution;
     1.7 +  uint16_t tiff_photometric_tag;
     1.8  } image_info_t;
     1.9  
    1.10  
     2.1 --- a/tumble_tiff.c	Mon Dec 14 16:00:58 2009 +0000
     2.2 +++ b/tumble_tiff.c	Mon Dec 14 16:15:04 2009 +0000
     2.3 @@ -36,6 +36,19 @@
     2.4   */
     2.5  #define TIFF_REVERSE_BITS
     2.6  
     2.7 +/*
     2.8 + * If we're reading in a TIFF file that doesn't have a
     2.9 + * PhotometricInterpretation TIFF tag (TIFFTAG_PHOTOMETRIC), then this
    2.10 + * value will be assumed.
    2.11 + *
    2.12 + * This is the default value used by tumble-0.33 before the Photometric
    2.13 + * Tag read changes. ImageMagick often produces G4TIFF images which have
    2.14 + * black and white reversed, and the photometric tag set accordingly; in
    2.15 + * these cases, Tumble will create a PDF file with B+W swapped.
    2.16 + *
    2.17 + * Ideally this should be a command-line parameter.
    2.18 + */
    2.19 +#define TUMBLE_TIFF_PHOTOMETRIC_ASSUME 0
    2.20  
    2.21  #include "semantics.h"
    2.22  #include "tumble.h"
    2.23 @@ -103,6 +116,7 @@
    2.24    uint16_t samples_per_pixel;
    2.25    uint16_t bits_per_sample;
    2.26    uint16_t planar_config;
    2.27 +  uint16_t photometric;
    2.28  
    2.29    uint16_t resolution_unit;
    2.30    float x_resolution, y_resolution;
    2.31 @@ -149,6 +163,18 @@
    2.32        return (0);
    2.33      }
    2.34  
    2.35 +  if (1 != TIFFGetField (tiff_in, TIFFTAG_PHOTOMETRIC, & photometric))
    2.36 +    {
    2.37 +      fprintf(stderr, "warning: photometric tag not present, assuming %d\n", TUMBLE_TIFF_PHOTOMETRIC_ASSUME);
    2.38 +      photometric = TUMBLE_TIFF_PHOTOMETRIC_ASSUME;
    2.39 +    }
    2.40 +
    2.41 +  if ((photometric != 0) && (photometric != 1))
    2.42 +    {
    2.43 +      fprintf(stderr, "TIFF photometric tag not valid; got %u, must be 0 or 1\n", photometric);
    2.44 +      return (0);
    2.45 +    }
    2.46 +
    2.47    if (1 != TIFFGetField (tiff_in, TIFFTAG_PLANARCONFIG, & planar_config))
    2.48      planar_config = 1;
    2.49  
    2.50 @@ -217,6 +243,8 @@
    2.51        return (0);
    2.52      }
    2.53  
    2.54 +  image_info->tiff_photometric_tag = photometric;
    2.55 +
    2.56    return (1);
    2.57  }
    2.58  
    2.59 @@ -333,7 +361,7 @@
    2.60  			  bitmap,
    2.61  			  0, /* ImageMask */
    2.62  			  0, 0, 0,  /* r, g, b */
    2.63 -			  0); /* BlackIs1 */
    2.64 +			  image_info->tiff_photometric_tag); /* 0=BlackIs1, 1=WhiteIs1 */
    2.65  #endif
    2.66  
    2.67    result = 1;