[QGIS Commit] r12818 - trunk/qgis/src/core/symbology-ng

svn_qgis at osgeo.org svn_qgis at osgeo.org
Fri Jan 22 10:02:07 EST 2010


Author: wonder
Date: 2010-01-22 10:02:07 -0500 (Fri, 22 Jan 2010)
New Revision: 12818

Modified:
   trunk/qgis/src/core/symbology-ng/qgsmarkersymbollayerv2.cpp
   trunk/qgis/src/core/symbology-ng/qgssymbollayerv2utils.cpp
Log:
Use ARGB premultiplied format for simple marker, fixed multiplication of alpha channel for images with premultiplied format.


Modified: trunk/qgis/src/core/symbology-ng/qgsmarkersymbollayerv2.cpp
===================================================================
--- trunk/qgis/src/core/symbology-ng/qgsmarkersymbollayerv2.cpp	2010-01-22 13:45:34 UTC (rev 12817)
+++ trunk/qgis/src/core/symbology-ng/qgsmarkersymbollayerv2.cpp	2010-01-22 15:02:07 UTC (rev 12818)
@@ -164,7 +164,7 @@
 
   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;

Modified: trunk/qgis/src/core/symbology-ng/qgssymbollayerv2utils.cpp
===================================================================
--- trunk/qgis/src/core/symbology-ng/qgssymbollayerv2utils.cpp	2010-01-22 13:45:34 UTC (rev 12817)
+++ trunk/qgis/src/core/symbology-ng/qgssymbollayerv2utils.cpp	2010-01-22 15:02:07 UTC (rev 12818)
@@ -722,20 +722,25 @@
     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 ) );
     }
   }
 }



More information about the QGIS-commit mailing list