@@ -1287,10 +1287,11 @@ void QgsShapeburstFillSymbolLayerV2::distanceTransform1d( double *f, int n, int
1287
1287
/* distance transform of 2d function using squared distance */
1288
1288
void QgsShapeburstFillSymbolLayerV2::distanceTransform2d ( double * im, int width, int height )
1289
1289
{
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 ];
1294
1295
1295
1296
// transform along columns
1296
1297
for ( int x = 0 ; x < width; x++ )
@@ -1365,16 +1366,22 @@ double * QgsShapeburstFillSymbolLayerV2::distanceTransform( QImage *im )
1365
1366
1366
1367
void QgsShapeburstFillSymbolLayerV2::dtArrayToQImage ( double * array, QImage *im, QgsVectorColorRampV2* ramp, double layerAlpha, bool useWholeShape, int maxPixelDistance )
1367
1368
{
1369
+ int width = im->width ();
1370
+ int height = im->height ();
1371
+
1368
1372
// find maximum distance value
1369
1373
double maxDistanceValue;
1370
1374
1371
1375
if ( useWholeShape )
1372
1376
{
1373
1377
// no max distance specified in symbol properties, so calculate from maximum value in distance transform results
1374
1378
double dtMaxValue = array[0 ];
1375
- for ( int i = 1 ; i < ( im-> width () * im-> height () ); ++i )
1379
+ for ( int i = 1 ; i < ( width * height ); ++i )
1376
1380
{
1377
- dtMaxValue = qMax ( dtMaxValue, array[i] );
1381
+ if ( array[i] > dtMaxValue )
1382
+ {
1383
+ dtMaxValue = array[i];
1384
+ }
1378
1385
}
1379
1386
1380
1387
// values in distance transform are squared
@@ -1391,11 +1398,12 @@ void QgsShapeburstFillSymbolLayerV2::dtArrayToQImage( double * array, QImage *im
1391
1398
double squaredVal = 0 ;
1392
1399
double pixVal = 0 ;
1393
1400
QColor pixColor;
1401
+ bool layerHasAlpha = layerAlpha < 1.0 ;
1394
1402
1395
- for ( int heightIndex = 0 ; heightIndex < im-> height () ; ++heightIndex )
1403
+ for ( int heightIndex = 0 ; heightIndex < height; ++heightIndex )
1396
1404
{
1397
1405
QRgb* scanLine = ( QRgb* )im->scanLine ( heightIndex );
1398
- for ( int widthIndex = 0 ; widthIndex < im-> width () ; ++widthIndex )
1406
+ for ( int widthIndex = 0 ; widthIndex < width; ++widthIndex )
1399
1407
{
1400
1408
// result of distance transform
1401
1409
squaredVal = array[idx];
@@ -1406,11 +1414,15 @@ void QgsShapeburstFillSymbolLayerV2::dtArrayToQImage( double * array, QImage *im
1406
1414
// convert value to color from ramp
1407
1415
pixColor = ramp->color ( pixVal );
1408
1416
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
+ }
1411
1425
1412
- // premultiply ramp color since we are storing this in a ARGB32_Premultiplied QImage
1413
- QgsSymbolLayerV2Utils::premultiplyColor ( pixColor, alpha );
1414
1426
scanLine[widthIndex] = pixColor.rgba ();
1415
1427
idx++;
1416
1428
}
0 commit comments