Skip to content

Commit

Permalink
Fix calculation of transparent region
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Oct 20, 2016
1 parent 02fc2b0 commit 4722274
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/core/effects/qgsimageoperation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -809,21 +809,28 @@ QRect QgsImageOperation::nonTransparentImageRect( const QImage &image, QSize min
// scan down till we hit something
for ( int y = 0; y < height; ++y )
{
bool found = false;
const QRgb* imgScanline = reinterpret_cast< const QRgb* >( image.constScanLine( y ) );
for ( int x = 0; x < width; ++x )
{
if ( qAlpha( imgScanline[x] ) )
{
ymin = y;
ymax = y;
xmin = x;
xmax = x;
found = true;
break;
}
}
if ( found )
break;
}

//scan up till we hit something
for ( int y = height - 1; y > ymin; --y )
for ( int y = height - 1; y >= ymin; --y )
{
bool found = false;
const QRgb* imgScanline = reinterpret_cast< const QRgb* >( image.constScanLine( y ) );
for ( int x = 0; x < width; ++x )
{
Expand All @@ -832,8 +839,12 @@ QRect QgsImageOperation::nonTransparentImageRect( const QImage &image, QSize min
ymax = y;
xmin = qMin( xmin, x );
xmax = qMax( xmax, x );
found = true;
break;
}
}
if ( found )
break;
}

//scan left to right till we hit something, using a refined y region
Expand Down

0 comments on commit 4722274

Please sign in to comment.