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

sharpen.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

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 21 of file sharpen.cpp.

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

Referenced by GrainEditor::adjustImage().

00024 {
00025   //construct blur copy
00026   QImage blurredImage = image.copy();
00027   blurImage( blurredImage, sigma );
00028   
00029   //iterate over each pixel and adjust luminance value
00030   int x, y;
00031   QRgb *origRgb, *blurredRgb, *edgeRgb;
00032   uchar *origScanline;
00033   uchar *blurredScanline;
00034   uchar *edgesScanline = NULL;
00035   
00036   for(y=0; y<image.height(); y++)
00037   {
00038     origScanline = image.scanLine(y);
00039     blurredScanline = blurredImage.scanLine(y);
00040     if( edgeImage != NULL )
00041     {
00042       int edgeY = ((edgeImage->height()-1) * (y+offset.y())) / (fullImageRes.height()-1);
00043       edgesScanline = edgeImage->scanLine(edgeY);
00044     }
00045     
00046     for(x=0; x<image.width(); x++)
00047     {
00048       //get rgb triplets
00049       origRgb = ((QRgb*)origScanline+x);
00050       double r1 = ((double)qRed(*origRgb)   )/255.0;
00051       double g1 = ((double)qGreen(*origRgb) )/255.0;
00052       double b1 = ((double)qBlue(*origRgb)  )/255.0;
00053       
00054       blurredRgb = ((QRgb*)blurredScanline+x);
00055       double r2 = ((double)qRed(*blurredRgb)   )/255.0;
00056       double g2 = ((double)qGreen(*blurredRgb) )/255.0;
00057       double b2 = ((double)qBlue(*blurredRgb)  )/255.0;
00058 
00059       //sharpen the entire thing!
00060       float alpha;
00061       if( edgeImage == NULL)
00062         alpha = 1.0f;
00063       else
00064       {
00065         int edgeX = ((edgeImage->width()-1) * (x+offset.x())) / (fullImageRes.width()-1);
00066         edgeRgb = ((QRgb*)edgesScanline+edgeX);
00067         
00068         alpha = ((float) qRed( *edgeRgb )) / 255.0f;
00069         
00070         //blur regions, not edges
00071         if(!blurEdges)
00072           alpha = 1.0f - alpha;
00073       }
00074       
00075       //convert to hsv
00076       double h1,s1,v1;
00077       RGBtoHSV(r1,g1,b1,&h1,&s1,&v1);
00078 
00079       double h2,s2,v2;
00080       RGBtoHSV(r2,g2,b2,&h2,&s2,&v2);
00081       
00082       //reset v
00083       v1  = (alpha * QMIN( QMAX(2*v1 - v2, 0), 1.0 )) + (1-alpha)*v1;
00084       
00085       //convert adjusted color back to rgb colorspace and clamp
00086       HSVtoRGB( &r1,&g1,&b1, h1,s1,v1);         
00087       int rp = (int) QMIN( QMAX((r1*255), 0), 255 );
00088       int gp = (int) QMIN( QMAX((g1*255), 0), 255 );
00089       int bp = (int) QMIN( QMAX((b1*255), 0), 255 );
00090       
00091       //set adjusted color value
00092       *origRgb = qRgb(rp,gp,bp);
00093     } //x
00094   } //y
00095 
00096 }


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