Skip to content

Commit

Permalink
Better array generation for paletted raster renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Jan 20, 2012
1 parent f16ca52 commit 15fe4da
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/core/raster/qgsrasterlayer.cpp
Expand Up @@ -597,23 +597,35 @@ void QgsRasterLayer::setRendererForDrawingStyle( const DrawingStyle & theDrawin
{
case PalettedColor:
{
//todo: go through list and take maximum value (it could be that entries don't start at 0 or indices are not contiguous
int grayBand = bandNumber( grayBandName() );
QgsColorRampShader* colorRampShader = dynamic_cast<QgsColorRampShader*>( rasterShader()->rasterShaderFunction() );
if ( colorRampShader )
{
QList<QgsColorRampShader::ColorRampItem> colorEntries = colorRampShader->colorRampItemList();
QColor* colorArray = new QColor[ colorEntries.size()];

//go through list and take maximum value (it could be that entries don't start at 0 or indices are not contiguous)
int colorArraySize = 0;
QList<QgsColorRampShader::ColorRampItem>::const_iterator colorIt = colorEntries.constBegin();
for ( ; colorIt != colorEntries.constEnd(); ++colorIt )
{
if ( colorIt->value > colorArraySize )
{
colorArraySize = ( int )( colorIt->value );
}
}

colorArraySize += 1; //usually starts at 0
QColor* colorArray = new QColor[ colorArraySize ];
colorIt = colorEntries.constBegin();
for ( ; colorIt != colorEntries.constEnd(); ++colorIt )
{
colorArray[( int )( colorIt->value )] = colorIt->color;
}

renderer = new QgsPalettedRasterRenderer( mDataProvider,
grayBand,
colorArray,
colorEntries.size() );
colorArraySize );
}
else //try to get it from the color table
{
Expand Down

0 comments on commit 15fe4da

Please sign in to comment.