QGIS API Documentation 3.41.0-Master (45a0abf3bec)
Loading...
Searching...
No Matches
Classes | Public Types | Static Public Member Functions | List of all members
QgsImageOperation Class Reference

Contains operations and filters which apply to QImages. More...

#include <qgsimageoperation.h>

Classes

struct  DistanceTransformProperties
 Struct for storing properties of a distance transform operation. More...
 

Public Types

enum  FlipType { FlipHorizontal , FlipVertical }
 Flip operation types. More...
 
enum  GrayscaleMode { GrayscaleLightness , GrayscaleLuminosity , GrayscaleAverage , GrayscaleOff }
 Modes for converting a QImage to grayscale. More...
 

Static Public Member Functions

static void adjustBrightnessContrast (QImage &image, int brightness, double contrast, QgsFeedback *feedback=nullptr)
 Alter the brightness or contrast of a QImage.
 
static void adjustHueSaturation (QImage &image, double saturation, const QColor &colorizeColor=QColor(), double colorizeStrength=1.0, QgsFeedback *feedback=nullptr)
 Alter the hue or saturation of a QImage.
 
static void convertToGrayscale (QImage &image, GrayscaleMode mode=GrayscaleLuminosity, QgsFeedback *feedback=nullptr)
 Convert a QImage to a grayscale image.
 
static QImage cropTransparent (const QImage &image, QSize minSize=QSize(), bool center=false)
 Crop any transparent border from around an image.
 
static void distanceTransform (QImage &image, const QgsImageOperation::DistanceTransformProperties &properties, QgsFeedback *feedback=nullptr)
 Performs a distance transform on the source image and shades the result using a color ramp.
 
static void flipImage (QImage &image, FlipType type)
 Flips an image horizontally or vertically.
 
static QImage * gaussianBlur (QImage &image, int radius, QgsFeedback *feedback=nullptr)
 Performs a gaussian blur on an image.
 
static void multiplyOpacity (QImage &image, double factor, QgsFeedback *feedback=nullptr)
 Multiplies opacity of image pixel values by a factor.
 
static QRect nonTransparentImageRect (const QImage &image, QSize minSize=QSize(), bool center=false)
 Calculates the non-transparent region of an image.
 
static void overlayColor (QImage &image, const QColor &color)
 Overlays a color onto an image.
 
static void stackBlur (QImage &image, int radius, bool alphaOnly=false, QgsFeedback *feedback=nullptr)
 Performs a stack blur on an image.
 

Detailed Description

Contains operations and filters which apply to QImages.

A set of optimised pixel manipulation operations and filters which can be applied to QImages. All operations only apply to ARGB32 format images, and it is left up to the calling procedure to ensure that any passed images are of the correct format.

Operations are written to either modify an image in place or return a new image, depending on which is faster for the particular operation.

Definition at line 46 of file qgsimageoperation.h.

Member Enumeration Documentation

◆ FlipType

Flip operation types.

Enumerator
FlipHorizontal 

Flip the image horizontally.

FlipVertical 

Flip the image vertically.

Definition at line 65 of file qgsimageoperation.h.

◆ GrayscaleMode

Modes for converting a QImage to grayscale.

Enumerator
GrayscaleLightness 

Keep the lightness of the color, drops the saturation.

GrayscaleLuminosity 

Grayscale by perceptual luminosity (weighted sum of color RGB components)

GrayscaleAverage 

Grayscale by taking average of color RGB components.

GrayscaleOff 

No change.

Definition at line 54 of file qgsimageoperation.h.

Member Function Documentation

◆ adjustBrightnessContrast()

void QgsImageOperation::adjustBrightnessContrast ( QImage &  image,
int  brightness,
double  contrast,
QgsFeedback feedback = nullptr 
)
static

Alter the brightness or contrast of a QImage.

Parameters
imageQImage to alter
brightnessbrightness value, in the range -255 to 255. A brightness value of 0 indicates no change to brightness, a negative value will darken the image, and a positive value will brighten the image.
contrastcontrast value. Must be a positive or zero value. A value of 1.0 indicates no change to the contrast, a value of 0 represents an image with 0 contrast, and a value > 1.0 will increase the contrast of the image.
feedbackoptional feedback object for responsive cancellation (since QGIS 3.22)

Definition at line 256 of file qgsimageoperation.cpp.

◆ adjustHueSaturation()

void QgsImageOperation::adjustHueSaturation ( QImage &  image,
double  saturation,
const QColor &  colorizeColor = QColor(),
double  colorizeStrength = 1.0,
QgsFeedback feedback = nullptr 
)
static

Alter the hue or saturation of a QImage.

