Skip to content

Commit

Permalink
introduced qgssize in rasters instead of size_t to typedef it easily …
Browse files Browse the repository at this point in the history
…in SIP
  • Loading branch information
blazek committed Nov 2, 2013
1 parent 84323d6 commit 47b055f
Show file tree
Hide file tree
Showing 18 changed files with 91 additions and 80 deletions.
3 changes: 3 additions & 0 deletions python/core/qgis.sip
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,6 @@ const double DEFAULT_LINE_WIDTH;
/** default snapping tolerance for segments (@note added in 1.8) */
const double DEFAULT_SEGMENT_EPSILON;

/** KEEP IN SYNC WITH qgssize defined in qgis.h! */
typedef unsigned long long qgssize;

2 changes: 1 addition & 1 deletion python/core/raster/qgsrasterbandstats.sip
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class QgsRasterBandStats

/** \brief The number of not no data cells in the band. */
// TODO: check if no data are excluded in stats calculation
size_t elementCount;
qgssize elementCount;

/** \brief The maximum cell value in the raster band. NO_DATA values
* are ignored. This does not use the gdal GetMaximmum function. */
Expand Down
14 changes: 7 additions & 7 deletions python/core/raster/qgsrasterblock.sip
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class QgsRasterBlock
* returned value is undefined.
* @param index data matrix index
* @return value */
double value( size_t index ) const;
double value( qgssize index ) const;

/** \brief Read a single color
* @param row row index
Expand All @@ -98,7 +98,7 @@ class QgsRasterBlock
/** \brief Read a single value
* @param index data matrix index
* @return color */
QRgb color( size_t index ) const;
QRgb color( qgssize index ) const;

/** \brief Check if value at position is no data
* @param row row index
Expand All @@ -109,7 +109,7 @@ class QgsRasterBlock
/** \brief Check if value at position is no data
* @param index data matrix index
* @return true if value is no data */
bool isNoData( size_t index );
bool isNoData( qgssize index );

/** \brief Set value on position
* @param row row index
Expand All @@ -122,7 +122,7 @@ class QgsRasterBlock
* @param index data matrix index
* @param value the value to be set
* @return true on success */
bool setValue( size_t index, double value );
bool setValue( qgssize index, double value );

/** \brief Set color on position
* @param row row index
Expand All @@ -135,7 +135,7 @@ class QgsRasterBlock
* @param index data matrix index
* @param color the color to be set, QRgb value
* @return true on success */
bool setColor( size_t index, QRgb color );
bool setColor( qgssize index, QRgb color );

/** \brief Set no data on pixel
* @param row row index
Expand All @@ -146,7 +146,7 @@ class QgsRasterBlock
/** \brief Set no data on pixel
* @param index data matrix index
* @return true on success */
bool setIsNoData( size_t index );
bool setIsNoData( qgssize index );

/** \brief Set the whole block to no data
* @return true on success */
Expand All @@ -169,7 +169,7 @@ class QgsRasterBlock
* @return pointer to data
* @note not available in python bindings
*/
// char * bits( size_t index );
// char * bits( qgssize index );

/** \brief Get pointer to data
* @return pointer to data
Expand Down
8 changes: 8 additions & 0 deletions src/core/qgis.h
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,14 @@ const double DEFAULT_SEGMENT_EPSILON = 1e-8;

typedef QMap<QString, QString> QgsStringMap;

/** qgssize is used instead of size_t, because size_t is stdlib type, unknown
* by SIP, and it would be hard to define size_t correctly in SIP.
* Currently used "unsigned long long" was introduced in C++11 (2011)
* but it was supported already before C++11 on common platforms.
* "unsigned long long int" gives syntax error in SIP.
* KEEP IN SYNC WITH qgssize defined in SIP! */
typedef unsigned long long qgssize;

