20 #define DOUBLE_DIFF_THRESHOLD 0.0000001
40 return QString(
"INTERPOLATED" );
43 return QString(
"DISCRETE" );
46 return QString(
"EXACT" );
49 return QString(
"Unknown" );
55 if ( myColorRampItemCount <= 0 )
60 double myTinyDiff = 0.0;
66 myTinyDiff = qAbs( theValue - myColorRampItem.
value );
75 *theReturnRedValue = myColorRampItem.
color.red();
76 *theReturnGreenValue = myColorRampItem.
color.green();
77 *theReturnBlueValue = myColorRampItem.
color.blue();
78 *theReturnAlphaValue = myColorRampItem.
color.alpha();
99 if ( myColorRampItemCount <= 0 )
104 double myTinyDiff = 0.0;
110 myTinyDiff = qAbs( theValue - myColorRampItem.
value );
113 *theReturnRedValue = myColorRampItem.
color.red();
114 *theReturnGreenValue = myColorRampItem.
color.green();
115 *theReturnBlueValue = myColorRampItem.
color.blue();
116 *theReturnAlphaValue = myColorRampItem.
color.alpha();
132 else if ( theValue > myColorRampItem.
value )
147 theReturnRedValue,
int* theReturnGreenValue,
int* theReturnBlueValue ,
int* theReturnAlphaValue )
150 if ( myColorRampItemCount <= 0 )
155 double myTinyDiff = 0.0;
156 double myCurrentRampRange;
157 double myOffsetInRange;
163 myTinyDiff = qAbs( theValue - myColorRampItem.
value );
172 myCurrentRampRange = myColorRampItem.
value - myPreviousColorRampItem.
value;
173 myOffsetInRange = theValue - myPreviousColorRampItem.
value;
174 double scale = myOffsetInRange / myCurrentRampRange;
176 *theReturnRedValue = ( int )((
double ) myPreviousColorRampItem.
color.red() + (( double )( myColorRampItem.
color.red() - myPreviousColorRampItem.
color.red() ) * scale ) ) ;
177 *theReturnGreenValue = ( int )((
double ) myPreviousColorRampItem.
color.green() + (( double )( myColorRampItem.
color.green() - myPreviousColorRampItem.
color.green() ) * scale ) );
178 *theReturnBlueValue = ( int )((
double ) myPreviousColorRampItem.
color.blue() + (( double )( myColorRampItem.
color.blue() - myPreviousColorRampItem.
color.blue() ) * scale ) );
179 *theReturnAlphaValue = ( int )((
double ) myPreviousColorRampItem.
color.alpha() + (( double )( myColorRampItem.
color.alpha() - myPreviousColorRampItem.
color.alpha() ) * scale ) );
182 QColor myNewColor( *theReturnRedValue, *theReturnGreenValue, *theReturnBlueValue, *theReturnAlphaValue );
195 *theReturnRedValue = myColorRampItem.
color.red();
196 *theReturnGreenValue = myColorRampItem.
color.green();
197 *theReturnBlueValue = myColorRampItem.
color.blue();
198 *theReturnAlphaValue = myColorRampItem.
color.alpha();
201 QColor myNewColor( *theReturnRedValue, *theReturnGreenValue, *theReturnBlueValue, *theReturnAlphaValue );
207 else if ( theValue > myColorRampItem.
value )
238 if ( theType ==
"INTERPOLATED" )
242 else if ( theType ==
"DISCRETE" )
252 bool QgsColorRampShader::shade(
double theValue,
int* theReturnRedValue,
int* theReturnGreenValue,
int* theReturnBlueValue ,
int *theReturnAlphaValue )
257 if ( myColor.isValid() )
259 *theReturnRedValue = myColor.red();
260 *theReturnGreenValue = myColor.green();
261 *theReturnBlueValue = myColor.blue();
262 *theReturnAlphaValue = myColor.alpha();
280 return exactColor( theValue, theReturnRedValue, theReturnGreenValue, theReturnBlueValue, theReturnAlphaValue );
284 return interpolatedColor( theValue, theReturnRedValue, theReturnGreenValue, theReturnBlueValue, theReturnAlphaValue );
287 return discreteColor( theValue, theReturnRedValue, theReturnGreenValue, theReturnBlueValue, theReturnAlphaValue );
291 double theBlueValue,
double theAlphaValue,
int* theReturnRedValue,
int* theReturnGreenValue,
int*
292 theReturnBlueValue ,
int* theReturnAlphaValue )
294 Q_UNUSED( theRedValue );
295 Q_UNUSED( theGreenValue );
296 Q_UNUSED( theBlueValue );
297 Q_UNUSED( theAlphaValue );
299 *theReturnRedValue = 0;
300 *theReturnGreenValue = 0;
301 *theReturnBlueValue = 0;
302 *theReturnAlphaValue = 0;
309 QList<QgsColorRampShader::ColorRampItem>::const_iterator colorRampIt =
mColorRampItemList.constBegin();
312 symbolItems.push_back( qMakePair( colorRampIt->label, colorRampIt->color ) );