home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume5 / xldimage / part01 / bright.c next >
Encoding:
C/C++ Source or Header  |  1989-11-13  |  1.0 KB  |  49 lines

  1. /* bright.c
  2.  *
  3.  * alter an image's brightness by a given percentage
  4.  *
  5.  * jim frost 10.10.89
  6.  *
  7.  * Copyright 1989 Jim Frost.  See included file "copyright.h" for complete
  8.  * copyright information.
  9.  */
  10.  
  11. #include "copyright.h"
  12. #include "image.h"
  13.  
  14. void brighten(image, percent, verbose)
  15.      Image        *image;
  16.      int           percent;
  17.      unsigned int  verbose;
  18. { int          a;
  19.   unsigned int newrgb;
  20.   float        fperc;
  21.  
  22.   if (! RGBP(image)) /* we're AT&T */
  23.     return;
  24.  
  25.   if (verbose) {
  26.     printf("  Brightening colormap by %d%%...", percent);
  27.     fflush(stdout);
  28.   }
  29.  
  30.   fperc= (float)percent / 100.0;
  31.   for (a= 0; a < image->rgb.used; a++) {
  32.     newrgb= *(image->rgb.red + a) * fperc;
  33.     if (newrgb > 65535)
  34.       newrgb= 65535;
  35.     *(image->rgb.red + a)= newrgb;
  36.     newrgb= *(image->rgb.green + a) * fperc;
  37.     if (newrgb > 65535)
  38.       newrgb= 65535;
  39.     *(image->rgb.green + a)= newrgb;
  40.     newrgb= *(image->rgb.blue + a) * fperc;
  41.     if (newrgb > 65535)
  42.       newrgb= 65535;
  43.     *(image->rgb.blue + a)= newrgb;
  44.   }
  45.  
  46.   if (verbose)
  47.     printf("done\n");
  48. }
  49.