10 #define NO_DECLARE_MALLOC
18 #define USE_PROTOTYPES 1
45 unsigned char bc4[16] = { 0, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
46 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xee, 0xff };
47 unsigned char bc2[4] = { 0, 0x55, 0xaa, 0xff };
48 unsigned char bc1[2] = { 0, 0xff };
56 unsigned short imagelength, imagewidth;
58 unsigned long imagelength, imagewidth;
60 unsigned short photometric, shortval;
61 unsigned short planarconfig, matteing;
64 char *infname = NULL, *outfname = NULL;
67 if (
scanargs( argc
, argv
, "% o%-outfile.rle!s infile.tiff!s\n(\
68 \tConvert TIFF image to URT.)",
69 &i
, &outfname
, &infname
) == 0 )
74 tif = TIFFOpen(infname,
"rb");
75 if (!
tif) error(
"can't open input file");
78 if (TIFFGetField(
tif, TIFFTAG_IMAGEWIDTH, &imagewidth) == 0)
79 error(
"TIFFGetField TIFFTAG_IMAGEWIDTH failed!");
80 if (TIFFGetField(
tif, TIFFTAG_IMAGELENGTH, &imagelength) == 0)
81 error(
"TIFFGetField TIFFTAG_IMAGELENGTH failed!");
83 error(
"TIFFGetField TIFFTAG_SAMPLESPERPIXEL failed!");
85 error(
"TIFFGetField TIFFTAG_BITSPERSAMPLE failed!");
86 if (TIFFGetField(
tif, TIFFTAG_PHOTOMETRIC, &photometric) == 0)
87 error(
"TIFFGetField TIFFTAG_PHOTOMETRIC failed!");
91 for ( i = 0; i < 16; i++ )
92 if ( photometric == PHOTOMETRIC_RGB )
98 for ( i = 0; i < 4; i++ )
99 if ( photometric == PHOTOMETRIC_RGB )
105 if ( photometric == PHOTOMETRIC_RGB )
119 error(
"Bits per sample not 1, 2, 4, or 8");
122 if (TIFFGetField(
tif, TIFFTAG_PLANARCONFIG, &planarconfig ) == 0)
123 error(
"TIFFGetField TIFFTAG_PLANARCONFIG failed!");
125 (
void)TIFFGetField(
tif, TIFFTAG_MATTEING, &matteing );
127 switch ( photometric ) {
128 case PHOTOMETRIC_MINISWHITE:
131 if ( planarconfig == PLANARCONFIG_SEPARATE && matteing )
136 the_hdr.cmap = (
unsigned short *)malloc((
unsigned)size*
sizeof(
short));
137 for (i=0; i<size; i++)
138 the_hdr.cmap[i] = 65535L - ((
long)i * 65535L)/(size - 1);
141 case PHOTOMETRIC_MINISBLACK:
144 if ( planarconfig == PLANARCONFIG_SEPARATE && matteing )
149 the_hdr.cmap = (
unsigned short *)malloc((
unsigned)size*
sizeof(
short));
150 for (i=0; i<size; i++)
154 case PHOTOMETRIC_RGB:
155 if (planarconfig != PLANARCONFIG_CONTIG)
156 error(
"can't handle separate planar config");
163 case PHOTOMETRIC_PALETTE:
165 unsigned short *red, *green, *blue;
169 if ( planarconfig == PLANARCONFIG_SEPARATE && matteing )
171 if (TIFFGetField(
tif, TIFFTAG_COLORMAP, &red, &green, &blue)) {
176 (3*size*
sizeof(
short)) );
177 for (i=0; i<size; i++) {
182 }
else error(
"TIFFGetField TIFFTAG_COLORMAP failed!");
186 error(
"tiff file PhotoMetric Interpretation not recognized");
205 tiffbuf = (
unsigned char*)malloc((
unsigned)TIFFScanlineSize(
tif));
206 if (!
tiffbuf) error(
"can't allocate tiff scanline buffer");
228 error(
"can't allocate a scan buffer");
233 error(
"can't allocate a scan buffer");
243 error(
"can't allocate scan buffer");
248 error(
"can't allocate scan buffer");
269 pix = bitconvert[(tiffbuf[k] >> shift) & mask];
270 if ( --phase == 0
) {
271 phase = 8
/ bitspersample;
272 shift = 8
- bitspersample;
276 shift -= bitspersample;
FILE * rle_open_f(char *prog_name, char *file_name, char *mode)
#define RLE_SET_BIT(glob, bit)
void rle_names(rle_hdr *the_hdr, const char *pgmname, const char *fname, int img_num)
static rle_pixel ** scan_red
char * cmd_name(char **argv)
void main(int argc, char **argv)
unsigned short samplesperpixel
static rle_pixel ** scan_blue
int scanargs(int argc, char **argv, const char *format,...)
static rle_pixel ** scan_green
void rle_putrow(rows, int rowlen, rle_hdr *the_hdr)
void rle_addhist(argv, rle_hdr *in_hdr, rle_hdr *out_hdr)
unsigned short bitspersample
void rle_put_setup(rle_hdr *the_hdr)
unsigned char bitconvert[16]
rle_hdr * rle_hdr_init(rle_hdr *the_hdr)