Utah Raster Toolkit  9999-git
URT Development version (post-3.1b)
rleldmap.c
Go to the documentation of this file.
1 /*
2  * This software is copyrighted as noted below. It may be freely copied,
3  * modified, and redistributed, provided that the copyright notice is
4  * preserved on all copies.
5  *
6  * There is no warranty or other guarantee of fitness for this software,
7  * it is provided solely "as is". Bug reports or fixes may be sent
8  * to the author, who may or may not act on them as he desires.
9  *
10  * You may not include this software in a program or other software product
11  * without supplying the source, or without informing the end-user that the
12  * source is available for no extra charge.
13  *
14  * If you modify this software, you should include a notice giving the
15  * name of the person performing the modification, the date of modification,
16  * and the reason for such modification.
17  */
18 /*
19  * rleldmap.c - Load a color map into an RLE file.
20  *
21  * Author: Spencer W. Thomas
22  * Computer Science Dept.
23  * University of Utah
24  * Date: Thu Jul 10 1986
25  * Copyright (c) 1986, Spencer W. Thomas
26  */
27 #ifndef lint
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 $";
29 #endif
30 #if 0
31 rleldmap() /* Tag. */
32 #endif
33 
34 #include <stdio.h>
35 #include <math.h>
36 #include "rle.h"
37 
38 void get_rle_map(), linmap(), gammap(), filemap(), mfilemap();
39 void applymap(), shiftmap();
40 
41 /*****************************************************************
42  * TAG( main )
43  *
44  * Usage:
45  * rleldmap [-ab] [-n nchan length] [-s bits] [-l [factor]] [-g gamma]
46  * [-{tf} file] [-m files ...] [-r rlefile]
47  * [-o outputfile] [inputfile]
48  * Terminology:
49  * input map: A color map already in the input RLE file.
50  * applied map: The color map specified by the arguments that will
51  * be applied (loaded) to the input map, producing
52  * the output map.
53  * output map: Unless -a or -b is specified, this is equal to the
54  * applied map.
55  * map composition:The output map is applied_map[input_map] if -a
56  * (after) is specified, or input_map[applied_map]
57  * if -b (before). The maps being composed must either
58  * have the same number of channels, or one of them must
59  * have only one channel. If an entry in the map being
60  * used as a subscript is larger than the length of the
61  * map being subscripted, it remains unchanged. The
62  * output map will be the same length as the subscript
63  * map and will have the number of channels that is the
64  * larger of the two. If the input map is used
65  * as a subscript, it will be downshifted the correct
66  * number of bits to serve as a subscript for the applied
67  * map. This also applies to the applied map if it is
68  * taken from an RLE file (-r option below).
69  * nchan: Number of separate lookup tables (channels) making up
70  * the color map. Default 3 (one for red, one for
71  * green, and one for blue).
72  * length: Number of entries in each channel of the map. Default
73  * is 256 (8 bits).
74  * bits: Size of each color map entry in bits. Default
75  * log2 length.
76  * range: Maximum value of a color map entry, equal to
77  * 2^bits - 1.
78  * Inputs:
79  * -ab: Compose the applied map with the input map.
80  * If the input file has no map, this flag has no effect.
81  *
82  * -n nchan length Gives the size of the applied map if it is not 3x256.
83  * length should be a power of two and will be rounded
84  * up if necessary. If applying the map, nchan must be
85  * either 1 or equal to the number of channels in the
86  * input map.
87  *
88  * -s bits Gives the size in bits of each color map entry.
89  *
90  * Note: exactly one of -l, -g, -t, -f, -F, or -r must be specified.
91  *
92  * -l factor Generate a linear applied map with entries equal to
93  * range * max(1.0, factor*(n/(length-1))). Factor
94  * defaults to 1.0.
95  *
96  * -g gamma Generate an applied map with the given gamma. The
97  * nth entry (out of length) is
98  * range * (n/(length-1))^gamma
99  *
100  * -t file Read color map entries from a file (t for table).
101  * The values for each channel of a particular entry
102  * follow each other in the file. (Thus, for an RGB
103  * color map, the file would look like:
104  * red0 green0 blue0
105  * red1 green1 blue1
106  * ... ... ...
107  * Line breaks in the input file are irrelevant.
108  *
109  * -f file Reads the applied map from a file, with all the
110  * entries for each channel following each other. Thus,
111  * the input file would appear as
112  * red0 red1 red2 ...
113  * green0 green1 green2 ...
114  * blue0 blue1 blue2 ...
115  * As above, line breaks are irrelevant.
116  *
117  * -m files ... Read the color map for each channel from a separate
118  * file. The number of files specified must equal the
119  * number of channels in the applied map. [Note: the
120  * list of files must be followed by another flag or
121  * by the null flag -- to separate it from the inputfile.
122  *
123  * -r rlefile Read the color map from another RLE file. In this
124  * case, the nchan, length and bits arguments will be
125  * ignored.
126  *
127  * inputfile The input RLE file. Defaults to stdin.
128  * Outputs:
129  * -o outputfile The output RLE file. Defaults to stdout.
130  * Assumptions:
131  * As stated above.
132  * Algorithm:
133  * Compute the desired map, and either replace the input map with it
134  * or compose the maps as specified above. Copy the image data from
135  * the input file to the output file. If stdin is empty (no input at
136  * all, an output RLE file with just a color map will be generated).
137  */
138 void
140 int argc;
141 char **argv;
142 {
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; /* Input map parameters */
147  int ochan, olength, olbits; /* output map parameters */
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;
153  rle_map ** imap = NULL, ** omap, ** amap, ** allocmap();
154  rle_hdr in_hdr, out_hdr, rle_f_hdr;
155  int rle_cnt, rle_err;
156 
157  in_hdr = *rle_hdr_init( NULL );
158  out_hdr = *rle_hdr_init( NULL );
159  rle_f_hdr = *rle_hdr_init( NULL );
160 
161  if ( scanargs( argc, argv,
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,
168  &inputfname ) == 0 )
169  exit( 1 ); /* bad arguments */
170 
171  /* Check for exclusive flag use */
172  if ( (lflag != 0) + (gflag != 0) + (tflag != 0) + (mflag != 0) +
173  (rflag != 0) != 1 )
174  {
175  fprintf(stderr,
176  "%s: Must specify exactly one of -l -g -t -f -m -r\n",
177  cmd_name( argv ) );
178  exit(-1);
179  }
180 
181  /* Compute color map parameters */
182  if ( rflag ) /* from RLE file? */
183  {
184  if ( lflag )
185  fprintf(stderr,
186  "%s: Nchan, length and bits ignored, values from rle file used\n",
187  cmd_name( argv ));
188  rle_names( &rle_f_hdr, cmd_name( argv ), rlefname, 0 );
189  get_rle_map( &rle_f_hdr, rlefname );
190  lbits = rle_f_hdr.cmaplen;
191  length = 1 << lbits;
192  nchan = rle_f_hdr.ncmap;
193  bits = 16;
194  /* Just use the rle map */
195  amap = allocmap( length, nchan, rle_f_hdr.cmap );
196  }
197  else
198  {
199  for ( lbits = 0; length > 1<<lbits; lbits++ )
200  ; /* Get log2 of length */
201  if ( length != 1 << lbits )
202  {
203  fprintf( stderr,
204  "%s: Length (%d) rounded up to power of 2 (%d)\n",
205  cmd_name( argv ), length, 1 << lbits );
206  length = 1 << lbits; /* round length to power of 2 */
207  }
208  /* Allocate space for the applied map */
209  amap = allocmap( nchan, length, NULL );
210  }
211  range = (1 << bits) - 1;
212 
213  /* Compute the requested map */
214  if ( lflag )
215  linmap( factor, nchan, length, range, amap );
216  if ( gflag )
217  gammap( gamma, nchan, length, range, amap );
218  if ( tflag )
219  filemap( tflag, mapfname, nchan, length, amap );
220  if ( mflag )
221  mfilemap( mfnames, nchan, length, amap );
222 
223  /* Open input file and verify header */
224  in_hdr.rle_file = rle_open_f(cmd_name( argv ), inputfname, "r");
225  rle_names( &in_hdr, cmd_name( argv ), inputfname, 0 );
226  rle_names( &out_hdr, in_hdr.cmd, outputfname, 0 );
227 
228  for ( rle_cnt = 0;
229  (rle_err = rle_get_setup( &in_hdr )) == RLE_SUCCESS ||
230  rle_err == RLE_EMPTY;
231  rle_cnt++ )
232  {
233  if ( rle_err == RLE_EMPTY )
234  {
235  if ( rle_cnt == 0 )
236  apply = 0; /* can't apply to non-existant map */
237  else
238  break;
239  /* Build in_hdr for non-existant image (all zeros works fine) */
240  bzero( &in_hdr, sizeof in_hdr );
241  }
242 
243  /* If apply flag was given, check for compatibility of color maps */
244  if ( in_hdr.ncmap == 0 )
245  apply = 0; /* Can't apply to non-existent map */
246  if ( apply )
247  {
248  char *c;
249 
250  ilbits = in_hdr.cmaplen;
251  ilength = (1 << ilbits);
252  if ( (c = rle_getcom( "color_map_length", &in_hdr )) &&
253  atoi(c) > 0 && atoi(c) < ilength )
254  ilength = atoi(c);
255  ichan = in_hdr.ncmap;
256  if ( ! ( nchan == 1 || ichan == 1 ||
257  nchan == ichan ) )
258  {
259  fprintf( stderr,
260  "%s: Nchan (%d) and input color map (%d channels) are not compatible\n",
261  cmd_name( argv ), nchan, ichan );
262  exit(-1);
263  }
264  ochan = (nchan > ichan) ? nchan : ichan;
265 
266  if ( apply == 1 ) /* "before", omap[i] = imap[amap[i]] */
267  {
268  olength = length;
269  olbits = lbits;
270  }
271  else /* "after", omap[i] = amap[imap[i]] */
272  {
273  olength = ilength;
274  olbits = ilbits;
275  }
276 
277  /* Get convenient access to the input map */
278  imap = allocmap( in_hdr.ncmap, 1 << in_hdr.cmaplen,
279  in_hdr.cmap );
280 
281  /* Allocate an output map */
282  omap = allocmap( ochan, olength, NULL );
283 
284  /* And do the application */
285  if ( apply == 1 )
286  applymap( imap, in_hdr.ncmap, 1 << in_hdr.cmaplen, 16,
287  amap, nchan, length, bits,
288  omap );
289  else
290  applymap( amap, nchan, length, bits,
291  imap, in_hdr.ncmap, ilength, 16,
292  omap );
293  }
294  else
295  {
296  /* "Copy" the applied map, and left justify it */
297  omap = allocmap( nchan, length, NULL );
298  bcopy( amap[0], omap[0], nchan * length * sizeof(rle_map) );
299  olength = length;
300  olbits = lbits;
301  ochan = nchan;
302  shiftmap( omap, ochan, olength, bits );
303  }
304 
305  /* Now, open the output */
306  /* start by copying input parameters */
307  (void)rle_hdr_cp( &in_hdr, &out_hdr );
308  out_hdr.ncmap = ochan;
309  out_hdr.cmaplen = olbits;
310  out_hdr.cmap = omap[0];
311  if ( olength != 1 << olbits )
312  {
313  sprintf( map_comment, "color_map_length=%d", olength );
314  rle_putcom( map_comment, &out_hdr );
315  }
316  else
317  rle_delcom( "color_map_length", &out_hdr );
318  if ( rle_cnt == 0 )
319  outfile = rle_open_f(cmd_name( argv ), outputfname, "w");
320  out_hdr.rle_file = outfile;
321 
322  rle_addhist( argv, &in_hdr, &out_hdr );
323 
324  rle_put_setup( &out_hdr );
325 
326  /* Copy the rest of the input to the output */
327  if ( rle_err != RLE_EMPTY )
328  rle_cp( &in_hdr, &out_hdr );
329 
330  /* Free temp storage. */
331  free( omap[0] );
332  free( omap );
333  out_hdr.cmap = 0; /* Don't try to free it again? */
334  if ( apply )
335  {
336  free( imap );
337  }
338  if ( rle_err == RLE_EMPTY )
339  {
340  rle_err = RLE_SUCCESS;
341  break;
342  }
343  }
344 
345  /* Check for an error. EOF or EMPTY is ok if at least one image
346  * has been read. Otherwise, print an error message.
347  */
348  if ( rle_cnt == 0 || (rle_err != RLE_EOF && rle_err != RLE_EMPTY) )
349  rle_get_error( rle_err, cmd_name( argv ), inputfname );
350 
351  exit( 0 );
352 }
353 
354 
355 /*****************************************************************
356  * TAG( allocmap )
357  *
358  * Allocate a color map of a given size.
359  * Inputs:
360  * nchan: Number of channels in the map.
361  * length: Length of each channel of the map.
362  * cmap: If non-null, the storage to be used.
363  * Outputs:
364  * Returns a pointer to an array[nchan] of pointers to
365  * array[length] of rle_map. The rle_map array can also
366  * be addressed contiguously as return[0][chan*length+i].
367  * Assumptions:
368  * If cmap is supplied, it is an array of nchan*length rle_maps.
369  * Algorithm:
370  * [None]
371  */
372 rle_map **
374 int nchan;
375 int length;
376 rle_map * cmap;
377 {
378  rle_map ** map;
379  register int i;
380 
381  map = (rle_map **)malloc( nchan * sizeof( rle_map * ) );
382  RLE_CHECK_ALLOC( "rleldmap", map, "color map" );
383  if ( cmap == NULL )
384  {
385  map[0] = (rle_map *)malloc( nchan * length * sizeof( rle_map ) );
386  RLE_CHECK_ALLOC( "rleldmap", map[0], "color map" );
387  }
388  else
389  map[0] = cmap;
390  for ( i = 1; i < nchan; i++ )
391  map[i] = &map[i-1][length];
392  return map;
393 }
394 
395 /*****************************************************************
396  * TAG( shiftmap )
397  *
398  * Shift the entries in the color map to left justify them.
399  * Inputs:
400  * map: The color map.
401  * nchan: Number of color channels in the map.
402  * length: Number of entries in each channel.
403  * bits: Number of bits in each entry.
404  * Outputs:
405  * map: Left justified map (modified in place).
406  * Assumptions:
407  * map[0] points to a contiguous array of nchan*length rle_maps
408  * (as set up by allocmap).
409  * Algorithm:
410  * [None]
411  */
412 void
414 rle_map **map;
415 int nchan, length, bits;
416 {
417  register rle_map * e;
418  register int i;
419 
420  bits = 16 - bits;
421  if ( bits == 0 )
422  return; /* no work! */
423 
424  for ( i = nchan * length, e = map[0]; i > 0; i--, e++ )
425  *e <<= bits;
426 }
427 
428 /*****************************************************************
429  * TAG( applymap )
430  *
431  * Compose two maps: map[submap].
432  * Inputs:
433  * map: Map being "applied".
434  * nchan: Number of channels in map.
435  * length: Length of each channel in map.
436  * bits: Number of bits used in each entry of map.
437  * submap: Map used as subscript.
438  * subchan: Number of channels in submap.
439  * sublen: Length of submap.
440  * subbits: Number of bits used in each entry of submap.
441  * Outputs:
442  * omap: Result map.
443  * Omap has max(nchan,subchan) channels, and
444  * sublen entries.
445  * Assumptions:
446  * Yeah.
447  * Algorithm:
448  * Basically, assign omap[c][i] = map[c][submap[c][i]]. If map has
449  * only one channel, get omap[c][i] = map[0][submap[c][i]], and if
450  * submap has only one channel, get omap[c][i] = map[c][submap[0][i]].
451  * Extra complications include shifting submap by the right number of
452  * bits so that it will index the full range of map, and left-justifying
453  * the output map.
454  */
455 void
458 rle_map **submap;
459 rle_map **map;
460 rle_map **omap;
461 {
462  register rle_map * s; /* pointer into submap */
463  register rle_map * o; /* pointer into omap */
464  rle_map ** mp, ** sp, ** op; /* pointer to channel of maps */
465  register int subshift;
466  int c, i, ochan = ((nchan > subchan) ? nchan : subchan);
467  int sub;
468 
469  /* Figure out how much to shift subscript */
470  for ( i = 1; i < length; i *= 2 )
471  ; /* Round up to power of 2. */
472  if ( (1 << subbits) > i ) /* Too many bits in subscript? */
473  for ( subshift = 0; (1 << (subbits + subshift)) > i; subshift-- )
474  ;
475  else /* not enough bits */
476  for ( subshift = 0; (1 << (subbits + subshift)) < i; subshift++ )
477  ;
478 
479  if ( subshift >= 0 )
480  {
481  for ( c = ochan, mp = map, sp = submap, op = omap;
482  c > 0;
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 )
486  *o = 0;
487  else
488  *o = (*mp)[sub];
489  }
490  else
491  {
492  subshift = -subshift;
493  for ( c = ochan, mp = map, sp = submap, op = omap;
494  c > 0;
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 )
498  *o = 0;
499  else
500  *o = (*mp)[sub];
501  }
502 
503  shiftmap( omap, ochan, sublen, bits );
504 }
505 
506 
507 /*****************************************************************
508  * TAG( linmap )
509  *
510  * Build a linear map.
511  * Inputs:
512  * factor: Linear factor to multiply map entries by.
513  * nchan: Number of color channels.
514  * length: Length of each channel.
515  * range: Range of elements of the map.
516  * Outputs:
517  * amap: Result map.
518  * Assumptions:
519  * [None]
520  * Algorithm:
521  * [None]
522  */
523 void
525 double factor;
526 int nchan, length, range;
527 rle_map **amap;
528 {
529  register int i;
530  double l = length - 1, m;
531 
532  for ( i = 0; i < length; i++ )
533  {
534  m = range * ((double)i / l) * factor;
535  if ( factor < 0 )
536  {
537  m = range + m;
538  if ( m < 0 )
539  m = 0;
540  }
541  else
542  if ( m > range )
543  m = range;
544  amap[0][i] = (rle_map)(0.5 + m);
545  }
546 
547  for ( i = 1; i < nchan; i++ )
548  bcopy( (char *)amap[0], (char *)amap[i],
549  length * sizeof(rle_map) );
550 }
551 
552 /*****************************************************************
553  * TAG( gammap )
554  *
555  * Build a gamma compensation map.
556  * Inputs:
557  * gamma: Gamma exponent.
558  * nchan: Number of color channels.
559  * length: Length of each channel.
560  * range: Range of elements of the map.
561  * Outputs:
562  * amap: Result map.
563  * Assumptions:
564  * [None]
565  * Algorithm:
566  * [None]
567  */
568 void
570 double gamma;
571 int nchan, length, range;
572 rle_map **amap;
573 {
574  register int i;
575  double l = length - 1;
576 
577  gamma = 1.0 / gamma;
578  for ( i = 0; i < length; i++ )
579  amap[0][i] = (rle_map)(0.5 + range * pow( (double)i / l,
580  gamma ));
581 
582  for ( i = 1; i < nchan; i++ )
583  bcopy( (char *)amap[0], (char *)amap[i],
584  length * sizeof(rle_map) );
585 }
586 
587 /*****************************************************************
588  * TAG( filemap )
589  *
590  * Read a color map from a file
591  * Inputs:
592  * tflag: Flag for type of file: 1 means all entries for a
593  * channel are together (-f), 2 means all entries for
594  * a given index are together (-t).
595  * mapfname: Name of file to read map from.
596  * nchan: Number of color channels.
597  * length: Length of each channel.
598  * Outputs:
599  * amap: Result map.
600  * Assumptions:
601  * [None]
602  * Algorithm:
603  * [None]
604  */
605 void
607 int tflag, nchan, length;
608 char *mapfname;
609 rle_map **amap;
610 {
611  FILE * mapfile;
612  register int c, i;
613  int ent;
614 
615  mapfile = rle_open_f( "rleldmap", mapfname, "r" );
616 
617  if ( tflag == 1 ) /* channel-major order */
618  for ( c = 0; c < nchan; c++ )
619  for ( i = 0; i < length; i++ )
620  switch ( fscanf( mapfile, "%d", &ent ) )
621  {
622  case EOF: /* EOF */
623  fprintf( stderr,
624  "rleldmap: Premature end of file reading map %s at channel %d, entry %d\n",
625  mapfname, c, i );
626  exit(-1);
627  /* NOTREACHED */
628  case 1: /* Got it */
629  amap[c][i] = ent;
630  break;
631  case 0: /* no conversion? */
632  fprintf( stderr,
633  "rleldmap: Bad data in map %s at channel %d, entry %d\n",
634  mapfname, c, i );
635  exit(-1);
636  /* NOTREACHED */
637  default: /* error */
638  fprintf( stderr,
639  "rleldmap: Error reading map %s at channel %d, entry %d\n",
640  mapfname, c, i );
641  exit(-1);
642  /* NOTREACHED */
643  }
644  else /* Entry-major order */
645  for ( i = 0; i < length; i++ )
646  for ( c = 0; c < nchan; c++ )
647  switch ( fscanf( mapfile, "%d", &ent ) )
648  {
649  case EOF: /* EOF */
650  fprintf( stderr,
651  "rleldmap: Premature end of file reading map %s at entry %d, channel %d\n",
652  mapfname, i, c );
653  exit(-1);
654  /* NOTREACHED */
655  case 1: /* Got it */
656  amap[c][i] = ent;
657  break;
658  case 0: /* no conversion? */
659  fprintf( stderr,
660  "rleldmap: Bad data in map %s at entry %d, channel %d\n",
661  mapfname, i, c );
662  exit(-1);
663  /* NOTREACHED */
664  default: /* error */
665  fprintf( stderr,
666  "rleldmap: Error reading map %s at entry %d, channel %d: ",
667  mapfname, i, c );
668  perror("");
669  exit(-1);
670  /* NOTREACHED */
671  }
672  if ( mapfile != stdin )
673  fclose( mapfile );
674 }
675 
676 /*****************************************************************
677  * TAG( mfilemap )
678  *
679  * Read a color map from a multiple files
680  * Inputs:
681  * mfnames: Name of files to read map from. Each file contains
682  * the entries for a single channel of the map.
683  * nchan: Number of color channels (thus number of files).
684  * length: Length of each channel.
685  * Outputs:
686  * amap: Result map.
687  * Assumptions:
688  * [None]
689  * Algorithm:
690  * [None]
691  */
692 void
694 char **mfnames;
695 int nchan, length;
696 rle_map **amap;
697 {
698  FILE * mapfile;
699  register int c, i;
700  int ent;
701 
702  for ( c = 0; c < nchan; c++, mfnames++ )
703  {
704  mapfile = rle_open_f( "rleldmap", *mfnames, "r" );
705 
706  for ( i = 0; i < length; i++ )
707  switch ( fscanf( mapfile, "%d", &ent ) )
708  {
709  case EOF: /* EOF */
710  fprintf( stderr,
711  "rleldmap: Premature end of file reading map %s at channel %d, entry %d\n",
712  *mfnames, c, i );
713  exit(-1);
714  /* NOTREACHED */
715  case 1: /* Got it */
716  amap[c][i] = ent;
717  break;
718  case 0: /* no conversion? */
719  fprintf( stderr,
720  "rleldmap: Bad data in map %s at channel %d, entry %d\n",
721  *mfnames, c, i );
722  exit(-1);
723  /* NOTREACHED */
724  default: /* error */
725  fprintf( stderr,
726  "rleldmap: Error reading map %s at channel %d, entry %d: ",
727  *mfnames, c, i );
728  perror("");
729  exit(-1);
730  /* NOTREACHED */
731  }
732  if ( mapfile != stdin )
733  fclose( mapfile );
734  }
735 }
736 
737 /*****************************************************************
738  * TAG( get_rle_map )
739  *
740  * Read the map from an RLE file.
741  * Inputs:
742  * fname: Name of file to read map from.
743  * Outputs:
744  * the_hdr: RLE header struct to fill in.
745  * Assumptions:
746  * [None]
747  * Algorithm:
748  * [None]
749  */
750 void
752 rle_hdr *the_hdr;
753 char *fname;
754 {
755  FILE * infile;
756 
757  infile = rle_open_f( "rleldmap", fname, "r" );
758 
759  the_hdr->rle_file = infile;
760  if ( rle_get_setup( the_hdr ) < 0 )
761  {
762  fprintf( stderr,
763  "rleldmap: Can't read setup information from %s\n", fname );
764  exit(-1);
765  }
766 
767  if ( the_hdr->ncmap == 0 )
768  {
769  fprintf( stderr, "rleldmap: No color map in %s\n", fname );
770  exit(-1);
771  }
772 
773  if ( infile != stdin )
774  fclose( infile );
775 }
FILE * rle_open_f(char *prog_name, char *file_name, char *mode)
Definition: rle_open_f.c:216
rle_hdr * rle_hdr_cp(rle_hdr *from_hdr, rle_hdr *to_hdr)
Definition: rle_hdr.c:119
void rle_cp(rle_hdr *in_hdr, rle_hdr *the_hdr)
Definition: rle_cp.c:69
void rle_names(rle_hdr *the_hdr, const char *pgmname, const char *fname, int img_num)
Definition: rle_hdr.c:48
#define RLE_EMPTY
Definition: rle.h:73
char * cmd_name(char **argv)
Definition: cmd_name.c:31
void main(int argc, char **argv)
Definition: aliastorle.c:121
int rle_get_setup(rle_hdr *the_hdr)
Definition: rle_getrow.c:74
rle_map * cmap
Definition: rle.h:112
#define RLE_SUCCESS
Definition: rle.h:70
int rle_get_error(int code, const char *pgmname, const char *fname)
Definition: rle_error.c:76
int scanargs(int argc, char **argv, const char *format,...)
Definition: scanargs.c:94
static char rcsid[]
Definition: rleldmap.c:28
const char * cmd
Definition: rle.h:133
void mfilemap(char **mfnames, int nchan, int length, rle_map **amap)
Definition: rleldmap.c:693
const char * rle_delcom(char *name, the_hdr) const
Definition: rle_putcom.c:140
#define RLE_EOF
Definition: rle.h:74
void rle_addhist(argv, rle_hdr *in_hdr, rle_hdr *out_hdr)
Definition: rle_addhist.c:54
char * rle_getcom(char *name, rle_hdr *the_hdr) const
Definition: rle_getcom.c:81
void shiftmap(rle_map **map, int nchan, int length, int bits)
Definition: rleldmap.c:413
void linmap(double factor, int nchan, int length, int range, rle_map **amap)
Definition: rleldmap.c:524
int ncmap
Definition: rle.h:100
void rle_put_setup(rle_hdr *the_hdr)
Definition: rle_putrow.c:453
const char * rle_putcom(char *value, rle_hdr *the_hdr) const
Definition: rle_putcom.c:82
int cmaplen
Definition: rle.h:100
void gammap(double gamma, int nchan, int length, int range, rle_map **amap)
Definition: rleldmap.c:569
void filemap(int tflag, char *mapfname, int nchan, int length, rle_map **amap)
Definition: rleldmap.c:606
void get_rle_map(rle_hdr *the_hdr, char *fname)
Definition: rleldmap.c:751
void applymap(rle_map **map, int nchan, int length, int bits, rle_map **submap, int subchan, int sublen, int subbits, rle_map **omap)
Definition: rleldmap.c:456
rle_map ** allocmap(int nchan, int length, rle_map *cmap)
Definition: rleldmap.c:373
unsigned short rle_map
Definition: rle.h:57
rle_hdr * rle_hdr_init(rle_hdr *the_hdr)
Definition: rle_hdr.c:267
FILE * rle_file
Definition: rle.h:114
#define RLE_CHECK_ALLOC(pgm, ptr, name)
Definition: rle.h:86