Skip to content

Commit 4809f06

Browse files
committed
More improvements for single band color data
1 parent 5ee5a17 commit 4809f06

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

src/core/raster/qgssinglebandcolordatarenderer.cpp

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
***************************************************************************/
1717

1818
#include "qgssinglebandcolordatarenderer.h"
19+
#include "qgsrasterviewport.h"
1920
#include <QImage>
2021

2122
QgsSingleBandColorDataRenderer::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

Comments
 (0)