Skip to content
Permalink
Browse files

Make use of image cache when rendering raster image fill layers

  • Loading branch information
nirvn committed Dec 6, 2018
1 parent 72783d5 commit 901da9dd580b69a4cbfc384a805d92697d12ec3f
Showing with 9 additions and 34 deletions.
  1. +9 −34 src/core/symbology/qgsfillsymbollayer.cpp
@@ -21,6 +21,7 @@
#include "qgsexpression.h"
#include "qgsgeometry.h"
#include "qgsgeometrycollection.h"
#include "qgsimagecache.h"
#include "qgsrendercontext.h"
#include "qgsproject.h"
#include "qgssvgcache.h"
@@ -3787,43 +3788,17 @@ void QgsRasterFillSymbolLayer::applyDataDefinedSettings( QgsSymbolRenderContext

void QgsRasterFillSymbolLayer::applyPattern( QBrush &brush, const QString &imageFilePath, const double width, const double alpha, const QgsSymbolRenderContext &context )
{
QImage image( imageFilePath );
if ( image.isNull() )
{
return;
}
if ( !image.hasAlphaChannel() )
{
image = image.convertToFormat( QImage::Format_ARGB32 );
}

double pixelWidth;
QSize size;
if ( width > 0 )
{
pixelWidth = context.renderContext().convertToPainterUnits( width, mWidthUnit, mWidthMapUnitScale );
}
else
{
pixelWidth = image.width();
}

//reduce alpha of image
if ( alpha < 1.0 )
{
QPainter p;
p.begin( &image );
p.setCompositionMode( QPainter::CompositionMode_DestinationIn );
QColor alphaColor( 0, 0, 0 );
alphaColor.setAlphaF( alpha );
p.fillRect( image.rect(), alphaColor );
p.end();
size.setWidth( context.renderContext().convertToPainterUnits( width, mWidthUnit, mWidthMapUnitScale ) );
size.setHeight( 0 );
}

//resize image if required
if ( !qgsDoubleNear( pixelWidth, image.width() ) )
{
image = image.scaledToWidth( pixelWidth, Qt::SmoothTransformation );
}
bool cached;
QImage img = QgsApplication::imageCache()->pathAsImage( imageFilePath, size, true, alpha, cached );
if ( img.isNull() )
return;

brush.setTextureImage( image );
brush.setTextureImage( img );
}

0 comments on commit 901da9d

Please sign in to comment.
You can’t perform that action at this time.