1999-07-27 17:50:26 -04:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1991-1997 Sam Leffler
|
|
|
|
* Copyright (c) 1991-1997 Silicon Graphics, Inc.
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, distribute, and sell this software and
|
|
|
|
* its documentation for any purpose is hereby granted without fee, provided
|
|
|
|
* that (i) the above copyright notices and this permission notice appear in
|
|
|
|
* all copies of the software and related documentation, and (ii) the names of
|
|
|
|
* Sam Leffler and Silicon Graphics may not be used in any advertising or
|
|
|
|
* publicity relating to the software without the specific, prior written
|
|
|
|
* permission of Sam Leffler and Silicon Graphics.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
|
|
|
|
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
*
|
|
|
|
* IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
|
|
|
|
* OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
|
|
|
* WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
|
|
|
|
* LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
|
|
|
* OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2004-09-02 10:51:04 -04:00
|
|
|
#include "tif_config.h"
|
|
|
|
|
1999-07-27 17:50:26 -04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
|
2004-09-02 10:51:04 -04:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
2006-04-20 08:36:23 -04:00
|
|
|
#ifdef HAVE_FCNTL_H
|
|
|
|
# include <fcntl.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_IO_H
|
|
|
|
# include <io.h>
|
|
|
|
#endif
|
|
|
|
|
2009-01-22 15:53:07 -05:00
|
|
|
#ifdef NEED_LIBPORT
|
|
|
|
# include "libport.h"
|
|
|
|
#endif
|
|
|
|
|
1999-07-27 17:50:26 -04:00
|
|
|
#include "tiffio.h"
|
|
|
|
|
2005-05-25 09:36:56 -04:00
|
|
|
#ifndef HAVE_GETOPT
|
2019-11-03 12:21:26 -05:00
|
|
|
extern int getopt(int argc, char * const argv[], const char *optstring);
|
2005-05-25 09:36:56 -04:00
|
|
|
#endif
|
|
|
|
|
1999-07-27 17:50:26 -04:00
|
|
|
#define streq(a,b) (strcmp(a,b) == 0)
|
|
|
|
#define strneq(a,b,n) (strncmp(a,b,n) == 0)
|
|
|
|
|
1999-12-21 12:03:03 -05:00
|
|
|
static uint16 compression = COMPRESSION_PACKBITS;
|
1999-07-27 17:50:26 -04:00
|
|
|
static uint16 predictor = 0;
|
|
|
|
static int quality = 75; /* JPEG quality */
|
|
|
|
static int jpegcolormode = JPEGCOLORMODE_RGB;
|
2006-03-01 05:41:24 -05:00
|
|
|
static uint32 g3opts;
|
1999-07-27 17:50:26 -04:00
|
|
|
|
|
|
|
static void usage(void);
|
|
|
|
static int processCompressOptions(char*);
|
|
|
|
|
2020-02-08 11:38:13 -05:00
|
|
|
static void
|
|
|
|
pack_none (unsigned char *buf, unsigned int smpls, uint16 bps)
|
|
|
|
{
|
2020-03-05 18:20:30 -05:00
|
|
|
(void)buf;
|
|
|
|
(void)smpls;
|
|
|
|
(void)bps;
|
2020-02-08 11:38:13 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
pack_swab (unsigned char *buf, unsigned int smpls, uint16 bps)
|
|
|
|
{
|
|
|
|
unsigned int s;
|
|
|
|
unsigned char h;
|
|
|
|
unsigned char l;
|
2020-03-05 18:20:30 -05:00
|
|
|
(void)bps;
|
2020-02-08 11:38:13 -05:00
|
|
|
|
|
|
|
for (s = 0; smpls > s; s++) {
|
|
|
|
|
|
|
|
h = buf [s * 2 + 0];
|
|
|
|
l = buf [s * 2 + 1];
|
|
|
|
|
|
|
|
buf [s * 2 + 0] = l;
|
|
|
|
buf [s * 2 + 1] = h;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
pack_bytes (unsigned char *buf, unsigned int smpls, uint16 bps)
|
|
|
|
{
|
|
|
|
unsigned int s;
|
|
|
|
unsigned int in;
|
|
|
|
unsigned int out;
|
|
|
|
int bits;
|
|
|
|
uint16 t;
|
|
|
|
|
|
|
|
in = 0;
|
|
|
|
out = 0;
|
|
|
|
bits = 0;
|
|
|
|
t = 0;
|
|
|
|
|
|
|
|
for (s = 0; smpls > s; s++) {
|
|
|
|
|
|
|
|
t <<= bps;
|
|
|
|
t |= (uint16) buf [in++];
|
|
|
|
|
|
|
|
bits += bps;
|
|
|
|
|
|
|
|
if (8 <= bits) {
|
|
|
|
bits -= 8;
|
|
|
|
buf [out++] = (t >> bits) & 0xFF;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (0 != bits)
|
|
|
|
buf [out] = (t << (8 - bits)) & 0xFF;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
pack_words (unsigned char *buf, unsigned int smpls, uint16 bps)
|
|
|
|
{
|
|
|
|
unsigned int s;
|
|
|
|
unsigned int in;
|
|
|
|
unsigned int out;
|
|
|
|
int bits;
|
|
|
|
uint32 t;
|
|
|
|
|
|
|
|
in = 0;
|
|
|
|
out = 0;
|
|
|
|
bits = 0;
|
|
|
|
t = 0;
|
|
|
|
|
|
|
|
for (s = 0; smpls > s; s++) {
|
|
|
|
|
|
|
|
t <<= bps;
|
|
|
|
t |= (uint32) buf [in++] << 8;
|
|
|
|
t |= (uint32) buf [in++] << 0;
|
|
|
|
|
|
|
|
bits += bps;
|
|
|
|
|
|
|
|
if (16 <= bits) {
|
|
|
|
|
|
|
|
bits -= 16;
|
|
|
|
buf [out++] = (t >> (bits + 8));
|
|
|
|
buf [out++] = (t >> (bits + 0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (0 != bits) {
|
|
|
|
t <<= 16 - bits;
|
|
|
|
|
|
|
|
buf [out++] = (t >> (16 + 8));
|
|
|
|
buf [out++] = (t >> (16 + 0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-07-27 17:50:26 -04:00
|
|
|
static void
|
|
|
|
BadPPM(char* file)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "%s: Not a PPM file.\n", file);
|
|
|
|
exit(-2);
|
|
|
|
}
|
|
|
|
|
2018-09-08 02:46:27 -04:00
|
|
|
|
|
|
|
#define TIFF_SIZE_T_MAX ((size_t) ~ ((size_t)0))
|
|
|
|
#define TIFF_TMSIZE_T_MAX (tmsize_t)(TIFF_SIZE_T_MAX >> 1)
|
|
|
|
|
2012-12-10 13:19:11 -05:00
|
|
|
static tmsize_t
|
|
|
|
multiply_ms(tmsize_t m1, tmsize_t m2)
|
|
|
|
{
|
2018-09-08 02:46:27 -04:00
|
|
|
if( m1 == 0 || m2 > TIFF_TMSIZE_T_MAX / m1 )
|
|
|
|
return 0;
|
|
|
|
return m1 * m2;
|
2012-12-10 13:19:11 -05:00
|
|
|
}
|
|
|
|
|
1999-07-27 17:50:26 -04:00
|
|
|
int
|
|
|
|
main(int argc, char* argv[])
|
|
|
|
{
|
2004-09-02 10:51:04 -04:00
|
|
|
uint16 photometric = 0;
|
1999-07-27 17:50:26 -04:00
|
|
|
uint32 rowsperstrip = (uint32) -1;
|
|
|
|
double resolution = -1;
|
|
|
|
unsigned char *buf = NULL;
|
2012-12-10 13:19:11 -05:00
|
|
|
tmsize_t linebytes = 0;
|
2020-02-08 11:38:13 -05:00
|
|
|
int pbm;
|
2004-09-02 10:51:04 -04:00
|
|
|
uint16 spp = 1;
|
2006-03-01 05:41:24 -05:00
|
|
|
uint16 bpp = 8;
|
2020-02-08 11:38:13 -05:00
|
|
|
void (*pack_func) (unsigned char *buf, unsigned int smpls, uint16 bps);
|
1999-07-27 17:50:26 -04:00
|
|
|
TIFF *out;
|
|
|
|
FILE *in;
|
2005-05-25 09:36:56 -04:00
|
|
|
unsigned int w, h, prec, row;
|
1999-07-27 17:50:26 -04:00
|
|
|
char *infile;
|
|
|
|
int c;
|
2015-06-20 21:09:09 -04:00
|
|
|
#if !HAVE_DECL_OPTARG
|
1999-07-27 17:50:26 -04:00
|
|
|
extern int optind;
|
|
|
|
extern char* optarg;
|
2015-06-20 21:09:09 -04:00
|
|
|
#endif
|
2012-11-02 01:13:24 -04:00
|
|
|
tmsize_t scanline_size;
|
1999-07-27 17:50:26 -04:00
|
|
|
|
2006-03-01 05:41:24 -05:00
|
|
|
if (argc < 2) {
|
2003-05-05 06:40:04 -04:00
|
|
|
fprintf(stderr, "%s: Too few arguments\n", argv[0]);
|
|
|
|
usage();
|
|
|
|
}
|
1999-07-27 17:50:26 -04:00
|
|
|
while ((c = getopt(argc, argv, "c:r:R:")) != -1)
|
|
|
|
switch (c) {
|
|
|
|
case 'c': /* compression scheme */
|
|
|
|
if (!processCompressOptions(optarg))
|
|
|
|
usage();
|
|
|
|
break;
|
|
|
|
case 'r': /* rows/strip */
|
|
|
|
rowsperstrip = atoi(optarg);
|
|
|
|
break;
|
|
|
|
case 'R': /* resolution */
|
|
|
|
resolution = atof(optarg);
|
|
|
|
break;
|
|
|
|
case '?':
|
|
|
|
usage();
|
|
|
|
/*NOTREACHED*/
|
|
|
|
}
|
|
|
|
|
2006-03-01 05:41:24 -05:00
|
|
|
if (optind + 2 < argc) {
|
2003-02-06 17:05:47 -05:00
|
|
|
fprintf(stderr, "%s: Too many arguments\n", argv[0]);
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
|
1999-07-27 17:50:26 -04:00
|
|
|
/*
|
|
|
|
* If only one file is specified, read input from
|
|
|
|
* stdin; otherwise usage is: ppm2tiff input output.
|
|
|
|
*/
|
|
|
|
if (argc - optind > 1) {
|
|
|
|
infile = argv[optind++];
|
2006-04-20 08:36:23 -04:00
|
|
|
in = fopen(infile, "rb");
|
1999-07-27 17:50:26 -04:00
|
|
|
if (in == NULL) {
|
|
|
|
fprintf(stderr, "%s: Can not open.\n", infile);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
infile = "<stdin>";
|
|
|
|
in = stdin;
|
2006-04-20 08:36:23 -04:00
|
|
|
#if defined(HAVE_SETMODE) && defined(O_BINARY)
|
|
|
|
setmode(fileno(stdin), O_BINARY);
|
|
|
|
#endif
|
1999-07-27 17:50:26 -04:00
|
|
|
}
|
|
|
|
|
2003-05-05 06:40:04 -04:00
|
|
|
if (fgetc(in) != 'P')
|
1999-07-27 17:50:26 -04:00
|
|
|
BadPPM(infile);
|
2003-05-05 06:40:04 -04:00
|
|
|
switch (fgetc(in)) {
|
2006-03-01 05:41:24 -05:00
|
|
|
case '4': /* it's a PBM file */
|
2020-02-08 11:38:13 -05:00
|
|
|
pbm = !0;
|
2006-03-01 05:41:24 -05:00
|
|
|
spp = 1;
|
|
|
|
photometric = PHOTOMETRIC_MINISWHITE;
|
|
|
|
break;
|
|
|
|
case '5': /* it's a PGM file */
|
2020-02-08 11:38:13 -05:00
|
|
|
pbm = 0;
|
2006-03-01 05:41:24 -05:00
|
|
|
spp = 1;
|
|
|
|
photometric = PHOTOMETRIC_MINISBLACK;
|
|
|
|
break;
|
|
|
|
case '6': /* it's a PPM file */
|
2020-02-08 11:38:13 -05:00
|
|
|
pbm = 0;
|
2006-03-01 05:41:24 -05:00
|
|
|
spp = 3;
|
|
|
|
photometric = PHOTOMETRIC_RGB;
|
|
|
|
if (compression == COMPRESSION_JPEG &&
|
|
|
|
jpegcolormode == JPEGCOLORMODE_RGB)
|
|
|
|
photometric = PHOTOMETRIC_YCBCR;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
BadPPM(infile);
|
1999-07-27 17:50:26 -04:00
|
|
|
}
|
2003-05-05 06:40:04 -04:00
|
|
|
|
|
|
|
/* Parse header */
|
|
|
|
while(1) {
|
|
|
|
if (feof(in))
|
|
|
|
BadPPM(infile);
|
|
|
|
c = fgetc(in);
|
|
|
|
/* Skip whitespaces (blanks, TABs, CRs, LFs) */
|
|
|
|
if (strchr(" \t\r\n", c))
|
|
|
|
continue;
|
|
|
|
|
2006-03-01 05:41:24 -05:00
|
|
|
/* Check for comment line */
|
2003-05-05 06:40:04 -04:00
|
|
|
if (c == '#') {
|
|
|
|
do {
|
|
|
|
c = fgetc(in);
|
2010-04-10 15:22:34 -04:00
|
|
|
} while(!(strchr("\r\n", c) || feof(in)));
|
2003-05-05 06:40:04 -04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
ungetc(c, in);
|
|
|
|
break;
|
|
|
|
}
|
2020-02-08 11:38:13 -05:00
|
|
|
if (pbm) {
|
2006-03-01 05:41:24 -05:00
|
|
|
if (fscanf(in, " %u %u", &w, &h) != 2)
|
|
|
|
BadPPM(infile);
|
|
|
|
if (fgetc(in) != '\n')
|
|
|
|
BadPPM(infile);
|
2020-02-08 11:38:13 -05:00
|
|
|
bpp = 1;
|
|
|
|
pack_func = pack_none;
|
|
|
|
} else {
|
2006-03-01 05:41:24 -05:00
|
|
|
if (fscanf(in, " %u %u %u", &w, &h, &prec) != 3)
|
|
|
|
BadPPM(infile);
|
2020-02-08 11:38:13 -05:00
|
|
|
if (fgetc(in) != '\n' || 0 == prec || 65535 < prec)
|
2006-03-01 05:41:24 -05:00
|
|
|
BadPPM(infile);
|
2020-02-08 11:38:13 -05:00
|
|
|
|
|
|
|
if (0 != (prec & (prec + 1))) {
|
|
|
|
fprintf(stderr, "%s: unsupported maxval %u.\n",
|
|
|
|
infile, prec);
|
|
|
|
exit(-2);
|
|
|
|
}
|
|
|
|
bpp = 0;
|
|
|
|
if ((prec + 1) & 0xAAAAAAAA) bpp |= 1;
|
|
|
|
if ((prec + 1) & 0xCCCCCCCC) bpp |= 2;
|
|
|
|
if ((prec + 1) & 0xF0F0F0F0) bpp |= 4;
|
|
|
|
if ((prec + 1) & 0xFF00FF00) bpp |= 8;
|
|
|
|
if ((prec + 1) & 0xFFFF0000) bpp |= 16;
|
|
|
|
|
|
|
|
switch (bpp) {
|
|
|
|
case 8:
|
|
|
|
pack_func = pack_none;
|
|
|
|
break;
|
|
|
|
case 16:
|
|
|
|
{
|
|
|
|
const unsigned short i = 0x0100;
|
|
|
|
|
|
|
|
if (0 == *(unsigned char*) &i)
|
|
|
|
pack_func = pack_swab;
|
|
|
|
else
|
|
|
|
pack_func = pack_none;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (8 >= bpp)
|
|
|
|
pack_func = pack_bytes;
|
|
|
|
else
|
|
|
|
pack_func = pack_words;
|
|
|
|
break;
|
|
|
|
}
|
2006-03-01 05:41:24 -05:00
|
|
|
}
|
1999-07-27 17:50:26 -04:00
|
|
|
out = TIFFOpen(argv[optind], "w");
|
|
|
|
if (out == NULL)
|
|
|
|
return (-4);
|
2005-05-25 09:36:56 -04:00
|
|
|
TIFFSetField(out, TIFFTAG_IMAGEWIDTH, (uint32) w);
|
|
|
|
TIFFSetField(out, TIFFTAG_IMAGELENGTH, (uint32) h);
|
1999-07-27 17:50:26 -04:00
|
|
|
TIFFSetField(out, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
|
|
|
|
TIFFSetField(out, TIFFTAG_SAMPLESPERPIXEL, spp);
|
2006-03-01 05:41:24 -05:00
|
|
|
TIFFSetField(out, TIFFTAG_BITSPERSAMPLE, bpp);
|
1999-07-27 17:50:26 -04:00
|
|
|
TIFFSetField(out, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
|
|
|
|
TIFFSetField(out, TIFFTAG_PHOTOMETRIC, photometric);
|
|
|
|
TIFFSetField(out, TIFFTAG_COMPRESSION, compression);
|
|
|
|
switch (compression) {
|
|
|
|
case COMPRESSION_JPEG:
|
|
|
|
TIFFSetField(out, TIFFTAG_JPEGQUALITY, quality);
|
|
|
|
TIFFSetField(out, TIFFTAG_JPEGCOLORMODE, jpegcolormode);
|
|
|
|
break;
|
|
|
|
case COMPRESSION_LZW:
|
|
|
|
case COMPRESSION_DEFLATE:
|
|
|
|
if (predictor != 0)
|
|
|
|
TIFFSetField(out, TIFFTAG_PREDICTOR, predictor);
|
|
|
|
break;
|
2006-03-01 05:41:24 -05:00
|
|
|
case COMPRESSION_CCITTFAX3:
|
|
|
|
TIFFSetField(out, TIFFTAG_GROUP3OPTIONS, g3opts);
|
|
|
|
break;
|
|
|
|
}
|
2020-02-08 11:38:13 -05:00
|
|
|
if (pbm) {
|
|
|
|
/* if round-up overflows, result will be zero, OK */
|
|
|
|
linebytes = (multiply_ms(spp, w) + (8 - 1)) / 8;
|
|
|
|
} else if (bpp <= 8) {
|
|
|
|
linebytes = multiply_ms(spp, w);
|
|
|
|
} else {
|
|
|
|
linebytes = multiply_ms(2 * spp, w);
|
|
|
|
}
|
|
|
|
if (rowsperstrip == (uint32) -1) {
|
|
|
|
TIFFSetField(out, TIFFTAG_ROWSPERSTRIP, h);
|
|
|
|
} else {
|
|
|
|
TIFFSetField(out, TIFFTAG_ROWSPERSTRIP,
|
|
|
|
TIFFDefaultStripSize(out, rowsperstrip));
|
1999-07-27 17:50:26 -04:00
|
|
|
}
|
2012-12-10 13:19:11 -05:00
|
|
|
if (linebytes == 0) {
|
|
|
|
fprintf(stderr, "%s: scanline size overflow\n", infile);
|
|
|
|
(void) TIFFClose(out);
|
|
|
|
exit(-2);
|
|
|
|
}
|
|
|
|
scanline_size = TIFFScanlineSize(out);
|
|
|
|
if (scanline_size == 0) {
|
|
|
|
/* overflow - TIFFScanlineSize already printed a message */
|
|
|
|
(void) TIFFClose(out);
|
|
|
|
exit(-2);
|
|
|
|
}
|
|
|
|
if (scanline_size < linebytes)
|
1999-07-27 17:50:26 -04:00
|
|
|
buf = (unsigned char *)_TIFFmalloc(linebytes);
|
2012-12-10 13:19:11 -05:00
|
|
|
else
|
|
|
|
buf = (unsigned char *)_TIFFmalloc(scanline_size);
|
|
|
|
if (buf == NULL) {
|
|
|
|
fprintf(stderr, "%s: Not enough memory\n", infile);
|
|
|
|
(void) TIFFClose(out);
|
|
|
|
exit(-2);
|
|
|
|
}
|
1999-07-27 17:50:26 -04:00
|
|
|
if (resolution > 0) {
|
|
|
|
TIFFSetField(out, TIFFTAG_XRESOLUTION, resolution);
|
|
|
|
TIFFSetField(out, TIFFTAG_YRESOLUTION, resolution);
|
|
|
|
TIFFSetField(out, TIFFTAG_RESOLUTIONUNIT, RESUNIT_INCH);
|
|
|
|
}
|
|
|
|
for (row = 0; row < h; row++) {
|
|
|
|
if (fread(buf, linebytes, 1, in) != 1) {
|
|
|
|
fprintf(stderr, "%s: scanline %lu: Read error.\n",
|
|
|
|
infile, (unsigned long) row);
|
|
|
|
break;
|
|
|
|
}
|
2020-02-08 11:38:13 -05:00
|
|
|
pack_func (buf, w * spp, bpp);
|
1999-07-27 17:50:26 -04:00
|
|
|
if (TIFFWriteScanline(out, buf, row, 0) < 0)
|
|
|
|
break;
|
|
|
|
}
|
2018-10-31 06:50:48 -04:00
|
|
|
if (in != stdin)
|
|
|
|
fclose(in);
|
1999-07-27 17:50:26 -04:00
|
|
|
(void) TIFFClose(out);
|
|
|
|
if (buf)
|
|
|
|
_TIFFfree(buf);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2006-03-01 05:41:24 -05:00
|
|
|
static void
|
|
|
|
processG3Options(char* cp)
|
|
|
|
{
|
|
|
|
g3opts = 0;
|
|
|
|
if( (cp = strchr(cp, ':')) ) {
|
|
|
|
do {
|
|
|
|
cp++;
|
|
|
|
if (strneq(cp, "1d", 2))
|
|
|
|
g3opts &= ~GROUP3OPT_2DENCODING;
|
|
|
|
else if (strneq(cp, "2d", 2))
|
|
|
|
g3opts |= GROUP3OPT_2DENCODING;
|
|
|
|
else if (strneq(cp, "fill", 4))
|
|
|
|
g3opts |= GROUP3OPT_FILLBITS;
|
|
|
|
else
|
|
|
|
usage();
|
|
|
|
} while( (cp = strchr(cp, ':')) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-07-27 17:50:26 -04:00
|
|
|
static int
|
|
|
|
processCompressOptions(char* opt)
|
|
|
|
{
|
|
|
|
if (streq(opt, "none"))
|
|
|
|
compression = COMPRESSION_NONE;
|
|
|
|
else if (streq(opt, "packbits"))
|
|
|
|
compression = COMPRESSION_PACKBITS;
|
|
|
|
else if (strneq(opt, "jpeg", 4)) {
|
|
|
|
char* cp = strchr(opt, ':');
|
2006-01-11 11:59:35 -05:00
|
|
|
|
2006-01-11 12:03:43 -05:00
|
|
|
compression = COMPRESSION_JPEG;
|
2006-03-01 05:41:24 -05:00
|
|
|
while (cp)
|
2006-01-11 11:59:35 -05:00
|
|
|
{
|
|
|
|
if (isdigit((int)cp[1]))
|
1999-07-27 17:50:26 -04:00
|
|
|
quality = atoi(cp+1);
|
2006-01-11 11:59:35 -05:00
|
|
|
else if (cp[1] == 'r' )
|
1999-07-27 17:50:26 -04:00
|
|
|
jpegcolormode = JPEGCOLORMODE_RAW;
|
2006-01-11 11:59:35 -05:00
|
|
|
else
|
|
|
|
usage();
|
|
|
|
|
|
|
|
cp = strchr(cp+1,':');
|
|
|
|
}
|
2006-03-01 05:41:24 -05:00
|
|
|
} else if (strneq(opt, "g3", 2)) {
|
|
|
|
processG3Options(opt);
|
|
|
|
compression = COMPRESSION_CCITTFAX3;
|
|
|
|
} else if (streq(opt, "g4")) {
|
|
|
|
compression = COMPRESSION_CCITTFAX4;
|
1999-07-27 17:50:26 -04:00
|
|
|
} else if (strneq(opt, "lzw", 3)) {
|
|
|
|
char* cp = strchr(opt, ':');
|
|
|
|
if (cp)
|
|
|
|
predictor = atoi(cp+1);
|
|
|
|
compression = COMPRESSION_LZW;
|
|
|
|
} else if (strneq(opt, "zip", 3)) {
|
|
|
|
char* cp = strchr(opt, ':');
|
|
|
|
if (cp)
|
|
|
|
predictor = atoi(cp+1);
|
|
|
|
compression = COMPRESSION_DEFLATE;
|
|
|
|
} else
|
|
|
|
return (0);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
char* stuff[] = {
|
|
|
|
"usage: ppm2tiff [options] input.ppm output.tif",
|
|
|
|
"where options are:",
|
|
|
|
" -r # make each strip have no more than # rows",
|
|
|
|
" -R # set x&y resolution (dpi)",
|
|
|
|
"",
|
|
|
|
" -c jpeg[:opts] compress output with JPEG encoding",
|
|
|
|
" -c lzw[:opts] compress output with Lempel-Ziv & Welch encoding",
|
|
|
|
" -c zip[:opts] compress output with deflate encoding",
|
2003-05-05 06:40:04 -04:00
|
|
|
" -c packbits compress output with packbits encoding (the default)",
|
2006-03-01 05:41:24 -05:00
|
|
|
" -c g3[:opts] compress output with CCITT Group 3 encoding",
|
|
|
|
" -c g4 compress output with CCITT Group 4 encoding",
|
1999-07-27 17:50:26 -04:00
|
|
|
" -c none use no compression algorithm on output",
|
|
|
|
"",
|
|
|
|
"JPEG options:",
|
|
|
|
" # set compression quality level (0-100, default 75)",
|
|
|
|
" r output color image as RGB rather than YCbCr",
|
|
|
|
"LZW and deflate options:",
|
|
|
|
" # set predictor value",
|
|
|
|
"For example, -c lzw:2 to get LZW-encoded data with horizontal differencing",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
usage(void)
|
|
|
|
{
|
|
|
|
char buf[BUFSIZ];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
setbuf(stderr, buf);
|
2003-03-12 09:05:05 -05:00
|
|
|
fprintf(stderr, "%s\n\n", TIFFGetVersion());
|
1999-07-27 17:50:26 -04:00
|
|
|
for (i = 0; stuff[i] != NULL; i++)
|
|
|
|
fprintf(stderr, "%s\n", stuff[i]);
|
|
|
|
exit(-1);
|
|
|
|
}
|
2004-09-02 10:51:04 -04:00
|
|
|
|
|
|
|
/* vim: set ts=8 sts=8 sw=8 noet: */
|
2010-03-10 13:56:48 -05:00
|
|
|
/*
|
|
|
|
* Local Variables:
|
|
|
|
* mode: c
|
|
|
|
* c-basic-offset: 8
|
|
|
|
* fill-column: 78
|
|
|
|
* End:
|
|
|
|
*/
|