Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
-removed the use of setPixel() in the rendering routines, thanks Yan …
…for the suggestion

-swapped all of the myColumns and myRows in the rendering routines, as they were reversed

git-svn-id: http://svn.osgeo.org/qgis/trunk@10918 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
ersts committed Jun 13, 2009
1 parent ec96e7e commit 0f94f59
Showing 1 changed file with 64 additions and 40 deletions.
104 changes: 64 additions & 40 deletions src/core/raster/qgsrasterlayer.cpp
Expand Up @@ -1555,12 +1555,13 @@ bool QgsRasterLayer::draw( QgsRenderContext& rendererContext )
int newTransparency;
for ( int myHeightRunner = 0; myHeightRunner < myHeight; myHeightRunner++ )
{
QRgb* myLineBuffer = ( QRgb* ) transparentImageCopy->scanLine( myHeightRunner );
for ( int myWidthRunner = 0; myWidthRunner < myWidth; myWidthRunner++ )
{
myRgb = image->pixel( myWidthRunner, myHeightRunner );
//combine transparency from WMS and layer transparency
newTransparency = ( double ) mTransparencyLevel / 255.0 * ( double )( qAlpha( myRgb ) );
image->setPixel( myWidthRunner, myHeightRunner, qRgba( qRed( myRgb ), qGreen( myRgb ), qBlue( myRgb ), newTransparency ) );
myLineBuffer[ myWidthRunner ] = qRgba( qRed( myRgb ), qGreen( myRgb ), qBlue( myRgb ), newTransparency );
}
}
}
Expand Down Expand Up @@ -2864,13 +2865,13 @@ QPixmap QgsRasterLayer::paletteAsPixmap( int theBandNumber )
double myValue = 0.0;
for ( int myRow = 0; myRow < mySize; myRow++ )
{
QRgb* myLineBuffer = ( QRgb* )myQImage.scanLine( myRow );
for ( int myCol = 0; myCol < mySize; myCol++ )
{

myValue = myStep * ( double )( myCol + myRow * mySize );
int c1, c2, c3;
myShader.shade( myValue, &c1, &c2, &c3 );
myQImage.setPixel( myCol, myRow, qRgb( c1, c2, c3 ) );
myLineBuffer[ myCol ] = qRgb( c1, c2, c3 );
}
}

Expand Down Expand Up @@ -4261,7 +4262,7 @@ void QgsRasterLayer::drawMultiBandColor( QPainter * theQPainter, QgsRasterViewPo
}

QImage myQImage = QImage( theRasterViewPort->drawableAreaXDim, theRasterViewPort->drawableAreaYDim, QImage::Format_ARGB32 );
myQImage.fill( qRgba( 255, 255, 255, 0 ) ); // fill transparent
QRgb myDefaultColor = qRgba( 255, 255, 255, 0 );

QgsRasterBandStats myRedBandStats;
QgsRasterBandStats myGreenBandStats;
Expand Down Expand Up @@ -4318,30 +4319,34 @@ void QgsRasterLayer::drawMultiBandColor( QPainter * theQPainter, QgsRasterViewPo
QgsContrastEnhancement* myBlueContrastEnhancement = contrastEnhancement( myBlueBandNo );

QgsDebugMsg( "Starting main render loop" );
for ( int myColumn = 0; myColumn < theRasterViewPort->drawableAreaYDim; ++myColumn )
for ( int myRow = 0; myRow < theRasterViewPort->drawableAreaYDim; ++myRow )
{
for ( int myRow = 0; myRow < theRasterViewPort->drawableAreaXDim; ++myRow )
QRgb* myLineBuffer = ( QRgb* )myQImage.scanLine( myRow );
for ( int myColumn = 0; myColumn < theRasterViewPort->drawableAreaXDim; ++myColumn )
{
myRedValue = readValue( myGdalRedData, ( GDALDataType )myRedType,
myColumn * theRasterViewPort->drawableAreaXDim + myRow );
myRow * theRasterViewPort->drawableAreaXDim + myColumn );
myGreenValue = readValue( myGdalGreenData, ( GDALDataType )myGreenType,
myColumn * theRasterViewPort->drawableAreaXDim + myRow );
myRow * theRasterViewPort->drawableAreaXDim + myColumn );
myBlueValue = readValue( myGdalBlueData, ( GDALDataType )myBlueType,
myColumn * theRasterViewPort->drawableAreaXDim + myRow );
myRow * theRasterViewPort->drawableAreaXDim + myColumn );

