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