AlbumShaper 1.0a3
emboss.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

QImage * embossEffect (QString filename, ManipulationOptions *options)
 

Function Documentation

◆ embossEffect()

QImage * embossEffect ( QString filename,
ManipulationOptions * options )

Definition at line 85 of file emboss.cpp.

86{
87 //load original image
88 QImage originalImage( filename );
89
90 //convert to 32-bit depth if necessary
91 if( originalImage.depth() < 32 ) { originalImage = originalImage.convertDepth( 32, Qt::AutoColor ); }
92
93 //create edited image
94 QImage* editedImage = new QImage( filename );
95
96 //convert to 32-bit depth if necessary
97 if( editedImage->depth() < 32 )
98 {
99 QImage* tmp = editedImage;
100 editedImage = new QImage( tmp->convertDepth( 32, Qt::AutoColor ) );
101 delete tmp; tmp=NULL;
102 }
103
104 //determine if busy indicators will be used
105 bool useBusyIndicators = false;
106 StatusWidget* status = NULL;
107 if( options != NULL && options->getStatus() != NULL )
108 {
109 useBusyIndicators = true;
110 status = options->getStatus();
111 }
112
113 //setup progress bar
114 if(useBusyIndicators)
115 {
116 QString statusMessage = qApp->translate( "embossEffect", "Applying Emboss Effect:" );
117 status->showProgressBar( statusMessage, 100 );
118 qApp->processEvents();
119 }
120
121 //update progress bar for every 1% of completion
122 const int updateIncrement = (int) ( 0.01 * originalImage.width() * originalImage.height() );
123 int newProgress = 0;
124
125 //iterate over each selected scanline
126 int x, y;
127 QRgb* rgb;
128 uchar* scanLine;
129
130 int yPrev, yNext, xPrev, xNext;
131
132 //compute the radius using image resolution
133 double minDimen = (double) MIN( editedImage->width(), editedImage->height() );
134 const int embossRadius = (int) MAX( 1, (sqrt(minDimen)/8) );
135
136 for( y=0; y<editedImage->height(); y++)
137 {
138 scanLine = originalImage.scanLine(y);
139
140 //compute previous and next y pixel coordinates
141 yPrev = MAX( y-embossRadius, 0 );
142 yNext = MIN( y+embossRadius, editedImage->height() - 1 );
143
144 //iterate over each selected pixel in scanline
145 for( x=0; x<editedImage->width(); x++)
146 {
147 //compute previous and next x pixel coordinates
148 xPrev = MAX( x-embossRadius, 0 );
149 xNext = MIN( x+embossRadius, editedImage->width() - 1 );
150
151 //start with a default luminance of 128 (50% luminance)
152 int sum = 128;
153
154 //sum weighted gray values of neighbors
155 scanLine = originalImage.scanLine( yPrev );
156 sum-= qGray( *((QRgb*)scanLine + xPrev ) );
157 sum-= qGray( *((QRgb*)scanLine + x ) );
158
159 scanLine = originalImage.scanLine( y );
160 sum-= qGray( *((QRgb*)scanLine + xPrev ) );
161 sum+= qGray( *((QRgb*)scanLine + xNext ) );
162
163 scanLine = originalImage.scanLine( yNext );
164 sum+= qGray( *((QRgb*)scanLine + x ) );
165 sum+= qGray( *((QRgb*)scanLine + xNext ) );
166
167 //clamp sum to within 0-255 range
168 sum = MAX( MIN( sum, 255), 0 );
169
170 //get original pixel color in HSV space
171 scanLine = editedImage->scanLine(y);
172 rgb = ((QRgb*)scanLine+x);
173 double r = ((double)qRed(*rgb) )/255.0;
174 double g = ((double)qGreen(*rgb) )/255.0;
175 double b = ((double)qBlue(*rgb) )/255.0;
176
177 //convert to hsv
178 double h,s,v;
179 RGBtoHSV(r,g,b,&h,&s,&v);
180
181 //reset v
182 v = ((double)sum)/255;
183
184 //convert adjusted color back to rgb colorspace and clamp
185 HSVtoRGB( &r,&g,&b, h,s,v);
186 int rp = (int) MIN( MAX((r*255), 0), 255 );
187 int gp = (int) MIN( MAX((g*255), 0), 255 );
188 int bp = (int) MIN( MAX((b*255), 0), 255 );
189
190 //set adjusted color value
191 *rgb = qRgb(rp,gp,bp);
192
193 //update status bar if significant progress has been made since last update
194 if(useBusyIndicators)
195 {
196 newProgress++;
198 {
199 newProgress = 0;
201 qApp->processEvents();
202 }
203 }
204
205 }
206 }
207
208 //return pointer to edited image
209 return editedImage;
210}
StatusWidget * getStatus()
void showProgressBar(QString message, int numSteps)
Initializes the progress bar.
void incrementProgress()
Updates the progress bar by one step.
#define MIN(x, y)
Definition emboss.cpp:17
#define MAX(x, y)
Definition emboss.cpp:18
void RGBtoHSV(double r, double g, double b, double *h, double *s, double *v)
Convert a RGB color triplet to HSV.
void HSVtoRGB(double *r, double *g, double *b, double h, double s, double v)
Convert a HSV color triplet to RGB.
long b
int updateIncrement
QImage * editedImage
StatusWidget * status
int newProgress

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

Referenced by EditingInterface::applyEffect().