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

Go to the source code of this file.

Functions

QImage * blackWhiteEffect (QString filename, ManipulationOptions *options)
 

Function Documentation

◆ blackWhiteEffect()

QImage * blackWhiteEffect ( QString filename,
ManipulationOptions * options )

Definition at line 60 of file blackWhite.cpp.

61{
62 //load image
63 QImage* editedImage = new QImage( filename );
64
65 //convert to 32-bit depth if necessary
66 if( editedImage->depth() < 32 )
67 {
68 QImage* tmp = editedImage;
69 editedImage = new QImage( tmp->convertDepth( 32, Qt::AutoColor ) );
70 delete tmp; tmp=NULL;
71 }
72
73 //determine if busy indicators will be used
74 bool useBusyIndicators = false;
75 StatusWidget* status = NULL;
76 if( options != NULL && options->getStatus() != NULL )
77 {
78 useBusyIndicators = true;
79 status = options->getStatus();
80 }
81
82 //setup progress bar
83 if(useBusyIndicators)
84 {
85 QString statusMessage = qApp->translate( "blackWhiteEffect", "Applying Black + White Effect:" );
86 status->showProgressBar( statusMessage, 100 );
87 qApp->processEvents();
88 }
89
90 //update progress bar for every 1% of completion
91 const int updateIncrement = (int) ( 0.01 * editedImage->width() * editedImage->height() );
92 int newProgress = 0;
93
94 //iterate over each selected scanline
95 int x, y, grayValue;
96 QRgb* rgb;
97 uchar* scanLine;
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 grayValue = (int) (0.2125*qRed(*rgb) + 0.7154*qGreen(*rgb) + 0.0721*qBlue(*rgb));
107
108 //clamp to ensure it falls in the 0-255 range
109 grayValue = QMIN( QMAX( grayValue, 0 ), 255 );
110
111 //set pixel channel values using computed gray value
112 *rgb = qRgb( grayValue, grayValue, grayValue );
113
114 //update status bar if significant progress has been made since last update
115 if(useBusyIndicators)
116 {
117 newProgress++;
119 {
120 newProgress = 0;
122 qApp->processEvents();
123 }
124 }
125
126 }
127 }
128
129 //return pointer to edited image
130 return editedImage;
131}
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

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

Referenced by EditingInterface::applyEffect(), and pointillismEffect().