28 static char rcsid[] =
"$Header: /tmp_mnt/n/itn/hendrix/u/spencer/RCS/rleldmap.c,v 3.0.1.5 1992/02/28 22:12:27 spencer Exp spencer $";
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];
152 FILE *outfile = stdout;
154 rle_hdr in_hdr, out_hdr, rle_f_hdr;
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",
211 range = (1 << bits) - 1;
240 bzero( &in_hdr,
sizeof in_hdr );
251 ilength = (1 << ilbits);
253 atoi(c) > 0 && atoi(c) < ilength )
256 if ( ! ( nchan == 1 || ichan == 1 ||
260 "%s: Nchan (%d) and input color map (%d channels) are not compatible\n",
264 ochan = (nchan > ichan) ? nchan : ichan;
287 amap
, nchan
, length
, bits
,
298 bcopy( amap[0], omap[0], nchan * length *
sizeof(
rle_map) );
310 out_hdr
.cmap = omap[0];
311 if ( olength != 1 << olbits )
313 sprintf( map_comment,
"color_map_length=%d", olength );
390 for ( i = 1; i < nchan; i++ )
391 map[i] = &map[i-1][length];
415 int nchan, length, bits;
424 for ( i = nchan * length, e = map[0]; i > 0; i--, e++ )
465 register int subshift;
466 int c, i, ochan = ((nchan > subchan) ? nchan : subchan);
470 for ( i = 1; i < length; i *= 2 )
472 if ( (1 << subbits) > i )
473 for ( subshift = 0; (1 << (subbits + subshift)) > i; subshift-- )
476 for ( subshift = 0; (1 << (subbits + subshift)) < i; subshift++ )
481 for ( c = ochan, mp = map, sp = submap, op = omap;
483 c--, op++, (nchan > 1 ? mp++ : 0), (subchan > 1 ? sp++ : 0) )
484 for ( i = sublen, s = *sp, o = *op; i > 0; i--, s++, o++ )
485 if ( (sub = (*s) << subshift) > length )
492 subshift = -subshift;
493 for ( c = ochan, mp = map, sp = submap, op = omap;
495 c--, op++, (nchan > 1 ? mp++ : 0), (subchan > 1 ? sp++ : 0) )
496 for ( i = sublen, s = *sp, o = *op; i > 0; i--, s++, o++ )
497 if ( (sub = (*s) >> subshift) > length )
526 int nchan, length, range;
530 double l = length - 1, m;
532 for ( i = 0; i < length; i++ )
534 m = range * ((
double)i / l) * factor;
544 amap[0][i] = (
rle_map)(0.5 + m);
547 for ( i = 1; i < nchan; i++ )
548 bcopy( (
char *)amap[0], (
char *)amap[i],
571 int nchan, length, range;
575 double l = length - 1;
578 for ( i = 0; i < length; i++ )
579 amap[0][i] = (
rle_map)(0.5 + range * pow( (
double)i / l,
582 for ( i = 1; i < nchan; i++ )
583 bcopy( (
char *)amap[0], (
char *)amap[i],
618 for ( c = 0; c < nchan; c++ )
619 for ( i = 0; i < length; i++ )
620 switch ( fscanf( mapfile,
"%d", &ent ) )
624 "rleldmap: Premature end of file reading map %s at channel %d, entry %d\n",
633 "rleldmap: Bad data in map %s at channel %d, entry %d\n",
639 "rleldmap: Error reading map %s at channel %d, entry %d\n",
645 for ( i = 0; i < length; i++ )
646 for ( c = 0; c < nchan; c++ )
647 switch ( fscanf( mapfile,
"%d", &ent ) )
651 "rleldmap: Premature end of file reading map %s at entry %d, channel %d\n",
660 "rleldmap: Bad data in map %s at entry %d, channel %d\n",
666 "rleldmap: Error reading map %s at entry %d, channel %d: ",
672 if ( mapfile != stdin )
702 for ( c = 0; c < nchan; c++, mfnames++ )
706 for ( i = 0; i < length; i++ )
707 switch ( fscanf( mapfile,
"%d", &ent ) )
711 "rleldmap: Premature end of file reading map %s at channel %d, entry %d\n",
720 "rleldmap: Bad data in map %s at channel %d, entry %d\n",
726 "rleldmap: Error reading map %s at channel %d, entry %d: ",
732 if ( mapfile != stdin )
763 "rleldmap: Can't read setup information from %s\n", fname );
769 fprintf( stderr,
"rleldmap: No color map in %s\n", fname );
773 if ( infile != stdin )
FILE * rle_open_f(char *prog_name, char *file_name, char *mode)
rle_hdr * rle_hdr_cp(rle_hdr *from_hdr, rle_hdr *to_hdr)
void rle_cp(rle_hdr *in_hdr, rle_hdr *the_hdr)
void rle_names(rle_hdr *the_hdr, const char *pgmname, const char *fname, int img_num)
char * cmd_name(char **argv)
void main(int argc, char **argv)
int rle_get_setup(rle_hdr *the_hdr)
int rle_get_error(int code, const char *pgmname, const char *fname)
int scanargs(int argc, char **argv, const char *format,...)
void mfilemap(char **mfnames, int nchan, int length, rle_map **amap)
const char * rle_delcom(char *name, the_hdr) const
void rle_addhist(argv, rle_hdr *in_hdr, rle_hdr *out_hdr)
char * rle_getcom(char *name, rle_hdr *the_hdr) const
void shiftmap(rle_map **map, int nchan, int length, int bits)
void linmap(double factor, int nchan, int length, int range, rle_map **amap)
void rle_put_setup(rle_hdr *the_hdr)
const char * rle_putcom(char *value, rle_hdr *the_hdr) const
void gammap(double gamma, int nchan, int length, int range, rle_map **amap)
void filemap(int tflag, char *mapfname, int nchan, int length, rle_map **amap)
void get_rle_map(rle_hdr *the_hdr, char *fname)
void applymap(rle_map **map, int nchan, int length, int bits, rle_map **submap, int subchan, int sublen, int subbits, rle_map **omap)
rle_map ** allocmap(int nchan, int length, rle_map *cmap)
rle_hdr * rle_hdr_init(rle_hdr *the_hdr)
#define RLE_CHECK_ALLOC(pgm, ptr, name)