mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-25 00:58:06 -05:00
Merge branch 'master' of https://github.com/qgis/Quantum-GIS
This commit is contained in:
commit
5afd739b04
@ -8,6 +8,8 @@ qgis-icon.png
|
||||
repoConnected.png
|
||||
repoDisabled.png
|
||||
repoUnavailable.png
|
||||
pluginExperimental.png
|
||||
pluginStable.png
|
||||
unzip.py
|
||||
version_compare.py
|
||||
)
|
||||
|
@ -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;
|
||||
@ -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 )
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
@ -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;
|
||||
@ -250,106 +250,112 @@ 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;
|
||||
@ -357,7 +363,7 @@ char * QgsRasterBlock::bits( size_t index )
|
||||
|
||||
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 )
|
||||
@ -365,32 +371,32 @@ 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;
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
@ -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 );
|
||||
|
||||
|
@ -722,7 +722,7 @@ QgsRasterBlock * QgsRasterProjector::block( int bandNo, QgsRectangle const & ex
|
||||
// If we zoom out too much, projector srcRows / srcCols maybe 0, which can cause problems in providers
|
||||
if ( srcRows() <= 0 || srcCols() <= 0 )
|
||||
{
|
||||
return 0;
|
||||
return outputBlock;
|
||||
}
|
||||
|
||||
//void * inputData = mInput->block( bandNo, srcExtent(), srcCols(), srcRows() );
|
||||
@ -736,11 +736,6 @@ QgsRasterBlock * QgsRasterProjector::block( int bandNo, QgsRectangle const & ex
|
||||
|
||||
size_t pixelSize = QgsRasterBlock::typeSize( mInput->dataType( bandNo ) ) / 8;
|
||||
|
||||
size_t inputSize = pixelSize * srcCols() * srcRows();
|
||||
|
||||
size_t outputSize = width * height * pixelSize;
|
||||
//void * outputData = malloc( outputSize );
|
||||
|
||||
if ( !outputBlock->reset( QgsRasterBlock::ARGB32_Premultiplied, width, height ) )
|
||||
{
|
||||
delete inputBlock;
|
||||
@ -755,15 +750,21 @@ QgsRasterBlock * QgsRasterProjector::block( int bandNo, QgsRectangle const & ex
|
||||
for ( int j = 0; j < width; ++j )
|
||||
{
|
||||
srcRowCol( i, j, &srcRow, &srcCol );
|
||||
size_t srcIndex = pixelSize * ( srcRow * mSrcCols + srcCol );
|
||||
size_t destIndex = pixelSize * ( i * width + j );
|
||||
|
||||
if ( srcIndex >= inputSize || destIndex >= outputSize ) continue; // should not happen
|
||||
|
||||
//memcpy(( char* )outputData + destIndex, ( char* )inputData + srcIndex, pixelSize );
|
||||
size_t srcIndex = srcRow * mSrcCols + srcCol;
|
||||
size_t destIndex = i * width + j;
|
||||
|
||||
char *srcBits = inputBlock->bits( srcIndex );
|
||||
char *destBits = outputBlock->bits( destIndex );
|
||||
if ( !srcBits )
|
||||
{
|
||||
QgsDebugMsg( "Cannot get input block data." );
|
||||
continue;
|
||||
}
|
||||
if ( !destBits )
|
||||
{
|
||||
QgsDebugMsg( "Cannot set output block data." );
|
||||
continue;
|
||||
}
|
||||
memcpy( destBits, srcBits, pixelSize );
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user