Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Class Members | File Members

sepia.cpp

Go to the documentation of this file.
00001 //==============================================
00002 //  copyright            : (C) 2003-2005 by Will Stokes
00003 //==============================================
00004 //  This program is free software; you can redistribute it
00005 //  and/or modify it under the terms of the GNU General
00006 //  Public License as published by the Free Software
00007 //  Foundation; either version 2 of the License, or
00008 //  (at your option) any later version.
00009 //==============================================
00010 
00011 //Systemwide includes
00012 #include <qimage.h>
00013 #include <qstring.h>
00014 #include <qapplication.h>
00015 
00016 //Projectwide includes
00017 #include "sepia.h"
00018 #include "../../gui/statusWidget.h"
00019 
00020 //----------------------------------------------
00021 // Inputs:
00022 // -------
00023 // QString filename - location of original image on disk
00024 // StatusWidget* status - widget for making progress visible to user
00025 //
00026 // Outputs:
00027 // --------
00028 // QImage* returned - constructed image
00029 //
00030 // Description:
00031 // ------------
00032 // This method constructs a sepia version of
00033 // the image by computing a sepia value for each pixel. 
00034 // The sepia effect is intended to mimick sepia coloring 
00035 // obtained during traditional film development.
00036 //
00037 // First, a sepia color is chosen with a nice yellowy-orange tone
00038 // (r,g,b = 162,128,101). This color is next converted to HSL 
00039 // (hue, saturation, luminance) space and used during sepia coloring.
00040 // 
00041 // For each pixel, we construct a modified sepia color where the original
00042 // luminance (brightness) is replaced with that pixels luminance using
00043 // a weighted sum of the color channels. (For more information on image
00044 // luminance see the blackWhite effect). This modified sepia color is
00045 // converted back to RGB color space and used for the pixel color
00046 // in the modified image. This way image brightness is maintained
00047 // while color information is replaced with the sepia color. The
00048 // sepia color can be adjusted to produce a differnt overall color
00049 // feeling by changing the original sepia color.
00050 //----------------------------------------------
00051 
00052 //==============================================
00053 QImage* sepiaEffect( QString filename, StatusWidget* status )
00054 {
00055   //load image
00056   QImage* editedImage = new QImage( filename );
00057   
00058   //determine if busy indicators will be used
00059   bool useBusyIndicators = (status != NULL);
00060   
00061   //setup progress bar
00062   if(useBusyIndicators)
00063   {
00064     QString statusMessage = qApp->translate( "sepiaEffect", "Applying Sepia Effect:" );
00065     status->showProgressBar( statusMessage, 100 );
00066     qApp->processEvents();  
00067   }
00068   
00069   //update progress bar for every 1% of completion
00070   const int updateIncrement = (int) ( 0.01 * editedImage->width() * editedImage->height() );
00071   int newProgress = 0; 
00072 
00073   //compute the hsl/hsv coordinates of sepia color
00074   int sepiaH, sepiaS, sepiaL;
00075   QColor(162,128,101).getHsv( &sepiaH, &sepiaS, &sepiaL );
00076   
00077   //iterate over each selected scanline 
00078   int x, y, pixelLuminance;
00079   QRgb* rgb;
00080   QColor sepiaColor;
00081   uchar* scanLine;
00082   
00083   for( y=0; y<editedImage->height(); y++)
00084   {   
00085     //iterate over each selected pixel in scanline
00086     scanLine = editedImage->scanLine(y);
00087     for( x=0; x<editedImage->width(); x++)
00088     {
00089       //compute gray value based on the display luminance of color coordinates
00090       rgb = ((QRgb*)scanLine+x);
00091       pixelLuminance = (int)(0.3*qRed(*rgb) + 0.59*qGreen(*rgb) + 0.11*qBlue(*rgb));
00092       
00093       //compute and set sepia color
00094       sepiaColor.setHsv( sepiaH, sepiaS, pixelLuminance );      
00095       *rgb = sepiaColor.rgb();
00096       
00097       //update status bar if significant progress has been made since last update
00098       if(useBusyIndicators)
00099       {
00100         newProgress++;
00101         if(newProgress >= updateIncrement)
00102         {
00103           newProgress = 0;
00104           status->incrementProgress();
00105           qApp->processEvents();  
00106         }
00107       }
00108       
00109     }
00110   }
00111   
00112   //return pointer to edited image
00113   return editedImage;  
00114 }
00115 //==============================================

Generated on Sat Apr 2 05:44:04 2005 for AlbumShaper by  doxygen 1.3.9.1