Skip to content

Commit

Permalink
Make use of image cache when rendering raster image fill layers
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn committed Dec 6, 2018
1 parent 72783d5 commit 901da9d
Showing 1 changed file with 9 additions and 34 deletions.
43 changes: 9 additions & 34 deletions src/core/symbology/qgsfillsymbollayer.cpp
Expand Up @@ -21,6 +21,7 @@
#include "qgsexpression.h" #include "qgsexpression.h"
#include "qgsgeometry.h" #include "qgsgeometry.h"
#include "qgsgeometrycollection.h" #include "qgsgeometrycollection.h"
#include "qgsimagecache.h"
#include "qgsrendercontext.h" #include "qgsrendercontext.h"
#include "qgsproject.h" #include "qgsproject.h"
#include "qgssvgcache.h" #include "qgssvgcache.h"
Expand Down Expand Up @@ -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 ) void QgsRasterFillSymbolLayer::applyPattern( QBrush &brush, const QString &imageFilePath, const double width, const double alpha, const QgsSymbolRenderContext &context )
{ {
QImage image( imageFilePath ); QSize size;
if ( image.isNull() )
{
return;
}
if ( !image.hasAlphaChannel() )
{
image = image.convertToFormat( QImage::Format_ARGB32 );
}

double pixelWidth;
if ( width > 0 ) if ( width > 0 )
{ {
pixelWidth = context.renderContext().convertToPainterUnits( width, mWidthUnit, mWidthMapUnitScale ); size.setWidth( context.renderContext().convertToPainterUnits( width, mWidthUnit, mWidthMapUnitScale ) );
} size.setHeight( 0 );
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();
} }


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


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

0 comments on commit 901da9d

Please sign in to comment.