1 /* $Id: raw2tiff.c,v 1.29 2017-01-14 13:12:33 erouault Exp $
2  *
3  * Project:  libtiff tools
4  * Purpose:  Convert raw byte sequences in TIFF images
5  * Author:   Andrey Kiselev, dron@ak4719.spb.edu
6  *
7  ******************************************************************************
8  * Copyright (c) 2002, Andrey Kiselev <dron@ak4719.spb.edu>
9  *
10  * Permission to use, copy, modify, distribute, and sell this software and
11  * its documentation for any purpose is hereby granted without fee, provided
12  * that (i) the above copyright notices and this permission notice appear in
13  * all copies of the software and related documentation, and (ii) the names of
14  * Sam Leffler and Silicon Graphics may not be used in any advertising or
15  * publicity relating to the software without the specific, prior written
16  * permission of Sam Leffler and Silicon Graphics.
17  *
18  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
19  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
20  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
21  *
22  * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
23  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
24  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
25  * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
26  * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
27  * OF THIS SOFTWARE.
28  */
29 
30 #include "tif_config.h"
31 
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <string.h>
35 #include <sys/stat.h>
36 #include <sys/types.h>
37 #include <math.h>
38 #include <ctype.h>
39 
40 #ifdef HAVE_UNISTD_H
41 # include <unistd.h>
42 #endif
43 
44 #if HAVE_FCNTL_H
45 # include <fcntl.h>
46 #endif
47 
48 #if HAVE_SYS_TYPES_H
49 # include <sys/types.h>
50 #endif
51 
52 #if HAVE_IO_H
53 # include <io.h>
54 #endif
55 
56 #ifdef NEED_LIBPORT
57 # include "libport.h"
58 #endif
59 
60 #include "tiffiop.h"
61 #include "tiffio.h"
62 
63 #ifndef HAVE_GETOPT
64 extern int getopt(int, char**, char*);
65 #endif
66 
67 #ifndef O_BINARY
68 # define O_BINARY 0
69 #endif
70 
71 typedef enum {
72 	PIXEL,
73 	BAND
74 } InterleavingType;
75 
76 static	uint16 compression = (uint16) -1;
77 static	int jpegcolormode = JPEGCOLORMODE_RGB;
78 static	int quality = 75;		/* JPEG quality */
79 static	uint16 predictor = 0;
80 
81 static void swapBytesInScanline(void *, uint32, TIFFDataType);
82 static int guessSize(int, TIFFDataType, _TIFF_off_t, uint32, int,
83 		     uint32 *, uint32 *);
84 static double correlation(void *, void *, uint32, TIFFDataType);
85 static void usage(void);
86 static	int processCompressOptions(char*);
87 
88 int
main(int argc,char * argv[])89 main(int argc, char* argv[])
90 {
91 	uint32	width = 0, length = 0, linebytes, bufsize;
92 	uint32	nbands = 1;		    /* number of bands in input image*/
93 	_TIFF_off_t hdr_size = 0;	    /* size of the header to skip */
94 	TIFFDataType dtype = TIFF_BYTE;
95 	int16	depth = 1;		    /* bytes per pixel in input image */
96 	int	swab = 0;		    /* byte swapping flag */
97 	InterleavingType interleaving = 0;  /* interleaving type flag */
98 	uint32  rowsperstrip = (uint32) -1;
99 	uint16	photometric = PHOTOMETRIC_MINISBLACK;
100 	uint16	config = PLANARCONFIG_CONTIG;
101 	uint16	fillorder = FILLORDER_LSB2MSB;
102 	int	fd;
103 	char	*outfilename = NULL;
104 	TIFF	*out;
105 
106 	uint32 row, col, band;
107 	int	c;
108 	unsigned char *buf = NULL, *buf1 = NULL;
109 #if !HAVE_DECL_OPTARG
110 	extern int optind;
111 	extern char* optarg;
112 #endif
113 
114 	while ((c = getopt(argc, argv, "c:r:H:w:l:b:d:LMp:si:o:h")) != -1) {
115 		switch (c) {
116 		case 'c':		/* compression scheme */
117 			if (!processCompressOptions(optarg))
118 				usage();
119 			break;
120 		case 'r':		/* rows/strip */
121 			rowsperstrip = atoi(optarg);
122 			break;
123 		case 'H':		/* size of input image file header */
124 			hdr_size = atoi(optarg);
125 			break;
126 		case 'w':		/* input image width */
127 			width = atoi(optarg);
128 			break;
129 		case 'l':		/* input image length */
130 			length = atoi(optarg);
131 			break;
132 		case 'b':		/* number of bands in input image */
133 			nbands = atoi(optarg);
134 			break;
135 		case 'd':		/* type of samples in input image */
136 			if (strncmp(optarg, "byte", 4) == 0)
137 				dtype = TIFF_BYTE;
138 			else if (strncmp(optarg, "short", 5) == 0)
139 				dtype = TIFF_SHORT;
140 			else if  (strncmp(optarg, "long", 4) == 0)
141 				dtype = TIFF_LONG;
142 			else if  (strncmp(optarg, "sbyte", 5) == 0)
143 				dtype = TIFF_SBYTE;
144 			else if  (strncmp(optarg, "sshort", 6) == 0)
145 				dtype = TIFF_SSHORT;
146 			else if  (strncmp(optarg, "slong", 5) == 0)
147 				dtype = TIFF_SLONG;
148 			else if  (strncmp(optarg, "float", 5) == 0)
149 				dtype = TIFF_FLOAT;
150 			else if  (strncmp(optarg, "double", 6) == 0)
151 				dtype = TIFF_DOUBLE;
152 			else
153 				dtype = TIFF_BYTE;
154 			depth = TIFFDataWidth(dtype);
155 			break;
156 		case 'L':		/* input has lsb-to-msb fillorder */
157 			fillorder = FILLORDER_LSB2MSB;
158 			break;
159 		case 'M':		/* input has msb-to-lsb fillorder */
160 			fillorder = FILLORDER_MSB2LSB;
161 			break;
162 		case 'p':		/* photometric interpretation */
163 			if (strncmp(optarg, "miniswhite", 10) == 0)
164 				photometric = PHOTOMETRIC_MINISWHITE;
165 			else if (strncmp(optarg, "minisblack", 10) == 0)
166 				photometric = PHOTOMETRIC_MINISBLACK;
167 			else if (strncmp(optarg, "rgb", 3) == 0)
168 				photometric = PHOTOMETRIC_RGB;
169 			else if (strncmp(optarg, "cmyk", 4) == 0)
170 				photometric = PHOTOMETRIC_SEPARATED;
171 			else if (strncmp(optarg, "ycbcr", 5) == 0)
172 				photometric = PHOTOMETRIC_YCBCR;
173 			else if (strncmp(optarg, "cielab", 6) == 0)
174 				photometric = PHOTOMETRIC_CIELAB;
175 			else if (strncmp(optarg, "icclab", 6) == 0)
176 				photometric = PHOTOMETRIC_ICCLAB;
177 			else if (strncmp(optarg, "itulab", 6) == 0)
178 				photometric = PHOTOMETRIC_ITULAB;
179 			else
180 				photometric = PHOTOMETRIC_MINISBLACK;
181 			break;
182 		case 's':		/* do we need to swap bytes? */
183 			swab = 1;
184 			break;
185 		case 'i':		/* type of interleaving */
186 			if (strncmp(optarg, "pixel", 4) == 0)
187 				interleaving = PIXEL;
188 			else if  (strncmp(optarg, "band", 6) == 0)
189 				interleaving = BAND;
190 			else
191 				interleaving = 0;
192 			break;
193 		case 'o':
194 			outfilename = optarg;
195 			break;
196 		case 'h':
197 			usage();
198 		default:
199 			break;
200 		}
201         }
202 
203         if (argc - optind < 2)
204 		usage();
205 
206         fd = open(argv[optind], O_RDONLY|O_BINARY, 0);
207 	if (fd < 0) {
208 		fprintf(stderr, "%s: %s: Cannot open input file.\n",
209 			argv[0], argv[optind]);
210 		return (-1);
211 	}
212 
213 	if (guessSize(fd, dtype, hdr_size, nbands, swab, &width, &length) < 0)
214 		return 1;
215 
216 	if (outfilename == NULL)
217 		outfilename = argv[optind+1];
218 	out = TIFFOpen(outfilename, "w");
219 	if (out == NULL) {
220 		fprintf(stderr, "%s: %s: Cannot open file for output.\n",
221 			argv[0], outfilename);
222 		return (-1);
223 	}
224 	TIFFSetField(out, TIFFTAG_IMAGEWIDTH, width);
225 	TIFFSetField(out, TIFFTAG_IMAGELENGTH, length);
226 	TIFFSetField(out, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
227 	TIFFSetField(out, TIFFTAG_SAMPLESPERPIXEL, nbands);
228 	TIFFSetField(out, TIFFTAG_BITSPERSAMPLE, depth * 8);
229 	TIFFSetField(out, TIFFTAG_FILLORDER, fillorder);
230 	TIFFSetField(out, TIFFTAG_PLANARCONFIG, config);
231 	TIFFSetField(out, TIFFTAG_PHOTOMETRIC, photometric);
232 	switch (dtype) {
233 	case TIFF_BYTE:
234 	case TIFF_SHORT:
235 	case TIFF_LONG:
236 		TIFFSetField(out, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_UINT);
237 		break;
238 	case TIFF_SBYTE:
239 	case TIFF_SSHORT:
240 	case TIFF_SLONG:
241 		TIFFSetField(out, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_INT);
242 		break;
243 	case TIFF_FLOAT:
244 	case TIFF_DOUBLE:
245 		TIFFSetField(out, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_IEEEFP);
246 		break;
247 	default:
248 		TIFFSetField(out, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_VOID);
249 		break;
250 	}
251 	if (compression == (uint16) -1)
252 		compression = COMPRESSION_PACKBITS;
253 	TIFFSetField(out, TIFFTAG_COMPRESSION, compression);
254 	switch (compression) {
255 	case COMPRESSION_JPEG:
256 		if (photometric == PHOTOMETRIC_RGB
257 		    && jpegcolormode == JPEGCOLORMODE_RGB)
258 			photometric = PHOTOMETRIC_YCBCR;
259 		TIFFSetField(out, TIFFTAG_JPEGQUALITY, quality);
260 		TIFFSetField(out, TIFFTAG_JPEGCOLORMODE, jpegcolormode);
261 		break;
262 	case COMPRESSION_LZW:
263 	case COMPRESSION_DEFLATE:
264 		if (predictor != 0)
265 			TIFFSetField(out, TIFFTAG_PREDICTOR, predictor);
266 		break;
267 	}
268 	switch(interleaving) {
269 	case BAND:				/* band interleaved data */
270 		linebytes = width * depth;
271 		buf = (unsigned char *)_TIFFmalloc(linebytes);
272 		break;
273 	case PIXEL:				/* pixel interleaved data */
274 	default:
275 		linebytes = width * nbands * depth;
276 		break;
277 	}
278 	bufsize = width * nbands * depth;
279 	buf1 = (unsigned char *)_TIFFmalloc(bufsize);
280 
281 	rowsperstrip = TIFFDefaultStripSize(out, rowsperstrip);
282 	if (rowsperstrip > length) {
283 		rowsperstrip = length;
284 	}
285 	TIFFSetField(out, TIFFTAG_ROWSPERSTRIP, rowsperstrip );
286 
287 	_TIFF_lseek_f(fd, hdr_size, SEEK_SET);		/* Skip the file header */
288 	for (row = 0; row < length; row++) {
289 		switch(interleaving) {
290 		case BAND:			/* band interleaved data */
291 			for (band = 0; band < nbands; band++) {
292 				if (_TIFF_lseek_f(fd,
293                                           hdr_size + (length*band+row)*linebytes,
294                                           SEEK_SET) == (_TIFF_off_t)-1) {
295                                         fprintf(stderr,
296                                                 "%s: %s: scanline %lu: seek error.\n",
297                                                 argv[0], argv[optind],
298                                                 (unsigned long) row);
299                                         break;
300                                 }
301 				if (read(fd, buf, linebytes) < 0) {
302 					fprintf(stderr,
303                                                 "%s: %s: scanline %lu: Read error.\n",
304                                                 argv[0], argv[optind],
305                                                 (unsigned long) row);
306                                         break;
307 				}
308 				if (swab)	/* Swap bytes if needed */
309 					swapBytesInScanline(buf, width, dtype);
310 				for (col = 0; col < width; col++)
311 					memcpy(buf1 + (col*nbands+band)*depth,
312 					       buf + col * depth, depth);
313 			}
314 			break;
315 		case PIXEL:			/* pixel interleaved data */
316 		default:
317 			if (read(fd, buf1, bufsize) < 0) {
318 				fprintf(stderr,
319 					"%s: %s: scanline %lu: Read error.\n",
320 					argv[0], argv[optind],
321 					(unsigned long) row);
322 				break;
323 			}
324 			if (swab)		/* Swap bytes if needed */
325 				swapBytesInScanline(buf1, width, dtype);
326 			break;
327 		}
328 
329 		if (TIFFWriteScanline(out, buf1, row, 0) < 0) {
330 			fprintf(stderr,	"%s: %s: scanline %lu: Write error.\n",
331 				argv[0], outfilename, (unsigned long) row);
332 			break;
333 		}
334 	}
335 	if (buf)
336 		_TIFFfree(buf);
337 	if (buf1)
338 		_TIFFfree(buf1);
339 	TIFFClose(out);
340 	return (0);
341 }
342 
343 static void
swapBytesInScanline(void * buf,uint32 width,TIFFDataType dtype)344 swapBytesInScanline(void *buf, uint32 width, TIFFDataType dtype)
345 {
346 	switch (dtype) {
347 		case TIFF_SHORT:
348 		case TIFF_SSHORT:
349 			TIFFSwabArrayOfShort((uint16*)buf,
350                                              (unsigned long)width);
351 			break;
352 		case TIFF_LONG:
353 		case TIFF_SLONG:
354 			TIFFSwabArrayOfLong((uint32*)buf,
355                                             (unsigned long)width);
356 			break;
357 		/* case TIFF_FLOAT: */	/* FIXME */
358 		case TIFF_DOUBLE:
359 			TIFFSwabArrayOfDouble((double*)buf,
360                                               (unsigned long)width);
361 			break;
362 		default:
363 			break;
364 	}
365 }
366 
367 static int
guessSize(int fd,TIFFDataType dtype,_TIFF_off_t hdr_size,uint32 nbands,int swab,uint32 * width,uint32 * length)368 guessSize(int fd, TIFFDataType dtype, _TIFF_off_t hdr_size, uint32 nbands,
369 	  int swab, uint32 *width, uint32 *length)
370 {
371 	const float longt = 40.0;    /* maximum possible height/width ratio */
372 	char	    *buf1, *buf2;
373 	_TIFF_stat_s filestat;
374 	uint32	    w, h, scanlinesize, imagesize;
375 	uint32	    depth = TIFFDataWidth(dtype);
376 	float	    cor_coef = 0, tmp;
377 
378 	if (_TIFF_fstat_f(fd, &filestat) == -1) {
379                 fprintf(stderr, "Failed to obtain file size.\n");
380 		return -1;
381         }
382 
383 	if (filestat.st_size < hdr_size) {
384 		fprintf(stderr, "Too large header size specified.\n");
385 		return -1;
386 	}
387 
388 	imagesize = (filestat.st_size - hdr_size) / nbands / depth;
389 
390 	if (*width != 0 && *length == 0) {
391 		fprintf(stderr,	"Image height is not specified.\n");
392 
393 		*length = imagesize / *width;
394 
395 		fprintf(stderr, "Height is guessed as %lu.\n",
396 			(unsigned long)*length);
397 
398 		return 1;
399 	} else if (*width == 0 && *length != 0) {
400 		fprintf(stderr, "Image width is not specified.\n");
401 
402 		*width = imagesize / *length;
403 
404 		fprintf(stderr,	"Width is guessed as %lu.\n",
405 			(unsigned long)*width);
406 
407 		return 1;
408 	} else if (*width == 0 && *length == 0) {
409                 unsigned int fail = 0;
410 		fprintf(stderr,	"Image width and height are not specified.\n");
411                 w = (uint32) sqrt(imagesize / longt);
412                 if( w == 0 )
413                 {
414                     fprintf(stderr, "Too small image size.\n");
415                     return -1;
416                 }
417 
418 		for (;
419 		     w < sqrt(imagesize * longt);
420 		     w++) {
421 			if (imagesize % w == 0) {
422 				scanlinesize = w * depth;
423 				buf1 = _TIFFmalloc(scanlinesize);
424 				buf2 = _TIFFmalloc(scanlinesize);
425 				h = imagesize / w;
426                                 do {
427                                         if (_TIFF_lseek_f(fd, hdr_size + (int)(h/2)*scanlinesize,
428                                                   SEEK_SET) == (_TIFF_off_t)-1) {
429                                                 fprintf(stderr, "seek error.\n");
430                                                 fail=1;
431                                                 break;
432                                         }
433                                         if (read(fd, buf1, scanlinesize) !=
434                                             (long) scanlinesize) {
435                                                 fprintf(stderr, "read error.\n");
436                                                 fail=1;
437                                                 break;
438                                         }
439                                         if (read(fd, buf2, scanlinesize) !=
440                                             (long) scanlinesize) {
441                                                 fprintf(stderr, "read error.\n");
442                                                 fail=1;
443                                                 break;
444                                         }
445                                         if (swab) {
446                                                 swapBytesInScanline(buf1, w, dtype);
447                                                 swapBytesInScanline(buf2, w, dtype);
448                                         }
449                                         tmp = (float) fabs(correlation(buf1, buf2,
450                                                                        w, dtype));
451                                         if (tmp > cor_coef) {
452                                                 cor_coef = tmp;
453                                                 *width = w, *length = h;
454                                         }
455                                 } while (0);
456 
457                                 _TIFFfree(buf1);
458 				_TIFFfree(buf2);
459 			}
460 		}
461 
462                 if (fail) {
463                         return -1;
464                 }
465 
466 		fprintf(stderr,
467 			"Width is guessed as %lu, height is guessed as %lu.\n",
468 			(unsigned long)*width, (unsigned long)*length);
469 
470 		return 1;
471 	} else {
472 		if (filestat.st_size<(_TIFF_off_t)(hdr_size+(*width)*(*length)*nbands*depth)) {
473 			fprintf(stderr, "Input file too small.\n");
474 		return -1;
475 		}
476 	}
477 
478 	return 1;
479 }
480 
481 /* Calculate correlation coefficient between two numeric vectors */
482 static double
correlation(void * buf1,void * buf2,uint32 n_elem,TIFFDataType dtype)483 correlation(void *buf1, void *buf2, uint32 n_elem, TIFFDataType dtype)
484 {
485 	double	X, Y, M1 = 0.0, M2 = 0.0, D1 = 0.0, D2 = 0.0, K = 0.0;
486 	uint32	i;
487 
488 	switch (dtype) {
489 		case TIFF_BYTE:
490 		default:
491                         for (i = 0; i < n_elem; i++) {
492 				X = ((unsigned char *)buf1)[i];
493 				Y = ((unsigned char *)buf2)[i];
494 				M1 += X, M2 += Y;
495 				D1 += X * X, D2 += Y * Y;
496 				K += X * Y;
497                         }
498 			break;
499 		case TIFF_SBYTE:
500                         for (i = 0; i < n_elem; i++) {
501 				X = ((signed char *)buf1)[i];
502 				Y = ((signed char *)buf2)[i];
503 				M1 += X, M2 += Y;
504 				D1 += X * X, D2 += Y * Y;
505 				K += X * Y;
506                         }
507 			break;
508 		case TIFF_SHORT:
509                         for (i = 0; i < n_elem; i++) {
510 				X = ((uint16 *)buf1)[i];
511 				Y = ((uint16 *)buf2)[i];
512 				M1 += X, M2 += Y;
513 				D1 += X * X, D2 += Y * Y;
514 				K += X * Y;
515                         }
516 			break;
517 		case TIFF_SSHORT:
518                         for (i = 0; i < n_elem; i++) {
519 				X = ((int16 *)buf1)[i];
520 				Y = ((int16 *)buf2)[i];
521 				M1 += X, M2 += Y;
522 				D1 += X * X, D2 += Y * Y;
523 				K += X * Y;
524                         }
525 			break;
526 		case TIFF_LONG:
527                         for (i = 0; i < n_elem; i++) {
528 				X = ((uint32 *)buf1)[i];
529 				Y = ((uint32 *)buf2)[i];
530 				M1 += X, M2 += Y;
531 				D1 += X * X, D2 += Y * Y;
532 				K += X * Y;
533                         }
534 			break;
535 		case TIFF_SLONG:
536                         for (i = 0; i < n_elem; i++) {
537 				X = ((int32 *)buf1)[i];
538 				Y = ((int32 *)buf2)[i];
539 				M1 += X, M2 += Y;
540 				D1 += X * X, D2 += Y * Y;
541 				K += X * Y;
542                         }
543 			break;
544 		case TIFF_FLOAT:
545                         for (i = 0; i < n_elem; i++) {
546 				X = ((float *)buf1)[i];
547 				Y = ((float *)buf2)[i];
548 				M1 += X, M2 += Y;
549 				D1 += X * X, D2 += Y * Y;
550 				K += X * Y;
551                         }
552 			break;
553 		case TIFF_DOUBLE:
554                         for (i = 0; i < n_elem; i++) {
555 				X = ((double *)buf1)[i];
556 				Y = ((double *)buf2)[i];
557 				M1 += X, M2 += Y;
558 				D1 += X * X, D2 += Y * Y;
559 				K += X * Y;
560                         }
561 			break;
562 	}
563 
564 	M1 /= n_elem;
565 	M2 /= n_elem;
566 	D1 -= M1 * M1 * n_elem;
567 	D2 -= M2 * M2 * n_elem;
568 	K = (K - M1 * M2 * n_elem) / sqrt(D1 * D2);
569 
570 	return K;
571 }
572 
573 static int
processCompressOptions(char * opt)574 processCompressOptions(char* opt)
575 {
576 	if (strcmp(opt, "none") == 0)
577 		compression = COMPRESSION_NONE;
578 	else if (strcmp(opt, "packbits") == 0)
579 		compression = COMPRESSION_PACKBITS;
580 	else if (strncmp(opt, "jpeg", 4) == 0) {
581 		char* cp = strchr(opt, ':');
582 
583                 compression = COMPRESSION_JPEG;
584                 while( cp )
585                 {
586                     if (isdigit((int)cp[1]))
587 			quality = atoi(cp+1);
588                     else if (cp[1] == 'r' )
589 			jpegcolormode = JPEGCOLORMODE_RAW;
590                     else
591                         usage();
592 
593                     cp = strchr(cp+1,':');
594                 }
595 	} else if (strncmp(opt, "lzw", 3) == 0) {
596 		char* cp = strchr(opt, ':');
597 		if (cp)
598 			predictor = atoi(cp+1);
599 		compression = COMPRESSION_LZW;
600 	} else if (strncmp(opt, "zip", 3) == 0) {
601 		char* cp = strchr(opt, ':');
602 		if (cp)
603 			predictor = atoi(cp+1);
604 		compression = COMPRESSION_DEFLATE;
605 	} else
606 		return (0);
607 	return (1);
608 }
609 
610 static char* stuff[] = {
611 "raw2tiff --- tool for converting raw byte sequences in TIFF images",
612 "usage: raw2tiff [options] input.raw output.tif",
613 "where options are:",
614 " -L		input data has LSB2MSB bit order (default)",
615 " -M		input data has MSB2LSB bit order",
616 " -r #		make each strip have no more than # rows",
617 " -H #		size of input image file header in bytes (0 by default)",
618 " -w #		width of input image in pixels",
619 " -l #		length of input image in lines",
620 " -b #		number of bands in input image (1 by default)",
621 "",
622 " -d data_type	type of samples in input image",
623 "where data_type may be:",
624 " byte		8-bit unsigned integer (default)",
625 " short		16-bit unsigned integer",
626 " long		32-bit unsigned integer",
627 " sbyte		8-bit signed integer",
628 " sshort		16-bit signed integer",
629 " slong		32-bit signed integer",
630 " float		32-bit IEEE floating point",
631 " double		64-bit IEEE floating point",
632 "",
633 " -p photo	photometric interpretation (color space) of the input image",
634 "where photo may be:",
635 " miniswhite	white color represented with 0 value",
636 " minisblack	black color represented with 0 value (default)",
637 " rgb		image has RGB color model",
638 " cmyk		image has CMYK (separated) color model",
639 " ycbcr		image has YCbCr color model",
640 " cielab		image has CIE L*a*b color model",
641 " icclab		image has ICC L*a*b color model",
642 " itulab		image has ITU L*a*b color model",
643 "",
644 " -s		swap bytes fetched from input file",
645 "",
646 " -i config	type of samples interleaving in input image",
647 "where config may be:",
648 " pixel		pixel interleaved data (default)",
649 " band		band interleaved data",
650 "",
651 " -c lzw[:opts]	compress output with Lempel-Ziv & Welch encoding",
652 " -c zip[:opts]	compress output with deflate encoding",
653 " -c jpeg[:opts]	compress output with JPEG encoding",
654 " -c packbits	compress output with packbits encoding",
655 " -c none	use no compression algorithm on output",
656 "",
657 "JPEG options:",
658 " #		set compression quality level (0-100, default 75)",
659 " r		output color image as RGB rather than YCbCr",
660 "For example, -c jpeg:r:50 to get JPEG-encoded RGB data with 50% comp. quality",
661 "",
662 "LZW and deflate options:",
663 " #		set predictor value",
664 "For example, -c lzw:2 to get LZW-encoded data with horizontal differencing",
665 " -o out.tif	write output to out.tif",
666 " -h		this help message",
667 NULL
668 };
669 
670 static void
usage(void)671 usage(void)
672 {
673 	char buf[BUFSIZ];
674 	int i;
675 
676 	setbuf(stderr, buf);
677         fprintf(stderr, "%s\n\n", TIFFGetVersion());
678 	for (i = 0; stuff[i] != NULL; i++)
679 		fprintf(stderr, "%s\n", stuff[i]);
680 	exit(-1);
681 }
682 
683 /* vim: set ts=8 sts=8 sw=8 noet: */
684 /*
685  * Local Variables:
686  * mode: c
687  * c-basic-offset: 8
688  * fill-column: 78
689  * End:
690  */
691