// FIXME: also in qgisinterface.h
#ifndef QGISEXTERN
#ifdef WIN32
Expand Down
2 changes: 1 addition & 1 deletion src/core/raster/qgsbrightnesscontrastfilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ QgsRasterBlock * QgsBrightnessContrastFilter::block( int bandNo, QgsRectangle c
int r, g, b, alpha;
double f = qPow(( mContrast + 100 ) / 100.0, 2 );

for ( size_t i = 0; i < ( size_t )width*height; i++ )
for ( qgssize i = 0; i < ( qgssize )width*height; i++ )
{
if ( inputBlock->color( i ) == myNoDataColor )
{
Expand Down
2 changes: 1 addition & 1 deletion src/core/raster/qgshuesaturationfilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ QgsRasterBlock * QgsHueSaturationFilter::block( int bandNo, QgsRectangle const
int r, g, b, alpha;
double alphaFactor = 1.0;

for ( size_t i = 0; i < ( size_t )width*height; i++ )
for ( qgssize i = 0; i < ( qgssize )width*height; i++ )
{
if ( inputBlock->color( i ) == myNoDataColor )
{
Expand Down
2 changes: 1 addition & 1 deletion src/core/raster/qgsmultibandcolorrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ QgsRasterBlock* QgsMultiBandColorRenderer::block( int bandNo, QgsRectangle cons

QRgb myDefaultColor = NODATA_COLOR;

for ( size_t i = 0; i < ( size_t )width*height; i++ )
for ( qgssize i = 0; i < ( qgssize )width*height; i++ )
{
if ( fastDraw ) //fast rendering if no transparency, stretching, color inversion, etc.
{
Expand Down
4 changes: 2 additions & 2 deletions src/core/raster/qgspalettedrasterrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ QgsRasterBlock * QgsPalettedRasterRenderer::block( int bandNo, QgsRectangle con
//because of performance
unsigned int* outputData = ( unsigned int* )( outputBlock->bits() );

size_t rasterSize = ( size_t )width * height;
for ( size_t i = 0; i < rasterSize; ++i )
qgssize rasterSize = ( qgssize )width * height;
for ( qgssize i = 0; i < rasterSize; ++i )
{
if ( inputBlock->isNoData( i ) )
{
Expand Down
2 changes: 1 addition & 1 deletion src/core/raster/qgsrasterbandstats.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class CORE_EXPORT QgsRasterBandStats

/** \brief The number of not no data cells in the band. */
// TODO: check if no data are excluded in stats calculation
size_t elementCount;
qgssize elementCount;

/** \brief The maximum cell value in the raster band. NO_DATA values
* are ignored. This does not use the gdal GetMaximmum function. */
Expand Down
64 changes: 32 additions & 32 deletions src/core/raster/qgsrasterblock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ bool QgsRasterBlock::reset( QGis::DataType theDataType, int theWidth, int theHei
if ( typeIsNumeric( theDataType ) )
{
QgsDebugMsg( "Numeric type" );
size_t tSize = typeSize( theDataType );
qgssize tSize = typeSize( theDataType );
QgsDebugMsg( QString( "allocate %1 bytes" ).arg( tSize * theWidth * theHeight ) );
mData = qgsMalloc( tSize * theWidth * theHeight );
if ( mData == 0 )
Expand Down Expand Up @@ -287,10 +287,10 @@ bool QgsRasterBlock::isNoDataValue( double value, double noDataValue )

double QgsRasterBlock::value( int row, int column ) const
{
return value(( size_t )row*mWidth + column );
return value(( qgssize )row*mWidth + column );
}

QRgb QgsRasterBlock::color( size_t index ) const
QRgb QgsRasterBlock::color( qgssize index ) const
{
int row = floor(( double )index / mWidth );
int column = index % mWidth;
Expand All @@ -304,10 +304,10 @@ QRgb QgsRasterBlock::color( int row, int column ) const
return mImage->pixel( column, row );
}

bool QgsRasterBlock::isNoData( size_t index )
bool QgsRasterBlock::isNoData( qgssize index )
{
if ( !mHasNoDataValue && !mNoDataBitmap ) return false;
if ( index >= ( size_t )mWidth*mHeight )
if ( index >= ( qgssize )mWidth*mHeight )
{
QgsDebugMsg( QString( "Index %1 out of range (%2 x %3)" ).arg( index ).arg( mWidth ).arg( mHeight ) );
return true; // we consider no data if outside
Expand All @@ -326,7 +326,7 @@ bool QgsRasterBlock::isNoData( size_t index )
// TODO: optimize
int row = ( int ) index / mWidth;
int column = index % mWidth;
size_t byte = ( size_t )row * mNoDataBitmapWidth + column / 8 ;
qgssize byte = ( qgssize )row * mNoDataBitmapWidth + column / 8 ;
int bit = column % 8;
int mask = 0x80 >> bit;
//int x = mNoDataBitmap[byte] & mask;
Expand All @@ -336,17 +336,17 @@ bool QgsRasterBlock::isNoData( size_t index )

bool QgsRasterBlock::isNoData( int row, int column )
{
return isNoData(( size_t )row*mWidth + column );
return isNoData(( qgssize )row*mWidth + column );
}

bool QgsRasterBlock::setValue( size_t index, double value )
bool QgsRasterBlock::setValue( qgssize index, double value )
{
if ( !mData )
{
QgsDebugMsg( "Data block not allocated" );
return false;
}
if ( index >= ( size_t )mWidth*mHeight )
if ( index >= ( qgssize )mWidth*mHeight )
{
QgsDebugMsg( QString( "Index %1 out of range (%2 x %3)" ).arg( index ).arg( mWidth ).arg( mHeight ) );
return false;
Expand All @@ -357,23 +357,23 @@ bool QgsRasterBlock::setValue( size_t index, double value )

bool QgsRasterBlock::setValue( int row, int column, double value )
{
return setValue(( size_t )row*mWidth + column, value );
return setValue(( qgssize )row*mWidth + column, value );
}

bool QgsRasterBlock::setColor( int row, int column, QRgb color )
{
return setColor(( size_t )row*mWidth + column, color );
return setColor(( qgssize )row*mWidth + column, color );
}

bool QgsRasterBlock::setColor( size_t index, QRgb color )
bool QgsRasterBlock::setColor( qgssize index, QRgb color )
{
if ( !mImage )
{
QgsDebugMsg( "Image not allocated" );
return false;
}

if ( index >= ( size_t )mImage->width()* mImage->height() )
if ( index >= ( qgssize )mImage->width()* mImage->height() )
{
QgsDebugMsg( QString( "index %1 out of range" ).arg( index ) );
return false;
Expand All @@ -387,10 +387,10 @@ bool QgsRasterBlock::setColor( size_t index, QRgb color )

bool QgsRasterBlock::setIsNoData( int row, int column )
{
return setIsNoData(( size_t )row*mWidth + column );
return setIsNoData(( qgssize )row*mWidth + column );
}

bool QgsRasterBlock::setIsNoData( size_t index )
bool QgsRasterBlock::setIsNoData( qgssize index )
{
if ( mHasNoDataValue )
{
Expand All @@ -408,7 +408,7 @@ bool QgsRasterBlock::setIsNoData( size_t index )
// TODO: optimize
int row = ( int ) index / mWidth;
int column = index % mWidth;
size_t byte = ( size_t )row * mNoDataBitmapWidth + column / 8;
qgssize byte = ( qgssize )row * mNoDataBitmapWidth + column / 8;
int bit = column % 8;
int nodata = 0x80 >> bit;
//QgsDebugMsg ( QString("set byte = %1 bit = %2 no data by %3").arg(byte).arg(bit).arg(nodata, 0,2 ) );
Expand All @@ -435,7 +435,7 @@ bool QgsRasterBlock::setIsNoData()
QByteArray noDataByteArray = valueBytes( mDataType, mNoDataValue );

char *nodata = noDataByteArray.data();
for ( size_t i = 0; i < ( size_t )mWidth*mHeight; i++ )
for ( qgssize i = 0; i < ( qgssize )mWidth*mHeight; i++ )
{
memcpy(( char* )mData + i*dataTypeSize, nodata, dataTypeSize );
}
Expand Down Expand Up @@ -506,13 +506,13 @@ bool QgsRasterBlock::setIsNoDataExcept( const QRect & theExceptRect )
for ( int r = 0; r < mHeight; r++ )
{
if ( r >= top && r <= bottom ) continue; // middle
size_t i = ( size_t )r * mWidth;
qgssize i = ( qgssize )r * mWidth;
memcpy(( char* )mData + i*dataTypeSize, nodataRow, dataTypeSize*mWidth );
}
// middle
for ( int r = top; r <= bottom; r++ )
{
size_t i = ( size_t )r * mWidth;
qgssize i = ( qgssize )r * mWidth;
// middle left
memcpy(( char* )mData + i*dataTypeSize, nodataRow, dataTypeSize*left );
// middle right
Expand Down Expand Up @@ -549,7 +549,7 @@ bool QgsRasterBlock::setIsNoDataExcept( const QRect & theExceptRect )
for ( int r = 0; r < mHeight; r++ )
{
if ( r >= top && r <= bottom ) continue; // middle
size_t i = ( size_t )r * mNoDataBitmapWidth;
qgssize i = ( qgssize )r * mNoDataBitmapWidth;
memcpy( mNoDataBitmap + i, nodataRow, mNoDataBitmapWidth );
}
// middle
Expand All @@ -564,7 +564,7 @@ bool QgsRasterBlock::setIsNoDataExcept( const QRect & theExceptRect )
}
for ( int r = top; r <= bottom; r++ )
{
size_t i = ( size_t )r * mNoDataBitmapWidth;
qgssize i = ( qgssize )r * mNoDataBitmapWidth;
memcpy( mNoDataBitmap + i, nodataRow, mNoDataBitmapWidth );
}
delete [] nodataRow;
Expand Down Expand Up @@ -607,13 +607,13 @@ bool QgsRasterBlock::setIsNoDataExcept( const QRect & theExceptRect )
for ( int r = 0; r < mHeight; r++ )
{
if ( r >= top && r <= bottom ) continue; // middle
size_t i = ( size_t )r * mWidth;
qgssize i = ( qgssize )r * mWidth;
memcpy(( void * )( mImage->bits() + rgbSize*i ), nodataRow, rgbSize*mWidth );
}
// middle
for ( int r = top; r <= bottom; r++ )
{
size_t i = ( size_t )r * mWidth;
qgssize i = ( qgssize )r * mWidth;
// middle left
if ( left > 0 )
{
Expand All @@ -629,10 +629,10 @@ bool QgsRasterBlock::setIsNoDataExcept( const QRect & theExceptRect )
}
}

char * QgsRasterBlock::bits( size_t index )
char * QgsRasterBlock::bits( qgssize index )
{
// Not testing type to avoid too much overhead because this method is called per pixel
if ( index >= ( size_t )mWidth*mHeight )
if ( index >= ( qgssize )mWidth*mHeight )
{
QgsDebugMsg( QString( "Index %1 out of range (%2 x %3)" ).arg( index ).arg( mWidth ).arg( mHeight ) );
return 0;
Expand All @@ -651,7 +651,7 @@ char * QgsRasterBlock::bits( size_t index )

char * QgsRasterBlock::bits( int row, int column )
{
return bits(( size_t )row*mWidth + column );
return bits(( qgssize )row*mWidth + column );
}

char * QgsRasterBlock::bits()
Expand Down Expand Up @@ -710,8 +710,8 @@ void QgsRasterBlock::applyNoDataValues( const QgsRasterRangeList & rangeList )
return;
}

size_t size = mWidth * mHeight;
for ( size_t i = 0; i < size; ++i )
qgssize size = mWidth * mHeight;
for ( qgssize i = 0; i < size; ++i )
{
double val = value( i );
if ( QgsRasterRange::contains( val, rangeList ) )
Expand Down Expand Up @@ -785,11 +785,11 @@ QString QgsRasterBlock::printValue( double value )
return s;
}

void * QgsRasterBlock::convert( void *srcData, QGis::DataType srcDataType, QGis::DataType destDataType, size_t size )
void * QgsRasterBlock::convert( void *srcData, QGis::DataType srcDataType, QGis::DataType destDataType, qgssize size )
{
int destDataTypeSize = typeSize( destDataType );
void *destData = qgsMalloc( destDataTypeSize * size );
for ( size_t i = 0; i < size; i++ )
for ( qgssize i = 0; i < size; i++ )
{
double value = readValue( srcData, srcDataType, i );
writeValue( destData, destDataType, i, value );
Expand All @@ -801,7 +801,7 @@ void * QgsRasterBlock::convert( void *srcData, QGis::DataType srcDataType, QGis:

QByteArray QgsRasterBlock::valueBytes( QGis::DataType theDataType, double theValue )
{
size_t size = QgsRasterBlock::typeSize( theDataType );
qgssize size = QgsRasterBlock::typeSize( theDataType );
QByteArray ba;
ba.resize(( int )size );
char * data = ba.data();
Expand Down Expand Up @@ -851,7 +851,7 @@ QByteArray QgsRasterBlock::valueBytes( QGis::DataType theDataType, double theVal
bool QgsRasterBlock::createNoDataBitmap()
{
mNoDataBitmapWidth = mWidth / 8 + 1;
mNoDataBitmapSize = ( size_t )mNoDataBitmapWidth * mHeight;
mNoDataBitmapSize = ( qgssize )mNoDataBitmapWidth * mHeight;
QgsDebugMsg( QString( "allocate %1 bytes" ).arg( mNoDataBitmapSize ) );
mNoDataBitmap = ( char* )qgsMalloc( mNoDataBitmapSize );
if ( mNoDataBitmap == 0 )
Expand Down
Loading

0 comments on commit 47b055f

Please sign in to comment.