summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'tiff/tools/tiff2bw.c')
-rw-r--r--tiff/tools/tiff2bw.c182
1 files changed, 96 insertions, 86 deletions
diff --git a/tiff/tools/tiff2bw.c b/tiff/tools/tiff2bw.c
index 654bd324..75811e6a 100644
--- a/tiff/tools/tiff2bw.c
+++ b/tiff/tools/tiff2bw.c
@@ -23,6 +23,7 @@
*/
#include "tif_config.h"
+#include "libport.h"
#include <stdio.h>
#include <stdlib.h>
@@ -33,10 +34,6 @@
# include <unistd.h>
#endif
-#ifdef NEED_LIBPORT
-# include "libport.h"
-#endif
-
#include "tiffio.h"
#include "tiffiop.h"
@@ -57,7 +54,7 @@ static void usage(int code);
static int processCompressOptions(char*);
static void
-compresscontig(unsigned char* out, unsigned char* rgb, uint32 n)
+compresscontig(unsigned char* out, unsigned char* rgb, uint32_t n)
{
register int v, red = RED, green = GREEN, blue = BLUE;
@@ -71,9 +68,9 @@ compresscontig(unsigned char* out, unsigned char* rgb, uint32 n)
static void
compresssep(unsigned char* out,
- unsigned char* r, unsigned char* g, unsigned char* b, uint32 n)
+ unsigned char* r, unsigned char* g, unsigned char* b, uint32_t n)
{
- register uint32 red = RED, green = GREEN, blue = BLUE;
+ register uint32_t red = RED, green = GREEN, blue = BLUE;
while (n-- > 0)
*out++ = (unsigned char)
@@ -81,7 +78,7 @@ compresssep(unsigned char* out,
}
static int
-checkcmap(TIFF* tif, int n, uint16* r, uint16* g, uint16* b)
+checkcmap(TIFF* tif, int n, uint16_t* r, uint16_t* g, uint16_t* b)
{
while (n-- > 0)
if (*r++ >= 256 || *g++ >= 256 || *b++ >= 256)
@@ -91,7 +88,7 @@ checkcmap(TIFF* tif, int n, uint16* r, uint16* g, uint16* b)
}
static void
-compresspalette(unsigned char* out, unsigned char* data, uint32 n, uint16* rmap, uint16* gmap, uint16* bmap)
+compresspalette(unsigned char* out, unsigned char* data, uint32_t n, uint16_t* rmap, uint16_t* gmap, uint16_t* bmap)
{
register int v, red = RED, green = GREEN, blue = BLUE;
@@ -104,8 +101,8 @@ compresspalette(unsigned char* out, unsigned char* data, uint32 n, uint16* rmap,
}
}
-static uint16 compression = (uint16) -1;
-static uint16 predictor = 0;
+static uint16_t compression = (uint16_t) -1;
+static uint16_t predictor = 0;
static int jpegcolormode = JPEGCOLORMODE_RGB;
static int quality = 75; /* JPEG quality */
@@ -114,18 +111,18 @@ static void cpTags(TIFF* in, TIFF* out);
int
main(int argc, char* argv[])
{
- uint32 rowsperstrip = (uint32) -1;
+ uint32_t rowsperstrip = (uint32_t) -1;
TIFF *in, *out;
- uint32 w, h;
- uint16 samplesperpixel;
- uint16 bitspersample;
- uint16 config;
- uint16 photometric;
- uint16* red;
- uint16* green;
- uint16* blue;
+ uint32_t w, h;
+ uint16_t samplesperpixel;
+ uint16_t bitspersample;
+ uint16_t config;
+ uint16_t photometric;
+ uint16_t* red;
+ uint16_t* green;
+ uint16_t* blue;
tsize_t rowsize;
- register uint32 row;
+ register uint32_t row;
register tsample_t s;
unsigned char *inbuf, *outbuf;
char thing[1024];
@@ -160,9 +157,12 @@ main(int argc, char* argv[])
break;
case 'h':
usage(EXIT_SUCCESS);
+ /*NOTREACHED*/
+ break;
case '?':
usage(EXIT_FAILURE);
/*NOTREACHED*/
+ break;
}
if (argc - optind < 2)
usage(EXIT_FAILURE);
@@ -209,7 +209,7 @@ main(int argc, char* argv[])
TIFFSetField(out, TIFFTAG_SAMPLESPERPIXEL, 1);
TIFFSetField(out, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
cpTags(in, out);
- if (compression != (uint16) -1) {
+ if (compression != (uint16_t) -1) {
TIFFSetField(out, TIFFTAG_COMPRESSION, compression);
switch (compression) {
case COMPRESSION_JPEG:
@@ -376,27 +376,27 @@ processCompressOptions(char* opt)
if (TIFFGetField(in, tag, &v1, &v2, &v3, &v4)) TIFFSetField(out, tag, v1, v2, v3, v4)
static void
-cpTag(TIFF* in, TIFF* out, uint16 tag, uint16 count, TIFFDataType type)
+cpTag(TIFF* in, TIFF* out, uint16_t tag, uint16_t count, TIFFDataType type)
{
switch (type) {
case TIFF_SHORT:
if (count == 1) {
- uint16 shortv;
+ uint16_t shortv;
CopyField(tag, shortv);
} else if (count == 2) {
- uint16 shortv1, shortv2;
+ uint16_t shortv1, shortv2;
CopyField2(tag, shortv1, shortv2);
} else if (count == 4) {
- uint16 *tr, *tg, *tb, *ta;
+ uint16_t *tr, *tg, *tb, *ta;
CopyField4(tag, tr, tg, tb, ta);
- } else if (count == (uint16) -1) {
- uint16 shortv1;
- uint16* shortav;
+ } else if (count == (uint16_t) -1) {
+ uint16_t shortv1;
+ uint16_t* shortav;
CopyField2(tag, shortv1, shortav);
}
break;
case TIFF_LONG:
- { uint32 longv;
+ { uint32_t longv;
CopyField(tag, longv);
}
break;
@@ -404,7 +404,7 @@ cpTag(TIFF* in, TIFF* out, uint16 tag, uint16 count, TIFFDataType type)
if (count == 1) {
float floatv;
CopyField(tag, floatv);
- } else if (count == (uint16) -1) {
+ } else if (count == (uint16_t) -1) {
float* floatav;
CopyField(tag, floatav);
}
@@ -418,7 +418,7 @@ cpTag(TIFF* in, TIFF* out, uint16 tag, uint16 count, TIFFDataType type)
if (count == 1) {
double doublev;
CopyField(tag, doublev);
- } else if (count == (uint16) -1) {
+ } else if (count == (uint16_t) -1) {
double* doubleav;
CopyField(tag, doubleav);
}
@@ -435,9 +435,9 @@ cpTag(TIFF* in, TIFF* out, uint16 tag, uint16 count, TIFFDataType type)
#undef CopyField2
#undef CopyField
-static struct cpTag {
- uint16 tag;
- uint16 count;
+static const struct cpTag {
+ uint16_t tag;
+ uint16_t count;
TIFFDataType type;
} tags[] = {
{ TIFFTAG_SUBFILETYPE, 1, TIFF_LONG },
@@ -449,49 +449,49 @@ static struct cpTag {
{ TIFFTAG_MINSAMPLEVALUE, 1, TIFF_SHORT },
{ TIFFTAG_MAXSAMPLEVALUE, 1, TIFF_SHORT },
{ TIFFTAG_XRESOLUTION, 1, TIFF_RATIONAL },
- { TIFFTAG_YRESOLUTION, 1, TIFF_RATIONAL },
- { TIFFTAG_PAGENAME, 1, TIFF_ASCII },
- { TIFFTAG_XPOSITION, 1, TIFF_RATIONAL },
- { TIFFTAG_YPOSITION, 1, TIFF_RATIONAL },
- { TIFFTAG_RESOLUTIONUNIT, 1, TIFF_SHORT },
- { TIFFTAG_SOFTWARE, 1, TIFF_ASCII },
- { TIFFTAG_DATETIME, 1, TIFF_ASCII },
- { TIFFTAG_ARTIST, 1, TIFF_ASCII },
- { TIFFTAG_HOSTCOMPUTER, 1, TIFF_ASCII },
- { TIFFTAG_WHITEPOINT, 2, TIFF_RATIONAL },
- { TIFFTAG_PRIMARYCHROMATICITIES,(uint16) -1,TIFF_RATIONAL },
- { TIFFTAG_HALFTONEHINTS, 2, TIFF_SHORT },
- { TIFFTAG_INKSET, 1, TIFF_SHORT },
- { TIFFTAG_DOTRANGE, 2, TIFF_SHORT },
- { TIFFTAG_TARGETPRINTER, 1, TIFF_ASCII },
- { TIFFTAG_SAMPLEFORMAT, 1, TIFF_SHORT },
- { TIFFTAG_YCBCRCOEFFICIENTS, (uint16) -1,TIFF_RATIONAL },
- { TIFFTAG_YCBCRSUBSAMPLING, 2, TIFF_SHORT },
- { TIFFTAG_YCBCRPOSITIONING, 1, TIFF_SHORT },
- { TIFFTAG_REFERENCEBLACKWHITE, (uint16) -1,TIFF_RATIONAL },
- { TIFFTAG_EXTRASAMPLES, (uint16) -1, TIFF_SHORT },
- { TIFFTAG_SMINSAMPLEVALUE, 1, TIFF_DOUBLE },
- { TIFFTAG_SMAXSAMPLEVALUE, 1, TIFF_DOUBLE },
- { TIFFTAG_STONITS, 1, TIFF_DOUBLE },
+ { TIFFTAG_YRESOLUTION, 1, TIFF_RATIONAL },
+ { TIFFTAG_PAGENAME, 1, TIFF_ASCII },
+ { TIFFTAG_XPOSITION, 1, TIFF_RATIONAL },
+ { TIFFTAG_YPOSITION, 1, TIFF_RATIONAL },
+ { TIFFTAG_RESOLUTIONUNIT, 1, TIFF_SHORT },
+ { TIFFTAG_SOFTWARE, 1, TIFF_ASCII },
+ { TIFFTAG_DATETIME, 1, TIFF_ASCII },
+ { TIFFTAG_ARTIST, 1, TIFF_ASCII },
+ { TIFFTAG_HOSTCOMPUTER, 1, TIFF_ASCII },
+ { TIFFTAG_WHITEPOINT, 2, TIFF_RATIONAL },
+ { TIFFTAG_PRIMARYCHROMATICITIES,(uint16_t) -1, TIFF_RATIONAL },
+ { TIFFTAG_HALFTONEHINTS, 2, TIFF_SHORT },
+ { TIFFTAG_INKSET, 1, TIFF_SHORT },
+ { TIFFTAG_DOTRANGE, 2, TIFF_SHORT },
+ { TIFFTAG_TARGETPRINTER, 1, TIFF_ASCII },
+ { TIFFTAG_SAMPLEFORMAT, 1, TIFF_SHORT },
+ { TIFFTAG_YCBCRCOEFFICIENTS, (uint16_t) -1, TIFF_RATIONAL },
+ { TIFFTAG_YCBCRSUBSAMPLING, 2, TIFF_SHORT },
+ { TIFFTAG_YCBCRPOSITIONING, 1, TIFF_SHORT },
+ { TIFFTAG_REFERENCEBLACKWHITE, (uint16_t) -1, TIFF_RATIONAL },
+ { TIFFTAG_EXTRASAMPLES, (uint16_t) -1, TIFF_SHORT },
+ { TIFFTAG_SMINSAMPLEVALUE, 1, TIFF_DOUBLE },
+ { TIFFTAG_SMAXSAMPLEVALUE, 1, TIFF_DOUBLE },
+ { TIFFTAG_STONITS, 1, TIFF_DOUBLE },
};
#define NTAGS (sizeof (tags) / sizeof (tags[0]))
static void
cpTags(TIFF* in, TIFF* out)
{
- struct cpTag *p;
+ const struct cpTag *p;
for (p = tags; p < &tags[NTAGS]; p++)
{
if( p->tag == TIFFTAG_GROUP3OPTIONS )
{
- uint16 compression;
+ uint16_t compression;
if( !TIFFGetField(in, TIFFTAG_COMPRESSION, &compression) ||
compression != COMPRESSION_CCITTFAX3 )
continue;
}
if( p->tag == TIFFTAG_GROUP4OPTIONS )
{
- uint16 compression;
+ uint16_t compression;
if( !TIFFGetField(in, TIFFTAG_COMPRESSION, &compression) ||
compression != COMPRESSION_CCITTFAX4 )
continue;
@@ -501,37 +501,47 @@ cpTags(TIFF* in, TIFF* out)
}
#undef NTAGS
-const char* stuff[] = {
-"usage: tiff2bw [options] input.tif output.tif",
-"where options are:",
-" -R % use #% from red channel",
-" -G % use #% from green channel",
-" -B % use #% from blue channel",
-"",
-" -r # make each strip have no more than # rows",
-"",
-" -c lzw[:opts] compress output with Lempel-Ziv & Welch encoding",
-" -c zip[:opts] compress output with deflate encoding",
-" -c packbits compress output with packbits encoding",
-" -c g3[:opts] compress output with CCITT Group 3 encoding",
-" -c g4 compress output with CCITT Group 4 encoding",
-" -c none use no compression algorithm on output",
-"",
-"LZW and deflate options:",
-" # set predictor value",
-"For example, -c lzw:2 to get LZW-encoded data with horizontal differencing",
-NULL
-};
+static const char usage_info[] =
+"Convert a color TIFF image to greyscale\n\n"
+"usage: tiff2bw [options] input.tif output.tif\n"
+"where options are:\n"
+" -R % use #% from red channel\n"
+" -G % use #% from green channel\n"
+" -B % use #% from blue channel\n"
+"\n"
+" -r # make each strip have no more than # rows\n"
+"\n"
+#ifdef LZW_SUPPORT
+" -c lzw[:opts] compress output with Lempel-Ziv & Welch encoding\n"
+/* " LZW options:\n" */
+" # set predictor value\n"
+" For example, -c lzw:2 for LZW-encoded data with horizontal differencing\n"
+#endif
+#ifdef ZIP_SUPPORT
+" -c zip[:opts] compress output with deflate encoding\n"
+/* " Deflate (ZIP) options:\n" */
+" # set predictor value\n"
+#endif
+#ifdef PACKBITS_SUPPORT
+" -c packbits compress output with packbits encoding\n"
+#endif
+#ifdef CCITT_SUPPORT
+" -c g3[:opts] compress output with CCITT Group 3 encoding\n"
+" -c g4 compress output with CCITT Group 4 encoding\n"
+#endif
+#if defined(LZW_SUPPORT) || defined(ZIP_SUPPORT) || defined(PACKBITS_SUPPORT) || defined(CCITT_SUPPORT)
+" -c none use no compression algorithm on output\n"
+#endif
+"\n"
+;
static void
usage(int code)
{
- int i;
FILE * out = (code == EXIT_SUCCESS) ? stdout : stderr;
fprintf(out, "%s\n\n", TIFFGetVersion());
- for (i = 0; stuff[i] != NULL; i++)
- fprintf(out, "%s\n", stuff[i]);
+ fprintf(out, "%s", usage_info);
exit(code);
}