Krita Source Code Documentation
Loading...
Searching...
No Matches
KoCmykColorSpaceTraits.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2007 Cyrille Berger <cberger@cberger.net>
3 * SPDX-FileCopyrightText: 2016, 2017, 2020 L. E. Segovia <amy@amyspark.me>
4 *
5 * SPDX-License-Identifier: LGPL-2.1-or-later
6*/
7
8#ifndef _KO_CMYK_COLORSPACE_TRAITS_H_
9#define _KO_CMYK_COLORSPACE_TRAITS_H_
10
12
17template<typename _channels_type_>
18struct KoCmykTraits : public KoColorSpaceTrait<_channels_type_, 5, 4> {
19 typedef _channels_type_ channels_type;
21
22 static const qint32 c_pos = 0;
23 static const qint32 m_pos = 1;
24 static const qint32 y_pos = 2;
25 static const qint32 k_pos = 3;
26
38 inline static channels_type C(quint8* data) {
40 return d[c_pos];
41 }
43 inline static void setC(quint8* data, channels_type nv) {
45 d[c_pos] = nv;
46 }
48 inline static channels_type M(quint8* data) {
50 return d[m_pos];
51 }
53 inline static void setM(quint8* data, channels_type nv) {
55 d[m_pos] = nv;
56 }
58 inline static channels_type Y(quint8* data) {
60 return d[y_pos];
61 }
63 inline static void setY(quint8* data, channels_type nv) {
65 d[y_pos] = nv;
66 }
68 inline static channels_type k(quint8* data) {
70 return d[k_pos];
71 }
73 inline static void setK(quint8* data, channels_type nv) {
75 d[k_pos] = nv;
76 }
77};
78
79struct KoCmykU8Traits : public KoCmykTraits<quint8> {
80};
81
82struct KoCmykU16Traits : public KoCmykTraits<quint16> {
83};
84
85#include <KoConfig.h>
86#ifdef HAVE_OPENEXR
87#include <half.h>
88
89struct KoCmykF16Traits : public KoCmykTraits<half> {
90
91 inline static QString normalisedChannelValueText(const quint8 *pixel, quint32 channelIndex) {
92 if (channelIndex > parent::channels_nb) return QString("Error");
93 channels_type c = nativeArray(pixel)[channelIndex];
94 switch (channelIndex) {
95 case c_pos:
96 case m_pos:
97 case y_pos:
98 case k_pos:
99 return QString().setNum(100.0 * qBound((qreal)0,
102 case 4:
103 return QString().setNum(100.0 * qBound((qreal)0,
106 default:
107 return QString("Error");
108 }
109 }
110
111 inline static void normalisedChannelsValue(const quint8 *pixel, QVector<float> &v)
112 {
113 Q_ASSERT((int)v.count() == (int)parent::channels_nb);
114 channels_type c;
115 float *channels = v.data();
116 for (uint i = 0; i < parent::channels_nb; i++) {
117 c = nativeArray(pixel)[i];
118 switch (i) {
119 case c_pos:
120 case m_pos:
121 case y_pos:
122 case k_pos:
123 channels[i] = qBound((qreal)0,
126 break;
127 // As per KoChannelInfo alpha channels are [0..1]
128 case 4:
129 default:
130 channels[i] = qBound((qreal)0,
133 break;
134 }
135 }
136 }
137
138 inline static void fromNormalisedChannelsValue(quint8 *pixel, const QVector<float> &values) {
139 Q_ASSERT((int)values.count() == (int)parent::channels_nb);
140 channels_type c;
141 for (uint i = 0; i < parent::channels_nb; i++) {
142 float b = 0;
143 switch(i) {
144 case c_pos:
145 case m_pos:
146 case y_pos:
147 case k_pos:
148 b = qBound((float)0,
151 break;
152 default:
156 break;
157 }
158 c = (channels_type)b;
159 parent::nativeArray(pixel)[i] = c;
160 }
161 }
162};
163
164#endif
165
166struct KoCmykF32Traits : public KoCmykTraits<float> {
167
168 inline static QString normalisedChannelValueText(const quint8 *pixel, quint32 channelIndex) {
169 if (channelIndex > parent::channels_nb) return QString("Error");
170 channels_type c = nativeArray(pixel)[channelIndex];
171 switch (channelIndex) {
172 case c_pos:
173 case m_pos:
174 case y_pos:
175 case k_pos:
176 return QString().setNum(100.0 * qBound((qreal)0,
179 case 4:
180 return QString().setNum(100.0 * qBound((qreal)0,
183 default:
184 return QString("Error");
185 }
186 }
187
188 inline static void normalisedChannelsValue(const quint8 *pixel, QVector<float> &v)
189 {
190 Q_ASSERT((int)v.count() == (int)parent::channels_nb);
192 float *channels = v.data();
193 for (uint i = 0; i < parent::channels_nb; i++) {
194 c = nativeArray(pixel)[i];
195 switch (i) {
196 case c_pos:
197 case m_pos:
198 case y_pos:
199 case k_pos:
200 channels[i] = qBound((qreal)0,
203 break;
204 // As per KoChannelInfo alpha channels are [0..1]
205 case 4:
206 default:
207 channels[i] = qBound((qreal)0,
210 break;
211 }
212 }
213 }
214
215 inline static void fromNormalisedChannelsValue(quint8 *pixel, const QVector<float> &values) {
216 Q_ASSERT((int)values.count() == (int)parent::channels_nb);
218 for (uint i = 0; i < parent::channels_nb; i++) {
219 float b = 0;
220 switch(i) {
221 case c_pos:
222 case m_pos:
223 case y_pos:
224 case k_pos:
225 b = qBound((float)0,
228 break;
229 default:
233 break;
234 }
235 c = (channels_type)b;
236 parent::nativeArray(pixel)[i] = c;
237 }
238 }
239};
240
241struct KoCmykF64Traits : public KoCmykTraits<double> {
242
243 inline static QString normalisedChannelValueText(const quint8 *pixel, quint32 channelIndex) {
244 if (channelIndex > parent::channels_nb) return QString("Error");
245 channels_type c = nativeArray(pixel)[channelIndex];
246 switch (channelIndex) {
247 case c_pos:
248 case m_pos:
249 case y_pos:
250 case k_pos:
251 return QString().setNum(100.0 * qBound((qreal)0,
254 case 4:
255 return QString().setNum(100.0 * qBound((qreal)0,
258 default:
259 return QString("Error");
260 }
261 }
262
263 inline static void normalisedChannelsValue(const quint8 *pixel, QVector<float> &v)
264 {
265 Q_ASSERT((int)v.count() == (int)parent::channels_nb);
267 float *channels = v.data();
268 for (uint i = 0; i < parent::channels_nb; i++) {
269 c = nativeArray(pixel)[i];
270 switch (i) {
271 case c_pos:
272 case m_pos:
273 case y_pos:
274 case k_pos:
275 channels[i] = qBound((qreal)0,
278 break;
279 // As per KoChannelInfo alpha channels are [0..1]
280 case 4:
281 default:
282 channels[i] = qBound((qreal)0,
285 break;
286 }
287 }
288 }
289
290 inline static void fromNormalisedChannelsValue(quint8 *pixel, const QVector<float> &values) {
291 Q_ASSERT((int)values.count() == (int)parent::channels_nb);
293 for (uint i = 0; i < parent::channels_nb; i++) {
294 float b = 0;
295 switch(i) {
296 case c_pos:
297 case m_pos:
298 case y_pos:
299 case k_pos:
300 b = qBound((float)0,
303 break;
304 default:
308 break;
309 }
310 c = (channels_type)b;
311 parent::nativeArray(pixel)[i] = c;
312 }
313 }
314};
315
316
317
318#endif
319
qreal v
unsigned int uint
static void fromNormalisedChannelsValue(quint8 *pixel, const QVector< float > &values)
static QString normalisedChannelValueText(const quint8 *pixel, quint32 channelIndex)
static void normalisedChannelsValue(const quint8 *pixel, QVector< float > &v)
static void fromNormalisedChannelsValue(quint8 *pixel, const QVector< float > &values)
static QString normalisedChannelValueText(const quint8 *pixel, quint32 channelIndex)
static void normalisedChannelsValue(const quint8 *pixel, QVector< float > &v)
static const qint32 y_pos
static channels_type C(quint8 *data)
static const qint32 c_pos
static void setY(quint8 *data, channels_type nv)
Set the Yellow component.
static void setK(quint8 *data, channels_type nv)
Set the Key component.
static void setM(quint8 *data, channels_type nv)
Set the Magenta component.
static const qint32 m_pos
static channels_type k(quint8 *data)
KoColorSpaceTrait< _channels_type_, 5, 4 > parent
static channels_type Y(quint8 *data)
static void setC(quint8 *data, channels_type nv)
Set the Cyan component.
static const qint32 k_pos
_channels_type_ channels_type
static channels_type M(quint8 *data)
static const quint32 channels_nb
the number of channels in this color space
static void fromNormalisedChannelsValue(quint8 *pixel, const QVector< float > &values)
static const channels_type * nativeArray(const quint8 *a)
static QString normalisedChannelValueText(const quint8 *pixel, quint32 channelIndex)
static void normalisedChannelsValue(const quint8 *pixel, QVector< float > &v)