sharpen.h File Reference

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

Go to the source code of this file.

Functions

void sharpenImage (QImage &image, float sigma, QPoint offset, QSize fullImageRes, QImage *edgeImage, bool blurEdges)


Function Documentation

void sharpenImage ( QImage &  image,
float  sigma,
QPoint  offset,
QSize  fullImageRes,
QImage *  edgeImage,
bool  blurEdges 
)

Definition at line 92 of file sharpen.cpp.

References b1, b2, blurImage(), HSVtoRGB(), and RGBtoHSV().

Referenced by GrainEditor::adjustImage().

00095 {
00096   //construct blur copy
00097   QImage blurredImage = image.copy();
00098   blurImage( blurredImage, sigma );
00099   
00100   //iterate over each pixel and adjust luminance value
00101   int x, y;
00102   QRgb *origRgb, *blurredRgb, *edgeRgb;
00103   uchar *origScanline;
00104   uchar *blurredScanline;
00105   uchar *edgesScanline = NULL;
00106   
00107   for(y=0; y<image.height(); y++)
00108   {
00109     origScanline = image.scanLine(y);
00110     blurredScanline = blurredImage.scanLine(y);
00111     if( edgeImage != NULL )
00112     {
00113       int edgeY = ((edgeImage->height()-1) * (y+offset.y())) / (fullImageRes.height()-1);
00114       edgesScanline = edgeImage->scanLine(edgeY);
00115     }
00116     
00117     for(x=0; x<image.width(); x++)
00118     {
00119       //get rgb triplets
00120       origRgb = ((QRgb*)origScanline+x);
00121       double r1 = ((double)qRed(*origRgb)   )/255.0;
00122       double g1 = ((double)qGreen(*origRgb) )/255.0;
00123       double b1 = ((double)qBlue(*origRgb)  )/255.0;
00124       
00125       blurredRgb = ((QRgb*)blurredScanline+x);
00126       double r2 = ((double)qRed(*blurredRgb)   )/255.0;
00127       double g2 = ((double)qGreen(*blurredRgb) )/255.0;
00128       double b2 = ((double)qBlue(*blurredRgb)  )/255.0;
00129 
00130       //sharpen the entire thing!
00131       float alpha;
00132       if( edgeImage == NULL)
00133         alpha = 1.0f;
00134       else
00135       {
00136         int edgeX = ((edgeImage->width()-1) * (x+offset.x())) / (fullImageRes.width()-1);
00137         edgeRgb = ((QRgb*)edgesScanline+edgeX);
00138         
00139         alpha = ((float) qRed( *edgeRgb )) / 255.0f;
00140         
00141         //blur regions, not edges
00142         if(!blurEdges)
00143           alpha = 1.0f - alpha;
00144       }
00145       
00146       //convert to hsv
00147       double h1,s1,v1;
00148       RGBtoHSV(r1,g1,b1,&h1,&s1,&v1);
00149 
00150       double h2,s2,v2;
00151       RGBtoHSV(r2,g2,b2,&h2,&s2,&v2);
00152       
00153       //reset v
00154       v1  = (alpha * QMIN( QMAX(2*v1 - v2, 0), 1.0 )) + (1-alpha)*v1;
00155       
00156       //convert adjusted color back to rgb colorspace and clamp
00157       HSVtoRGB( &r1,&g1,&b1, h1,s1,v1);         
00158       int rp = (int) QMIN( QMAX((r1*255), 0), 255 );
00159       int gp = (int) QMIN( QMAX((g1*255), 0), 255 );
00160       int bp = (int) QMIN( QMAX((b1*255), 0), 255 );
00161       
00162       //set adjusted color value
00163       *origRgb = qRgb(rp,gp,bp);
00164     } //x
00165   } //y
00166 
00167 }


Generated on Sun Aug 23 02:34:32 2009 for AlbumShaper by  doxygen 1.5.9