mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-25 00:58:06 -05:00
Ported r6598 to trunk
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@6599 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
parent
9eaca7f909
commit
ca4f055a27
@ -1121,11 +1121,19 @@ bool QgsRasterLayer::draw(QPainter * theQPainter,
|
||||
|
||||
// /\/\/\ - added to handle zoomed-in rasters
|
||||
|
||||
if ((myRasterViewPort->drawableAreaXDimInt) > 4000 && (myRasterViewPort->drawableAreaYDimInt > 4000))
|
||||
{
|
||||
// We have scale one raster pixel to more than 4000 screen pixels. What's the point of showing this layer?
|
||||
// Instead, we just stop displaying the layer. Prevents allocating the entire world of memory for showing
|
||||
// The pixel in all its glory.
|
||||
QgsDebugMsg("Too zoomed out! Raster will not display");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// Provider mode: See if a provider key is specified, and if so use the provider instead
|
||||
|
||||
|
||||
QgsDebugMsg("QgsRasterLayer::draw: Checking for provider key.");
|
||||
|
||||
|
||||
if (!mProviderKey.isEmpty())
|
||||
{
|
||||
QgsDebugMsg("QgsRasterLayer::draw: Wanting a '" + mProviderKey + "' provider to draw this.");
|
||||
@ -1326,7 +1334,7 @@ void QgsRasterLayer::draw (QPainter * theQPainter,
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
|
||||
//see if debug info is wanted
|
||||
if (showDebugOverlayFlag)
|
||||
{
|
||||
@ -1344,6 +1352,12 @@ void QgsRasterLayer::drawSingleBandGray(QPainter * theQPainter, QgsRasterViewPor
|
||||
GDALDataType myDataType = myGdalBand->GetRasterDataType();
|
||||
void *myGdalScanData = readData ( myGdalBand, theRasterViewPort );
|
||||
|
||||
/* Check for out of memory error */
|
||||
if (myGdalScanData == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
QImage myQImage = QImage(theRasterViewPort->drawableAreaXDimInt, theRasterViewPort->drawableAreaYDimInt, 32);
|
||||
//myQImage.fill(0);
|
||||
myQImage.setAlphaBuffer(true);
|
||||
@ -1432,6 +1446,8 @@ void QgsRasterLayer::drawSingleBandGray(QPainter * theQPainter, QgsRasterViewPor
|
||||
myQImage.setPixel(myRowInt, myColumnInt, qRgba(myGrayValInt, myGrayValInt, myGrayValInt, mTransparencyLevel));
|
||||
}
|
||||
}
|
||||
|
||||
/* TODO: Should readData be freed here? */
|
||||
|
||||
//render any inline filters
|
||||
filterLayer(&myQImage);
|
||||
@ -1487,6 +1503,12 @@ void QgsRasterLayer::drawSingleBandPseudoColor(QPainter * theQPainter,
|
||||
GDALDataType myDataType = myGdalBand->GetRasterDataType();
|
||||
void *myGdalScanData = readData ( myGdalBand, theRasterViewPort );
|
||||
|
||||
/* Check for out of memory error */
|
||||
if (myGdalScanData == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
QImage myQImage = QImage(theRasterViewPort->drawableAreaXDimInt, theRasterViewPort->drawableAreaYDimInt, 32);
|
||||
//myQImage.fill(0);
|
||||
myQImage.setAlphaBuffer(true);
|
||||
@ -1704,6 +1726,13 @@ void QgsRasterLayer::drawPalettedSingleBandColor(QPainter * theQPainter, QgsRast
|
||||
GDALRasterBand *myGdalBand = gdalDataset->GetRasterBand(theBandNoInt);
|
||||
GDALDataType myDataType = myGdalBand->GetRasterDataType();
|
||||
void *myGdalScanData = readData ( myGdalBand, theRasterViewPort );
|
||||
|
||||
/* Check for out of memory error */
|
||||
if (myGdalScanData == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
QgsColorTable *myColorTable = colorTable ( theBandNoInt );
|
||||
|
||||
QImage myQImage = QImage(theRasterViewPort->drawableAreaXDimInt, theRasterViewPort->drawableAreaYDimInt, 32);
|
||||
@ -1734,6 +1763,9 @@ void QgsRasterLayer::drawPalettedSingleBandColor(QPainter * theQPainter, QgsRast
|
||||
myQImage.setPixel(myRowInt, myColumnInt, qRgba(c1, c2, c3, mTransparencyLevel));
|
||||
}
|
||||
}
|
||||
|
||||
/* TODO: Should readData be freed here? */
|
||||
|
||||
//render any inline filters
|
||||
filterLayer(&myQImage);
|
||||
|
||||
@ -1794,6 +1826,13 @@ void QgsRasterLayer::drawPalettedSingleBandGray(QPainter * theQPainter, QgsRaste
|
||||
GDALRasterBand *myGdalBand = gdalDataset->GetRasterBand(theBandNoInt);
|
||||
GDALDataType myDataType = myGdalBand->GetRasterDataType();
|
||||
void *myGdalScanData = readData ( myGdalBand, theRasterViewPort );
|
||||
|
||||
/* Check for out of memory error */
|
||||
if (myGdalScanData == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
QgsColorTable *myColorTable = &(myRasterBandStats.colorTable);
|
||||
|
||||
QImage myQImage = QImage(theRasterViewPort->drawableAreaXDimInt, theRasterViewPort->drawableAreaYDimInt, 32);
|
||||
@ -1898,6 +1937,13 @@ void QgsRasterLayer::drawPalettedSingleBandPseudoColor(QPainter * theQPainter, Q
|
||||
GDALRasterBand *myGdalBand = gdalDataset->GetRasterBand(theBandNoInt);
|
||||
GDALDataType myDataType = myGdalBand->GetRasterDataType();
|
||||
void *myGdalScanData = readData ( myGdalBand, theRasterViewPort );
|
||||
|
||||
/* Check for out of memory error */
|
||||
if (myGdalScanData == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
QgsColorTable *myColorTable = &(myRasterBandStats.colorTable);
|
||||
|
||||
QImage myQImage = QImage(theRasterViewPort->drawableAreaXDimInt, theRasterViewPort->drawableAreaYDimInt, 32);
|
||||
@ -2134,6 +2180,13 @@ void QgsRasterLayer::drawPalettedMultiBandColor(QPainter * theQPainter, QgsRaste
|
||||
GDALRasterBand *myGdalBand = gdalDataset->GetRasterBand(theBandNoInt);
|
||||
GDALDataType myDataType = myGdalBand->GetRasterDataType();
|
||||
void *myGdalScanData = readData ( myGdalBand, theRasterViewPort );
|
||||
|
||||
/* Check for out of memory error */
|
||||
if (myGdalScanData == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
QgsColorTable *myColorTable = colorTable ( theBandNoInt );
|
||||
|
||||
QImage myQImage = QImage(theRasterViewPort->drawableAreaXDimInt, theRasterViewPort->drawableAreaYDimInt, 32);
|
||||
@ -2272,6 +2325,16 @@ void QgsRasterLayer::drawMultiBandColor(QPainter * theQPainter, QgsRasterViewPor
|
||||
void *myGdalGreenData = readData ( myGdalGreenBand, theRasterViewPort );
|
||||
void *myGdalBlueData = readData ( myGdalBlueBand, theRasterViewPort );
|
||||
|
||||
/* Check for out of memory error */
|
||||
if (myGdalRedData == NULL || myGdalGreenData == NULL || myGdalBlueData == NULL)
|
||||
{
|
||||
// Safe to free NULL-pointer */
|
||||
VSIFree(myGdalRedData);
|
||||
VSIFree(myGdalGreenData);
|
||||
VSIFree(myGdalBlueData);
|
||||
return;
|
||||
}
|
||||
|
||||
bool haveTransparencyBand(false);
|
||||
GDALRasterBand *myGdalTransparentBand;
|
||||
GDALDataType myTransparentType;
|
||||
@ -2284,6 +2347,14 @@ void QgsRasterLayer::drawMultiBandColor(QPainter * theQPainter, QgsRasterViewPor
|
||||
myGdalTransparentBand = gdalDataset->GetRasterBand(myTransparentBandNoInt);
|
||||
myTransparentType = myGdalTransparentBand->GetRasterDataType();
|
||||
myGdalTransparentData = readData ( myGdalTransparentBand, theRasterViewPort );
|
||||
if (myGdalTransparentData == NULL)
|
||||
{
|
||||
// Safe to free NULL-pointer */
|
||||
VSIFree(myGdalRedData);
|
||||
VSIFree(myGdalGreenData);
|
||||
VSIFree(myGdalBlueData);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
QImage myQImage = QImage(theRasterViewPort->drawableAreaXDimInt, theRasterViewPort->drawableAreaYDimInt, 32);
|
||||
@ -4377,8 +4448,6 @@ void *QgsRasterLayer::readData ( GDALRasterBand *gdalBand, QgsRasterViewPort *vi
|
||||
GDALDataType type = gdalBand->GetRasterDataType();
|
||||
int size = GDALGetDataTypeSize ( type ) / 8;
|
||||
|
||||
void *data = CPLMalloc ( size * viewPort->drawableAreaXDimInt * viewPort->drawableAreaYDimInt );
|
||||
|
||||
QgsDebugMsg("QgsRasterLayer::readData: calling RasterIO with " +\
|
||||
QString(", source NW corner: ") + QString::number(viewPort->rectXOffsetInt)+\
|
||||
", " + QString::number(viewPort->rectYOffsetInt)+\
|
||||
@ -4387,20 +4456,29 @@ void *QgsRasterLayer::readData ( GDALRasterBand *gdalBand, QgsRasterViewPort *vi
|
||||
", dest size: " + QString::number(viewPort->drawableAreaXDimInt)+\
|
||||
", " + QString::number(viewPort->drawableAreaYDimInt));
|
||||
|
||||
CPLErr myErr = gdalBand->RasterIO ( GF_Read,
|
||||
viewPort->rectXOffsetInt,
|
||||
viewPort->rectYOffsetInt,
|
||||
viewPort->clippedWidthInt,
|
||||
viewPort->clippedHeightInt,
|
||||
data,
|
||||
viewPort->drawableAreaXDimInt,
|
||||
viewPort->drawableAreaYDimInt,
|
||||
type, 0, 0 );
|
||||
if (myErr != CPLE_None)
|
||||
void *data = VSIMalloc ( size * viewPort->drawableAreaXDimInt * viewPort->drawableAreaYDimInt );
|
||||
|
||||
/* Abort if out of memory */
|
||||
if (data == NULL)
|
||||
{
|
||||
QgsLogger::warning("RaterIO error: " + QString(CPLGetLastErrorMsg()));
|
||||
QgsDebugMsg("Layer " + this->name() + " couldn't allocate enough memory. Ignoring");
|
||||
}
|
||||
else
|
||||
{
|
||||
CPLErr myErr = gdalBand->RasterIO ( GF_Read,
|
||||
viewPort->rectXOffsetInt,
|
||||
viewPort->rectYOffsetInt,
|
||||
viewPort->clippedWidthInt,
|
||||
viewPort->clippedHeightInt,
|
||||
data,
|
||||
viewPort->drawableAreaXDimInt,
|
||||
viewPort->drawableAreaYDimInt,
|
||||
type, 0, 0 );
|
||||
if (myErr != CPLE_None)
|
||||
{
|
||||
QgsLogger::warning("RaterIO error: " + QString(CPLGetLastErrorMsg()));
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user