@@ -1287,10 +1287,11 @@ void QgsShapeburstFillSymbolLayerV2::distanceTransform1d( double *f, int n, int
12871287/* distance transform of 2d function using squared distance */
12881288void QgsShapeburstFillSymbolLayerV2::distanceTransform2d ( double * im, int width, int height )
12891289{
1290- double *f = new double [ qMax ( width,height )];
1291- int *v = new int [ qMax ( width,height )];
1292- double *z = new double [ qMax ( width,height ) + 1 ];
1293- double *d = new double [ qMax ( width,height )];
1290+ int maxDimension = qMax ( width, height );
1291+ double *f = new double [ maxDimension ];
1292+ int *v = new int [ maxDimension ];
1293+ double *z = new double [ maxDimension + 1 ];
1294+ double *d = new double [ maxDimension ];
12941295
12951296 // transform along columns
12961297 for ( int x = 0 ; x < width; x++ )
@@ -1365,16 +1366,22 @@ double * QgsShapeburstFillSymbolLayerV2::distanceTransform( QImage *im )
13651366
13661367void QgsShapeburstFillSymbolLayerV2::dtArrayToQImage ( double * array, QImage *im, QgsVectorColorRampV2* ramp, double layerAlpha, bool useWholeShape, int maxPixelDistance )
13671368{
1369+ int width = im->width ();
1370+ int height = im->height ();
1371+
13681372 // find maximum distance value
13691373 double maxDistanceValue;
13701374
13711375 if ( useWholeShape )
13721376 {
13731377 // no max distance specified in symbol properties, so calculate from maximum value in distance transform results
13741378 double dtMaxValue = array[0 ];
1375- for ( int i = 1 ; i < ( im-> width () * im-> height () ); ++i )
1379+ for ( int i = 1 ; i < ( width * height ); ++i )
13761380 {
1377- dtMaxValue = qMax ( dtMaxValue, array[i] );
1381+ if ( array[i] > dtMaxValue )
1382+ {
1383+ dtMaxValue = array[i];
1384+ }
13781385 }
13791386
13801387 // values in distance transform are squared
@@ -1391,11 +1398,12 @@ void QgsShapeburstFillSymbolLayerV2::dtArrayToQImage( double * array, QImage *im
13911398 double squaredVal = 0 ;
13921399 double pixVal = 0 ;
13931400 QColor pixColor;
1401+ bool layerHasAlpha = layerAlpha < 1.0 ;
13941402
1395- for ( int heightIndex = 0 ; heightIndex < im-> height () ; ++heightIndex )
1403+ for ( int heightIndex = 0 ; heightIndex < height; ++heightIndex )
13961404 {
13971405 QRgb* scanLine = ( QRgb* )im->scanLine ( heightIndex );
1398- for ( int widthIndex = 0 ; widthIndex < im-> width () ; ++widthIndex )
1406+ for ( int widthIndex = 0 ; widthIndex < width; ++widthIndex )
13991407 {
14001408 // result of distance transform
14011409 squaredVal = array[idx];
@@ -1406,11 +1414,15 @@ void QgsShapeburstFillSymbolLayerV2::dtArrayToQImage( double * array, QImage *im
14061414 // convert value to color from ramp
14071415 pixColor = ramp->color ( pixVal );
14081416
1409- // apply layer's transparency to alpha value
1410- double alpha = pixColor.alpha () * layerAlpha;
1417+ int pixAlpha = pixColor.alpha ();
1418+ if (( layerHasAlpha ) || ( pixAlpha != 255 ) )
1419+ {
1420+ // apply layer's transparency to alpha value
1421+ double alpha = pixAlpha * layerAlpha;
1422+ // premultiply ramp color since we are storing this in a ARGB32_Premultiplied QImage
1423+ QgsSymbolLayerV2Utils::premultiplyColor ( pixColor, alpha );
1424+ }
14111425
1412- // premultiply ramp color since we are storing this in a ARGB32_Premultiplied QImage
1413- QgsSymbolLayerV2Utils::premultiplyColor ( pixColor, alpha );
14141426 scanLine[widthIndex] = pixColor.rgba ();
14151427 idx++;
14161428 }
0 commit comments