Utah Raster Toolkit  9999-git
URT Development version (post-3.1b)
Macros | Functions | Variables
rlehdr.c File Reference
#include <stdio.h>
#include <stdint.h>
#include "rle.h"
#include "../patchlevel.h"
Include dependency graph for rlehdr.c:

Go to the source code of this file.

Macros

#define URT_VERSION   3.0
 

Functions

void print_hdr ()
 
void print_map ()
 
void print_codes ()
 
void print_brief_hdr ()
 
void main (int argc, char **argv)
 
void print_hdr (rle_hdr *the_hdr)
 
void print_brief_hdr (rle_hdr *the_hdr, int ncomment, char **comment_names)
 
void print_map (rle_hdr *the_hdr, int mflag)
 
void print_codes (rle_hdr *the_hdr)
 

Variables

char rcsid [] = "$Header: /l/spencer/src/urt/tools/RCS/rlehdr.c,v 3.0.1.4 1992/04/30 14:12:09 spencer Exp $"
 

Macro Definition Documentation

#define URT_VERSION   3.0

Definition at line 40 of file rlehdr.c.

Function Documentation

void main ( int  argc,
char **  argv 
)

Definition at line 70 of file rlehdr.c.

73 {
74  CONST_DECL char ** fname = NULL;
75  CONST_DECL char *stdname = "-";
76  char **comment_names = NULL;
77  int brief = 0,
78  cflag = 0,
79  hflag = 0,
80  num_hdr = 1,
81  mflag = 0,
82  suppress = 0,
83  dbg_flag = 0,
84  nfname = 0,
85  version = 0;
86  int rle_err = 0, rle_cnt;
88 
89  in_hdr = *rle_hdr_init( NULL );
90 
91  if ( scanargs( argc, argv,
92  "% b%- c%-comment-name!,s h%-n%d Mm%- s%- d%- v%- infile%*s (\n\
93 \t-b\tBrief mode, one line per image.\n\
94 \t-c\tWith -b, print 1st line of 1st comment matching a name.\n\
95 \t-h [n]\tPrint only first (n) header(s) in each file.\n\
96 \t-m\tPrint contents of colormap.\n\
97 \t-M\tPrint colormap suitable for rleldmap -t.\n\
98 \t-s\tSuppress printing header at all (useful with -M).\n\
99 \t-d\tPrint image data (LOTS of output)\n\
100 \t-v\tPrint URT version number. Ignores other arguments.)",
101  &brief, &cflag, &cflag, &comment_names,
102  &hflag, &num_hdr, &mflag, &suppress, &dbg_flag, &version,
103  &nfname, &fname ) == 0 )
104  exit( 1 );
105 
106  /* If -c was specified, set -b. */
107  if ( cflag )
108  brief = 1;
109 
110  if ( nfname == 0 )
111  {
112  nfname = 1;
113  fname = &stdname;
114  }
115 
116  if ( version )
117  {
118  printf( "Utah Raster Toolkit version %3.1f", URT_VERSION );
119 #if PATCHLEVEL > 0
120  printf( "(patch %d)", PATCHLEVEL );
121 #endif
122  putchar( '\n' );
123  exit( 0 );
124  }
125 
126  for ( ; nfname > 0; fname++, nfname-- )
127  {
128  in_hdr.rle_file = rle_open_f(cmd_name( argv ), *fname, "r");
129  rle_names( &in_hdr, cmd_name( argv ), *fname, 0 );
130 
131  for ( rle_cnt = 0;
132  !(hflag && rle_cnt >= num_hdr) &&
133  (rle_err = rle_get_setup( &in_hdr )) == RLE_SUCCESS;
134  rle_cnt++ )
135  {
136  /* Separate headers with a newline. */
137  if ( !brief && rle_cnt > 0 )
138  putchar( '\n' );
139 
140  if ( !suppress )
141  if ( brief )
142  print_brief_hdr( &in_hdr, cflag, comment_names );
143  else
144  print_hdr( &in_hdr );
145  if ( mflag )
146  print_map( &in_hdr, mflag );
147  if ( dbg_flag )
148  print_codes( &in_hdr );
149  else if ( !hflag || rle_cnt + 1 < num_hdr )
150  while ( rle_getskip( &in_hdr ) != 32768 )
151  ;
152  }
153 
154  /* Separate headers with a newline. */
155  if ( !brief && nfname > 1 )
156  putchar( '\n' );
157 
158  fclose( in_hdr.rle_file );
159 
160  /* Check for an error. EOF or EMPTY is ok if at least one image
161  * has been read. Otherwise, print an error message.
162  */
163  if ( rle_cnt == 0 || (rle_err != RLE_EOF && rle_err != RLE_EMPTY) )
164  rle_get_error( rle_err, cmd_name( argv ), *fname );
165  }
166 
167  exit( 0 ); /* success */
168 }
gpr_ $version_t version
Definition: getap.c:106
void print_codes()
#define URT_VERSION
Definition: rlehdr.c:40
int scanargs(int argc, char **argv, const char *format,...)
Definition: scanargs.c:94
static rle_hdr in_hdr
Definition: rletogif.c:37
#define RLE_EMPTY
Definition: rle.h:73
void print_brief_hdr()
void print_map()
#define RLE_SUCCESS
Definition: rle.h:70
char * fname[3]
Definition: show3.c:31
void rle_names(rle_hdr *the_hdr, const char *pgmname, const char *fname, int img_num)
int rle_get_setup(rle_hdr *the_hdr)
Definition: rle_getrow.c:74
Definition: rle.h:96
int rle_get_error(int code, const char *pgmname, const char *fname)
unsigned int rle_getskip(rle_hdr *the_hdr)
Definition: rle_getskip.c:57
#define RLE_EOF
Definition: rle.h:74
#define CONST_DECL
Definition: rle_config.h:42
void print_hdr()
FILE * rle_open_f(const char *prog_name, const char *f_name, const char *mode)
int cflag
Definition: getgmr.c:19
char * cmd_name(char **argv)
Definition: cmd_name.c:31
FILE * rle_file
Definition: rle.h:114
rle_hdr * rle_hdr_init(rle_hdr *the_hdr)
Definition: rle_hdr.c:267
void print_brief_hdr ( )
void print_brief_hdr ( rle_hdr the_hdr,
int  ncomment,
char **  comment_names 
)

