#include <qimage.h>
#include <qstring.h>
#include <qapplication.h>
#include <math.h>
#include "emboss.h"
#include "../tools/imageTools.h"
#include "../../gui/statusWidget.h"
Include dependency graph for emboss.cpp:
Go to the source code of this file.
Functions | |
QImage * | embossEffect (QString filename, StatusWidget *status) |
|
Definition at line 81 of file emboss.cpp. References b, editedImage, HSVtoRGB(), StatusWidget::incrementProgress(), newProgress, RGBtoHSV(), StatusWidget::showProgressBar(), status, and updateIncrement. Referenced by EditingInterface::applyEffect(). 00082 { 00083 //load original image 00084 QImage originalImage( filename ); 00085 00086 //create edited image 00087 QImage* editedImage = new QImage( filename ); 00088 00089 //determine if busy indicators will be used 00090 bool useBusyIndicators = (status != NULL); 00091 00092 //setup progress bar 00093 if(useBusyIndicators) 00094 { 00095 QString statusMessage = qApp->translate( "embossEffect", "Applying Emboss Effect:" ); 00096 status->showProgressBar( statusMessage, 100 ); 00097 qApp->processEvents(); 00098 } 00099 00100 //update progress bar for every 1% of completion 00101 const int updateIncrement = (int) ( 0.01 * originalImage.width() * originalImage.height() ); 00102 int newProgress = 0; 00103 00104 //iterate over each selected scanline 00105 int x, y; 00106 QRgb* rgb; 00107 uchar* scanLine; 00108 00109 int yPrev, yNext, xPrev, xNext; 00110 00111 //compute the radius using image resolution 00112 double minDimen = (double) QMIN( editedImage->width(), editedImage->height() ); 00113 const int embossRadius = (int) QMAX( 1, (sqrt(minDimen)/8) ); 00114 00115 for( y=0; y<editedImage->height(); y++) 00116 { 00117 scanLine = originalImage.scanLine(y); 00118 00119 //compute previous and next y pixel coordinates 00120 yPrev = QMAX( y-embossRadius, 0 ); 00121 yNext = QMIN( y+embossRadius, editedImage->height() - 1 ); 00122 00123 //iterate over each selected pixel in scanline 00124 for( x=0; x<editedImage->width(); x++) 00125 { 00126 //compute previous and next x pixel coordinates 00127 xPrev = QMAX( x-embossRadius, 0 ); 00128 xNext = QMIN( x+embossRadius, editedImage->width() - 1 ); 00129 00130 //start with a default luminance of 128 (50% luminance) 00131 int sum = 128; 00132 00133 //sum weighted gray values of neighbors 00134 scanLine = originalImage.scanLine( yPrev ); 00135 sum-= qGray( *((QRgb*)scanLine + xPrev ) ); 00136 sum-= qGray( *((QRgb*)scanLine + x ) ); 00137 00138 scanLine = originalImage.scanLine( y ); 00139 sum-= qGray( *((QRgb*)scanLine + xPrev ) ); 00140 sum+= qGray( *((QRgb*)scanLine + xNext ) ); 00141 00142 scanLine = originalImage.scanLine( yNext ); 00143 sum+= qGray( *((QRgb*)scanLine + x ) ); 00144 sum+= qGray( *((QRgb*)scanLine + xNext ) ); 00145 00146 //clamp sum to within 0-255 range 00147 sum = QMAX( QMIN( sum, 255), 0 ); 00148 00149 //get original pixel color in HSV space 00150 scanLine = editedImage->scanLine(y); 00151 rgb = ((QRgb*)scanLine+x); 00152 double r = ((double)qRed(*rgb) )/255.0; 00153 double g = ((double)qGreen(*rgb) )/255.0; 00154 double b = ((double)qBlue(*rgb) )/255.0; 00155 00156 //convert to hsv 00157 double h,s,v; 00158 RGBtoHSV(r,g,b,&h,&s,&v); 00159 00160 //reset v 00161 v = ((double)sum)/255; 00162 00163 //convert adjusted color back to rgb colorspace and clamp 00164 HSVtoRGB( &r,&g,&b, h,s,v); 00165 int rp = (int) QMIN( QMAX((r*255), 0), 255 ); 00166 int gp = (int) QMIN( QMAX((g*255), 0), 255 ); 00167 int bp = (int) QMIN( QMAX((b*255), 0), 255 ); 00168 00169 //set adjusted color value 00170 *rgb = qRgb(rp,gp,bp); 00171 00172 //update status bar if significant progress has been made since last update 00173 if(useBusyIndicators) 00174 { 00175 newProgress++; 00176 if(newProgress >= updateIncrement) 00177 { 00178 newProgress = 0; 00179 status->incrementProgress(); 00180 qApp->processEvents(); 00181 } 00182 } 00183 00184 } 00185 } 00186 00187 //return pointer to edited image 00188 return editedImage; 00189 }
|