Skip to content

Commit cec0413

Browse files
author
wonder
committed
Use ARGB premultiplied format for simple marker, fixed multiplication of alpha channel for images with premultiplied format.
git-svn-id: http://svn.osgeo.org/qgis/trunk@12818 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 788da55 commit cec0413

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

src/core/symbology-ng/qgsmarkersymbollayerv2.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ void QgsSimpleMarkerSymbolLayerV2::startRender( QgsSymbolV2RenderContext& contex
164164

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

167-
mCache = QImage( QSize( imageSize, imageSize ), QImage::Format_ARGB32 );
167+
mCache = QImage( QSize( imageSize, imageSize ), QImage::Format_ARGB32_Premultiplied );
168168
mCache.fill( 0 );
169169

170170
QPainter p;

src/core/symbology-ng/qgssymbollayerv2utils.cpp

+15-10
Original file line numberDiff line numberDiff line change
@@ -722,20 +722,25 @@ void QgsSymbolLayerV2Utils::multiplyImageOpacity( QImage* image, qreal alpha )
722722
return;
723723
}
724724

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

731-
for ( ; heightIndex < image->height(); ++heightIndex )
733+
//change the alpha component of every pixel
734+
for ( int heightIndex = 0; heightIndex < image->height(); ++heightIndex )
732735
{
733-
scanLine = ( QRgb* )image->scanLine( heightIndex );
734-
widthIndex = 0;
735-
for ( ; widthIndex < image->width(); ++widthIndex )
736+
QRgb* scanLine = ( QRgb* )image->scanLine( heightIndex );
737+
for ( int widthIndex = 0; widthIndex < image->width(); ++widthIndex )
736738
{
737-
myRgb = image->pixel( widthIndex, heightIndex );
738-
scanLine[widthIndex] = qRgba( qRed( myRgb ), qGreen( myRgb ), qBlue( myRgb ), qAlpha( myRgb ) * alpha );
739+
myRgb = scanLine[widthIndex];
740+
if ( format == QImage::Format_ARGB32_Premultiplied )
741+
scanLine[widthIndex] = qRgba( alpha * qRed( myRgb ), alpha * qGreen( myRgb ), alpha * qBlue( myRgb ), alpha * qAlpha( myRgb ) );
742+
else
743+
scanLine[widthIndex] = qRgba( qRed( myRgb ), qGreen( myRgb ), qBlue( myRgb ), alpha * qAlpha( myRgb ) );
739744
}
740745
}
741746
}

0 commit comments

Comments
 (0)