Skip to content

Commit

Permalink
Ported r6598 to trunk
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@6599 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
homann committed Feb 15, 2007
1 parent 9eaca7f commit ca4f055
Showing 1 changed file with 95 additions and 17 deletions.
112 changes: 95 additions & 17 deletions src/core/raster/qgsrasterlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down Expand Up @@ -1326,7 +1334,7 @@ void QgsRasterLayer::draw (QPainter * theQPainter,
break;

}

//see if debug info is wanted
if (showDebugOverlayFlag)
{
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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)+\
Expand All @@ -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;
}

Expand Down

0 comments on commit ca4f055

Please sign in to comment.