Skip to content

Commit

Permalink
Support for global transparency in raster renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Dec 26, 2011
1 parent 17e6afc commit 4827820
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/core/raster/qgspalettedrasterrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ void QgsPalettedRasterRenderer::draw( QPainter* p, QgsRasterViewPort* viewPort,
for ( int j = 0; j < nCols; ++j )
{
val = readValue( rasterData, rasterType, currentRasterPos );
imageScanLine[j] = mColors[ val ].rgba();
//imageScanLine[j] = mColors[ val ].rgba();
QColor& currentColor = mColors[val];
imageScanLine[j] = qRgba( mOpacity * currentColor.red(), mOpacity * currentColor.green(), mOpacity * currentColor.blue(), mOpacity * 255 );
++currentRasterPos;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/core/raster/qgsrasterlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,7 @@ void QgsRasterLayer::draw( QPainter * theQPainter,
//QgsBilinearRasterResampler resampler;
QgsCubicRasterResampler resampler;
QgsPalettedRasterRenderer renderer( mDataProvider, bNumber, colorArray, itemList.size(), 0 /*&resampler*/ );
renderer.setOpacity( mTransparencyLevel / 255.0 );
renderer.draw( theQPainter, theRasterViewPort, theQgsMapToPixel );
#if 0
drawPalettedSingleBandColor( theQPainter, theRasterViewPort,
Expand Down
3 changes: 2 additions & 1 deletion src/core/raster/qgsrasterrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
#include "qgsrasterviewport.h"
#include "qgsmaptopixel.h"

QgsRasterRenderer::QgsRasterRenderer( QgsRasterDataProvider* provider, QgsRasterResampler* resampler ): mProvider( provider ), mResampler( resampler )
QgsRasterRenderer::QgsRasterRenderer( QgsRasterDataProvider* provider, QgsRasterResampler* resampler ): mProvider( provider ), mResampler( resampler ),
mOpacity( 255 )
{
}

Expand Down
4 changes: 4 additions & 0 deletions src/core/raster/qgsrasterrenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ class QgsRasterRenderer
virtual ~QgsRasterRenderer();
virtual void draw( QPainter* p, QgsRasterViewPort* viewPort, const QgsMapToPixel* theQgsMapToPixel ) = 0;

void setOpacity( double opacity ) { mOpacity = opacity; }
double opacity() const { return mOpacity; }

protected:
inline double readValue( void *data, QgsRasterDataProvider::DataType type, int index );

Expand All @@ -56,6 +59,7 @@ class QgsRasterRenderer
QgsRasterDataProvider* mProvider;
QgsRasterResampler* mResampler;
QMap<int, RasterPartInfo> mRasterPartInfos;
double mOpacity; //global alpha value

private:
/**Remove part into and release memory*/
Expand Down

0 comments on commit 4827820

Please sign in to comment.