Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members

blackWhite.cpp File Reference

#include <qimage.h>
#include <qstring.h>
#include <qapplication.h>
#include "blackWhite.h"
#include "manipulationOptions.h"
#include "../../gui/statusWidget.h"

Include dependency graph for blackWhite.cpp:

Go to the source code of this file.

Functions

QImage * blackWhiteEffect (QString filename, ManipulationOptions *options)


Function Documentation

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

00061 { 00062 //load image 00063 QImage* editedImage = new QImage( filename ); 00064 00065 //convert to 32-bit depth if necessary 00066 if( editedImage->depth() < 32 ) 00067 { 00068 QImage* tmp = editedImage; 00069 editedImage = new QImage( tmp->convertDepth( 32, Qt::AutoColor ) ); 00070 delete tmp; tmp=NULL; 00071 } 00072 00073 //determine if busy indicators will be used 00074 bool useBusyIndicators = false; 00075 StatusWidget* status = NULL; 00076 if( options != NULL && options->getStatus() != NULL ) 00077 { 00078 useBusyIndicators = true; 00079 status = options->getStatus(); 00080 } 00081 00082 //setup progress bar 00083 if(useBusyIndicators) 00084 { 00085 QString statusMessage = qApp->translate( "blackWhiteEffect", "Applying Black + White Effect:" ); 00086 status->showProgressBar( statusMessage, 100 ); 00087 qApp->processEvents(); 00088 } 00089 00090 //update progress bar for every 1% of completion 00091 const int updateIncrement = (int) ( 0.01 * editedImage->width() * editedImage->height() ); 00092 int newProgress = 0; 00093 00094 //iterate over each selected scanline 00095 int x, y, grayValue; 00096 QRgb* rgb; 00097 uchar* scanLine; 00098 for( y=0; y<editedImage->height(); y++) 00099 { 00100 //iterate over each selected pixel in scanline 00101 scanLine = editedImage->scanLine(y); 00102 for( x=0; x<editedImage->width(); x++) 00103 { 00104 //compute gray value based on the display luminance of color coordinates 00105 rgb = ((QRgb*)scanLine+x); 00106 grayValue = (int) (0.2125*qRed(*rgb) + 0.7154*qGreen(*rgb) + 0.0721*qBlue(*rgb)); 00107 00108 //clamp to ensure it falls in the 0-255 range 00109 grayValue = QMIN( QMAX( grayValue, 0 ), 255 ); 00110 00111 //set pixel channel values using computed gray value 00112 *rgb = qRgb( grayValue, grayValue, grayValue ); 00113 00114 //update status bar if significant progress has been made since last update 00115 if(useBusyIndicators) 00116 { 00117 newProgress++; 00118 if(newProgress >= updateIncrement) 00119 { 00120 newProgress = 0; 00121 status->incrementProgress(); 00122 qApp->processEvents(); 00123 } 00124 } 00125 00126 } 00127 } 00128 00129 //return pointer to edited image 00130 return editedImage; 00131 }


Generated on Sun Mar 4 19:42:58 2007 for AlbumShaper by doxygen 1.3.7