Warning, file /office/calligra/libs/pigment/KoChannelInfo.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 * Copyright (c) 2004 Boudewijn Rempt <boud@valdyas.org> 0003 * 0004 * This library is free software; you can redistribute it and/or 0005 * modify it under the terms of the GNU Library General Public 0006 * License as published by the Free Software Foundation; either 0007 * version 2 of the License, or (at your option) any later version. 0008 * 0009 * This library is distributed in the hope that it will be useful, 0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 * Library General Public License for more details. 0013 * 0014 * You should have received a copy of the GNU Library General Public License 0015 * along with this library; see the file COPYING.LIB. If not, write to 0016 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 * Boston, MA 02110-1301, USA. 0018 */ 0019 #ifndef KOCHANNELINFO_H_ 0020 #define KOCHANNELINFO_H_ 0021 0022 #include <limits> 0023 0024 #include <QColor> 0025 #include <QString> 0026 #include <QList> 0027 0028 /** 0029 * This class gives some basic information about a channel, 0030 * that is, one of the components that makes up a particular 0031 * pixel. 0032 */ 0033 class KoChannelInfo 0034 { 0035 public: 0036 /** 0037 * Used to represent a min and max range. 0038 */ 0039 struct DoubleRange 0040 { 0041 public: 0042 double minVal, maxVal; 0043 public: 0044 /// creates an invalid range of 0,0 0045 DoubleRange(void) : minVal(0), maxVal(0) { } 0046 /// creates 0047 DoubleRange(qreal _minVal, qreal _maxVal) : minVal(_minVal), maxVal(_maxVal) { Q_ASSERT(minVal <= maxVal); } 0048 /// true if this range is usable 0049 bool isValid(void) const { return minVal < maxVal; } 0050 }; 0051 public: 0052 /// enum to define the type of the channel 0053 enum enumChannelType { 0054 COLOR, ///< The channel represents a color 0055 ALPHA ///< The channel represents the opacity of a pixel 0056 //SUBSTANCE, ///< The channel represents a real-world substance like pigments or medium 0057 //SUBSTRATE ///< The channel represents a real-world painting substrate like a canvas 0058 }; 0059 /// enum to define the value of the channel 0060 enum enumChannelValueType { 0061 UINT8, ///< use this for an unsigned integer 8bits channel 0062 UINT16, ///< use this for an integer 16bits channel 0063 UINT32, ///< use this for an unsigned integer 21bits channel 0064 FLOAT16, ///< use this for a float 16bits channel 0065 FLOAT32, ///< use this for a float 32bits channel 0066 FLOAT64, ///< use this for a float 64bits channel 0067 INT8, ///< use this for an integer 8bits channel 0068 INT16, ///< use this for an integer 16bits channel 0069 OTHER ///< Use this if the channel is neither an integer or a float 0070 }; 0071 0072 public: 0073 KoChannelInfo() { } 0074 /** 0075 * @param name of the channel 0076 * @param npos position of the channel in the pixel (in bytes) 0077 * @param displayPosition the position of the channel in the user-visible order 0078 * @param channelType type of the channel 0079 * @param channelValueType type of the numerical data used by the channel 0080 * @param size number of bytes (not bits) of the channel (if -1, it is deduced from the channelType) 0081 * @param color a color to represent that channel (for instance in an histogram) 0082 * @param uiMinMax the reange 0083 */ 0084 KoChannelInfo(const QString & name, 0085 qint32 npos, 0086 qint32 displayPosition, 0087 enumChannelType channelType, 0088 enumChannelValueType channelValueType, 0089 qint32 size = -1, 0090 const QColor &color = QColor(0, 0, 0), 0091 const DoubleRange &uiMinMax = DoubleRange()) 0092 : m_name(name) 0093 , m_pos(npos) 0094 , m_displayPosition(displayPosition) 0095 , m_channelType(channelType) 0096 , m_channelValueType(channelValueType) 0097 , m_size(size) 0098 , m_color(color) 0099 , m_uiMinMax(uiMinMax) 0100 { 0101 switch(m_channelValueType) 0102 { 0103 case UINT8: 0104 case INT8: 0105 Q_ASSERT(m_size == -1 || m_size == 1); 0106 m_size = 1; 0107 break; 0108 case UINT16: 0109 case INT16: 0110 Q_ASSERT(m_size == -1 || m_size == 2); 0111 m_size = 2; 0112 break; 0113 case UINT32: 0114 Q_ASSERT(m_size == -1 || m_size == 4); 0115 m_size = 4; 0116 break; 0117 case FLOAT16: 0118 Q_ASSERT(m_size == -1 || m_size == 2); 0119 m_size = 2; 0120 break; 0121 case FLOAT32: 0122 Q_ASSERT(m_size == -1 || m_size == 4); 0123 m_size = 4; 0124 break; 0125 case FLOAT64: 0126 Q_ASSERT(m_size == -1 || m_size == 8); 0127 m_size = 8; 0128 break; 0129 case OTHER: 0130 Q_ASSERT(m_size != -1); 0131 } 0132 if (!uiMinMax.isValid()) { 0133 switch (m_channelValueType) { 0134 case UINT8: 0135 m_uiMinMax.minVal = std::numeric_limits<quint8>::min(); 0136 m_uiMinMax.maxVal = std::numeric_limits<quint8>::max(); 0137 break; 0138 case INT8: 0139 m_uiMinMax.minVal = std::numeric_limits<qint8>::min(); 0140 m_uiMinMax.maxVal = std::numeric_limits<qint8>::max(); 0141 break; 0142 case UINT16: 0143 m_uiMinMax.minVal = std::numeric_limits<quint16>::min(); 0144 m_uiMinMax.maxVal = std::numeric_limits<quint16>::max(); 0145 break; 0146 case INT16: 0147 m_uiMinMax.minVal = std::numeric_limits<qint16>::min(); 0148 m_uiMinMax.maxVal = std::numeric_limits<qint16>::max(); 0149 break; 0150 case UINT32: 0151 m_uiMinMax.minVal = std::numeric_limits<quint32>::min(); 0152 m_uiMinMax.maxVal = std::numeric_limits<quint32>::max(); 0153 break; 0154 default: 0155 // assume real otherwise, which is 0..1 by default 0156 m_uiMinMax.minVal = 0.0; 0157 m_uiMinMax.maxVal = 1.0; 0158 break; 0159 } 0160 } 0161 Q_ASSERT(m_uiMinMax.isValid()); 0162 } 0163 public: 0164 0165 /** 0166 * converts the display position to the pixel-order index in the channels vector. 0167 */ 0168 static int displayPositionToChannelIndex(int displayPosition, const QList<KoChannelInfo*> &channels) 0169 { 0170 for (int i = 0; i < channels.size(); ++i) { 0171 if (channels.at(i)->displayPosition() == displayPosition) { 0172 return i; 0173 } 0174 } 0175 return -1; 0176 } 0177 0178 static QList<KoChannelInfo*> displayOrderSorted(const QList<KoChannelInfo*> &channels) 0179 { 0180 QList <KoChannelInfo*> sortedChannels; 0181 for (int i = 0; i < channels.size(); ++i) { 0182 foreach(KoChannelInfo* channel, channels) { 0183 if (channel->displayPosition() == i) { 0184 sortedChannels << channel; 0185 break; 0186 } 0187 } 0188 } 0189 Q_ASSERT(channels.size() == sortedChannels.size()); 0190 return sortedChannels; 0191 } 0192 0193 /** 0194 * User-friendly name for this channel for presentation purposes in the gui 0195 */ 0196 inline QString name() const { 0197 return m_name; 0198 } 0199 0200 /** 0201 * returns the position of the first byte of the channel in the pixel 0202 */ 0203 inline qint32 pos() const { 0204 return m_pos; 0205 } 0206 0207 /** 0208 * @return the displayPosition of the channel in pixel 0209 */ 0210 inline qint32 displayPosition() const { 0211 return m_displayPosition; 0212 } 0213 0214 /** 0215 * returns the number of bytes this channel takes 0216 */ 0217 inline qint32 size() const { 0218 return m_size; 0219 } 0220 0221 /** 0222 * returns the type of the channel 0223 */ 0224 inline enumChannelType channelType() const { 0225 return m_channelType; 0226 } 0227 /** 0228 * return the type of the value of the channel (float, uint8 or uint16) 0229 */ 0230 inline enumChannelValueType channelValueType() const { 0231 return m_channelValueType; 0232 } 0233 /** 0234 * This is a color that can be used to represent this channel in histograms and so. 0235 * By default this is black, so keep in mind that many channels might look the same 0236 */ 0237 inline QColor color() const { 0238 return m_color; 0239 } 0240 0241 /** 0242 * A channel is less than another channel if its pos is smaller. 0243 */ 0244 inline bool operator<(const KoChannelInfo & info) { 0245 return m_pos < info.m_pos; 0246 } 0247 0248 /** 0249 * Gets the minimum value that this channel should have. 0250 * This is suitable for UI use. 0251 */ 0252 inline double getUIMin(void) const { 0253 return m_uiMinMax.minVal; 0254 } 0255 0256 /** 0257 * Gets the minimum value that this channel should have. 0258 * This is suitable for UI use. 0259 */ 0260 inline double getUIMax(void) const { 0261 return m_uiMinMax.maxVal; 0262 } 0263 0264 private: 0265 0266 QString m_name; 0267 qint32 m_pos; 0268 qint32 m_displayPosition; 0269 enumChannelType m_channelType; 0270 enumChannelValueType m_channelValueType; 0271 qint32 m_size; 0272 QColor m_color; 0273 DoubleRange m_uiMinMax; 0274 0275 }; 0276 0277 #endif // KOCHANNELINFO_H_