Commit c743eceb authored by Albert Astals Cid's avatar Albert Astals Cid

Optimize all those SettingsCore::paperColor().rgb() calls

Maybe the compiler can do it, but i can do it as well :D
parent 9d7533d2
...@@ -306,8 +306,8 @@ QSizeF Utils::realDpi(QWidget*) ...@@ -306,8 +306,8 @@ QSizeF Utils::realDpi(QWidget*)
} }
#endif #endif
inline static bool isPaperColor( QRgb argb ) { inline static bool isPaperColor( QRgb argb, QRgb paperColor ) {
return ( argb & 0xFFFFFF ) == ( SettingsCore::paperColor().rgb() & 0xFFFFFF); // ignore alpha return ( argb & 0xFFFFFF ) == ( paperColor & 0xFFFFFF); // ignore alpha
} }
NormalizedRect Utils::imageBoundingBox( const QImage * image ) NormalizedRect Utils::imageBoundingBox( const QImage * image )
...@@ -315,8 +315,9 @@ NormalizedRect Utils::imageBoundingBox( const QImage * image ) ...@@ -315,8 +315,9 @@ NormalizedRect Utils::imageBoundingBox( const QImage * image )
if ( !image ) if ( !image )
return NormalizedRect(); return NormalizedRect();
int width = image->width(); const int width = image->width();
int height = image->height(); const int height = image->height();
const QRgb paperColor = SettingsCore::paperColor().rgb();
int left, top, bottom, right, x, y; int left, top, bottom, right, x, y;
#ifdef BBOX_DEBUG #ifdef BBOX_DEBUG
...@@ -327,7 +328,7 @@ NormalizedRect Utils::imageBoundingBox( const QImage * image ) ...@@ -327,7 +328,7 @@ NormalizedRect Utils::imageBoundingBox( const QImage * image )
// Scan pixels for top non-white // Scan pixels for top non-white
for ( top = 0; top < height; ++top ) for ( top = 0; top < height; ++top )
for ( x = 0; x < width; ++x ) for ( x = 0; x < width; ++x )
if ( !isPaperColor( image->pixel( x, top ) ) ) if ( !isPaperColor( image->pixel( x, top ), paperColor ) )
goto got_top; goto got_top;
return NormalizedRect( 0, 0, 0, 0 ); // the image is blank return NormalizedRect( 0, 0, 0, 0 ); // the image is blank
got_top: got_top:
...@@ -336,7 +337,7 @@ got_top: ...@@ -336,7 +337,7 @@ got_top:
// Scan pixels for bottom non-white // Scan pixels for bottom non-white
for ( bottom = height-1; bottom >= top; --bottom ) for ( bottom = height-1; bottom >= top; --bottom )
for ( x = width-1; x >= 0; --x ) for ( x = width-1; x >= 0; --x )
if ( !isPaperColor( image->pixel( x, bottom ) ) ) if ( !isPaperColor( image->pixel( x, bottom ), paperColor ) )
goto got_bottom; goto got_bottom;
Q_ASSERT( 0 ); // image changed?! Q_ASSERT( 0 ); // image changed?!
got_bottom: got_bottom:
...@@ -349,10 +350,10 @@ got_bottom: ...@@ -349,10 +350,10 @@ got_bottom:
for ( y = top; y <= bottom && ( left > 0 || right < width-1 ); ++y ) for ( y = top; y <= bottom && ( left > 0 || right < width-1 ); ++y )
{ {
for ( x = 0; x < left; ++x ) for ( x = 0; x < left; ++x )
if ( !isPaperColor( image->pixel( x, y ) ) ) if ( !isPaperColor( image->pixel( x, y ), paperColor ) )
left = x; left = x;
for ( x = width-1; x > right+1; --x ) for ( x = width-1; x > right+1; --x )
if ( !isPaperColor( image->pixel( x, y ) ) ) if ( !isPaperColor( image->pixel( x, y ), paperColor ) )
right = x; right = x;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment