Skip to content

Commit 901da9d

Browse files
committed
Make use of image cache when rendering raster image fill layers
1 parent 72783d5 commit 901da9d

File tree

1 file changed

+9
-34
lines changed

1 file changed

+9
-34
lines changed

src/core/symbology/qgsfillsymbollayer.cpp

+9-34
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "qgsexpression.h"
2222
#include "qgsgeometry.h"
2323
#include "qgsgeometrycollection.h"
24+
#include "qgsimagecache.h"
2425
#include "qgsrendercontext.h"
2526
#include "qgsproject.h"
2627
#include "qgssvgcache.h"
@@ -3787,43 +3788,17 @@ void QgsRasterFillSymbolLayer::applyDataDefinedSettings( QgsSymbolRenderContext
37873788

37883789
void QgsRasterFillSymbolLayer::applyPattern( QBrush &brush, const QString &imageFilePath, const double width, const double alpha, const QgsSymbolRenderContext &context )
37893790
{
3790-
QImage image( imageFilePath );
3791-
if ( image.isNull() )
3792-
{
3793-
return;
3794-
}
3795-
if ( !image.hasAlphaChannel() )
3796-
{
3797-
image = image.convertToFormat( QImage::Format_ARGB32 );
3798-
}
3799-
3800-
double pixelWidth;
3791+
QSize size;
38013792
if ( width > 0 )
38023793
{
3803-
pixelWidth = context.renderContext().convertToPainterUnits( width, mWidthUnit, mWidthMapUnitScale );
3804-
}
3805-
else
3806-
{
3807-
pixelWidth = image.width();
3808-
}
3809-
3810-
//reduce alpha of image
3811-
if ( alpha < 1.0 )
3812-
{
3813-
QPainter p;
3814-
p.begin( &image );
3815-
p.setCompositionMode( QPainter::CompositionMode_DestinationIn );
3816-
QColor alphaColor( 0, 0, 0 );
3817-
alphaColor.setAlphaF( alpha );
3818-
p.fillRect( image.rect(), alphaColor );
3819-
p.end();
3794+
size.setWidth( context.renderContext().convertToPainterUnits( width, mWidthUnit, mWidthMapUnitScale ) );
3795+
size.setHeight( 0 );
38203796
}
38213797

3822-
//resize image if required
3823-
if ( !qgsDoubleNear( pixelWidth, image.width() ) )
3824-
{
3825-
image = image.scaledToWidth( pixelWidth, Qt::SmoothTransformation );
3826-
}
3798+
bool cached;
3799+
QImage img = QgsApplication::imageCache()->pathAsImage( imageFilePath, size, true, alpha, cached );
3800+
if ( img.isNull() )
3801+
return;
38273802

3828-
brush.setTextureImage( image );
3803+
brush.setTextureImage( img );
38293804
}

0 commit comments

Comments
 (0)