Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
158 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/*************************************************************************** | ||
qgssinglebandgrayrenderer.cpp | ||
----------------------------- | ||
begin : December 2011 | ||
copyright : (C) 2011 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 "qgssinglebandgrayrenderer.h" | ||
#include "qgscontrastenhancement.h" | ||
#include "qgsrasterresampler.h" | ||
#include "qgsrasterviewport.h" | ||
#include <QImage> | ||
#include <QPainter> | ||
|
||
QgsSingleBandGrayRenderer::QgsSingleBandGrayRenderer( QgsRasterDataProvider* provider, int grayBand, QgsRasterResampler* resampler ): | ||
QgsRasterRenderer( provider, resampler ), mGrayBand( grayBand ), mContrastEnhancement( 0 ) | ||
{ | ||
} | ||
|
||
QgsSingleBandGrayRenderer::~QgsSingleBandGrayRenderer() | ||
{ | ||
} | ||
|
||
void QgsSingleBandGrayRenderer::draw( QPainter* p, QgsRasterViewPort* viewPort, const QgsMapToPixel* theQgsMapToPixel ) | ||
{ | ||
if ( !p || !mProvider || !viewPort || !theQgsMapToPixel ) | ||
{ | ||
return; | ||
} | ||
|
||
double oversamplingX, oversamplingY; | ||
startRasterRead( mGrayBand, viewPort, theQgsMapToPixel, oversamplingX, oversamplingY ); | ||
|
||
int nCols = 0; | ||
int nRows = 0; | ||
int topLeftCol = 0; | ||
int topLeftRow = 0; | ||
QgsRasterDataProvider::DataType rasterType = ( QgsRasterDataProvider::DataType )mProvider->dataType( mGrayBand ); | ||
void* rasterData; | ||
//double currentOpacity = mOpacity; | ||
int grayVal; | ||
|
||
while ( readNextRasterPart( mGrayBand, viewPort, nCols, nRows, &rasterData, topLeftCol, topLeftRow ) ) | ||
{ | ||
//create image | ||
QImage img( nCols, nRows, QImage::Format_ARGB32_Premultiplied ); | ||
QRgb* imageScanLine = 0; | ||
int currentRasterPos = 0; | ||
|
||
for ( int i = 0; i < nRows; ++i ) | ||
{ | ||
imageScanLine = ( QRgb* )( img.scanLine( i ) ); | ||
for ( int j = 0; j < nCols; ++j ) | ||
{ | ||
grayVal = readValue( rasterData, rasterType, currentRasterPos ); | ||
if ( mContrastEnhancement ) | ||
{ | ||
grayVal = mContrastEnhancement->enhanceContrast( grayVal ); | ||
} | ||
|
||
if ( mInvertColor ) | ||
{ | ||
grayVal = 255 - grayVal; | ||
} | ||
|
||
imageScanLine[j] = qRgba( grayVal, grayVal, grayVal, 255 ); | ||
++currentRasterPos; | ||
} | ||
} | ||
|
||
//draw image | ||
//top left position in device coords | ||
QPointF tlPoint = QPointF( viewPort->topLeftPoint.x(), viewPort->topLeftPoint.y() ); | ||
tlPoint += QPointF( topLeftCol / oversamplingX, topLeftRow / oversamplingY ); | ||
|
||
if ( mResampler ) //resample to output resolution | ||
{ | ||
QImage dstImg( nCols / oversamplingX + 1.0, nRows / oversamplingY + 1.0, QImage::Format_ARGB32_Premultiplied ); | ||
mResampler->resample( img, dstImg ); | ||
p->drawImage( tlPoint, dstImg ); | ||
} | ||
else //use original image | ||
{ | ||
p->drawImage( tlPoint, img ); | ||
} | ||
} | ||
|
||
stopRasterRead( mGrayBand ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/*************************************************************************** | ||
qgssinglebandgrayrenderer.h | ||
--------------------------- | ||
begin : December 2011 | ||
copyright : (C) 2011 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 QGSSINGLEBANDGRAYRENDERER_H | ||
#define QGSSINGLEBANDGRAYRENDERER_H | ||
|
||
#include "qgsrasterrenderer.h" | ||
|
||
class QgsContrastEnhancement; | ||
|
||
class QgsSingleBandGrayRenderer: public QgsRasterRenderer | ||
{ | ||
public: | ||
QgsSingleBandGrayRenderer( QgsRasterDataProvider* provider, int grayBand, QgsRasterResampler* resampler = 0 ); | ||
~QgsSingleBandGrayRenderer(); | ||
|
||
virtual void draw( QPainter* p, QgsRasterViewPort* viewPort, const QgsMapToPixel* theQgsMapToPixel ); | ||
|
||
const QgsContrastEnhancement* contrastEnhancement() const { return mContrastEnhancement; } | ||
void setContrastEnhancement( QgsContrastEnhancement* ce ) { mContrastEnhancement = ce; } | ||
|
||
private: | ||
int mGrayBand; | ||
QgsContrastEnhancement* mContrastEnhancement; | ||
}; | ||
|
||
#endif // QGSSINGLEBANDGRAYRENDERER_H |