AlbumShaper  1.0a3
Functions
sepia.h File Reference
This graph shows which files directly or indirectly include this file:

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.

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

Referenced by EditingInterface::applyEffect().

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++;
116  if(newProgress >= updateIncrement)
117  {
118  newProgress = 0;
119  status->incrementProgress();
120  qApp->processEvents();
121  }
122  }
123 
124  }
125  }
126 
127  //return pointer to edited image
128  return editedImage;
129 }
int updateIncrement
StatusWidget * getStatus()
void incrementProgress()
Updates the progress bar by one step.
void showProgressBar(QString message, int numSteps)
Initializes the progress bar.
StatusWidget * status
QImage * editedImage
int newProgress