Skip to content

Commit

Permalink
Use ARGB premultiplied format for simple marker, fixed multiplication…
Browse files Browse the repository at this point in the history
… of alpha channel for images with premultiplied format.

git-svn-id: http://svn.osgeo.org/qgis/trunk@12818 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed Jan 22, 2010
1 parent 788da55 commit cec0413
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/core/symbology-ng/qgsmarkersymbollayerv2.cpp
Expand Up @@ -164,7 +164,7 @@ void QgsSimpleMarkerSymbolLayerV2::startRender( QgsSymbolV2RenderContext& contex

double center = (( double ) imageSize / 2 ) + 0.5; // add 1/2 pixel for proper rounding when the figure's coordinates are added

mCache = QImage( QSize( imageSize, imageSize ), QImage::Format_ARGB32 );
mCache = QImage( QSize( imageSize, imageSize ), QImage::Format_ARGB32_Premultiplied );
mCache.fill( 0 );

QPainter p;
Expand Down
25 changes: 15 additions & 10 deletions src/core/symbology-ng/qgssymbollayerv2utils.cpp
Expand Up @@ -722,20 +722,25 @@ void QgsSymbolLayerV2Utils::multiplyImageOpacity( QImage* image, qreal alpha )
return;
}

//change the alpha component of every pixel
int widthIndex = 0;
int heightIndex = 0;
QRgb* scanLine = 0;
QRgb myRgb;
QImage::Format format = image->format();
if ( format != QImage::Format_ARGB32_Premultiplied && format != QImage::Format_ARGB32 )
{
QgsDebugMsg( "no alpha channel." );
return;
}

for ( ; heightIndex < image->height(); ++heightIndex )
//change the alpha component of every pixel
for ( int heightIndex = 0; heightIndex < image->height(); ++heightIndex )
{
scanLine = ( QRgb* )image->scanLine( heightIndex );
widthIndex = 0;
for ( ; widthIndex < image->width(); ++widthIndex )
QRgb* scanLine = ( QRgb* )image->scanLine( heightIndex );
for ( int widthIndex = 0; widthIndex < image->width(); ++widthIndex )
{
myRgb = image->pixel( widthIndex, heightIndex );
scanLine[widthIndex] = qRgba( qRed( myRgb ), qGreen( myRgb ), qBlue( myRgb ), qAlpha( myRgb ) * alpha );
myRgb = scanLine[widthIndex];
if ( format == QImage::Format_ARGB32_Premultiplied )
scanLine[widthIndex] = qRgba( alpha * qRed( myRgb ), alpha * qGreen( myRgb ), alpha * qBlue( myRgb ), alpha * qAlpha( myRgb ) );
else
scanLine[widthIndex] = qRgba( qRed( myRgb ), qGreen( myRgb ), qBlue( myRgb ), alpha * qAlpha( myRgb ) );
}
}
}

0 comments on commit cec0413

Please sign in to comment.