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_plane.c < prev    next >
C/C++ Source or Header  |  1996-01-31  |  2KB  |  76 lines

  1. /*
  2.  * ------------------------------------------------------------------
  3.  * average_plane.c - average plane
  4.  * Created by Robert Heller on Tue Feb 11 09:26:14 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 <llvs_per_plane.h>
  18.  
  19. average_plane(inplane,inplane_info,outplane,outplane_info,limits,scale_factor)
  20. PLANE *inplane, *outplane;
  21. PLANE_INFO *inplane_info, *outplane_info;
  22. LIMITS *limits;
  23. float scale_factor;
  24. {
  25.     int runlevel, indeltalev, outdeltalev;
  26.     int current_row, current_column, in_row, in_col, out_row, out_col;
  27.     float fpixel, sum, fback, divisor;
  28.     int wsize, wr, wc;
  29.  
  30.     /* compute delta level */
  31.     runlevel = limits->level;
  32.     indeltalev = runlevel - inplane_info->level;
  33.     outdeltalev = runlevel - outplane_info->level;
  34.     wsize = 1 << (-indeltalev);
  35.     divisor = wsize * wsize;
  36.     /* grab background value */
  37.     if (inplane_info->datatype == FLOAT)
  38.         fback = inplane_info->background.flonum;
  39.     else    fback = inplane_info->background.fixnum;
  40.  
  41.     /* row loop */
  42.     for (current_row = limits->startrow;
  43.          current_row <= limits->endrow;
  44.          current_row += limits->deltarow) {
  45.         /* translate row offset */
  46.         TRANSLEVEL(in_row, current_row, indeltalev,
  47.                    inplane_info->row_location);
  48.         TRANSLEVEL(out_row, current_row, outdeltalev,
  49.                    outplane_info->row_location);
  50.         /* column loop */
  51.         for (current_column = limits->startcol;
  52.              current_column <= limits->endcol;
  53.              current_column += limits->deltacol) {
  54.             /* translate column offsets */
  55.             TRANSLEVEL(in_col, current_column, indeltalev,
  56.                    inplane_info->column_location);
  57.             TRANSLEVEL(out_col, current_column, outdeltalev,
  58.                    outplane_info->column_location);
  59.             sum = 0.0;
  60.             for (wr = 0; wr < wsize; wr++) {
  61.                 for (wc = 0; wc < wsize; wc++) {
  62.                     /* fetch pixel */
  63.                     GET_PIXEL(fpixel, fback, inplane,
  64.                           in_row + wr, in_col + wc,
  65.                           (*inplane_info));
  66.                     sum += fpixel;
  67.                 }
  68.             }
  69.             fpixel = (sum / divisor) * scale_factor;
  70.             SET_PIXEL(fpixel, outplane, out_row, out_col,
  71.                   (*outplane_info));
  72.         }
  73.     }
  74. }
  75.  
  76.