Parameters
imageQImage to alter
saturationdouble between 0 and 2 inclusive, where 0 = desaturate and 1.0 = no change
colorizeColorcolor to use for colorizing image. Set to an invalid QColor to disable colorization.
colorizeStrengthdouble between 0 and 1, where 0 = no colorization and 1.0 = full colorization
feedbackoptional feedback object for responsive cancellation (since QGIS 3.22)

Definition at line 280 of file qgsimageoperation.cpp.

◆ convertToGrayscale()

void QgsImageOperation::convertToGrayscale ( QImage &  image,
GrayscaleMode  mode = GrayscaleLuminosity,
QgsFeedback feedback = nullptr 
)
static

Convert a QImage to a grayscale image.

Alpha channel is preserved.

Parameters
imageQImage to convert
modemode to use during grayscale conversion
feedbackoptional feedback object for responsive cancellation (since QGIS 3.22)

Definition at line 195 of file qgsimageoperation.cpp.

◆ cropTransparent()

QImage QgsImageOperation::cropTransparent ( const QImage &  image,
QSize  minSize = QSize(),
bool  center = false 
)
static

Crop any transparent border from around an image.

Parameters
imagesource image
minSizeminimum size for cropped image, if desired. If the cropped image is smaller than the minimum size, it will be centered in the returned image.
centercropped image will be centered on the center of the original image if set to true

Definition at line 959 of file qgsimageoperation.cpp.

◆ distanceTransform()

void QgsImageOperation::distanceTransform ( QImage &  image,
const QgsImageOperation::DistanceTransformProperties properties,
QgsFeedback feedback = nullptr 
)
static

Performs a distance transform on the source image and shades the result using a color ramp.

Parameters
imageQImage to alter
propertiesDistanceTransformProperties object with parameters for the distance transform operation
feedbackoptional feedback object for responsive cancellation (since QGIS 3.22)

Definition at line 391 of file qgsimageoperation.cpp.

◆ flipImage()

void QgsImageOperation::flipImage ( QImage &  image,
QgsImageOperation::FlipType  type 
)
static

Flips an image horizontally or vertically.

Parameters
imageQImage to flip
typetype of flip to perform (horizontal or vertical)

Definition at line 847 of file qgsimageoperation.cpp.

◆ gaussianBlur()

QImage * QgsImageOperation::gaussianBlur ( QImage &  image,
int  radius,
QgsFeedback feedback = nullptr 
)
static

Performs a gaussian blur on an image.

Gaussian blur is slower but results in a high quality blur.

Parameters
imageQImage to blur
radiusblur radius in pixels
feedbackoptional feedback object for responsive cancellation (since QGIS 3.22)
Returns
blurred image
Note
for fastest operation, ensure the source image is ARGB32_Premultiplied

Definition at line 655 of file qgsimageoperation.cpp.

◆ multiplyOpacity()

void QgsImageOperation::multiplyOpacity ( QImage &  image,
double  factor,
QgsFeedback feedback = nullptr 
)
static

Multiplies opacity of image pixel values by a factor.

Parameters
imageQImage to alter
factorfactor to multiple pixel's opacity by
feedbackoptional feedback object for responsive cancellation (since QGIS 3.22)

Definition at line 335 of file qgsimageoperation.cpp.

◆ nonTransparentImageRect()

QRect QgsImageOperation::nonTransparentImageRect ( const QImage &  image,
QSize  minSize = QSize(),
bool  center = false 
)
static

Calculates the non-transparent region of an image.

Parameters
imagesource image
minSizeminimum size for returned region, if desired. If the non-transparent region of the image is smaller than this minimum size, it will be centered in the returned rectangle.
centerreturn rectangle will be centered on the center of the original image if set to true
See also
cropTransparent

Definition at line 854 of file qgsimageoperation.cpp.

◆ overlayColor()

void QgsImageOperation::overlayColor ( QImage &  image,
const QColor &  color 
)
static

Overlays a color onto an image.

This operation retains the alpha channel of the original image, but replaces all image pixel colors with the specified color.

Parameters
imageQImage to alter
colorcolor to overlay (any alpha component of the color is ignored)

Definition at line 375 of file qgsimageoperation.cpp.

◆ stackBlur()

void QgsImageOperation::stackBlur ( QImage &  image,
int  radius,
bool  alphaOnly = false,
QgsFeedback feedback = nullptr 
)
static

Performs a stack blur on an image.

Stack blur represents a good balance between speed and blur quality.

Parameters
imageQImage to blur
radiusblur radius in pixels, maximum value of 16
alphaOnlyset to true to blur only the alpha component of the image
feedbackoptional feedback object for responsive cancellation (since QGIS 3.22)
Note
for fastest operation, ensure the source image is ARGB32_Premultiplied if alphaOnly is set to false, or ARGB32 if alphaOnly is true

Definition at line 589 of file qgsimageoperation.cpp.


The documentation for this class was generated from the following files: