Skip to content

Commit 8dc45e4

Browse files
committedJan 2, 2012
Add single band color data renderer
1 parent be97ca4 commit 8dc45e4

File tree

4 files changed

+105
-1
lines changed

4 files changed

+105
-1
lines changed
 

‎src/core/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ SET(QGIS_CORE_SRCS
169169
raster/qgscubicrasterresampler.cpp
170170
raster/qgspalettedrasterrenderer.cpp
171171
raster/qgsmultibandcolorrenderer.cpp
172+
raster/qgssinglebandcolordatarenderer.cpp
172173
raster/qgssinglebandgrayrenderer.cpp
173174

174175
renderer/qgscontinuouscolorrenderer.cpp

‎src/core/raster/qgsrasterlayer.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ email : tim at linfiniti.com
4141
#include "qgsbilinearrasterresampler.h"
4242
#include "qgscubicrasterresampler.h"
4343
#include "qgsmultibandcolorrenderer.h"
44+
#include "qgssinglebandcolordatarenderer.h"
4445
#include "qgssinglebandgrayrenderer.h"
4546

4647
#include <cstdio>
@@ -151,6 +152,8 @@ QgsRasterLayer::QgsRasterLayer( int dummy,
151152
, mStyles( styles )
152153
, mFormat( format )
153154
, mCrs( crs )
155+
, mResampler( 0 )
156+
, mRenderer( 0 )
154157
{
155158
Q_UNUSED( dummy );
156159

@@ -840,7 +843,7 @@ void QgsRasterLayer::draw( QPainter * theQPainter,
840843
{
841844
mGrayMinimumMaximumEstimated = true;
842845
setMaximumValue( grayBand, mDataProvider->maximumValue( grayBand ) );
843-
setMinimumValue( grayBand, mDataProvider->minimumValue( grayBand ) );
846+
setMinimumValue( grayBand, mDataProvider->minimumValue( grayBand ) );
844847
}
845848
r.setContrastEnhancement( contrastEnhancement( grayBand ) );
846849
r.draw( theQPainter, theRasterViewPort, theQgsMapToPixel );
@@ -1017,8 +1020,12 @@ void QgsRasterLayer::draw( QPainter * theQPainter,
10171020
}
10181021
else
10191022
{
1023+
QgsSingleBandColorDataRenderer r( mDataProvider, bandNumber( mGrayBandName ), mResampler );
1024+
r.draw( theQPainter, theRasterViewPort, theQgsMapToPixel );
1025+
#if 0
10201026
drawSingleBandColorData( theQPainter, theRasterViewPort,
10211027
theQgsMapToPixel, bandNumber( mGrayBandName ) );
1028+
#endif //0
10221029
break;
10231030
}
10241031

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/***************************************************************************
2+
qgssinglebandcolordatarenderer.cpp
3+
----------------------------------
4+
begin : January 2012
5+
copyright : (C) 2012 by Marco Hugentobler
6+
email : marco at sourcepole dot ch
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
18+
#include "qgssinglebandcolordatarenderer.h"
19+
#include <QImage>
20+
21+
QgsSingleBandColorDataRenderer::QgsSingleBandColorDataRenderer( QgsRasterDataProvider* provider, int band, QgsRasterResampler* resampler ):
22+
QgsRasterRenderer( provider, resampler ), mBand( band )
23+
{
24+
25+
}
26+
27+
QgsSingleBandColorDataRenderer::~QgsSingleBandColorDataRenderer()
28+
{
29+
}
30+
31+
void QgsSingleBandColorDataRenderer::draw( QPainter* p, QgsRasterViewPort* viewPort, const QgsMapToPixel* theQgsMapToPixel )
32+
{
33+
if ( !p || !mProvider || !viewPort || !theQgsMapToPixel )
34+
{
35+
return;
36+
}
37+
38+
double oversamplingX, oversamplingY;
39+
startRasterRead( mBand, viewPort, theQgsMapToPixel, oversamplingX, oversamplingY );
40+
41+
int topLeftCol, topLeftRow, nCols, nRows, currentRasterPos;
42+
void* rasterData;
43+
44+
while ( readNextRasterPart( mBand, viewPort, nCols, nRows, &rasterData, topLeftCol, topLeftRow ) )
45+
{
46+
currentRasterPos = 0;
47+
QImage img( nCols, nRows, QImage::Format_ARGB32_Premultiplied );
48+
for ( int i = 0; i < nRows; ++i )
49+
{
50+
memcpy( img.scanLine( i ), &((( uint* )rasterData )[currentRasterPos] ), nCols * 4 );
51+
for ( int j = 0; j < nCols; ++j )
52+
{
53+
++currentRasterPos;
54+
}
55+
}
56+
57+
drawImage( p, viewPort, img, topLeftCol, topLeftRow, nCols, nRows, oversamplingX, oversamplingY );
58+
}
59+
60+
stopRasterRead( mBand );
61+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/***************************************************************************
2+
qgssinglebandcolordatarenderer.h
3+
--------------------------------
4+
begin : January 2012
5+
copyright : (C) 2012 by Marco Hugentobler
6+
email : marco at sourcepole dot ch
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
18+
#ifndef QGSSINGLEBANDCOLORDATARENDERER_H
19+
#define QGSSINGLEBANDCOLORDATARENDERER_H
20+
21+
#include "qgsrasterrenderer.h"
22+
23+
class QgsSingleBandColorDataRenderer: public QgsRasterRenderer
24+
{
25+
public:
26+
QgsSingleBandColorDataRenderer( QgsRasterDataProvider* provider, int band, QgsRasterResampler* resampler = 0 );
27+
~QgsSingleBandColorDataRenderer();
28+
29+
virtual void draw( QPainter* p, QgsRasterViewPort* viewPort, const QgsMapToPixel* theQgsMapToPixel );
30+
31+
private:
32+
int mBand;
33+
};
34+
35+
#endif // QGSSINGLEBANDCOLORDATARENDERER_H

0 commit comments

Comments
 (0)
Please sign in to comment.