diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 5317572d658e..0849ed549f02 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -169,6 +169,7 @@ SET(QGIS_CORE_SRCS raster/qgscubicrasterresampler.cpp raster/qgspalettedrasterrenderer.cpp raster/qgsmultibandcolorrenderer.cpp + raster/qgssinglebandcolordatarenderer.cpp raster/qgssinglebandgrayrenderer.cpp renderer/qgscontinuouscolorrenderer.cpp diff --git a/src/core/raster/qgsrasterlayer.cpp b/src/core/raster/qgsrasterlayer.cpp index f6466cacbe1f..30e9693b1633 100644 --- a/src/core/raster/qgsrasterlayer.cpp +++ b/src/core/raster/qgsrasterlayer.cpp @@ -41,6 +41,7 @@ email : tim at linfiniti.com #include "qgsbilinearrasterresampler.h" #include "qgscubicrasterresampler.h" #include "qgsmultibandcolorrenderer.h" +#include "qgssinglebandcolordatarenderer.h" #include "qgssinglebandgrayrenderer.h" #include @@ -151,6 +152,8 @@ QgsRasterLayer::QgsRasterLayer( int dummy, , mStyles( styles ) , mFormat( format ) , mCrs( crs ) + , mResampler( 0 ) + , mRenderer( 0 ) { Q_UNUSED( dummy ); @@ -840,7 +843,7 @@ void QgsRasterLayer::draw( QPainter * theQPainter, { mGrayMinimumMaximumEstimated = true; setMaximumValue( grayBand, mDataProvider->maximumValue( grayBand ) ); - setMinimumValue( grayBand, mDataProvider->minimumValue( grayBand ) ); + setMinimumValue( grayBand, mDataProvider->minimumValue( grayBand ) ); } r.setContrastEnhancement( contrastEnhancement( grayBand ) ); r.draw( theQPainter, theRasterViewPort, theQgsMapToPixel ); @@ -1017,8 +1020,12 @@ void QgsRasterLayer::draw( QPainter * theQPainter, } else { + QgsSingleBandColorDataRenderer r( mDataProvider, bandNumber( mGrayBandName ), mResampler ); + r.draw( theQPainter, theRasterViewPort, theQgsMapToPixel ); +#if 0 drawSingleBandColorData( theQPainter, theRasterViewPort, theQgsMapToPixel, bandNumber( mGrayBandName ) ); +#endif //0 break; } diff --git a/src/core/raster/qgssinglebandcolordatarenderer.cpp b/src/core/raster/qgssinglebandcolordatarenderer.cpp new file mode 100644 index 000000000000..445647d1c3b0 --- /dev/null +++ b/src/core/raster/qgssinglebandcolordatarenderer.cpp @@ -0,0 +1,61 @@ +/*************************************************************************** + qgssinglebandcolordatarenderer.cpp + ---------------------------------- + begin : January 2012 + copyright : (C) 2012 by Marco Hugentobler + email : marco at sourcepole dot ch + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include "qgssinglebandcolordatarenderer.h" +#include + +QgsSingleBandColorDataRenderer::QgsSingleBandColorDataRenderer( QgsRasterDataProvider* provider, int band, QgsRasterResampler* resampler ): + QgsRasterRenderer( provider, resampler ), mBand( band ) +{ + +} + +QgsSingleBandColorDataRenderer::~QgsSingleBandColorDataRenderer() +{ +} + +void QgsSingleBandColorDataRenderer::draw( QPainter* p, QgsRasterViewPort* viewPort, const QgsMapToPixel* theQgsMapToPixel ) +{ + if ( !p || !mProvider || !viewPort || !theQgsMapToPixel ) + { + return; + } + + double oversamplingX, oversamplingY; + startRasterRead( mBand, viewPort, theQgsMapToPixel, oversamplingX, oversamplingY ); + + int topLeftCol, topLeftRow, nCols, nRows, currentRasterPos; + void* rasterData; + + while ( readNextRasterPart( mBand, viewPort, nCols, nRows, &rasterData, topLeftCol, topLeftRow ) ) + { + currentRasterPos = 0; + QImage img( nCols, nRows, QImage::Format_ARGB32_Premultiplied ); + for ( int i = 0; i < nRows; ++i ) + { + memcpy( img.scanLine( i ), &((( uint* )rasterData )[currentRasterPos] ), nCols * 4 ); + for ( int j = 0; j < nCols; ++j ) + { + ++currentRasterPos; + } + } + + drawImage( p, viewPort, img, topLeftCol, topLeftRow, nCols, nRows, oversamplingX, oversamplingY ); + } + + stopRasterRead( mBand ); +} diff --git a/src/core/raster/qgssinglebandcolordatarenderer.h b/src/core/raster/qgssinglebandcolordatarenderer.h new file mode 100644 index 000000000000..ed7e5f61174a --- /dev/null +++ b/src/core/raster/qgssinglebandcolordatarenderer.h @@ -0,0 +1,35 @@ +/*************************************************************************** + qgssinglebandcolordatarenderer.h + -------------------------------- + begin : January 2012 + copyright : (C) 2012 by Marco Hugentobler + email : marco at sourcepole dot ch + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef QGSSINGLEBANDCOLORDATARENDERER_H +#define QGSSINGLEBANDCOLORDATARENDERER_H + +#include "qgsrasterrenderer.h" + +class QgsSingleBandColorDataRenderer: public QgsRasterRenderer +{ + public: + QgsSingleBandColorDataRenderer( QgsRasterDataProvider* provider, int band, QgsRasterResampler* resampler = 0 ); + ~QgsSingleBandColorDataRenderer(); + + virtual void draw( QPainter* p, QgsRasterViewPort* viewPort, const QgsMapToPixel* theQgsMapToPixel ); + + private: + int mBand; +}; + +#endif // QGSSINGLEBANDCOLORDATARENDERER_H