@@ -822,7 +822,6 @@ void QgsRasterLayer::draw( QPainter * theQPainter,
822
822
823
823
drawPalettedSingleBandColor ( theQPainter, theRasterViewPort,
824
824
theQgsMapToPixel, bandNumber ( mGrayBandName ) );
825
-
826
825
break ;
827
826
}
828
827
// a "Palette" layer drawn in gray scale (using only one of the color components)
@@ -2377,7 +2376,7 @@ void QgsRasterLayer::setDataProvider( QString const & provider,
2377
2376
mGreenBandName = bandName ( 2 );
2378
2377
}
2379
2378
2380
- // for the third layer we cant be sure so..
2379
+ // for the third band we cant be sure so..
2381
2380
if (( mDataProvider ->bandCount () > 2 ) )
2382
2381
{
2383
2382
mBlueBandName = bandName ( myQSettings.value ( " /Raster/defaultBlueBand" , 3 ).toInt () ); // sensible default
@@ -3675,16 +3674,22 @@ void QgsRasterLayer::drawMultiBandColor( QPainter * theQPainter, QgsRasterViewPo
3675
3674
return ;
3676
3675
}
3677
3676
3677
+ int myTransparencyBandNo = bandNumber ( mTransparencyBandName );
3678
+ bool hasTransparencyBand = 0 < myTransparencyBandNo;
3679
+
3678
3680
int myRedType = mDataProvider ->dataType ( myRedBandNo );
3679
3681
int myGreenType = mDataProvider ->dataType ( myGreenBandNo );
3680
3682
int myBlueType = mDataProvider ->dataType ( myBlueBandNo );
3683
+ int myTransparencyType = hasTransparencyBand ? mDataProvider ->dataType ( myTransparencyBandNo ) : 0 ;
3681
3684
3682
3685
QRgb* redImageScanLine = 0 ;
3683
3686
void * redRasterScanLine = 0 ;
3684
3687
QRgb* greenImageScanLine = 0 ;
3685
3688
void * greenRasterScanLine = 0 ;
3686
3689
QRgb* blueImageScanLine = 0 ;
3687
3690
void * blueRasterScanLine = 0 ;
3691
+ QRgb* transparencyImageScanLine = 0 ;
3692
+ void * transparencyRasterScanLine = 0 ;
3688
3693
3689
3694
QRgb myDefaultColor = qRgba ( 255 , 255 , 255 , 0 );
3690
3695
@@ -3730,6 +3735,7 @@ void QgsRasterLayer::drawMultiBandColor( QPainter * theQPainter, QgsRasterViewPo
3730
3735
double myRedValue = 0.0 ;
3731
3736
double myGreenValue = 0.0 ;
3732
3737
double myBlueValue = 0.0 ;
3738
+ int myTransparencyValue = 0 ;
3733
3739
3734
3740
int myStretchedRedValue = 0 ;
3735
3741
int myStretchedGreenValue = 0 ;
@@ -3748,12 +3754,31 @@ void QgsRasterLayer::drawMultiBandColor( QPainter * theQPainter, QgsRasterViewPo
3748
3754
blueImageBuffer.setWritingEnabled ( false ); // only draw to redImageBuffer
3749
3755
blueImageBuffer.reset ();
3750
3756
3757
+ QgsRasterImageBuffer *transparencyImageBuffer = 0 ;
3758
+ if ( hasTransparencyBand )
3759
+ {
3760
+ transparencyImageBuffer = new QgsRasterImageBuffer ( mDataProvider , myTransparencyBandNo, theQPainter, theRasterViewPort, theQgsMapToPixel, &mGeoTransform [0 ] );
3761
+ transparencyImageBuffer->setWritingEnabled ( false ); // only draw to redImageBuffer
3762
+ transparencyImageBuffer->reset ();
3763
+ }
3764
+
3751
3765
while ( redImageBuffer.nextScanLine ( &redImageScanLine, &redRasterScanLine )
3752
3766
&& greenImageBuffer.nextScanLine ( &greenImageScanLine, &greenRasterScanLine )
3753
- && blueImageBuffer.nextScanLine ( &blueImageScanLine, &blueRasterScanLine ) )
3767
+ && blueImageBuffer.nextScanLine ( &blueImageScanLine, &blueRasterScanLine )
3768
+ && ( !transparencyImageBuffer || transparencyImageBuffer->nextScanLine ( &transparencyImageScanLine, &transparencyRasterScanLine ) ) )
3754
3769
{
3755
3770
for ( int i = 0 ; i < theRasterViewPort->drawableAreaXDim ; ++i )
3756
3771
{
3772
+ if ( transparencyImageBuffer )
3773
+ {
3774
+ myTransparencyValue = readValue ( transparencyRasterScanLine, myTransparencyType, i );
3775
+ if ( 0 == myTransparencyValue )
3776
+ {
3777
+ redImageScanLine[ i ] = myDefaultColor;
3778
+ continue ;
3779
+ }
3780
+ }
3781
+
3757
3782
myRedValue = readValue ( redRasterScanLine, myRedType, i );
3758
3783
myGreenValue = readValue ( greenRasterScanLine, myGreenType, i );
3759
3784
myBlueValue = readValue ( blueRasterScanLine, myBlueType, i );
@@ -3806,9 +3831,15 @@ void QgsRasterLayer::drawMultiBandColor( QPainter * theQPainter, QgsRasterViewPo
3806
3831
myStretchedBlueValue = 255 - myStretchedBlueValue;
3807
3832
}
3808
3833
3834
+ if ( myTransparencyValue )
3835
+ myAlphaValue *= myTransparencyValue / 255.0 ;
3836
+
3809
3837
redImageScanLine[ i ] = qRgba ( myStretchedRedValue, myStretchedGreenValue, myStretchedBlueValue, myAlphaValue );
3810
3838
}
3811
3839
}
3840
+
3841
+ if ( transparencyImageBuffer )
3842
+ delete transparencyImageBuffer;
3812
3843
}
3813
3844
3814
3845
void QgsRasterLayer::drawMultiBandSingleBandGray ( QPainter * theQPainter, QgsRasterViewPort * theRasterViewPort,
@@ -3842,30 +3873,56 @@ void QgsRasterLayer::drawPalettedSingleBandColor( QPainter * theQPainter, QgsRas
3842
3873
return ;
3843
3874
}
3844
3875
3876
+ int myTransparencyBandNo = bandNumber ( mTransparencyBandName );
3877
+ bool hasTransparencyBand = 0 < myTransparencyBandNo;
3878
+
3845
3879
if ( NULL == mRasterShader )
3846
3880
{
3847
3881
return ;
3848
3882
}
3849
3883
3850
3884
int myDataType = mDataProvider ->dataType ( theBandNo );
3885
+ int myTransparencyType = hasTransparencyBand ? mDataProvider ->dataType ( myTransparencyBandNo ) : 0 ;
3851
3886
3852
3887
QgsRasterImageBuffer imageBuffer ( mDataProvider , theBandNo, theQPainter, theRasterViewPort, theQgsMapToPixel, &mGeoTransform [0 ] );
3853
3888
imageBuffer.reset ();
3854
3889
3890
+ QgsRasterImageBuffer *transparencyImageBuffer = 0 ;
3891
+ if ( hasTransparencyBand )
3892
+ {
3893
+ transparencyImageBuffer = new QgsRasterImageBuffer ( mDataProvider , myTransparencyBandNo, theQPainter, theRasterViewPort, theQgsMapToPixel, &mGeoTransform [0 ] );
3894
+ transparencyImageBuffer->setWritingEnabled ( false ); // only draw to imageBuffer
3895
+ transparencyImageBuffer->reset ();
3896
+ }
3897
+
3855
3898
QRgb* imageScanLine = 0 ;
3856
3899
void * rasterScanLine = 0 ;
3900
+ QRgb* transparencyImageScanLine = 0 ;
3901
+ void * transparencyRasterScanLine = 0 ;
3857
3902
3858
3903
QRgb myDefaultColor = qRgba ( 255 , 255 , 255 , 0 );
3859
3904
double myPixelValue = 0.0 ;
3860
3905
int myRedValue = 0 ;
3861
3906
int myGreenValue = 0 ;
3862
3907
int myBlueValue = 0 ;
3908
+ int myTransparencyValue = 0 ;
3863
3909
int myAlphaValue = 0 ;
3864
3910
3865
- while ( imageBuffer.nextScanLine ( &imageScanLine, &rasterScanLine ) )
3911
+ while ( imageBuffer.nextScanLine ( &imageScanLine, &rasterScanLine )
3912
+ && ( !transparencyImageBuffer || transparencyImageBuffer->nextScanLine ( &transparencyImageScanLine, &transparencyRasterScanLine ) ) )
3866
3913
{
3867
3914
for ( int i = 0 ; i < theRasterViewPort->drawableAreaXDim ; ++i )
3868
3915
{
3916
+ if ( transparencyImageBuffer )
3917
+ {
3918
+ myTransparencyValue = readValue ( transparencyRasterScanLine, myTransparencyType, i );
3919
+ if ( 0 == myTransparencyValue )
3920
+ {
3921
+ imageScanLine[ i ] = myDefaultColor;
3922
+ continue ;
3923
+ }
3924
+ }
3925
+
3869
3926
myRedValue = 0 ;
3870
3927
myGreenValue = 0 ;
3871
3928
myBlueValue = 0 ;
@@ -3891,9 +3948,12 @@ void QgsRasterLayer::drawPalettedSingleBandColor( QPainter * theQPainter, QgsRas
3891
3948
continue ;
3892
3949
}
3893
3950
3951
+ if ( myTransparencyValue )
3952
+ myAlphaValue *= myTransparencyValue / 255.0 ;
3953
+
3894
3954
if ( mInvertColor )
3895
3955
{
3896
- // Invert flag, flip blue and read
3956
+ // Invert flag, flip blue and red
3897
3957
imageScanLine[ i ] = qRgba ( myBlueValue, myGreenValue, myRedValue, myAlphaValue );
3898
3958
}
3899
3959
else
@@ -3903,6 +3963,9 @@ void QgsRasterLayer::drawPalettedSingleBandColor( QPainter * theQPainter, QgsRas
3903
3963
}
3904
3964
}
3905
3965
}
3966
+
3967
+ if ( transparencyImageBuffer )
3968
+ delete transparencyImageBuffer;
3906
3969
}
3907
3970
3908
3971
/* *
@@ -3922,30 +3985,56 @@ void QgsRasterLayer::drawPalettedSingleBandGray( QPainter * theQPainter, QgsRast
3922
3985
return ;
3923
3986
}
3924
3987
3988
+ int myTransparencyBandNo = bandNumber ( mTransparencyBandName );
3989
+ bool hasTransparencyBand = 0 < myTransparencyBandNo;
3990
+
3925
3991
if ( NULL == mRasterShader )
3926
3992
{
3927
3993
return ;
3928
3994
}
3929
3995
3930
3996
int myDataType = mDataProvider ->dataType ( theBandNo );
3997
+ int myTransparencyType = hasTransparencyBand ? mDataProvider ->dataType ( myTransparencyBandNo ) : 0 ;
3931
3998
3932
3999
QgsRasterImageBuffer imageBuffer ( mDataProvider , theBandNo, theQPainter, theRasterViewPort, theQgsMapToPixel, &mGeoTransform [0 ] );
3933
4000
imageBuffer.reset ();
3934
4001
4002
+ QgsRasterImageBuffer *transparencyImageBuffer = 0 ;
4003
+ if ( hasTransparencyBand )
4004
+ {
4005
+ transparencyImageBuffer = new QgsRasterImageBuffer ( mDataProvider , myTransparencyBandNo, theQPainter, theRasterViewPort, theQgsMapToPixel, &mGeoTransform [0 ] );
4006
+ transparencyImageBuffer->setWritingEnabled ( false ); // only draw to redImageBuffer
4007
+ transparencyImageBuffer->reset ();
4008
+ }
4009
+
3935
4010
QRgb* imageScanLine = 0 ;
3936
4011
void * rasterScanLine = 0 ;
4012
+ QRgb* transparencyImageScanLine = 0 ;
4013
+ void * transparencyRasterScanLine = 0 ;
3937
4014
3938
4015
QRgb myDefaultColor = qRgba ( 255 , 255 , 255 , 0 );
3939
4016
double myPixelValue = 0.0 ;
3940
4017
int myRedValue = 0 ;
3941
4018
int myGreenValue = 0 ;
3942
4019
int myBlueValue = 0 ;
4020
+ int myTransparencyValue = 0 ;
3943
4021
int myAlphaValue = 0 ;
3944
4022
3945
- while ( imageBuffer.nextScanLine ( &imageScanLine, &rasterScanLine ) )
4023
+ while ( imageBuffer.nextScanLine ( &imageScanLine, &rasterScanLine )
4024
+ && ( !transparencyImageBuffer || transparencyImageBuffer->nextScanLine ( &transparencyImageScanLine, &transparencyRasterScanLine ) ) )
3946
4025
{
3947
4026
for ( int i = 0 ; i < theRasterViewPort->drawableAreaXDim ; ++i )
3948
4027
{
4028
+ if ( transparencyImageBuffer )
4029
+ {
4030
+ myTransparencyValue = readValue ( transparencyRasterScanLine, myTransparencyType, i );
4031
+ if ( 0 == myTransparencyValue )
4032
+ {
4033
+ imageScanLine[ i ] = myDefaultColor;
4034
+ continue ;
4035
+ }
4036
+ }
4037
+
3949
4038
myRedValue = 0 ;
3950
4039
myGreenValue = 0 ;
3951
4040
myBlueValue = 0 ;
@@ -3971,9 +4060,12 @@ void QgsRasterLayer::drawPalettedSingleBandGray( QPainter * theQPainter, QgsRast
3971
4060
continue ;
3972
4061
}
3973
4062
4063
+ if ( myTransparencyValue )
4064
+ myAlphaValue *= myTransparencyValue / 255.0 ;
4065
+
3974
4066
if ( mInvertColor )
3975
4067
{
3976
- // Invert flag, flip blue and read
4068
+ // Invert flag, flip blue and red
3977
4069
double myGrayValue = ( 0.3 * ( double )myRedValue ) + ( 0.59 * ( double )myGreenValue ) + ( 0.11 * ( double )myBlueValue );
3978
4070
imageScanLine[ i ] = qRgba (( int )myGrayValue, ( int )myGrayValue, ( int )myGrayValue, myAlphaValue );
3979
4071
}
@@ -3985,6 +4077,9 @@ void QgsRasterLayer::drawPalettedSingleBandGray( QPainter * theQPainter, QgsRast
3985
4077
}
3986
4078
}
3987
4079
}
4080
+
4081
+ if ( transparencyImageBuffer )
4082
+ delete transparencyImageBuffer;
3988
4083
}
3989
4084
3990
4085
/* *
@@ -4005,14 +4100,33 @@ void QgsRasterLayer::drawPalettedSingleBandPseudoColor( QPainter * theQPainter,
4005
4100
return ;
4006
4101
}
4007
4102
4103
+ int myTransparencyBandNo = bandNumber ( mTransparencyBandName );
4104
+ bool hasTransparencyBand = 0 < myTransparencyBandNo;
4105
+
4106
+ if ( NULL == mRasterShader )
4107
+ {
4108
+ return ;
4109
+ }
4110
+
4008
4111
QgsRasterBandStats myRasterBandStats = bandStatistics ( theBandNo );
4009
4112
int myDataType = mDataProvider ->dataType ( theBandNo );
4113
+ int myTransparencyType = hasTransparencyBand ? mDataProvider ->dataType ( myTransparencyBandNo ) : 0 ;
4010
4114
4011
4115
QgsRasterImageBuffer imageBuffer ( mDataProvider , theBandNo, theQPainter, theRasterViewPort, theQgsMapToPixel, &mGeoTransform [0 ] );
4012
4116
imageBuffer.reset ();
4013
4117
4118
+ QgsRasterImageBuffer *transparencyImageBuffer = 0 ;
4119
+ if ( hasTransparencyBand )
4120
+ {
4121
+ transparencyImageBuffer = new QgsRasterImageBuffer ( mDataProvider , myTransparencyBandNo, theQPainter, theRasterViewPort, theQgsMapToPixel, &mGeoTransform [0 ] );
4122
+ transparencyImageBuffer->setWritingEnabled ( false ); // only draw to imageBuffer
4123
+ transparencyImageBuffer->reset ();
4124
+ }
4125
+
4014
4126
QRgb* imageScanLine = 0 ;
4015
4127
void * rasterScanLine = 0 ;
4128
+ QRgb* transparencyImageScanLine = 0 ;
4129
+ void * transparencyRasterScanLine = 0 ;
4016
4130
4017
4131
QRgb myDefaultColor = qRgba ( 255 , 255 , 255 , 0 );
4018
4132
double myMinimumValue = 0.0 ;
@@ -4036,15 +4150,24 @@ void QgsRasterLayer::drawPalettedSingleBandPseudoColor( QPainter * theQPainter,
4036
4150
int myRedValue = 0 ;
4037
4151
int myGreenValue = 0 ;
4038
4152
int myBlueValue = 0 ;
4153
+ int myTransparencyValue = 0 ;
4039
4154
int myAlphaValue = 0 ;
4040
4155
4041
- while ( imageBuffer.nextScanLine ( &imageScanLine, &rasterScanLine ) )
4156
+ while ( imageBuffer.nextScanLine ( &imageScanLine, &rasterScanLine )
4157
+ && ( !transparencyImageBuffer || transparencyImageBuffer->nextScanLine ( &transparencyImageScanLine, &transparencyRasterScanLine ) ) )
4042
4158
{
4043
4159
for ( int i = 0 ; i < theRasterViewPort->drawableAreaXDim ; ++i )
4044
4160
{
4045
- myRedValue = 0 ;
4046
- myGreenValue = 0 ;
4047
- myBlueValue = 0 ;
4161
+ if ( transparencyImageBuffer )
4162
+ {
4163
+ myTransparencyValue = readValue ( transparencyRasterScanLine, myTransparencyType, i );
4164
+ if ( 0 == myTransparencyValue )
4165
+ {
4166
+ imageScanLine[ i ] = myDefaultColor;
4167
+ continue ;
4168
+ }
4169
+ }
4170
+
4048
4171
myPixelValue = readValue ( rasterScanLine, myDataType, i );
4049
4172
4050
4173
if ( mValidNoDataValue && ( qAbs ( myPixelValue - mNoDataValue ) <= TINY_VALUE || myPixelValue != myPixelValue ) )
@@ -4066,9 +4189,12 @@ void QgsRasterLayer::drawPalettedSingleBandPseudoColor( QPainter * theQPainter,
4066
4189
continue ;
4067
4190
}
4068
4191
4192
+ if ( myTransparencyValue )
4193
+ myAlphaValue *= myTransparencyValue / 255.0 ;
4194
+
4069
4195
if ( mInvertColor )
4070
4196
{
4071
- // Invert flag, flip blue and read
4197
+ // Invert flag, flip blue and red
4072
4198
imageScanLine[ i ] = qRgba ( myBlueValue, myGreenValue, myRedValue, myAlphaValue );
4073
4199
}
4074
4200
else
@@ -4078,6 +4204,9 @@ void QgsRasterLayer::drawPalettedSingleBandPseudoColor( QPainter * theQPainter,
4078
4204
}
4079
4205
}
4080
4206
}
4207
+
4208
+ if ( transparencyImageBuffer )
4209
+ delete transparencyImageBuffer;
4081
4210
}
4082
4211
4083
4212
/* *
@@ -4098,7 +4227,8 @@ void QgsRasterLayer::drawPalettedMultiBandColor( QPainter * theQPainter, QgsRast
4098
4227
QgsDebugMsg ( " Not supported at this time" );
4099
4228
}
4100
4229
4101
- void QgsRasterLayer::drawSingleBandGray ( QPainter * theQPainter, QgsRasterViewPort * theRasterViewPort, const QgsMapToPixel* theQgsMapToPixel, int theBandNo )
4230
+ void QgsRasterLayer::drawSingleBandGray ( QPainter * theQPainter, QgsRasterViewPort * theRasterViewPort,
4231
+ const QgsMapToPixel* theQgsMapToPixel, int theBandNo )
4102
4232
{
4103
4233
QgsDebugMsg ( " layer=" + QString::number ( theBandNo ) );
4104
4234
// Invalid band number, segfault prevention
@@ -4107,17 +4237,33 @@ void QgsRasterLayer::drawSingleBandGray( QPainter * theQPainter, QgsRasterViewPo
4107
4237
return ;
4108
4238
}
4109
4239
4240
+ int myTransparencyBandNo = bandNumber ( mTransparencyBandName );
4241
+ bool hasTransparencyBand = 0 < myTransparencyBandNo;
4242
+
4110
4243
int myDataType = mDataProvider ->dataType ( theBandNo );
4111
4244
QgsDebugMsg ( " myDataType = " + QString::number ( myDataType ) );
4245
+ int myTransparencyType = hasTransparencyBand ? mDataProvider ->dataType ( myTransparencyBandNo ) : 0 ;
4246
+
4112
4247
QgsRasterImageBuffer imageBuffer ( mDataProvider , theBandNo, theQPainter, theRasterViewPort, theQgsMapToPixel, &mGeoTransform [0 ] );
4113
4248
imageBuffer.reset ();
4114
4249
4250
+ QgsRasterImageBuffer *transparencyImageBuffer = 0 ;
4251
+ if ( hasTransparencyBand )
4252
+ {
4253
+ transparencyImageBuffer = new QgsRasterImageBuffer ( mDataProvider , myTransparencyBandNo, theQPainter, theRasterViewPort, theQgsMapToPixel, &mGeoTransform [0 ] );
4254
+ transparencyImageBuffer->setWritingEnabled ( false ); // only draw to imageBuffer
4255
+ transparencyImageBuffer->reset ();
4256
+ }
4257
+
4115
4258
QRgb* imageScanLine = 0 ;
4116
4259
void * rasterScanLine = 0 ;
4260
+ QRgb* transparencyImageScanLine = 0 ;
4261
+ void * transparencyRasterScanLine = 0 ;
4117
4262
4118
4263
QRgb myDefaultColor = qRgba ( 255 , 255 , 255 , 0 );
4119
4264
double myGrayValue = 0.0 ;
4120
4265
int myGrayVal = 0 ;
4266
+ int myTransparencyValue = 0 ;
4121
4267
int myAlphaValue = 0 ;
4122
4268
QgsContrastEnhancement* myContrastEnhancement = contrastEnhancement ( theBandNo );
4123
4269
@@ -4137,15 +4283,25 @@ void QgsRasterLayer::drawSingleBandGray( QPainter * theQPainter, QgsRasterViewPo
4137
4283
mGrayMinimumMaximumEstimated = true ;
4138
4284
setMaximumValue ( theBandNo, mDataProvider ->maximumValue ( theBandNo ) );
4139
4285
setMinimumValue ( theBandNo, mDataProvider ->minimumValue ( theBandNo ) );
4140
-
4141
4286
}
4142
4287
4143
4288
QgsDebugMsg ( " -> imageBuffer.nextScanLine" );
4144
- while ( imageBuffer.nextScanLine ( &imageScanLine, &rasterScanLine ) )
4289
+ while ( imageBuffer.nextScanLine ( &imageScanLine, &rasterScanLine )
4290
+ && ( !transparencyImageBuffer || transparencyImageBuffer->nextScanLine ( &transparencyImageScanLine, &transparencyRasterScanLine ) ) )
4145
4291
{
4146
4292
// QgsDebugMsg( " rendering line");
4147
4293
for ( int i = 0 ; i < theRasterViewPort->drawableAreaXDim ; ++i )
4148
4294
{
4295
+ if ( transparencyImageBuffer )
4296
+ {
4297
+ myTransparencyValue = readValue ( transparencyRasterScanLine, myTransparencyType, i );
4298
+ if ( 0 == myTransparencyValue )
4299
+ {
4300
+ imageScanLine[ i ] = myDefaultColor;
4301
+ continue ;
4302
+ }
4303
+ }
4304
+
4149
4305
myGrayValue = readValue ( rasterScanLine, myDataType, i );
4150
4306
// QgsDebugMsg( QString( "i = %1 myGrayValue = %2 ").arg(i).arg( myGrayValue ) );
4151
4307
// if ( myGrayValue != -2147483647 ) {
@@ -4179,16 +4335,20 @@ void QgsRasterLayer::drawSingleBandGray( QPainter * theQPainter, QgsRasterViewPo
4179
4335
myGrayVal = 255 - myGrayVal;
4180
4336
}
4181
4337
4338
+ if ( myTransparencyValue )
4339
+ myAlphaValue *= myTransparencyValue / 255.0 ;
4340
+
4182
4341
// QgsDebugMsg( QString( "i = %1 myGrayValue = %2 myGrayVal = %3 myAlphaValue = %4").arg(i).arg( myGrayValue ).arg(myGrayVal).arg(myAlphaValue) );
4183
4342
imageScanLine[ i ] = qRgba ( myGrayVal, myGrayVal, myGrayVal, myAlphaValue );
4184
4343
}
4185
4344
}
4345
+
4346
+ if ( transparencyImageBuffer )
4347
+ delete transparencyImageBuffer;
4186
4348
} // QgsRasterLayer::drawSingleBandGray
4187
4349
4188
- void QgsRasterLayer::drawSingleBandPseudoColor ( QPainter * theQPainter,
4189
- QgsRasterViewPort * theRasterViewPort,
4190
- const QgsMapToPixel* theQgsMapToPixel,
4191
- int theBandNo )
4350
+ void QgsRasterLayer::drawSingleBandPseudoColor ( QPainter * theQPainter, QgsRasterViewPort * theRasterViewPort,
4351
+ const QgsMapToPixel* theQgsMapToPixel, int theBandNo )
4192
4352
{
4193
4353
QgsDebugMsg ( " entered." );
4194
4354
// Invalid band number, segfault prevention
@@ -4197,20 +4357,35 @@ void QgsRasterLayer::drawSingleBandPseudoColor( QPainter * theQPainter,
4197
4357
return ;
4198
4358
}
4199
4359
4360
+ int myTransparencyBandNo = bandNumber ( mTransparencyBandName );
4361
+ bool hasTransparencyBand = 0 < myTransparencyBandNo;
4362
+
4363
+ if ( NULL == mRasterShader )
4364
+ {
4365
+ return ;
4366
+ }
4367
+
4200
4368
QgsRasterBandStats myRasterBandStats = bandStatistics ( theBandNo );
4201
4369
int myDataType = mDataProvider ->dataType ( theBandNo );
4370
+ int myTransparencyType = hasTransparencyBand ? mDataProvider ->dataType ( myTransparencyBandNo ) : 0 ;
4202
4371
4203
4372
QgsRasterImageBuffer imageBuffer ( mDataProvider , theBandNo, theQPainter, theRasterViewPort, theQgsMapToPixel, &mGeoTransform [0 ] );
4204
4373
imageBuffer.reset ();
4205
4374
4375
+ QgsRasterImageBuffer *transparencyImageBuffer = 0 ;
4376
+ if ( hasTransparencyBand )
4377
+ {
4378
+ transparencyImageBuffer = new QgsRasterImageBuffer ( mDataProvider , myTransparencyBandNo, theQPainter, theRasterViewPort, theQgsMapToPixel, &mGeoTransform [0 ] );
4379
+ transparencyImageBuffer->setWritingEnabled ( false ); // only draw to imageBuffer
4380
+ transparencyImageBuffer->reset ();
4381
+ }
4382
+
4206
4383
QRgb* imageScanLine = 0 ;
4207
4384
void * rasterScanLine = 0 ;
4385
+ QRgb* transparencyImageScanLine = 0 ;
4386
+ void * transparencyRasterScanLine = 0 ;
4208
4387
4209
4388
QRgb myDefaultColor = qRgba ( 255 , 255 , 255 , 0 );
4210
- if ( NULL == mRasterShader )
4211
- {
4212
- return ;
4213
- }
4214
4389
4215
4390
double myMinimumValue = 0.0 ;
4216
4391
double myMaximumValue = 0.0 ;
@@ -4232,14 +4407,26 @@ void QgsRasterLayer::drawSingleBandPseudoColor( QPainter * theQPainter,
4232
4407
int myRedValue = 255 ;
4233
4408
int myGreenValue = 255 ;
4234
4409
int myBlueValue = 255 ;
4410
+ int myTransparencyValue = 0 ;
4235
4411
4236
4412
double myPixelValue = 0.0 ;
4237
4413
int myAlphaValue = 0 ;
4238
4414
4239
- while ( imageBuffer.nextScanLine ( &imageScanLine, &rasterScanLine ) )
4415
+ while ( imageBuffer.nextScanLine ( &imageScanLine, &rasterScanLine )
4416
+ && ( !transparencyImageBuffer || transparencyImageBuffer->nextScanLine ( &transparencyImageScanLine, &transparencyRasterScanLine ) ) )
4240
4417
{
4241
4418
for ( int i = 0 ; i < theRasterViewPort->drawableAreaXDim ; ++i )
4242
4419
{
4420
+ if ( transparencyImageBuffer )
4421
+ {
4422
+ myTransparencyValue = readValue ( transparencyRasterScanLine, myTransparencyType, i );
4423
+ if ( 0 == myTransparencyValue )
4424
+ {
4425
+ imageScanLine[ i ] = myDefaultColor;
4426
+ continue ;
4427
+ }
4428
+ }
4429
+
4243
4430
myPixelValue = readValue ( rasterScanLine, myDataType, i );
4244
4431
4245
4432
if ( mValidNoDataValue && ( qAbs ( myPixelValue - mNoDataValue ) <= TINY_VALUE || myPixelValue != myPixelValue ) )
@@ -4261,9 +4448,12 @@ void QgsRasterLayer::drawSingleBandPseudoColor( QPainter * theQPainter,
4261
4448
continue ;
4262
4449
}
4263
4450
4451
+ if ( myTransparencyValue )
4452
+ myAlphaValue *= myTransparencyValue / 255.0 ;
4453
+
4264
4454
if ( mInvertColor )
4265
4455
{
4266
- // Invert flag, flip blue and read
4456
+ // Invert flag, flip blue and red
4267
4457
imageScanLine[ i ] = qRgba ( myBlueValue, myGreenValue, myRedValue, myAlphaValue );
4268
4458
}
4269
4459
else
@@ -4274,6 +4464,9 @@ void QgsRasterLayer::drawSingleBandPseudoColor( QPainter * theQPainter,
4274
4464
}
4275
4465
}
4276
4466
}
4467
+
4468
+ if ( transparencyImageBuffer )
4469
+ delete transparencyImageBuffer;
4277
4470
}
4278
4471
4279
4472
#if 0
0 commit comments