1616 ***************************************************************************/
1717
1818#include " qgssinglebandcolordatarenderer.h"
19+ #include " qgsrasterviewport.h"
1920#include < QImage>
2021
2122QgsSingleBandColorDataRenderer::QgsSingleBandColorDataRenderer ( QgsRasterDataProvider* provider, int band, QgsRasterResampler* resampler ):
@@ -41,16 +42,29 @@ void QgsSingleBandColorDataRenderer::draw( QPainter* p, QgsRasterViewPort* viewP
4142 int topLeftCol, topLeftRow, nCols, nRows, currentRasterPos;
4243 void * rasterData;
4344
45+ bool hasTransparency = usesTransparency ( viewPort->mSrcCRS , viewPort->mDestCRS );
46+
4447 while ( readNextRasterPart ( mBand , viewPort, nCols, nRows, &rasterData, topLeftCol, topLeftRow ) )
4548 {
4649 currentRasterPos = 0 ;
47- QImage img ( nCols, nRows, QImage::Format_ARGB32_Premultiplied );
50+ QImage img ( nCols, nRows, QImage::Format_ARGB32 );
51+ uchar* scanLine = 0 ;
4852 for ( int i = 0 ; i < nRows; ++i )
4953 {
50- memcpy ( img.scanLine ( i ), &((( uint* )rasterData )[currentRasterPos] ), nCols * 4 );
51- for ( int j = 0 ; j < nCols; ++j )
54+ scanLine = img.scanLine ( i );
55+ if ( !hasTransparency )
56+ {
57+ memcpy ( scanLine, &((( uint* )rasterData )[currentRasterPos] ), nCols * 4 );
58+ currentRasterPos += nCols;
59+ }
60+ else
5261 {
53- ++currentRasterPos;
62+ for ( int j = 0 ; j < nCols; ++j )
63+ {
64+ QRgb c ( ( (uint*)(rasterData) )[currentRasterPos] );
65+ scanLine[i] = qRgba ( qRed ( c ), qGreen ( c ), qBlue ( c ), 255 );
66+ ++currentRasterPos;
67+ }
5468 }
5569 }
5670
0 commit comments