home *** CD-ROM | disk | FTP | other *** search
/ Compressed Image File Formats / CompressedImageFileFormatsJohnMiano.iso / pc / Library / BCBViewer / ImageEdit.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-12-17  |  1.3 KB  |  47 lines

  1. #include <math.h>
  2. #include "imageedit.h"
  3. #include "bitimage.h"
  4.  
  5. const double MaxColor = 255.0 ;
  6.  
  7. void GammaCorrect (BitmapImage &image, double gamma)
  8. {
  9.   if (image.BitCount () == 24)
  10.   {
  11.     for (unsigned int ii = 0 ; ii < image.Height () ; ++ ii)
  12.     {
  13.       for (unsigned int jj = 0 ; jj < 3 * image.Width () ; ++ jj)
  14.       {
  15.         if (image [ii][jj] != 0)
  16.         {
  17.           double value = image [ii][jj] ;
  18.           value = MaxColor * exp (gamma * log (image [ii][jj]/MaxColor)) ;
  19.           image [ii][jj] = value + 0.5 ;
  20.         }
  21.       }
  22.     }
  23.   }
  24.   else
  25.   {
  26.     for (unsigned int ii = 0 ; ii < image.ColorCount () ; ++ ii)
  27.     {
  28.       double value ;
  29.       if (image.ColorMap (ii).red != 0)
  30.       {
  31.         value = MaxColor * exp (gamma * log (image.ColorMap (ii).red/MaxColor)) ;
  32.         image.ColorMap (ii).red = value + 0.5 ;
  33.       }
  34.       if (image.ColorMap (ii).green != 0)
  35.       {
  36.         value = MaxColor * exp (gamma * log (image.ColorMap (ii).green/MaxColor)) ;
  37.         image.ColorMap (ii).green = value + 0.5 ;
  38.       }
  39.       if (image.ColorMap (ii).blue != 0)
  40.       {
  41.         value = MaxColor * exp (gamma * log (image.ColorMap (ii).blue/MaxColor)) ;
  42.         image.ColorMap (ii).blue = value + 0.5 ;
  43.       }
  44.     }
  45.   }
  46. }
  47.