AlbumShaper
1.0a3
|
Go to the source code of this file.
Functions | |
QImage * | blackWhiteEffect (QString filename, ManipulationOptions *options) |
QImage* blackWhiteEffect | ( | QString | filename, |
ManipulationOptions * | options | ||
) |
Definition at line 60 of file blackWhite.cpp.
References editedImage, ManipulationOptions::getStatus(), StatusWidget::incrementProgress(), newProgress, StatusWidget::showProgressBar(), status, and updateIncrement.
Referenced by EditingInterface::applyEffect(), and pointillismEffect().
{ //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( "blackWhiteEffect", "Applying Black + White 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; //iterate over each selected scanline int x, y, grayValue; QRgb* rgb; 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); grayValue = (int) (0.2125*qRed(*rgb) + 0.7154*qGreen(*rgb) + 0.0721*qBlue(*rgb)); //clamp to ensure it falls in the 0-255 range grayValue = QMIN( QMAX( grayValue, 0 ), 255 ); //set pixel channel values using computed gray value *rgb = qRgb( grayValue, grayValue, grayValue ); //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; }