25
25
QgsRenderChecker::QgsRenderChecker ( ) :
26
26
mReport(" " ),
27
27
mExpectedImageFile(" " ),
28
+ mRenderedImageFile(" " ),
28
29
mMismatchCount(0 ),
29
30
mMatchTarget(0 ),
30
31
mElapsedTime(0 ),
@@ -53,10 +54,7 @@ bool QgsRenderChecker::runTest( QString theTestName )
53
54
// Now render our layers onto a pixmap
54
55
//
55
56
QImage myImage ( myExpectedImage.width () , myExpectedImage.height (), QImage::Format_RGB32 );
56
- QImage myDifferenceImage ( myExpectedImage.width () , myExpectedImage.height (), QImage::Format_RGB32);
57
- QString myResultDiffImage = QDir::tempPath () + QDir::separator () + theTestName + " _result_diff.png" ;
58
57
myImage.fill ( qRgb ( 152 ,219 ,249 ) );
59
- myDifferenceImage.fill ( qRgb ( 152 ,219 ,249 ) );
60
58
QPainter myPainter ( &myImage );
61
59
mpMapRenderer->setOutputSize ( QSize ( myExpectedImage.width (),myExpectedImage.height () ),72 );
62
60
QTime myTime;
@@ -68,51 +66,81 @@ bool QgsRenderChecker::runTest( QString theTestName )
68
66
// Save the pixmap to disk so the user can make a
69
67
// visual assessment if needed
70
68
//
71
- QString myResultImage = QDir::tempPath () + QDir::separator () + theTestName + " _result.png" ;
72
- myImage.save (myResultImage);
69
+ mRenderedImageFile = QDir::tempPath () + QDir::separator () + theTestName + " _result.png" ;
70
+ myImage.save (mRenderedImageFile );
71
+ return compareImages (theTestName);
72
+
73
+ }
74
+
75
+
76
+ bool QgsRenderChecker::compareImages ( QString theTestName )
77
+ {
78
+ if (mExpectedImageFile .isEmpty ())
79
+ {
80
+ qDebug (" QgsRenderChecker::runTest failed - Expected Image (control) File not set." );
81
+ mReport = " <table>"
82
+ " <tr><td>Test Result:</td><td>Expected Result:</td></tr>\n "
83
+ " <tr><td>Nothing rendered</td>\n <td>Failed because Expected "
84
+ " Image File not set.</td></tr></table>\n " ;
85
+ return false ;
86
+ }
87
+ if (mRenderedImageFile .isEmpty ())
88
+ {
89
+ qDebug (" QgsRenderChecker::runTest failed - Rendered Image File not set." );
90
+ mReport = " <table>"
91
+ " <tr><td>Test Result:</td><td>Expected Result:</td></tr>\n "
92
+ " <tr><td>Nothing rendered</td>\n <td>Failed because Expected "
93
+ " Image File not set.</td></tr></table>\n " ;
94
+ return false ;
95
+ }
96
+ //
97
+ // Load /create the images
98
+ //
99
+ QImage myExpectedImage (mExpectedImageFile );
100
+ QImage myResultImage (mRenderedImageFile );
101
+ QImage myDifferenceImage ( myExpectedImage.width () , myExpectedImage.height (), QImage::Format_RGB32);
102
+ QString myResultDiffImage = QDir::tempPath () + QDir::separator () + theTestName + " _result_diff.png" ;
103
+ myDifferenceImage.fill ( qRgb ( 152 ,219 ,249 ) );
104
+
73
105
//
74
106
// Set pixel count score and target
75
107
//
76
108
mMatchTarget = myExpectedImage.width () * myExpectedImage.height ();
77
- int myPixelCount = myImage .width () * myImage .height ();
109
+ int myPixelCount = myResultImage .width () * myResultImage .height ();
78
110
//
79
111
// Set the report with the result
80
112
//
81
113
mReport = " <table>" ;
82
114
mReport += " <tr><td colspan=2>" ;
83
115
mReport += " Test image and result image for " + theTestName + " <br>"
84
116
" Expected size: " + QString::number (myExpectedImage.width ()).toLocal8Bit () + " w x " +
85
- QString::number (myExpectedImage.width ()).toLocal8Bit () + " h (" +
86
- QString::number (mMatchTarget ).toLocal8Bit () + " pixels)<br>"
87
- " Actual size: " + QString::number (myImage .width ()).toLocal8Bit () + " w x " +
88
- QString::number (myImage .width ()).toLocal8Bit () + " h (" +
89
- QString::number (myPixelCount).toLocal8Bit () + " pixels)" ;
117
+ QString::number (myExpectedImage.width ()).toLocal8Bit () + " h (" +
118
+ QString::number (mMatchTarget ).toLocal8Bit () + " pixels)<br>"
119
+ " Actual size: " + QString::number (myResultImage .width ()).toLocal8Bit () + " w x " +
120
+ QString::number (myResultImage .width ()).toLocal8Bit () + " h (" +
121
+ QString::number (myPixelCount).toLocal8Bit () + " pixels)" ;
90
122
mReport += " </td></tr>" ;
91
123
mReport += " <tr><td colspan = 2>\n " ;
92
124
mReport += " Expected Duration : <= " + QString::number (mElapsedTimeTarget ) +
93
- " ms (0 indicates not specified)<br>" ;
125
+ " ms (0 indicates not specified)<br>" ;
94
126
mReport += " Actual Duration : " + QString::number (mElapsedTime ) + " ms<br>" ;
95
127
QString myImagesString= " </td></tr>"
96
128
" <tr><td>Test Result:</td><td>Expected Result:</td><td>Difference (all blue is good, any red is bad)</td></tr>\n "
97
129
" <tr><td><img src=\" file://" +
98
- myResultImage +
130
+ mRenderedImageFile +
99
131
" \" ></td>\n <td><img src=\" file://" +
100
- mExpectedImageFile +
132
+ mExpectedImageFile +
101
133
" \" ></td><td><img src=\" file://" +
102
- myResultDiffImage +
134
+ myResultDiffImage +
103
135
" \" ></td>\n </tr>\n </table>" ;
104
136
//
105
137
// Put the same info to debug too
106
138
//
107
- qDebug (" Expected size: " + QString::number (myExpectedImage.width ()).toLocal8Bit () + + " w x " +
108
- QString::number (myExpectedImage.width ()).toLocal8Bit () + + " h" );
109
- qDebug (" Actual size: " + QString::number (myImage.width ()).toLocal8Bit () + + " w x " +
110
- QString::number (myImage.width ()).toLocal8Bit () + + " h" );
111
- //
112
- // Now load the renderered image and the expected image
113
- // and then iterate through them counting how many
114
- // dissimilar pixel values there are
115
- //
139
+
140
+ qDebug (" Expected size: " + QString::number (myExpectedImage.width ()).toLocal8Bit () + " w x " +
141
+ QString::number (myExpectedImage.width ()).toLocal8Bit () + " h" );
142
+ qDebug (" Actual size: " + QString::number (myResultImage.width ()).toLocal8Bit () + " w x " +
143
+ QString::number (myResultImage.width ()).toLocal8Bit () + " h" );
116
144
117
145
if (mMatchTarget != myPixelCount )
118
146
{
@@ -123,13 +151,19 @@ bool QgsRenderChecker::runTest( QString theTestName )
123
151
mReport += myImagesString;
124
152
return false ;
125
153
}
154
+
155
+ //
156
+ // Now iterate through them counting how many
157
+ // dissimilar pixel values there are
158
+ //
159
+
126
160
mMismatchCount = 0 ;
127
161
for (int x = 0 ; x < myExpectedImage.width (); ++x)
128
162
{
129
163
for (int y = 0 ; y < myExpectedImage.height (); ++y)
130
164
{
131
165
QRgb myExpectedPixel = myExpectedImage.pixel (x,y);
132
- QRgb myActualPixel = myImage .pixel (x,y);
166
+ QRgb myActualPixel = myResultImage .pixel (x,y);
133
167
if (myExpectedPixel != myActualPixel)
134
168
{
135
169
++mMismatchCount ;
@@ -141,14 +175,14 @@ bool QgsRenderChecker::runTest( QString theTestName )
141
175
// save the diff image to disk
142
176
//
143
177
myDifferenceImage.save (myResultDiffImage);
144
-
178
+
145
179
//
146
180
// Send match result to debug
147
181
//
148
182
qDebug (QString::number (mMismatchCount ).toLocal8Bit () + " /" +
149
- QString::number (mMatchTarget ).toLocal8Bit () +
150
- " pixels mismatched" );;
151
-
183
+ QString::number (mMatchTarget ).toLocal8Bit () +
184
+ " pixels mismatched" );;
185
+
152
186
//
153
187
// Send match result to report
154
188
//
@@ -158,7 +192,7 @@ bool QgsRenderChecker::runTest( QString theTestName )
158
192
" pixels mismatched" ;
159
193
mReport += " </td></tr>" ;
160
194
161
-
195
+
162
196
if ( mMismatchCount ==0 )
163
197
{
164
198
mReport += " <tr><td colspan = 3>\n " ;
0 commit comments