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

blackWhite.h File Reference

This graph shows which files directly or indirectly include this file:

Included by dependency graph

Go to the source code of this file.

Functions

QImage * blackWhiteEffect (QString filename, StatusWidget *status)


Function Documentation

QImage* blackWhiteEffect QString  filename,
StatusWidget status
 

Definition at line 51 of file blackWhite.cpp.

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

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

00052 {
00053   //load image
00054   QImage* editedImage = new QImage( filename );
00055    
00056   //determine if busy indicators will be used
00057   bool useBusyIndicators = (status != NULL);
00058   
00059   //setup progress bar
00060   if(useBusyIndicators)
00061   {
00062     QString statusMessage = qApp->translate( "blackWhiteEffect", "Applying Black + White Effect:" );
00063     status->showProgressBar( statusMessage, 100 );
00064     qApp->processEvents();  
00065   }
00066   
00067   //update progress bar for every 1% of completion
00068   const int updateIncrement = (int) ( 0.01 * editedImage->width() * editedImage->height() );
00069   int newProgress = 0; 
00070 
00071   //iterate over each selected scanline 
00072   int x, y, grayValue;
00073   QRgb* rgb;
00074   uchar* scanLine;
00075   for( y=0; y<editedImage->height(); y++)
00076   {   
00077     //iterate over each selected pixel in scanline
00078     scanLine = editedImage->scanLine(y);
00079     for( x=0; x<editedImage->width(); x++)
00080     {
00081       //compute gray value based on the display luminance of color coordinates
00082       rgb = ((QRgb*)scanLine+x);
00083       grayValue = (int) (0.3*qRed(*rgb) + 0.59*qGreen(*rgb) + 0.11*qBlue(*rgb));
00084       
00085       //clamp to ensure it falls in the 0-255 range
00086       grayValue = QMIN( QMAX( grayValue, 0 ), 255 );      
00087       
00088       //set pixel channel values using computed gray value
00089       *rgb = qRgb( grayValue, grayValue, grayValue );      
00090 
00091       //update status bar if significant progress has been made since last update
00092       if(useBusyIndicators)
00093       {
00094         newProgress++;
00095         if(newProgress >= updateIncrement)
00096         {
00097           newProgress = 0;
00098           status->incrementProgress();
00099           qApp->processEvents();  
00100         }
00101       }
00102 
00103     }
00104   }
00105    
00106   //return pointer to edited image
00107   return editedImage;  
00108 }


Generated on Sat Apr 2 05:44:09 2005 for AlbumShaper by  doxygen 1.3.9.1