Skip to content

Commit 4cafb1a

Browse files
author
ersts
committed
-Patch for slowdown or segfault when zooming very far into rasters.
-Closes ticket #2268 git-svn-id: http://svn.osgeo.org/qgis/trunk@12793 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 3c28f5d commit 4cafb1a

File tree

1 file changed

+112
-5
lines changed

1 file changed

+112
-5
lines changed

src/core/raster/qgsrasterlayer.cpp

+112-5
Original file line numberDiff line numberDiff line change
@@ -1533,6 +1533,15 @@ bool QgsRasterLayer::draw( QgsRenderContext& rendererContext )
15331533
myRasterViewPort->drawableAreaXDim = static_cast<int>( fabs(( myRasterViewPort->clippedWidth / theQgsMapToPixel.mapUnitsPerPixel() * mGeoTransform[1] ) ) + 0.5 );
15341534
myRasterViewPort->drawableAreaYDim = static_cast<int>( fabs(( myRasterViewPort->clippedHeight / theQgsMapToPixel.mapUnitsPerPixel() * mGeoTransform[5] ) ) + 0.5 );
15351535

1536+
//the drawable area can start to get very very large when you get down displaying 2x2 or smaller, this is becasue
1537+
//theQgsMapToPixel.mapUnitsPerPixel() is less then 1,
1538+
//so we will just get the pixel data and then render these special cases differently in paintImageToCanvas()
1539+
if( 2 >= myRasterViewPort->clippedWidth && 2 >= myRasterViewPort->clippedHeight )
1540+
{
1541+
myRasterViewPort->drawableAreaXDim = myRasterViewPort->clippedWidth;
1542+
myRasterViewPort->drawableAreaYDim = myRasterViewPort->clippedHeight;
1543+
}
1544+
15361545
QgsDebugMsg( QString( "mapUnitsPerPixel = %1" ).arg( theQgsMapToPixel.mapUnitsPerPixel() ) );
15371546
QgsDebugMsg( QString( "mWidth = %1" ).arg( mWidth ) );
15381547
QgsDebugMsg( QString( "mHeight = %1" ).arg( mHeight ) );
@@ -5064,6 +5073,8 @@ void QgsRasterLayer::paintImageToCanvas( QPainter* theQPainter, QgsRasterViewPor
50645073
);
50655074
}
50665075

