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

Go to the source code of this file.

Typedefs

typedef FILE * FILPTR
 

Functions

void main (int argc, argv)
 

Variables

static char rcsid [] = "$Header: /l/spencer/src/urt/cnv/RCS/rletogray.c,v 3.0.1.2 1992/04/30 13:59:29 spencer Exp $"
 

Typedef Documentation

typedef FILE* FILPTR

Definition at line 35 of file rletogray.c.

Function Documentation

void main ( int  argc,
argv   
)

Definition at line 45 of file rletogray.c.

48 {
49  char *inpnam = NULL; /* Input file name. */
50  static char defpref[] = "out"; /* So it's not CONST. */
51  char *prefix = NULL; /* Output file name prefix. */
52  rle_hdr hdr;
53  int aflag = 0; /* Alpha channel flag. */
54  int oflag = 0; /* Output file name prefix flag. */
55  register char * cp, * slashp;
56  FILPTR *outfil; /* Output file pointers. */
57  char outnam[BUFSIZ]; /* Output file name. */
58  int files; /* Number of output files. */
59  int scans, rasts; /* Number of scan lines. */
60  rle_pixel **inprow; /* Input buffer. */
61  int i, row;
62 
63  if (! scanargs( argc,argv,
64  "% o%-outprefix!s infile%s", &oflag, &prefix, &inpnam ))
65  exit( -1 );
66 
67  /* Set up header and open input. */
68  /* Initialize header. */
69  hdr = *rle_hdr_init( (rle_hdr *)NULL );
70  rle_names( &hdr, cmd_name( argv ), inpnam, 0 );
71 
72  hdr.rle_file = rle_open_f(hdr.cmd, inpnam, "r");
73 
74  /* Read header information. */
75 
76  rle_get_setup_ok( &hdr, NULL, NULL );
77  if ( hdr.alpha )
78  aflag = 1;
79  scans = hdr.ymax - hdr.ymin + 1;
80  rasts = hdr.xmax - hdr.xmin + 1;
81  files = aflag + hdr.ncolors;
82 
83  /* Figure out what we want to call the output files. */
84 
85  if ( !inpnam && !oflag )
86  prefix = defpref;
87  else if ( inpnam && !oflag )
88  {
89  /* Strip ".rle" suffix from input file name */
90  /* Avoid strrchr, rindex problem */
91  for ( cp = inpnam; *cp; cp++ )
92  ; /* find end of name */
93  /* Look for last slash */
94  for ( slashp = cp - 1; *slashp != '/' && slashp > inpnam; )
95  slashp--;
96  if ( *slashp == '/' )
97  slashp++;
98  /* Look for last dot */
99  while ( *--cp != '.' && cp > inpnam )
100  ; /* find last . */
101  if ( strcmp( cp, ".rle" ) != 0 )
102  cp = inpnam + strlen( inpnam );
103  /* Make null full string buffer */
104  prefix = (char *)calloc( cp - slashp + 1, 1 );
105  /* Copy everything but suffix */
106  strncpy( prefix, inpnam, cp - slashp );
107  }
108 
109  /*
110  * Get enough file pointers for all output files that are necessary,
111  * and try to open them.
112  */
113 
114  outfil = (FILPTR *)malloc( sizeof( FILPTR ) * files );
115  for ( i = -aflag; i<files-aflag; i++ )
116  {
117  switch( i )
118  {
119  case -1:
120  sprintf( outnam, "%s.alpha", prefix );
121  break;
122 
123  case 0:
124  sprintf( outnam, "%s.red", prefix );
125  break;
126 
127  case 1:
128  sprintf( outnam, "%s.green", prefix );
129  break;
130 
131  case 2:
132  sprintf( outnam, "%s.blue", prefix );
133  break;
134 
135  default:
136  sprintf( outnam, "%s.%03d", prefix, i );
137  break;
138  }
139 
140 
141  if ( (outfil[i+aflag] = fopen( outnam, "w" )) == NULL )
142  {
143  fprintf( stderr, "%s: Can't create %s: ", hdr.cmd, outnam );
144  perror( "" );
145  exit( -1 );
146  }
147  }
148 
149  /* Allocate input buffer. */
150 
151  if (rle_row_alloc( &hdr, &inprow ))
152  {
153  fprintf(stderr, "%s: Out of memory.\n", hdr.cmd);
154  exit(-2);
155  }
156 
157  /* Read .rle file, splitting into gray files. */
158 
159  for (row=0; (row<scans); row++)
160  {
161  rle_getrow( &hdr, inprow );
162  for ( i = -aflag; i<files-aflag; i++ )
163  fwrite( inprow[i], 1, rasts, outfil[i+aflag] );
164  }
165 }
int xmin
Definition: rle.h:100
int scanargs(int argc, char **argv, const char *format,...)
Definition: scanargs.c:94
int rle_row_alloc(rle_hdr *the_hdr, rle_pixel ***scanp)
Definition: rle_row_alc.c:56
rle_hdr hdr
Definition: iristorle.c:35
int ymin
Definition: rle.h:100
void rle_names(rle_hdr *the_hdr, const char *pgmname, const char *fname, int img_num)
const char * cmd
Definition: rle.h:133
Definition: rle.h:96
int xmax
Definition: rle.h:100
int ymax
Definition: rle.h:100
unsigned char rle_pixel
Definition: rle.h:56
void * malloc()
int i
Definition: rletorla.c:82
int alpha
Definition: rle.h:100
FILE * rle_open_f(const char *prog_name, const char *f_name, const char *mode)
FILE * FILPTR
Definition: graytorle.c:31
char * cmd_name(char **argv)
Definition: cmd_name.c:31
int row
Definition: rle.c:27
int oflag
Definition: painttorle.c:45
void rle_get_setup_ok(rle_hdr *the_hdr, const char *prog_name, const char *file_name)
int rle_getrow(rle_hdr *the_hdr, rle_pixel *scanline[])
FILE * rle_file
Definition: rle.h:114
int ncolors
Definition: rle.h:100
rle_hdr * rle_hdr_init(rle_hdr *the_hdr)
Definition: rle_hdr.c:267

Variable Documentation

char rcsid[] = "$Header: /l/spencer/src/urt/cnv/RCS/rletogray.c,v 3.0.1.2 1992/04/30 13:59:29 spencer Exp $"
static

Definition at line 27 of file rletogray.c.