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

Go to the source code of this file.

Typedefs

typedef FILE * FILPTR
 

Functions

void main (int argc, argv)
 

Typedef Documentation

typedef FILE* FILPTR

Definition at line 31 of file graytorle.c.

Function Documentation

void main ( int  argc,
argv   
)

Definition at line 43 of file graytorle.c.

46 {
47  int hflag = 0; /* Header size flag */
48  int aflag = 0; /* Alpha channel flag. */
49  int stdin_used = 0;
50  char *oname = NULL; /* Output file name. */
51  FILE **inpfil; /* Input file pointers. */
52  int xsize, ysize; /* Image size. */
53  int hsize; /* Image header size. */
54  int oflag; /* Output file flag. */
55  int files; /* Number of files. */
56  char **fname; /* List of input file names. */
58  rle_pixel **outrow; /* Output buffer. */
59  int i, row;
60  char *trash;
61 
62  if (! scanargs( argc,argv,
63  "% a%- h%-hdrsize!d o%-outfile!s xsize!d ysize!d files!*s\n(\
64 \tConvert one or more raw images to an RLE image.\n\
65 \t-a\tFirst input file is alpha channel. Normally first is red.\n\
66 \t-h\tSpecify number of bytes to discard from input header.\n\
67 \txsize ysize\tSize of input images.\n\
68 \tTry rawtorle for more complex situations.)",
69  &aflag,
70  &hflag, &hsize,
71  &oflag, &oname,
72  &xsize, &ysize,
73  &files, &fname ))
74  exit( -1 );
75 
76  out_hdr = *rle_hdr_init( (rle_hdr *)NULL );
77  rle_names( &out_hdr, cmd_name( argv ), oname, 0 );
78 
79  /*
80  * Get enough file pointers for all input files that are specified,
81  * and try to open them.
82  */
83 
84  inpfil = (FILE **)malloc( sizeof( FILE * ) * files );
85  for ( i=0; i<files; i++ )
86  {
87  inpfil[i] = rle_open_f( "graytorle", fname[i], "r" );
88  if ( inpfil[i] == stdin )
89  {
90  if ( stdin_used )
91  {
92  fprintf( stderr,
93  "%s: Can't use standard input for more than one file\n",
94  out_hdr.cmd );
95  exit( -1 );
96  }
97  stdin_used++;
98  }
99  }
100 
101  /* Throw away file headers. */
102 
103  if ( hflag && (hsize > 0) )
104  {
105  trash = (char *)malloc( hsize );
106 
107  for ( i=0; i<files; i++ )
108  fread( trash, 1, hsize, inpfil[i] );
109 
110  free( trash );
111  }
112 
113  /* Adjust alpha channnel flag to use as index. */
114 
115  if ( aflag )
116  aflag = 1;
117  else
118  aflag = 0;
119 
120  /* Initialize the_hdr and allocate image row storage. */
121 
122  out_hdr.alpha = aflag;
123  out_hdr.ncolors = files - aflag;
124  out_hdr.xmax = xsize - 1;
125  out_hdr.ymax = ysize - 1;
126  out_hdr.rle_file = rle_open_f(out_hdr.cmd, oname, "w");
127  for ( i = -aflag; i<out_hdr.ncolors; i++)
128  RLE_SET_BIT( out_hdr, i );
129  rle_addhist( argv, (rle_hdr *)NULL, &out_hdr );
130  rle_put_setup( &out_hdr );
131 
132  if (rle_row_alloc( &out_hdr, &outrow ))
133  {
134  fprintf(stderr, "%s: Ran out of heap space!!\n",
135  out_hdr.cmd );
136  exit(-2);
137  }
138 
139  /* Combine rows and write to output file. Adjust for alpha. */
140 
141  for ( row=0; row<ysize; row++)
142  {
143  for ( i = -aflag; i<files-aflag; i++ )
144  fread( outrow[i], 1, xsize, inpfil[i+aflag] );
145  rle_putrow( outrow, xsize, &out_hdr );
146  }
147  rle_puteof( &out_hdr );
148 }
#define RLE_SET_BIT(glob, bit)
Definition: rle.h:122
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
void rle_putrow(rle_pixel *rows[], int rowlen, rle_hdr *the_hdr)
void rle_addhist(char *argv[], rle_hdr *in_hdr, rle_hdr *out_hdr)
int xsize
Definition: read98721.c:58
char * fname[3]
Definition: show3.c:31
void rle_puteof(rle_hdr *the_hdr)
Definition: rle_putrow.c:474
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
int ysize
Definition: read98721.c:59
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)
void rle_put_setup(rle_hdr *the_hdr)
Definition: rle_putrow.c:453
char * cmd_name(char **argv)
Definition: cmd_name.c:31
int row
Definition: rle.c:27
int oflag
Definition: painttorle.c:45
FILE * rle_file
Definition: rle.h:114
rle_hdr out_hdr
Definition: dvirle2.c:89
int ncolors
Definition: rle.h:100
rle_hdr * rle_hdr_init(rle_hdr *the_hdr)
Definition: rle_hdr.c:267