|
|
|
|
@ -306,8 +306,8 @@ QSizeF Utils::realDpi(QWidget*) |
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
inline static bool isPaperColor( QRgb argb ) { |
|
|
|
|
return ( argb & 0xFFFFFF ) == ( SettingsCore::paperColor().rgb() & 0xFFFFFF); // ignore alpha
|
|
|
|
|
inline static bool isPaperColor( QRgb argb, QRgb paperColor ) { |
|
|
|
|
return ( argb & 0xFFFFFF ) == ( paperColor & 0xFFFFFF); // ignore alpha
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
NormalizedRect Utils::imageBoundingBox( const QImage * image ) |
|
|
|
|
@ -315,8 +315,9 @@ NormalizedRect Utils::imageBoundingBox( const QImage * image ) |
|
|
|
|
if ( !image ) |
|
|
|
|
return NormalizedRect(); |
|
|
|
|
|
|
|
|
|
int width = image->width(); |
|
|
|
|
int height = image->height(); |
|
|
|
|
const int width = image->width(); |
|
|
|
|
const int height = image->height(); |
|
|
|
|
const QRgb paperColor = SettingsCore::paperColor().rgb(); |
|
|
|
|
int left, top, bottom, right, x, y; |
|
|
|
|
|
|
|
|
|
#ifdef BBOX_DEBUG |
|
|
|
|
@ -327,7 +328,7 @@ NormalizedRect Utils::imageBoundingBox( const QImage * image ) |
|
|
|
|
// Scan pixels for top non-white
|
|
|
|
|
for ( top = 0; top < height; ++top ) |
|
|
|
|
for ( x = 0; x < width; ++x ) |
|
|
|
|
if ( !isPaperColor( image->pixel( x, top ) ) ) |
|
|
|
|
if ( !isPaperColor( image->pixel( x, top ), paperColor ) ) |
|
|
|
|
goto got_top; |
|
|
|
|
return NormalizedRect( 0, 0, 0, 0 ); // the image is blank
|
|
|
|
|
got_top: |
|
|
|
|
@ -336,7 +337,7 @@ got_top: |
|
|
|
|
// Scan pixels for bottom non-white
|
|
|
|
|
for ( bottom = height-1; bottom >= top; --bottom ) |
|
|
|
|
for ( x = width-1; x >= 0; --x ) |
|
|
|
|
if ( !isPaperColor( image->pixel( x, bottom ) ) ) |
|
|
|
|
if ( !isPaperColor( image->pixel( x, bottom ), paperColor ) ) |
|
|
|
|
goto got_bottom; |
|
|
|
|
Q_ASSERT( 0 ); // image changed?!
|
|
|
|
|
got_bottom: |
|
|
|
|
@ -349,10 +350,10 @@ got_bottom: |
|
|
|
|
for ( y = top; y <= bottom && ( left > 0 || right < width-1 ); ++y ) |
|
|
|
|
{ |
|
|
|
|
for ( x = 0; x < left; ++x ) |
|
|
|
|
if ( !isPaperColor( image->pixel( x, y ) ) ) |
|
|
|
|
if ( !isPaperColor( image->pixel( x, y ), paperColor ) ) |
|
|
|
|
left = x; |
|
|
|
|
for ( x = width-1; x > right+1; --x ) |
|
|
|
|
if ( !isPaperColor( image->pixel( x, y ) ) ) |
|
|
|
|
if ( !isPaperColor( image->pixel( x, y ), paperColor ) ) |
|
|
|
|
right = x; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|