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

Go to the source code of this file.

Functions

void do_slice ()
 
void copy_scanline ()
 
void main (int argc, char **argv)
 
void do_slice (int num, char *filename)
 
void copy_scanline (int ypos, int copy_flag)
 

Variables

static char rcsid [] = "$Header: /l/spencer/src/urt/tools/RCS/unslice.c,v 3.0.1.2 1992/04/30 14:14:54 spencer Exp $"
 
rle_hdr in_hdr
 
rle_hdr out_hdr
 
rle_op ** out_raw
 
intout_nraw
 
int max_y = 0
 
int num_skip = 0
 
int ctlflag = 0
 
int ctl_lines
 
intstart_line
 
intstop_line
 
char default_ctl_file [] = "unslice.ctl"
 
char * progname
 
char ** gargv
 

Function Documentation

void copy_scanline ( )
void copy_scanline ( int  ypos,
int  copy_flag 
)

Definition at line 252 of file unslice.c.

255 {
256 
257  SKIP_ROW:
258 
259  if (num_skip > 0) /* Must skip blank rows */
260  {
261  if (copy_flag)
262  rle_skiprow( &out_hdr, 1 );
263  num_skip--;
264  if (num_skip == 0)
265  num_skip = -1; /* Flag raw data available */
266  return;
267  }
268 
269  if (num_skip == 0) /* ...Must read new data */
271  else
272  num_skip = ypos; /* num_skip < 0, data was already there */
273 
274  if (num_skip == 32768) /* Hit the EOF */
275  {
276  if (copy_flag)
277  rle_skiprow( &out_hdr, 1 );
278  return;
279  }
280 
281  num_skip -= ypos; /* Find how many blank lines left */
282 
283  if (num_skip > 0)
284  goto SKIP_ROW;
285 
286  if (copy_flag)
289 }
void rle_skiprow(rle_hdr *the_hdr, int nrow)
Definition: rle_putrow.c:393
void rle_freeraw(rle_hdr *the_hdr, scanraw, nraw)
Definition: rle_getraw.c:268
int * out_nraw
Definition: unslice.c:40
void rle_putraw()
rle_hdr out_hdr
Definition: unslice.c:34
int num_skip
Definition: unslice.c:43
rle_op ** out_raw
Definition: unslice.c:39
rle_hdr in_hdr
Definition: unslice.c:34
unsigned int rle_getraw(rle_hdr *the_hdr, scanraw, nraw)
Definition: rle_getraw.c:78
void do_slice ( )
void do_slice ( int  num,
char *  filename 
)

Definition at line 144 of file unslice.c.

