Skip to content

Commit 34c7bcb

Browse files
committed
Fix transparent 1 pixel borders in raster layer, caused by rounding to int
1 parent d51ea41 commit 34c7bcb

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

src/core/raster/qgsrasterlayer.cpp

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -354,24 +354,22 @@ bool QgsRasterLayer::draw( QgsRenderContext& rendererContext )
354354
// we could use floating point for raster devices as well, but respecting the
355355
// output device grid should make it more effective as the resampling is done in
356356
// the provider anyway
357-
if ( true )
358-
{
359-
myRasterViewPort->mTopLeftPoint.setX( floor( myRasterViewPort->mTopLeftPoint.x() ) );
360-
myRasterViewPort->mTopLeftPoint.setY( floor( myRasterViewPort->mTopLeftPoint.y() ) );
361-
myRasterViewPort->mBottomRightPoint.setX( ceil( myRasterViewPort->mBottomRightPoint.x() ) );
362-
myRasterViewPort->mBottomRightPoint.setY( ceil( myRasterViewPort->mBottomRightPoint.y() ) );
363-
// recalc myRasterExtent to aligned values
364-
myRasterExtent.set(
365-
theQgsMapToPixel.toMapCoordinatesF( myRasterViewPort->mTopLeftPoint.x(),
366-
myRasterViewPort->mBottomRightPoint.y() ),
367-
theQgsMapToPixel.toMapCoordinatesF( myRasterViewPort->mBottomRightPoint.x(),
368-
myRasterViewPort->mTopLeftPoint.y() )
369-
);
357+
myRasterViewPort->mTopLeftPoint.setX( floor( myRasterViewPort->mTopLeftPoint.x() ) );
358+
myRasterViewPort->mTopLeftPoint.setY( floor( myRasterViewPort->mTopLeftPoint.y() ) );
359+
myRasterViewPort->mBottomRightPoint.setX( ceil( myRasterViewPort->mBottomRightPoint.x() ) );
360+
myRasterViewPort->mBottomRightPoint.setY( ceil( myRasterViewPort->mBottomRightPoint.y() ) );
361+
// recalc myRasterExtent to aligned values
362+
myRasterExtent.set(
363+
theQgsMapToPixel.toMapCoordinatesF( myRasterViewPort->mTopLeftPoint.x(),
364+
myRasterViewPort->mBottomRightPoint.y() ),
365+
theQgsMapToPixel.toMapCoordinatesF( myRasterViewPort->mBottomRightPoint.x(),
366+
myRasterViewPort->mTopLeftPoint.y() )
367+
);
370368

371-
}
369+
//raster viewport top left / bottom right are already rounded to int
370+
myRasterViewPort->mWidth = static_cast<int>( myRasterViewPort->mBottomRightPoint.x() - myRasterViewPort->mTopLeftPoint.x() );
371+
myRasterViewPort->mHeight = static_cast<int>( myRasterViewPort->mBottomRightPoint.y() - myRasterViewPort->mTopLeftPoint.y() );
372372

373-
myRasterViewPort->mWidth = static_cast<int>( qAbs(( myRasterExtent.width() / theQgsMapToPixel.mapUnitsPerPixel() ) ) );
374-
myRasterViewPort->mHeight = static_cast<int>( qAbs(( myRasterExtent.height() / theQgsMapToPixel.mapUnitsPerPixel() ) ) );
375373

376374
//the drawable area can start to get very very large when you get down displaying 2x2 or smaller, this is becasue
377375
//theQgsMapToPixel.mapUnitsPerPixel() is less then 1,

0 commit comments

Comments
 (0)