23 #define DOUBLE_DIFF_THRESHOLD 0.0 // 0.0000001 33 , mColorRampType( INTERPOLATED )
36 , mLUTInitialized( false )
44 switch ( mColorRampType )
47 return QString(
"INTERPOLATED" );
58 mColorRampItemList = theList.
toVector();
60 mLUTInitialized =
false;
66 mColorRampType = theColorRampType;
71 if ( theType ==
"INTERPOLATED" )
75 else if ( theType ==
"DISCRETE" )
81 mColorRampType =
EXACT;
85 bool QgsColorRampShader::shade(
double theValue,
int* theReturnRedValue,
int* theReturnGreenValue,
int* theReturnBlueValue,
int *theReturnAlphaValue )
87 if ( mColorRampItemList.
isEmpty() )
91 if ( qIsNaN( theValue ) || qIsInf( theValue ) )
94 int colorRampItemListCount = mColorRampItemList.
count();
96 if ( !mLUTInitialized )
103 if ( colorRampItemListCount >= 3 )
105 double rangeValue = mColorRampItemList.
at( colorRampItemListCount - 2 ).value -
minimumValue;
106 if ( rangeValue > 0 )
109 mLUTFactor = ( lutSize - 0.0000001 ) / rangeValue;
113 for (
int i = 0; i < lutSize; i++ )
115 val = ( i / mLUTFactor ) + mLUTOffset;
116 while ( idx < colorRampItemListCount
117 && mColorRampItemList.
at( idx ).value - DOUBLE_DIFF_THRESHOLD < val )
125 mLUTInitialized =
true;
130 bool overflow =
false;
133 int lutIndex = ( theValue - mLUTOffset ) * mLUTFactor;
134 if ( theValue < mLUTOffset )
138 else if ( lutIndex >= mLUT.
count() )
140 idx = colorRampItemListCount - 1;
149 idx = mLUT.
at( lutIndex );
153 while ( idx < colorRampItemListCount && mColorRampItemList.
at( idx ).value +
DOUBLE_DIFF_THRESHOLD < theValue )
157 if ( idx >= colorRampItemListCount )
159 idx = colorRampItemListCount - 1;
170 if ( mClip && ( overflow
175 *theReturnRedValue = currentColorRampItem.
color.
red();
176 *theReturnGreenValue = currentColorRampItem.
color.
green();
177 *theReturnBlueValue = currentColorRampItem.
color.
blue();
178 *theReturnAlphaValue = currentColorRampItem.
color.
alpha();
184 double currentRampRange = currentColorRampItem.
value - previousColorRampItem.
value;
185 double offsetInRange = theValue - previousColorRampItem.
value;
186 double scale = offsetInRange / currentRampRange;
188 *theReturnRedValue =
static_cast< int >(
static_cast< double >( previousColorRampItem.
color.
red() ) + ( static_cast< double >( currentColorRampItem.
color.
red() - previousColorRampItem.
color.
red() ) * scale ) );
189 *theReturnGreenValue =
static_cast< int >(
static_cast< double >( previousColorRampItem.
color.
green() ) + ( static_cast< double >( currentColorRampItem.
color.
green() - previousColorRampItem.
color.
green() ) * scale ) );
190 *theReturnBlueValue =
static_cast< int >(
static_cast< double >( previousColorRampItem.
color.
blue() ) + ( static_cast< double >( currentColorRampItem.
color.
blue() - previousColorRampItem.
color.
blue() ) * scale ) );
191 *theReturnAlphaValue =
static_cast< int >(
static_cast< double >( previousColorRampItem.
color.
alpha() ) + ( static_cast< double >( currentColorRampItem.
color.
alpha() - previousColorRampItem.
color.
alpha() ) * scale ) );
202 *theReturnRedValue = currentColorRampItem.
color.
red();
203 *theReturnGreenValue = currentColorRampItem.
color.
green();
204 *theReturnBlueValue = currentColorRampItem.
color.
blue();
205 *theReturnAlphaValue = currentColorRampItem.
color.
alpha();
212 *theReturnRedValue = currentColorRampItem.
color.
red();
213 *theReturnGreenValue = currentColorRampItem.
color.
green();
214 *theReturnBlueValue = currentColorRampItem.
color.
blue();
215 *theReturnAlphaValue = currentColorRampItem.
color.
alpha();
226 double theBlueValue,
double theAlphaValue,
227 int* theReturnRedValue,
int* theReturnGreenValue,
228 int* theReturnBlueValue,
int* theReturnAlphaValue )
230 Q_UNUSED( theRedValue );
231 Q_UNUSED( theGreenValue );
232 Q_UNUSED( theBlueValue );
233 Q_UNUSED( theAlphaValue );
235 *theReturnRedValue = 0;
236 *theReturnGreenValue = 0;
237 *theReturnBlueValue = 0;
238 *theReturnAlphaValue = 0;
246 for ( ; colorRampIt != mColorRampItemList.
constEnd(); ++colorRampIt )
248 symbolItems.push_back( qMakePair( colorRampIt->label, colorRampIt->color ) );
Assigns the color of the exact matching value in the color ramp item list.
QgsColorRampShader(double theMinimumValue=0.0, double theMaximumValue=255.0)
const_iterator constEnd() const
QVector< T > toVector() const
void setColorRampItemList(const QList< QgsColorRampShader::ColorRampItem > &theList)
Set custom colormap.
#define QgsDebugMsgLevel(str, level)
bool shade(double, int *, int *, int *, int *) override
Generates and new RGB value based on one input value.
The raster shade function applies a shader to a pixel at render time - typically used to render grays...
void legendSymbologyItems(QList< QPair< QString, QColor > > &symbolItems) const override
double minimumValue() const
void setColorRampType(QgsColorRampShader::ColorRamp_TYPE theColorRampType)
Set the color ramp type.
QString colorRampTypeAsQString()
Get the color ramp type as a string.
const T & at(int i) const
const_iterator constBegin() const
Interpolates the color between two class breaks linearly.
Assigns the color of the higher class for every pixel between two class breaks.
int count(const T &value) const
#define DOUBLE_DIFF_THRESHOLD
void push_back(const T &value)
ColorRamp_TYPE
Supported methods for color interpolation.