@@ -171,6 +171,20 @@ QgsRasterBlock * QgsPalettedRasterRenderer::block( int bandNo, QgsRectangle con
171
171
return outputBlock;
172
172
}
173
173
174
+ // create copy of color table with nodata values replaced by fully transparent color
175
+ QRgb colorTable[mNColors ];
176
+ for ( int i = 0 ; i < mNColors ; ++i )
177
+ {
178
+ if ( inputBlock->isNoDataValue ( i ) )
179
+ {
180
+ colorTable[i] = QColor ( 0 , 0 , 0 , 0 ).rgba ();
181
+ }
182
+ else
183
+ {
184
+ colorTable[i] = mColors [i];
185
+ }
186
+ }
187
+
174
188
// use direct data access instead of QgsRasterBlock::setValue
175
189
// because of performance
176
190
unsigned int * outputData = ( unsigned int * )( outputBlock->data () );
@@ -179,14 +193,9 @@ QgsRasterBlock * QgsPalettedRasterRenderer::block( int bandNo, QgsRectangle con
179
193
for ( size_t i = 0 ; i < rasterSize; ++i )
180
194
{
181
195
int val = ( int ) inputBlock->value ( i );
182
- if ( inputBlock->isNoDataValue ( val ) )
183
- {
184
- outputBlock->setColor ( i, myDefaultColor );
185
- continue ;
186
- }
187
196
if ( !hasTransparency )
188
197
{
189
- outputData[i] = mColors [ val ];
198
+ outputData[i] = colorTable [ val ];
190
199
}
191
200
else
192
201
{
@@ -199,7 +208,7 @@ QgsRasterBlock * QgsPalettedRasterRenderer::block( int bandNo, QgsRectangle con
199
208
{
200
209
currentOpacity *= alphaBlock->value ( i ) / 255.0 ;
201
210
}
202
- QColor currentColor = QColor ( mColors [val] );
211
+ QColor currentColor = QColor ( colorTable [val] );
203
212
outputData[i] = qRgba ( currentOpacity * currentColor.red (), currentOpacity * currentColor.green (), currentOpacity * currentColor.blue (), currentOpacity * 255 );
204
213
}
205
214
}
0 commit comments