Skip to content
Permalink
Browse files

More clang warning fixes

  • Loading branch information
nyalldawson committed Jan 6, 2016
1 parent 6051d3a commit 03ec7ed3eca13dc1a1b195753efb2e9a2f5881e5
@@ -20,7 +20,7 @@ originally part of the larger QgsRasterLayer class
#define DOUBLE_DIFF_THRESHOLD 0.0000001

#include "qgslogger.h"

#include "qgis.h"
#include "qgscolorrampshader.h"

#include <cmath>
@@ -108,7 +108,7 @@ bool QgsColorRampShader::exactColor( double theValue, int* theReturnRedValue, in
//Start searching from the last index - assumtion is that neighboring pixels tend to be similar values
myColorRampItem = mColorRampItemList.value( mCurrentColorRampItemIndex );
myTinyDiff = qAbs( theValue - myColorRampItem.value );
if ( theValue == myColorRampItem.value || myTinyDiff <= DOUBLE_DIFF_THRESHOLD )
if ( qgsDoubleNear( theValue, myColorRampItem.value ) || myTinyDiff <= DOUBLE_DIFF_THRESHOLD )
{
*theReturnRedValue = myColorRampItem.color.red();
*theReturnGreenValue = myColorRampItem.color.green();
@@ -173,10 +173,10 @@ bool QgsColorRampShader::interpolatedColor( double theValue, int*
myOffsetInRange = theValue - myPreviousColorRampItem.value;
double scale = myOffsetInRange / myCurrentRampRange;

*theReturnRedValue = ( int )(( double ) myPreviousColorRampItem.color.red() + (( double )( myColorRampItem.color.red() - myPreviousColorRampItem.color.red() ) * scale ) );
*theReturnGreenValue = ( int )(( double ) myPreviousColorRampItem.color.green() + (( double )( myColorRampItem.color.green() - myPreviousColorRampItem.color.green() ) * scale ) );
*theReturnBlueValue = ( int )(( double ) myPreviousColorRampItem.color.blue() + (( double )( myColorRampItem.color.blue() - myPreviousColorRampItem.color.blue() ) * scale ) );
*theReturnAlphaValue = ( int )(( double ) myPreviousColorRampItem.color.alpha() + (( double )( myColorRampItem.color.alpha() - myPreviousColorRampItem.color.alpha() ) * scale ) );
*theReturnRedValue = static_cast< int >( static_cast< double >( myPreviousColorRampItem.color.red() ) + ( static_cast< double >( myColorRampItem.color.red() - myPreviousColorRampItem.color.red() ) * scale ) );
*theReturnGreenValue = static_cast< int >( static_cast< double >( myPreviousColorRampItem.color.green() ) + ( static_cast< double >( myColorRampItem.color.green() - myPreviousColorRampItem.color.green() ) * scale ) );
*theReturnBlueValue = static_cast< int >( static_cast< double >( myPreviousColorRampItem.color.blue() ) + ( static_cast< double >( myColorRampItem.color.blue() - myPreviousColorRampItem.color.blue() ) * scale ) );
*theReturnAlphaValue = static_cast< int >( static_cast< double >( myPreviousColorRampItem.color.alpha() ) + ( static_cast< double >( myColorRampItem.color.alpha() - myPreviousColorRampItem.color.alpha() ) * scale ) );
if ( mMaximumColorCacheSize >= mColorCache.size() )
{
QColor myNewColor( *theReturnRedValue, *theReturnGreenValue, *theReturnBlueValue, *theReturnAlphaValue );
@@ -217,7 +217,7 @@ bool QgsContrastEnhancement::generateLookupTable()

for ( int myIterator = 0; myIterator <= mRasterDataTypeRange; myIterator++ )
{
mLookupTable[myIterator] = mContrastEnhancementFunction->enhance(( double )myIterator - mLookupTableOffset );
mLookupTable[myIterator] = mContrastEnhancementFunction->enhance( static_cast< double >( myIterator ) - mLookupTableOffset );
}

return true;
@@ -247,7 +247,7 @@ bool QgsContrastEnhancement::isValueInDisplayableRange( double theValue )
*/
void QgsContrastEnhancement::setContrastEnhancementAlgorithm( ContrastEnhancementAlgorithm theAlgorithm, bool generateTable )
{
QgsDebugMsg( "called algorithm: " + QString::number(( int )theAlgorithm ) + " generate lookup table: " + QString::number(( int )generateTable ) );
QgsDebugMsg( "called algorithm: " + QString::number( static_cast< int >( theAlgorithm ) ) + " generate lookup table: " + QString::number( static_cast< int >( generateTable ) ) );

if ( theAlgorithm != mContrastEnhancementAlgorithm )
{
@@ -310,7 +310,7 @@ void QgsContrastEnhancement::setContrastEnhancementFunction( QgsContrastEnhancem
*/
void QgsContrastEnhancement::setMaximumValue( double theValue, bool generateTable )
{
QgsDebugMsg( "called value: " + QString::number( theValue ) + " generate lookup table: " + QString::number(( int )generateTable ) );
QgsDebugMsg( "called value: " + QString::number( theValue ) + " generate lookup table: " + QString::number( static_cast< int >( generateTable ) ) );

if ( theValue > maximumValuePossible( mRasterDataType ) )
{
@@ -342,7 +342,7 @@ void QgsContrastEnhancement::setMaximumValue( double theValue, bool generateTabl
*/
void QgsContrastEnhancement::setMinimumValue( double theValue, bool generateTable )
{
QgsDebugMsg( "called value: " + QString::number( theValue ) + " generate lookup table: " + QString::number(( int )generateTable ) );
QgsDebugMsg( "called value: " + QString::number( theValue ) + " generate lookup table: " + QString::number( static_cast< int >( generateTable ) ) );

if ( theValue < minimumValuePossible( mRasterDataType ) )
{
@@ -45,15 +45,15 @@ bool QgsRasterChecker::runTest( const QString& theVerifiedKey, QString theVerifi
mReport += "\n\n";

//QgsRasterDataProvider* verifiedProvider = QgsRasterLayer::loadProvider( theVerifiedKey, theVerifiedUri );
QgsRasterDataProvider* verifiedProvider = ( QgsRasterDataProvider* ) QgsProviderRegistry::instance()->provider( theVerifiedKey, theVerifiedUri );
QgsRasterDataProvider* verifiedProvider = dynamic_cast< QgsRasterDataProvider* >( QgsProviderRegistry::instance()->provider( theVerifiedKey, theVerifiedUri ) );
if ( !verifiedProvider || !verifiedProvider->isValid() )
{
error( QString( "Cannot load provider %1 with URI: %2" ).arg( theVerifiedKey, theVerifiedUri ), mReport );
ok = false;
}

//QgsRasterDataProvider* expectedProvider = QgsRasterLayer::loadProvider( theExpectedKey, theExpectedUri );
QgsRasterDataProvider* expectedProvider = ( QgsRasterDataProvider* ) QgsProviderRegistry::instance()->provider( theExpectedKey, theExpectedUri );
QgsRasterDataProvider* expectedProvider = dynamic_cast< QgsRasterDataProvider* >( QgsProviderRegistry::instance()->provider( theExpectedKey, theExpectedUri ) );
if ( !expectedProvider || !expectedProvider->isValid() )
{
error( QString( "Cannot load provider %1 with URI: %2" ).arg( theExpectedKey, theExpectedUri ), mReport );
@@ -181,8 +181,8 @@ QgsRasterBlock * QgsRasterDataProvider::block( int theBandNo, QgsRectangle cons
return block;
}

qgssize tmpIndex = ( qgssize )tmpRow * ( qgssize )tmpWidth + tmpCol;
qgssize index = row * ( qgssize )theWidth + col;
qgssize tmpIndex = static_cast< qgssize >( tmpRow ) * static_cast< qgssize >( tmpWidth ) + tmpCol;
qgssize index = row * static_cast< qgssize >( theWidth ) + col;

char *tmpBits = tmpBlock->bits( tmpIndex );
char *bits = block->bits( index );
@@ -313,8 +313,8 @@ QgsRasterIdentifyResult QgsRasterDataProvider::identify( const QgsPoint & thePoi
double xres = ( myExtent.width() ) / theWidth;
double yres = ( myExtent.height() ) / theHeight;

int col = ( int ) floor(( thePoint.x() - myExtent.xMinimum() ) / xres );
int row = ( int ) floor(( myExtent.yMaximum() - thePoint.y() ) / yres );
int col = static_cast< int >( floor(( thePoint.x() - myExtent.xMinimum() ) / xres ) );
int row = static_cast< int >( floor(( myExtent.yMaximum() - thePoint.y() ) / yres ) );

double xMin = myExtent.xMinimum() + col * xres;
double xMax = xMin + xres;
@@ -349,7 +349,7 @@ QString QgsRasterDataProvider::lastErrorFormat()
typedef QList<QPair<QString, QString> > *pyramidResamplingMethods_t();
QList<QPair<QString, QString> > QgsRasterDataProvider::pyramidResamplingMethods( const QString& providerKey )
{
pyramidResamplingMethods_t *pPyramidResamplingMethods = ( pyramidResamplingMethods_t * ) cast_to_fptr( QgsProviderRegistry::instance()->function( providerKey, "pyramidResamplingMethods" ) );
pyramidResamplingMethods_t *pPyramidResamplingMethods = reinterpret_cast< pyramidResamplingMethods_t * >( cast_to_fptr( QgsProviderRegistry::instance()->function( providerKey, "pyramidResamplingMethods" ) ) );
if ( pPyramidResamplingMethods )
{
QList<QPair<QString, QString> > *methods = pPyramidResamplingMethods();
@@ -435,7 +435,7 @@ QgsRasterDataProvider* QgsRasterDataProvider::create( const QString &providerKey
const QgsCoordinateReferenceSystem& crs,
const QStringList& createOptions )
{
createFunction_t *createFn = ( createFunction_t* ) cast_to_fptr( QgsProviderRegistry::instance()->function( providerKey, "create" ) );
createFunction_t *createFn = reinterpret_cast< createFunction_t* >( cast_to_fptr( QgsProviderRegistry::instance()->function( providerKey, "create" ) ) );
if ( !createFn )
{
QgsDebugMsg( "Cannot resolve 'create' function in " + providerKey + " provider" );
@@ -220,8 +220,8 @@ QgsRasterFileWriter::WriterError QgsRasterFileWriter::writeDataRaster( const Qgs
QgsRasterBandStats stats = srcProvider->bandStatistics( bandNo, QgsRasterBandStats::Min | QgsRasterBandStats::Max, srcExtent, 250000 );

// Test if we have free (not used) values
double typeMinValue = QgsContrastEnhancement::maximumValuePossible(( QGis::DataType )srcProvider->srcDataType( bandNo ) );
double typeMaxValue = QgsContrastEnhancement::maximumValuePossible(( QGis::DataType )srcProvider->srcDataType( bandNo ) );
double typeMinValue = QgsContrastEnhancement::maximumValuePossible( static_cast< QGis::DataType >( srcProvider->srcDataType( bandNo ) ) );
double typeMaxValue = QgsContrastEnhancement::maximumValuePossible( static_cast< QGis::DataType >( srcProvider->srcDataType( bandNo ) ) );
if ( stats.minimumValue > typeMinValue )
{
destNoDataValue = typeMinValue;
@@ -530,7 +530,7 @@ QgsRasterFileWriter::WriterError QgsRasterFileWriter::writeImageRaster( QgsRaste
}

//fill into red/green/blue/alpha channels
qgssize nPixels = ( qgssize )iterCols * iterRows;
qgssize nPixels = static_cast< qgssize >( iterCols ) * iterRows;
// TODO: should be char not int? we are then copying 1 byte
int red = 0;
int green = 0;
@@ -547,15 +547,15 @@ QgsRasterFileWriter::WriterError QgsRasterFileWriter::writeImageRaster( QgsRaste
if ( inputDataType == QGis::ARGB32_Premultiplied )
{
double a = alpha / 255.;
QgsDebugMsgLevel( QString( "red = %1 green = %2 blue = %3 alpha = %4 p = %5 a = %6" ).arg( red ).arg( green ).arg( blue ).arg( alpha ).arg(( int )c, 0, 16 ).arg( a ), 5 );
QgsDebugMsgLevel( QString( "red = %1 green = %2 blue = %3 alpha = %4 p = %5 a = %6" ).arg( red ).arg( green ).arg( blue ).arg( alpha ).arg( static_cast< int >( c ), 0, 16 ).arg( a ), 5 );
red /= a;
green /= a;
blue /= a;
}
memcpy(( char* )redData + i, &red, 1 );
memcpy(( char* )greenData + i, &green, 1 );
memcpy(( char* )blueData + i, &blue, 1 );
memcpy(( char* )alphaData + i, &alpha, 1 );
memcpy( reinterpret_cast< char* >( redData ) + i, &red, 1 );
memcpy( reinterpret_cast< char* >( greenData ) + i, &green, 1 );
memcpy( reinterpret_cast< char* >( blueData ) + i, &blue, 1 );
memcpy( reinterpret_cast< char* >( alphaData ) + i, &alpha, 1 );
}
delete inputBlock;

@@ -710,7 +710,7 @@ void QgsRasterFileWriter::buildPyramids( const QString& filename )
{
QgsDebugMsg( "filename = " + filename );
// open new dataProvider so we can build pyramids with it
QgsRasterDataProvider* destProvider = ( QgsRasterDataProvider* ) QgsProviderRegistry::instance()->provider( mOutputProviderKey, filename );
QgsRasterDataProvider* destProvider = dynamic_cast< QgsRasterDataProvider* >( QgsProviderRegistry::instance()->provider( mOutputProviderKey, filename ) );
if ( !destProvider )
{
return;
@@ -948,7 +948,7 @@ void QgsRasterFileWriter::globalOutputParameters( const QgsRectangle& extent, in
//calculate nRows automatically for providers without exact resolution
if ( nRows < 0 )
{
nRows = ( double )nCols / extent.width() * extent.height() + 0.5;
nRows = static_cast< double >( nCols ) / extent.width() * extent.height() + 0.5;
}
geoTransform[0] = extent.xMinimum();
geoTransform[1] = pixelSize;
@@ -186,7 +186,7 @@ QgsRasterBandStats QgsRasterInterface::bandStatistics( int theBandNo,
QgsRasterBlock* blk = block( theBandNo, myPartExtent, myBlockWidth, myBlockHeight );

// Collect the histogram counts.
for ( qgssize i = 0; i < (( qgssize ) myBlockHeight ) * myBlockWidth; i++ )
for ( qgssize i = 0; i < ( static_cast< qgssize >( myBlockHeight ) ) * myBlockWidth; i++ )
{
if ( blk->isNoData( i ) ) continue; // NULL

@@ -468,7 +468,7 @@ QgsRasterHistogram QgsRasterInterface::histogram( int theBandNo,
QgsRasterBlock* blk = block( theBandNo, myPartExtent, myBlockWidth, myBlockHeight );

// Collect the histogram counts.
for ( qgssize i = 0; i < (( qgssize ) myBlockHeight ) * myBlockWidth; i++ )
for ( qgssize i = 0; i < ( static_cast< qgssize >( myBlockHeight ) ) * myBlockWidth; i++ )
{
if ( blk->isNoData( i ) )
{
@@ -533,8 +533,8 @@ void QgsRasterInterface::cumulativeCut( int theBandNo,

double myBinXStep = ( myHistogram.maximum - myHistogram.minimum ) / myHistogram.binCount;
int myCount = 0;
int myMinCount = ( int ) qRound( theLowerCount * myHistogram.nonNullCount );
int myMaxCount = ( int ) qRound( theUpperCount * myHistogram.nonNullCount );
int myMinCount = static_cast< int >( qRound( theLowerCount * myHistogram.nonNullCount ) );
int myMaxCount = static_cast< int >( qRound( theUpperCount * myHistogram.nonNullCount ) );
bool myLowerFound = false;
QgsDebugMsg( QString( "binCount = %1 minimum = %2 maximum = %3 myBinXStep = %4" ).arg( myHistogram.binCount ).arg( myHistogram.minimum ).arg( myHistogram.maximum ).arg( myBinXStep ) );
QgsDebugMsg( QString( "myMinCount = %1 myMaxCount = %2" ).arg( myMinCount ).arg( myMaxCount ) );
@@ -87,10 +87,10 @@ bool QgsRasterIterator::readNextRasterPart( int bandNumber,

//get subrectangle
QgsRectangle viewPortExtent = mExtent;
double xmin = viewPortExtent.xMinimum() + pInfo.currentCol / ( double )pInfo.nCols * viewPortExtent.width();
double xmax = viewPortExtent.xMinimum() + ( pInfo.currentCol + nCols ) / ( double )pInfo.nCols * viewPortExtent.width();
double ymin = viewPortExtent.yMaximum() - ( pInfo.currentRow + nRows ) / ( double )pInfo.nRows * viewPortExtent.height();
double ymax = viewPortExtent.yMaximum() - pInfo.currentRow / ( double )pInfo.nRows * viewPortExtent.height();
double xmin = viewPortExtent.xMinimum() + pInfo.currentCol / static_cast< double >( pInfo.nCols ) * viewPortExtent.width();
double xmax = viewPortExtent.xMinimum() + ( pInfo.currentCol + nCols ) / static_cast< double >( pInfo.nCols ) * viewPortExtent.width();
double ymin = viewPortExtent.yMaximum() - ( pInfo.currentRow + nRows ) / static_cast< double >( pInfo.nRows ) * viewPortExtent.height();
double ymax = viewPortExtent.yMaximum() - pInfo.currentRow / static_cast< double >( pInfo.nRows ) * viewPortExtent.height();
QgsRectangle blockRect( xmin, ymin, xmax, ymax );

*block = mInput->block( bandNumber, blockRect, nCols, nRows );
@@ -169,7 +169,7 @@ QgsRasterLayer::~QgsRasterLayer()
*/
bool QgsRasterLayer::isValidRasterFileName( const QString& theFileNameQString, QString& retErrMsg )
{
isvalidrasterfilename_t *pValid = ( isvalidrasterfilename_t * ) cast_to_fptr( QgsProviderRegistry::instance()->function( "gdal", "isValidRasterFileName" ) );
isvalidrasterfilename_t *pValid = reinterpret_cast< isvalidrasterfilename_t * >( cast_to_fptr( QgsProviderRegistry::instance()->function( "gdal", "isValidRasterFileName" ) ) );
if ( ! pValid )
{
QgsDebugMsg( "Could not resolve isValidRasterFileName in gdal provider library" );
@@ -558,14 +558,14 @@ QPixmap QgsRasterLayer::paletteAsPixmap( int theBandNumber )
myQImage.fill( 0 );
myPalettePixmap.fill();

double myStep = (( double )myColorRampItemList.size() - 1 ) / ( double )( mySize * mySize );
double myStep = ( static_cast< double >( myColorRampItemList.size() ) - 1 ) / static_cast< double >( mySize * mySize );
double myValue = 0.0;
for ( int myRow = 0; myRow < mySize; myRow++ )
{
QRgb* myLineBuffer = ( QRgb* )myQImage.scanLine( myRow );
QRgb* myLineBuffer = reinterpret_cast< QRgb* >( myQImage.scanLine( myRow ) );
for ( int myCol = 0; myCol < mySize; myCol++ )
{
myValue = myStep * ( double )( myCol + myRow * mySize );
myValue = myStep * static_cast< double >( myCol + myRow * mySize );
int c1, c2, c3, c4;
myShader.shade( myValue, &c1, &c2, &c3, &c4 );
myLineBuffer[ myCol ] = qRgba( c1, c2, c3, c4 );
@@ -651,7 +651,7 @@ void QgsRasterLayer::setDataProvider( QString const & provider )

//mBandCount = 0;

mDataProvider = ( QgsRasterDataProvider* )QgsProviderRegistry::instance()->provider( mProviderKey, mDataSource );
mDataProvider = dynamic_cast< QgsRasterDataProvider* >( QgsProviderRegistry::instance()->provider( mProviderKey, mDataSource ) );
if ( !mDataProvider )
{
//QgsMessageLog::logMessage( tr( "Cannot instantiate the data provider" ), tr( "Raster" ) );
@@ -886,8 +886,8 @@ void QgsRasterLayer::setContrastEnhancement( QgsContrastEnhancement::ContrastEnh
{
if ( myBand != -1 )
{
QGis::DataType myType = ( QGis::DataType )mDataProvider->dataType( myBand );
QgsContrastEnhancement* myEnhancement = new QgsContrastEnhancement(( QGis::DataType )myType );
QGis::DataType myType = static_cast< QGis::DataType >( mDataProvider->dataType( myBand ) );
QgsContrastEnhancement* myEnhancement = new QgsContrastEnhancement( static_cast< QGis::DataType >( myType ) );
myEnhancement->setContrastEnhancementAlgorithm( theAlgorithm, theGenerateLookupTableFlag );

double myMin = std::numeric_limits<double>::quiet_NaN();
@@ -1115,7 +1115,7 @@ QPixmap QgsRasterLayer::previewAsPixmap( const QSize& size, const QColor& bgColo
double myX = 0.0;
double myY = 0.0;
QgsRectangle myExtent = mDataProvider->extent();
if ( myExtent.width() / myExtent.height() >= ( double )myQPixmap.width() / myQPixmap.height() )
if ( myExtent.width() / myExtent.height() >= static_cast< double >( myQPixmap.width() ) / myQPixmap.height() )
{
myMapUnitsPerPixel = myExtent.width() / myQPixmap.width();
myY = ( myQPixmap.height() - myExtent.height() / myMapUnitsPerPixel ) / 2;
@@ -1167,7 +1167,7 @@ QImage QgsRasterLayer::previewAsImage( const QSize& size, const QColor& bgColor,
double myX = 0.0;
double myY = 0.0;
QgsRectangle myExtent = mDataProvider->extent();
if ( myExtent.width() / myExtent.height() >= ( double )myQImage.width() / myQImage.height() )
if ( myExtent.width() / myExtent.height() >= static_cast< double >( myQImage.width() ) / myQImage.height() )
{
myMapUnitsPerPixel = myExtent.width() / myQImage.width();
myY = ( myQImage.height() - myExtent.height() / myMapUnitsPerPixel ) / 2;
@@ -1215,7 +1215,7 @@ void QgsRasterLayer::onProgress( int theType, double theProgress, const QString&
Q_UNUSED( theType );
Q_UNUSED( theMessage );
QgsDebugMsg( QString( "theProgress = %1" ).arg( theProgress ) );
emit progressUpdate(( int )theProgress );
emit progressUpdate( static_cast< int >( theProgress ) );
}

//////////////////////////////////////////////////////////
@@ -1309,7 +1309,7 @@ bool QgsRasterLayer::readSymbology( const QDomNode& layer_node, QString& errorMe
if ( !blendModeNode.isNull() )
{
QDomElement e = blendModeNode.toElement();
setBlendMode( QgsMapRenderer::getCompositionMode(( QgsMapRenderer::BlendMode ) e.text().toInt() ) );
setBlendMode( QgsMapRenderer::getCompositionMode( static_cast< QgsMapRenderer::BlendMode >( e.text().toInt() ) ) );
}

return true;

0 comments on commit 03ec7ed

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