Skip to content
Permalink
Browse files

resampler separated, reenabled transparency in renderers

  • Loading branch information
blazek committed Jul 1, 2012
1 parent 8760718 commit 3f227c4af4ae802c9058442f5ca7c81450b5e27a
@@ -201,16 +201,18 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer* lyr, QgsMapCanv
mZoomedInResamplingComboBox->insertItem( 2, tr( "Cubic" ) );
mZoomedOutResamplingComboBox->insertItem( 0, tr( "Nearest neighbour" ) );
mZoomedOutResamplingComboBox->insertItem( 1, tr( "Average" ) );

const QgsRasterResampleFilter* resampleFilter = mRasterLayer->resampleFilter();
//set combo boxes to current resampling types
if ( renderer )
if ( resampleFilter )
{
//invert color map
if ( renderer->invertColor() )
{
mInvertColorMapCheckBox->setCheckState( Qt::Checked );
}

const QgsRasterResampler* zoomedInResampler = renderer->zoomedInResampler();
const QgsRasterResampler* zoomedInResampler = resampleFilter->zoomedInResampler();
if ( zoomedInResampler )
{
if ( zoomedInResampler->type() == "bilinear" )
@@ -227,7 +229,7 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer* lyr, QgsMapCanv
mZoomedInResamplingComboBox->setCurrentIndex( 0 );
}

const QgsRasterResampler* zoomedOutResampler = renderer->zoomedOutResampler();
const QgsRasterResampler* zoomedOutResampler = resampleFilter->zoomedOutResampler();
if ( zoomedOutResampler )
{
if ( zoomedOutResampler->type() == "bilinear" ) //bilinear resampler does averaging when zooming out
@@ -798,6 +800,8 @@ void QgsRasterLayerProperties::apply()
pixmapLegend->setScaledContents( true );
pixmapLegend->repaint();

QgsRasterResampleFilter* resampleFilter = mRasterLayer->resampleFilter();

QgsRasterResampler* zoomedInResampler = 0;
QString zoomedInResamplingMethod = mZoomedInResamplingComboBox->currentText();
if ( zoomedInResamplingMethod == tr( "Bilinear" ) )
@@ -809,9 +813,9 @@ void QgsRasterLayerProperties::apply()
zoomedInResampler = new QgsCubicRasterResampler();
}

if ( rasterRenderer )
if ( resampleFilter )
{
rasterRenderer->setZoomedInResampler( zoomedInResampler );
resampleFilter->setZoomedInResampler( zoomedInResampler );
}

//raster resampling
@@ -822,14 +826,14 @@ void QgsRasterLayerProperties::apply()
zoomedOutResampler = new QgsBilinearRasterResampler();
}

if ( rasterRenderer )
if ( resampleFilter )
{
rasterRenderer->setZoomedOutResampler( zoomedOutResampler );
resampleFilter->setZoomedOutResampler( zoomedOutResampler );
}

if ( rasterRenderer )
if ( resampleFilter )
{
rasterRenderer->setMaxOversampling( mMaximumOversamplingSpinBox->value() );
resampleFilter->setMaxOversampling( mMaximumOversamplingSpinBox->value() );
}


