bool QgsRasterBlock::isEmpty() const { QgsDebugMsg( QString( "mWidth= %1 mHeight = %2 mDataType = %3 mData = %4 mImage = %5" ).arg( mWidth ).arg( mHeight ).arg( mDataType ).arg(( intptr_t )mData ).arg(( intptr_t )mImage ) ); if ( mWidth == 0 || mHeight == 0 || ( typeIsNumeric( mDataType ) && mData == 0 ) || ( typeIsColor( mDataType ) && mImage == 0 ) ) { return true; } return false; }
bool QgsRasterBlock::reset( QGis::DataType theDataType, int theWidth, int theHeight, double theNoDataValue ) { QgsDebugMsg( QString( "theWidth= %1 theHeight = %2 theDataType = %3 theNoDataValue = %4" ).arg( theWidth ).arg( theHeight ).arg( theDataType ).arg( theNoDataValue ) ); qgsFree( mData ); mData = nullptr; delete mImage; mImage = nullptr; qgsFree( mNoDataBitmap ); mNoDataBitmap = nullptr; mDataType = QGis::UnknownDataType; mTypeSize = 0; mWidth = 0; mHeight = 0; mHasNoDataValue = false; mNoDataValue = std::numeric_limits<double>::quiet_NaN(); mValid = false; if ( typeIsNumeric( theDataType ) ) { QgsDebugMsg( "Numeric type" ); qgssize tSize = typeSize( theDataType ); QgsDebugMsg( QString( "allocate %1 bytes" ).arg( tSize * theWidth * theHeight ) ); mData = qgsMalloc( tSize * theWidth * theHeight ); if ( !mData ) { QgsDebugMsg( QString( "Couldn't allocate data memory of %1 bytes" ).arg( tSize * theWidth * theHeight ) ); return false; } } else if ( typeIsColor( theDataType ) ) { QgsDebugMsg( "Color type" ); QImage::Format format = imageFormat( theDataType ); mImage = new QImage( theWidth, theHeight, format ); } else { QgsDebugMsg( "Wrong data type" ); return false; } mValid = true; mDataType = theDataType; mTypeSize = QgsRasterBlock::typeSize( mDataType ); mWidth = theWidth; mHeight = theHeight; mHasNoDataValue = true; mNoDataValue = theNoDataValue; QgsDebugMsg( QString( "mWidth= %1 mHeight = %2 mDataType = %3 mData = %4 mImage = %5" ).arg( mWidth ).arg( mHeight ).arg( mDataType ) .arg( reinterpret_cast< ulong >( mData ) ).arg( reinterpret_cast< ulong >( mImage ) ) ); return true; }
bool QgsRasterBlock::isEmpty() const { QgsDebugMsg( QString( "mWidth= %1 mHeight = %2 mDataType = %3 mData = %4 mImage = %5" ).arg( mWidth ).arg( mHeight ).arg( mDataType ) .arg( reinterpret_cast< ulong >( mData ) ).arg( reinterpret_cast< ulong >( mImage ) ) ); if ( mWidth == 0 || mHeight == 0 || ( typeIsNumeric( mDataType ) && !mData ) || ( typeIsColor( mDataType ) && !mImage ) ) { return true; } return false; }
bool QgsRasterBlock::setIsNoData() { QgsDebugMsg( "Entered" ); if ( typeIsNumeric( mDataType ) ) { if ( mHasNoDataValue ) { if ( !mData ) { QgsDebugMsg( "Data block not allocated" ); return false; } QgsDebugMsg( "set mData to mNoDataValue" ); int dataTypeSize = typeSize( mDataType ); QByteArray noDataByteArray = valueBytes( mDataType, mNoDataValue ); char *nodata = noDataByteArray.data(); for ( qgssize i = 0; i < static_cast< qgssize >( mWidth )*mHeight; i++ ) { memcpy( reinterpret_cast< char* >( mData ) + i*dataTypeSize, nodata, dataTypeSize ); } } else { // use bitmap if ( !mNoDataBitmap ) { if ( !createNoDataBitmap() ) { return false; } } QgsDebugMsg( "set mNoDataBitmap to 1" ); memset( mNoDataBitmap, 0xff, mNoDataBitmapSize ); } return true; } else { // image if ( !mImage ) { QgsDebugMsg( "Image not allocated" ); return false; } QgsDebugMsg( "Fill image" ); mImage->fill( mNoDataColor ); return true; } }
bool QgsRasterRenderer::setInput( QgsRasterInterface* input ) { // Renderer can only work with numerical values in at least 1 band if ( !input ) return false; if ( !mOn ) { // In off mode we can connect to anything mInput = input; return true; } for ( int i = 1; i <= input->bandCount(); i++ ) { if ( !typeIsNumeric( input->dataType( i ) ) ) { return false; } } mInput = input; return true; }