Skip to content

Commit

Permalink
Optimisations for shapeburst fill rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jul 30, 2019
1 parent ee29b4c commit a123a51
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
24 changes: 8 additions & 16 deletions src/core/symbology/qgsfillsymbollayer.cpp
Expand Up @@ -1244,7 +1244,11 @@ void QgsShapeburstFillSymbolLayer::renderPolygon( const QPolygonF &points, QList

//copy distance transform values back to QImage, shading by appropriate color ramp
dtArrayToQImage( dtArray, fillImage.get(), mColorType == QgsShapeburstFillSymbolLayer::SimpleTwoColor ? twoColorGradientRamp.get() : mGradientRamp.get(),
context.renderContext(), context.opacity(), useWholeShape, outputPixelMaxDist );
context.renderContext(), useWholeShape, outputPixelMaxDist );
if ( context.opacity() < 1 )
{
QgsImageOperation::multiplyOpacity( *fillImage, context.opacity() );
}

//clean up some variables
delete [] dtArray;
Expand Down Expand Up @@ -1405,7 +1409,7 @@ double *QgsShapeburstFillSymbolLayer::distanceTransform( QImage *im, QgsRenderCo
return dtArray;
}

void QgsShapeburstFillSymbolLayer::dtArrayToQImage( double *array, QImage *im, QgsColorRamp *ramp, QgsRenderContext &context, double layerAlpha, bool useWholeShape, int maxPixelDistance )
void QgsShapeburstFillSymbolLayer::dtArrayToQImage( double *array, QImage *im, QgsColorRamp *ramp, QgsRenderContext &context, bool useWholeShape, int maxPixelDistance )
{
int width = im->width();
int height = im->height();
Expand Down Expand Up @@ -1438,8 +1442,6 @@ void QgsShapeburstFillSymbolLayer::dtArrayToQImage( double *array, QImage *im, Q
int idx = 0;
double squaredVal = 0;
double pixVal = 0;
QColor pixColor;
bool layerHasAlpha = layerAlpha < 1.0;

for ( int heightIndex = 0; heightIndex < height; ++heightIndex )
{
Expand All @@ -1463,18 +1465,8 @@ void QgsShapeburstFillSymbolLayer::dtArrayToQImage( double *array, QImage *im, Q
}

//convert value to color from ramp
pixColor = ramp->color( pixVal );

int pixAlpha = pixColor.alpha();
if ( ( layerHasAlpha ) || ( pixAlpha != 255 ) )
{
//apply layer's transparency to alpha value
double alpha = pixAlpha * layerAlpha;
//premultiply ramp color since we are storing this in a ARGB32_Premultiplied QImage
QgsSymbolLayerUtils::premultiplyColor( pixColor, alpha );
}

scanLine[widthIndex] = pixColor.rgba();
//premultiply ramp color since we are storing this in a ARGB32_Premultiplied QImage
scanLine[widthIndex] = qPremultiply( ramp->color( pixVal ).rgba() );
idx++;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/symbology/qgsfillsymbollayer.h
Expand Up @@ -616,7 +616,7 @@ class CORE_EXPORT QgsShapeburstFillSymbolLayer : public QgsFillSymbolLayer
double *distanceTransform( QImage *im, QgsRenderContext &context );

/* fills a QImage with values from an array of doubles containing squared distance transform values */
void dtArrayToQImage( double *array, QImage *im, QgsColorRamp *ramp, QgsRenderContext &context, double layerAlpha = 1, bool useWholeShape = true, int maxPixelDistance = 0 );
void dtArrayToQImage( double *array, QImage *im, QgsColorRamp *ramp, QgsRenderContext &context, bool useWholeShape = true, int maxPixelDistance = 0 );

#ifdef SIP_RUN
QgsShapeburstFillSymbolLayer( const QgsShapeburstFillSymbolLayer &other );
Expand Down

0 comments on commit a123a51

Please sign in to comment.