if ( mValidNoDataValue && (( myRedValue == mNoDataValue || myRedValue != myRedValue ) || ( myGreenValue == mNoDataValue || myGreenValue != myGreenValue ) || ( myBlueValue == mNoDataValue || myBlueValue != myBlueValue ) ) )
{
myLineBuffer[ myColumn ] = myDefaultColor;
continue;
}

if ( !myRedContrastEnhancement->isValueInDisplayableRange( myRedValue ) || !myGreenContrastEnhancement->isValueInDisplayableRange( myGreenValue ) || !myBlueContrastEnhancement->isValueInDisplayableRange( myBlueValue ) )
{
myLineBuffer[ myColumn ] = myDefaultColor;
continue;
}

myAlphaValue = mRasterTransparency.alphaValue( myRedValue, myGreenValue, myBlueValue, mTransparencyLevel );
if ( 0 == myAlphaValue )
{
myLineBuffer[ myColumn ] = myDefaultColor;
continue;
}

Expand All @@ -4356,7 +4361,7 @@ void QgsRasterLayer::drawMultiBandColor( QPainter * theQPainter, QgsRasterViewPo
myStretchedBlueValue = 255 - myStretchedBlueValue;
}

myQImage.setPixel( myRow, myColumn, qRgba( myStretchedRedValue, myStretchedGreenValue, myStretchedBlueValue, myAlphaValue ) );
myLineBuffer[ myColumn ] = qRgba( myStretchedRedValue, myStretchedGreenValue, myStretchedBlueValue, myAlphaValue );
}
}
//free the scanline memory
Expand Down Expand Up @@ -4432,7 +4437,7 @@ void QgsRasterLayer::drawPalettedSingleBandColor( QPainter * theQPainter, QgsRas
}

QImage myQImage = QImage( theRasterViewPort->drawableAreaXDim, theRasterViewPort->drawableAreaYDim, QImage::Format_ARGB32 );
myQImage.fill( qRgba( 255, 255, 255, 0 ) ); // fill transparent
QRgb myDefaultColor = qRgba( 255, 255, 255, 0 );

double myPixelValue = 0.0;
int myRedValue = 0;
Expand All @@ -4441,41 +4446,45 @@ void QgsRasterLayer::drawPalettedSingleBandColor( QPainter * theQPainter, QgsRas
int myAlphaValue = 0;

QgsDebugMsg( "Starting main render loop" );
for ( int myColumn = 0; myColumn < theRasterViewPort->drawableAreaYDim; ++myColumn )
for ( int myRow = 0; myRow < theRasterViewPort->drawableAreaYDim; ++myRow )
{
for ( int myRow = 0; myRow < theRasterViewPort->drawableAreaXDim; ++myRow )
QRgb* myLineBuffer = ( QRgb* )myQImage.scanLine( myRow );
for ( int myColumn = 0; myColumn < theRasterViewPort->drawableAreaXDim; ++myColumn )
{
myRedValue = 0;
myGreenValue = 0;
myBlueValue = 0;
myPixelValue = readValue( myGdalScanData, ( GDALDataType )myDataType,
myColumn * theRasterViewPort->drawableAreaXDim + myRow );
myRow * theRasterViewPort->drawableAreaXDim + myColumn );

if ( mValidNoDataValue && ( myPixelValue == mNoDataValue || myPixelValue != myPixelValue ) )
{
myLineBuffer[ myColumn ] = myDefaultColor;
continue;
}

myAlphaValue = mRasterTransparency.alphaValue( myPixelValue, mTransparencyLevel );
if ( 0 == myAlphaValue )
{
myLineBuffer[ myColumn ] = myDefaultColor;
continue;
}

if ( !mRasterShader->shade( myPixelValue, &myRedValue, &myGreenValue, &myBlueValue ) )
{
myLineBuffer[ myColumn ] = myDefaultColor;
continue;
}

if ( mInvertColor )
{
//Invert flag, flip blue and read
myQImage.setPixel( myRow, myColumn, qRgba( myBlueValue, myGreenValue, myRedValue, myAlphaValue ) );
myLineBuffer[ myColumn ] = qRgba( myBlueValue, myGreenValue, myRedValue, myAlphaValue );
}
else
{
//Normal
myQImage.setPixel( myRow, myColumn, qRgba( myRedValue, myGreenValue, myBlueValue, myAlphaValue ) );
myLineBuffer[ myColumn ] = qRgba( myRedValue, myGreenValue, myBlueValue, myAlphaValue );
}
}
}
Expand Down Expand Up @@ -4516,7 +4525,7 @@ void QgsRasterLayer::drawPalettedSingleBandGray( QPainter * theQPainter, QgsRast
}

