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

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().

{
  //load image
  QImage* editedImage = new QImage( filename );
  
  //convert to 32-bit depth if necessary
  if( editedImage->depth() < 32 )
  {
    QImage* tmp = editedImage;
    editedImage = new QImage( tmp->convertDepth( 32, Qt::AutoColor ) );
    delete tmp; tmp=NULL;
  }

  //determine if busy indicators will be used
  bool useBusyIndicators = false;
  StatusWidget* status = NULL;
  if( options != NULL && options->getStatus() != NULL )
  {
    useBusyIndicators = true;
    status = options->getStatus(); 
  }
  
  //setup progress bar
  if(useBusyIndicators)
  {
    QString statusMessage = qApp->translate( "sepiaEffect", "Applying Sepia Effect:" );
    status->showProgressBar( statusMessage, 100 );
    qApp->processEvents();  
  }
  
  //update progress bar for every 1% of completion
  const int updateIncrement = (int) ( 0.01 * editedImage->width() * editedImage->height() );
  int newProgress = 0; 

  //compute the hsl/hsv coordinates of sepia color
  int sepiaH, sepiaS, sepiaL;
  QColor(162,128,101).getHsv( &sepiaH, &sepiaS, &sepiaL );
  
  //iterate over each selected scanline 
  int x, y, pixelLuminance;
  QRgb* rgb;
  QColor sepiaColor;
  uchar* scanLine;
  
  for( y=0; y<editedImage->height(); y++)
  {   
    //iterate over each selected pixel in scanline
    scanLine = editedImage->scanLine(y);
    for( x=0; x<editedImage->width(); x++)
    {
      //compute gray value based on the display luminance of color coordinates
      rgb = ((QRgb*)scanLine+x);
      pixelLuminance = (int) (0.2125*qRed(*rgb) + 0.7154*qGreen(*rgb) + 0.0721*qBlue(*rgb));
      
      //compute and set sepia color
      sepiaColor.setHsv( sepiaH, sepiaS, pixelLuminance );      
      *rgb = sepiaColor.rgb();
      
      //update status bar if significant progress has been made since last update
      if(useBusyIndicators)
      {
        newProgress++;
        if(newProgress >= updateIncrement)
        {
          newProgress = 0;
          status->incrementProgress();
          qApp->processEvents();  
        }
      }
      
    }
  }
  
  //return pointer to edited image
  return editedImage;  
}