Krita Source Code Documentation
Loading...
Searching...
No Matches
KoChannelInfo.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2004 Boudewijn Rempt <boud@valdyas.org>
3 * SPDX-FileCopyrightText: 2020 L. E. Segovia <amy@amyspark.me>
4 *
5 * SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7#ifndef KOCHANNELINFO_H_
8#define KOCHANNELINFO_H_
9
10#include <limits>
11
12#include <QColor>
13#include <QString>
14#include <QList>
15
22{
23public:
28 {
29 public:
30 double minVal, maxVal;
31 public:
33 DoubleRange(void) : minVal(0), maxVal(0) { }
35 DoubleRange(qreal _minVal, qreal _maxVal) : minVal(_minVal), maxVal(_maxVal) { Q_ASSERT(minVal <= maxVal); }
37 bool isValid(void) const { return minVal < maxVal; }
38 };
39public:
43 ALPHA
44 //SUBSTANCE, ///< The channel represents a real-world substance like pigments or medium
45 //SUBSTRATE ///< The channel represents a real-world painting substrate like a canvas
46 };
59
60public:
72 KoChannelInfo(const QString & name,
73 qint32 npos,
74 qint32 displayPosition,
77 qint32 size = -1,
78 const QColor &color = QColor(0, 0, 0),
79 const DoubleRange &uiMinMax = DoubleRange())
80 : m_name(name)
81 , m_pos(npos)
85 , m_size(size)
86 , m_color(color)
87 , m_uiMinMax(uiMinMax)
88 {
89 switch(m_channelValueType)
90 {
91 case UINT8:
92 case INT8:
93 Q_ASSERT(m_size == -1 || m_size == 1);
94 m_size = 1;
95 break;
96 case UINT16:
97 case INT16:
98 Q_ASSERT(m_size == -1 || m_size == 2);
99 m_size = 2;
100 break;
101 case UINT32:
102 Q_ASSERT(m_size == -1 || m_size == 4);
103 m_size = 4;
104 break;
105 case FLOAT16:
106 Q_ASSERT(m_size == -1 || m_size == 2);
107 m_size = 2;
108 break;
109 case FLOAT32:
110 Q_ASSERT(m_size == -1 || m_size == 4);
111 m_size = 4;
112 break;
113 case FLOAT64:
114 Q_ASSERT(m_size == -1 || m_size == 8);
115 m_size = 8;
116 break;
117 case OTHER:
118 Q_ASSERT(m_size != -1);
119 }
120 if (!uiMinMax.isValid()) {
121 switch (m_channelValueType) {
122 case UINT8:
123 m_uiMinMax.minVal = std::numeric_limits<quint8>::min();
124 m_uiMinMax.maxVal = std::numeric_limits<quint8>::max();
125 break;
126 case INT8:
127 m_uiMinMax.minVal = std::numeric_limits<qint8>::min();
128 m_uiMinMax.maxVal = std::numeric_limits<qint8>::max();
129 break;
130 case UINT16:
131 m_uiMinMax.minVal = std::numeric_limits<quint16>::min();
132 m_uiMinMax.maxVal = std::numeric_limits<quint16>::max();
133 break;
134 case INT16:
135 m_uiMinMax.minVal = std::numeric_limits<qint16>::min();
136 m_uiMinMax.maxVal = std::numeric_limits<qint16>::max();
137 break;
138 case UINT32:
139 m_uiMinMax.minVal = std::numeric_limits<quint32>::min();
140 m_uiMinMax.maxVal = std::numeric_limits<quint32>::max();
141 break;
142 default:
143 // assume real otherwise, which is 0..1 by default
144 m_uiMinMax.minVal = 0.0;
145 m_uiMinMax.maxVal = 1.0;
146 break;
147 }
148 }
149 Q_ASSERT(m_uiMinMax.isValid());
150 }
151public:
152
157 {
158 for (int i = 0; i < channels.size(); ++i) {
159 if (channels.at(i)->displayPosition() == displayPosition) {
160 return i;
161 }
162 }
163 return -1;
164 }
165
167 {
168 QList <KoChannelInfo*> sortedChannels;
169 for (int i = 0; i < channels.size(); ++i) {
170 Q_FOREACH (KoChannelInfo* channel, channels) {
171 if (channel->displayPosition() == i) {
172 sortedChannels << channel;
173 break;
174 }
175 }
176 }
177 Q_ASSERT(channels.size() == sortedChannels.size());
178 return sortedChannels;
179 }
180
184 inline QString name() const {
185 return m_name;
186 }
187
191 inline qint32 pos() const {
192 return m_pos;
193 }
194
198 inline qint32 displayPosition() const {
199 return m_displayPosition;
200 }
201
205 inline qint32 size() const {
206 return m_size;
207 }
208
213 return m_channelType;
214 }
219 return m_channelValueType;
220 }
225 inline QColor color() const {
226 return m_color;
227 }
228
232 inline bool operator<(const KoChannelInfo & info) {
233 return m_pos < info.m_pos;
234 }
235
240 inline double getUIMin(void) const {
241 return m_uiMinMax.minVal;
242 }
243
248 inline double getUIMax(void) const {
249 return m_uiMinMax.maxVal;
250 }
251
257 inline double getUIUnitValue(void) const {
259 }
260
261private:
262
263 QString m_name;
264 qint32 m_pos;
268 qint32 m_size;
269 QColor m_color;
271
272};
273
274#endif // KOCHANNELINFO_H_
QColor color() const
enumChannelType
enum to define the type of the channel
@ ALPHA
The channel represents the opacity of a pixel.
@ COLOR
The channel represents a color.
qint32 size() const
qint32 pos() const
bool operator<(const KoChannelInfo &info)
enumChannelValueType
enum to define the value of the channel
@ UINT8
use this for an unsigned integer 8bits channel
@ UINT16
use this for an integer 16bits channel
@ OTHER
Use this if the channel is neither an integer or a float.
@ INT16
use this for an integer 16bits channel
@ INT8
use this for an integer 8bits channel
@ FLOAT32
use this for a float 32bits channel
@ FLOAT16
use this for a float 16bits channel
@ UINT32
use this for an unsigned integer 21bits channel
@ FLOAT64
use this for a float 64bits channel
enumChannelType channelType() const
KoChannelInfo(const QString &name, qint32 npos, qint32 displayPosition, enumChannelType channelType, enumChannelValueType channelValueType, qint32 size=-1, const QColor &color=QColor(0, 0, 0), const DoubleRange &uiMinMax=DoubleRange())
static int displayPositionToChannelIndex(int displayPosition, const QList< KoChannelInfo * > &channels)
enumChannelType m_channelType
enumChannelValueType channelValueType() const
qint32 m_displayPosition
double getUIUnitValue(void) const
getUIUnitValue Gets the unit value for this channel. This is suitable for converting between represen...
QString name() const
static QList< KoChannelInfo * > displayOrderSorted(const QList< KoChannelInfo * > &channels)
double getUIMin(void) const
enumChannelValueType m_channelValueType
qint32 displayPosition() const
double getUIMax(void) const
DoubleRange m_uiMinMax
DoubleRange(void)
creates an invalid range of 0,0
DoubleRange(qreal _minVal, qreal _maxVal)
creates
bool isValid(void) const
true if this range is usable