Пример #1
0
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;
  }
}
Пример #2
0
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();
  }
}
Пример #3
0
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();
}
Пример #4
0
void QgsBlurEffect::drawGaussianBlur( QgsRenderContext &context )
{
  QImage *im = QgsImageOperation::gaussianBlur( *sourceAsImage( context ), mBlurLevel );
  drawBlurredImage( context, *im );
  delete im;
}
Пример #5
0
void QgsBlurEffect::drawStackBlur( QgsRenderContext &context )
{
  QImage im = sourceAsImage( context )->copy();
  QgsImageOperation::stackBlur( im, mBlurLevel );
  drawBlurredImage( context, im );
}