tumble_tiff.c

changeset 168
ad0b9a8990ac
parent 152
e69798068425
     1.1 --- a/tumble_tiff.c	Mon Dec 14 16:00:58 2009 +0000
     1.2 +++ b/tumble_tiff.c	Mon Dec 14 16:15:04 2009 +0000
     1.3 @@ -36,6 +36,19 @@
     1.4   */
     1.5  #define TIFF_REVERSE_BITS
     1.6  
     1.7 +/*
     1.8 + * If we're reading in a TIFF file that doesn't have a
     1.9 + * PhotometricInterpretation TIFF tag (TIFFTAG_PHOTOMETRIC), then this
    1.10 + * value will be assumed.
    1.11 + *
    1.12 + * This is the default value used by tumble-0.33 before the Photometric
    1.13 + * Tag read changes. ImageMagick often produces G4TIFF images which have
    1.14 + * black and white reversed, and the photometric tag set accordingly; in
    1.15 + * these cases, Tumble will create a PDF file with B+W swapped.
    1.16 + *
    1.17 + * Ideally this should be a command-line parameter.
    1.18 + */
    1.19 +#define TUMBLE_TIFF_PHOTOMETRIC_ASSUME 0
    1.20  
    1.21  #include "semantics.h"
    1.22  #include "tumble.h"
    1.23 @@ -103,6 +116,7 @@
    1.24    uint16_t samples_per_pixel;
    1.25    uint16_t bits_per_sample;
    1.26    uint16_t planar_config;
    1.27 +  uint16_t photometric;
    1.28  
    1.29    uint16_t resolution_unit;
    1.30    float x_resolution, y_resolution;
    1.31 @@ -149,6 +163,18 @@
    1.32        return (0);
    1.33      }
    1.34  
    1.35 +  if (1 != TIFFGetField (tiff_in, TIFFTAG_PHOTOMETRIC, & photometric))
    1.36 +    {
    1.37 +      fprintf(stderr, "warning: photometric tag not present, assuming %d\n", TUMBLE_TIFF_PHOTOMETRIC_ASSUME);
    1.38 +      photometric = TUMBLE_TIFF_PHOTOMETRIC_ASSUME;
    1.39 +    }
    1.40 +
    1.41 +  if ((photometric != 0) && (photometric != 1))
    1.42 +    {
    1.43 +      fprintf(stderr, "TIFF photometric tag not valid; got %u, must be 0 or 1\n", photometric);
    1.44 +      return (0);
    1.45 +    }
    1.46 +
    1.47    if (1 != TIFFGetField (tiff_in, TIFFTAG_PLANARCONFIG, & planar_config))
    1.48      planar_config = 1;
    1.49  
    1.50 @@ -217,6 +243,8 @@
    1.51        return (0);
    1.52      }
    1.53  
    1.54 +  image_info->tiff_photometric_tag = photometric;
    1.55 +
    1.56    return (1);
    1.57  }
    1.58  
    1.59 @@ -333,7 +361,7 @@
    1.60  			  bitmap,
    1.61  			  0, /* ImageMask */
    1.62  			  0, 0, 0,  /* r, g, b */
    1.63 -			  0); /* BlackIs1 */
    1.64 +			  image_info->tiff_photometric_tag); /* 0=BlackIs1, 1=WhiteIs1 */
    1.65  #endif
    1.66  
    1.67    result = 1;