Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
WMS transparency fix, issue #6276
  • Loading branch information
blazek committed Sep 3, 2012
1 parent d9c9052 commit e538921
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 16 deletions.
11 changes: 10 additions & 1 deletion src/app/qgsrasterlayerproperties.cpp
Expand Up @@ -282,7 +282,11 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer* lyr, QgsMapCanv
{
if ( QgsRasterRendererRegistry::instance()->rendererData( name, entry ) )
{
mRenderTypeComboBox->addItem( entry.visibleName, entry.name );
if (( mRasterLayer->rasterType() != QgsRasterLayer::ColorLayer && entry.name != "singlebandcolordata" ) ||
( mRasterLayer->rasterType() == QgsRasterLayer::ColorLayer && entry.name == "singlebandcolordata" ) )
{
mRenderTypeComboBox->addItem( entry.visibleName, entry.name );
}
}
}

Expand All @@ -296,6 +300,8 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer* lyr, QgsMapCanv
}

//prevent change between singleband color renderer and the other renderers
// No more necessary, combo entries according to layer type
#if 0
if ( rendererType == "singlebandcolordata" )
{
mRenderTypeComboBox->setEnabled( false );
Expand All @@ -304,6 +310,7 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer* lyr, QgsMapCanv
{
mRenderTypeComboBox->removeItem( mRenderTypeComboBox->findData( "singlebandcolordata" ) );
}
#endif
}
on_mRenderTypeComboBox_currentIndexChanged( mRenderTypeComboBox->currentIndex() );

Expand Down Expand Up @@ -425,13 +432,15 @@ void QgsRasterLayerProperties::populateTransparencyTable( QgsRasterRenderer* ren

void QgsRasterLayerProperties::setRendererWidget( const QString& rendererName )
{
QgsDebugMsg( "rendererName = " + rendererName );
QgsRasterRendererWidget* oldWidget = mRendererWidget;

QgsRasterRendererRegistryEntry rendererEntry;
if ( QgsRasterRendererRegistry::instance()->rendererData( rendererName, rendererEntry ) )
{
if ( rendererEntry.widgetCreateFunction ) //single band color data renderer e.g. has no widget
{
QgsDebugMsg( "renderer has widgetCreateFunction" );
// Current canvas extent (used to calc min/max) in layer CRS
QgsRectangle myExtent = mMapCanvas->mapRenderer()->outputExtentToLayerExtent( mRasterLayer, mMapCanvas->extent() );
mRendererWidget = ( *rendererEntry.widgetCreateFunction )( mRasterLayer, myExtent );
Expand Down
3 changes: 2 additions & 1 deletion src/core/raster/qgsrasterlayer.cpp
Expand Up @@ -1699,7 +1699,8 @@ void QgsRasterLayer::setDataProvider( QString const & provider )
mValidNoDataValue = mDataProvider->isNoDataValueValid();

// set up the raster drawing style
setDrawingStyle( MultiBandColor ); //sensible default
// Do not set any 'sensible' style here, the style is set later
// setDrawingStyle( MultiBandColor ); //sensible default

// Setup source CRS
setCrs( QgsCoordinateReferenceSystem( mDataProvider->crs() ) );
Expand Down
8 changes: 4 additions & 4 deletions src/core/raster/qgsrasterrenderer.cpp
Expand Up @@ -74,13 +74,13 @@ bool QgsRasterRenderer::setInput( QgsRasterInterface* input )

for ( int i = 1; i <= input->bandCount(); i++ )
{
if ( typeIsNumeric( input->dataType( i ) ) )
if ( !typeIsNumeric( input->dataType( i ) ) )
{
mInput = input;
return true;
return false;
}
}
return false;
mInput = input;
return true;
}

bool QgsRasterRenderer::usesTransparency( ) const
Expand Down
38 changes: 28 additions & 10 deletions src/core/raster/qgssinglebandcolordatarenderer.cpp
Expand Up @@ -76,18 +76,15 @@ void * QgsSingleBandColorDataRenderer::readBlock( int bandNo, QgsRectangle cons
}
else
{
QRgb pixelColor;
double alpha = 255.0;
for ( int j = 0; j < width; ++j )
{
QRgb pixelColor;
double alpha = 255.0;
for ( int j = 0; j < width; ++j )
{
QRgb c((( uint* )( rasterData ) )[currentRasterPos] );
alpha = qAlpha( c );
pixelColor = qRgba( qRed( c ), qGreen( c ), qBlue( c ), mOpacity * alpha );
memcpy( &( scanLine[j*4] ), &pixelColor, 4 );
++currentRasterPos;
}
QRgb c((( uint* )( rasterData ) )[currentRasterPos] );
alpha = qAlpha( c );
pixelColor = qRgba( mOpacity * qRed( c ), mOpacity * qGreen( c ), mOpacity * qBlue( c ), mOpacity * alpha );
memcpy( &( scanLine[j*4] ), &pixelColor, 4 );
++currentRasterPos;
}
}
}
Expand Down Expand Up @@ -119,3 +116,24 @@ QList<int> QgsSingleBandColorDataRenderer::usesBands() const
}
return bandList;
}

bool QgsSingleBandColorDataRenderer::setInput( QgsRasterInterface* input )
{
// Renderer can only work with numerical values in at least 1 band
if ( !input ) return false;

if ( !mOn )
{
// In off mode we can connect to anything
mInput = input;
return true;
}

if ( input->dataType( 1 ) == QgsRasterInterface::ARGB32 ||
input->dataType( 1 ) == QgsRasterInterface::ARGB32_Premultiplied )
{
mInput = input;
return true;
}
return false;
}
2 changes: 2 additions & 0 deletions src/core/raster/qgssinglebandcolordatarenderer.h
Expand Up @@ -31,6 +31,8 @@ class CORE_EXPORT QgsSingleBandColorDataRenderer: public QgsRasterRenderer

static QgsRasterRenderer* create( const QDomElement& elem, QgsRasterInterface* input );

bool setInput( QgsRasterInterface* input );

void * readBlock( int bandNo, QgsRectangle const & extent, int width, int height );

void writeXML( QDomDocument& doc, QDomElement& parentElem ) const;
Expand Down

0 comments on commit e538921

Please sign in to comment.