Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Consider invert color flag
  • Loading branch information
mhugent committed Dec 29, 2011
1 parent b33f24f commit 5344b2a
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 7 deletions.
9 changes: 8 additions & 1 deletion src/core/raster/qgsmultibandcolorrenderer.cpp
Expand Up @@ -25,7 +25,7 @@
#include <QSet>

QgsMultiBandColorRenderer::QgsMultiBandColorRenderer( QgsRasterDataProvider* provider, int redBand, int greenBand, int blueBand, QgsRasterResampler* resampler ):
QgsRasterRenderer( provider, resampler ), mRedBand( redBand ), mGreenBand( greenBand ), mBlueBand( blueBand )
QgsRasterRenderer( provider, resampler ), mRedBand( redBand ), mGreenBand( greenBand ), mBlueBand( blueBand ), mContrastEnhancement( 0 )
{
}

Expand Down Expand Up @@ -109,6 +109,13 @@ void QgsMultiBandColorRenderer::draw( QPainter* p, QgsRasterViewPort* viewPort,
greenVal = readValue( greenData, greenType, currentRasterPos );
blueVal = readValue( blueData, blueType, currentRasterPos );

if ( mInvertColor )
{
redVal = 255 - redVal;
greenVal = 255 - greenVal;
blueVal = 255 - blueVal;
}

//opacity
currentOpacity = mOpacity;
if ( mRasterTransparency )
Expand Down
7 changes: 7 additions & 0 deletions src/core/raster/qgsmultibandcolorrenderer.h
Expand Up @@ -20,6 +20,8 @@

#include "qgsrasterrenderer.h"

class QgsContrastEnhancement;

/**Renderer for multiband images with the color components*/
class QgsMultiBandColorRenderer: public QgsRasterRenderer
{
Expand All @@ -29,10 +31,15 @@ class QgsMultiBandColorRenderer: public QgsRasterRenderer

void draw( QPainter* p, QgsRasterViewPort* viewPort, const QgsMapToPixel* theQgsMapToPixel );

const QgsContrastEnhancement* contrastEnhancement() const { return mContrastEnhancement; }
void setContrastEnhancement( QgsContrastEnhancement* ce ) { mContrastEnhancement = ce; }

private:
int mRedBand;
int mGreenBand;
int mBlueBand;

QgsContrastEnhancement* mContrastEnhancement;
};

#endif // QGSMULTIBANDCOLORRENDERER_H
10 changes: 9 additions & 1 deletion src/core/raster/qgspalettedrasterrenderer.cpp
Expand Up @@ -108,7 +108,15 @@ void QgsPalettedRasterRenderer::draw( QPainter* p, QgsRasterViewPort* viewPort,
currentOpacity *= ( readValue( transparencyData, transparencyType, currentRasterPos ) / 255.0 );
}
QColor& currentColor = mColors[val];
imageScanLine[j] = qRgba( currentOpacity * currentColor.red(), currentOpacity * currentColor.green(), currentOpacity * currentColor.blue(), currentOpacity * 255 );

if ( mInvertColor )
{
imageScanLine[j] = qRgba( currentOpacity * currentColor.blue(), currentOpacity * currentColor.green(), currentOpacity * currentColor.red(), currentOpacity * 255 );
}
else
{
imageScanLine[j] = qRgba( currentOpacity * currentColor.red(), currentOpacity * currentColor.green(), currentOpacity * currentColor.blue(), currentOpacity * 255 );
}
}
++currentRasterPos;
}
Expand Down
3 changes: 2 additions & 1 deletion src/core/raster/qgsrasterlayer.cpp
Expand Up @@ -865,6 +865,7 @@ void QgsRasterLayer::draw( QPainter * theQPainter,
renderer.setAlphaBand( tBandNr );
}
}
renderer.setInvertColor( mInvertColor );
renderer.draw( theQPainter, theRasterViewPort, theQgsMapToPixel );
#if 0
drawPalettedSingleBandColor( theQPainter, theRasterViewPort,
Expand Down Expand Up @@ -968,7 +969,7 @@ void QgsRasterLayer::draw( QPainter * theQPainter,
r.setAlphaBand( tBandNr );
}
}

r.setInvertColor( mInvertColor );
r.draw( theQPainter, theRasterViewPort, theQgsMapToPixel );
#if 0
drawMultiBandColor( theQPainter, theRasterViewPort,
Expand Down
6 changes: 3 additions & 3 deletions src/core/raster/qgsrasterrenderer.cpp
Expand Up @@ -70,9 +70,9 @@ void QgsRasterRenderer::startRasterRead( int bandNumber, QgsRasterViewPort* view

int totalMemoryUsage = pInfo.nCols * pInfo.nRows * mProvider->dataTypeSize( bandNumber );
int parts = totalMemoryUsage / 100000 + 1;
pInfo.nPartsPerDimension = sqrt( parts );
pInfo.nColsPerPart = floor( pInfo.nCols / pInfo.nPartsPerDimension / oversamplingX ) * oversamplingX;
pInfo.nRowsPerPart = floor( pInfo.nRows / pInfo.nPartsPerDimension / oversamplingY ) * oversamplingY;
int nPartsPerDimension = sqrt( parts );
pInfo.nColsPerPart = floor( pInfo.nCols / nPartsPerDimension / oversamplingX ) * oversamplingX;
pInfo.nRowsPerPart = floor( pInfo.nRows / nPartsPerDimension / oversamplingY ) * oversamplingY;
pInfo.currentCol = 0;
pInfo.currentRow = 0;
pInfo.data = 0;
Expand Down
1 change: 0 additions & 1 deletion src/core/raster/qgsrasterrenderer.h
Expand Up @@ -38,7 +38,6 @@ class QgsRasterRenderer
int nRows;
int nColsPerPart;
int nRowsPerPart;
int nPartsPerDimension;
void* data;
};

Expand Down

0 comments on commit 5344b2a

Please sign in to comment.