33 : mColorizeColor( QColor::fromRgb( 255, 128, 128 ) )
43 QPainter *painter = context.
painter();
72 painter->setCompositionMode( mBlendMode );
73 painter->drawImage(
imageOffset( context ), image );
80 props.insert( QStringLiteral(
"enabled" ),
mEnabled ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) );
81 props.insert( QStringLiteral(
"draw_mode" ), QString::number(
int(
mDrawMode ) ) );
82 props.insert( QStringLiteral(
"blend_mode" ), QString::number(
int( mBlendMode ) ) );
83 props.insert( QStringLiteral(
"opacity" ), QString::number( mOpacity ) );
84 props.insert( QStringLiteral(
"brightness" ), QString::number( mBrightness ) );
85 props.insert( QStringLiteral(
"contrast" ), QString::number( mContrast ) );
86 props.insert( QStringLiteral(
"saturation" ), QString::number( mSaturation ) );
87 props.insert( QStringLiteral(
"grayscale_mode" ), QString::number(
int( mGrayscaleMode ) ) );
88 props.insert( QStringLiteral(
"colorize" ), mColorizeOn ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) );
90 props.insert( QStringLiteral(
"colorize_strength" ), QString::number( mColorizeStrength ) );
98 QPainter::CompositionMode mode =
static_cast< QPainter::CompositionMode
>( props.value( QStringLiteral(
"blend_mode" ) ).toInt( &ok ) );
103 if ( props.contains( QStringLiteral(
"transparency" ) ) )
105 double transparency = props.value( QStringLiteral(
"transparency" ) ).toDouble( &ok );
108 mOpacity = 1.0 - transparency;
113 double opacity = props.value( QStringLiteral(
"opacity" ) ).toDouble( &ok );
119 mEnabled = props.value( QStringLiteral(
"enabled" ), QStringLiteral(
"1" ) ).toInt();
122 mBrightness = props.value( QStringLiteral(
"brightness" ), QStringLiteral(
"0" ) ).toInt();
123 mContrast = props.value( QStringLiteral(
"contrast" ), QStringLiteral(
"0" ) ).toInt();
124 mSaturation = props.value( QStringLiteral(
"saturation" ), QStringLiteral(
"1.0" ) ).toDouble();
126 mColorizeOn = props.value( QStringLiteral(
"colorize" ), QStringLiteral(
"0" ) ).toInt();
127 if ( props.contains( QStringLiteral(
"colorize_color" ) ) )
131 mColorizeStrength = props.value( QStringLiteral(
"colorize_strength" ), QStringLiteral(
"100" ) ).toInt();
142 mBrightness = std::clamp(
brightness, -255, 255 );
147 mContrast = std::clamp(
contrast, -100, 100 );
A paint effect which alters the colors (e.g., brightness, contrast) in a source picture.
void readProperties(const QVariantMap &props) override
Reads a string map of an effect's properties and restores the effect to the state described by the pr...
double opacity() const
Returns the opacity for the effect.
QgsColorEffect * clone() const override
Duplicates an effect by creating a deep copy of the effect.
void setColorizeColor(const QColor &colorizeColor)
Sets the color used for colorizing a picture.
static QgsPaintEffect * create(const QVariantMap &map)
Creates a new QgsColorEffect effect from a properties string map.
int contrast() const
Returns the contrast modification for the effect.
int brightness() const
Returns the brightness modification for the effect.
void setContrast(int contrast)
Sets the contrast modification for the effect.
void draw(QgsRenderContext &context) override
Handles drawing of the effect's result on to the specified render context.
void setBrightness(int brightness)
Sets the brightness modification for the effect.
QVariantMap properties() const override
Returns the properties describing the paint effect encoded in a string format.
QColor colorizeColor() const
Returns the color used for colorizing a picture.
static QColor colorFromString(const QString &string)
Decodes a string into a color value.
static QString colorToString(const QColor &color)
Encodes a color into a string value.
bool isCanceled() const
Tells whether the operation has been canceled already.
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 multiplyOpacity(QImage &image, double factor, QgsFeedback *feedback=nullptr)
Multiplies opacity of image pixel values by a factor.
static void adjustBrightnessContrast(QImage &image, int brightness, double contrast, QgsFeedback *feedback=nullptr)
Alter the brightness or contrast of a QImage.
static void convertToGrayscale(QImage &image, GrayscaleMode mode=GrayscaleLuminosity, QgsFeedback *feedback=nullptr)
Convert a QImage to a grayscale image.
GrayscaleMode
Modes for converting a QImage to grayscale.
Base class for visual effects which can be applied to QPicture drawings.
QPointF imageOffset(const QgsRenderContext &context) const
Returns the offset which should be used when drawing the source image on to a destination render cont...
const QPicture * source() const
Returns the source QPicture.
bool enabled() const
Returns whether the effect is enabled.
DrawMode
Drawing modes for effects.
QImage * sourceAsImage(QgsRenderContext &context)
Returns the source QPicture rendered to a new QImage.
Contains information about the context of a rendering operation.
QPainter * painter()
Returns the destination QPainter for the render operation.
QgsFeedback * feedback() const
Returns the feedback object that can be queried regularly during rendering to check if rendering shou...
Scoped object for saving and restoring a QPainter object's state.