|
AlbumShaper
1.0a3
|

Go to the source code of this file.
Functions | |
| void | sharpenImage (QImage &image, float sigma, QPoint offset, QSize fullImageRes, QImage *edgeImage, bool blurEdges) |
| 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().
{
//construct blur copy
QImage blurredImage = image.copy();
blurImage( blurredImage, sigma );
//iterate over each pixel and adjust luminance value
int x, y;
QRgb *origRgb, *blurredRgb, *edgeRgb;
uchar *origScanline;
uchar *blurredScanline;
uchar *edgesScanline = NULL;
for(y=0; y<image.height(); y++)
{
origScanline = image.scanLine(y);
blurredScanline = blurredImage.scanLine(y);
if( edgeImage != NULL )
{
int edgeY = ((edgeImage->height()-1) * (y+offset.y())) / (fullImageRes.height()-1);
edgesScanline = edgeImage->scanLine(edgeY);
}
for(x=0; x<image.width(); x++)
{
//get rgb triplets
origRgb = ((QRgb*)origScanline+x);
double r1 = ((double)qRed(*origRgb) )/255.0;
double g1 = ((double)qGreen(*origRgb) )/255.0;
double b1 = ((double)qBlue(*origRgb) )/255.0;
blurredRgb = ((QRgb*)blurredScanline+x);
double r2 = ((double)qRed(*blurredRgb) )/255.0;
double g2 = ((double)qGreen(*blurredRgb) )/255.0;
double b2 = ((double)qBlue(*blurredRgb) )/255.0;
//sharpen the entire thing!
float alpha;
if( edgeImage == NULL)
alpha = 1.0f;
else
{
int edgeX = ((edgeImage->width()-1) * (x+offset.x())) / (fullImageRes.width()-1);
edgeRgb = ((QRgb*)edgesScanline+edgeX);
alpha = ((float) qRed( *edgeRgb )) / 255.0f;
//blur regions, not edges
if(!blurEdges)
alpha = 1.0f - alpha;
}
//convert to hsv
double h1,s1,v1;
RGBtoHSV(r1,g1,b1,&h1,&s1,&v1);
double h2,s2,v2;
RGBtoHSV(r2,g2,b2,&h2,&s2,&v2);
//reset v
v1 = (alpha * QMIN( QMAX(2*v1 - v2, 0), 1.0 )) + (1-alpha)*v1;
//convert adjusted color back to rgb colorspace and clamp
HSVtoRGB( &r1,&g1,&b1, h1,s1,v1);
int rp = (int) QMIN( QMAX((r1*255), 0), 255 );
int gp = (int) QMIN( QMAX((g1*255), 0), 255 );
int bp = (int) QMIN( QMAX((b1*255), 0), 255 );
//set adjusted color value
*origRgb = qRgb(rp,gp,bp);
} //x
} //y
}
1.7.5.1