Skip to content
Permalink
Browse files

Minor speed boost to identify highlight

Unfortunately this whole identify highlight class is very inefficient,
resulting in multiple large image redraws at every paint event
and slow iteration over every pixel in these images.

TODO This needs to be completely reworked in future.
  • Loading branch information
nyalldawson committed Feb 5, 2018
1 parent 535de3b commit d1c6941ae4a12b483044b99dbc505919665950bd
Showing with 9 additions and 7 deletions.
  1. +9 −7 src/gui/qgshighlight.cpp
@@ -349,21 +349,23 @@ void QgsHighlight::paint( QPainter *p )

imagePainter.end();

QColor color( mPen.color() ); // true output color
// true output color
int penRed = mPen.color().red();
int penGreen = mPen.color().green();
int penBlue = mPen.color().blue();
// coefficient to subtract alpha using green (temporary fill)
double k = ( 255. - mBrush.color().alpha() ) / 255.;
QRgb *line = nullptr;
for ( int r = 0; r < image.height(); r++ )
{
line = ( QRgb * )image.scanLine( r );
for ( int c = 0; c < image.width(); c++ )
{
QRgb rgba = image.pixel( c, r );
int alpha = qAlpha( rgba );
int alpha = qAlpha( line[c] );
if ( alpha > 0 )
{
int green = qGreen( rgba );
color.setAlpha( qBound<int>( 0, alpha - ( green * k ), 255 ) );

image.setPixel( c, r, color.rgba() );
int green = qGreen( line[c] );
line[c] = qRgba( penRed, penGreen, penBlue, qBound<int>( 0, alpha - ( green * k ), 255 ) );
}
}
}

0 comments on commit d1c6941

Please sign in to comment.
You can’t perform that action at this time.