Definition at line 247 of file rlehdr.c.

251 {
252  register int i;
253 
254  if ( the_hdr->img_num > 1 )
255  printf( "%s(%d):",
256  the_hdr->file_name, the_hdr->img_num );
257  else
258  printf( "%s:", the_hdr->file_name );
259  printf( "\t[%d,%d]+[%d,%d]",
260  the_hdr->xmin, the_hdr->ymin,
261  the_hdr->xmax - the_hdr->xmin + 1,
262  the_hdr->ymax - the_hdr->ymin + 1 );
263  printf( "x%d%s", the_hdr->ncolors,
264  the_hdr->alpha ? "+A" : "" );
265  if ( the_hdr->background == 0 )
266  ;
267  else
268  {
269  if ( the_hdr->background == 1 )
270  printf( ", OV=" );
271  else
272  printf( ", BG=" );
273  for ( i = 0; i < the_hdr->ncolors; i++ )
274  printf( "%d%s", the_hdr->bg_color[i],
275  i == the_hdr->ncolors - 1 ? " " : "," );
276  }
277 
278  if ( the_hdr->ncmap > 0 )
279  printf( ", map %dx%d",
280  the_hdr->ncmap, 1 << the_hdr->cmaplen );
281 
282  if ( the_hdr->comments != NULL && *the_hdr->comments != NULL )
283  {
284  char *the_comment, *cp;
285 
286  if ( ncomment > 0 )
287  {
288  for ( ; ncomment > 0; ncomment--, comment_names++ )
289  if (the_comment = rle_getcom( *comment_names, the_hdr ))
290  {
291  if ( (cp = index( the_comment, '\n' )) )
292  printf( ", %s=%.*s", *comment_names,
293  cp - the_comment - 1, the_comment );
294  else
295  printf( ", %s=%s", *comment_names, the_comment );
296  break;
297  }
298  }
299  if ( ncomment == 0 )
300  printf( ", (C)" );
301  }
302 
303  putchar( '\n' );
304 
305  fflush( stdout );
306 }
int xmin
Definition: rle.h:100
const char ** comments
Definition: rle.h:113
char * rle_getcom(const char *name, rle_hdr *the_hdr)
int * bg_color
Definition: rle.h:100
int ymin
Definition: rle.h:100
int xmax
Definition: rle.h:100
int img_num
Definition: rle.h:135
#define index
Definition: rle_config.h:96
int background
Definition: rle.h:100
int ncmap
Definition: rle.h:100
int ymax
Definition: rle.h:100
int cmaplen
Definition: rle.h:100
int i
Definition: rletorla.c:82
int alpha
Definition: rle.h:100
const char * file_name
Definition: rle.h:134
int ncolors
Definition: rle.h:100
void print_codes ( )
void print_codes ( rle_hdr the_hdr)

Definition at line 383 of file rlehdr.c.

385 {
386  rle_pixel ** scans;
387 
388  if ( rle_row_alloc( the_hdr, &scans ) < 0 )
389  RLE_CHECK_ALLOC( "rlehdr", 0, 0 );
390 
391  rle_debug(1);
392  while ( !feof( the_hdr->rle_file ) &&
393  !the_hdr->priv.get.is_eof )
394  rle_getrow( the_hdr, scans );
395 
396  rle_row_free( the_hdr, scans );
397 }
void rle_row_free(rle_hdr *the_hdr, rle_pixel **scanp)
Definition: rle_row_alc.c:114
int rle_row_alloc(rle_hdr *the_hdr, rle_pixel ***scanp)
Definition: rle_row_alc.c:56
struct rle_hdr::@0::@1 get
union rle_hdr::@0 priv
void rle_debug(int on_off)
Definition: rle_getrow.c:293
unsigned char rle_pixel
Definition: rle.h:56
int rle_getrow(rle_hdr *the_hdr, rle_pixel *scanline[])
FILE * rle_file
Definition: rle.h:114
#define RLE_CHECK_ALLOC(pgm, ptr, name)
Definition: rle.h:86
void print_hdr ( )
void print_hdr ( rle_hdr the_hdr)