QImage myQImage = QImage( theRasterViewPort->drawableAreaXDim, theRasterViewPort->drawableAreaYDim, QImage::Format_ARGB32 );
myQImage.fill( qRgba( 255, 255, 255, 0 ) ); // fill transparent
QRgb myDefaultColor = qRgba( 255, 255, 255, 0 );

double myPixelValue = 0.0;
int myRedValue = 0;
Expand All @@ -4525,43 +4534,47 @@ void QgsRasterLayer::drawPalettedSingleBandGray( QPainter * theQPainter, QgsRast
int myAlphaValue = 0;

QgsDebugMsg( "Starting main render loop" );
for ( int myColumn = 0; myColumn < theRasterViewPort->drawableAreaYDim; ++myColumn )
for ( int myRow = 0; myRow < theRasterViewPort->drawableAreaYDim; ++myRow )
{
for ( int myRow = 0; myRow < theRasterViewPort->drawableAreaXDim; ++myRow )
QRgb* myLineBuffer = ( QRgb* )myQImage.scanLine( myRow );
for ( int myColumn = 0; myColumn < theRasterViewPort->drawableAreaXDim; ++myColumn )
{
myRedValue = 0;
myGreenValue = 0;
myBlueValue = 0;
myPixelValue = readValue( myGdalScanData, ( GDALDataType )myDataType,
myColumn * theRasterViewPort->drawableAreaXDim + myRow );
myRow * theRasterViewPort->drawableAreaXDim + myColumn );

if ( mValidNoDataValue && ( myPixelValue == mNoDataValue || myPixelValue != myPixelValue ) )
{
myLineBuffer[ myColumn ] = myDefaultColor;
continue;
}

myAlphaValue = mRasterTransparency.alphaValue( myPixelValue, mTransparencyLevel );
if ( 0 == myAlphaValue )
{
myLineBuffer[ myColumn ] = myDefaultColor;
continue;
}

if ( !mRasterShader->shade( myPixelValue, &myRedValue, &myGreenValue, &myBlueValue ) )
{
myLineBuffer[ myColumn ] = myDefaultColor;
continue;
}

if ( mInvertColor )
{
//Invert flag, flip blue and read
double myGrayValue = ( 0.3 * ( double )myRedValue ) + ( 0.59 * ( double )myGreenValue ) + ( 0.11 * ( double )myBlueValue );
myQImage.setPixel( myRow, myColumn, qRgba(( int )myGrayValue, ( int )myGrayValue, ( int )myGrayValue, myAlphaValue ) );
myLineBuffer[ myColumn ] = qRgba(( int )myGrayValue, ( int )myGrayValue, ( int )myGrayValue, myAlphaValue );
}
else
{
//Normal
double myGrayValue = ( 0.3 * ( double )myBlueValue ) + ( 0.59 * ( double )myGreenValue ) + ( 0.11 * ( double )myRedValue );
myQImage.setPixel( myRow, myColumn, qRgba(( int )myGrayValue, ( int )myGrayValue, ( int )myGrayValue, myAlphaValue ) );
myLineBuffer[ myColumn ] = qRgba(( int )myGrayValue, ( int )myGrayValue, ( int )myGrayValue, myAlphaValue );
}
}
}
Expand Down Expand Up @@ -4600,7 +4613,7 @@ void QgsRasterLayer::drawPalettedSingleBandPseudoColor( QPainter * theQPainter,
}

