Skip to content

Commit b54e905

Browse files
committedDec 21, 2012
Paletted raster renderer: replace nodata values in a color table copy before the main loop
1 parent 38232a0 commit b54e905

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed
 

‎src/core/raster/qgspalettedrasterrenderer.cpp

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,20 @@ QgsRasterBlock * QgsPalettedRasterRenderer::block( int bandNo, QgsRectangle con
171171
return outputBlock;
172172
}
173173

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+
174188
//use direct data access instead of QgsRasterBlock::setValue
175189
//because of performance
176190
unsigned int* outputData = ( unsigned int* )( outputBlock->data() );
@@ -179,14 +193,9 @@ QgsRasterBlock * QgsPalettedRasterRenderer::block( int bandNo, QgsRectangle con
179193
for ( size_t i = 0; i < rasterSize; ++i )
180194
{
181195
int val = ( int ) inputBlock->value( i );
182-
if ( inputBlock->isNoDataValue( val ) )
183-
{
184-
outputBlock->setColor( i, myDefaultColor );
185-
continue;
186-
}
187196
if ( !hasTransparency )
188197
{
189-
outputData[i] = mColors[ val ];
198+
outputData[i] = colorTable[ val ];
190199
}
191200
else
192201
{
@@ -199,7 +208,7 @@ QgsRasterBlock * QgsPalettedRasterRenderer::block( int bandNo, QgsRectangle con
199208
{
200209
currentOpacity *= alphaBlock->value( i ) / 255.0;
201210
}
202-
QColor currentColor = QColor( mColors[val] );
211+
QColor currentColor = QColor( colorTable[val] );
203212
outputData[i] = qRgba( currentOpacity * currentColor.red(), currentOpacity * currentColor.green(), currentOpacity * currentColor.blue(), currentOpacity * 255 );
204213
}
205214
}

0 commit comments

Comments
 (0)
Please sign in to comment.