Utah Raster Toolkit  9999-git
URT Development version (post-3.1b)
rlesetbg.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  * rlesetbg.c - set the background color (based on repos)
20  *
21  * Author: John W. Peterson & Rod Bogart
22  * Computer Science Dept.
23  * University of Utah
24  * Date: Sat Jun 21 1986
25  * Copyright (c) 1986, University of Utah
26  *
27  */
28 #ifndef lint
29 static char rcs_ident[] = "$Id: rlesetbg.c,v 3.0.1.1 1992/01/23 20:44:32 spencer Exp $";
30 #endif
31 
32 #include <stdio.h>
33 #include "rle.h"
34 
35 char buffer[4096];
36 
37 void
39 int argc;
40 char *argv[];
41 {
42  int *new_back = NULL, nback = 0;
43  int overlay_flag = 0, backcolor_flag = 0, oflag = 0;
44  rle_hdr in_hdr, out_hdr;
45  char * fname = NULL, *out_fname = NULL;
46  FILE *outfile = stdout;
47  int rle_cnt, rle_err;
48 
49  in_hdr = *rle_hdr_init( NULL );
50  out_hdr = *rle_hdr_init( NULL );
51 
52  if (scanargs(argc, argv,
53  "% DO%- c%-bgcolor!*d o%-outfile!s infile%s",
54  &overlay_flag, &backcolor_flag,
55  &nback, &new_back,
56  &oflag, &out_fname, &fname ) == 0)
57  {
58  exit(-1);
59  }
60  if (overlay_flag == 2 && backcolor_flag)
61  {
62  fprintf(stderr, "%s: Delete or new color, but not both\n",
63  cmd_name( argv ));
64  exit(-1);
65  }
66  in_hdr.rle_file = rle_open_f(cmd_name( argv ), fname, "r");
67  rle_names( &in_hdr, cmd_name( argv ), fname, 0 );
68  rle_names( &out_hdr, in_hdr.cmd, out_fname, 0 );
69 
70  for ( rle_cnt = 0;
71  (rle_err = rle_get_setup( &in_hdr )) == RLE_SUCCESS;
72  rle_cnt++ )
73  {
74  if ( backcolor_flag && nback < in_hdr.ncolors )
75  {
76  fprintf( stderr, "Need %d colors, only %d supplied.\n",
77  in_hdr.ncolors, nback );
78  exit(-1);
79  }
80  (void)rle_hdr_cp( &in_hdr, &out_hdr );
81  if ( rle_cnt == 0 )
82  outfile = rle_open_f( cmd_name( argv ), out_fname, "w" );
83  out_hdr.rle_file = outfile;
84 
85  rle_addhist( argv, &in_hdr, &out_hdr );
86 
87  out_hdr.background = 2 - overlay_flag;
88  if ( backcolor_flag != 0 )
89  out_hdr.bg_color = new_back;
90 
91  rle_put_setup( &out_hdr );
92 
93  rle_cp( &in_hdr, &out_hdr );
94  }
95 
96  /* Check for an error. EOF or EMPTY is ok if at least one image
97  * has been read. Otherwise, print an error message.
98  */
99  if ( rle_cnt == 0 || (rle_err != RLE_EOF && rle_err != RLE_EMPTY) )
100  rle_get_error( rle_err, cmd_name( argv ), fname );
101 
102  exit( 0 );
103 }
FILE * rle_open_f(char *prog_name, char *file_name, char *mode)
Definition: rle_open_f.c:216
rle_hdr * rle_hdr_cp(rle_hdr *from_hdr, rle_hdr *to_hdr)
Definition: rle_hdr.c:119
void rle_cp(rle_hdr *in_hdr, rle_hdr *the_hdr)
Definition: rle_cp.c:69
void rle_names(rle_hdr *the_hdr, const char *pgmname, const char *fname, int img_num)
Definition: rle_hdr.c:48
#define RLE_EMPTY
Definition: rle.h:73
char * cmd_name(char **argv)
Definition: cmd_name.c:31
char buffer[4096]
Definition: rlesetbg.c:35
void main(int argc, char **argv)
Definition: aliastorle.c:121
int rle_get_setup(rle_hdr *the_hdr)
Definition: rle_getrow.c:74
int * bg_color
Definition: rle.h:100
#define RLE_SUCCESS
Definition: rle.h:70
int rle_get_error(int code, const char *pgmname, const char *fname)
Definition: rle_error.c:76
int scanargs(int argc, char **argv, const char *format,...)
Definition: scanargs.c:94
const char * cmd
Definition: rle.h:133
#define RLE_EOF
Definition: rle.h:74
void rle_addhist(argv, rle_hdr *in_hdr, rle_hdr *out_hdr)
Definition: rle_addhist.c:54
int background
Definition: rle.h:100
void rle_put_setup(rle_hdr *the_hdr)
Definition: rle_putrow.c:453
static char rcs_ident[]
Definition: rlesetbg.c:29
rle_hdr * rle_hdr_init(rle_hdr *the_hdr)
Definition: rle_hdr.c:267
FILE * rle_file
Definition: rle.h:114
int ncolors
Definition: rle.h:100