28 #include <QDomDocument>
29 #include <QDomElement>
34 mContrastEnhancementFunction = 0;
35 mEnhancementDirty =
false;
37 mRasterDataType = theDataType;
41 mRasterDataTypeRange = mMaximumValue - mMinimumValue;
43 mLookupTableOffset = mMinimumValue * -1;
48 if ( mRasterDataTypeRange <= 65535.0 )
50 mLookupTable =
new int[static_cast <
int>( mRasterDataTypeRange+1 )];
58 mContrastEnhancementFunction = 0;
59 mEnhancementDirty =
true;
60 mRasterDataType = ce.mRasterDataType;
62 mMinimumValue = ce.mMinimumValue;
63 mMaximumValue = ce.mMaximumValue;
64 mRasterDataTypeRange = ce.mRasterDataTypeRange;
72 if ( mRasterDataTypeRange <= 65535.0 )
74 mLookupTable =
new int[static_cast <
int>( mRasterDataTypeRange+1 )];
80 delete [] mLookupTable;
81 delete mContrastEnhancementFunction;
94 switch ( theDataType )
143 switch ( theDataType )
200 if ( mEnhancementDirty )
202 generateLookupTable();
205 if ( mLookupTable &&
NoEnhancement != mContrastEnhancementAlgorithm )
207 return mLookupTable[static_cast <
int>( theValue + mLookupTableOffset )];
214 return mContrastEnhancementFunction->
enhance( theValue );
221 bool QgsContrastEnhancement::generateLookupTable()
223 mEnhancementDirty =
false;
225 if ( !mContrastEnhancementFunction )
240 for (
int myIterator = 0; myIterator <= mRasterDataTypeRange; myIterator++ )
242 mLookupTable[myIterator] = mContrastEnhancementFunction->
enhance((
double )myIterator - mLookupTableOffset );
256 if ( 0 != mContrastEnhancementFunction )
274 if ( theAlgorithm != mContrastEnhancementAlgorithm )
276 switch ( theAlgorithm )
279 delete mContrastEnhancementFunction;
283 delete mContrastEnhancementFunction;
287 delete mContrastEnhancementFunction;
294 delete mContrastEnhancementFunction;
299 mEnhancementDirty =
true;
300 mContrastEnhancementAlgorithm = theAlgorithm;
304 generateLookupTable();
318 if ( 0 != theFunction )
320 delete mContrastEnhancementFunction;
321 mContrastEnhancementFunction = theFunction;
323 generateLookupTable();
343 mMaximumValue = theValue;
346 if ( 0 != mContrastEnhancementFunction )
351 mEnhancementDirty =
true;
355 generateLookupTable();
375 mMinimumValue = theValue;
378 if ( 0 != mContrastEnhancementFunction )
383 mEnhancementDirty =
true;
387 generateLookupTable();
415 if ( !minValueElem.
isNull() )
420 if ( !maxValueElem.
isNull() )
425 if ( !algorithmElem.
isNull() )
430 if ( algorithmString ==
"0" )
434 else if ( algorithmString ==
"1" )
438 else if ( algorithmString ==
"2" )
442 else if ( algorithmString ==
"3" )
446 else if ( algorithmString ==
"4" )
464 return "NoEnhancement";
466 return "StretchToMinimumMaximum";
468 return "StretchAndClipToMinimumMaximum";
470 return "ClipToMinimumMaximum";
472 return "UserDefinedEnhancement";
474 return "NoEnhancement";
479 if ( contrastEnhancementString ==
"StretchToMinimumMaximum" )
483 else if ( contrastEnhancementString ==
"StretchAndClipToMinimumMaximum" )
487 else if ( contrastEnhancementString ==
"ClipToMinimumMaximum" )
491 else if ( contrastEnhancementString ==
"UserDefinedEnhancement" )
Sixty four bit floating point (double)
~QgsContrastEnhancement()
void setContrastEnhancementAlgorithm(ContrastEnhancementAlgorithm, bool generateTable=true)
Set the contrast enhancement algorithm.
void writeXML(QDomDocument &doc, QDomElement &parentElem) const
Sixteen bit signed integer (qint16)
void readXML(const QDomElement &elem)
QDomNode appendChild(const QDomNode &newChild)
Eight bit unsigned integer (quint8)
Sixteen bit unsigned integer (quint16)
bool isValueInDisplayableRange(double)
Return true if pixel is in stretable range, false if pixel is outside of range (i.e., clipped)
static double maximumValuePossible(QGis::DataType)
Helper function that returns the maximum possible value for a GDAL data type.
double toDouble(bool *ok) const
ContrastEnhancementAlgorithm
This enumerator describes the types of contrast enhancement algorithms that can be used...
double ANALYSIS_EXPORT max(double x, double y)
Returns the maximum of two doubles or the first argument if both are equal.
void setContrastEnhancementFunction(QgsContrastEnhancementFunction *)
A public method that allows the user to set their own custom contrast enhancment function.
void setMinimumValue(double)
Mutator for the minimum value.
QString number(int n, int base)
static double minimumValuePossible(QGis::DataType)
Helper function that returns the minimum possible value for a GDAL data type.
Thirty two bit floating point (float)
A linear enhanceContrast enhancement that first clips to min max and then enhanceContrastes linearly ...
void setMinimumValue(double, bool generateTable=true)
Return the minimum value for the contrast enhancement range.
static QString contrastEnhancementAlgorithmString(ContrastEnhancementAlgorithm algorithm)
A contrast enhancement funcion is the base class for all raster contrast enhancements.
DataType
Raster data types.
A color enhancement function that performs a linear enhanceContrast between min and max...
QDomText createTextNode(const QString &value)
QgsContrastEnhancement(QGis::DataType theDatatype=QGis::Byte)
static ContrastEnhancementAlgorithm contrastEnhancementAlgorithmFromString(const QString &contrastEnhancementString)
A raster contrast enhancement that will clip a value to the specified min/max range.
Thirty two bit signed integer (qint32)
int enhanceContrast(double)
Apply the contrast enhancement to a value.
Unknown or unspecified type.
QDomElement firstChildElement(const QString &tagName) const
virtual int enhance(double)
A customizable method that takes in a double and returns a int between 0 and 255. ...
virtual bool isValueInDisplayableRange(double)
A customicable method to indicate if the pixels is displayable.
Manipulates raster pixel values so that they enhanceContrast or clip into a specified numerical range...
double ANALYSIS_EXPORT min(double x, double y)
Returns the minimum of two doubles or the first argument if both are equal.
QDomElement createElement(const QString &tagName)
Color, alpha, red, green, blue, 4 bytes the same as QImage::Format_ARGB32.
Color, alpha, red, green, blue, 4 bytes the same as QImage::Format_ARGB32_Premultiplied.
void setMaximumValue(double, bool generateTable=true)
Set the maximum value for the contrast enhancement range.
Thirty two bit unsigned integer (quint32)
void setMaximumValue(double)
Mustator for the maximum value.