@@ -167,6 +167,7 @@ SET(QGIS_CORE_SRCS
raster/qgsrastershaderfunction.cpp

raster/qgsrasterdrawer.cpp
raster/qgsrasterresamplefilter.cpp
raster/qgsrasterrendererregistry.cpp
raster/qgsrasterrenderer.cpp
raster/qgsbilinearrasterresampler.cpp
@@ -101,7 +101,6 @@ QgsRasterRenderer* QgsMultiBandColorRenderer::create( const QDomElement& elem, Q
return r;
}

//void QgsMultiBandColorRenderer::draw( QPainter* p, QgsRasterViewPort* viewPort, const QgsMapToPixel* theQgsMapToPixel )
void * QgsMultiBandColorRenderer::readBlock( int bandNo, QgsRectangle const & extent, int width, int height )
{
if ( !mInput )
@@ -171,31 +170,16 @@ void * QgsMultiBandColorRenderer::readBlock( int bandNo, QgsRectangle const & e
for ( ; bandIt != bands.constEnd(); ++bandIt )
{
bandData.insert( *bandIt, defaultPointer );
//startRasterRead( *bandIt, viewPort, theQgsMapToPixel, oversamplingX, oversamplingY );
}

void* redData = 0;
void* greenData = 0;
void* blueData = 0;
void* alphaData = 0;
//number of cols/rows in output pixels
int nCols = 0;
int nRows = 0;
//number of raster cols/rows with oversampling
int nRasterCols = 0;
int nRasterRows = 0;
//shift to top left point for the raster part
int topLeftCol = 0;
int topLeftRow = 0;

bool readSuccess = true;

//QSet<int>::const_iterator bandIt = bands.constBegin();

bandIt = bands.constBegin();
for ( ; bandIt != bands.constEnd(); ++bandIt )
{
//readSuccess = readSuccess && readNextRasterPart( *bandIt, oversamplingX, oversamplingY, viewPort, nCols, nRows,
// nRasterCols, nRasterRows, &bandData[*bandIt], topLeftCol, topLeftRow );
bandData[*bandIt] = mInput->readBlock( *bandIt, extent, width, height );
if ( !bandData[*bandIt] ) return 0;
}
@@ -81,38 +81,19 @@ QColor* QgsPalettedRasterRenderer::colors() const
return colorArray;
}

//void QgsPalettedRasterRenderer::draw( QPainter* p, QgsRasterViewPort* viewPort, const QgsMapToPixel* theQgsMapToPixel )
void * QgsPalettedRasterRenderer::readBlock( int bandNo, QgsRectangle const & extent, int width, int height )
{
if ( !mInput )
{
return 0;
}

//double oversamplingX, oversamplingY;
//QgsRasterFace::DataType transparencyType = QgsRasterFace::UnknownDataType;
//if ( mAlphaBand > 0 )
//{
//transparencyType = ( QgsRasterFace::DataType )mInput->dataType( mAlphaBand );
//}
//startRasterRead( mBandNumber, viewPort, theQgsMapToPixel, oversamplingX, oversamplingY );

////Read alpha band if necessary
//if ( mAlphaBand > 0 && mAlphaBand != mBandNumber )
//{
//startRasterRead( mAlphaBand, viewPort, theQgsMapToPixel, oversamplingX, oversamplingY );
//}

////number of cols/rows in output pixels
//int nCols = 0;
//int nRows = 0;
////number of raster cols/rows with oversampling
//int nRasterCols = 0;
//int nRasterRows = 0;
////shift to top left point for the raster part
//int topLeftCol = 0;
//int topLeftRow = 0;
//int currentRasterPos = 0;
QgsRasterFace::DataType transparencyType = QgsRasterFace::UnknownDataType;
if ( mAlphaBand > 0 )
{
transparencyType = ( QgsRasterFace::DataType )mInput->dataType( mAlphaBand );
}

QgsRasterFace::DataType rasterType = ( QgsRasterFace::DataType )mInput->dataType( mBandNumber );
void* rasterData = mInput->readBlock( bandNo, extent, width, height );
double currentOpacity = mOpacity;
@@ -123,15 +104,14 @@ void * QgsPalettedRasterRenderer::readBlock( int bandNo, QgsRectangle const & e
//bool hasTransparency = usesTransparency( viewPort->mSrcCRS, viewPort->mDestCRS );
void* transparencyData = 0;

//if ( mAlphaBand > 0 && mAlphaBand != mBandNumber )
//{
//readNextRasterPart( mAlphaBand, oversamplingX, oversamplingY, viewPort, nCols, nRows, nRasterCols, nRasterRows,
//&transparencyData, topLeftCol, topLeftRow );
//}
//else if ( mAlphaBand == mBandNumber )
//{
//transparencyData = rasterData;
//}
if ( mAlphaBand > 0 && mAlphaBand != mBandNumber )
{
transparencyData = mInput->readBlock( mAlphaBand, extent, width, height );
}
else if ( mAlphaBand == mBandNumber )
{
transparencyData = rasterData;
}

//create image
QImage img( width, height, QImage::Format_ARGB32_Premultiplied );
@@ -156,10 +136,10 @@ void * QgsPalettedRasterRenderer::readBlock( int bandNo, QgsRectangle const & e
{
currentOpacity = mRasterTransparency->alphaValue( val, mOpacity * 255 ) / 255.0;
}
//if ( mAlphaBand > 0 )
//{
//currentOpacity *= ( readValue( transparencyData, transparencyType, currentRasterPos ) / 255.0 );
//}
if ( mAlphaBand > 0 )
{
currentOpacity *= ( readValue( transparencyData, transparencyType, currentRasterPos ) / 255.0 );
}
QColor& currentColor = mColors[val];

if ( mInvertColor )
@@ -117,6 +117,7 @@ QgsRasterLayer::QgsRasterLayer(
, mWidth( std::numeric_limits<int>::max() )
, mHeight( std::numeric_limits<int>::max() )
, mRenderer( 0 )
, mResampleFilter( 0 )
{
QgsDebugMsg( "Entered" );

@@ -189,6 +190,7 @@ QgsRasterLayer::~QgsRasterLayer()
mValid = false;
delete mDataProvider;
delete mRenderer;
delete mResampleFilter;
}

//////////////////////////////////////////////////////////
@@ -824,8 +826,16 @@ void QgsRasterLayer::draw( QPainter * theQPainter,
if ( mRenderer )
{
//mRenderer->draw( theQPainter, theRasterViewPort, theQgsMapToPixel );
QgsRasterDrawer drawer( mRenderer );
//if ( mResampleFilter )
//{
QgsRasterDrawer drawer( mResampleFilter );
drawer.draw( theQPainter, theRasterViewPort, theQgsMapToPixel );
//}
//else
//{
// QgsRasterDrawer drawer( mRenderer );
// drawer.draw( theQPainter, theRasterViewPort, theQgsMapToPixel );
//}
}

QgsDebugMsg( QString( "raster draw time (ms): %1" ).arg( time.elapsed() ) );
@@ -2062,8 +2072,27 @@ void QgsRasterLayer::setTransparentBandName( QString const & )

void QgsRasterLayer::setRenderer( QgsRasterRenderer* renderer )
{
QgsDebugMsg( "Entered" );
delete mRenderer;
mRenderer = renderer;

if ( !mResampleFilter )
{
mResampleFilter = new QgsRasterResampleFilter( mRenderer );
}
else
{
mResampleFilter->setInput( mRenderer );
}
}

// not sure if we want it
void QgsRasterLayer::setResampleFilter( QgsRasterResampleFilter* resampleFilter )
{
QgsDebugMsg( "Entered" );
delete mResampleFilter;
mResampleFilter = resampleFilter;
mResampleFilter->setInput( mRenderer );
}

void QgsRasterLayer::showProgress( int theValue )
@@ -2233,6 +2262,60 @@ bool QgsRasterLayer::readSymbology( const QDomNode& layer_node, QString& errorMe
}
}
}

//resampler
delete mResampleFilter;
mResampleFilter = new QgsRasterResampleFilter( mRenderer );

//max oversampling
QDomElement resampleElem = layer_node.firstChildElement( "rasterresampler" );
if ( !resampleElem.isNull() )
{
mResampleFilter->readXML( resampleElem );
}
/*
if ( mResampleFilter )
{
QDomElement maxOversamplingElem = mnl.firstChildElement( "maxOversampling" );
if ( !maxOversamplingElem.isNull() )
{
bool conversion;
double maxOversampling = maxOversamplingElem.text().toDouble( &conversion );
if ( conversion )
{
mResampleFilter->setMaxOversampling( maxOversampling );
}
}
}
QDomElement zoomedInResamplerElem = mnl.firstChildElement( "zoomedInResampler" );
if ( mResampleFilter && !zoomedInResamplerElem.isNull() )
{
QgsRasterResampler* zoomedInResampler = 0;
QString zoomedInResamplerType = zoomedInResamplerElem.text();
if ( zoomedInResamplerType == "bilinear" )
{
zoomedInResampler = new QgsBilinearRasterResampler();
}
else if ( zoomedInResamplerType == "cubic" )
{
zoomedInResampler = new QgsCubicRasterResampler();
}
mResampleFilter->setZoomedInResampler( zoomedInResampler );
}
QDomElement zoomedOutResamplerElem = mnl.firstChildElement( "zoomedOutResampler" );
if ( mResampleFilter && !zoomedOutResamplerElem.isNull() )
{
QgsRasterResampler* zoomedOutResampler = 0;
QString zoomedOutResamplerType = zoomedOutResamplerElem.text();
if ( zoomedOutResamplerType == "bilinear" )
{
zoomedOutResampler = new QgsBilinearRasterResampler();
}
mResampleFilter->setZoomedOutResampler( zoomedOutResampler );
}
*/

return true;
} //readSymbology

@@ -2365,11 +2448,18 @@ bool QgsRasterLayer::writeSymbology( QDomNode & layer_node, QDomDocument & docum
{
Q_UNUSED( errorMessage );
QDomElement layerElem = layer_node.toElement();

if ( mRenderer )
{
mRenderer->writeXML( document, layerElem );
}

if ( mResampleFilter )
{
QDomElement layerElem = layer_node.toElement();
mResampleFilter->writeXML( document, layerElem );
}

return true;
} // bool QgsRasterLayer::writeSymbology

@@ -43,6 +43,7 @@
#include "qgsrastershaderfunction.h"
#include "qgsrasterface.h"
#include "qgsrasterdrawer.h"
#include "qgsrasterresamplefilter.h"
#include "qgsrasterdataprovider.h"

//
@@ -353,6 +354,11 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
const QgsRasterRenderer* renderer() const { return mRenderer; }
QgsRasterRenderer* renderer() { return mRenderer; }

/**Set raster resample filter. Takes ownership of the resample filter object*/
void setResampleFilter( QgsRasterResampleFilter* resampleFilter );
const QgsRasterResampleFilter* resampleFilter() const { return mResampleFilter; }
QgsRasterResampleFilter * resampleFilter() { return mResampleFilter; }

/** \brief Accessor to find out how many standard deviations are being plotted */
double standardDeviations() const { return mStandardDeviations; }

@@ -855,6 +861,7 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
bool mValidNoDataValue;

QgsRasterRenderer* mRenderer;
QgsRasterResampleFilter *mResampleFilter;
};

#endif

0 comments on commit 3f227c4

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