Skip to content
Permalink
Browse files

-Fixed issue with color ramp shader and doubles

-Closes ticket #1497

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@10271 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
ersts
ersts committed Mar 11, 2009
1 parent eed9011 commit 62787bc17926ce50b9aa0e0fa0a381e5822f8bdb
Showing with 12 additions and 4 deletions.
  1. +12 −4 src/core/raster/qgscolorrampshader.cpp
@@ -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." );
@@ -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();
@@ -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();
@@ -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;

0 comments on commit 62787bc

Please sign in to comment.
You can’t perform that action at this time.