Commit 9d7533d2 authored by Lauri Lyly's avatar Lauri Lyly Committed by Albert Astals Cid

Fix trimming margins when paperColor not white

REVIEW: 125721
parent 94b62614
......@@ -11,6 +11,8 @@
#include "utils.h"
#include "utils_p.h"
#include "settings_core.h"
#include <QtCore/QRect>
#include <QApplication>
#include <QDesktopWidget>
......@@ -304,8 +306,8 @@ QSizeF Utils::realDpi(QWidget*)
}
#endif
inline static bool isWhite( QRgb argb ) {
return ( argb & 0xFFFFFF ) == 0xFFFFFF; // ignore alpha
inline static bool isPaperColor( QRgb argb ) {
return ( argb & 0xFFFFFF ) == ( SettingsCore::paperColor().rgb() & 0xFFFFFF); // ignore alpha
}
NormalizedRect Utils::imageBoundingBox( const QImage * image )
......@@ -325,7 +327,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 ( !isWhite( image->pixel( x, top ) ) )
if ( !isPaperColor( image->pixel( x, top ) ) )
goto got_top;
return NormalizedRect( 0, 0, 0, 0 ); // the image is blank
got_top:
......@@ -334,7 +336,7 @@ got_top:
// Scan pixels for bottom non-white
for ( bottom = height-1; bottom >= top; --bottom )
for ( x = width-1; x >= 0; --x )
if ( !isWhite( image->pixel( x, bottom ) ) )
if ( !isPaperColor( image->pixel( x, bottom ) ) )
goto got_bottom;
Q_ASSERT( 0 ); // image changed?!
got_bottom:
......@@ -347,10 +349,10 @@ got_bottom:
for ( y = top; y <= bottom && ( left > 0 || right < width-1 ); ++y )
{
for ( x = 0; x < left; ++x )
if ( !isWhite( image->pixel( x, y ) ) )
if ( !isPaperColor( image->pixel( x, y ) ) )
left = x;
for ( x = width-1; x > right+1; --x )
if ( !isWhite( image->pixel( x, y ) ) )
if ( !isPaperColor( image->pixel( x, y ) ) )
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