AlbumShaper 1.0a3
sepia.cpp
Go to the documentation of this file.
1//==============================================
2// copyright : (C) 2003-2005 by Will Stokes
3//==============================================
4// This program is free software; you can redistribute it
5// and/or modify it under the terms of the GNU General
6// Public License as published by the Free Software
7// Foundation; either version 2 of the License, or
8// (at your option) any later version.
9//==============================================
10
11//Systemwide includes
12#include <qimage.h>
13#include <qstring.h>
14#include <qapplication.h>
15
16//Projectwide includes
17#include "sepia.h"
18#include "manipulationOptions.h"
20
21//----------------------------------------------
22// Inputs:
23// -------
24// QString filename - location of original image on disk
25// StatusWidget* status - widget for making progress visible to user
26//
27// Outputs:
28// --------
29// QImage* returned - constructed image
30//
31// Description:
32// ------------
33// This method constructs a sepia version of
34// the image by computing a sepia value for each pixel.
35// The sepia effect is intended to mimick sepia coloring
36// obtained during traditional film development.
37//
38// First, a sepia color is chosen with a nice yellowy-orange tone
39// (r,g,b = 162,128,101). This color is next converted to HSL
40// (hue, saturation, luminance) space and used during sepia coloring.
41//
42// For each pixel, we construct a modified sepia color where the original
43// luminance (brightness) is replaced with that pixels luminance using
44// a weighted sum of the color channels. (For more information on image
45// luminance see the blackWhite effect). This modified sepia color is
46// converted back to RGB color space and used for the pixel color
47// in the modified image. This way image brightness is maintained
48// while color information is replaced with the sepia color. The
49// sepia color can be adjusted to produce a differnt overall color
50// feeling by changing the original sepia color.
51//----------------------------------------------
52
53//==============================================
54QImage* sepiaEffect( QString filename, ManipulationOptions* options )
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}
130//==============================================
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
QImage * sepiaEffect(QString filename, ManipulationOptions *options)
Definition sepia.cpp:54