home *** CD-ROM | disk | FTP | other *** search
- //
- // Copyright (c) 1998 Colosseum Builders, Inc.
- // All rights reserved.
- //
- // Colosseum Builders, Inc. makes no warranty, expressed or implied
- // with regards to this software. It is provided as is.
- //
- // Permission to use, redistribute, and copy this file is granted
- // without a fee so long as as the following conditions are adhered to:
- //
- // o The user assumes all risk for using this software. The authors of this
- // software shall be liable for no damages of any kind.
- //
- // o If the source code is distributed then this copyright notice must
- // remain unaltered and any modification must be noted.
- //
- // o If this code is shipped in binary format the accompanying documentation
- // should state that "this software is based, in part, on the work of
- // Colosseum Builders, Inc."
- //
-
- //
- // Title: Sample Image Viewer/Format Conversion Application
- //
- // Author: John M. Miano miano@colosseumbuilders.com
- //
- #include "EditableBitmap.h"
-
- #include <math.h>
- #include "bitimage.h"
- #include "jfif.h"
-
- const double MaxColor = 255.0 ;
-
- EditableBitmapImage &EditableBitmapImage::operator=(
- const BitmapImage &source)
- {
- BitmapImage::operator=(source) ;
- return *this ;
- }
-
-
-
- void EditableBitmapImage::GammaCorrect (double gamma)
- {
- if (BitCount () == 24)
- {
- for (unsigned int ii = 0 ; ii < Height () ; ++ ii)
- {
- for (unsigned int jj = 0 ; jj < 3 * Width () ; ++ jj)
- {
- if ((*this)[ii][jj] != 0)
- {
- double value ;
- value = MaxColor * exp (gamma * log ((*this) [ii][jj]/MaxColor)) ;
- (*this) [ii][jj] = value + 0.5 ;
- }
- }
- }
- }
- else
- {
- for (unsigned int ii = 0 ; ii < ColorCount () ; ++ ii)
- {
- double value ;
- if (ColorMap (ii).red != 0)
- {
- value = MaxColor * exp (gamma * log (ColorMap (ii).red/MaxColor)) ;
- ColorMap (ii).red = value + 0.5 ;
- }
- if (ColorMap (ii).green != 0)
- {
- value = MaxColor * exp (gamma * log (ColorMap (ii).green/MaxColor)) ;
- ColorMap (ii).green = value + 0.5 ;
- }
- if (ColorMap (ii).blue != 0)
- {
- value = MaxColor * exp (gamma * log (ColorMap (ii).blue/MaxColor)) ;
- ColorMap (ii).blue = value + 0.5 ;
- }
- }
- }
- return ;
- }
-
- void EditableBitmapImage::ToGrayscale ()
- {
- BitmapImage image ;
- if (BitCount () == 24)
- {
- image.SetSize (256, 8, Width (), Height ()) ;
- for (unsigned int ii = 0 ; ii < 256 ; ++ ii)
- {
- image.ColorMap (ii).red = ii ;
- image.ColorMap (ii).green = ii ;
- image.ColorMap (ii).blue = ii ;
- }
- for (unsigned int ii = 0 ; ii < Height () ; ++ ii)
- {
- for (unsigned int jj = 0 ; jj < Width () ; ++ jj)
- {
- unsigned int value = RGBToY (
- (*this)[ii][3*jj+BitmapImage::RedOffset],
- (*this)[ii][3*jj+BitmapImage::GreenOffset],
- (*this)[ii][3*jj+BitmapImage::BlueOffset]) ;
- image [ii][jj] = value ;
- }
- }
- }
- else
- {
- // Color adjustments are much easier on palette images.
- image = *this ;
- for (unsigned int ii = 0 ; ii < ColorCount () ; ++ ii)
- {
- unsigned int value = RGBToY (
- ColorMap (ii).red,
- ColorMap (ii).green,
- ColorMap (ii).blue) ;
- ColorMap (ii).red = value ;
- ColorMap (ii).green = value ;
- ColorMap (ii).blue = value ;
- }
- }
- *this = image ;
- return ;
- }
-
-