Utah Raster Toolkit  9999-git
URT Development version (post-3.1b)
repos.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  * repos.c - Reposition RLE image.
20  *
21  * Author: Rod Bogart & John W. Peterson
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[] = "$Header: /software/dmsv/sun4/sunos/SWT-BACKUP/spencer/src/urt/tools/tools/RCS/repos.c,v 3.0.1.1 1992/01/23 16:26:39 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 xlen, ylen, xpos, ypos, posflag=0;
43  int oflag = 0, incflag=0, xinc, yinc;
44  char * infilename = NULL, *out_fname = NULL;
45  FILE *outfile = stdout;
46  rle_hdr in_hdr, out_hdr;
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  "% p%-xpos!dypos!d P%-xinc!dyinc!d o%-outfile!s infile%s",
54  &posflag, &xpos, &ypos, &incflag, &xinc, &yinc,
55  &oflag, &out_fname, &infilename) == 0)
56  {
57  exit(-1);
58  }
59 
60  in_hdr.rle_file = rle_open_f( cmd_name( argv ), infilename, "r" );
61  rle_names( &in_hdr, cmd_name( argv ), infilename, 0 );
62  rle_names( &out_hdr, in_hdr.cmd, out_fname, 0 );
63 
64  for ( rle_cnt = 0;
65  (rle_err = rle_get_setup( &in_hdr )) == RLE_SUCCESS;
66  rle_cnt++ )
67  {
68  (void)rle_hdr_cp( &in_hdr, &out_hdr );
69  if ( rle_cnt == 0 )
70  outfile = rle_open_f( cmd_name( argv ), out_fname, "w" );
71  out_hdr.rle_file = outfile;
72  rle_addhist( argv, &in_hdr, &out_hdr );
73 
74  xlen = in_hdr.xmax - in_hdr.xmin;
75  ylen = in_hdr.ymax - in_hdr.ymin;
76 
77  if (posflag)
78  {
79  out_hdr.xmin = xpos;
80  out_hdr.ymin = ypos;
81  out_hdr.xmax = xpos + xlen;
82  out_hdr.ymax = ypos + ylen;
83  }
84  else if (incflag)
85  {
86  out_hdr.xmin = in_hdr.xmin + xinc;
87  out_hdr.ymin = in_hdr.ymin + yinc;
88  out_hdr.xmax = in_hdr.xmax + xinc;
89  out_hdr.ymax = in_hdr.ymax + yinc;
90  }
91  else
92  {
93  /* nothing specified on command line, assume -p 0 0 */
94  out_hdr.xmin = 0;
95  out_hdr.ymin = 0;
96  out_hdr.xmax = xlen;
97  out_hdr.ymax = ylen;
98  }
99 
100  if ((out_hdr.xmin < 0) || (out_hdr.ymin < 0))
101  {
102  fprintf(stderr, "Negative boundaries are not allowed!!!\n");
103  exit( -1 );
104  }
105 
106  rle_put_setup( &out_hdr );
107 
108  rle_cp( &in_hdr, &out_hdr );
109  }
110 
111  /* Check for an error. EOF or EMPTY is ok if at least one image
112  * has been read. Otherwise, print an error message.
113  */
114  if ( rle_cnt == 0 || (rle_err != RLE_EOF && rle_err != RLE_EMPTY) )
115  rle_get_error( rle_err, cmd_name( argv ), infilename );
116 
117  exit( 0 );
118 }
FILE * rle_open_f(char *prog_name, char *file_name, char *mode)
Definition: rle_open_f.c:216
int xmin
Definition: rle.h:100
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
#define RLE_SUCCESS
Definition: rle.h:70
int ymin
Definition: rle.h:100
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
static char rcs_ident[]
Definition: repos.c:29
int xmax
Definition: rle.h:100
#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 ymax
Definition: rle.h:100
void rle_put_setup(rle_hdr *the_hdr)
Definition: rle_putrow.c:453
rle_hdr * rle_hdr_init(rle_hdr *the_hdr)
Definition: rle_hdr.c:267
FILE * rle_file
Definition: rle.h:114