Skip to content

Commit e45958e

Browse files
committed
Move more raster block methods to header for better compiler optimisation
1 parent fe863cb commit e45958e

File tree

2 files changed

+160
-189
lines changed

2 files changed

+160
-189
lines changed

src/core/raster/qgsrasterblock.cpp

-173
Original file line numberDiff line numberDiff line change
@@ -219,11 +219,6 @@ Qgis::DataType QgsRasterBlock::typeWithNoDataValue( Qgis::DataType dataType, dou
219219
return newDataType;
220220
}
221221

222-
bool QgsRasterBlock::hasNoData() const
223-
{
224-
return mHasNoDataValue || mNoDataBitmap;
225-
}
226-
227222
void QgsRasterBlock::setNoDataValue( double noDataValue )
228223
{
229224
mHasNoDataValue = true;
@@ -236,147 +231,6 @@ void QgsRasterBlock::resetNoDataValue()
236231
mNoDataValue = std::numeric_limits<double>::quiet_NaN();
237232
}
238233

239-
bool QgsRasterBlock::isNoDataValue( double value, double noDataValue )
240-
{
241-
// TODO: optimize no data value test by memcmp()
242-
// More precise would be std::isnan(value) && std::isnan(noDataValue(bandNo)), but probably
243-
// not important and slower
244-
return std::isnan( value ) ||
245-
qgsDoubleNear( value, noDataValue );
246-
}
247-
248-
double QgsRasterBlock::value( int row, int column ) const
249-
{
250-
return value( static_cast< qgssize >( row ) * mWidth + column );
251-
}
252-
253-
QRgb QgsRasterBlock::color( qgssize index ) const
254-
{
255-
int row = std::floor( static_cast< double >( index ) / mWidth );
256-
int column = index % mWidth;
257-
return color( row, column );
258-
}
259-
260-
QRgb QgsRasterBlock::color( int row, int column ) const
261-
{
262-
if ( !mImage ) return NO_DATA_COLOR;
263-
264-
return mImage->pixel( column, row );
265-
}
266-
267-
bool QgsRasterBlock::isNoData( qgssize index )
268-
{
269-
if ( !mHasNoDataValue && !mNoDataBitmap ) return false;
270-
if ( index >= static_cast< qgssize >( mWidth )*mHeight )
271-
{
272-
QgsDebugMsg( QString( "Index %1 out of range (%2 x %3)" ).arg( index ).arg( mWidth ).arg( mHeight ) );
273-
return true; // we consider no data if outside
274-
}
275-
if ( mHasNoDataValue )
276-
{
277-
double value = readValue( mData, mDataType, index );
278-
return isNoDataValue( value );
279-
}
280-
// use no data bitmap
281-
if ( !mNoDataBitmap )
282-
{
283-
// no data are not defined
284-
return false;
285-
}
286-
// TODO: optimize
287-
int row = static_cast< int >( index ) / mWidth;
288-
int column = index % mWidth;
289-
qgssize byte = static_cast< qgssize >( row ) * mNoDataBitmapWidth + column / 8;
290-
int bit = column % 8;
291-
int mask = 0x80 >> bit;
292-
//int x = mNoDataBitmap[byte] & mask;
293-
//QgsDebugMsg ( QString("byte = %1 bit = %2 mask = %3 nodata = %4 is nodata = %5").arg(byte).arg(bit).arg(mask, 0, 2 ).arg( x, 0, 2 ).arg( (bool)(x) ) );
294-
return mNoDataBitmap[byte] & mask;
295-
}
296-
297-
bool QgsRasterBlock::isNoData( int row, int column )
298-
{
299-
return isNoData( static_cast< qgssize >( row ) * mWidth + column );
300-
}
301-
302-
bool QgsRasterBlock::setValue( qgssize index, double value )
303-
{
304-
if ( !mData )
305-
{
306-
QgsDebugMsg( "Data block not allocated" );
307-
return false;
308-
}
309-
if ( index >= static_cast< qgssize >( mWidth ) *mHeight )
310-
{
311-
QgsDebugMsg( QString( "Index %1 out of range (%2 x %3)" ).arg( index ).arg( mWidth ).arg( mHeight ) );
312-
return false;
313-
}
314-
writeValue( mData, mDataType, index, value );
315-
return true;
316-
}
317-
318-
bool QgsRasterBlock::setValue( int row, int column, double value )
319-
{
320-
return setValue( static_cast< qgssize >( row ) * mWidth + column, value );
321-
}
322-
323-
bool QgsRasterBlock::setColor( int row, int column, QRgb color )
324-
{
325-
return setColor( static_cast< qgssize >( row ) * mWidth + column, color );
326-
}
327-
328-
bool QgsRasterBlock::setColor( qgssize index, QRgb color )
329-
{
330-
if ( !mImage )
331-
{
332-
QgsDebugMsg( "Image not allocated" );
333-
return false;
334-
}
335-
336-
if ( index >= static_cast< qgssize >( mImage->width() ) * mImage->height() )
337-
{
338-
QgsDebugMsg( QString( "index %1 out of range" ).arg( index ) );
339-
return false;
340-
}
341-
342-
// setPixel() is slow, see Qt doc -> use direct access
343-
QRgb *bits = reinterpret_cast< QRgb * >( mImage->bits() );
344-
bits[index] = color;
345-
return true;
346-
}
347-
348-
bool QgsRasterBlock::setIsNoData( int row, int column )
349-
{
350-
return setIsNoData( static_cast< qgssize >( row ) * mWidth + column );
351-
}
352-
353-
bool QgsRasterBlock::setIsNoData( qgssize index )
354-
{
355-
if ( mHasNoDataValue )
356-
{
357-
return setValue( index, mNoDataValue );
358-
}
359-
else
360-
{
361-
if ( !mNoDataBitmap )
362-
{
363-
if ( !createNoDataBitmap() )
364-
{
365-
return false;
366-
}
367-
}
368-
// TODO: optimize
369-
int row = static_cast< int >( index ) / mWidth;
370-
int column = index % mWidth;
371-
qgssize byte = static_cast< qgssize >( row ) * mNoDataBitmapWidth + column / 8;
372-
int bit = column % 8;
373-
int nodata = 0x80 >> bit;
374-
//QgsDebugMsg ( QString("set byte = %1 bit = %2 no data by %3").arg(byte).arg(bit).arg(nodata, 0,2 ) );
375-
mNoDataBitmap[byte] = mNoDataBitmap[byte] | nodata;
376-
return true;
377-
}
378-
}
379-
380234
bool QgsRasterBlock::setIsNoData()
381235
{
382236
QgsDebugMsgLevel( "Entered", 4 );
@@ -589,33 +443,6 @@ bool QgsRasterBlock::setIsNoDataExcept( QRect exceptRect )
589443
}
590444
}
591445

592-
void QgsRasterBlock::setIsData( int row, int column )
593-
{
594-
setIsData( static_cast< qgssize >( row )*mWidth + column );
595-
}
596-
597-
void QgsRasterBlock::setIsData( qgssize index )
598-
{
599-
if ( mHasNoDataValue )
600-
{
601-
//no data value set, so mNoDataBitmap is not being used
602-
return;
603-
}
604-
605-
if ( !mNoDataBitmap )
606-
{
607-
return;
608-
}
609-
610-
// TODO: optimize
611-
int row = static_cast< int >( index ) / mWidth;
612-
int column = index % mWidth;
613-
qgssize byte = static_cast< qgssize >( row ) * mNoDataBitmapWidth + column / 8;
614-
int bit = column % 8;
615-
int nodata = 0x80 >> bit;
616-
mNoDataBitmap[byte] = mNoDataBitmap[byte] & ~nodata;
617-
}
618-
619446
QByteArray QgsRasterBlock::data() const
620447
{
621448
if ( mData )

0 commit comments

Comments
 (0)