Commit 5cf66025 authored by Torsten Rahn's avatar Torsten Rahn Committed by Torsten Rahn

Improve render quality especially at

maximum zoom levels
(by reverting d4b6aea7).
parent b4a9588e
......@@ -32,11 +32,8 @@ ScanlineTextureMapperContext::ScanlineTextureMapperContext( StackedTileLoader *
m_normGlobalWidth( m_globalWidth / ( 2 * M_PI ) ),
m_normGlobalHeight( m_globalHeight / M_PI ),
m_tile( 0 ),
m_deltaLevel( 0 ),
m_tilePosX( 65535 ),
m_tilePosY( 65535 ),
m_vTileStartX( 0 ),
m_vTileStartY( 0 ),
m_toTileCoordinatesLon( 0.5 * m_globalWidth - m_tilePosX ),
m_toTileCoordinatesLat( 0.5 * m_globalHeight - m_tilePosY ),
m_prevLat( 0.0 ),
......@@ -74,8 +71,7 @@ void ScanlineTextureMapperContext::pixelValueF( const qreal lon, const qreal lat
nextTile( posX, posY );
}
if ( m_tile ) {
*scanLine = m_tile->pixelF( ( (int)posX + m_vTileStartX ) / ( 1 << m_deltaLevel ),
( (int)posY + m_vTileStartY ) / ( 1 << m_deltaLevel ) );
*scanLine = m_tile->pixelF( posX, posY );
}
else {
*scanLine = 0;
......@@ -113,8 +109,7 @@ void ScanlineTextureMapperContext::pixelValue( const qreal lon, const qreal lat,
}
if ( m_tile ) {
*scanLine = m_tile->pixel( ( iPosX + m_vTileStartX ) >> m_deltaLevel,
( iPosY + m_vTileStartY ) >> m_deltaLevel );
*scanLine = m_tile->pixel( iPosX, iPosY );
}
else {
*scanLine = 0;
......@@ -185,26 +180,21 @@ void ScanlineTextureMapperContext::pixelValueApproxF( const qreal lon, const qre
nextTile( posX, posY );
itLon = m_prevPixelX + m_toTileCoordinatesLon;
itLat = m_prevPixelY + m_toTileCoordinatesLat;
posX = qMax<qreal>( 0.0, qMin<qreal>( tileWidth-1.0, itLon + itStepLon * j ) );
posY = qMax<qreal>( 0.0, qMin<qreal>( tileHeight-1.0, itLat + itStepLat * j ) );
posX = qBound <qreal>( 0.0, (itLon + itStepLon * j), tileWidth-1.0 );
posY = qBound <qreal>( 0.0, (itLat + itStepLat * j), tileHeight-1.0 );
oldPosX = -1;
}
*scanLine = m_tile->pixel( ( (int)posX + m_vTileStartX ) >> m_deltaLevel,
( (int)posY + m_vTileStartY ) >> m_deltaLevel );
*scanLine = m_tile->pixelF( posX, posY );
// Just perform bilinear interpolation if there's a color change compared to the
// last pixel that was evaluated. This speeds up things greatly for maps like OSM
if ( *scanLine != oldRgb ) {
if ( oldPosX != -1 ) {
*(scanLine - 1) = m_tile->pixelF( ( oldPosX + m_vTileStartX ) / ( 1 << m_deltaLevel ),
( oldPosY + m_vTileStartY ) / ( 1 << m_deltaLevel ),
*(scanLine - 1) );
*(scanLine - 1) = m_tile->pixelF( oldPosX, oldPosY, *(scanLine - 1) );
oldPosX = -1;
}
oldRgb = m_tile->pixelF( ( posX + m_vTileStartX ) / ( 1 << m_deltaLevel ),
( posY + m_vTileStartY ) / ( 1 << m_deltaLevel ),
*scanLine );
oldRgb = m_tile->pixelF( posX, posY, *scanLine );
*scanLine = oldRgb;
}
else {
......@@ -313,8 +303,7 @@ void ScanlineTextureMapperContext::pixelValueApprox( const qreal lon, const qrea
for ( int j = 1; j < n; ++j ) {
iPosXf += itStepLon;
iPosYf += itStepLat;
*scanLine = m_tile->pixel( ( ( iPosXf >> 7 ) + m_vTileStartX ) >> m_deltaLevel,
( ( iPosYf >> 7 ) + m_vTileStartY ) >> m_deltaLevel );
*scanLine = m_tile->pixel( iPosXf >> 7, iPosYf >> 7 );
++scanLine;
}
}
......@@ -335,8 +324,7 @@ void ScanlineTextureMapperContext::pixelValueApprox( const qreal lon, const qrea
iPosY = ( itLat + itStepLat * j ) >> 7;
}
*scanLine = m_tile->pixel( ( iPosX + m_vTileStartX ) >> m_deltaLevel,
( iPosY + m_vTileStartY ) >> m_deltaLevel );
*scanLine = m_tile->pixel( iPosX, iPosY );
++scanLine;
}
}
......@@ -462,8 +450,7 @@ void ScanlineTextureMapperContext::nextTile( int &posX, int &posY )
const int tileCol = lon / m_tileSize.width();
const int tileRow = lat / m_tileSize.height();
m_deltaLevel = 0;
m_tile = m_tileLoader->loadTile( TileId( 0, m_tileLevel - m_deltaLevel, tileCol >> m_deltaLevel, tileRow >> m_deltaLevel ) );
m_tile = m_tileLoader->loadTile( TileId( 0, m_tileLevel, tileCol, tileRow ) );
// Update position variables:
// m_tilePosX/Y stores the position of the tiles in
......@@ -471,12 +458,10 @@ void ScanlineTextureMapperContext::nextTile( int &posX, int &posY )
// ( origin upper left, measured in pixels )
m_tilePosX = tileCol * m_tileSize.width();
m_vTileStartX = ( tileCol - ( ( tileCol >> m_deltaLevel ) << m_deltaLevel ) ) * m_tileSize.width();
m_toTileCoordinatesLon = (qreal)(0.5 * m_globalWidth - m_tilePosX);
posX = lon - m_tilePosX;
m_tilePosY = tileRow * m_tileSize.height();
m_vTileStartY = ( tileRow - ( ( tileRow >> m_deltaLevel ) << m_deltaLevel ) ) * m_tileSize.height();
m_toTileCoordinatesLat = (qreal)(0.5 * m_globalHeight - m_tilePosY);
posY = lat - m_tilePosY;
}
......@@ -504,8 +489,7 @@ void ScanlineTextureMapperContext::nextTile( qreal &posX, qreal &posY )
const int tileCol = lon / m_tileSize.width();
const int tileRow = lat / m_tileSize.height();
m_deltaLevel = 0;
m_tile = m_tileLoader->loadTile( TileId( 0, m_tileLevel - m_deltaLevel, tileCol >> m_deltaLevel, tileRow >> m_deltaLevel ) );
m_tile = m_tileLoader->loadTile( TileId( 0, m_tileLevel, tileCol, tileRow ) );
// Update position variables:
// m_tilePosX/Y stores the position of the tiles in
......@@ -513,12 +497,10 @@ void ScanlineTextureMapperContext::nextTile( qreal &posX, qreal &posY )
// ( origin upper left, measured in pixels )
m_tilePosX = tileCol * m_tileSize.width();
m_vTileStartX = ( tileCol - ( ( tileCol >> m_deltaLevel ) << m_deltaLevel ) ) * m_tileSize.width();
m_toTileCoordinatesLon = (qreal)(0.5 * m_globalWidth - m_tilePosX);
posX = lon - m_tilePosX;
m_tilePosY = tileRow * m_tileSize.height();
m_vTileStartY = ( tileRow - ( ( tileRow >> m_deltaLevel ) << m_deltaLevel ) ) * m_tileSize.height();
m_toTileCoordinatesLat = (qreal)(0.5 * m_globalHeight - m_tilePosY);
posY = lat - m_tilePosY;
}
......@@ -85,16 +85,12 @@ private:
const StackedTile *m_tile;
int m_deltaLevel;
// Coordinate transformations:
// Position of the tile in global Texture Coordinates
// ( with origin in upper left corner, measured in pixel)
int m_tilePosX;
int m_tilePosY;
int m_vTileStartX;
int m_vTileStartY;
// Converts global texture coordinates
// ( with origin in center, measured in pixel)
......
......@@ -134,17 +134,7 @@ void TileScalingTextureMapper::mapTexture( GeoPainter *painter, const ViewportPa
const StackedTile *const tile = m_tileLoader->loadTile( stackedId );
const QImage *const toScale = tile->resultImage();
const int deltaLevel = stackedId.zoomLevel() - tile->id().zoomLevel();
const int restTileX = stackedId.x() % ( 1 << deltaLevel );
const int restTileY = stackedId.y() % ( 1 << deltaLevel );
const int partWidth = toScale->width() >> deltaLevel;
const int partHeight = toScale->height() >> deltaLevel;
const int startX = restTileX * partWidth;
const int startY = restTileY * partHeight;
const QImage part = toScale->copy( startX, startY, partWidth, partHeight ).scaled( toScale->size() );
imagePainter.drawImage( rect, part );
imagePainter.drawImage( rect, *tile->resultImage() );
}
}
......@@ -173,17 +163,7 @@ void TileScalingTextureMapper::mapTexture( GeoPainter *painter, const ViewportPa
const QPixmap *const im_cached = m_cache[cacheId];
const QPixmap *im = im_cached;
if ( im == 0 ) {
const QImage *const toScale = tile->resultImage();
const int deltaLevel = stackedId.zoomLevel() - tile->id().zoomLevel();
const int restTileX = stackedId.x() % ( 1 << deltaLevel );
const int restTileY = stackedId.y() % ( 1 << deltaLevel );
const int partWidth = toScale->width() >> deltaLevel;
const int partHeight = toScale->height() >> deltaLevel;
const int startX = restTileX * partWidth;
const int startY = restTileY * partHeight;
const QImage part = toScale->copy( startX, startY, partWidth, partHeight ).scaled( toScale->size() );
im = new QPixmap( QPixmap::fromImage( part.scaled( size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation ) ) );
im = new QPixmap( QPixmap::fromImage( tile->resultImage()->scaled( size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation ) ) );
}
painter->drawPixmap( rect.topLeft(), *im );
......
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