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

sepia.cpp File Reference

#include <qimage.h>
#include <qstring.h>
#include <qapplication.h>
#include "sepia.h"
#include "../../gui/statusWidget.h"

Include dependency graph for sepia.cpp:

Include dependency graph

Go to the source code of this file.

Functions

QImage * sepiaEffect (QString filename, StatusWidget *status)


Function Documentation

QImage* sepiaEffect QString  filename,
StatusWidget status
 

Definition at line 53 of file sepia.cpp.

References editedImage, StatusWidget::incrementProgress(), newProgress, StatusWidget::showProgressBar(), status, and updateIncrement.

Referenced by EditingInterface::applyEffect().

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 }


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