14 #include <qapplication.h> 17 #define MIN(x,y) ((x) < (y) ? (x) : (y)) 18 #define MAX(x,y) ((x) < (y) ? (x) : (y)) 23 #include "../tools/imageTools.h" 24 #include "../../gui/statusWidget.h" 88 QImage originalImage( filename );
91 if( originalImage.depth() < 32 ) { originalImage = originalImage.convertDepth( 32, Qt::AutoColor ); }
97 if( editedImage->depth() < 32 )
100 editedImage =
new QImage( tmp->convertDepth( 32, Qt::AutoColor ) );
101 delete tmp; tmp=NULL;
105 bool useBusyIndicators =
false;
107 if( options != NULL && options->
getStatus() != NULL )
109 useBusyIndicators =
true;
114 if(useBusyIndicators)
116 QString statusMessage = qApp->translate(
"embossEffect",
"Applying Emboss Effect:" );
118 qApp->processEvents();
122 const int updateIncrement = (int) ( 0.01 * originalImage.width() * originalImage.height() );
130 int yPrev, yNext, xPrev, xNext;
133 double minDimen = (double)
MIN( editedImage->width(), editedImage->height() );
134 const int embossRadius = (int)
MAX( 1, (sqrt(minDimen)/8) );
136 for( y=0; y<editedImage->height(); y++)
138 scanLine = originalImage.scanLine(y);
141 yPrev =
MAX( y-embossRadius, 0 );
142 yNext =
MIN( y+embossRadius, editedImage->height() - 1 );
145 for( x=0; x<editedImage->width(); x++)
148 xPrev =
MAX( x-embossRadius, 0 );
149 xNext =
MIN( x+embossRadius, editedImage->width() - 1 );
155 scanLine = originalImage.scanLine( yPrev );
156 sum-= qGray( *((QRgb*)scanLine + xPrev ) );
157 sum-= qGray( *((QRgb*)scanLine + x ) );
159 scanLine = originalImage.scanLine( y );
160 sum-= qGray( *((QRgb*)scanLine + xPrev ) );
161 sum+= qGray( *((QRgb*)scanLine + xNext ) );
163 scanLine = originalImage.scanLine( yNext );
164 sum+= qGray( *((QRgb*)scanLine + x ) );
165 sum+= qGray( *((QRgb*)scanLine + xNext ) );
168 sum =
MAX(
MIN( sum, 255), 0 );
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;
182 v = ((double)sum)/255;
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 );
191 *rgb = qRgb(rp,gp,bp);
194 if(useBusyIndicators)
197 if(newProgress >= updateIncrement)
201 qApp->processEvents();
StatusWidget * getStatus()
QImage * embossEffect(QString filename, ManipulationOptions *options)