@@ -535,12 +535,13 @@ bool QgsRasterBlock::setIsNoDataExcept( const QRect & theExceptRect )
535
535
QgsDebugMsg ( " set mNoDataBitmap to 1" );
536
536
537
537
char *nodataRow = new char [mNoDataBitmapWidth ]; // full row of no data
538
+ // TODO: we can simply set all bytes to 11111111 (~0) I think
538
539
memset ( nodataRow, 0 , mNoDataBitmapWidth );
539
540
for ( int c = 0 ; c < mWidth ; c ++ )
540
541
{
541
542
int byte = c / 8 ;
542
543
int bit = c % 8 ;
543
- int nodata = 0x80 >> bit;
544
+ char nodata = 0x80 >> bit;
544
545
memset ( nodataRow + byte, nodataRow[byte] | nodata, 1 );
545
546
}
546
547
@@ -558,7 +559,7 @@ bool QgsRasterBlock::setIsNoDataExcept( const QRect & theExceptRect )
558
559
if ( c >= left && c <= right ) continue ; // middle
559
560
int byte = c / 8 ;
560
561
int bit = c % 8 ;
561
- int nodata = 0x80 >> bit;
562
+ char nodata = 0x80 >> bit;
562
563
memset ( nodataRow + byte, nodataRow[byte] | nodata, 1 );
563
564
}
564
565
for ( int r = top; r <= bottom; r++ )
@@ -578,7 +579,22 @@ bool QgsRasterBlock::setIsNoDataExcept( const QRect & theExceptRect )
578
579
QgsDebugMsg ( " Image not allocated" );
579
580
return false ;
580
581
}
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
+
582
598
QRgb nodataRgba = qRgba ( 0 , 0 , 0 , 0 );
583
599
QRgb *nodataRow = new QRgb[mWidth ]; // full row of no data
584
600
int rgbSize = sizeof ( QRgb );
@@ -597,12 +613,15 @@ bool QgsRasterBlock::setIsNoDataExcept( const QRect & theExceptRect )
597
613
// middle
598
614
for ( int r = top; r <= bottom; r++ )
599
615
{
600
- size_t i = r * mWidth ;
616
+ size_t i = ( size_t ) r * mWidth ;
601
617
// 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
+ }
603
622
// middle right
604
623
i += right + 1 ;
605
- int w = mWidth - right;
624
+ int w = mWidth - right - 1 ;
606
625
memcpy (( void * )( mImage ->bits () + rgbSize*i ), nodataRow, rgbSize*w );
607
626
}
608
627
delete [] nodataRow;
0 commit comments