Skip to content

Commit 2b8197f

Browse files
committed
fix set image no data, fixes #8773
1 parent 753977d commit 2b8197f

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

src/core/raster/qgsrasterblock.cpp

+25-6
Original file line numberDiff line numberDiff line change
@@ -535,12 +535,13 @@ bool QgsRasterBlock::setIsNoDataExcept( const QRect & theExceptRect )
535535
QgsDebugMsg( "set mNoDataBitmap to 1" );
536536

537537
char *nodataRow = new char[mNoDataBitmapWidth]; // full row of no data
538+
// TODO: we can simply set all bytes to 11111111 (~0) I think
538539
memset( nodataRow, 0, mNoDataBitmapWidth );
539540
for ( int c = 0; c < mWidth; c ++ )
540541
{
541542
int byte = c / 8;
542543
int bit = c % 8;
543-
int nodata = 0x80 >> bit;
544+
char nodata = 0x80 >> bit;
544545
memset( nodataRow + byte, nodataRow[byte] | nodata, 1 );
545546
}
546547

@@ -558,7 +559,7 @@ bool QgsRasterBlock::setIsNoDataExcept( const QRect & theExceptRect )
558559
if ( c >= left && c <= right ) continue; // middle
559560
int byte = c / 8;
560561
int bit = c % 8;
561-
int nodata = 0x80 >> bit;
562+
char nodata = 0x80 >> bit;
562563
memset( nodataRow + byte, nodataRow[byte] | nodata, 1 );
563564
}
564565
for ( int r = top; r <= bottom; r++ )
@@ -578,7 +579,22 @@ bool QgsRasterBlock::setIsNoDataExcept( const QRect & theExceptRect )
578579
QgsDebugMsg( "Image not allocated" );
579580
return false;
580581
}
581-
QgsDebugMsg( "Fill image" );
582+
583+
if ( mImage->width() != mWidth || mImage->height() != mHeight )
584+
{
585+
QgsDebugMsg( "Image and block size differ" );
586+
return false;
587+
}
588+
589+
QgsDebugMsg( QString( "Fill image depth = %1" ).arg( mImage->depth() ) );
590+
591+
// TODO: support different depths
592+
if ( mImage->depth() != 32 )
593+
{
594+
QgsDebugMsg( "Unsupported image depth" );
595+
return false;
596+
}
597+
582598
QRgb nodataRgba = qRgba( 0, 0, 0, 0 );
583599
QRgb *nodataRow = new QRgb[mWidth]; // full row of no data
584600
int rgbSize = sizeof( QRgb );
@@ -597,12 +613,15 @@ bool QgsRasterBlock::setIsNoDataExcept( const QRect & theExceptRect )
597613
// middle
598614
for ( int r = top; r <= bottom; r++ )
599615
{
600-
size_t i = r * mWidth;
616+
size_t i = ( size_t )r * mWidth;
601617
// middle left
602-
memcpy(( void * )( mImage->bits() + rgbSize*i ), nodataRow, rgbSize*left );
618+
if ( left > 0 )
619+
{
620+
memcpy(( void * )( mImage->bits() + rgbSize*i ), nodataRow, rgbSize*( left - 1 ) );
621+
}
603622
// middle right
604623
i += right + 1;
605-
int w = mWidth - right;
624+
int w = mWidth - right - 1;
606625
memcpy(( void * )( mImage->bits() + rgbSize*i ), nodataRow, rgbSize*w );
607626
}
608627
delete [] nodataRow;

0 commit comments

Comments
 (0)