18 #ifndef QGSIMAGEOPERATION_H    19 #define QGSIMAGEOPERATION_H    23 #include <QtCore/qmath.h>    68     static void convertToGrayscale( 
QImage &image, 
const GrayscaleMode mode = GrayscaleLuminosity );
    79     static void adjustBrightnessContrast( 
QImage &image, 
const int brightness, 
const double contrast );
    88     static void adjustHueSaturation( 
QImage &image, 
const double saturation, 
const QColor& colorizeColor = 
QColor(),
    89                                      const double colorizeStrength = 1.0 );
    95     static void multiplyOpacity( 
QImage &image, 
const double factor );
   102     static void overlayColor( 
QImage &image, 
const QColor& color );
   108           : shadeExterior( true )
   109           , useMaxDistance( true )
   148     static void stackBlur( 
QImage &image, 
const int radius, 
const bool alphaOnly = 
false );
   157     static QImage* gaussianBlur( 
QImage &image, 
const int radius );
   174     static QRect nonTransparentImageRect( 
const QImage & image, 
QSize minSize = 
QSize(), 
bool center = 
false );
   189     enum LineOperationDirection
   194     template <
class BlockOperation> 
static void runBlockOperationInThreads( 
QImage &image, BlockOperation& operation, LineOperationDirection direction );
   197       unsigned int beginLine;
   198       unsigned int endLine;
   199       unsigned int lineLength;
   204     template <
typename RectOperation> 
static void runRectOperation( 
QImage &image, RectOperation& operation );
   205     template <
class RectOperation> 
static void runRectOperationOnWholeImage( 
QImage &image, RectOperation& operation );
   208     template <
class PixelOperation> 
static void runPixelOperation( 
QImage &image, PixelOperation& operation );
   209     template <
class PixelOperation> 
static void runPixelOperationOnWholeImage( 
QImage &image, PixelOperation& operation );
   210     template <
class PixelOperation>
   211     struct ProcessBlockUsingPixelOperation
   213       explicit ProcessBlockUsingPixelOperation( PixelOperation& operation )
   214           : mOperation( operation ) { }
   216       typedef void result_type;
   218       void operator()( ImageBlock& block )
   220         for ( 
unsigned int y = block.beginLine; y < block.endLine; ++y )
   222           QRgb* ref = 
reinterpret_cast< QRgb* 
>( block.image->scanLine( y ) );
   223           for ( 
unsigned int x = 0; x < block.lineLength; ++x )
   225             mOperation( ref[x], x, y );
   230       PixelOperation& mOperation;
   234     template <
typename LineOperation> 
static void runLineOperation( 
QImage &image, LineOperation& operation );
   235     template <
class LineOperation> 
static void runLineOperationOnWholeImage( 
QImage &image, LineOperation& operation );
   236     template <
class LineOperation>
   237     struct ProcessBlockUsingLineOperation
   239       explicit ProcessBlockUsingLineOperation( LineOperation& operation )
   240           : mOperation( operation ) { }
   242       typedef void result_type;
   244       void operator()( ImageBlock& block )
   247         int bpl = block.image->bytesPerLine();
   248         if ( mOperation.direction() == ByRow )
   250           for ( 
unsigned int y = block.beginLine; y < block.endLine; ++y )
   252             QRgb* ref = 
