Skip to content

Commit

Permalink
more methods from provider to interface, renderer shortcuts
Browse files Browse the repository at this point in the history
  • Loading branch information
blazek committed Jul 1, 2012
1 parent a9e1d76 commit b34e058
Show file tree
Hide file tree
Showing 15 changed files with 35 additions and 93 deletions.
2 changes: 1 addition & 1 deletion python/core/qgsrasterrenderer.sip
Expand Up @@ -31,7 +31,7 @@ class QgsRasterRenderer
virtual QString type() const;
virtual void * readBlock( int bandNo, const QgsRectangle & extent, int width, int height );

bool usesTransparency( QgsCoordinateReferenceSystem& srcSRS, QgsCoordinateReferenceSystem& dstSRS ) const;
bool usesTransparency() const;

void setOpacity( double opacity );
double opacity() const;
Expand Down
3 changes: 2 additions & 1 deletion src/app/qgisapp.cpp
Expand Up @@ -6797,7 +6797,8 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
else if ( layer->type() == QgsMapLayer::RasterLayer )
{
const QgsRasterLayer *rlayer = qobject_cast<const QgsRasterLayer *>( layer );
if ( rlayer->dataProvider()->dataType( 1 ) != QgsRasterDataProvider::ARGBDataType )
if ( rlayer->dataProvider()->dataType( 1 ) != QgsRasterDataProvider::ARGB32
&& rlayer->dataProvider()->dataType( 1 ) != QgsRasterDataProvider::ARGB32_Premultiplied )
{
if ( rlayer->dataProvider()->capabilities() & QgsRasterDataProvider::Size )
{
Expand Down
6 changes: 4 additions & 2 deletions src/app/qgsrasterlayerproperties.cpp
Expand Up @@ -438,7 +438,8 @@ void QgsRasterLayerProperties::sync()
{
QSettings myQSettings;

if ( mRasterLayer->dataProvider()->dataType( 1 ) == QgsRasterDataProvider::ARGBDataType )
if ( mRasterLayer->dataProvider()->dataType( 1 ) == QgsRasterDataProvider::ARGB32
|| mRasterLayer->dataProvider()->dataType( 1 ) == QgsRasterDataProvider::ARGB32_Premultiplied )
{
gboxNoDataValue->setEnabled( false );
gboxCustomTransparency->setEnabled( false );
Expand Down Expand Up @@ -527,7 +528,8 @@ void QgsRasterLayerProperties::sync()
lblRows->setText( tr( "Rows: " ) + tr( "n/a" ) );
}

if ( mRasterLayer->dataProvider()->dataType( 1 ) == QgsRasterDataProvider::ARGBDataType )
if ( mRasterLayer->dataProvider()->dataType( 1 ) == QgsRasterDataProvider::ARGB32
|| mRasterLayer->dataProvider()->dataType( 1 ) == QgsRasterDataProvider::ARGB32_Premultiplied )
{
lblNoData->setText( tr( "No-Data Value: " ) + tr( "n/a" ) );
}
Expand Down
63 changes: 0 additions & 63 deletions src/core/qgsrasterdataprovider.h
Expand Up @@ -68,25 +68,6 @@ class CORE_EXPORT QgsRasterDataProvider : public QgsDataProvider, public QgsRast
Size = 1 << 6 // has fixed source type
};

// This is modified copy of GDALDataType
enum DataType
{
/*! Unknown or unspecified type */ UnknownDataType = 0,
/*! Eight bit unsigned integer */ Byte = 1,
/*! Sixteen bit unsigned integer */ UInt16 = 2,
/*! Sixteen bit signed integer */ Int16 = 3,
/*! Thirty two bit unsigned integer */ UInt32 = 4,
/*! Thirty two bit signed integer */ Int32 = 5,
/*! Thirty two bit floating point */ Float32 = 6,
/*! Sixty four bit floating point */ Float64 = 7,
/*! Complex Int16 */ CInt16 = 8,
/*! Complex Int32 */ CInt32 = 9,
/*! Complex Float32 */ CFloat32 = 10,
/*! Complex Float64 */ CFloat64 = 11,
/*! Color, alpha, red, green, blue, 4 bytes */ ARGBDataType = 12,
TypeCount = 13 /* maximum type # + 1 */
};

// This is modified copy of GDALColorInterp
enum ColorInterpretation
{
Expand Down Expand Up @@ -190,50 +171,6 @@ class CORE_EXPORT QgsRasterDataProvider : public QgsDataProvider, public QgsRast
return QgsRasterDataProvider::UnknownDataType;
}

int typeSize( int dataType ) const
{
// modified copy from GDAL
switch ( dataType )
{
case Byte:
return 8;

case UInt16:
case Int16:
return 16;

case UInt32:
case Int32:
case Float32:
case CInt16:
return 32;

case Float64:
case CInt32:
case CFloat32:
return 64;

case CFloat64:
return 128;

case ARGBDataType:
return 32;

default:
return 0;
}
}
int dataTypeSize( int bandNo ) const
{
return typeSize( dataType( bandNo ) );
}

/** Get numbur of bands */
virtual int bandCount() const
{
return 1;
}

/** Returns data type for the band specified by number */
virtual int colorInterpretation( int theBandNo ) const
{
Expand Down
8 changes: 2 additions & 6 deletions src/core/raster/qgsmultibandcolorrenderer.cpp
Expand Up @@ -109,15 +109,11 @@ void * QgsMultiBandColorRenderer::readBlock( int bandNo, QgsRectangle const & e
}

//In some (common) cases, we can simplify the drawing loop considerably and save render time
// TODO
bool fastDraw = false;
/*
bool fastDraw = (
!usesTransparency( viewPort->mSrcCRS, viewPort->mDestCRS )
bool fastDraw = ( !usesTransparency()
&& mRedBand > 0 && mGreenBand > 0 && mBlueBand > 0
&& mAlphaBand < 1 && !mRedContrastEnhancement && !mGreenContrastEnhancement && !mBlueContrastEnhancement
&& !mInvertColor );
*/

QgsRasterInterface::DataType redType = QgsRasterInterface::UnknownDataType;

if ( mRedBand > 0 )
Expand Down
4 changes: 1 addition & 3 deletions src/core/raster/qgspalettedrasterrenderer.cpp
Expand Up @@ -99,9 +99,7 @@ void * QgsPalettedRasterRenderer::readBlock( int bandNo, QgsRectangle const & e
double currentOpacity = mOpacity;

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

if ( mAlphaBand > 0 && mAlphaBand != mBandNumber )
Expand Down
2 changes: 2 additions & 0 deletions src/core/raster/qgsrasterinterface.cpp
Expand Up @@ -28,6 +28,8 @@ QgsRasterInterface::~QgsRasterInterface()
{
}

// 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 )
{
// Qt has its own internal function depthForFormat(), unfortunately it is not public
Expand Down
19 changes: 15 additions & 4 deletions src/core/raster/qgsrasterinterface.h
Expand Up @@ -51,8 +51,12 @@ class CORE_EXPORT QgsRasterInterface //: public QObject
/*! Complex Int32 */ CInt32 = 9,
/*! Complex Float32 */ CFloat32 = 10,
/*! Complex Float64 */ CFloat64 = 11,
/*! Color, alpha, red, green, blue, 4 bytes */ ARGBDataType = 12,
TypeCount = 13 /* maximum type # + 1 */
/*! Color, alpha, red, green, blue, 4 bytes the same as
QImage::Format_ARGB32 */ ARGB32 = 12,
/*! Color, alpha, red, green, blue, 4 bytes the same as
QImage::Format_ARGB32_Premultiplied */ ARGB32_Premultiplied = 13,

TypeCount = 14 /* maximum type # + 1 */
};

int typeSize( int dataType ) const
Expand Down Expand Up @@ -81,7 +85,8 @@ class CORE_EXPORT QgsRasterInterface //: public QObject
case CFloat64:
return 128;

case ARGBDataType:
case ARGB32:
case ARGB32_Premultiplied:
return 32;

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


QgsRasterInterface( QgsRasterInterface * input = 0 );

virtual ~QgsRasterInterface();

/** Returns data type for the band specified by number */
virtual int dataType( int bandNo ) const
{
Q_UNUSED( bandNo );
return UnknownDataType;
}

/** Get numbur of bands */
virtual int bandCount() const
{
return 1;
}

// TODO
virtual double noDataValue() const { return 0; }

Expand Down
3 changes: 2 additions & 1 deletion src/core/raster/qgsrasterlayer.cpp
Expand Up @@ -1720,7 +1720,8 @@ void QgsRasterLayer::setDataProvider( QString const & provider )
{
mRasterType = Multiband;
}
else if ( mDataProvider->dataType( 1 ) == QgsRasterDataProvider::ARGBDataType )
else if ( mDataProvider->dataType( 1 ) == QgsRasterDataProvider::ARGB32
|| mDataProvider->dataType( 1 ) == QgsRasterDataProvider::ARGB32_Premultiplied )
{
mRasterType = ColorLayer;
}
Expand Down
6 changes: 2 additions & 4 deletions src/core/raster/qgsrasterrenderer.cpp
Expand Up @@ -41,11 +41,9 @@ QgsRasterRenderer::~QgsRasterRenderer()
{
}

bool QgsRasterRenderer::usesTransparency( QgsCoordinateReferenceSystem& srcSRS, QgsCoordinateReferenceSystem& dstSRS ) const
bool QgsRasterRenderer::usesTransparency( ) const
{
//transparency is always used if on-the-fly reprojection is enabled
bool reprojectionEnabled = ( srcSRS.isValid() && dstSRS.isValid() && srcSRS != dstSRS );
if ( !mInput || reprojectionEnabled )
if ( !mInput )
{
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/raster/qgsrasterrenderer.h
Expand Up @@ -46,7 +46,7 @@ class CORE_EXPORT QgsRasterRenderer : public QgsRasterInterface
return 0;
}

bool usesTransparency( QgsCoordinateReferenceSystem& srcSRS, QgsCoordinateReferenceSystem& dstSRS ) const;
bool usesTransparency() const;

void setOpacity( double opacity ) { mOpacity = opacity; }
double opacity() const { return mOpacity; }
Expand Down
3 changes: 1 addition & 2 deletions src/core/raster/qgssinglebandcolordatarenderer.cpp
Expand Up @@ -53,8 +53,7 @@ void * QgsSingleBandColorDataRenderer::readBlock( int bandNo, QgsRectangle cons

int currentRasterPos;

//bool hasTransparency = usesTransparency( viewPort->mSrcCRS, viewPort->mDestCRS );
bool hasTransparency = false;
bool hasTransparency = usesTransparency();

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

Expand Down
2 changes: 0 additions & 2 deletions src/core/raster/qgssinglebandgrayrenderer.cpp
Expand Up @@ -95,8 +95,6 @@ void * QgsSingleBandGrayRenderer::readBlock( int bandNo, QgsRectangle const & e
alphaData = rasterData;
}

// To give to image preallocated memory is the only way to avoid memcpy at the end
//QImage img( width, height, QImage::Format_ARGB32_Premultiplied );
QImage *img = createImage ( width, height, QImage::Format_ARGB32_Premultiplied );
QRgb* imageScanLine = 0;
int currentRasterPos = 0;
Expand Down
3 changes: 1 addition & 2 deletions src/core/raster/qgssinglebandpseudocolorrenderer.cpp
Expand Up @@ -82,8 +82,7 @@ void * QgsSingleBandPseudoColorRenderer::readBlock( int bandNo, QgsRectangle co
QRgb myDefaultColor = qRgba( 255, 255, 255, 0 );

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

if ( mAlphaBand > 0 && mAlphaBand != mBand )
{
Expand Down
2 changes: 1 addition & 1 deletion src/providers/wms/qgswmsprovider.cpp
Expand Up @@ -1358,7 +1358,7 @@ int QgsWmsProvider::dataType( int bandNo ) const
int QgsWmsProvider::srcDataType( int bandNo ) const
{
Q_UNUSED( bandNo );
return QgsRasterDataProvider::ARGBDataType;
return QgsRasterDataProvider::ARGB32;
}

int QgsWmsProvider::bandCount() const
Expand Down

0 comments on commit b34e058

Please sign in to comment.