Skip to content
Permalink
Browse files
-Cleaning out references to obsolete class QgsColorTable
-Changed how Paletted bands are drawn as gray scale
-Added cache to QgsColorRampShader to speed up rendering time when using large color tables (still poor)
-Fixed small bug in rendering the palette as a pixmap

git-svn-id: http://svn.osgeo.org/qgis/trunk@9251 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
ersts committed Sep 2, 2008
1 parent 61e0377 commit 767f4a3fb6d6fe84da324cc6744746a16e1a1faf
@@ -100,7 +100,7 @@ public:
void drawThumbnail(QPixmap * theQPixmap);

/** \brief Get an 8x8 pixmap of the colour palette. If the layer has no palette a white pixmap will be returned. */
QPixmap getPaletteAsPixmap();
QPixmap getPaletteAsPixmap(int theBand=1);

/** \brief This is called when the view on the rasterlayer needs to be refreshed (redrawn).
*/
@@ -498,7 +498,7 @@ public slots:
* \param band number
* \return pointer to color table
*/
QgsColorTable *colorTable ( int theBandNoInt );
QList<QgsColorRampShader::ColorRampItem>* getColorTable ( int theBandNoInt );
protected:

/** reads vector layer specific state from project file Dom node.
@@ -828,7 +828,7 @@ void QgsRasterLayerProperties::sync()
pixmapLegend->repaint();

//set the palette pixmap
pixmapPalette->setPixmap( mRasterLayer->getPaletteAsPixmap() );
pixmapPalette->setPixmap( mRasterLayer->getPaletteAsPixmap(mRasterLayer->getRasterBandNumber(mRasterLayer->getGrayBandName())));
pixmapPalette->setScaledContents( true );
pixmapPalette->repaint();

@@ -1971,7 +1971,7 @@ void QgsRasterLayerProperties::on_pbnHistRefresh_clicked()
== QgsRasterLayer::PALETTE ) //paletted layers have hard coded color entries
{
QPolygonF myPolygon;
QgsColorTable *myColorTable = mRasterLayer->colorTable( 1 );
QgsColorRampShader* myRasterShaderFunction = ( QgsColorRampShader* )mRasterLayer->getRasterShader()->getRasterShaderFunction();
QgsDebugMsg( "Making paletted image histogram....computing band stats" );
QgsDebugMsg( QString( "myLastBinWithData = %1" ).arg( myLastBinWithData ) );

@@ -2002,8 +2002,7 @@ void QgsRasterLayerProperties::on_pbnHistRefresh_clicked()

QgsDebugMsg( QString( "myMiddle = %1" ).arg( myMiddle ) );

bool found = myColorTable->color( myMiddle, &c1, &c2, &c3 );
if ( !found )
if ( myRasterShaderFunction->generateShadedValue(myMiddle, &c1, &c2, &c3))
{
QgsDebugMsg( "Color not found" );
c1 = c2 = c3 = 180; // grey
@@ -25,10 +25,22 @@ originally part of the larger QgsRasterLayer class
QgsColorRampShader::QgsColorRampShader( double theMinimumValue, double theMaximumValue ) : QgsRasterShaderFunction( theMinimumValue, theMaximumValue )
{
QgsDebugMsg( "called." );
mMaximumColorCacheSize = 256; //good starting value
}

bool QgsColorRampShader::generateShadedValue( double theValue, int* theReturnRedValue, int* theReturnGreenValue, int* theReturnBlueValue )
{
//Get the shaded from the cache if it exists already
QColor myColor = mColorCache.value(theValue);
if(myColor.isValid())
{
*theReturnRedValue = myColor.red();
*theReturnGreenValue = myColor.green();
*theReturnBlueValue = myColor.blue();
return true;
}

//Else we have to generate the shaded value
if ( QgsColorRampShader::INTERPOLATED == mColorRampType )
{
return getInterpolatedColor( theValue, theReturnRedValue, theReturnGreenValue, theReturnBlueValue );
@@ -81,15 +93,16 @@ bool QgsColorRampShader::getDiscreteColor( double theValue, int* theReturnRedVal
myCurrentRampValue = it->value;
if ( theValue <= myCurrentRampValue )
{
if ( last_it != mColorRampItemList.end() )
*theReturnRedValue = it->color.red();
*theReturnGreenValue = it->color.green();
*theReturnBlueValue = it->color.blue();
//Cache the shaded value
if(mMaximumColorCacheSize <= mColorCache.size())
{
*theReturnRedValue = last_it->color.red();
*theReturnGreenValue = last_it->color.green();
*theReturnBlueValue = last_it->color.blue();
return true;
mColorCache.insert(theValue, it->color);
}
return true;
}
last_it = it;
}

return false; // value not found
@@ -109,6 +122,11 @@ bool QgsColorRampShader::getExactColor( double theValue, int* theReturnRedValue,
*theReturnRedValue = it->color.red();
*theReturnGreenValue = it->color.green();
*theReturnBlueValue = it->color.blue();
//Cache the shaded value
if(mMaximumColorCacheSize <= mColorCache.size())
{
mColorCache.insert(theValue, it->color);
}
return true;
}
}
@@ -143,6 +161,11 @@ bool QgsColorRampShader::getInterpolatedColor( double theValue, int* theReturnRe
*theReturnRedValue = ( int )(( it->color.red() * myDiffTheValueLastRampValue + last_it->color.red() * myDiffCurrentRampValueTheValue ) / myCurrentRampRange );
*theReturnGreenValue = ( int )(( it->color.green() * myDiffTheValueLastRampValue + last_it->color.green() * myDiffCurrentRampValueTheValue ) / myCurrentRampRange );
*theReturnBlueValue = ( int )(( it->color.blue() * myDiffTheValueLastRampValue + last_it->color.blue() * myDiffCurrentRampValueTheValue ) / myCurrentRampRange );
//Cache the shaded value
if(mMaximumColorCacheSize <= mColorCache.size())
{
mColorCache.insert(theValue, it->color);
}
return true;
}
}
@@ -22,6 +22,7 @@ originally part of the larger QgsRasterLayer class
#define QGSCOLORRAMPSHADER_H

#include <QColor>
#include <QMap>

#include "qgsrastershaderfunction.h"

@@ -62,6 +63,9 @@ class CORE_EXPORT QgsColorRampShader : public QgsRasterShaderFunction
QgsColorRampShader::COLOR_RAMP_TYPE getColorRampType() {return mColorRampType;}
QString getColorRampTypeAsQString();

/**Get the maximum size the color cache can be*/
int getMaximumColorCacheSize() { return mMaximumColorCacheSize; }

