AlbumShaper  1.0a3
Macros | Functions
sharpen.cpp File Reference
#include <qimage.h>
#include <qstring.h>
#include "sharpen.h"
#include "blur.h"
#include "../tools/imageTools.h"
Include dependency graph for sharpen.cpp:

Go to the source code of this file.

Macros

#define MIN(x, y)   ((x) < (y) ? (x) : (y))
 
#define MAX(x, y)   ((x) < (y) ? (x) : (y))
 

Functions

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

Macro Definition Documentation

§ MAX

#define MAX (   x,
 
)    ((x) < (y) ? (x) : (y))

Definition at line 16 of file sharpen.cpp.

Referenced by sharpenImage().

§ MIN

#define MIN (   x,
 
)    ((x) < (y) ? (x) : (y))

Definition at line 15 of file sharpen.cpp.

Referenced by sharpenImage().

Function Documentation

§ sharpenImage()

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

Definition at line 95 of file sharpen.cpp.

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

Referenced by GrainEditor::adjustImage().

98 {
99  //construct blur copy
100  QImage blurredImage = image.copy();
101  blurImage( blurredImage, sigma );
102 
103  //iterate over each pixel and adjust luminance value
104  int x, y;
105  QRgb *origRgb, *blurredRgb, *edgeRgb;
106  uchar *origScanline;
107  uchar *blurredScanline;
108  uchar *edgesScanline = NULL;
109 
110  for(y=0; y<image.height(); y++)
111  {
112  origScanline = image.scanLine(y);
113  blurredScanline = blurredImage.scanLine(y);
114  if( edgeImage != NULL )
115  {
116  int edgeY = ((edgeImage->height()-1) * (y+offset.y())) / (fullImageRes.height()-1);
117  edgesScanline = edgeImage->scanLine(edgeY);
118  }
119 
120  for(x=0; x<image.width(); x++)
121  {
122  //get rgb triplets
123  origRgb = ((QRgb*)origScanline+x);
124  double r1 = ((double)qRed(*origRgb) )/255.0;
125  double g1 = ((double)qGreen(*origRgb) )/255.0;
126  double b1 = ((double)qBlue(*origRgb) )/255.0;
127 
128  blurredRgb = ((QRgb*)blurredScanline+x);
129  double r2 = ((double)qRed(*blurredRgb) )/255.0;
130  double g2 = ((double)qGreen(*blurredRgb) )/255.0;
131  double b2 = ((double)qBlue(*blurredRgb) )/255.0;
132 
133  //sharpen the entire thing!
134  float alpha;
135  if( edgeImage == NULL)
136  alpha = 1.0f;
137  else
138  {
139  int edgeX = ((edgeImage->width()-1) * (x+offset.x())) / (fullImageRes.width()-1);
140  edgeRgb = ((QRgb*)edgesScanline+edgeX);
141 
142  alpha = ((float) qRed( *edgeRgb )) / 255.0f;
143 
144  //blur regions, not edges
145  if(!blurEdges)
146  alpha = 1.0f - alpha;
147  }
148 
149  //convert to hsv
150  double h1,s1,v1;
151  RGBtoHSV(r1,g1,b1,&h1,&s1,&v1);
152 
153  double h2,s2,v2;
154  RGBtoHSV(r2,g2,b2,&h2,&s2,&v2);
155 
156  //reset v
157  v1 = (alpha * MIN( MAX(2*v1 - v2, 0), 1.0 )) + (1-alpha)*v1;
158 
159  //convert adjusted color back to rgb colorspace and clamp
160  HSVtoRGB( &r1,&g1,&b1, h1,s1,v1);
161  int rp = (int) MIN( MAX((r1*255), 0), 255 );
162  int gp = (int) MIN( MAX((g1*255), 0), 255 );
163  int bp = (int) MIN( MAX((b1*255), 0), 255 );
164 
165  //set adjusted color value
166  *origRgb = qRgb(rp,gp,bp);
167  } //x
168  } //y
169 
170 }
void blurImage(QImage &image, float sigma)
Definition: blur.cpp:94
void HSVtoRGB(double *r, double *g, double *b, double h, double s, double v)
Convert a HSV color triplet to RGB.
Definition: imageTools.cpp:264
QImage * edgeImage
Definition: blur.cpp:87
#define MIN(x, y)
Definition: sharpen.cpp:15
void RGBtoHSV(double r, double g, double b, double *h, double *s, double *v)
Convert a RGB color triplet to HSV.
Definition: imageTools.cpp:231
float b1
Definition: blur.cpp:78
float b2
Definition: blur.cpp:78
#define MAX(x, y)
Definition: sharpen.cpp:16