15
15
16
16
#include " qgscompositionchecker.h"
17
17
#include " qgscomposition.h"
18
+ #include < QDir>
19
+ #include < QFileInfo>
18
20
#include < QImage>
19
21
#include < QPainter>
20
22
@@ -71,10 +73,11 @@ bool QgsCompositionChecker::testComposition()
71
73
mComposition ->render ( &p, targetArea, sourceArea );
72
74
p.end ();
73
75
74
- return compareImages ( expectedImage, outputImage );
76
+ QString diffFilePath = QDir::tempPath () + QDir::separator () + QFileInfo ( mExpectedImageFile ).baseName () + " _diff.png" ;
77
+ return compareImages ( expectedImage, outputImage, diffFilePath );
75
78
}
76
79
77
- bool QgsCompositionChecker::compareImages ( const QImage& img1, const QImage& img2 ) const
80
+ bool QgsCompositionChecker::compareImages ( const QImage& img1, const QImage& img2, const QString& differenceImagePath ) const
78
81
{
79
82
if ( img1.width () != img2.width () || img1.height () != img2.height () )
80
83
{
@@ -85,6 +88,9 @@ bool QgsCompositionChecker::compareImages( const QImage& img1, const QImage& img
85
88
int imageHeight = img1.height ();
86
89
int mismatchCount = 0 ;
87
90
91
+ QImage differenceImage ( imageWidth, imageHeight, QImage::Format_ARGB32_Premultiplied );
92
+ differenceImage.fill ( qRgb ( 152 , 219 , 249 ) );
93
+
88
94
QRgb pixel1, pixel2;
89
95
for ( int i = 0 ; i < imageHeight; ++i )
90
96
{
@@ -95,12 +101,17 @@ bool QgsCompositionChecker::compareImages( const QImage& img1, const QImage& img
95
101
if ( pixel1 != pixel2 )
96
102
{
97
103
++mismatchCount;
104
+ differenceImage.setPixel ( j, i, qRgb ( 255 , 0 , 0 ) );
98
105
}
99
106
}
100
107
}
101
108
102
- int pixelCount = imageWidth * imageHeight;
109
+ if ( !differenceImagePath.isEmpty () )
110
+ {
111
+ differenceImage.save ( differenceImagePath, " PNG" );
112
+ }
103
113
104
114
// allow pixel deviation of 1 percent
115
+ int pixelCount = imageWidth * imageHeight;
105
116
return (( double )mismatchCount / ( double )pixelCount ) < 0.01 ;
106
117
}
0 commit comments