AlbumShaper 1.0a3
sepia.cpp File Reference
#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)
 

Function Documentation

◆ sepiaEffect()

QImage * sepiaEffect ( QString filename,
ManipulationOptions * options )

Definition at line 54 of file sepia.cpp.

55{
56 //load image
57 QImage* editedImage = new QImage( filename );
58
59 //convert to 32-bit depth if necessary
60 if( editedImage->depth() < 32 )
61 {
62 QImage* tmp = editedImage;
63 editedImage = new QImage( tmp->convertDepth( 32, Qt::AutoColor ) );
64 delete tmp; tmp=NULL;
65 }
66
67 //determine if busy indicators will be used
68 bool useBusyIndicators = false;
69 StatusWidget* status = NULL;
70 if( options != NULL && options->getStatus() != NULL )
71 {
72 useBusyIndicators = true;
73 status = options->getStatus();
74 }
75
76 //setup progress bar
77 if(useBusyIndicators)
78 {
79 QString statusMessage = qApp->translate( "sepiaEffect", "Applying Sepia Effect:" );
80 status->showProgressBar( statusMessage, 100 );
81 qApp->processEvents();
82 }
83
84 //update progress bar for every 1% of completion
85 const int updateIncrement = (int) ( 0.01 * editedImage->width() * editedImage->height() );
86 int newProgress = 0;
87
88 //compute the hsl/hsv coordinates of sepia color
89 int sepiaH, sepiaS, sepiaL;
90 QColor(162,128,101).getHsv( &sepiaH, &sepiaS, &sepiaL );
91
92 //iterate over each selected scanline
93 int x, y, pixelLuminance;
94 QRgb* rgb;
95 QColor sepiaColor;
96 uchar* scanLine;
97
98 for( y=0; y<editedImage->height(); y++)
99 {
100 //iterate over each selected pixel in scanline
101 scanLine = editedImage->scanLine(y);
102 for( x=0; x<editedImage->width(); x++)
103 {
104 //compute gray value based on the display luminance of color coordinates
105 rgb = ((QRgb*)scanLine+x);
106 pixelLuminance = (int) (0.2125*qRed(*rgb) + 0.7154*qGreen(*rgb) + 0.0721*qBlue(*rgb));
107
108 //compute and set sepia color
109 sepiaColor.setHsv( sepiaH, sepiaS, pixelLuminance );
110 *rgb = sepiaColor.rgb();
111
112 //update status bar if significant progress has been made since last update
113 if(useBusyIndicators)
114 {
115 newProgress++;
117 {
118 newProgress = 0;
120 qApp->processEvents();
121 }
122 }
123
124 }
125 }
126
127 //return pointer to edited image
128 return editedImage;
129}
StatusWidget * getStatus()
void showProgressBar(QString message, int numSteps)
Initializes the progress bar.
void incrementProgress()
Updates the progress bar by one step.
int updateIncrement
QImage * editedImage
StatusWidget * status
int newProgress

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

Referenced by EditingInterface::applyEffect().