home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / procssng / ccs / ccs-11tl.lha / lbl / sun / lib2 / sub_mean.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-07-01  |  2.1 KB  |  70 lines

  1. /*    sub_mean . c
  2. %
  3. %    calculate mean value in a sub area for interline 24-bit (RLE) color
  4. %
  5. %    When X0 & y0 zeros, rgb_in & rgb_out point to begining of sub buffer.
  6. %    Otherwise, rgb_in & rgb_out point to begining of original array.
  7. %
  8. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  9.  
  10. This software is copyright (C) by the Lawrence Berkeley Laboratory.
  11. Permission is granted to reproduce this software for non-commercial
  12. purposes provided that this notice is left intact.
  13.  
  14. It is acknowledged that the U.S. Government has rights to this software
  15. under Contract DE-AC03-765F00098 between the U.S.  Department of Energy
  16. and the University of California.
  17.  
  18. This software is provided as a professional and academic contribution
  19. for joint exchange. Thus, it is experimental, and is provided ``as is'',
  20. with no warranties of any kind whatsoever, no support, no promise of
  21. updates, or printed documentation. By using this software, you
  22. acknowledge that the Lawrence Berkeley Laboratory and Regents of the
  23. University of California shall have no liability with respect to the
  24. infringement of other copyrights by any part of this software.
  25.  
  26. For further information about this notice, contact William Johnston,
  27. Bld. 50B, Rm. 2239, Lawrence Berkeley Laboratory, Berkeley, CA, 94720.
  28. (wejohnston@lbl.gov)
  29.  
  30. For further information about this software, contact:
  31.         Jin Guojun
  32.         Bld. 50B, Rm. 2275, Lawrence Berkeley Laboratory, Berkeley, CA, 94720.
  33.         jin@george.lbl.gov
  34.  
  35. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  36. %
  37. % AUTHOR:    Jin Guojun - LBL    4/1/92
  38. */
  39.  
  40. #include "imagedef.h"
  41.  
  42. CalcSubWinMean(rgb_in, rgb_out, w, x0, y0, sw, sh)
  43. byte    *rgb_in, *rgb_out;
  44. {
  45. register byte    *pr, *pg, *pb;
  46. register int    c, ir, ig, ib;
  47. int    r;
  48.  
  49. rgb_in += w*y0*3 + x0;
  50. rgb_out += w*y0*3 + x0;
  51.     for (r=sh, ir=ig=ib=0; r--; rgb_in += w*3)    {
  52.     pr = rgb_in;     pg = pr + w;    pb = pg + w;
  53.     for (c=sw; c--;)    {
  54.         ir += *pr++;
  55.         ig += *pg++;
  56.         ib += *pb++;
  57.     }
  58.     }
  59.     c = sw * sh;
  60.     ir /= c,    ig /= c,    ib /=c;
  61.     for (r=sh; r--; rgb_out += w*3)    {
  62.     pr = rgb_out;     pg = pr + w;    pb = pg + w;
  63.     for (c=sw; c--;)    {
  64.         *pr++ = ir;
  65.         *pg++ = ig;
  66.         *pb++ = ib;
  67.     }
  68.     }
  69. }
  70.