147 {
148  register int y;
149  static int current_y = 0;
150 
151  in_hdr.rle_file = rle_open_f(progname, filename, "r");
152  rle_names( &in_hdr, progname, filename, 0 );
153 
154  /*
155  * Many sanity checks. Code must be 3am-proof!
156  */
157 
158  rle_get_setup_ok( &in_hdr, progname, filename );
159 
160  if (ctlflag &&
161  ((start_line[num] > in_hdr.ymax) ||
162  (stop_line[num] < in_hdr.ymin)))
163  {
164  fprintf(stderr, "%s: %s is out of slice range (%d %d)\n",
165  progname, filename, start_line[num], stop_line[num]);
166  exit(-1);
167  }
168 
169  /*
170  * If this is the first slice, generate the output header.
171  */
172 
173  if (num == 0)
174  {
175  FILE *f = out_hdr.rle_file;
176  CONST_DECL char *name = out_hdr.file_name;
177 
178  out_hdr.file_name = NULL;
179  (void)rle_hdr_cp( &in_hdr, &out_hdr );
180  out_hdr.file_name = name;
181  out_hdr.rle_file = f;
182  rle_addhist( gargv, (rle_hdr *)0, &out_hdr );
183 
184  if (ctlflag)
185  {
186  out_hdr.ymin = start_line[0];
188  }
189  else
190  {
192  out_hdr.ymax = max_y;
193  }
194  current_y = out_hdr.ymin;
196 
197  if (rle_raw_alloc( &out_hdr, &out_raw, &out_nraw ) < 0)
198  RLE_CHECK_ALLOC( progname, 0, 0 );
199  }
200 
201  if ((! ctlflag) && (in_hdr.ymax < current_y))
202  {
203  fprintf(stderr,
204  "%s: warning: slice %s completely ignored (wrong order?)\n",
205  progname, filename);
206  fclose( in_hdr.rle_file );
207  return;
208  }
209 
210  /*
211  * Copy the file to the output.
212  */
213  num_skip = 0;
214 
215  if (ctlflag)
216  {
217  for (y = in_hdr.ymin; y <= in_hdr.ymax; y++ )
218  if ((y >= start_line[num]) && (y <= stop_line[num]))
219  copy_scanline( y, 1 );
220  else
221  copy_scanline( y, 0 ); /* Data out of range, just toss it. */
222  }
223  else
224  {
225  for (y = in_hdr.ymin; y <= in_hdr.ymax; y++ )
226  if (y >= current_y)
227  copy_scanline( y, 1 );
228  else
229  copy_scanline( y, 0 );
230 
231  current_y = in_hdr.ymax + 1;
232  }
233 
234  fclose( in_hdr.rle_file );
235 }
int * start_line
Definition: unslice.c:47
int rle_raw_alloc()
int * out_nraw
Definition: unslice.c:40
void rle_addhist(char *argv[], rle_hdr *in_hdr, rle_hdr *out_hdr)
int * stop_line
Definition: unslice.c:47
void copy_scanline()
int ymin
Definition: rle.h:100
char * progname
Definition: unslice.c:51
int ctlflag
Definition: unslice.c:45
static int y
Definition: getami.c:691
void rle_names(rle_hdr *the_hdr, const char *pgmname, const char *fname, int img_num)
Definition: rle.h:96
rle_hdr out_hdr
Definition: unslice.c:34
#define CONST_DECL
Definition: rle_config.h:42
int num_skip
Definition: unslice.c:43
char ** gargv
Definition: unslice.c:52
int ctl_lines
Definition: unslice.c:46
int ymax
Definition: rle.h:100
rle_hdr * rle_hdr_cp(rle_hdr *from_hdr, rle_hdr *to_hdr)
Definition: rle_hdr.c:119
rle_op ** out_raw
Definition: unslice.c:39
FILE * rle_open_f(const char *prog_name, const char *f_name, const char *mode)
int max_y
Definition: unslice.c:42
void rle_put_setup(rle_hdr *the_hdr)
Definition: rle_putrow.c:453
rle_hdr in_hdr
Definition: unslice.c:34
const char * file_name
Definition: rle.h:134
void rle_get_setup_ok(rle_hdr *the_hdr, const char *prog_name, const char *file_name)
FILE * rle_file
Definition: rle.h:114
#define RLE_CHECK_ALLOC(pgm, ptr, name)
Definition: rle.h:86
void main ( int  argc,
char **  argv 
)

Definition at line 55 of file unslice.c.

