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

emboss.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 * embossEffect (QString filename, ManipulationOptions *options)


Function Documentation

QImage* embossEffect QString  filename,
ManipulationOptions options
 

Definition at line 82 of file emboss.cpp.

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

Referenced by EditingInterface::applyEffect().

00083 {
00084   //load original image  
00085   QImage originalImage( filename );
00086 
00087   //convert to 32-bit depth if necessary
00088   if( originalImage.depth() < 32 ) { originalImage = originalImage.convertDepth( 32, Qt::AutoColor ); }
00089   
00090   //create edited image
00091   QImage* editedImage = new QImage( filename );
00092 
00093   //convert to 32-bit depth if necessary
00094   if( editedImage->depth() < 32 )
00095   {
00096     QImage* tmp = editedImage;
00097     editedImage = new QImage( tmp->convertDepth( 32, Qt::AutoColor ) );
00098     delete tmp; tmp=NULL;
00099   }
00100   
00101   //determine if busy indicators will be used
00102   bool useBusyIndicators = false;
00103   StatusWidget* status = NULL;
00104   if( options != NULL && options->getStatus() != NULL )
00105   {
00106     useBusyIndicators = true;
00107     status = options->getStatus(); 
00108   }
00109   
00110   //setup progress bar
00111   if(useBusyIndicators)
00112   {
00113     QString statusMessage = qApp->translate( "embossEffect", "Applying Emboss Effect:" );
00114     status->showProgressBar( statusMessage, 100 );
00115     qApp->processEvents();  
00116   }
00117   
00118   //update progress bar for every 1% of completion
00119   const int updateIncrement = (int) ( 0.01 * originalImage.width() * originalImage.height() );
00120   int newProgress = 0; 
00121 
00122   //iterate over each selected scanline 
00123   int x, y;
00124   QRgb* rgb;
00125   uchar* scanLine;
00126 
00127   int yPrev, yNext, xPrev, xNext;
00128   
00129   //compute the radius using image resolution
00130   double minDimen = (double) QMIN( editedImage->width(), editedImage->height() );  
00131   const int embossRadius = (int) QMAX( 1, (sqrt(minDimen)/8) );
00132   
00133   for( y=0; y<editedImage->height(); y++)
00134   {   
00135     scanLine = originalImage.scanLine(y);
00136 
00137     //compute previous and next y pixel coordinates
00138     yPrev = QMAX( y-embossRadius, 0 );
00139     yNext = QMIN( y+embossRadius, editedImage->height() - 1 );
00140     
00141     //iterate over each selected pixel in scanline
00142     for( x=0; x<editedImage->width(); x++)
00143     {
00144       //compute previous and next x  pixel coordinates
00145       xPrev = QMAX( x-embossRadius, 0 );
00146       xNext = QMIN( x+embossRadius, editedImage->width() - 1 );
00147 
00148       //start with a default luminance of 128 (50% luminance)
00149       int sum = 128;
00150       
00151       //sum weighted gray values of neighbors
00152       scanLine = originalImage.scanLine( yPrev );
00153       sum-= qGray( *((QRgb*)scanLine + xPrev ) );
00154       sum-= qGray( *((QRgb*)scanLine + x ) );
00155 
00156       scanLine = originalImage.scanLine( y );
00157       sum-= qGray( *((QRgb*)scanLine + xPrev ) );
00158       sum+= qGray( *((QRgb*)scanLine + xNext ) );
00159 
00160       scanLine = originalImage.scanLine( yNext );
00161       sum+= qGray( *((QRgb*)scanLine + x ) );
00162       sum+= qGray( *((QRgb*)scanLine + xNext ) );
00163       
00164       //clamp sum to within 0-255 range
00165       sum = QMAX( QMIN( sum, 255), 0 );
00166 
00167       //get original pixel color in HSV space
00168       scanLine = editedImage->scanLine(y);            
00169       rgb = ((QRgb*)scanLine+x);
00170       double r = ((double)qRed(*rgb)   )/255.0;
00171       double g = ((double)qGreen(*rgb) )/255.0;
00172       double b = ((double)qBlue(*rgb)  )/255.0;
00173       
00174       //convert to hsv
00175       double h,s,v;
00176       RGBtoHSV(r,g,b,&h,&s,&v);
00177       
00178       //reset v
00179       v = ((double)sum)/255;
00180       
00181       //convert adjusted color back to rgb colorspace and clamp
00182       HSVtoRGB( &r,&g,&b, h,s,v);         
00183       int rp = (int) QMIN( QMAX((r*255), 0), 255 );
00184       int gp = (int) QMIN( QMAX((g*255), 0), 255 );
00185       int bp = (int) QMIN( QMAX((b*255), 0), 255 );
00186       
00187       //set adjusted color value
00188       *rgb = qRgb(rp,gp,bp);
00189       
00190       //update status bar if significant progress has been made since last update
00191       if(useBusyIndicators)
00192       {
00193         newProgress++;
00194         if(newProgress >= updateIncrement)
00195         {
00196           newProgress = 0;
00197           status->incrementProgress();
00198           qApp->processEvents();  
00199         }
00200       }
00201       
00202     }
00203   }
00204   
00205   //return pointer to edited image
00206   return editedImage;  
00207 }


Generated on Mon Apr 11 18:27:57 2005 for AlbumShaper by  doxygen 1.3.9.1