Skip to content

Commit

Permalink
Add single band color data renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Jan 2, 2012
1 parent be97ca4 commit 8dc45e4
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/core/CMakeLists.txt
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion src/core/raster/qgsrasterlayer.cpp
Expand Up @@ -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 <cstdio>
Expand Down Expand Up @@ -151,6 +152,8 @@ QgsRasterLayer::QgsRasterLayer( int dummy,
, mStyles( styles )
, mFormat( format )
, mCrs( crs )
, mResampler( 0 )
, mRenderer( 0 )
{
Q_UNUSED( dummy );

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

Expand Down
61 changes: 61 additions & 0 deletions 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 <QImage>

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 );
}
35 changes: 35 additions & 0 deletions 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

0 comments on commit 8dc45e4

Please sign in to comment.