1 /*************************************************************************** 2 qgsbrightnesscontrastfilter.h 3 ------------------- 4 begin : February 2013 5 copyright : (C) 2013 by Alexander Bruy 6 email : alexander dot bruy at gmail dot com 7 ***************************************************************************/ 8 9 /*************************************************************************** 10 * * 11 * This program is free software; you can redistribute it and/or modify * 12 * it under the terms of the GNU General Public License as published by * 13 * the Free Software Foundation; either version 2 of the License, or * 14 * (at your option) any later version. * 15 * * 16 ***************************************************************************/ 17 18 #ifndef QGSBRIGHTNESSCONTRASTFILTER_H 19 #define QGSBRIGHTNESSCONTRASTFILTER_H 20 21 #include "qgis_core.h" 22 #include "qgis_sip.h" 23 #include "qgsrasterinterface.h" 24 25 class QDomElement; 26 27 /** 28 * \ingroup core 29 * \brief Brightness/contrast and gamma correction filter pipe for rasters. 30 */ 31 class CORE_EXPORT QgsBrightnessContrastFilter : public QgsRasterInterface 32 { 33 public: 34 QgsBrightnessContrastFilter( QgsRasterInterface *input = nullptr ); 35 36 //! Clone itself, create deep copy 37 QgsBrightnessContrastFilter *clone() const override SIP_FACTORY; 38 39 //! Gets number of bands 40 int bandCount() const override; 41 42 //! Returns data type for the band specified by number 43 Qgis::DataType dataType( int bandNo ) const override; 44 45 /** 46 * Set input. 47 * Returns TRUE if set correctly, FALSE if cannot use that input 48 */ 49 bool setInput( QgsRasterInterface *input ) override; 50 51 /** 52 * Read block of data using given extent and size. 53 * Returns pointer to data. 54 * Caller is responsible to free the memory returned. 55 * \param bandNo band number 56 * \param extent extent of block 57 * \param width pixel width of block 58 * \param height pixel height of block 59 * \param feedback optional raster feedback object for cancellation/preview. Added in QGIS 3.0. 60 */ 61 QgsRasterBlock *block( int bandNo, const QgsRectangle &extent, int width, int height, QgsRasterBlockFeedback *feedback = nullptr ) override SIP_FACTORY; 62 63 /** 64 * Set brightness level. Acceptable value range is -255…255 65 * \see brightness() 66 */ 67 void setBrightness( int brightness ); 68 69 /** 70 * Returns current brightness level. 71 * \see setBrightness() 72 */ brightness()73 int brightness() const { return mBrightness; } 74 75 /** 76 * Set contrast level. Acceptable value range is -100…100 77 * \see contrast() 78 */ 79 void setContrast( int contrast ); 80 81 /** 82 * Returns current contrast level. 83 * \see setContrast() 84 */ contrast()85 int contrast() const { return mContrast; } 86 87 /** 88 * Set gamma value. Acceptable value range is -0.1…10 89 * \see gamma() 90 * 91 * \since QGIS 3.16 92 */ 93 void setGamma( double gamma ); 94 95 /** 96 * Returns current gamma value. 97 * \see setGamma() 98 * 99 * \since QGIS 3.16 100 */ gamma()101 double gamma() const { return mGamma; } 102 103 //! Write base class members to xml. 104 void writeXml( QDomDocument &doc, QDomElement &parentElem ) const override; 105 106 //! Sets base class members from xml. Usually called from create() methods of subclasses 107 void readXml( const QDomElement &filterElem ) override; 108 109 private: 110 //! Adjusts a color component by the specified brightness, contrast factor and gamma correction 111 int adjustColorComponent( int colorComponent, int alpha, int brightness, double contrastFactor, double gammaCorrection ) const; 112 113 //! Current brightness coefficient value. Default: 0. Range: -255...255 114 int mBrightness = 0; 115 116 //! Current contrast coefficient value. Default: 0. Range: -100...100 117 int mContrast = 0; 118 119 //! Current gamma value. Default: 1. Range: 0.1…10.0 120 double mGamma = 1.0; 121 122 }; 123 124 #endif // QGSBRIGHTNESSCONTRASTFILTER_H 125