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

Go to the source code of this file.

Functions

void main (int argc, char **argv)
 

Variables

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

Function Documentation

void main ( int  argc,
char **  argv 
)

Definition at line 55 of file rlegrid.c.

58 {
59  char *outfname = NULL;
60  int oflag = 0, sflag=0, wflag=0, fflag=0, bflag=0, cflag=0;
61  int xsize=512, ysize=512, width=16, fg_color=255, bg_color=0;
62  int x,y,i;
63  FILE *outfile;
65  rle_op **scanraw[2]; /* space for two raw scanline buffers */
66  rle_op *p, *q;
67  int *nrawp[2];
68  unsigned char fg, bg;
69 
70  out_hdr = *rle_hdr_init( NULL );
71 
72  if ( scanargs( argc, argv,
73  "% o%-outfile!s s%-xsize!dysize!d w%-width!d f%-fg_color!d b%-bg_color!d c%-",
74  &oflag, &outfname,
75  &sflag, &xsize, &ysize,
76  &wflag, &width,
77  &fflag, &fg_color,
78  &bflag, &bg_color,
79  &cflag )
80  == 0 )
81  exit( 1 );
82 
83  fg = fg_color;
84  bg = bg_color;
85 
86  outfile = rle_open_f( cmd_name( argv ), outfname, "w" );
87 
88  /* Set up the output header.
89  */
90  (void)rle_hdr_init( &out_hdr );
91  rle_names( &out_hdr, cmd_name( argv ), outfname, 0 );
92  out_hdr.rle_file = outfile;
93  out_hdr.xmax = xsize -1;
94  out_hdr.ymax = ysize -1;
95  out_hdr.ncolors = 1;
96  out_hdr.alpha = 0;
97 
98 
99  /* Add to the history comment. */
100  rle_addhist( argv, (rle_hdr *)0, &out_hdr );
101 
102  /* Write the output image header. */
103  rle_put_setup( &out_hdr );
104 
105 
106  /* Allocate memory into which the image scanlines can be read.
107  */
108  if ( rle_raw_alloc( &out_hdr, scanraw+0, nrawp+0 ) < 0 ||
109  rle_raw_alloc( &out_hdr, scanraw+1, nrawp+1 ) < 0 )
110  RLE_CHECK_ALLOC( cmd_name( argv ), 0, "image memory" );
111 
112  /* Fill the scan lines */
113  if (cflag)
114  {
115  /* checkerboard option */
116  p = scanraw[0][0];
117  q = scanraw[1][0];
118  *nrawp[0] = *nrawp[1] = 0;
119  for(x=0; x<xsize;x+=2*width)
120  {
121  p->opcode = RRunDataOp;
122  p->xloc = x;
123  p->length = width;
124  *q = *p;
125  p->u.run_val = fg_color;
126  q->u.run_val = bg_color;
127  (*nrawp[0])++; (*nrawp[1])++;
128 
129  p++; q++;
130  p->opcode = RRunDataOp;
131  p->xloc = x+width;
132  p->length = (x+width < xsize) ? width : (xsize-x);
133  *q = *p;
134  p->u.run_val = bg_color;
135  q->u.run_val = fg_color;
136  (*nrawp[0])++; (*nrawp[1])++;
137  p++; q++;
138  }
139  }
140  else
141  { /* default: grid */
142 
143  p = scanraw[0][0];
144  p->opcode = RRunDataOp;
145  p->xloc = 0;
146  p->length = xsize;
147  p->u.run_val = fg_color;
148  *nrawp[0] = 1;
149 
150  /* grided scanline */
151  p = scanraw[1][0];
152  *nrawp[1] = 0;
153  for(x=0; x<xsize;x+=width)
154  {
155  p->opcode = RByteDataOp;
156  p->xloc = x;
157  p->length = 1;
158  p->u.pixels = (rle_pixel *) &fg;
159  (*nrawp[1])++;
160 
161  p++;
162  p->opcode = RRunDataOp;
163  p->xloc = x+1;
164  p->length = (x+width < xsize) ? width-1 : (xsize-x);
165  p->u.run_val = bg_color;
166  (*nrawp[1])++;
167  p++;
168  }
169  }
170 
171  /* write the output file */
172  for ( y = 0; y < ysize; y++ )
173  {
174  i = (cflag) ? ((y/width) %2) : ((y %width) != 0);
175  rle_putraw( scanraw[i], nrawp[i], &out_hdr );
176  }
177 
178  /* Free memory. */
179  rle_raw_free( &out_hdr, scanraw[0], nrawp[0] );
180  rle_raw_free( &out_hdr, scanraw[1], nrawp[1] );
181 
182  /* Write an end-of-image code. */
183  rle_puteof( &out_hdr );
184 
185  exit( 0 );
186 }
#define RRunDataOp
Definition: rle_code.h:41
int scanargs(int argc, char **argv, const char *format,...)
Definition: scanargs.c:94
FILE * outfile
Definition: giftorle.c:61
int length
Definition: rle_raw.h:51
int opcode
Definition: rle_raw.h:49
int rle_raw_alloc()
int width
Definition: pgmtorle.c:51
void rle_addhist(char *argv[], rle_hdr *in_hdr, rle_hdr *out_hdr)
void rle_raw_free()
int xsize
Definition: read98721.c:58
void rle_puteof(rle_hdr *the_hdr)
Definition: rle_putrow.c:474
static int y
Definition: getami.c:691
int run_val
Definition: rle_raw.h:54
void rle_names(rle_hdr *the_hdr, const char *pgmname, const char *fname, int img_num)
static int bg_color[3]
Definition: rle_global.c:64
int xloc
Definition: rle_raw.h:50
Definition: rle.h:96
#define sflag
void rle_putraw()
int xmax
Definition: rle.h:100
static int x
Definition: getami.c:691
int ymax
Definition: rle.h:100
int ysize
Definition: read98721.c:59
rle_pixel * pixels
Definition: rle_raw.h:53
unsigned char rle_pixel
Definition: rle.h:56
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)
union rle_op::@7 u
int cflag
Definition: getgmr.c:19
void rle_put_setup(rle_hdr *the_hdr)
Definition: rle_putrow.c:453
char * cmd_name(char **argv)
Definition: cmd_name.c:31
int oflag
Definition: painttorle.c:45
Definition: rle_raw.h:47
FILE * rle_file
Definition: rle.h:114
rle_hdr out_hdr
Definition: dvirle2.c:89
int ncolors
Definition: rle.h:100
#define RByteDataOp
Definition: rle_code.h:40
#define RLE_CHECK_ALLOC(pgm, ptr, name)
Definition: rle.h:86
rle_hdr * rle_hdr_init(rle_hdr *the_hdr)
Definition: rle_hdr.c:267

Variable Documentation

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

Definition at line 28 of file rlegrid.c.