Skip to content

Commit

Permalink
For xyz tiles, disable smooth pixmap transform when
Browse files Browse the repository at this point in the history
we are rendering at native tile resolutions (or just close enough to)

This allows pixel-perfect rendering of tiles at native resolutions

(cherry picked from commit 1c9586a)
  • Loading branch information
nyalldawson committed Jun 10, 2019
1 parent 2b75a27 commit 25c8cb7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
13 changes: 8 additions & 5 deletions src/providers/wms/qgswmsprovider.cpp
Expand Up @@ -563,7 +563,7 @@ void QgsWmsProvider::fetchOtherResTiles( QgsTileMode tileMode, const QgsRectangl
( viewExtent.yMaximum() - r.rect.bottom() ) / cr,
r.rect.width() / cr,
r.rect.height() / cr );
otherResTiles << TileImage( dst, localImage );
otherResTiles << TileImage( dst, localImage, false );

// see if there are any missing rects that are completely covered by this tile
Q_FOREACH ( const QRectF &missingRect, missingRects )
Expand Down Expand Up @@ -773,12 +773,13 @@ QImage *QgsWmsProvider::draw( QgsRectangle const &viewExtent, int pixelWidth, in
if ( QgsTileCache::tile( r.url, localImage ) )
{
double cr = viewExtent.width() / image->width();

QRectF dst( ( r.rect.left() - viewExtent.xMinimum() ) / cr,
( viewExtent.yMaximum() - r.rect.bottom() ) / cr,
r.rect.width() / cr,
r.rect.height() / cr );
tileImages << TileImage( dst, localImage );
// if image size is "close enough" to destination size, don't smooth it out. Instead try for pixel-perfect placement!
bool disableSmoothing = ( qgsDoubleNear( dst.width(), tm->tileWidth, 2 ) && qgsDoubleNear( dst.height(), tm->tileHeight, 2 ) );
tileImages << TileImage( dst, localImage, !disableSmoothing );
}
else
{
Expand Down Expand Up @@ -836,7 +837,7 @@ QImage *QgsWmsProvider::draw( QgsRectangle const &viewExtent, int pixelWidth, in
// draw composite in this resolution
Q_FOREACH ( const TileImage &ti, tileImages )
{
if ( mSettings.mSmoothPixmapTransform )
if ( ti.smooth && mSettings.mSmoothPixmapTransform )
p.setRenderHint( QPainter::SmoothPixmapTransform, true );
p.drawImage( ti.rect, ti.img );

Expand Down Expand Up @@ -3943,7 +3944,9 @@ void QgsWmsTiledImageDownloadHandler::tileReplyFinished()
if ( !myLocalImage.isNull() )
{
QPainter p( mImage );
if ( mSmoothPixmapTransform )
// if image size is "close enough" to destination size, don't smooth it out. Instead try for pixel-perfect placement!
const bool disableSmoothing = ( qgsDoubleNear( dst.width(), myLocalImage.width(), 2 ) && qgsDoubleNear( dst.height(), myLocalImage.height(), 2 ) );
if ( !disableSmoothing && mSmoothPixmapTransform )
p.setRenderHint( QPainter::SmoothPixmapTransform, true );
p.drawImage( dst, myLocalImage );
#if 0
Expand Down
3 changes: 2 additions & 1 deletion src/providers/wms/qgswmsprovider.h
Expand Up @@ -335,9 +335,10 @@ class QgsWmsProvider : public QgsRasterDataProvider
//! Helper structure to store a cached tile image with its rectangle
typedef struct TileImage
{
TileImage( const QRectF &r, const QImage &i ): rect( r ), img( i ) {}
TileImage( const QRectF &r, const QImage &i, bool smooth ): rect( r ), img( i ), smooth( smooth ) {}
QRectF rect; //!< Destination rectangle for a tile (in screen coordinates)
QImage img; //!< Cached tile to be drawn
bool smooth; //!< Whether to use antialiasing/smooth transforms when rendering tile
} TileImage;
//! Gets tiles from a different resolution to cover the missing areas
void fetchOtherResTiles( QgsTileMode tileMode, const QgsRectangle &viewExtent, int imageWidth, QList<QRectF> &missing, double tres, int resOffset, QList<TileImage> &otherResTiles );
Expand Down

0 comments on commit 25c8cb7

Please sign in to comment.