143 int apply = 0, nflag = 0,
nchan = 3, length = 256, range, lbits,
144 sflag = 0, bits = 8, lflag = 0, gflag = 0,
145 tflag = 0, mflag = 0, rflag = 0,
oflag = 0, nmfiles = 0;
146 int ichan, ilength, ilbits;
147 int ochan, olength, olbits;
148 double factor = 1.0,
gamma = 1.0;
149 char * mapfname = NULL, ** mfnames = NULL, * rlefname = NULL,
150 * outputfname = NULL, * inputfname = NULL;
151 char map_comment[30];
155 int rle_cnt, rle_err;
162 "% ab%- n%-nchan!dlength!d s%-bits!d l%-factor%F g%-gamma!F \n\
163 \ttf%-file!s m%-files!*s r%-rlefile!s o%-outputfile!s inputfile%s",
164 &apply, &nflag, &
nchan, &length, &sflag, &bits,
165 &lflag, &factor, &gflag, &
gamma,
166 &tflag, &mapfname, &mflag, &nmfiles, &mfnames,
167 &rflag, &rlefname, &
oflag, &outputfname,
172 if ( (lflag != 0) + (gflag != 0) + (tflag != 0) + (mflag != 0) +
176 "%s: Must specify exactly one of -l -g -t -f -m -r\n",
186 "%s: Nchan, length and bits ignored, values from rle file used\n",
199 for ( lbits = 0; length > 1<<lbits; lbits++ )
201 if ( length != 1 << lbits )
204 "%s: Length (%d) rounded up to power of 2 (%d)\n",
205 cmd_name( argv ), length, 1 << lbits );
211 range = (1 << bits) - 1;
240 bzero( &in_hdr,
sizeof in_hdr );
244 if ( in_hdr.
ncmap == 0 )
251 ilength = (1 << ilbits);
252 if ( (c =
rle_getcom(
"color_map_length", &in_hdr )) &&
253 atoi(c) > 0 && atoi(c) < ilength )
255 ichan = in_hdr.
ncmap;
256 if ( ! (
nchan == 1 || ichan == 1 ||
260 "%s: Nchan (%d) and input color map (%d channels) are not compatible\n",
282 omap =
allocmap( ochan, olength, NULL );
287 amap,
nchan, length, bits,
291 imap, in_hdr.
ncmap, ilength, 16,
298 bcopy( amap[0], omap[0],
nchan * length *
sizeof(
rle_map) );
302 shiftmap( omap, ochan, olength, bits );
308 out_hdr.
ncmap = ochan;
310 out_hdr.
cmap = omap[0];
311 if ( olength != 1 << olbits )
313 sprintf( map_comment,
"color_map_length=%d", olength );
328 rle_cp( &in_hdr, &out_hdr );
int scanargs(int argc, char **argv, const char *format,...)
char * rle_getcom(const char *name, rle_hdr *the_hdr)
const char * rle_delcom(const char *name, rle_hdr *the_hdr)
const char * rle_putcom(const char *value, rle_hdr *the_hdr)
void rle_cp(rle_hdr *in_hdr, rle_hdr *out_hdr)
void rle_addhist(char *argv[], rle_hdr *in_hdr, rle_hdr *out_hdr)
void rle_names(rle_hdr *the_hdr, const char *pgmname, const char *fname, int img_num)
int rle_get_setup(rle_hdr *the_hdr)
int rle_get_error(int code, const char *pgmname, const char *fname)
int gamma(int x, float gamma_value)
rle_hdr * rle_hdr_cp(rle_hdr *from_hdr, rle_hdr *to_hdr)
FILE * rle_open_f(const char *prog_name, const char *f_name, const char *mode)
rle_map ** allocmap(int nchan, int length, rle_map *cmap)
void rle_put_setup(rle_hdr *the_hdr)
char * cmd_name(char **argv)
rle_hdr * rle_hdr_init(rle_hdr *the_hdr)