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

Go to the source code of this file.

Functions

void main (int argc, argv)
 

Function Documentation

void main ( int  argc,
argv   
)

Definition at line 33 of file rlebg.c.

36 {
38  rle_op backrundata[4], *rows[4];
39  char * outfilename = NULL;
40  static int numrundata[4] = { 1, 1, 1, 1};
41  float top_inten = 1.0 , bot_inten = 0.1, delta = 0;
42  unsigned char a, r, g, b;
43  int no_alpha_given;
44  float scale, inten;
45  int linear_ramp = 0;
46  int i, j, alpha = -1, red, green, blue;
47  int oflag = 0, sizeflag = 0, xsize = 512, ysize = 480, vbackflag = 0;
48 
49  if ( scanargs( argc, argv,
50  "% s%-xsize!dysize!d l%- v%-top%fbottom%f o%-outfile!s \n\
51  red!d green!d blue!d alpha%d",
52  &sizeflag, &xsize, &ysize, &linear_ramp, &vbackflag,
53  &top_inten, &bot_inten, &oflag, &outfilename,
54  &red, &green, &blue, &alpha ) == 0 )
55  {
56  exit(-1);
57  }
58 
59  the_hdr = *rle_hdr_init( (rle_hdr *)NULL );
60  rle_names( &the_hdr, cmd_name( argv ), outfilename, 0 );
61 
62  the_hdr.rle_file = rle_open_f(the_hdr.cmd, outfilename, "w");
63  rle_addhist( argv, (rle_hdr *)0, &the_hdr );
64 
65  if ((top_inten < 0.0) || (top_inten > 1.0) || (bot_inten < 0.0) ||
66  (bot_inten > 1.0))
67  {
68  fprintf(stderr,"background: -v bounds must be 0.0 to 1.0");
69  exit(-1);
70  }
71 
72  if (no_alpha_given = (alpha == -1))
73  alpha = 255;
74 
75  for (i=0; i < 4; i++)
76  {
77  backrundata[i].opcode = RRunDataOp;
78  backrundata[i].xloc = 0;
79  backrundata[i].length = xsize;
80  }
81  /* Initialize scanline */
82  if (!vbackflag)
83  {
84  backrundata[0].u.run_val = alpha;
85  backrundata[1].u.run_val = red;
86  backrundata[2].u.run_val = green;
87  backrundata[3].u.run_val = blue;
88  }
89  else
90  delta = (top_inten - bot_inten) / ysize;
91 
92  for(i=0; i < 4; i++)
93  rows[i] = &(backrundata[i]);
94 
95  RLE_SET_BIT(the_hdr, RLE_ALPHA);
96 
97  the_hdr.xmax = xsize - 1;
98  the_hdr.ymax = ysize - 1;
99  the_hdr.alpha = 1;
100  rle_put_setup( &the_hdr );
101 
102  a = alpha;
103  scale = (top_inten - bot_inten) / (ysize * ysize);
104  inten = bot_inten;
105  for (j = 0; j < ysize; j++)
106  {
107  if (vbackflag)
108  {
109  if (linear_ramp)
110  inten += delta;
111  else
112  {
113  if (top_inten > bot_inten)
114  inten = scale * (float) (j * j) + bot_inten;
115  else
116  inten = top_inten - (scale * (float)
117  ((ysize - j) * (ysize - j)));
118  }
119  if (!no_alpha_given)
120  /* Cast to int to get around HP compiler bug. */
121  a = (int) ((float)alpha * inten);
122  /* Cast to int to get around HP compiler bug. */
123  r = (int) ((float)red * inten);
124  g = (int) ((float)green * inten);
125  b = (int) ((float)blue * inten);
126  backrundata[0].u.run_val = a;
127  backrundata[1].u.run_val = r;
128  backrundata[2].u.run_val = g;
129  backrundata[3].u.run_val = b;
130  }
131  rle_putraw( &rows[1], &numrundata[1], &the_hdr );
132  }
133  rle_puteof( &the_hdr );
134  exit( 0 );
135 }
rle_hdr the_hdr
Definition: aliastorle.c:100
static unsigned char g
Definition: getami.c:692
#define RLE_SET_BIT(glob, bit)
Definition: rle.h:122
#define RRunDataOp
Definition: rle_code.h:41
int scanargs(int argc, char **argv, const char *format,...)
Definition: scanargs.c:94
static unsigned char blue[256]
Definition: rastorle.c:71
int length
Definition: rle_raw.h:51
int opcode
Definition: rle_raw.h:49
static unsigned char r
Definition: getami.c:692
int sizeflag
Definition: get4d.c:41
void rle_addhist(char *argv[], rle_hdr *in_hdr, rle_hdr *out_hdr)
int xsize
Definition: read98721.c:58
void rle_puteof(rle_hdr *the_hdr)
Definition: rle_putrow.c:474
int run_val
Definition: rle_raw.h:54
static unsigned char b
Definition: getami.c:692
void rle_names(rle_hdr *the_hdr, const char *pgmname, const char *fname, int img_num)
int xloc
Definition: rle_raw.h:50
const char * cmd
Definition: rle.h:133
Definition: rle.h:96
void rle_putraw()
int xmax
Definition: rle.h:100
static unsigned char green[256]
Definition: rastorle.c:71
rle_pixel ** rows
Definition: rletopaint.c:57
int
Definition: getami.c:848
int ymax
Definition: rle.h:100
int ysize
Definition: read98721.c:59
int i
Definition: rletorla.c:82
int alpha
Definition: rle.h:100
#define RLE_ALPHA
Definition: rle.h:65
FILE * rle_open_f(const char *prog_name, const char *f_name, const char *mode)
union rle_op::@7 u
void rle_put_setup(rle_hdr *the_hdr)
Definition: rle_putrow.c:453
char * cmd_name(char **argv)
Definition: cmd_name.c:31
static unsigned char red[256]
Definition: rastorle.c:71
int oflag
Definition: painttorle.c:45
Definition: rle_raw.h:47
FILE * rle_file
Definition: rle.h:114
rle_hdr * rle_hdr_init(rle_hdr *the_hdr)
Definition: rle_hdr.c:267