Utah Raster Toolkit  9999-git
URT Development version (post-3.1b)
rlebg.c
Go to the documentation of this file.
1 /*
2  * This software is copyrighted as noted below. It may be freely copied,
3  * modified, and redistributed, provided that the copyright notice is
4  * preserved on all copies.
5  *
6  * There is no warranty or other guarantee of fitness for this software,
7  * it is provided solely "as is". Bug reports or fixes may be sent
8  * to the author, who may or may not act on them as he desires.
9  *
10  * You may not include this software in a program or other software product
11  * without supplying the source, or without informing the end-user that the
12  * source is available for no extra charge.
13  *
14  * If you modify this software, you should include a notice giving the
15  * name of the person performing the modification, the date of modification,
16  * and the reason for such modification.
17  */
18 /*
19  * background.c - Create a background frame of any color/alpha
20  *
21  * Author: Rod Bogart & John W. Peterson
22  * Computer Science Dept.
23  * University of Utah
24  * Date: Tue Jun 24 1986
25  * Copyright (c) 1986, University of Utah
26  *
27  */
28 #include <stdio.h>
29 #include "rle.h"
30 #include "rle_raw.h"
31 
32 void
34 int argc;
35 char *argv[];
36 {
37  rle_hdr the_hdr;
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 }
FILE * rle_open_f(char *prog_name, char *file_name, char *mode)
Definition: rle_open_f.c:216
#define RLE_SET_BIT(glob, bit)
Definition: rle.h:122
#define RRunDataOp
Definition: rle_code.h:41
int length
Definition: rle_raw.h:51
void rle_names(rle_hdr *the_hdr, const char *pgmname, const char *fname, int img_num)
Definition: rle_hdr.c:48
int opcode
Definition: rle_raw.h:49
char * cmd_name(char **argv)
Definition: cmd_name.c:31
void main(int argc, char **argv)
Definition: aliastorle.c:121
void rle_putraw(rle_op **scanraw, int *nraw, rle_hdr *the_hdr)
Definition: rle_putraw.c:60
int scanargs(int argc, char **argv, const char *format,...)
Definition: scanargs.c:94
int xloc
Definition: rle_raw.h:50
const char * cmd
Definition: rle.h:133
void rle_puteof(rle_hdr *the_hdr)
Definition: rle_putrow.c:474
int xmax
Definition: rle.h:100
void rle_addhist(argv, rle_hdr *in_hdr, rle_hdr *out_hdr)
Definition: rle_addhist.c:54
int ymax
Definition: rle.h:100
void rle_put_setup(rle_hdr *the_hdr)
Definition: rle_putrow.c:453
int alpha
Definition: rle.h:100
#define RLE_ALPHA
Definition: rle.h:65
rle_hdr * rle_hdr_init(rle_hdr *the_hdr)
Definition: rle_hdr.c:267
FILE * rle_file
Definition: rle.h:114