home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
vis-ftp.cs.umass.edu
/
vis-ftp.cs.umass.edu.tar
/
vis-ftp.cs.umass.edu
/
pub
/
Software
/
ASCENDER
/
ascendMar8.tar
/
UMass
/
BoldtNew
/
LLVS
/
average_and_scale.c
< prev
next >
Wrap
C/C++ Source or Header
|
1996-01-31
|
3KB
|
97 lines
/*
* ------------------------------------------------------------------
* average_and_scale.c - average and scale a plane
* Created by Robert Heller on Tue Feb 11 09:59:12 1992
* ------------------------------------------------------------------
* Modification History:
* ------------------------------------------------------------------
* Contents:
* ------------------------------------------------------------------
*
* Copyright (c) 1992 by University of Massachuetts
* All Rights Reserved
*
*/
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <llvs_per_plane.h>
extern void average_plane(), min_max_plane();
main (argc, argv)
int argc;
char* argv[];
{
static PLANE *inpl, *outpl;
static PLANE_INFO *inpl_info, *outpl_info;
static char *inassoc, outfile[256], infile[256];
register char *p;
register int outlevel, deltalev, new_row_dim, new_col_dim,
new_row_loc, new_col_loc, error;
static LIMITS limits;
static float minval, maxval;
float scale_factor;
if (argc != 4) usage_abort();
strcpy(infile,argv[1]);
strcpy(outfile,argv[2]);
outlevel = atoi(argv[3]);
p = strrchr(infile,'.');
if (p == NULL) strcat(infile,".plane");
else if (strchr(p,'/') != NULL) strcat(infile,".plane");
p = strrchr(outfile,'.');
if (p == NULL) strcat(outfile,".plane");
else if (strchr(p,'/') != NULL) strcat(outfile,".plane");
if (read_plane(&inpl,&inpl_info,&inassoc,infile) < 0) {
error = errno;
perror("average_and_scale: read_plane");
fprintf(stderr,"average_and_scale: read_plane: could not read in plane %s\n",
infile);
exit(error);
}
limits.level = inpl_info->level;
limits.deltarow = 1;
limits.deltacol = 1;
limits.startrow = inpl_info->row_location;
limits.endrow = (inpl_info->row_location + inpl_info->row_dimension) - 1;
limits.startcol = inpl_info->column_location;
limits.endcol = (inpl_info->column_location + inpl_info->column_dimension) - 1;
min_max_plane(inpl,inpl_info,&limits,&minval,&maxval);
scale_factor = 255.0 / (maxval - minval);
deltalev = inpl_info->level - outlevel;
new_row_dim = inpl_info->row_dimension >> deltalev;
new_col_dim = inpl_info->column_dimension >> deltalev;
new_row_loc = inpl_info->row_location >> deltalev;
new_col_loc = inpl_info->column_location >> deltalev;
if (new_plane(&outpl,&outpl_info,LLVS_BYTE,outlevel,new_row_dim,new_col_dim,
new_row_loc,new_col_loc,&inpl_info->background) < 0) {
error = errno;
perror("average_and_scale: new_plane");
fprintf(stderr,"average_and_scale: new_plane: could not allocate plane\n");
exit(error);
}
limits.level = outlevel;
limits.startrow = new_row_loc;
limits.endrow = (new_row_loc + new_row_dim) - 1;
limits.startcol = new_col_loc;
limits.endcol = (new_col_loc + new_col_dim) - 1;
average_plane(inpl,inpl_info,outpl,outpl_info,&limits,scale_factor);
if (write_plane(outpl,outpl_info,"NIL",outfile) < 0) {
error = errno;
perror("average_and_scale: write_plane");
fprintf(stderr,"average_and_scale: write_plane: could not create plane %s\n",
outfile);
exit(error);
}
}
usage_abort()
{
printf("usage: average_and_scale inplanefile outplanefile outlevel\n");
exit(EINVAL);
}