5076+
5077+
50675078
QgsDebugMsg( "painting image to canvas from "
50685079
+ QString::number( paintXoffset ) + ", " + QString::number( paintYoffset )
50695080
+ " to "
@@ -5072,11 +5083,107 @@ void QgsRasterLayer::paintImageToCanvas( QPainter* theQPainter, QgsRasterViewPor
50725083
+ QString::number( static_cast<int>( theRasterViewPort->topLeftPoint.y() + 0.5 ) )
50735084
+ "." );
50745085

5075-
theQPainter->drawImage( static_cast<int>( theRasterViewPort->topLeftPoint.x() + 0.5 ),
5076-
static_cast<int>( theRasterViewPort->topLeftPoint.y() + 0.5 ),
5077-
*theImage,
5078-
paintXoffset,
5079-
paintYoffset );
5086+
//Catch special rendering cases
5087+
//INSTANCE: 1x1
5088+
if( 1 == theRasterViewPort->clippedWidth && 1 == theRasterViewPort->clippedHeight )
5089+
{
5090+
QColor myColor( theImage->pixel( 0, 0 ) );
5091+
myColor.setAlpha( qAlpha( theImage->pixel( 0, 0 ) ) );
5092+
theQPainter->fillRect( static_cast<int>( theRasterViewPort->topLeftPoint.x() + 0.5 ),
5093+
static_cast<int>( theRasterViewPort->topLeftPoint.y() + 0.5 ),
5094+
static_cast<int>( theRasterViewPort->bottomRightPoint.x() ),
5095+
static_cast<int>( theRasterViewPort->bottomRightPoint.y() ),
5096+
QBrush( myColor ) );
5097+
}
5098+
//1x2, 2x1 or 2x2
5099+
else if( 2 >= theRasterViewPort->clippedWidth && 2 >= theRasterViewPort->clippedHeight )
5100+
{
5101+
int myPixelBoundaryX = 0;
5102+
int myPixelBoundaryY = 0;
5103+
if( theQgsMapToPixel ) {
5104+
myPixelBoundaryX = static_cast<int>( theRasterViewPort->topLeftPoint.x() + 0.5 ) + static_cast<int>( fabs ( mGeoTransform[1] / theQgsMapToPixel->mapUnitsPerPixel() ) ) - paintXoffset;
5105+
myPixelBoundaryY = static_cast<int>( theRasterViewPort->topLeftPoint.y() + 0.5 ) + static_cast<int>( fabs(mGeoTransform[5] / theQgsMapToPixel->mapUnitsPerPixel() )) - paintYoffset;
5106+
}
5107+
5108+
//INSTANCE: 1x2
5109+
if( 1 == theRasterViewPort->clippedWidth ) {
5110+
QColor myColor( theImage->pixel( 0, 0 ) );
5111+
myColor.setAlpha( qAlpha( theImage->pixel( 0, 0 ) ) );
5112+
theQPainter->fillRect( static_cast<int>( theRasterViewPort->topLeftPoint.x() + 0.5 ),
5113+
static_cast<int>( theRasterViewPort->topLeftPoint.y() + 0.5 ),
5114+
static_cast<int>( theRasterViewPort->bottomRightPoint.x() ),
5115+
static_cast<int>( myPixelBoundaryY ),
5116+
QBrush( myColor ) );
5117+
myColor = QColor( theImage->pixel( 0, 1) );
5118+
myColor.setAlpha( qAlpha( theImage->pixel( 0, 1 ) ) );
5119+
theQPainter->fillRect( static_cast<int>( theRasterViewPort->topLeftPoint.x() + 0.5 ),
5120+
static_cast<int>( myPixelBoundaryY ),
5121+
static_cast<int>( theRasterViewPort->bottomRightPoint.x() ),
5122+
static_cast<int>( theRasterViewPort->bottomRightPoint.y() ),
5123+
QBrush( myColor ) );
5124+
}
5125+
else {
5126+
//INSTANCE: 2x1
5127+
if( 1 == theRasterViewPort->clippedHeight )
5128+
{
5129+
QColor myColor( theImage->pixel( 0, 0 ) );
5130+
myColor.setAlpha( qAlpha( theImage->pixel( 0,0 ) ) );
5131+
theQPainter->fillRect( static_cast<int>( theRasterViewPort->topLeftPoint.x() + 0.5 ),
5132+
static_cast<int>( theRasterViewPort->topLeftPoint.y() + 0.5 ),
5133+
static_cast<int>( myPixelBoundaryX ),
5134+
static_cast<int>( theRasterViewPort->bottomRightPoint.y() ),
5135+
QBrush( myColor ) );
5136+
myColor = QColor( theImage->pixel( 1, 0 ) );
5137+
myColor.setAlpha( qAlpha( theImage->pixel( 1, 0 ) ) );
5138+
theQPainter->fillRect( static_cast<int>( myPixelBoundaryX ),
5139+
static_cast<int>( theRasterViewPort->topLeftPoint.y() + 0.5 ),
5140+
static_cast<int>( theRasterViewPort->bottomRightPoint.x() ),
5141+
static_cast<int>( theRasterViewPort->bottomRightPoint.y() ),
5142+
QBrush( myColor ) );
5143+
}
5144+
//INSTANCE: 2x2
5145+
else
5146+
{
5147+
QColor myColor( theImage->pixel( 0, 0 ) );
5148+
myColor.setAlpha( qAlpha( theImage->pixel( 0, 0 ) ) );
5149+
theQPainter->fillRect( static_cast<int>( theRasterViewPort->topLeftPoint.x() + 0.5 ),
5150+
static_cast<int>( theRasterViewPort->topLeftPoint.y() + 0.5 ),
5151+
static_cast<int>(myPixelBoundaryX ),
5152+
static_cast<int>( myPixelBoundaryY ),
5153+
QBrush( myColor ) );
5154+
myColor = QColor( theImage->pixel( 1, 0 ) );
5155+
myColor.setAlpha( qAlpha( theImage->pixel( 1, 0 ) ) );
5156+
theQPainter->fillRect( static_cast<int>( myPixelBoundaryX ),
5157+
static_cast<int>( theRasterViewPort->topLeftPoint.y() + 0.5 ),
5158+
static_cast<int>( theRasterViewPort->bottomRightPoint.x() ),
5159+
static_cast<int>( myPixelBoundaryY ),
5160+
QBrush( myColor ) );
5161+
myColor = QColor( theImage->pixel( 0, 1 ) );
5162+
myColor.setAlpha( qAlpha( theImage->pixel( 0, 1 ) ) );
5163+
theQPainter->fillRect( static_cast<int>( theRasterViewPort->topLeftPoint.x() + 0.5 ),
5164+
static_cast<int>( myPixelBoundaryY ),
5165+
static_cast<int>( myPixelBoundaryX ),
5166+
static_cast<int>( theRasterViewPort->bottomRightPoint.y() ),
5167+
QBrush( myColor ) );
5168+
myColor = QColor( theImage->pixel( 1, 1 ) );
5169+
myColor.setAlpha( qAlpha( theImage->pixel( 1, 1 ) ) );
5170+
theQPainter->fillRect( static_cast<int>( myPixelBoundaryX ),
5171+
static_cast<int>( myPixelBoundaryY ),
5172+
static_cast<int>( theRasterViewPort->bottomRightPoint.x() ),
5173+
static_cast<int>( theRasterViewPort->bottomRightPoint.y() ),
5174+
QBrush( myColor ) );
5175+
}
5176+
}
5177+
5178+
}
5179+
// INSTANCE: > 2x2, so just use the image filled by GDAL
5180+
else {
5181+
theQPainter->drawImage( static_cast<int>( theRasterViewPort->topLeftPoint.x() + 0.5 ),
5182+
static_cast<int>( theRasterViewPort->topLeftPoint.y() + 0.5 ),
5183+
*theImage,
5184+
paintXoffset,
5185+
paintYoffset );
5186+
}
50805187
}
50815188

50825189
QString QgsRasterLayer::projectionWkt()

0 commit comments

Comments
 (0)