Skip to content

Commit c987446

Browse files
committed
use QgsRasterInterface::DataType enum instead of int; in raster interfaces check in setInput if input is compatible;
1 parent 9352fa1 commit c987446

13 files changed

Lines changed: 89 additions & 17 deletions

‎src/core/qgsrasterdataprovider.h‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ class CORE_EXPORT QgsRasterDataProvider : public QgsDataProvider, public QgsRast
106106

107107
QgsRasterInterface * srcInput() { return this; }
108108

109+
/* It makes no sense to set input on provider */
110+
bool setInput( QgsRasterInterface* input ) { return false; }
111+
109112
/**
110113
* Add the list of WMS layer names to be rendered by this server
111114
*/
@@ -157,15 +160,15 @@ class CORE_EXPORT QgsRasterDataProvider : public QgsDataProvider, public QgsRast
157160
// TODO: Get the file masks supported by this provider, suitable for feeding into the file open dialog box
158161

159162
/** Returns data type for the band specified by number */
160-
virtual int dataType( int bandNo ) const
163+
virtual QgsRasterInterface::DataType dataType( int bandNo ) const
161164
{
162165
return srcDataType( bandNo );
163166
}
164167

165168
/** Returns source data type for the band specified by number,
166169
* source data type may be shorter than dataType
167170
*/
168-
virtual int srcDataType( int bandNo ) const
171+
virtual QgsRasterInterface::DataType srcDataType( int bandNo ) const
169172
{
170173
Q_UNUSED( bandNo );
171174
return QgsRasterDataProvider::UnknownDataType;

‎src/core/raster/qgsrasterinterface.cpp‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,37 @@ QgsRasterInterface::~QgsRasterInterface()
3333
{
3434
}
3535

36+
bool QgsRasterInterface::typeIsNumeric( DataType dataType ) const
37+
{
38+
switch ( dataType )
39+
{
40+
case Byte:
41+
case UInt16:
42+
case Int16:
43+
case UInt32:
44+
case Int32:
45+
case Float32:
46+
case CInt16:
47+
case Float64:
48+
case CInt32:
49+
case CFloat32:
50+
case CFloat64:
51+
return true;
52+
}
53+
return false;
54+
}
55+
56+
bool QgsRasterInterface::typeIsColor( DataType dataType ) const
57+
{
58+
switch ( dataType )
59+
{
60+
case ARGB32:
61+
case ARGB32_Premultiplied:
62+
return true;
63+
}
64+
return false;
65+
}
66+
3667
// To give to an image preallocated memory is the only way to avoid memcpy
3768
// when we want to keep data but delete QImage
3869
QImage * QgsRasterInterface::createImage( int width, int height, QImage::Format format )

‎src/core/raster/qgsrasterinterface.h‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,14 @@ class CORE_EXPORT QgsRasterInterface
9999
return typeSize( dataType( bandNo ) );
100100
}
101101

