Skip to content
Permalink
Browse files

use QgsRasterInterface::DataType enum instead of int; in raster inter…

…faces check in setInput if input is compatible;
  • Loading branch information
blazek committed Jul 1, 2012
1 parent 9352fa1 commit c98744646c08f44bd42397c2df9a5ccc161999e7
@@ -106,6 +106,9 @@ class CORE_EXPORT QgsRasterDataProvider : public QgsDataProvider, public QgsRast

QgsRasterInterface * srcInput() { return this; }

/* It makes no sense to set input on provider */
bool setInput( QgsRasterInterface* input ) { return false; }

/**
* Add the list of WMS layer names to be rendered by this server
*/
@@ -157,15 +160,15 @@ class CORE_EXPORT QgsRasterDataProvider : public QgsDataProvider, public QgsRast
// TODO: Get the file masks supported by this provider, suitable for feeding into the file open dialog box

/** Returns data type for the band specified by number */
virtual int dataType( int bandNo ) const
virtual QgsRasterInterface::DataType dataType( int bandNo ) const
{
return srcDataType( bandNo );
}

/** Returns source data type for the band specified by number,
* source data type may be shorter than dataType
*/
virtual int srcDataType( int bandNo ) const
virtual QgsRasterInterface::DataType srcDataType( int bandNo ) const
{
Q_UNUSED( bandNo );
return QgsRasterDataProvider::UnknownDataType;
@@ -33,6 +33,37 @@ QgsRasterInterface::~QgsRasterInterface()
{
}

bool QgsRasterInterface::typeIsNumeric( DataType dataType ) const
{
switch ( dataType )
{
case Byte:
case UInt16:
case Int16:
case UInt32:
case Int32:
case Float32:
case CInt16:
case Float64:
case CInt32:
case CFloat32:
case CFloat64:
return true;
}
return false;
}

bool QgsRasterInterface::typeIsColor( DataType dataType ) const
{
switch ( dataType )
{
case ARGB32:
case ARGB32_Premultiplied:
return true;
}
return false;
}

// To give to an image preallocated memory is the only way to avoid memcpy
// when we want to keep data but delete QImage
QImage * QgsRasterInterface::createImage( int width, int height, QImage::Format format )
@@ -99,8 +99,14 @@ class CORE_EXPORT QgsRasterInterface
return typeSize( dataType( bandNo ) );
}

/** Returns true if data type is numeric */
bool typeIsNumeric( DataType type ) const;

/** Returns true if data type is color */
bool typeIsColor( DataType type ) const;

