Skip to content

Commit

Permalink
-Fixed issue with color ramp shader and doubles
Browse files Browse the repository at this point in the history
-Closes ticket #1497

git-svn-id: http://svn.osgeo.org/qgis/trunk@10271 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
ersts committed Mar 11, 2009
1 parent 707550a commit 8349cfd
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/core/raster/qgscolorrampshader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ originally part of the larger QgsRasterLayer class
* (at your option) any later version. *
* *
***************************************************************************/
#define REALLY_SMALL 0.0000001

#include "qgslogger.h"

#include "qgscolorrampshader.h"

#include <math.h>

QgsColorRampShader::QgsColorRampShader( double theMinimumValue, double theMaximumValue ) : QgsRasterShaderFunction( theMinimumValue, theMaximumValue )
{
QgsDebugMsg( "called." );
Expand Down Expand Up @@ -54,17 +57,19 @@ bool QgsColorRampShader::discreteColor( double theValue, int* theReturnRedValue,
return false;
}

double myTinyDiff = 0.0;
QgsColorRampShader::ColorRampItem myColorRampItem;
while ( mCurrentColorRampItemIndex >= 0 && mCurrentColorRampItemIndex < myColorRampItemCount )
{
//Start searching from the last index - assumtion is that neighboring pixels tend to be similar values
myColorRampItem = mColorRampItemList.value( mCurrentColorRampItemIndex );
myTinyDiff = fabs( theValue - myColorRampItem.value );
//If the previous entry is less, then search closer to the top of the list (assumes mColorRampItemList is sorted)
if ( mCurrentColorRampItemIndex != 0 && theValue <= mColorRampItemList.at( mCurrentColorRampItemIndex - 1 ).value )
{
mCurrentColorRampItemIndex--;
}
else if ( theValue <= myColorRampItem.value )
else if ( theValue <= myColorRampItem.value || myTinyDiff <= REALLY_SMALL )
{
*theReturnRedValue = myColorRampItem.color.red();
*theReturnGreenValue = myColorRampItem.color.green();
Expand Down Expand Up @@ -94,12 +99,14 @@ bool QgsColorRampShader::exactColor( double theValue, int* theReturnRedValue, in
return false;
}

double myTinyDiff = 0.0;
QgsColorRampShader::ColorRampItem myColorRampItem;
while ( mCurrentColorRampItemIndex >= 0 && mCurrentColorRampItemIndex < myColorRampItemCount )
{
//Start searching from the last index - assumtion is that neighboring pixels tend to be similar values
myColorRampItem = mColorRampItemList.value( mCurrentColorRampItemIndex );
if ( theValue == myColorRampItem.value )
myTinyDiff = fabs( theValue - myColorRampItem.value );
if ( theValue == myColorRampItem.value || myTinyDiff <= REALLY_SMALL )
{
*theReturnRedValue = myColorRampItem.color.red();
*theReturnGreenValue = myColorRampItem.color.green();
Expand Down Expand Up @@ -133,26 +140,27 @@ bool QgsColorRampShader::exactColor( double theValue, int* theReturnRedValue, in

bool QgsColorRampShader::interpolatedColor( double theValue, int* theReturnRedValue, int* theReturnGreenValue, int* theReturnBlueValue )
{

int myColorRampItemCount = mColorRampItemList.count();
if ( myColorRampItemCount <= 0 )
{
return false;
}

double myTinyDiff = 0.0;
double myCurrentRampRange; //difference between two consecutive entry values
double myOffsetInRange; //difference between the previous entry value and value
QgsColorRampShader::ColorRampItem myColorRampItem;
while ( mCurrentColorRampItemIndex >= 0 && mCurrentColorRampItemIndex < myColorRampItemCount )
{
//Start searching from the last index - assumtion is that neighboring pixels tend to be similar values
myColorRampItem = mColorRampItemList.value( mCurrentColorRampItemIndex );
myTinyDiff = fabs( theValue - myColorRampItem.value );
//If the previous entry is less, then search closer to the top of the list (assumes mColorRampItemList is sorted)
if ( mCurrentColorRampItemIndex != 0 && theValue <= mColorRampItemList.at( mCurrentColorRampItemIndex - 1 ).value )
{
mCurrentColorRampItemIndex--;
}
else if ( mCurrentColorRampItemIndex != 0 && theValue <= myColorRampItem.value )
else if ( mCurrentColorRampItemIndex != 0 && ( theValue <= myColorRampItem.value || myTinyDiff <= REALLY_SMALL ) )
{
QgsColorRampShader::ColorRampItem myPreviousColorRampItem = mColorRampItemList.value( mCurrentColorRampItemIndex - 1 );
myCurrentRampRange = myColorRampItem.value - myPreviousColorRampItem.value;
Expand Down

0 comments on commit 8349cfd

Please sign in to comment.