Definition at line 186 of file rlehdr.c.

188 {
189  register int i;
190 
191  if ( the_hdr->img_num > 1 )
192  printf( "RLE header information for %s image %d:\n",
193  the_hdr->file_name, the_hdr->img_num );
194  else
195  printf( "RLE header information for %s:\n", the_hdr->file_name );
196  printf( "Originally positioned at (%d, %d), size (%d, %d)\n",
197  the_hdr->xmin, the_hdr->ymin,
198  the_hdr->xmax - the_hdr->xmin + 1,
199  the_hdr->ymax - the_hdr->ymin + 1 );
200  printf( "Saved %d color channels%s\n", the_hdr->ncolors,
201  the_hdr->alpha ? " plus Alpha channel" : "" );
202  if ( the_hdr->background == 0 )
203  printf( "No background information was saved\n" );
204  else
205  {
206  if ( the_hdr->background == 1 )
207  printf( "Saved in overlay mode with original background color" );
208  else
209  printf( "Screen will be cleared to background color" );
210  for ( i = 0; i < the_hdr->ncolors; i++ )
211  printf( " %d", the_hdr->bg_color[i] );
212  putchar( '\n' );
213  }
214 
215  if ( the_hdr->ncmap > 0 )
216  printf( "%d channels of color map %d entries long were saved.\n",
217  the_hdr->ncmap, 1 << the_hdr->cmaplen );
218 
219  if ( the_hdr->comments != NULL && *the_hdr->comments != NULL )
220  {
221  printf( "Comments:\n" );
222  for ( i = 0; the_hdr->comments[i] != NULL; i++ )
223  printf( "%s\n", the_hdr->comments[i] );
224  }
225 
226  fflush( stdout );
227 }
int xmin
Definition: rle.h:100
const char ** comments
Definition: rle.h:113
int * bg_color
Definition: rle.h:100
int ymin
Definition: rle.h:100
int xmax
Definition: rle.h:100
int img_num
Definition: rle.h:135
int background
Definition: rle.h:100
int ncmap
Definition: rle.h:100
int ymax
Definition: rle.h:100
int cmaplen
Definition: rle.h:100
int i
Definition: rletorla.c:82
int alpha
Definition: rle.h:100
const char * file_name
Definition: rle.h:134
int ncolors
Definition: rle.h:100
void print_map ( )
void print_map ( rle_hdr the_hdr,
int  mflag 
)

Definition at line 324 of file rlehdr.c.

327 {
328  register int i, j;
329  int c, maplen, ncmap, nmap;
330  rle_map * cmap;
331  char *len_com;
332 
333  if ( the_hdr->ncmap == 0 )
334  return;
335 
336  maplen = (1 << the_hdr->cmaplen);
337  ncmap = the_hdr->ncmap;
338  cmap = the_hdr->cmap;
339 
340  if ( (len_com = rle_getcom( "color_map_length", the_hdr )) != NULL &&
341  atoi( len_com ) > 0 )
342  nmap = atoi( len_com );
343  else
344  nmap = maplen;
345 
346  if ( mflag == 1 )
347  {
348  printf( "Color map contents, values are 16-bit(8-bit):\n" );
349  for ( i = 0; i < nmap; i++ )
350  {
351  printf( "%3d:\t", i );
352  for ( j = 0, c = 0; j < ncmap; j++, c += maplen )
353  printf( "%5d(%3d)%c", cmap[i+c], cmap[i+c] >> 8,
354  j == ncmap - 1 ? '\n' : '\t' );
355 
356  }
357  }
358  else
359  for ( i = 0; i < nmap; i++ )
360  {
361  for ( j = 0, c = 0; j < ncmap; j++, c += maplen )
362  printf( "%3d%c", cmap[i+c] >> 8,
363  j == ncmap - 1 ? '\n' : '\t' );
364 
365  }
366 }
char * rle_getcom(const char *name, rle_hdr *the_hdr)
int maplen
Definition: rletoppm.c:61
rle_map * cmap
Definition: rle.h:112
int ncmap
Definition: rle.h:100
int cmaplen
Definition: rle.h:100
int i
Definition: rletorla.c:82
unsigned short rle_map
Definition: rle.h:57
rle_pixel ** cmap
Definition: get4d.c:47

Variable Documentation

char rcsid[] = "$Header: /l/spencer/src/urt/tools/RCS/rlehdr.c,v 3.0.1.4 1992/04/30 14:12:09 spencer Exp $"

Definition at line 28 of file rlehdr.c.