/**Set custom colormap */
void setColorRampItemList( const QList<QgsColorRampShader::ColorRampItem>& theList ) { mColorRampItemList = theList; }

@@ -70,6 +74,9 @@ class CORE_EXPORT QgsColorRampShader : public QgsRasterShaderFunction

/**Set the color ramp type*/
void setColorRampType( QString );

/**Set the maximum size the color cache can be */
void setMaximumColorCacheSize(int theSize) { mMaximumColorCacheSize = theSize; }



@@ -85,6 +92,8 @@ class CORE_EXPORT QgsColorRampShader : public QgsRasterShaderFunction
QList<QgsColorRampShader::ColorRampItem> mColorRampItemList;

QgsColorRampShader::COLOR_RAMP_TYPE mColorRampType;
QMap<double, QColor> mColorCache;
int mMaximumColorCacheSize; //The color cache could eat a ton of memory if you have 32-bit data
};

#endif
@@ -24,7 +24,7 @@

#include <limits>

#include "qgscolortable.h"
#include "qgscolorrampshader.h"
/** \ingroup core
* The RasterBandStats struct is a container for statistics about a single
* raster band.
@@ -82,6 +82,6 @@ class CORE_EXPORT QgsRasterBandStats
/** whehter histogram compuation should include out of range values */
bool histogramOutOfRangeFlag;
/** Color table */
QgsColorTable colorTable;
QList<QgsColorRampShader::ColorRampItem> colorTable;
};
#endif

0 comments on commit 767f4a3

Please sign in to comment.