Skip to content
Permalink
Browse files

introduced qgssize in rasters instead of size_t to typedef it easily …

…in SIP
  • Loading branch information
blazek committed Nov 2, 2013
1 parent 84323d6 commit 47b055f5a6d1d7eb4c8faa42effaf04d957af763
@@ -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;

@@ -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. */
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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 */
@@ -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
@@ -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
@@ -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 )
{
@@ -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 )
{
@@ -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.
{
@@ -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 ) )
{
@@ -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. */
@@ -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 )
@@ -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;
@@ -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
@@ -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;
@@ -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;
@@ -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;
@@ -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 )
{
@@ -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 ) );
@@ -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 );
}
@@ -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
@@ -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
@@ -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;
@@ -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 )
{
@@ -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;
@@ -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()
@@ -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 ) )
@@ -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 );
@@ -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();
@@ -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 )

0 comments on commit 47b055f

Please sign in to comment.
You can’t perform that action at this time.