58 {
59  int nfiles, i;
60  char **slicefiles;
61  FILE *ctlfile;
62  int y_flag, oflag = 0;
63 
64  char * ctlfilename = NULL, * out_fname = NULL;
65 
66  progname = cmd_name( argv );
67  gargv = argv;
68 
69  if (! scanargs(argc, argv,
70  "% y%-ymax!d f%-ctlfile!s files!*s o%-outfile!s",
71  &y_flag, &max_y,
72  &ctlflag, &ctlfilename, &nfiles, &slicefiles,
73  &oflag, &out_fname ))
74  exit(1);
75 
76  /* Open the output file */
77  (void)rle_hdr_init( &in_hdr );
78  (void)rle_hdr_init( &out_hdr );
79  out_hdr.rle_file = rle_open_f(progname, out_fname, "w");
80  rle_names( &out_hdr, cmd_name( argv ), out_fname, 0 );
81 
82  start_line = (int *) malloc( nfiles * sizeof(int) );
84  stop_line = (int *) malloc( nfiles * sizeof(int) );
86 
87  if (ctlflag) /* Read in and verify the control file */
88  {
89  if (! ctlfilename)
90  ctlfilename = default_ctl_file;
91 
92  /* Read in the control file */
93 
94  ctlfile = rle_open_f( progname, ctlfilename, "r" );
95 
96  ctl_lines = 0;
97  while (! feof( ctlfile ))
98  {
99  fscanf( ctlfile, "%d %d",
100  &(start_line[ctl_lines]), &(stop_line[ctl_lines]) );
101 
102  if (start_line[ctl_lines] >= stop_line[ctl_lines])
103  fprintf( stderr, "%s: ctl file garbled? (start %d, stop %d)\n",
104  progname,
105  start_line[ctl_lines], stop_line[ctl_lines] );
106  ctl_lines++;
107  }
108  ctl_lines--;
109 
110  if (ctl_lines > nfiles)
111  fprintf(stderr,
112  "%s: Warning: not enough slices for ctl file\n", progname);
113  if (ctl_lines < nfiles)
114  fprintf(stderr,
115  "%s: Warning: too many slices for ctl file\n", progname);
116 
117  }
118  else
119  if (! max_y)
120  {
121  fprintf(stderr,
122  "%s: max y (-y ymax) must be given if no ctl file used\n",
123  progname);
124  exit(-1);
125  }
126 
127  /* Process the slices */
128 
129  for (i = 0; i < nfiles; i++)
130  do_slice( i, slicefiles[i] );
131 
132  rle_puteof( &out_hdr );
133 
134  exit( 0 );
135 }
char default_ctl_file[]
Definition: unslice.c:50
int scanargs(int argc, char **argv, const char *format,...)
Definition: scanargs.c:94
int * start_line
Definition: unslice.c:47
int * stop_line
Definition: unslice.c:47
int y_flag
Definition: getap.c:91
char * progname
Definition: unslice.c:51
int ctlflag
Definition: unslice.c:45
void rle_puteof(rle_hdr *the_hdr)
Definition: rle_putrow.c:474
void do_slice()
void rle_names(rle_hdr *the_hdr, const char *pgmname, const char *fname, int img_num)
rle_hdr out_hdr
Definition: unslice.c:34
char ** gargv
Definition: unslice.c:52
int ctl_lines
Definition: unslice.c:46
void * malloc()
int i
Definition: rletorla.c:82
FILE * rle_open_f(const char *prog_name, const char *f_name, const char *mode)
int max_y
Definition: unslice.c:42
rle_hdr in_hdr
Definition: unslice.c:34
char * cmd_name(char **argv)
Definition: cmd_name.c:31
int oflag
Definition: painttorle.c:45
FILE * rle_file
Definition: rle.h:114
#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

int ctl_lines

Definition at line 46 of file unslice.c.

int ctlflag = 0

Definition at line 45 of file unslice.c.

char default_ctl_file[] = "unslice.ctl"

Definition at line 50 of file unslice.c.

char** gargv

Definition at line 52 of file unslice.c.

rle_hdr in_hdr

Definition at line 34 of file unslice.c.

int max_y = 0

Definition at line 42 of file unslice.c.

int num_skip = 0

Definition at line 43 of file unslice.c.

rle_hdr out_hdr

Definition at line 34 of file unslice.c.

Referenced by FormFeed().

int* out_nraw

Definition at line 40 of file unslice.c.

rle_op** out_raw

Definition at line 39 of file unslice.c.

char* progname

Definition at line 51 of file unslice.c.

char rcsid[] = "$Header: /l/spencer/src/urt/tools/RCS/unslice.c,v 3.0.1.2 1992/04/30 14:14:54 spencer Exp $"
static

Definition at line 12 of file unslice.c.

int* start_line

Definition at line 47 of file unslice.c.

int * stop_line

Definition at line 47 of file unslice.c.