Skip to content

Commit 31c3250

Browse files
nyalldawsonm-kuhn
authored andcommitted
Switch to RGB32 images for composition checker
1 parent 2cfcca1 commit 31c3250

File tree

111 files changed

+37
-9
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+37
-9
lines changed

python/core/qgsrenderchecker.sip

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,11 @@ class QgsRenderChecker
8282
bool isKnownAnomaly( QString theDiffImageFile );
8383

8484
QString expectedImageFile();
85+
86+
protected:
87+
88+
/**Draws a checkboard pattern for image backgrounds, so that transparency is visible
89+
* without requiring a transparent background for the image
90+
*/
91+
void drawBackround( QImage* image );
8592
};

src/core/qgsrenderchecker.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,27 @@ void QgsRenderChecker::setMapSettings( const QgsMapSettings& mapSettings )
7878
mMapSettings = mapSettings;
7979
}
8080

81+
void QgsRenderChecker::drawBackround( QImage* image )
82+
{
83+
// create a 2x2 checker-board image
84+
uchar pixDataRGB[] = { 255, 255, 255, 255,
85+
127, 127, 127, 255,
86+
127, 127, 127, 255,
87+
255, 255, 255, 255
88+
};
89+
90+
QImage img( pixDataRGB, 2, 2, 8, QImage::Format_ARGB32 );
91+
QPixmap pix = QPixmap::fromImage( img.scaled( 20, 20 ) );
92+
93+
// fill image with texture
94+
QBrush brush;
95+
brush.setTexture( pix );
96+
QPainter p( image );
97+
p.setRenderHint( QPainter::Antialiasing, false );
98+
p.fillRect( QRect( 0, 0, image->width(), image->height() ), brush );
99+
p.end();
100+
}
101+
81102
bool QgsRenderChecker::isKnownAnomaly( QString theDiffImageFile )
82103
{
83104
QString myControlImageDir = controlImagePath() + mControlName

src/core/qgsrenderchecker.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,11 @@ class CORE_EXPORT QgsRenderChecker
136136
QString mRenderedImageFile;
137137
QString mExpectedImageFile;
138138

139+
/**Draws a checkboard pattern for image backgrounds, so that transparency is visible
140+
* without requiring a transparent background for the image
141+
*/
142+
void drawBackround( QImage* image );
143+
139144
private:
140145
QString mControlName;
141146
unsigned int mMismatchCount;

tests/src/core/qgscompositionchecker.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ bool QgsCompositionChecker::testComposition( QString &theReport, int page, int p
7373
#if 0
7474
//fake mode to generate expected image
7575
//assume 96 dpi and size of the control image 1122 * 794
76-
QImage newImage( QSize( 1122, 794 ), QImage::Format_ARGB32 );
76+
QImage newImage( QSize( 1122, 794 ), QImage::Format_RGB32 );
7777
mComposition->setPlotStyle( QgsComposition::Print );
7878
newImage.setDotsPerMeterX( 96 / 25.4 * 1000 );
7979
newImage.setDotsPerMeterY( 96 / 25.4 * 1000 );
@@ -87,7 +87,7 @@ bool QgsCompositionChecker::testComposition( QString &theReport, int page, int p
8787
return true;
8888
#endif //0
8989

90-
QImage outputImage( mSize, QImage::Format_ARGB32 );
90+
QImage outputImage( mSize, QImage::Format_RGB32 );
9191

9292
mComposition->setPlotStyle( QgsComposition::Print );
9393
outputImage.setDotsPerMeterX( mDotsPerMeter );

tests/src/core/qgscompositionchecker.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,6 @@ class QgsCompositionChecker : public QgsMultiRenderChecker
3434
private:
3535
QgsCompositionChecker(); //forbidden
3636

37-
/**Draws a checkboard pattern for image backgrounds, so that transparency is visible
38-
* without requiring a transparent background for the image
39-
*/
40-
void drawBackround( QImage* image );
41-
4237
QString mTestName;
4338
QgsComposition* mComposition;
4439
QSize mSize;

tests/src/python/qgscompositionchecker.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ def testComposition(self, page=0, pixelDiff=0 ):
3939
#get width/height, create image and render the composition to it
4040
width = expectedImage.width();
4141
height = expectedImage.height();
42-
outputImage = QImage( QSize( width, height ), QImage.Format_ARGB32 )
42+
outputImage = QImage( QSize( width, height ), QImage.Format_RGB32 )
4343

4444
self.mComposition.setPlotStyle( QgsComposition.Print )
4545
outputImage.setDotsPerMeterX( expectedImage.dotsPerMeterX() )
4646
outputImage.setDotsPerMeterY( expectedImage.dotsPerMeterX() )
47-
outputImage.fill( 0 )
47+
self.drawBackround( outputImage )
4848
p = QPainter( outputImage )
4949
self.mComposition.renderPage( p, page )
5050
p.end()

0 commit comments

Comments
 (0)