2 * Project
: libtiff tools
3 * Purpose
: Convert Windows BMP files in TIFF
.
4 * Author
: Andrey Kiselev
, dron@ak4719
.spb
.edu
6 ******************************************************************************
7 * Copyright (c
) 2004, Andrey Kiselev
<dron@ak4719
.spb
.edu
>
9 * Permission to use
, copy
, modify
, distribute
, and sell
this software
and
10 * its documentation
for any purpose is hereby granted without fee
, provided
11 * that (i
) the above copyright notices
and this permission notice appear in
12 * all copies of the software
and related documentation
, and (ii
) the names of
13 * Sam Leffler
and Silicon Graphics may
not be used in any advertising
or
14 * publicity relating to the software without the specific
, prior written
15 * permission of Sam Leffler
and Silicon Graphics
.
17 * THE SOFTWARE IS PROVIDED
"AS-IS" AND WITHOUT WARRANTY OF ANY KIND
,
18 * EXPRESS
, IMPLIED OR OTHERWISE
, INCLUDING WITHOUT LIMITATION
, ANY
19 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
.
21 * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
22 * ANY SPECIAL
, INCIDENTAL
, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND
,
23 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE
, DATA OR PROFITS
,
24 * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE
, AND ON ANY THEORY OF
25 * LIABILITY
, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
29 #include "tif_config.h"
35 #include <sys/types.h>
47 # include <sys/types.h>
66 BMPT_WIN4
, /* BMP used in Windows 3.0/NT 3.51/95 */
67 BMPT_WIN5
, /* BMP used in Windows NT 4.0/98/Me/2000/XP */
68 BMPT_OS21
, /* BMP used in OS/2 PM 1.x */
69 BMPT_OS22
/* BMP used in OS/2 PM 2.x */
73 * Bitmap file consists of a BMPFileHeader structure followed by a
74 * BMPInfoHeader structure. An array of BMPColorEntry structures (also called
75 * a colour table) follows the bitmap information header structure. The colour
76 * table is followed by a second array of indexes into the colour table (the
77 * actual bitmap data). Data may be comressed, for 4-bpp and 8-bpp used RLE
80 * +---------------------+
82 * +---------------------+
84 * +---------------------+
85 * | BMPColorEntry array |
86 * +---------------------+
87 * | Colour-index array |
88 * +---------------------+
90 * All numbers stored in Intel order with least significant byte first.
95 BMPC_RGB
= 0L, /* Uncompressed */
96 BMPC_RLE8
= 1L, /* RLE for 8 bpp images */
97 BMPC_RLE4
= 2L, /* RLE for 4 bpp images */
98 BMPC_BITFIELDS
= 3L, /* Bitmap is not compressed and the colour table
99 * consists of three DWORD color masks that specify
100 * the red, green, and blue components of each
101 * pixel. This is valid when used with
102 * 16- and 32-bpp bitmaps. */
103 BMPC_JPEG
= 4L, /* Indicates that the image is a JPEG image. */
104 BMPC_PNG
= 5L /* Indicates that the image is a PNG image. */
107 enum BMPLCSType
/* Type of logical color space. */
109 BMPLT_CALIBRATED_RGB
= 0, /* This value indicates that endpoints and
110 * gamma values are given in the appropriate
112 BMPLT_DEVICE_RGB
= 1,
113 BMPLT_DEVICE_CMYK
= 2
123 typedef struct /* This structure contains the x, y, and z */
124 { /* coordinates of the three colors that */
126 BMPCIEXYZ iCIERed
; /* to the red, green, and blue endpoints for */
127 BMPCIEXYZ iCIEGreen
; /* a specified logical color space. */
133 char bType
[2]; /* Signature "BM" */
134 uint32 iSize
; /* Size in bytes of the bitmap file. Should
135 * always be ignored while reading because
136 * of error in Windows 3.0 SDK's description
138 uint16 iReserved1
; /* Reserved, set as 0 */
139 uint16 iReserved2
; /* Reserved, set as 0 */
140 uint32 iOffBits
; /* Offset of the image from file start in bytes */
143 /* File header size in bytes: */
144 const int BFH_SIZE
= 14;
148 uint32 iSize
; /* Size of BMPInfoHeader structure in bytes.
149 * Should be used to determine start of the
151 int32 iWidth
; /* Image width */
152 int32 iHeight
; /* Image height. If positive, image has bottom
153 * left origin, if negative --- top left. */
154 int16 iPlanes
; /* Number of image planes (must be set to 1) */
155 int16 iBitCount
; /* Number of bits per pixel (1, 4, 8, 16, 24
156 * or 32). If 0 then the number of bits per
157 * pixel is specified or is implied by the
158 * JPEG or PNG format. */
159 uint32 iCompression
; /* Compression method */
160 uint32 iSizeImage
; /* Size of uncomressed image in bytes. May
161 * be 0 for BMPC_RGB bitmaps. If iCompression
162 * is BI_JPEG or BI_PNG, iSizeImage indicates
163 * the size of the JPEG or PNG image buffer. */
164 int32 iXPelsPerMeter
; /* X resolution, pixels per meter (0 if not used) */
165 int32 iYPelsPerMeter
; /* Y resolution, pixels per meter (0 if not used) */
166 uint32 iClrUsed
; /* Size of colour table. If 0, iBitCount should
167 * be used to calculate this value
168 * (1<<iBitCount). This value should be
169 * unsigned for proper shifting. */
170 int32 iClrImportant
; /* Number of important colours. If 0, all
171 * colours are required */
174 * Fields above should be used for bitmaps, compatible with Windows NT 3.51
175 * and earlier. Windows 98/Me, Windows 2000/XP introduces additional fields:
178 int32 iRedMask
; /* Colour mask that specifies the red component
179 * of each pixel, valid only if iCompression
180 * is set to BI_BITFIELDS. */
181 int32 iGreenMask
; /* The same for green component */
182 int32 iBlueMask
; /* The same for blue component */
183 int32 iAlphaMask
; /* Colour mask that specifies the alpha
184 * component of each pixel. */
185 uint32 iCSType
; /* Colour space of the DIB. */
186 BMPCIEXYZTriple sEndpoints
; /* This member is ignored unless the iCSType
187 * member specifies BMPLT_CALIBRATED_RGB. */
188 int32 iGammaRed
; /* Toned response curve for red. This member
189 * is ignored unless color values are
190 * calibrated RGB values and iCSType is set to
191 * BMPLT_CALIBRATED_RGB. Specified
192 * in 16^16 format. */
193 int32 iGammaGreen
; /* Toned response curve for green. */
194 int32 iGammaBlue
; /* Toned response curve for blue. */
198 * Info header size in bytes:
200 const unsigned int BIH_WIN4SIZE
= 40; /* for BMPT_WIN4 */
201 const unsigned int BIH_WIN5SIZE
= 57; /* for BMPT_WIN5 */
202 const unsigned int BIH_OS21SIZE
= 12; /* for BMPT_OS21 */
203 const unsigned int BIH_OS22SIZE
= 64; /* for BMPT_OS22 */
206 * We will use plain byte array instead of this structure, but declaration
207 * provided for reference
214 char bReserved
; /* Must be 0 */
217 static uint16 compression
= (uint16
) -1;
218 static int jpegcolormode
= JPEGCOLORMODE_RGB
;
219 static int quality
= 75; /* JPEG quality */
220 static uint16 predictor
= 0;
222 static void usage(void);
223 static int processCompressOptions(char*);
224 static void rearrangePixels(char *, uint32
, uint32
);
227 main(int argc
, char* argv
[])
229 uint32 width
, length
;
230 uint16 nbands
= 1; /* number of bands in input image */
231 uint16 depth
= 8; /* bits per pixel in input image */
232 uint32 rowsperstrip
= (uint32
) -1;
233 uint16 photometric
= PHOTOMETRIC_MINISBLACK
;
236 char *outfilename
= NULL
, *infilename
= NULL
;
239 BMPFileHeader file_hdr
;
240 BMPInfoHeader info_hdr
;
242 uint32 clr_tbl_size
, n_clr_elems
= 3;
243 unsigned char *clr_tbl
;
244 unsigned short *red_tbl
= NULL
, *green_tbl
= NULL
, *blue_tbl
= NULL
;
251 while ((c
= getopt(argc
, argv
, "c:r:o:h")) != -1) {
253 case 'c': /* compression scheme */
254 if (!processCompressOptions(optarg
))
257 case 'r': /* rows/strip */
258 rowsperstrip
= atoi(optarg
);
261 outfilename
= optarg
;
270 if (argc
- optind
< 2)
273 if (outfilename
== NULL
)
274 outfilename
= argv
[argc
-1];
275 out
= TIFFOpen(outfilename
, "w");
277 TIFFError(infilename
, "Cannot open file %s for output",
283 while (optind
< argc
-1) {
284 infilename
= argv
[optind
];
287 fd
= open(infilename
, O_RDONLY
|O_BINARY
, 0);
289 TIFFError(infilename
, "Cannot open input file");
293 read(fd
, file_hdr
.bType
, 2);
294 if(file_hdr
.bType
[0] != 'B' || file_hdr
.bType
[1] != 'M') {
295 TIFFError(infilename
, "File is not BMP");
299 /* -------------------------------------------------------------------- */
300 /* Read the BMPFileHeader. We need iOffBits value only */
301 /* -------------------------------------------------------------------- */
302 lseek(fd
, 10, SEEK_SET
);
303 read(fd
, &file_hdr
.iOffBits
, 4);
304 #ifdef WORDS_BIGENDIAN
305 TIFFSwabLong(&file_hdr
.iOffBits
);
308 file_hdr
.iSize
= instat
.st_size
;
310 /* -------------------------------------------------------------------- */
311 /* Read the BMPInfoHeader. */
312 /* -------------------------------------------------------------------- */
314 lseek(fd
, BFH_SIZE
, SEEK_SET
);
315 read(fd
, &info_hdr
.iSize
, 4);
316 #ifdef WORDS_BIGENDIAN
317 TIFFSwabLong(&info_hdr
.iSize
);
320 if (info_hdr
.iSize
== BIH_WIN4SIZE
)
321 bmp_type
= BMPT_WIN4
;
322 else if (info_hdr
.iSize
== BIH_OS21SIZE
)
323 bmp_type
= BMPT_OS21
;
324 else if (info_hdr
.iSize
== BIH_OS22SIZE
325 || info_hdr
.iSize
== 16)
326 bmp_type
= BMPT_OS22
;
328 bmp_type
= BMPT_WIN5
;
330 if (bmp_type
== BMPT_WIN4
331 || bmp_type
== BMPT_WIN5
332 || bmp_type
== BMPT_OS22
) {
333 read(fd
, &info_hdr
.iWidth
, 4);
334 read(fd
, &info_hdr
.iHeight
, 4);
335 read(fd
, &info_hdr
.iPlanes
, 2);
336 read(fd
, &info_hdr
.iBitCount
, 2);
337 read(fd
, &info_hdr
.iCompression
, 4);
338 read(fd
, &info_hdr
.iSizeImage
, 4);
339 read(fd
, &info_hdr
.iXPelsPerMeter
, 4);
340 read(fd
, &info_hdr
.iYPelsPerMeter
, 4);
341 read(fd
, &info_hdr
.iClrUsed
, 4);
342 read(fd
, &info_hdr
.iClrImportant
, 4);
343 #ifdef WORDS_BIGENDIAN
344 TIFFSwabLong((uint32
*) &info_hdr
.iWidth
);
345 TIFFSwabLong((uint32
*) &info_hdr
.iHeight
);
346 TIFFSwabShort((uint16
*) &info_hdr
.iPlanes
);
347 TIFFSwabShort((uint16
*) &info_hdr
.iBitCount
);
348 TIFFSwabLong((uint32
*) &info_hdr
.iCompression
);
349 TIFFSwabLong((uint32
*) &info_hdr
.iSizeImage
);
350 TIFFSwabLong((uint32
*) &info_hdr
.iXPelsPerMeter
);
351 TIFFSwabLong((uint32
*) &info_hdr
.iYPelsPerMeter
);
352 TIFFSwabLong((uint32
*) &info_hdr
.iClrUsed
);
353 TIFFSwabLong((uint32
*) &info_hdr
.iClrImportant
);
358 if (bmp_type
== BMPT_OS22
) {
360 * FIXME: different info in different documents
366 if (bmp_type
== BMPT_OS21
) {
369 read(fd
, &iShort
, 2);
370 #ifdef WORDS_BIGENDIAN
371 TIFFSwabShort((uint16
*) &iShort
);
373 info_hdr
.iWidth
= iShort
;
374 read(fd
, &iShort
, 2);
375 #ifdef WORDS_BIGENDIAN
376 TIFFSwabShort((uint16
*) &iShort
);
378 info_hdr
.iHeight
= iShort
;
379 read(fd
, &iShort
, 2);
380 #ifdef WORDS_BIGENDIAN
381 TIFFSwabShort((uint16
*) &iShort
);
383 info_hdr
.iPlanes
= iShort
;
384 read(fd
, &iShort
, 2);
385 #ifdef WORDS_BIGENDIAN
386 TIFFSwabShort((uint16
*) &iShort
);
388 info_hdr
.iBitCount
= iShort
;
389 info_hdr
.iCompression
= BMPC_RGB
;
393 if (info_hdr
.iBitCount
!= 1 && info_hdr
.iBitCount
!= 4 &&
394 info_hdr
.iBitCount
!= 8 && info_hdr
.iBitCount
!= 16 &&
395 info_hdr
.iBitCount
!= 24 && info_hdr
.iBitCount
!= 32) {
396 TIFFError(infilename
,
397 "Cannot process BMP file with bit count %d",
403 width
= info_hdr
.iWidth
;
404 length
= (info_hdr
.iHeight
> 0) ? info_hdr
.iHeight
: -info_hdr
.iHeight
;
406 switch (info_hdr
.iBitCount
)
412 depth
= info_hdr
.iBitCount
;
413 photometric
= PHOTOMETRIC_PALETTE
;
414 /* Allocate memory for colour table and read it. */
415 if (info_hdr
.iClrUsed
)
417 ((uint32
)(1<<depth
)<info_hdr
.iClrUsed
)
418 ? (uint32
) (1 << depth
)
421 clr_tbl_size
= 1 << depth
;
422 clr_tbl
= (unsigned char *)
423 _TIFFmalloc(n_clr_elems
* clr_tbl_size
);
425 TIFFError(infilename
,
426 "Can't allocate space for color table");
430 lseek(fd
, BFH_SIZE
+ info_hdr
.iSize
, SEEK_SET
);
431 read(fd
, clr_tbl
, n_clr_elems
* clr_tbl_size
);
433 red_tbl
= (unsigned short*)
434 _TIFFmalloc(((tmsize_t
)1)<<depth
* sizeof(unsigned short));
436 TIFFError(infilename
,
437 "Can't allocate space for red component table");
441 green_tbl
= (unsigned short*)
442 _TIFFmalloc(((tmsize_t
)1)<<depth
* sizeof(unsigned short));
444 TIFFError(infilename
,
445 "Can't allocate space for green component table");
449 blue_tbl
= (unsigned short*)
450 _TIFFmalloc(((tmsize_t
)1)<<depth
* sizeof(unsigned short));
452 TIFFError(infilename
,
453 "Can't allocate space for blue component table");
458 for(clr
= 0; clr
< clr_tbl_size
; clr
++) {
459 red_tbl
[clr
] = 257*clr_tbl
[clr
*n_clr_elems
+2];
460 green_tbl
[clr
] = 257*clr_tbl
[clr
*n_clr_elems
+1];
461 blue_tbl
[clr
] = 257*clr_tbl
[clr
*n_clr_elems
];
469 depth
= info_hdr
.iBitCount
/ nbands
;
470 photometric
= PHOTOMETRIC_RGB
;
475 photometric
= PHOTOMETRIC_RGB
;
481 /* -------------------------------------------------------------------- */
482 /* Create output file. */
483 /* -------------------------------------------------------------------- */
485 TIFFSetField(out
, TIFFTAG_IMAGEWIDTH
, width
);
486 TIFFSetField(out
, TIFFTAG_IMAGELENGTH
, length
);
487 TIFFSetField(out
, TIFFTAG_ORIENTATION
, ORIENTATION_TOPLEFT
);
488 TIFFSetField(out
, TIFFTAG_SAMPLESPERPIXEL
, nbands
);
489 TIFFSetField(out
, TIFFTAG_BITSPERSAMPLE
, depth
);
490 TIFFSetField(out
, TIFFTAG_PLANARCONFIG
, PLANARCONFIG_CONTIG
);
491 TIFFSetField(out
, TIFFTAG_PHOTOMETRIC
, photometric
);
492 TIFFSetField(out
, TIFFTAG_ROWSPERSTRIP
,
493 TIFFDefaultStripSize(out
, rowsperstrip
));
495 if (red_tbl
&& green_tbl
&& blue_tbl
) {
496 TIFFSetField(out
, TIFFTAG_COLORMAP
,
497 red_tbl
, green_tbl
, blue_tbl
);
500 if (compression
== (uint16
) -1)
501 compression
= COMPRESSION_PACKBITS
;
502 TIFFSetField(out
, TIFFTAG_COMPRESSION
, compression
);
503 switch (compression
) {
504 case COMPRESSION_JPEG
:
505 if (photometric
== PHOTOMETRIC_RGB
506 && jpegcolormode
== JPEGCOLORMODE_RGB
)
507 photometric
= PHOTOMETRIC_YCBCR
;
508 TIFFSetField(out
, TIFFTAG_JPEGQUALITY
, quality
);
509 TIFFSetField(out
, TIFFTAG_JPEGCOLORMODE
, jpegcolormode
);
511 case COMPRESSION_LZW
:
512 case COMPRESSION_DEFLATE
:
514 TIFFSetField(out
, TIFFTAG_PREDICTOR
, predictor
);
518 /* -------------------------------------------------------------------- */
519 /* Read uncompressed image data. */
520 /* -------------------------------------------------------------------- */
522 if (info_hdr
.iCompression
== BMPC_RGB
) {
526 /* XXX: Avoid integer overflow. We can calculate size
529 * size = ((width * info_hdr.iBitCount + 31) & ~31) / 8
531 * formulae, but we should check for overflow
532 * conditions during calculation.
534 size
= width
* info_hdr
.iBitCount
+ 31;
535 if (!width
|| !info_hdr
.iBitCount
536 || (size
- 31) / info_hdr
.iBitCount
!= width
) {
537 TIFFError(infilename
,
538 "Wrong image parameters; can't "
539 "allocate space for scanline buffer");
542 size
= (size
& ~31) / 8;
544 scanbuf
= (char *) _TIFFmalloc(size
);
546 TIFFError(infilename
,
547 "Can't allocate space for scanline buffer");
551 for (row
= 0; row
< length
; row
++) {
552 if (info_hdr
.iHeight
> 0)
553 offset
= file_hdr
.iOffBits
+(length
-row
-1)*size
;
555 offset
= file_hdr
.iOffBits
+ row
* size
;
556 if (lseek(fd
, offset
, SEEK_SET
) == (off_t
)-1) {
557 TIFFError(infilename
,
558 "scanline %lu: Seek error",
559 (unsigned long) row
);
563 if (read(fd
, scanbuf
, size
) < 0) {
564 TIFFError(infilename
,
565 "scanline %lu: Read error",
566 (unsigned long) row
);
570 rearrangePixels(scanbuf
, width
, info_hdr
.iBitCount
);
572 if (TIFFWriteScanline(out
, scanbuf
, row
, 0)<0) {
573 TIFFError(infilename
,
574 "scanline %lu: Write error",
575 (unsigned long) row
);
582 /* -------------------------------------------------------------------- */
583 /* Read compressed image data. */
584 /* -------------------------------------------------------------------- */
586 } else if ( info_hdr
.iCompression
== BMPC_RLE8
587 || info_hdr
.iCompression
== BMPC_RLE4
) {
588 uint32 i
, j
, k
, runlength
;
589 uint32 compr_size
, uncompr_size
;
590 unsigned char *comprbuf
;
591 unsigned char *uncomprbuf
;
593 compr_size
= file_hdr
.iSize
- file_hdr
.iOffBits
;
594 uncompr_size
= width
* length
;
595 comprbuf
= (unsigned char *) _TIFFmalloc( compr_size
);
597 TIFFError(infilename
,
598 "Can't allocate space for compressed scanline buffer");
601 uncomprbuf
= (unsigned char *)_TIFFmalloc(uncompr_size
);
603 TIFFError(infilename
,
604 "Can't allocate space for uncompressed scanline buffer");
608 lseek(fd
, file_hdr
.iOffBits
, SEEK_SET
);
609 read(fd
, comprbuf
, compr_size
);
612 if (info_hdr
.iBitCount
== 8) { /* RLE8 */
613 while(j
< uncompr_size
&& i
< compr_size
) {
615 runlength
= comprbuf
[i
++];
618 && i
< compr_size
) {
619 uncomprbuf
[j
++] = comprbuf
[i
];
625 if (comprbuf
[i
] == 0) /* Next scanline */
627 else if (comprbuf
[i
] == 1) /* End of image */
629 else if (comprbuf
[i
] == 2) { /* Move to... */
631 if (i
< compr_size
- 1) {
632 j
+=comprbuf
[i
]+comprbuf
[i
+1]*width
;
637 } else { /* Absolute mode */
638 runlength
= comprbuf
[i
++];
639 for (k
= 0; k
< runlength
&& j
< uncompr_size
&& i
< compr_size
; k
++)
640 uncomprbuf
[j
++] = comprbuf
[i
++];
648 while( j
< uncompr_size
&& i
< compr_size
) {
650 runlength
= comprbuf
[i
++];
651 while( runlength
> 0 && j
< uncompr_size
&& i
< compr_size
) {
652 if ( runlength
& 0x01 )
653 uncomprbuf
[j
++] = (comprbuf
[i
] & 0xF0) >> 4;
655 uncomprbuf
[j
++] = comprbuf
[i
] & 0x0F;
661 if (comprbuf
[i
] == 0) /* Next scanline */
663 else if (comprbuf
[i
] == 1) /* End of image */
665 else if (comprbuf
[i
] == 2) { /* Move to... */
667 if (i
< compr_size
- 1) {
668 j
+=comprbuf
[i
]+comprbuf
[i
+1]*width
;
673 } else { /* Absolute mode */
674 runlength
= comprbuf
[i
++];
675 for (k
= 0; k
< runlength
&& j
< uncompr_size
&& i
< compr_size
; k
++) {
677 uncomprbuf
[j
++] = comprbuf
[i
++] & 0x0F;
679 uncomprbuf
[j
++] = (comprbuf
[i
] & 0xF0) >> 4;
690 for (row
= 0; row
< length
; row
++) {
691 if (TIFFWriteScanline(out
,
692 uncomprbuf
+ (length
- row
- 1) * width
,
694 TIFFError(infilename
,
695 "scanline %lu: Write error.\n",
696 (unsigned long) row
);
700 _TIFFfree(uncomprbuf
);
702 TIFFWriteDirectory(out
);
708 _TIFFfree(green_tbl
);
722 _TIFFfree(green_tbl
);
735 * Image data in BMP file stored in BGR (or ABGR) format. We should rearrange
736 * pixels to RGB (RGBA) format.
739 rearrangePixels(char *buf
, uint32 width
, uint32 bit_count
)
745 case 16: /* FIXME: need a sample file */
748 for (i
= 0; i
< width
; i
++, buf
+= 3) {
758 for (i
= 0; i
< width
; i
++, buf
+= 4) {
760 *buf1
++ = *(buf
+ 2);
761 *buf1
++ = *(buf
+ 1);
772 processCompressOptions(char* opt
)
774 if (strcmp(opt
, "none") == 0)
775 compression
= COMPRESSION_NONE
;
776 else if (strcmp(opt
, "packbits") == 0)
777 compression
= COMPRESSION_PACKBITS
;
778 else if (strncmp(opt
, "jpeg", 4) == 0) {
779 char* cp
= strchr(opt
, ':');
781 compression
= COMPRESSION_JPEG
;
784 if (isdigit((int)cp
[1]))
785 quality
= atoi(cp
+1);
786 else if (cp
[1] == 'r' )
787 jpegcolormode
= JPEGCOLORMODE_RAW
;
791 cp
= strchr(cp
+1,':');
793 } else if (strncmp(opt
, "lzw", 3) == 0) {
794 char* cp
= strchr(opt
, ':');
796 predictor
= atoi(cp
+1);
797 compression
= COMPRESSION_LZW
;
798 } else if (strncmp(opt
, "zip", 3) == 0) {
799 char* cp
= strchr(opt
, ':');
801 predictor
= atoi(cp
+1);
802 compression
= COMPRESSION_DEFLATE
;
808 static char* stuff
[] = {
809 "bmp2tiff --- convert Windows BMP files to TIFF",
810 "usage: bmp2tiff [options] input.bmp [input2.bmp ...] output.tif",
811 "where options are:",
812 " -r # make each strip have no more than # rows",
814 " -c lzw[:opts] compress output with Lempel-Ziv & Welch encoding",
815 " -c zip[:opts] compress output with deflate encoding",
816 " -c jpeg[:opts]compress output with JPEG encoding",
817 " -c packbits compress output with packbits encoding",
818 " -c none use no compression algorithm on output",
821 " # set compression quality level (0-100, default 75)",
822 " r output color image as RGB rather than YCbCr",
823 "For example, -c jpeg:r:50 to get JPEG-encoded RGB data with 50% comp. quality",
825 "LZW and deflate options:",
826 " # set predictor value",
827 "For example, -c lzw:2 to get LZW-encoded data with horizontal differencing",
828 " -o out.tif write output to out.tif",
829 " -h this help message",
840 fprintf(stderr
, "%s\n\n", TIFFGetVersion());
841 for (i
= 0; stuff
[i
] != NULL
; i
++)
842 fprintf(stderr
, "%s\n", stuff
[i
]);
846 /* vim: set ts=8 sts=8 sw=8 noet: */