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 >
C/C++ Source or Header  |  1996-01-31  |  3KB  |  97 lines

  1. /*
  2.  * ------------------------------------------------------------------
  3.  * average_and_scale.c - average and scale a plane
  4.  * Created by Robert Heller on Tue Feb 11 09:59:12 1992
  5.  * ------------------------------------------------------------------
  6.  * Modification History:
  7.  * ------------------------------------------------------------------
  8.  * Contents:
  9.  * ------------------------------------------------------------------
  10.  *  
  11.  * Copyright (c) 1992 by University of Massachuetts
  12.  *     All Rights Reserved
  13.  * 
  14.  */
  15.  
  16. #include <stdio.h>
  17. #include <errno.h>
  18. #include <string.h>
  19. #include <llvs_per_plane.h>
  20.  
  21. extern void average_plane(), min_max_plane();
  22.  
  23. main (argc, argv)
  24. int argc;
  25. char* argv[];
  26. {
  27.     static PLANE *inpl, *outpl;
  28.     static PLANE_INFO *inpl_info, *outpl_info;
  29.     static char *inassoc, outfile[256], infile[256];
  30.     register char *p;
  31.     register int outlevel, deltalev, new_row_dim, new_col_dim,
  32.              new_row_loc, new_col_loc, error;
  33.     static LIMITS limits;
  34.     static float minval, maxval;
  35.     float scale_factor;
  36.     
  37.     if (argc != 4) usage_abort();
  38.     strcpy(infile,argv[1]);
  39.     strcpy(outfile,argv[2]);
  40.     outlevel = atoi(argv[3]);
  41.     p = strrchr(infile,'.');
  42.     if (p == NULL) strcat(infile,".plane");
  43.     else if (strchr(p,'/') != NULL) strcat(infile,".plane");
  44.     p = strrchr(outfile,'.');
  45.     if (p == NULL) strcat(outfile,".plane");
  46.     else if (strchr(p,'/') != NULL) strcat(outfile,".plane");
  47.     if (read_plane(&inpl,&inpl_info,&inassoc,infile) < 0) {
  48.         error = errno;
  49.         perror("average_and_scale: read_plane");
  50.         fprintf(stderr,"average_and_scale: read_plane: could not read in plane %s\n",
  51.             infile);
  52.         exit(error);
  53.     }
  54.     limits.level = inpl_info->level;
  55.     limits.deltarow = 1;
  56.     limits.deltacol = 1;
  57.     limits.startrow = inpl_info->row_location;
  58.     limits.endrow   = (inpl_info->row_location + inpl_info->row_dimension) - 1;
  59.     limits.startcol = inpl_info->column_location;
  60.     limits.endcol   = (inpl_info->column_location + inpl_info->column_dimension) - 1;
  61.     min_max_plane(inpl,inpl_info,&limits,&minval,&maxval);
  62.     scale_factor = 255.0 / (maxval - minval);
  63.     deltalev = inpl_info->level - outlevel;
  64.     new_row_dim = inpl_info->row_dimension >> deltalev;
  65.     new_col_dim = inpl_info->column_dimension >> deltalev;
  66.     new_row_loc = inpl_info->row_location >> deltalev;
  67.     new_col_loc = inpl_info->column_location >> deltalev;
  68.     if (new_plane(&outpl,&outpl_info,LLVS_BYTE,outlevel,new_row_dim,new_col_dim,
  69.               new_row_loc,new_col_loc,&inpl_info->background) < 0) {
  70.         error = errno;
  71.         perror("average_and_scale: new_plane");
  72.         fprintf(stderr,"average_and_scale: new_plane: could not allocate plane\n");
  73.         exit(error);
  74.     }
  75.     limits.level = outlevel;
  76.     limits.startrow = new_row_loc;
  77.     limits.endrow   = (new_row_loc + new_row_dim) - 1;
  78.     limits.startcol = new_col_loc;
  79.     limits.endcol   = (new_col_loc + new_col_dim) - 1;
  80.     average_plane(inpl,inpl_info,outpl,outpl_info,&limits,scale_factor);
  81.     if (write_plane(outpl,outpl_info,"NIL",outfile) < 0) {
  82.         error = errno;
  83.         perror("average_and_scale: write_plane");
  84.         fprintf(stderr,"average_and_scale: write_plane: could not create plane %s\n",
  85.             outfile);
  86.         exit(error);
  87.     }
  88. }
  89.  
  90. usage_abort()
  91. {
  92.     printf("usage: average_and_scale inplanefile outplanefile outlevel\n");
  93.     exit(EINVAL);
  94. }
  95.  
  96.  
  97.