Skip to content

Commit

Permalink
use QgsRasterInterface::DataType enum instead of int; in raster inter…
Browse files Browse the repository at this point in the history
…faces check in setInput if input is compatible;
  • Loading branch information
blazek committed Jul 1, 2012
1 parent 9352fa1 commit c987446
Show file tree
Hide file tree
Showing 13 changed files with 89 additions and 17 deletions.
7 changes: 5 additions & 2 deletions src/core/qgsrasterdataprovider.h
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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;
Expand Down
31 changes: 31 additions & 0 deletions src/core/raster/qgsrasterinterface.cpp
Expand Up @@ -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 )
Expand Down
8 changes: 7 additions & 1 deletion src/core/raster/qgsrasterinterface.h
Expand Up @@ -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;
Expand Down
16 changes: 16 additions & 0 deletions src/core/raster/qgsrasterrenderer.cpp
Expand Up @@ -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 )
Expand Down
2 changes: 2 additions & 0 deletions src/core/raster/qgsrasterrenderer.h
Expand Up @@ -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 );
Expand Down
12 changes: 12 additions & 0 deletions src/core/raster/qgsrasterresamplefilter.cpp
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/core/raster/qgsrasterresamplefilter.h
Expand Up @@ -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*/
Expand Down
6 changes: 3 additions & 3 deletions src/providers/gdal/qgsgdalprovider.cpp
Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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;

Expand Down
6 changes: 3 additions & 3 deletions src/providers/gdal/qgsgdalprovider.h
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions src/providers/grass/qgsgrassrasterprovider.cpp
Expand Up @@ -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 )
Expand Down
4 changes: 2 additions & 2 deletions src/providers/grass/qgsgrassrasterprovider.h
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions src/providers/wms/qgswmsprovider.cpp
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/providers/wms/qgswmsprovider.h
Expand Up @@ -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;


Expand Down

0 comments on commit c987446

Please sign in to comment.