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

Go to the source code of this file.

Data Structures

struct  was_head
 
struct  was_op
 

Functions

void main (int argc, char **argv)
 
FILE * open_with_ext (char *basename, char *ext)
 

Variables

struct was_head was_head
 
short rlemap [3][256]
 
rle_pixel rgb [3]
 
struct was_op was_op
 

Function Documentation

void main ( int  argc,
char **  argv 
)

Definition at line 54 of file wasatchrle.c.

57 {
58  FILE *open_with_ext();
59  int oflag = 0;
60  char *out_name = NULL;
61  rle_hdr hdr;
62  char *was_basename;
63  FILE *lut_file, *rlc_file; /* Wasatch input files */
64  rle_pixel **row;
65  rle_pixel *pxlptr;
66  int i, xpos;
67 
68  if (scanargs( argc, argv, "% o%-outfile!s basename!s",
69  &oflag, &out_name, &was_basename ) == 0)
70  exit(-1);
71 
72  /* Initialize header. */
73  hdr = *rle_hdr_init( (rle_hdr *)NULL );
74  rle_names( &hdr, cmd_name( argv ), out_name, 0 );
75 
76  lut_file = open_with_ext( was_basename, ".lut" );
77  rlc_file = open_with_ext( was_basename, ".rlc" );
78 
79  hdr.rle_file = rle_open_f( hdr.cmd, out_name, "w" );
80 
81  fread( &was_head, sizeof( was_head ), 1, rlc_file );
82 
83  /*
84  * The spec provided by Wasatch is not clear on the meaning or any
85  * intended order of the "viewport corners". Also, look out for
86  * BYTE SWAPPING.
87  */
88  hdr.xmin = was_head.x1;
89  hdr.ymin = was_head.y1;
90  hdr.xmax = was_head.x2;
91  hdr.ymax = was_head.y2;
92 
93  hdr.ncolors = 1;
94  hdr.alpha = 0; /* What a shame... */
95  for (i = 1; i < hdr.ncolors; i++)
96  RLE_CLR_BIT( hdr, i );
97  hdr.ncmap = 3;
98  hdr.cmaplen = 8; /* == 256 entries */
99  hdr.cmap = (rle_map *) rlemap;
100 
101  /* Grab the map. */
102 
103  for (i = 0; i < 256; i++)
104  {
105  fread( rgb, sizeof( rgb ), 1, lut_file );
106  rlemap[RLE_RED][i] = ( (int)rgb[RLE_RED] ) << 8;
107  rlemap[RLE_GREEN][i] = ( (int)rgb[RLE_GREEN] ) << 8;
108  rlemap[RLE_BLUE][i] = ( (int)rgb[RLE_BLUE] ) << 8;
109  }
110 
111  rle_addhist( argv, (rle_hdr *)NULL, &hdr );
112  rle_put_setup( &hdr );
113  hdr.xmax -= hdr.xmin;
114  hdr.xmin = 0;
115 
116  if (rle_row_alloc( &hdr, &row ))
117  {
118  fprintf( stderr, "wasacthrle: malloc failed\n" );
119  exit(-2);
120  }
121 
122  xpos = 0;
123  pxlptr = row[0];
124  was_op.count = 0; /* Haven't read anything yet. */
125 
126  do {
127  while (was_op.count--)
128  {
129  if (xpos > hdr.xmax) /* Flush scanline */
130  {
131  rle_putrow( row, (hdr.xmax + 1), &hdr );
132  xpos = 0;
133  pxlptr = row[0];
134  }
135  *pxlptr++ = was_op.data;
136  xpos++;
137  }
138  fread( &was_op, sizeof( was_op ), 1, rlc_file );
139  } while( was_op.count );
140 
141  if (xpos)
142  rle_putrow( row, (hdr.xmax + 1), &hdr );
143  rle_puteof( &hdr );
144  exit(0);
145 }
rle_pixel count
Definition: wasatchrle.c:50
int xmin
Definition: rle.h:100
int scanargs(int argc, char **argv, const char *format,...)
Definition: scanargs.c:94
short y2
Definition: wasatchrle.c:40
rle_pixel rgb[3]
Definition: wasatchrle.c:47
int rle_row_alloc(rle_hdr *the_hdr, rle_pixel ***scanp)
Definition: rle_row_alc.c:56
rle_map * cmap
Definition: rle.h:112
void rle_putrow(rle_pixel *rows[], int rowlen, rle_hdr *the_hdr)
#define RLE_GREEN
Definition: rle.h:63
void rle_addhist(char *argv[], rle_hdr *in_hdr, rle_hdr *out_hdr)
rle_hdr hdr
Definition: iristorle.c:35
int ymin
Definition: rle.h:100
#define RLE_BLUE
Definition: rle.h:64
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
#define RLE_RED
Definition: rle.h:62
int xmax
Definition: rle.h:100
short rlemap[3][256]
Definition: wasatchrle.c:46
int
Definition: getami.c:848
#define RLE_CLR_BIT(glob, bit)
Definition: rle.h:124
int ncmap
Definition: rle.h:100
int ymax
Definition: rle.h:100
unsigned char rle_pixel
Definition: rle.h:56
int cmaplen
Definition: rle.h:100
rle_pixel data
Definition: wasatchrle.c:50
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)
short x1
Definition: wasatchrle.c:39
FILE * open_with_ext(char *basename, char *ext)
Definition: wasatchrle.c:156
short y1
Definition: wasatchrle.c:39
void rle_put_setup(rle_hdr *the_hdr)
Definition: rle_putrow.c:453
unsigned short rle_map
Definition: rle.h:57
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
int ncolors
Definition: rle.h:100
rle_hdr * rle_hdr_init(rle_hdr *the_hdr)
Definition: rle_hdr.c:267
short x2
Definition: wasatchrle.c:40
FILE* open_with_ext ( char *  basename,
char *  ext 
)

Definition at line 156 of file wasatchrle.c.

159 {
160  char file_name[255];
161  char ext_name[10];
162  char * cptr;
163  FILE * f;
164 
165  strcpy( ext_name, ext );
166  strcpy( file_name, basename );
167  strcat( file_name, ext_name );
168 
169  if (! (f = fopen( file_name, "r" )))
170  {
171  if (errno == ENOENT) /* Not found, try upper case */
172  {
173  strcpy( file_name, basename );
174  cptr = ext_name;
175  for (; *cptr; cptr++ )
176  *cptr = toupper( *cptr );
177  strcat( file_name, ext_name );
178  f = fopen( file_name, "r" );
179  }
180  }
181 
182  if (! f) /* fopen failed */
183  {
184  perror( file_name );
185  exit( -1 );
186  }
187  return( f );
188 }
static Panel_item file_name
Definition: gettaac.c:59

Variable Documentation

rle_pixel rgb[3]

Definition at line 47 of file wasatchrle.c.

short rlemap[3][256]

Definition at line 46 of file wasatchrle.c.

struct was_op was_op