00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
#include <qimage.h>
00013
#include <qstring.h>
00014
#include <qapplication.h>
00015
#include <math.h>
00016
00017
00018
#include "emboss.h"
00019
#include "manipulationOptions.h"
00020
#include "../tools/imageTools.h"
00021
#include "../../gui/statusWidget.h"
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082 QImage*
embossEffect( QString filename,
ManipulationOptions* options )
00083 {
00084
00085 QImage originalImage( filename );
00086
00087
00088
if( originalImage.depth() < 32 ) { originalImage = originalImage.convertDepth( 32, Qt::AutoColor ); }
00089
00090
00091 QImage*
editedImage =
new QImage( filename );
00092
00093
00094
if(
editedImage->depth() < 32 )
00095 {
00096 QImage* tmp =
editedImage;
00097
editedImage =
new QImage( tmp->convertDepth( 32, Qt::AutoColor ) );
00098
delete tmp; tmp=NULL;
00099 }
00100
00101
00102
bool useBusyIndicators =
false;
00103
StatusWidget*
status = NULL;
00104
if( options != NULL && options->
getStatus() != NULL )
00105 {
00106 useBusyIndicators =
true;
00107
status = options->
getStatus();
00108 }
00109
00110
00111
if(useBusyIndicators)
00112 {
00113 QString statusMessage = qApp->translate(
"embossEffect",
"Applying Emboss Effect:" );
00114
status->
showProgressBar( statusMessage, 100 );
00115 qApp->processEvents();
00116 }
00117
00118
00119
const int updateIncrement = (
int) ( 0.01 * originalImage.width() * originalImage.height() );
00120
int newProgress = 0;
00121
00122
00123
int x, y;
00124 QRgb* rgb;
00125 uchar* scanLine;
00126
00127
int yPrev, yNext, xPrev, xNext;
00128
00129
00130
double minDimen = (
double) QMIN(
editedImage->width(),
editedImage->height() );
00131
const int embossRadius = (
int) QMAX( 1, (sqrt(minDimen)/8) );
00132
00133
for( y=0; y<
editedImage->height(); y++)
00134 {
00135 scanLine = originalImage.scanLine(y);
00136
00137
00138 yPrev = QMAX( y-embossRadius, 0 );
00139 yNext = QMIN( y+embossRadius,
editedImage->height() - 1 );
00140
00141
00142
for( x=0; x<
editedImage->width(); x++)
00143 {
00144
00145 xPrev = QMAX( x-embossRadius, 0 );
00146 xNext = QMIN( x+embossRadius,
editedImage->width() - 1 );
00147
00148
00149
int sum = 128;
00150
00151
00152 scanLine = originalImage.scanLine( yPrev );
00153 sum-= qGray( *((QRgb*)scanLine + xPrev ) );
00154 sum-= qGray( *((QRgb*)scanLine + x ) );
00155
00156 scanLine = originalImage.scanLine( y );
00157 sum-= qGray( *((QRgb*)scanLine + xPrev ) );
00158 sum+= qGray( *((QRgb*)scanLine + xNext ) );
00159
00160 scanLine = originalImage.scanLine( yNext );
00161 sum+= qGray( *((QRgb*)scanLine + x ) );
00162 sum+= qGray( *((QRgb*)scanLine + xNext ) );
00163
00164
00165 sum = QMAX( QMIN( sum, 255), 0 );
00166
00167
00168 scanLine =
editedImage->scanLine(y);
00169 rgb = ((QRgb*)scanLine+x);
00170
double r = ((
double)qRed(*rgb) )/255.0;
00171
double g = ((
double)qGreen(*rgb) )/255.0;
00172
double b = ((
double)qBlue(*rgb) )/255.0;
00173
00174
00175
double h,s,v;
00176
RGBtoHSV(r,g,
b,&h,&s,&v);
00177
00178
00179 v = ((
double)sum)/255;
00180
00181
00182
HSVtoRGB( &r,&g,&
b, h,s,v);
00183
int rp = (
int) QMIN( QMAX((r*255), 0), 255 );
00184
int gp = (
int) QMIN( QMAX((g*255), 0), 255 );
00185
int bp = (
int) QMIN( QMAX((
b*255), 0), 255 );
00186
00187
00188 *rgb = qRgb(rp,gp,bp);
00189
00190
00191
if(useBusyIndicators)
00192 {
00193
newProgress++;
00194
if(
newProgress >=
updateIncrement)
00195 {
00196
newProgress = 0;
00197
status->
incrementProgress();
00198 qApp->processEvents();
00199 }
00200 }
00201
00202 }
00203 }
00204
00205
00206
return editedImage;
00207 }
00208