Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/qgis/Quantum-GIS
Browse files Browse the repository at this point in the history
  • Loading branch information
volaya committed Oct 15, 2012
2 parents 4b76e69 + 4f98420 commit 5afd739
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 90 deletions.
2 changes: 2 additions & 0 deletions python/plugins/plugin_installer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ qgis-icon.png
repoConnected.png
repoDisabled.png
repoUnavailable.png
pluginExperimental.png
pluginStable.png
unzip.py
version_compare.py
)
Expand Down
162 changes: 84 additions & 78 deletions src/core/raster/qgsrasterblock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,41 +27,41 @@
#include "cpl_conv.h"

QgsRasterBlock::QgsRasterBlock()
//mValid (false)
: mDataType ( UnknownDataType )
, mTypeSize(0)
, mWidth(0)
, mHeight(0)
, mNoDataValue(std::numeric_limits<double>::quiet_NaN())
, mData(0)
, mImage(0)
//mValid (false)
: mDataType( UnknownDataType )
, mTypeSize( 0 )
, mWidth( 0 )
, mHeight( 0 )
, mNoDataValue( std::numeric_limits<double>::quiet_NaN() )
, mData( 0 )
, mImage( 0 )
{
}

QgsRasterBlock::QgsRasterBlock( DataType theDataType, int theWidth, int theHeight, double theNoDataValue )
//mValid(true)
: mDataType(theDataType)
, mTypeSize(0)
, mWidth(theWidth)
, mHeight(theHeight)
, mNoDataValue(theNoDataValue)
, mData(0)
, mImage(0)
//mValid(true)
: mDataType( theDataType )
, mTypeSize( 0 )
, mWidth( theWidth )
, mHeight( theHeight )
, mNoDataValue( theNoDataValue )
, mData( 0 )
, mImage( 0 )
{
reset ( mDataType, mWidth, mHeight, mNoDataValue );
reset( mDataType, mWidth, mHeight, mNoDataValue );
}

QgsRasterBlock::~QgsRasterBlock()
{
QgsFree(mData);
QgsFree( mData );

}

bool QgsRasterBlock::reset( 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));
QgsDebugMsg( QString( "theWidth= %1 theHeight = %2 theDataType = %3 theNoDataValue = %4" ).arg( theWidth ).arg( theHeight ).arg( theDataType ).arg( theNoDataValue ) );

