Skip to content

Commit b34e058

Browse files
committed
more methods from provider to interface, renderer shortcuts
1 parent a9e1d76 commit b34e058

15 files changed

+35
-93
lines changed

python/core/qgsrasterrenderer.sip

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class QgsRasterRenderer
3131
virtual QString type() const;
3232
virtual void * readBlock( int bandNo, const QgsRectangle & extent, int width, int height );
3333

34-
bool usesTransparency( QgsCoordinateReferenceSystem& srcSRS, QgsCoordinateReferenceSystem& dstSRS ) const;
34+
bool usesTransparency() const;
3535

3636
void setOpacity( double opacity );
3737
double opacity() const;

src/app/qgisapp.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -6797,7 +6797,8 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
67976797
else if ( layer->type() == QgsMapLayer::RasterLayer )
67986798
{
67996799
const QgsRasterLayer *rlayer = qobject_cast<const QgsRasterLayer *>( layer );
6800-
if ( rlayer->dataProvider()->dataType( 1 ) != QgsRasterDataProvider::ARGBDataType )
6800+
if ( rlayer->dataProvider()->dataType( 1 ) != QgsRasterDataProvider::ARGB32
6801+
&& rlayer->dataProvider()->dataType( 1 ) != QgsRasterDataProvider::ARGB32_Premultiplied )
68016802
{
68026803
if ( rlayer->dataProvider()->capabilities() & QgsRasterDataProvider::Size )
68036804
{

src/app/qgsrasterlayerproperties.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,8 @@ void QgsRasterLayerProperties::sync()
438438
{
439439
QSettings myQSettings;
440440

441-
if ( mRasterLayer->dataProvider()->dataType( 1 ) == QgsRasterDataProvider::ARGBDataType )
441+
if ( mRasterLayer->dataProvider()->dataType( 1 ) == QgsRasterDataProvider::ARGB32
442+
|| mRasterLayer->dataProvider()->dataType( 1 ) == QgsRasterDataProvider::ARGB32_Premultiplied )
442443
{
443444
gboxNoDataValue->setEnabled( false );
444445
gboxCustomTransparency->setEnabled( false );
@@ -527,7 +528,8 @@ void QgsRasterLayerProperties::sync()
527528
lblRows->setText( tr( "Rows: " ) + tr( "n/a" ) );
528529
}
529530

530-
if ( mRasterLayer->dataProvider()->dataType( 1 ) == QgsRasterDataProvider::ARGBDataType )
531+
if ( mRasterLayer->dataProvider()->dataType( 1 ) == QgsRasterDataProvider::ARGB32
532+
|| mRasterLayer->dataProvider()->dataType( 1 ) == QgsRasterDataProvider::ARGB32_Premultiplied )
531533
{
532534
lblNoData->setText( tr( "No-Data Value: " ) + tr( "n/a" ) );
533535
}

src/core/qgsrasterdataprovider.h

-63
Original file line numberDiff line numberDiff line change
@@ -68,25 +68,6 @@ class CORE_EXPORT QgsRasterDataProvider : public QgsDataProvider, public QgsRast
6868
Size = 1 << 6 // has fixed source type
6969
};
7070

71-
// This is modified copy of GDALDataType
72-
enum DataType
73-
{
74-
/*! Unknown or unspecified type */ UnknownDataType = 0,
75-
/*! Eight bit unsigned integer */ Byte = 1,
76-
/*! Sixteen bit unsigned integer */ UInt16 = 2,
77-
/*! Sixteen bit signed integer */ Int16 = 3,
78-
/*! Thirty two bit unsigned integer */ UInt32 = 4,
79-
/*! Thirty two bit signed integer */ Int32 = 5,
80-
/*! Thirty two bit floating point */ Float32 = 6,
81-
/*! Sixty four bit floating point */ Float64 = 7,
82-
/*! Complex Int16 */ CInt16 = 8,
83-
/*! Complex Int32 */ CInt32 = 9,
84-
/*! Complex Float32 */ CFloat32 = 10,
85-
/*! Complex Float64 */ CFloat64 = 11,
86-
/*! Color, alpha, red, green, blue, 4 bytes */ ARGBDataType = 12,
87-
TypeCount = 13 /* maximum type # + 1 */
88-
};
89-
9071
// This is modified copy of GDALColorInterp
9172
enum ColorInterpretation
9273
{
@@ -190,50 +171,6 @@ class CORE_EXPORT QgsRasterDataProvider : public QgsDataProvider, public QgsRast
190171
return QgsRasterDataProvider::UnknownDataType;
191172
}
192173

193-
int typeSize( int dataType ) const
194-
{
195-
// modified copy from GDAL
196-
switch ( dataType )
197-
{
198-
case Byte:
199-
return 8;
200-
201-
case UInt16:
202-
case Int16:
203-
return 16;
204-
205-
case UInt32:
206-
case Int32:
207-
case Float32:
208-
case CInt16:
209-
return 32;
210-
211-
case Float64:
212-
case CInt32:
213-
case CFloat32:
214-
return 64;
215-
216-
case CFloat64:
217-
return 128;
218-
219-
case ARGBDataType:
220-
return 32;
221-
222-
default:
223-
return 0;
224-
}
225-
}
226-
int dataTypeSize( int bandNo ) const
227-
{
228-
return typeSize( dataType( bandNo ) );
229-
}
230-
231-
/** Get numbur of bands */
232-
virtual int bandCount() const
233-
{
234-
return 1;
235-
}
236-
237174
/** Returns data type for the band specified by number */
238175
virtual int colorInterpretation( int theBandNo ) const
239176
{

src/core/raster/qgsmultibandcolorrenderer.cpp

+2-6
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,11 @@ void * QgsMultiBandColorRenderer::readBlock( int bandNo, QgsRectangle const & e
109109
}
110110

111111
//In some (common) cases, we can simplify the drawing loop considerably and save render time
112-
// TODO
113-
bool fastDraw = false;
114-
/*
115-
bool fastDraw = (
116-
!usesTransparency( viewPort->mSrcCRS, viewPort->mDestCRS )
112+
bool fastDraw = ( !usesTransparency()
117113
&& mRedBand > 0 && mGreenBand > 0 && mBlueBand > 0
118114
&& mAlphaBand < 1 && !mRedContrastEnhancement && !mGreenContrastEnhancement && !mBlueContrastEnhancement
119115
&& !mInvertColor );
120-
*/
116+
121117
QgsRasterInterface::DataType redType = QgsRasterInterface::UnknownDataType;
122118

123119
if ( mRedBand > 0 )

src/core/raster/qgspalettedrasterrenderer.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,7 @@ void * QgsPalettedRasterRenderer::readBlock( int bandNo, QgsRectangle const & e
9999
double currentOpacity = mOpacity;
100100

101101
//rendering is faster without considering user-defined transparency
102-
// TODO
103-
bool hasTransparency = false;
104-
//bool hasTransparency = usesTransparency( viewPort->mSrcCRS, viewPort->mDestCRS );
102+
bool hasTransparency = usesTransparency();
105103
void* transparencyData = 0;
106104

107105
if ( mAlphaBand > 0 && mAlphaBand != mBandNumber )

src/core/raster/qgsrasterinterface.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ QgsRasterInterface::~QgsRasterInterface()
2828
{
2929
}
3030

31+
// To give to an image preallocated memory is the only way to avoid memcpy
32+
// when we want to keep data but delete QImage
3133
QImage * QgsRasterInterface::createImage ( int width, int height, QImage::Format format )
3234
{
3335
// Qt has its own internal function depthForFormat(), unfortunately it is not public

src/core/raster/qgsrasterinterface.h

+15-4
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,12 @@ class CORE_EXPORT QgsRasterInterface //: public QObject
5151
/*! Complex Int32 */ CInt32 = 9,
5252
/*! Complex Float32 */ CFloat32 = 10,
5353
/*! Complex Float64 */ CFloat64 = 11,
54-
/*! Color, alpha, red, green, blue, 4 bytes */ ARGBDataType = 12,
55-
TypeCount = 13 /* maximum type # + 1 */
54+
/*! Color, alpha, red, green, blue, 4 bytes the same as
55+
QImage::Format_ARGB32 */ ARGB32 = 12,
56+
/*! Color, alpha, red, green, blue, 4 bytes the same as
57+
QImage::Format_ARGB32_Premultiplied */ ARGB32_Premultiplied = 13,
58+
59+
TypeCount = 14 /* maximum type # + 1 */
5660
};
5761

5862
int typeSize( int dataType ) const
@@ -81,7 +85,8 @@ class CORE_EXPORT QgsRasterInterface //: public QObject
8185
case CFloat64:
8286
return 128;
8387

84-
case ARGBDataType:
88+
case ARGB32:
89+
case ARGB32_Premultiplied:
8590
return 32;
8691

8792
default:
@@ -93,17 +98,23 @@ class CORE_EXPORT QgsRasterInterface //: public QObject
9398
return typeSize( dataType( bandNo ) );
9499
}
95100

96-
97101
QgsRasterInterface( QgsRasterInterface * input = 0 );
98102

99103
virtual ~QgsRasterInterface();
100104

101105
/** Returns data type for the band specified by number */
102106
virtual int dataType( int bandNo ) const
103107
{
108+
Q_UNUSED( bandNo );
104109
return UnknownDataType;
105110
}
106111

112+
/** Get numbur of bands */
113+
virtual int bandCount() const
114+
{
115+
return 1;
116+
}
117+
107118
// TODO
108119
virtual double noDataValue() const { return 0; }
109120

src/core/raster/qgsrasterlayer.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -1720,7 +1720,8 @@ void QgsRasterLayer::setDataProvider( QString const & provider )
17201720
{
17211721
mRasterType = Multiband;
17221722
}
1723-
else if ( mDataProvider->dataType( 1 ) == QgsRasterDataProvider::ARGBDataType )
1723+
else if ( mDataProvider->dataType( 1 ) == QgsRasterDataProvider::ARGB32
1724+
|| mDataProvider->dataType( 1 ) == QgsRasterDataProvider::ARGB32_Premultiplied )
17241725
{
17251726
mRasterType = ColorLayer;
17261727
}

src/core/raster/qgsrasterrenderer.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,9 @@ QgsRasterRenderer::~QgsRasterRenderer()
4141
{
4242
}
4343

44-
bool QgsRasterRenderer::usesTransparency( QgsCoordinateReferenceSystem& srcSRS, QgsCoordinateReferenceSystem& dstSRS ) const
44+
bool QgsRasterRenderer::usesTransparency( ) const
4545
{
46-
//transparency is always used if on-the-fly reprojection is enabled
47-
bool reprojectionEnabled = ( srcSRS.isValid() && dstSRS.isValid() && srcSRS != dstSRS );
48-
if ( !mInput || reprojectionEnabled )
46+
if ( !mInput )
4947
{
5048
return true;
5149
}

src/core/raster/qgsrasterrenderer.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class CORE_EXPORT QgsRasterRenderer : public QgsRasterInterface
4646
return 0;
4747
}
4848

49-
bool usesTransparency( QgsCoordinateReferenceSystem& srcSRS, QgsCoordinateReferenceSystem& dstSRS ) const;
49+
bool usesTransparency() const;
5050

5151
void setOpacity( double opacity ) { mOpacity = opacity; }
5252
double opacity() const { return mOpacity; }

src/core/raster/qgssinglebandcolordatarenderer.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ void * QgsSingleBandColorDataRenderer::readBlock( int bandNo, QgsRectangle cons
5353

5454
int currentRasterPos;
5555

56-
//bool hasTransparency = usesTransparency( viewPort->mSrcCRS, viewPort->mDestCRS );
57-
bool hasTransparency = false;
56+
bool hasTransparency = usesTransparency();
5857

5958
QgsRasterInterface::DataType rasterType = ( QgsRasterInterface::DataType )mInput->dataType( mBand );
6059

src/core/raster/qgssinglebandgrayrenderer.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,6 @@ void * QgsSingleBandGrayRenderer::readBlock( int bandNo, QgsRectangle const & e
9595
alphaData = rasterData;
9696
}
9797

98-
// To give to image preallocated memory is the only way to avoid memcpy at the end
99-
//QImage img( width, height, QImage::Format_ARGB32_Premultiplied );
10098
QImage *img = createImage ( width, height, QImage::Format_ARGB32_Premultiplied );
10199
QRgb* imageScanLine = 0;
102100
int currentRasterPos = 0;

src/core/raster/qgssinglebandpseudocolorrenderer.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,7 @@ void * QgsSingleBandPseudoColorRenderer::readBlock( int bandNo, QgsRectangle co
8282
QRgb myDefaultColor = qRgba( 255, 255, 255, 0 );
8383

8484
//rendering is faster without considering user-defined transparency
85-
//bool hasTransparency = usesTransparency( viewPort->mSrcCRS, viewPort->mDestCRS );
86-
bool hasTransparency = false;
85+
bool hasTransparency = usesTransparency();
8786

8887
if ( mAlphaBand > 0 && mAlphaBand != mBand )
8988
{

src/providers/wms/qgswmsprovider.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1358,7 +1358,7 @@ int QgsWmsProvider::dataType( int bandNo ) const
13581358
int QgsWmsProvider::srcDataType( int bandNo ) const
13591359
{
13601360
Q_UNUSED( bandNo );
1361-
return QgsRasterDataProvider::ARGBDataType;
1361+
return QgsRasterDataProvider::ARGB32;
13621362
}
13631363

13641364
int QgsWmsProvider::bandCount() const

0 commit comments

Comments
 (0)