/** Returns data type for the band specified by number */
virtual int dataType( int bandNo ) const
virtual DataType dataType( int bandNo ) const
{
Q_UNUSED( bandNo );
return UnknownDataType;
@@ -42,6 +42,22 @@ QgsRasterRenderer::~QgsRasterRenderer()
{
}

bool QgsRasterRenderer::setInput( QgsRasterInterface* input )
{
// Renderer can only work with numerical values in at least 1 band
if ( !mInput ) return false;

for ( int i = 1; i <= mInput->bandCount(); i++ )
{
if ( typeIsNumeric( mInput->dataType( i ) ) )
{
mInput = input;
return true;
}
}
return false;
}

bool QgsRasterRenderer::usesTransparency( ) const
{
if ( !mInput )
@@ -39,6 +39,8 @@ class CORE_EXPORT QgsRasterRenderer : public QgsRasterInterface

virtual QString type() const { return mType; }

virtual bool setInput( QgsRasterInterface* input );

virtual void * readBlock( int bandNo, QgsRectangle const & extent, int width, int height )
{
Q_UNUSED( bandNo ); Q_UNUSED( extent ); Q_UNUSED( width ); Q_UNUSED( height );
@@ -45,6 +45,18 @@ QgsRasterResampleFilter::~QgsRasterResampleFilter()
delete mZoomedOutResampler;
}

bool QgsRasterResampleFilter::setInput( QgsRasterInterface* input )
{
// Resampler can only work with single band ARGB32_Premultiplied
if ( !mInput ) return false;

if ( mInput->bandCount() < 1 ) return false;

if ( mInput->dataType( 1 ) != QgsRasterInterface::ARGB32_Premultiplied ) return false;

return true;
}

void QgsRasterResampleFilter::setZoomedInResampler( QgsRasterResampler* r )
{
delete mZoomedInResampler;
@@ -31,6 +31,8 @@ class QgsRasterResampleFilter : public QgsRasterInterface
QgsRasterResampleFilter( QgsRasterInterface* input = 0 );
~QgsRasterResampleFilter();

bool setInput( QgsRasterInterface* input );

void * readBlock( int bandNo, QgsRectangle const & extent, int width, int height );

/**Set resampler for zoomed in scales. Takes ownership of the object*/
@@ -1200,7 +1200,7 @@ int QgsGdalProvider::capabilities() const
return capability;
}

int QgsGdalProvider::dataTypeFormGdal( int theGdalDataType ) const
QgsRasterInterface::DataType QgsGdalProvider::dataTypeFormGdal( int theGdalDataType ) const
{
switch ( theGdalDataType )
{
@@ -1247,14 +1247,14 @@ int QgsGdalProvider::dataTypeFormGdal( int theGdalDataType ) const
return QgsRasterDataProvider::UnknownDataType;
}

int QgsGdalProvider::srcDataType( int bandNo ) const
QgsRasterInterface::DataType QgsGdalProvider::srcDataType( int bandNo ) const
{
GDALRasterBandH myGdalBand = GDALGetRasterBand( mGdalDataset, bandNo );
GDALDataType myGdalDataType = GDALGetRasterDataType( myGdalBand );
return dataTypeFormGdal( myGdalDataType );
}

int QgsGdalProvider::dataType( int bandNo ) const
QgsRasterInterface::DataType QgsGdalProvider::dataType( int bandNo ) const
{
if ( mGdalDataType.size() == 0 ) return QgsRasterDataProvider::UnknownDataType;

@@ -184,10 +184,10 @@ class QgsGdalProvider : public QgsRasterDataProvider
*/
int capabilities() const;

int dataType( int bandNo ) const;
int srcDataType( int bandNo ) const;
QgsRasterInterface::DataType dataType( int bandNo ) const;
QgsRasterInterface::DataType srcDataType( int bandNo ) const;

int dataTypeFormGdal( int theGdalDataType ) const;
QgsRasterInterface::DataType dataTypeFormGdal( int theGdalDataType ) const;

int bandCount() const;

@@ -383,12 +383,12 @@ int QgsGrassRasterProvider::capabilities() const
return capability;
}

int QgsGrassRasterProvider::dataType( int bandNo ) const
QgsRasterInterface::DataType QgsGrassRasterProvider::dataType( int bandNo ) const
{
return srcDataType( bandNo );
}

int QgsGrassRasterProvider::srcDataType( int bandNo ) const
QgsRasterInterface::DataType QgsGrassRasterProvider::srcDataType( int bandNo ) const
{
Q_UNUSED( bandNo );
switch ( mGrassDataType )
@@ -189,8 +189,8 @@ class QgsGrassRasterProvider : public QgsRasterDataProvider
*/
int capabilities() const;

int dataType( int bandNo ) const;
int srcDataType( int bandNo ) const;
QgsRasterInterface::DataType dataType( int bandNo ) const;
QgsRasterInterface::DataType srcDataType( int bandNo ) const;

int bandCount() const;

@@ -1350,12 +1350,12 @@ void QgsWmsProvider::capabilitiesReplyFinished()
mCapabilitiesReply = 0;
}

int QgsWmsProvider::dataType( int bandNo ) const
QgsRasterInterface::DataType QgsWmsProvider::dataType( int bandNo ) const
{
return srcDataType( bandNo );
}

int QgsWmsProvider::srcDataType( int bandNo ) const
QgsRasterInterface::DataType QgsWmsProvider::srcDataType( int bandNo ) const
{
Q_UNUSED( bandNo );
return QgsRasterDataProvider::ARGB32;
@@ -640,8 +640,8 @@ class QgsWmsProvider : public QgsRasterDataProvider
*/
int capabilities() const;

int dataType( int bandNo ) const;
int srcDataType( int bandNo ) const;
QgsRasterInterface::DataType dataType( int bandNo ) const;
QgsRasterInterface::DataType srcDataType( int bandNo ) const;
int bandCount() const;


0 comments on commit c987446

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