QgsFree(mData);
QgsFree( mData );
mData = 0;
delete mImage;
mImage = 0;
Expand All @@ -72,9 +72,9 @@ bool QgsRasterBlock::reset( DataType theDataType, int theWidth, int theHeight, d
mNoDataValue = std::numeric_limits<double>::quiet_NaN();
//mValid = false;

if ( typeIsNumeric(theDataType) )
if ( typeIsNumeric( theDataType ) )
{
QgsDebugMsg ( "Numeric type");
QgsDebugMsg( "Numeric type" );
int tSize = typeSize( theDataType ) / 8;
mData = QgsMalloc( tSize * theWidth * theHeight );
if ( mData == 0 )
Expand All @@ -85,23 +85,23 @@ bool QgsRasterBlock::reset( DataType theDataType, int theWidth, int theHeight, d
}
else if ( typeIsColor( theDataType ) )
{
QgsDebugMsg ( "Color type");
QImage::Format format = imageFormat ( theDataType );
QgsDebugMsg( "Color type" );
QImage::Format format = imageFormat( theDataType );
mImage = new QImage( theWidth, theHeight, format );
}
else
{
QgsDebugMsg ( "Wrong data type");
QgsDebugMsg( "Wrong data type" );
return false;
}

//mValid = true;
mDataType = theDataType;
mTypeSize = QgsRasterBlock::typeSize(mDataType);
mTypeSize = QgsRasterBlock::typeSize( mDataType );
mWidth = theWidth;
mHeight = theHeight;
mNoDataValue = theNoDataValue;
QgsDebugMsg ( QString("mWidth= %1 mHeight = %2 mDataType = %3 mData = %4 mImage = %5").arg(mWidth).arg(mHeight).arg(mDataType).arg((ulong)mData).arg((ulong)mImage));
QgsDebugMsg( QString( "mWidth= %1 mHeight = %2 mDataType = %3 mData = %4 mImage = %5" ).arg( mWidth ).arg( mHeight ).arg( mDataType ).arg(( ulong )mData ).arg(( ulong )mImage ) );
return true;
}

Expand All @@ -112,15 +112,15 @@ QImage::Format QgsRasterBlock::imageFormat( QgsRasterBlock::DataType theDataType
return QImage::Format_ARGB32;
}
else if ( theDataType == QgsRasterBlock::ARGB32_Premultiplied )
{
{
return QImage::Format_ARGB32_Premultiplied;
}
return QImage::Format_Invalid;
}

QgsRasterBlock::DataType QgsRasterBlock::dataType ( QImage::Format theFormat )
QgsRasterBlock::DataType QgsRasterBlock::dataType( QImage::Format theFormat )
{
if ( theFormat == QImage::Format_ARGB32 )
if ( theFormat == QImage::Format_ARGB32 )
{
return QgsRasterBlock::ARGB32;
}
Expand All @@ -133,9 +133,9 @@ QgsRasterBlock::DataType QgsRasterBlock::dataType ( QImage::Format theFormat )

bool QgsRasterBlock::isEmpty() const
{
QgsDebugMsg ( QString("mWidth= %1 mHeight = %2 mDataType = %3 mData = %4 mImage = %5").arg(mWidth).arg(mHeight).arg(mDataType).arg((ulong)mData).arg((ulong)mImage));
if ( mWidth == 0 || mHeight == 0 ||
( typeIsNumeric(mDataType ) && mData == 0 ) ||
QgsDebugMsg( QString( "mWidth= %1 mHeight = %2 mDataType = %3 mData = %4 mImage = %5" ).arg( mWidth ).arg( mHeight ).arg( mDataType ).arg(( ulong )mData ).arg(( ulong )mImage ) );
if ( mWidth == 0 || mHeight == 0 ||
( typeIsNumeric( mDataType ) && mData == 0 ) ||
( typeIsColor( mDataType ) && mImage == 0 ) )
{
return true;
Expand Down Expand Up @@ -250,147 +250,153 @@ bool QgsRasterBlock::isNoDataValue( double value ) const
return false;
}

double QgsRasterBlock::value( size_t index) const
double QgsRasterBlock::value( size_t index ) const
{
if ( index < 0 || index >= (size_t)mWidth*mHeight )
if ( index < 0 || index >= ( size_t )mWidth*mHeight )
{
QgsDebugMsg( QString("Index %1 out of range (%2 x %3)").arg(index).arg(mWidth).arg(mHeight) );
QgsDebugMsg( QString( "Index %1 out of range (%2 x %3)" ).arg( index ).arg( mWidth ).arg( mHeight ) );
return mNoDataValue;
}
return readValue ( mData, mDataType, index );
return readValue( mData, mDataType, index );
}

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

QRgb QgsRasterBlock::color( size_t index) const
QRgb QgsRasterBlock::color( size_t index ) const
{
int row = floor ( (double)index / mWidth );
int row = floor(( double )index / mWidth );
int column = index % mWidth;
return color( row, column);
return color( row, column );
}

QRgb QgsRasterBlock::color( int row, int column) const
QRgb QgsRasterBlock::color( int row, int column ) const
{
if ( !mImage ) return qRgba( 255, 255, 255, 0 );

return mImage->pixel ( column, row );
return mImage->pixel( column, row );
}

bool QgsRasterBlock::isNoData( size_t index )
{
if ( index < 0 || index >= (size_t)mWidth*mHeight )
if ( index < 0 || index >= ( size_t )mWidth*mHeight )
{
QgsDebugMsg( QString("Index %1 out of range (%2 x %3)").arg(index).arg(mWidth).arg(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
}
double value = readValue ( mData, mDataType, index );
double value = readValue( mData, mDataType, index );
return isNoDataValue( value );
}

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

bool QgsRasterBlock::setValue( size_t index, double value )
{
if ( !mData )
if ( !mData )
{
QgsDebugMsg( "Data block not allocated" );
return false;
}
if ( index < 0 || index >= (size_t)mWidth*mHeight )
if ( index < 0 || index >= ( size_t )mWidth*mHeight )
{
QgsDebugMsg( QString("Index %1 out of range (%2 x %3)").arg(index).arg(mWidth).arg(mHeight) );
QgsDebugMsg( QString( "Index %1 out of range (%2 x %3)" ).arg( index ).arg( mWidth ).arg( mHeight ) );
return false;
}
writeValue ( mData, mDataType, index, value );
writeValue( mData, mDataType, index, value );
return true;
}

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

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

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

if ( index >= (size_t)mImage->width()* mImage->height() )
if ( index >= ( size_t )mImage->width()* mImage->height() )
{
QgsDebugMsg( QString("index %1 out of range").arg(index) );
QgsDebugMsg( QString( "index %1 out of range" ).arg( index ) );
return false;
}

// setPixel() is slow, see Qt doc -> use direct access
QRgb* bits = (QRgb*)mImage->bits();
QRgb* bits = ( QRgb* )mImage->bits();
bits[index] = color;
return true;
}

char * QgsRasterBlock::bits( size_t index )
{
if ( mData )
// Not testing type to avoid too much overhead because this method is called per pixel
if ( index < 0 || index >= ( size_t )mWidth*mHeight )
{
return (char*)mData + index * mTypeSize;
QgsDebugMsg( QString( "Index %1 out of range (%2 x %3)" ).arg( index ).arg( mWidth ).arg( mHeight ) );
return 0;
}
if ( mImage )
if ( mData )
{
return (char*) (mImage->bits() + index * 4);
return ( char* )mData + index * mTypeSize;
}
if ( mImage && mImage->bits() )
{
return ( char* )( mImage->bits() + index * 4 );
}

return 0;
}

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

bool QgsRasterBlock::convert( QgsRasterBlock::DataType destDataType )
{
if ( isEmpty() ) return false;
if ( destDataType == mDataType ) return true;

if ( typeIsNumeric(mDataType) && typeIsNumeric(destDataType) )
if ( typeIsNumeric( mDataType ) && typeIsNumeric( destDataType ) )
{
void *data = convert ( mData, mDataType, destDataType, mWidth*mHeight );
void *data = convert( mData, mDataType, destDataType, mWidth * mHeight );

if ( data == 0 )
{
QgsDebugMsg ( "Cannot convert raster block" );
QgsDebugMsg( "Cannot convert raster block" );
return false;
}
QgsFree ( mData );
QgsFree( mData );
mData = data;
}
else if ( typeIsColor(mDataType) && typeIsColor(destDataType) )
else if ( typeIsColor( mDataType ) && typeIsColor( destDataType ) )
{
// It would be probably faster to convert value by value here instead of
// creating new image, QImage (4.8) does not have any method to convert in place
QImage::Format format = imageFormat ( destDataType );
QImage image = mImage->convertToFormat ( format );
memcpy ( mImage->bits(), image.bits(), mImage->byteCount() );
QImage::Format format = imageFormat( destDataType );
QImage image = mImage->convertToFormat( format );
memcpy( mImage->bits(), image.bits(), mImage->byteCount() );
//mImage = new QImage( mWidth, mHeight, format );
}
else
{
return false;
}

return true;
}

Expand All @@ -409,11 +415,11 @@ bool QgsRasterBlock::setImage( const QImage * image )
mData = 0;
delete mImage;
mImage = 0;
mImage = new QImage ( *image );
mImage = new QImage( *image );
mWidth = mImage->width();
mHeight = mImage->height();
mDataType = dataType ( mImage->format() );
mTypeSize = QgsRasterBlock::typeSize(mDataType);
mDataType = dataType( mImage->format() );
mTypeSize = QgsRasterBlock::typeSize( mDataType );
mNoDataValue = std::numeric_limits<double>::quiet_NaN();
return true;
}
Expand Down
5 changes: 5 additions & 0 deletions src/core/raster/qgsrasterdrawer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ void QgsRasterDrawer::draw( QPainter* p, QgsRasterViewPort* viewPort, const QgsM
while ( mIterator->readNextRasterPart( bandNumber, nCols, nRows,
&block, topLeftCol, topLeftRow ) )
{
if ( !block )
{
QgsDebugMsg( "Cannot get block" );
continue;
}
//create image
//QImage img( nRasterCols, nRasterRows, QImage::Format_ARGB32_Premultiplied );

Expand Down
Loading

0 comments on commit 5afd739

Please sign in to comment.