void QgsGlowEffect::draw( QgsRenderContext &context ) { if ( !source() || !enabled() || !context.painter() ) return; QImage im = sourceAsImage( context )->copy(); QgsColorRamp* ramp = nullptr; if ( mColorType == ColorRamp && mRamp ) { ramp = mRamp; } else { //create a temporary ramp QColor transparentColor = mColor; transparentColor.setAlpha( 0 ); ramp = new QgsGradientColorRamp( mColor, transparentColor ); } QgsImageOperation::DistanceTransformProperties dtProps; dtProps.spread = mSpread * QgsSymbolLayerUtils::pixelSizeScaleFactor( context, mSpreadUnit, mSpreadMapUnitScale ); dtProps.useMaxDistance = false; dtProps.shadeExterior = shadeExterior(); dtProps.ramp = ramp; QgsImageOperation::distanceTransform( im, dtProps ); if ( mBlurLevel > 0 ) { QgsImageOperation::stackBlur( im, mBlurLevel ); } QgsImageOperation::multiplyOpacity( im, 1.0 - mTransparency ); if ( !shadeExterior() ) { //only keep interior portion QPainter p( &im ); p.setRenderHint( QPainter::Antialiasing ); p.setCompositionMode( QPainter::CompositionMode_DestinationIn ); p.drawImage( 0, 0, *sourceAsImage( context ) ); p.end(); } QPainter* painter = context.painter(); painter->save(); painter->setCompositionMode( mBlendMode ); painter->drawImage( imageOffset( context ), im ); painter->restore(); if ( !mRamp ) { //delete temporary ramp delete ramp; } }
void QgsDrawSourceEffect::draw( QgsRenderContext &context ) { if ( !enabled() || !context.painter() ) return; QPainter *painter = context.painter(); if ( mBlendMode == QPainter::CompositionMode_SourceOver && qgsDoubleNear( mTransparency, 0.0 ) ) { //just draw unmodified source drawSource( *painter ); } else { //rasterize source and apply modifications QImage image = sourceAsImage( context )->copy(); QgsImageOperation::multiplyOpacity( image, 1.0 - mTransparency ); painter->save(); painter->setCompositionMode( mBlendMode ); painter->drawImage( imageOffset( context ), image ); painter->restore(); } }
void QgsColorEffect::draw( QgsRenderContext &context ) { if ( !source() || !enabled() || !context.painter() ) return; QPainter* painter = context.painter(); //rasterise source and apply modifications QImage image = sourceAsImage( context )->copy(); QgsImageOperation::adjustBrightnessContrast( image, mBrightness, mContrast / 100.0 + 1 ); if ( mGrayscaleMode != QgsImageOperation::GrayscaleOff ) { QgsImageOperation::convertToGrayscale( image, static_cast< QgsImageOperation::GrayscaleMode >( mGrayscaleMode ) ); } QgsImageOperation::adjustHueSaturation( image, mSaturation, mColorizeOn ? mColorizeColor : QColor(), mColorizeStrength / 100.0 ); QgsImageOperation::multiplyOpacity( image, 1.0 - mTransparency ); painter->save(); painter->setCompositionMode( mBlendMode ); painter->drawImage( imageOffset( context ), image ); painter->restore(); }
void QgsBlurEffect::drawGaussianBlur( QgsRenderContext &context ) { QImage *im = QgsImageOperation::gaussianBlur( *sourceAsImage( context ), mBlurLevel ); drawBlurredImage( context, *im ); delete im; }
void QgsBlurEffect::drawStackBlur( QgsRenderContext &context ) { QImage im = sourceAsImage( context )->copy(); QgsImageOperation::stackBlur( im, mBlurLevel ); drawBlurredImage( context, im ); }