QImage myQImage = QImage( theRasterViewPort->drawableAreaXDim, theRasterViewPort->drawableAreaYDim, QImage::Format_ARGB32 );
myQImage.fill( qRgba( 255, 255, 255, 0 ) ); // fill transparent
QRgb myDefaultColor = qRgba( 255, 255, 255, 0 );

if ( NULL == mRasterShader )
{
Expand Down Expand Up @@ -4631,41 +4644,45 @@ void QgsRasterLayer::drawPalettedSingleBandPseudoColor( QPainter * theQPainter,
int myAlphaValue = 0;

QgsDebugMsg( "Starting main render loop" );
for ( int myColumn = 0; myColumn < theRasterViewPort->drawableAreaYDim; ++myColumn )
for ( int myRow = 0; myRow < theRasterViewPort->drawableAreaYDim; ++myRow )
{
for ( int myRow = 0; myRow < theRasterViewPort->drawableAreaXDim; ++myRow )
QRgb* myLineBuffer = ( QRgb* )myQImage.scanLine( myRow );
for ( int myColumn = 0; myColumn < theRasterViewPort->drawableAreaXDim; ++myColumn )
{
myRedValue = 0;
myGreenValue = 0;
myBlueValue = 0;
myPixelValue = readValue( myGdalScanData, ( GDALDataType )myDataType,
myColumn * theRasterViewPort->drawableAreaXDim + myRow );
myRow * theRasterViewPort->drawableAreaXDim + myColumn );

if ( mValidNoDataValue && ( myPixelValue == mNoDataValue || myPixelValue != myPixelValue ) )
{
myLineBuffer[ myColumn ] = myDefaultColor;
continue;
}

myAlphaValue = mRasterTransparency.alphaValue( myPixelValue, mTransparencyLevel );
if ( 0 == myAlphaValue )
{
myLineBuffer[ myColumn ] = myDefaultColor;
continue;
}

if ( !mRasterShader->shade( myPixelValue, &myRedValue, &myGreenValue, &myBlueValue ) )
{
myLineBuffer[ myColumn ] = myDefaultColor;
continue;
}

if ( mInvertColor )
{
//Invert flag, flip blue and read
myQImage.setPixel( myRow, myColumn, qRgba( myBlueValue, myGreenValue, myRedValue, myAlphaValue ) );
myLineBuffer[ myColumn ] = qRgba( myBlueValue, myGreenValue, myRedValue, myAlphaValue );
}
else
{
//Normal
myQImage.setPixel( myRow, myColumn, qRgba( myRedValue, myGreenValue, myBlueValue, myAlphaValue ) );
myLineBuffer[ myColumn ] = qRgba( myRedValue, myGreenValue, myBlueValue, myAlphaValue );
}
}
}
Expand Down Expand Up @@ -4706,7 +4723,7 @@ void QgsRasterLayer::drawSingleBandGray( QPainter * theQPainter, QgsRasterViewPo
}

QImage myQImage = QImage( theRasterViewPort->drawableAreaXDim, theRasterViewPort->drawableAreaYDim, QImage::Format_ARGB32 );
myQImage.fill( qRgba( 255, 255, 255, 0 ) ); // fill transparent
QRgb myDefaultColor = qRgba( 255, 255, 255, 0 );

QgsRasterBandStats myGrayBandStats;

Expand Down Expand Up @@ -4735,30 +4752,34 @@ void QgsRasterLayer::drawSingleBandGray( QPainter * theQPainter, QgsRasterViewPo
int myGrayVal = 0;
int myAlphaValue = 0;
QgsContrastEnhancement* myContrastEnhancement = contrastEnhancement( theBandNo );
for ( int myColumn = 0; myColumn < theRasterViewPort->drawableAreaYDim; ++myColumn )
for ( int myRow = 0; myRow < theRasterViewPort->drawableAreaYDim; ++myRow )
{
for ( int myRow = 0; myRow < theRasterViewPort->drawableAreaXDim; ++myRow )
QRgb* myLineBuffer = ( QRgb* )myQImage.scanLine( myRow );
for ( int myColumn = 0; myColumn < theRasterViewPort->drawableAreaXDim; ++myColumn )
{
myGrayValue = readValue( myGdalScanData, myDataType,
myColumn * theRasterViewPort->drawableAreaXDim + myRow );
myRow * theRasterViewPort->drawableAreaXDim + myColumn );

// If mNoDataValue is 'nan', the comparison
// against myGrayVal will always fail ( nan==nan always
// returns false, by design), hence the slightly odd comparison
// of myGrayVal against itself.
if ( mValidNoDataValue && ( myGrayValue == mNoDataValue || myGrayValue != myGrayValue ) )
{
myLineBuffer[ myColumn ] = myDefaultColor;
continue;
}

if ( !myContrastEnhancement->isValueInDisplayableRange( myGrayValue ) )
{
myLineBuffer[ myColumn ] = myDefaultColor;
continue;
}

myAlphaValue = mRasterTransparency.alphaValue( myGrayValue, mTransparencyLevel );
if ( 0 == myAlphaValue )
{
myLineBuffer[ myColumn ] = myDefaultColor;
continue;
}

Expand All @@ -4770,8 +4791,7 @@ void QgsRasterLayer::drawSingleBandGray( QPainter * theQPainter, QgsRasterViewPo
myGrayVal = 255 - myGrayVal;
}

myQImage.setPixel( myRow, myColumn, qRgba( myGrayVal, myGrayVal, myGrayVal, myAlphaValue ) );

myLineBuffer[ myColumn ] = qRgba( myGrayVal, myGrayVal, myGrayVal, myAlphaValue );
}
}

Expand Down Expand Up @@ -4807,7 +4827,7 @@ void QgsRasterLayer::drawSingleBandPseudoColor( QPainter * theQPainter,
}

QImage myQImage = QImage( theRasterViewPort->drawableAreaXDim, theRasterViewPort->drawableAreaYDim, QImage::Format_ARGB32 );
myQImage.fill( qRgba( 255, 255, 255, 0 ) ); // fill transparent
QRgb myDefaultColor = qRgba( 255, 255, 255, 0 );

if ( NULL == mRasterShader )
{
Expand Down Expand Up @@ -4839,38 +4859,42 @@ void QgsRasterLayer::drawSingleBandPseudoColor( QPainter * theQPainter,
double myPixelValue = 0.0;
int myAlphaValue = 0;
QgsDebugMsg( "Starting main render loop" );
for ( int myColumn = 0; myColumn < theRasterViewPort->drawableAreaYDim; ++myColumn )
for ( int myRow = 0; myRow < theRasterViewPort->drawableAreaYDim; ++myRow )
{
for ( int myRow = 0; myRow < theRasterViewPort->drawableAreaXDim; ++myRow )
QRgb* myLineBuffer = ( QRgb* )myQImage.scanLine( myRow );
for ( int myColumn = 0; myColumn < theRasterViewPort->drawableAreaXDim; ++myColumn )
{
myPixelValue = readValue( myGdalScanData, myDataType,
myColumn * theRasterViewPort->drawableAreaXDim + myRow );
myRow * theRasterViewPort->drawableAreaXDim + myColumn );

if ( mValidNoDataValue && ( myPixelValue == mNoDataValue || myPixelValue != myPixelValue ) )
{
myLineBuffer[ myColumn ] = myDefaultColor;
continue;
}

myAlphaValue = mRasterTransparency.alphaValue( myPixelValue, mTransparencyLevel );
if ( 0 == myAlphaValue )
{
myLineBuffer[ myColumn ] = myDefaultColor;
continue;
}

if ( !mRasterShader->shade( myPixelValue, &myRedValue, &myGreenValue, &myBlueValue ) )
{
myLineBuffer[ myColumn ] = myDefaultColor;
continue;
}

if ( mInvertColor )
{
//Invert flag, flip blue and read
myQImage.setPixel( myRow, myColumn, qRgba( myBlueValue, myGreenValue, myRedValue, myAlphaValue ) );
myLineBuffer[ myColumn ] = qRgba( myBlueValue, myGreenValue, myRedValue, myAlphaValue );
}
else
{
//Normal
myQImage.setPixel( myRow, myColumn, qRgba( myRedValue, myGreenValue, myBlueValue, myAlphaValue ) );
myLineBuffer[ myColumn ] = qRgba( myRedValue, myGreenValue, myBlueValue, myAlphaValue );
}
} //end of columnwise loop
} //end of rowwise loop
Expand Down

0 comments on commit 0f94f59

Please sign in to comment.