102+
/** Returns true if data type is numeric */
103+
bool typeIsNumeric( DataType type ) const;
104+
105+
/** Returns true if data type is color */
106+
bool typeIsColor( DataType type ) const;
107+
102108
/** Returns data type for the band specified by number */
103-
virtual int dataType( int bandNo ) const
109+
virtual DataType dataType( int bandNo ) const
104110
{
105111
Q_UNUSED( bandNo );
106112
return UnknownDataType;

‎src/core/raster/qgsrasterrenderer.cpp‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,22 @@ QgsRasterRenderer::~QgsRasterRenderer()
4242
{
4343
}
4444

45+
bool QgsRasterRenderer::setInput( QgsRasterInterface* input )
46+
{
47+
// Renderer can only work with numerical values in at least 1 band
48+
if ( !mInput ) return false;
49+
50+
for ( int i = 1; i <= mInput->bandCount(); i++ )
51+
{
52+
if ( typeIsNumeric( mInput->dataType( i ) ) )
53+
{
54+
mInput = input;
55+
return true;
56+
}
57+
}
58+
return false;
59+
}
60+
4561
bool QgsRasterRenderer::usesTransparency( ) const
4662
{
4763
if ( !mInput )

‎src/core/raster/qgsrasterrenderer.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ class CORE_EXPORT QgsRasterRenderer : public QgsRasterInterface
3939

4040
virtual QString type() const { return mType; }
4141

42+
virtual bool setInput( QgsRasterInterface* input );
43+
4244
virtual void * readBlock( int bandNo, QgsRectangle const & extent, int width, int height )
4345
{
4446
Q_UNUSED( bandNo ); Q_UNUSED( extent ); Q_UNUSED( width ); Q_UNUSED( height );

‎src/core/raster/qgsrasterresamplefilter.cpp‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,18 @@ QgsRasterResampleFilter::~QgsRasterResampleFilter()
4545
delete mZoomedOutResampler;
4646
}
4747

48+
bool QgsRasterResampleFilter::setInput( QgsRasterInterface* input )
49+
{
50+
// Resampler can only work with single band ARGB32_Premultiplied
51+
if ( !mInput ) return false;
52+
53+
if ( mInput->bandCount() < 1 ) return false;
54+
55+
if ( mInput->dataType( 1 ) != QgsRasterInterface::ARGB32_Premultiplied ) return false;
56+
57+
return true;
58+
}
59+
4860
void QgsRasterResampleFilter::setZoomedInResampler( QgsRasterResampler* r )
4961
{
5062
delete mZoomedInResampler;

‎src/core/raster/qgsrasterresamplefilter.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ class QgsRasterResampleFilter : public QgsRasterInterface
3131
QgsRasterResampleFilter( QgsRasterInterface* input = 0 );
3232
~QgsRasterResampleFilter();
3333

34+
bool setInput( QgsRasterInterface* input );
35+
3436
void * readBlock( int bandNo, QgsRectangle const & extent, int width, int height );
3537

3638
/**Set resampler for zoomed in scales. Takes ownership of the object*/

‎src/providers/gdal/qgsgdalprovider.cpp‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,7 +1200,7 @@ int QgsGdalProvider::capabilities() const
12001200
return capability;
12011201
}
12021202

1203-
int QgsGdalProvider::dataTypeFormGdal( int theGdalDataType ) const
1203+
QgsRasterInterface::DataType QgsGdalProvider::dataTypeFormGdal( int theGdalDataType ) const
12041204
{
12051205
switch ( theGdalDataType )
12061206
{
@@ -1247,14 +1247,14 @@ int QgsGdalProvider::dataTypeFormGdal( int theGdalDataType ) const
12471247
return QgsRasterDataProvider::UnknownDataType;
12481248
}
12491249

1250-
int QgsGdalProvider::srcDataType( int bandNo ) const
1250+
QgsRasterInterface::DataType QgsGdalProvider::srcDataType( int bandNo ) const
12511251
{
12521252
GDALRasterBandH myGdalBand = GDALGetRasterBand( mGdalDataset, bandNo );
12531253
GDALDataType myGdalDataType = GDALGetRasterDataType( myGdalBand );
12541254
return dataTypeFormGdal( myGdalDataType );
12551255
}
12561256

1257-
int QgsGdalProvider::dataType( int bandNo ) const
1257+
QgsRasterInterface::DataType QgsGdalProvider::dataType( int bandNo ) const
12581258
{
12591259
if ( mGdalDataType.size() == 0 ) return QgsRasterDataProvider::UnknownDataType;
12601260

‎src/providers/gdal/qgsgdalprovider.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,10 @@ class QgsGdalProvider : public QgsRasterDataProvider
184184
*/
185185
int capabilities() const;
186186

187-
int dataType( int bandNo ) const;
188-
int srcDataType( int bandNo ) const;
187+
QgsRasterInterface::DataType dataType( int bandNo ) const;
188+
QgsRasterInterface::DataType srcDataType( int bandNo ) const;
189189

190-
int dataTypeFormGdal( int theGdalDataType ) const;
190+
QgsRasterInterface::DataType dataTypeFormGdal( int theGdalDataType ) const;
191191

192192
int bandCount() const;
193193

‎src/providers/grass/qgsgrassrasterprovider.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,12 +383,12 @@ int QgsGrassRasterProvider::capabilities() const
383383
return capability;
384384
}
385385

386-
int QgsGrassRasterProvider::dataType( int bandNo ) const
386+
QgsRasterInterface::DataType QgsGrassRasterProvider::dataType( int bandNo ) const
387387
{
388388
return srcDataType( bandNo );
389389
}
390390

391-
int QgsGrassRasterProvider::srcDataType( int bandNo ) const
391+
QgsRasterInterface::DataType QgsGrassRasterProvider::srcDataType( int bandNo ) const
392392
{
393393
Q_UNUSED( bandNo );
394394
switch ( mGrassDataType )

0 commit comments

Comments
 (0)