Skip to content

Commit

Permalink
fix set image no data, fixes #8773
Browse files Browse the repository at this point in the history
  • Loading branch information
blazek committed Oct 17, 2013
1 parent 753977d commit 2b8197f
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions src/core/raster/qgsrasterblock.cpp
Expand Up @@ -535,12 +535,13 @@ bool QgsRasterBlock::setIsNoDataExcept( const QRect & theExceptRect )
QgsDebugMsg( "set mNoDataBitmap to 1" );

char *nodataRow = new char[mNoDataBitmapWidth]; // full row of no data
// TODO: we can simply set all bytes to 11111111 (~0) I think
memset( nodataRow, 0, mNoDataBitmapWidth );
for ( int c = 0; c < mWidth; c ++ )
{
int byte = c / 8;
int bit = c % 8;
int nodata = 0x80 >> bit;
char nodata = 0x80 >> bit;
memset( nodataRow + byte, nodataRow[byte] | nodata, 1 );
}

Expand All @@ -558,7 +559,7 @@ bool QgsRasterBlock::setIsNoDataExcept( const QRect & theExceptRect )
if ( c >= left && c <= right ) continue; // middle
int byte = c / 8;
int bit = c % 8;
int nodata = 0x80 >> bit;
char nodata = 0x80 >> bit;
memset( nodataRow + byte, nodataRow[byte] | nodata, 1 );
}
for ( int r = top; r <= bottom; r++ )
Expand All @@ -578,7 +579,22 @@ bool QgsRasterBlock::setIsNoDataExcept( const QRect & theExceptRect )
QgsDebugMsg( "Image not allocated" );
return false;
}
QgsDebugMsg( "Fill image" );

if ( mImage->width() != mWidth || mImage->height() != mHeight )
{
QgsDebugMsg( "Image and block size differ" );
return false;
}

QgsDebugMsg( QString( "Fill image depth = %1" ).arg( mImage->depth() ) );

// TODO: support different depths
if ( mImage->depth() != 32 )
{
QgsDebugMsg( "Unsupported image depth" );
return false;
}

QRgb nodataRgba = qRgba( 0, 0, 0, 0 );
QRgb *nodataRow = new QRgb[mWidth]; // full row of no data
int rgbSize = sizeof( QRgb );
Expand All @@ -597,12 +613,15 @@ bool QgsRasterBlock::setIsNoDataExcept( const QRect & theExceptRect )
// middle
for ( int r = top; r <= bottom; r++ )
{
size_t i = r * mWidth;
size_t i = ( size_t )r * mWidth;
// middle left
memcpy(( void * )( mImage->bits() + rgbSize*i ), nodataRow, rgbSize*left );
if ( left > 0 )
{
memcpy(( void * )( mImage->bits() + rgbSize*i ), nodataRow, rgbSize*( left - 1 ) );
}
// middle right
i += right + 1;
int w = mWidth - right;
int w = mWidth - right - 1;
memcpy(( void * )( mImage->bits() + rgbSize*i ), nodataRow, rgbSize*w );
}
delete [] nodataRow;
Expand Down

0 comments on commit 2b8197f

Please sign in to comment.