1 /* ************************************************************************** 2 qgsrastertransparency.h - description 3 ------------------- 4 begin : Mon Nov 30 2007 5 copyright : (C) 2007 by Peter J. Ersts 6 email : ersts@amnh.org 7 8 ****************************************************************************/ 9 10 /* ************************************************************************** 11 * * 12 * This program is free software; you can redistribute it and/or modify * 13 * it under the terms of the GNU General Public License as published by * 14 * the Free Software Foundation; either version 2 of the License, or * 15 * (at your option) any later version. * 16 * * 17 ***************************************************************************/ 18 #ifndef QGSRASTERTRANSPARENCY_H 19 #define QGSRASTERTRANSPARENCY_H 20 21 #include "qgis_core.h" 22 #include "qgis_sip.h" 23 #include <QList> 24 class QDomDocument; 25 class QDomElement; 26 27 /** 28 * \ingroup core 29 * \brief Defines the list of pixel values to be considered as transparent or semi 30 * transparent when rendering rasters. 31 */ 32 class CORE_EXPORT QgsRasterTransparency 33 { 34 35 public: 36 37 /** 38 * Constructor for QgsRasterTransparency. 39 */ 40 QgsRasterTransparency() = default; 41 42 // 43 // Structs to hold transparent pixel values 44 // 45 struct TransparentThreeValuePixel 46 { 47 double red; 48 double green; 49 double blue; 50 double percentTransparent; 51 }; 52 53 struct TransparentSingleValuePixel 54 { 55 double min; 56 double max; 57 double percentTransparent; 58 }; 59 60 // 61 // Initializer, Accessor and mutator for transparency tables. 62 // 63 64 /** 65 * Returns the transparent single value pixel list. 66 * \see setTransparentSingleValuePixelList() 67 */ 68 QList<QgsRasterTransparency::TransparentSingleValuePixel> transparentSingleValuePixelList() const; 69 70 /** 71 * Returns the transparent three value pixel list. 72 * \see setTransparentThreeValuePixelList() 73 */ 74 QList<QgsRasterTransparency::TransparentThreeValuePixel> transparentThreeValuePixelList() const; 75 76 /** 77 * Resets the transparency list to a single \a value. 78 */ 79 void initializeTransparentPixelList( double value ); 80 81 /** 82 * Resets the transparency list to single red, green, and blue values. 83 */ 84 void initializeTransparentPixelList( double redValue, double greenValue, double blueValue ); 85 86 /** 87 * Sets the transparent single value pixel list, replacing the whole existing list. 88 * \see transparentSingleValuePixelList() 89 */ 90 void setTransparentSingleValuePixelList( const QList<QgsRasterTransparency::TransparentSingleValuePixel> &newList ); 91 92 /** 93 * Sets the transparent three value pixel list, replacing the whole existing list. 94 * \see transparentThreeValuePixelList() 95 */ 96 void setTransparentThreeValuePixelList( const QList<QgsRasterTransparency::TransparentThreeValuePixel> &newList ); 97 98 /** 99 * Returns the transparency value for a single \a value pixel. 100 * 101 * Searches through the transparency list, and if a match is found, the global transparency value is scaled 102 * by the stored transparency value. 103 * 104 * \param value the needle to search for in the transparency hay stack 105 * \param globalTransparency the overall transparency level for the layer 106 */ 107 int alphaValue( double value, int globalTransparency = 255 ) const; 108 109 //! \brief 110 111 /** 112 * Returns the transparency value for a RGB pixel. 113 * 114 * Searches through the transparency list, if a match is found, the global transparency value is scaled 115 * by the stored transparency value. 116 * \param redValue the red portion of the needle to search for in the transparency hay stack 117 * \param greenValue the green portion of the needle to search for in the transparency hay stack 118 * \param blueValue the green portion of the needle to search for in the transparency hay stack 119 * \param globalTransparency the overall transparency level for the layer 120 */ 121 int alphaValue( double redValue, double greenValue, double blueValue, int globalTransparency = 255 ) const; 122 123 //! True if there are no entries in the pixel lists except the nodata value 124 bool isEmpty() const; 125 126 /** 127 * Writes the transparency information to an XML document. 128 */ 129 void writeXml( QDomDocument &doc, QDomElement &parentElem ) const; 130 131 /** 132 * Reads the transparency information from an XML document. 133 */ 134 void readXml( const QDomElement &elem ); 135 136 private: 137 //! \brief The list to hold transparency values for RGB layers 138 QList<QgsRasterTransparency::TransparentThreeValuePixel> mTransparentThreeValuePixelList; 139 140 //! \brief The list to hold transparency values for single value pixel layers 141 QList<QgsRasterTransparency::TransparentSingleValuePixel> mTransparentSingleValuePixelList; 142 143 }; 144 #endif 145