Skip to content
Permalink
Browse files

Hillshaderenderer: Fix transparency effects (#3185)

  • Loading branch information
AsgerPetersen authored and NathanW2 committed Jun 8, 2016
1 parent 2265115 commit 85fbeb26f8cbb0a82ffd8a4ef80b318eb157c373
Showing with 52 additions and 2 deletions.
  1. +52 −2 src/core/raster/qgshillshaderenderer.cpp
@@ -18,7 +18,7 @@
#include <QColor>

#include "qgshillshaderenderer.h"

#include "qgsrastertransparency.h"
#include "qgsrasterinterface.h"
#include "qgsrasterblock.h"
#include "qgsrectangle.h"
@@ -40,6 +40,10 @@ QgsHillshadeRenderer *QgsHillshadeRenderer::clone() const
QgsHillshadeRenderer* r = new QgsHillshadeRenderer( nullptr, mBand, mLightAzimuth, mLightAngle );
r->setZFactor( mZFactor );
r->setMultiDirectional( mMultiDirectional );
// "Effects"
r->setOpacity( mOpacity );
r->setAlphaBand( mAlphaBand );
r->setRasterTransparency( mRasterTransparency ? new QgsRasterTransparency( *mRasterTransparency ) : nullptr );
return r;
}

@@ -98,12 +102,34 @@ QgsRasterBlock *QgsHillshadeRenderer::block( int bandNo, const QgsRectangle &ext
return outputBlock;
}

QgsRasterBlock *alphaBlock = nullptr;

if ( mAlphaBand > 0 && mBand != mAlphaBand )
{

alphaBlock = mInput->block( mAlphaBand, extent, width, height );
if ( !alphaBlock || alphaBlock->isEmpty() )
{
// TODO: better to render without alpha
delete inputBlock;
delete alphaBlock;
return outputBlock;
}
}
else if ( mAlphaBand > 0 )
{
alphaBlock = inputBlock;
}

if ( !outputBlock->reset( QGis::ARGB32_Premultiplied, width, height ) )
{
delete inputBlock;
delete alphaBlock;
return outputBlock;
}



double cellXSize = extent.width() / double( width );
double cellYSize = extent.height() / double( height );
double zenithRad = qMax( 0.0, 90 - mLightAngle ) * M_PI / 180.0;
@@ -224,9 +250,33 @@ QgsRasterBlock *QgsHillshadeRenderer::block( int bandNo, const QgsRectangle &ext
double color3 = cosSlope + sinSlope * cos( angle3Rad - aspectRad ) ;
grayValue = qBound( 0.0, 255 * ( weight0 * color0 + weight1 * color1 + weight2 * color2 + weight3 * color3 ) * 0.5, 255.0 );
}
outputBlock->setColor( i, j, qRgb( grayValue, grayValue, grayValue ) );

double currentAlpha = mOpacity;
if ( mRasterTransparency )
{
currentAlpha = mRasterTransparency->alphaValue( x22, mOpacity * 255 ) / 255.0;
}
if ( mAlphaBand > 0 )
{
currentAlpha *= alphaBlock->value( i ) / 255.0;
}

if ( qgsDoubleNear( currentAlpha, 1.0 ) )
{
outputBlock->setColor( i, j, qRgba( grayValue, grayValue, grayValue, 255 ) );
}
else
{
outputBlock->setColor( i, j, qRgba( currentAlpha * grayValue, currentAlpha * grayValue, currentAlpha * grayValue, currentAlpha * 255 ) );
}
}
}

delete inputBlock;
if ( mAlphaBand > 0 && mBand != mAlphaBand )
{
delete alphaBlock;
}
return outputBlock;
}

2 comments on commit 85fbeb2

@nirvn

This comment has been minimized.

Copy link
Contributor

@nirvn nirvn replied Jul 1, 2016

@AsgerPetersen , @NathanW2 , it appears the global transparency is not working anymore.

@AsgerPetersen

This comment has been minimized.

Copy link
Contributor Author

@AsgerPetersen AsgerPetersen replied Jul 1, 2016

@nirvn @NathanW2: It seems like global transparency is only broken in the style dock. Using the layer properties dialog it works ok. Tested in 600ff4f.

I am not sure this is something I can fix.

Please sign in to comment.
You can’t perform that action at this time.