reinterpret_cast< QRgb* 
>( block.image->scanLine( y ) );
   253             mOperation( ref, block.lineLength, bpl );
   259           unsigned char* ref = block.image->scanLine( 0 ) + 4 * block.beginLine;
   260           for ( 
unsigned int x = block.beginLine; x < block.endLine; ++x, ref += 4 )
   262             mOperation( reinterpret_cast< QRgb* >( ref ), block.lineLength, bpl );
   267       LineOperation& mOperation;
   273     class GrayscalePixelOperation
   280         void operator()( QRgb& rgb, 
const int x, 
const int y );
   285     static void grayscaleLightnessOp( QRgb& rgb );
   286     static void grayscaleLuminosityOp( QRgb& rgb );
   287     static void grayscaleAverageOp( QRgb& rgb );
   290     class BrightnessContrastPixelOperation
   293         BrightnessContrastPixelOperation( 
const int brightness, 
const double contrast )
   294             : mBrightness( brightness )
   295             , mContrast( contrast )
   298         void operator()( QRgb& rgb, 
const int x, 
const int y );
   306     class HueSaturationPixelOperation
   309         HueSaturationPixelOperation( 
const double saturation, 
const bool colorize,
   310                                      const int colorizeHue, 
const int colorizeSaturation,
   311                                      const double colorizeStrength )
   312             : mSaturation( saturation )
   313             , mColorize( colorize )
   314             , mColorizeHue( colorizeHue )
   315             , mColorizeSaturation( colorizeSaturation )
   316             , mColorizeStrength( colorizeStrength )
   319         void operator()( QRgb& rgb, 
const int x, 
const int y );
   325         int mColorizeSaturation;
   326         double mColorizeStrength; 
   328     static int adjustColorComponent( 
int colorComponent, 
int brightness, 
double contrastFactor );
   331     class MultiplyOpacityPixelOperation
   334         explicit MultiplyOpacityPixelOperation( 
const double factor )
   338         void operator()( QRgb& rgb, 
const int x, 
const int y );
   344     class ConvertToArrayPixelOperation
   347         ConvertToArrayPixelOperation( 
const int width, 
double * array, 
const bool exterior = 
true )
   350             , mExterior( exterior )
   354         void operator()( QRgb& rgb, 
const int x, 
const int y );
   362     class ShadeFromArrayOperation
   365         ShadeFromArrayOperation( 
const int width, 
double* array, 
const double spread,
   370             , mProperties( properties )
   372           mSpreadSquared = qPow( mSpread, 2.0 );
   375         void operator()( QRgb& rgb, 
const int x, 
const int y );
   381         double mSpreadSquared;
   384     static void distanceTransform2d( 
double *im, 
int width, 
int height );
   385     static void distanceTransform1d( 
double *f, 
int n, 
int *v, 
double *z, 
double *d );
   386     static double maxValueInDistanceTransformArray( 
const double *array, 
const unsigned int size );
   389     class StackBlurLineOperation
   392         StackBlurLineOperation( 
int alpha, LineOperationDirection direction, 
bool forwardDirection, 
int i1, 
int i2 )
   394             , mDirection( direction )
   395             , mForwardDirection( forwardDirection )
   400         typedef void result_type;
   402         LineOperationDirection direction() { 
return mDirection; }
   404         void operator()( QRgb* startRef, 
const int lineLength, 
const int bytesPerLine );
   408         LineOperationDirection mDirection;
   409         bool mForwardDirection;
   414     static double *createGaussianKernel( 
const int radius );
   416     class GaussianBlurOperation
   419         GaussianBlurOperation( 
int radius, LineOperationDirection direction, 
QImage* destImage, 
double* kernel )
   421             , mDirection( direction )
   422             , mDestImage( destImage )
   423             , mDestImageBpl( destImage->bytesPerLine() )
   427         typedef void result_type;
   429         void operator()( ImageBlock& block );
   433         LineOperationDirection mDirection;
   438         inline QRgb gaussianBlurVertical( 
const int posy, 
unsigned char *sourceFirstLine, 
const int sourceBpl, 
const int height );
   439         inline QRgb gaussianBlurHorizontal( 
const int posx, 
unsigned char *sourceFirstLine, 
const int width );
   445     class FlipLineOperation
   448         explicit FlipLineOperation( LineOperationDirection direction )
   449             : mDirection( direction )
   452         typedef void result_type;
   454         LineOperationDirection direction() { 
return mDirection; }
   456         void operator()( QRgb* startRef, 
const int lineLength, 
const int bytesPerLine );
   459         LineOperationDirection mDirection;
   465 #endif // QGSIMAGEOPERATION_H 
Contains operations and filters which apply to QImages. 
 
FlipType
Flip operation types. 
 
GrayscaleMode
Modes for converting a QImage to grayscale. 
 
Abstract base class for color ramps.