Skip to content

Commit

Permalink
Minor speed boost to identify highlight
Browse files Browse the repository at this point in the history
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 d1c6941
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/gui/qgshighlight.cpp
Expand Up @@ -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 ) );
}
}
}
Expand Down

0 comments on commit d1c6941

Please sign in to comment.