Skip to content
Permalink
Browse files

more methods from provider to interface, renderer shortcuts

  • Loading branch information
blazek committed Jul 1, 2012
1 parent a9e1d76 commit b34e058f4b4903916950ed629530dd387031e022
@@ -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;
@@ -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 )
{
@@ -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 );
@@ -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" ) );
}
@@ -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
{
@@ -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
{
@@ -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 )
@@ -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 )
@@ -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
@@ -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
@@ -81,7 +85,8 @@ class CORE_EXPORT QgsRasterInterface //: public QObject
case CFloat64:
return 128;

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

default:
@@ -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; }

@@ -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;
}
@@ -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;
}
@@ -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; }
@@ -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 );

@@ -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;
@@ -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 )
{
@@ -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

0 comments on commit b34e058

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