#include <qimage.h>
#include <qstring.h>
#include <qapplication.h>
#include "sepia.h"
#include "manipulationOptions.h"
#include "../../gui/statusWidget.h"
Include dependency graph for sepia.cpp:

Go to the source code of this file.
Functions | |
| QImage * | sepiaEffect (QString filename, ManipulationOptions *options) |
|
||||||||||||
|
Definition at line 54 of file sepia.cpp. References editedImage, ManipulationOptions::getStatus(), StatusWidget::incrementProgress(), newProgress, StatusWidget::showProgressBar(), status, and updateIncrement. Referenced by EditingInterface::applyEffect(). 00055 {
00056 //load image
00057 QImage* editedImage = new QImage( filename );
00058
00059 //convert to 32-bit depth if necessary
00060 if( editedImage->depth() < 32 )
00061 {
00062 QImage* tmp = editedImage;
00063 editedImage = new QImage( tmp->convertDepth( 32, Qt::AutoColor ) );
00064 delete tmp; tmp=NULL;
00065 }
00066
00067 //determine if busy indicators will be used
00068 bool useBusyIndicators = false;
00069 StatusWidget* status = NULL;
00070 if( options != NULL && options->getStatus() != NULL )
00071 {
00072 useBusyIndicators = true;
00073 status = options->getStatus();
00074 }
00075
00076 //setup progress bar
00077 if(useBusyIndicators)
00078 {
00079 QString statusMessage = qApp->translate( "sepiaEffect", "Applying Sepia Effect:" );
00080 status->showProgressBar( statusMessage, 100 );
00081 qApp->processEvents();
00082 }
00083
00084 //update progress bar for every 1% of completion
00085 const int updateIncrement = (int) ( 0.01 * editedImage->width() * editedImage->height() );
00086 int newProgress = 0;
00087
00088 //compute the hsl/hsv coordinates of sepia color
00089 int sepiaH, sepiaS, sepiaL;
00090 QColor(162,128,101).getHsv( &sepiaH, &sepiaS, &sepiaL );
00091
00092 //iterate over each selected scanline
00093 int x, y, pixelLuminance;
00094 QRgb* rgb;
00095 QColor sepiaColor;
00096 uchar* scanLine;
00097
00098 for( y=0; y<editedImage->height(); y++)
00099 {
00100 //iterate over each selected pixel in scanline
00101 scanLine = editedImage->scanLine(y);
00102 for( x=0; x<editedImage->width(); x++)
00103 {
00104 //compute gray value based on the display luminance of color coordinates
00105 rgb = ((QRgb*)scanLine+x);
00106 pixelLuminance = (int) (0.2125*qRed(*rgb) + 0.7154*qGreen(*rgb) + 0.0721*qBlue(*rgb));
00107
00108 //compute and set sepia color
00109 sepiaColor.setHsv( sepiaH, sepiaS, pixelLuminance );
00110 *rgb = sepiaColor.rgb();
00111
00112 //update status bar if significant progress has been made since last update
00113 if(useBusyIndicators)
00114 {
00115 newProgress++;
00116 if(newProgress >= updateIncrement)
00117 {
00118 newProgress = 0;
00119 status->incrementProgress();
00120 qApp->processEvents();
00121 }
00122 }
00123
00124 }
00125 }
00126
00127 //return pointer to edited image
00128 return editedImage;
00129 }
|
1.3.9.1