Krita Source Code Documentation
Loading...
Searching...
No Matches
KoColorSpaceTrait< _channels_type_, _channels_nb_, _alpha_pos_ > Struct Template Reference

#include <KoColorSpaceTraits.h>

+ Inheritance diagram for KoColorSpaceTrait< _channels_type_, _channels_nb_, _alpha_pos_ >:

Public Types

typedef _channels_type_ channels_type
 the type of the value of the channels of this color space
 
typedef KoColorSpaceMathsTraits< _channels_type_ > math_trait
 the associated math class
 

Static Public Member Functions

static quint8 * allocate (quint32 nPixels)
 
static void applyAlphaNormedFloatMask (quint8 *pixels, const float *alpha, qint32 nPixels)
 
static void applyAlphaU8Mask (quint8 *pixels, const quint8 *alpha, qint32 nPixels)
 
static void applyInverseAlphaNormedFloatMask (quint8 *pixels, const float *alpha, qint32 nPixels)
 
static void applyInverseAlphaU8Mask (quint8 *pixels, const quint8 *alpha, qint32 nPixels)
 
static QString channelValueText (const quint8 *pixel, quint32 channelIndex)
 
static void copyOpacityU8 (quint8 *src, quint8 *dst, qint32 nPixels)
 
static void fillGrayBrushWithColor (quint8 *pixels, const QRgb *brush, quint8 *brushColor, qint32 nPixels)
 
static void fillInverseAlphaNormedFloatMaskWithColor (quint8 *pixels, const float *alpha, const quint8 *brushColor, qint32 nPixels)
 
static void fromNormalisedChannelsValue (quint8 *pixel, const QVector< float > &values)
 
template<typename I , typename std::enable_if_t< std::numeric_limits< I >::is_integer, int > = 1>
static void fromNormalisedChannelsValueImpl (quint8 *pixel, const QVector< float > &values)
 
template<typename I , typename std::enable_if_t<!std::numeric_limits< I >::is_integer, int > = 1>
static void fromNormalisedChannelsValueImpl (quint8 *pixel, const QVector< float > &values)
 
static void multiplyAlpha (quint8 *pixels, quint8 alpha, qint32 nPixels)
 
static const channels_typenativeArray (const quint8 *a)
 
static channels_typenativeArray (quint8 *a)
 
static void normalisedChannelsValue (const quint8 *pixel, QVector< float > &v)
 
template<typename I , typename std::enable_if_t< std::numeric_limits< I >::is_integer, int > = 1>
static void normalisedChannelsValueImpl (const quint8 *pixel, QVector< float > &v)
 
template<typename I , typename std::enable_if_t<!std::numeric_limits< I >::is_integer, int > = 1>
static void normalisedChannelsValueImpl (const quint8 *pixel, QVector< float > &v)
 
static QString normalisedChannelValueText (const quint8 *pixel, quint32 channelIndex)
 
static qreal opacityF (const quint8 *U8_pixel)
 
static quint8 opacityU8 (const quint8 *U8_pixel)
 
static void setOpacity (quint8 *pixels, qreal alpha, qint32 nPixels)
 
static void setOpacity (quint8 *pixels, quint8 alpha, qint32 nPixels)
 
static void singleChannelPixel (quint8 *dstPixel, const quint8 *srcPixel, quint32 channelIndex)
 

Static Public Attributes

static const qint32 alpha_pos = _alpha_pos_
 
static const quint32 channels_nb = _channels_nb_
 the number of channels in this color space
 
static const int depth = KoColorSpaceMathsTraits<_channels_type_>::bits
 the number of bit for each channel
 
static const quint32 pixelSize = channels_nb * sizeof(channels_type)
 

Detailed Description

template<typename _channels_type_, int _channels_nb_, int _alpha_pos_>
struct KoColorSpaceTrait< _channels_type_, _channels_nb_, _alpha_pos_ >

This class is the base class to define the main characteristics of a colorspace which inherits KoColorSpaceAbstract.

  • channels_type is the type of the value use for each channel, for example quint8 for 8bits per channel color spaces, or quint16 for 16bits integer per channel, float for 32bits per channel floating point color spaces
  • channels_nb is the total number of channels in an image (for example RGB is 3 but RGBA is four)
  • alpha_pos is the position of the alpha channel among the channels, if there is no alpha channel, then alpha_pos is set to -1

For instance a colorspace of three color channels and alpha channel in 16bits, will be defined as KoColorSpaceTrait<quint16, 4, 3>. The same without the alpha channel is KoColorSpaceTrait<quint16,3,-1>

Definition at line 39 of file KoColorSpaceTraits.h.

Member Typedef Documentation

◆ channels_type

template<typename _channels_type_ , int _channels_nb_, int _alpha_pos_>
typedef _channels_type_ KoColorSpaceTrait< _channels_type_, _channels_nb_, _alpha_pos_ >::channels_type

the type of the value of the channels of this color space

Definition at line 45 of file KoColorSpaceTraits.h.

◆ math_trait

template<typename _channels_type_ , int _channels_nb_, int _alpha_pos_>
typedef KoColorSpaceMathsTraits<_channels_type_> KoColorSpaceTrait< _channels_type_, _channels_nb_, _alpha_pos_ >::math_trait

the associated math class

Definition at line 58 of file KoColorSpaceTraits.h.

Member Function Documentation

◆ allocate()

template<typename _channels_type_ , int _channels_nb_, int _alpha_pos_>
static quint8 * KoColorSpaceTrait< _channels_type_, _channels_nb_, _alpha_pos_ >::allocate ( quint32 nPixels)
inlinestatic

Allocate nPixels pixels for this colorspace.

Definition at line 130 of file KoColorSpaceTraits.h.

130 {
131 return new quint8[ nPixels * pixelSize ];
132 }
static const quint32 pixelSize

References KoColorSpaceTrait< _channels_type_, _channels_nb_, _alpha_pos_ >::pixelSize.

◆ applyAlphaNormedFloatMask()

template<typename _channels_type_ , int _channels_nb_, int _alpha_pos_>
static void KoColorSpaceTrait< _channels_type_, _channels_nb_, _alpha_pos_ >::applyAlphaNormedFloatMask ( quint8 * pixels,
const float * alpha,
qint32 nPixels )
inlinestatic

Definition at line 247 of file KoColorSpaceTraits.h.

247 {
248 if (alpha_pos < 0) return;
249
250 for (; nPixels > 0; --nPixels, pixels += pixelSize, ++alpha) {
252 channels_type* alphapixel = nativeArray(pixels) + alpha_pos;
253 *alphapixel = KoColorSpaceMaths<channels_type>::multiply(*alphapixel, valpha);
254 }
255 }
static _Tdst multiply(_T a, _Tdst b)
static const qint32 alpha_pos
_channels_type_ channels_type
the type of the value of the channels of this color space
static const channels_type * nativeArray(const quint8 *a)

References KoColorSpaceTrait< _channels_type_, _channels_nb_, _alpha_pos_ >::alpha_pos, KoColorSpaceMaths< _T, _Tdst >::multiply(), KoColorSpaceTrait< _channels_type_, _channels_nb_, _alpha_pos_ >::nativeArray(), and KoColorSpaceTrait< _channels_type_, _channels_nb_, _alpha_pos_ >::pixelSize.

◆ applyAlphaU8Mask()

template<typename _channels_type_ , int _channels_nb_, int _alpha_pos_>
static void KoColorSpaceTrait< _channels_type_, _channels_nb_, _alpha_pos_ >::applyAlphaU8Mask ( quint8 * pixels,
const quint8 * alpha,
qint32 nPixels )
inlinestatic

◆ applyInverseAlphaNormedFloatMask()

template<typename _channels_type_ , int _channels_nb_, int _alpha_pos_>
static void KoColorSpaceTrait< _channels_type_, _channels_nb_, _alpha_pos_ >::applyInverseAlphaNormedFloatMask ( quint8 * pixels,
const float * alpha,
qint32 nPixels )
inlinestatic

◆ applyInverseAlphaU8Mask()

template<typename _channels_type_ , int _channels_nb_, int _alpha_pos_>
static void KoColorSpaceTrait< _channels_type_, _channels_nb_, _alpha_pos_ >::applyInverseAlphaU8Mask ( quint8 * pixels,
const quint8 * alpha,
qint32 nPixels )
inlinestatic

◆ channelValueText()

template<typename _channels_type_ , int _channels_nb_, int _alpha_pos_>
static QString KoColorSpaceTrait< _channels_type_, _channels_nb_, _alpha_pos_ >::channelValueText ( const quint8 * pixel,
quint32 channelIndex )
inlinestatic

Definition at line 146 of file KoColorSpaceTraits.h.

146 {
147 if (channelIndex > channels_nb) return QString("Error");
148 channels_type c = nativeArray(pixel)[channelIndex];
149 return QString().setNum(c);
150 }
static const quint32 channels_nb
the number of channels in this color space

References KoColorSpaceTrait< _channels_type_, _channels_nb_, _alpha_pos_ >::channels_nb, and KoColorSpaceTrait< _channels_type_, _channels_nb_, _alpha_pos_ >::nativeArray().

◆ copyOpacityU8()

template<typename _channels_type_ , int _channels_nb_, int _alpha_pos_>
static void KoColorSpaceTrait< _channels_type_, _channels_nb_, _alpha_pos_ >::copyOpacityU8 ( quint8 * src,
quint8 * dst,
qint32 nPixels )
inlinestatic

◆ fillGrayBrushWithColor()

template<typename _channels_type_ , int _channels_nb_, int _alpha_pos_>
static void KoColorSpaceTrait< _channels_type_, _channels_nb_, _alpha_pos_ >::fillGrayBrushWithColor ( quint8 * pixels,
const QRgb * brush,
quint8 * brushColor,
qint32 nPixels )
inlinestatic

Definition at line 278 of file KoColorSpaceTraits.h.

278 {
279 if (alpha_pos >= 0) {
280 for (; nPixels > 0; --nPixels, pixels += pixelSize, ++brush) {
281 memcpy(pixels, brushColor, pixelSize);
282 const quint8 opacity = KoColorSpaceMaths<quint8>::multiply(OPACITY_OPAQUE_U8 - quint8(qRed(*brush)), quint8(qAlpha(*brush)));
284 }
285 } else {
286 for (; nPixels > 0; --nPixels, pixels += pixelSize) {
287 memcpy(pixels, brushColor, pixelSize);
288 }
289 }
290 }

References KoColorSpaceTrait< _channels_type_, _channels_nb_, _alpha_pos_ >::alpha_pos, KoColorSpaceMaths< _T, _Tdst >::multiply(), KoColorSpaceTrait< _channels_type_, _channels_nb_, _alpha_pos_ >::nativeArray(), OPACITY_OPAQUE_U8, and KoColorSpaceTrait< _channels_type_, _channels_nb_, _alpha_pos_ >::pixelSize.

◆ fillInverseAlphaNormedFloatMaskWithColor()

template<typename _channels_type_ , int _channels_nb_, int _alpha_pos_>
static void KoColorSpaceTrait< _channels_type_, _channels_nb_, _alpha_pos_ >::fillInverseAlphaNormedFloatMaskWithColor ( quint8 * pixels,
const float * alpha,
const quint8 * brushColor,
qint32 nPixels )
inlinestatic

Definition at line 267 of file KoColorSpaceTraits.h.

267 {
268 if (alpha_pos < 0) return;
269
270 for (; nPixels > 0; --nPixels, pixels += pixelSize, ++alpha) {
271 memcpy(pixels, brushColor, pixelSize);
273 *(nativeArray(pixels) + alpha_pos) = valpha;
274 }
275 }

References KoColorSpaceTrait< _channels_type_, _channels_nb_, _alpha_pos_ >::alpha_pos, KoColorSpaceTrait< _channels_type_, _channels_nb_, _alpha_pos_ >::nativeArray(), and KoColorSpaceTrait< _channels_type_, _channels_nb_, _alpha_pos_ >::pixelSize.

◆ fromNormalisedChannelsValue()

template<typename _channels_type_ , int _channels_nb_, int _alpha_pos_>
static void KoColorSpaceTrait< _channels_type_, _channels_nb_, _alpha_pos_ >::fromNormalisedChannelsValue ( quint8 * pixel,
const QVector< float > & values )
inlinestatic

Definition at line 185 of file KoColorSpaceTraits.h.

186 {
187 return fromNormalisedChannelsValueImpl<channels_type>(pixel, values);
188 }

◆ fromNormalisedChannelsValueImpl() [1/2]

template<typename _channels_type_ , int _channels_nb_, int _alpha_pos_>
template<typename I , typename std::enable_if_t< std::numeric_limits< I >::is_integer, int > = 1>
static void KoColorSpaceTrait< _channels_type_, _channels_nb_, _alpha_pos_ >::fromNormalisedChannelsValueImpl ( quint8 * pixel,
const QVector< float > & values )
inlinestatic

Definition at line 191 of file KoColorSpaceTraits.h.

192 {
193 Q_ASSERT((int)values.count() >= (int)channels_nb);
195 const float *v = values.data();
196 for (uint i = 0; i < channels_nb; i++) {
197 float b = qBound(
201 c = (channels_type)b;
202 nativeArray(pixel)[i] = c;
203 }
204 }
qreal v
unsigned int uint

References KoColorSpaceTrait< _channels_type_, _channels_nb_, _alpha_pos_ >::channels_nb, KoColorSpaceTrait< _channels_type_, _channels_nb_, _alpha_pos_ >::nativeArray(), and v.

◆ fromNormalisedChannelsValueImpl() [2/2]

template<typename _channels_type_ , int _channels_nb_, int _alpha_pos_>
template<typename I , typename std::enable_if_t<!std::numeric_limits< I >::is_integer, int > = 1>
static void KoColorSpaceTrait< _channels_type_, _channels_nb_, _alpha_pos_ >::fromNormalisedChannelsValueImpl ( quint8 * pixel,
const QVector< float > & values )
inlinestatic

Definition at line 207 of file KoColorSpaceTraits.h.

208 {
209 Q_ASSERT((int)values.count() >= (int)channels_nb);
210 const float *v = values.data();
211 for (uint i = 0; i < channels_nb; i++) {
213 }
214 }

References KoColorSpaceTrait< _channels_type_, _channels_nb_, _alpha_pos_ >::channels_nb, KoColorSpaceTrait< _channels_type_, _channels_nb_, _alpha_pos_ >::nativeArray(), and v.

◆ multiplyAlpha()

template<typename _channels_type_ , int _channels_nb_, int _alpha_pos_>
static void KoColorSpaceTrait< _channels_type_, _channels_nb_, _alpha_pos_ >::multiplyAlpha ( quint8 * pixels,
quint8 alpha,
qint32 nPixels )
inlinestatic

◆ nativeArray() [1/2]

template<typename _channels_type_ , int _channels_nb_, int _alpha_pos_>
static const channels_type * KoColorSpaceTrait< _channels_type_, _channels_nb_, _alpha_pos_ >::nativeArray ( const quint8 * a)
inlinestatic

Convenient function for transforming a quint8* array in a pointer of the native channels type

Definition at line 116 of file KoColorSpaceTraits.h.

116 {
117 return reinterpret_cast<const channels_type*>(a);
118 }

◆ nativeArray() [2/2]

template<typename _channels_type_ , int _channels_nb_, int _alpha_pos_>
static channels_type * KoColorSpaceTrait< _channels_type_, _channels_nb_, _alpha_pos_ >::nativeArray ( quint8 * a)
inlinestatic

Convenient function for transforming a quint8* array in a pointer of the native channels type

Definition at line 123 of file KoColorSpaceTraits.h.

123 {
124 return reinterpret_cast< channels_type*>(a);
125 }

◆ normalisedChannelsValue()

template<typename _channels_type_ , int _channels_nb_, int _alpha_pos_>
static void KoColorSpaceTrait< _channels_type_, _channels_nb_, _alpha_pos_ >::normalisedChannelsValue ( const quint8 * pixel,
QVector< float > & v )
inlinestatic

Definition at line 158 of file KoColorSpaceTraits.h.

159 {
160 return normalisedChannelsValueImpl<channels_type>(pixel, v);
161 }

References v.

◆ normalisedChannelsValueImpl() [1/2]

template<typename _channels_type_ , int _channels_nb_, int _alpha_pos_>
template<typename I , typename std::enable_if_t< std::numeric_limits< I >::is_integer, int > = 1>
static void KoColorSpaceTrait< _channels_type_, _channels_nb_, _alpha_pos_ >::normalisedChannelsValueImpl ( const quint8 * pixel,
QVector< float > & v )
inlinestatic

Definition at line 164 of file KoColorSpaceTraits.h.

165 {
166 Q_ASSERT((int)v.count() >= (int)channels_nb);
168 float *channels = v.data();
169 for (uint i = 0; i < channels_nb; i++) {
170 c = nativeArray(pixel)[i];
171 channels[i] = ((float)c) / KoColorSpaceMathsTraits<channels_type>::unitValue;
172 }
173 }

References KoColorSpaceTrait< _channels_type_, _channels_nb_, _alpha_pos_ >::channels_nb, KoColorSpaceTrait< _channels_type_, _channels_nb_, _alpha_pos_ >::nativeArray(), and v.

◆ normalisedChannelsValueImpl() [2/2]

template<typename _channels_type_ , int _channels_nb_, int _alpha_pos_>
template<typename I , typename std::enable_if_t<!std::numeric_limits< I >::is_integer, int > = 1>
static void KoColorSpaceTrait< _channels_type_, _channels_nb_, _alpha_pos_ >::normalisedChannelsValueImpl ( const quint8 * pixel,
QVector< float > & v )
inlinestatic

Definition at line 176 of file KoColorSpaceTraits.h.

177 {
178 Q_ASSERT((int)v.count() >= (int)channels_nb);
179 float *channels = v.data();
180 for (uint i = 0; i < channels_nb; i++) {
181 channels[i] = float(nativeArray(pixel)[i]);
182 }
183 }

References KoColorSpaceTrait< _channels_type_, _channels_nb_, _alpha_pos_ >::channels_nb, KoColorSpaceTrait< _channels_type_, _channels_nb_, _alpha_pos_ >::nativeArray(), and v.

◆ normalisedChannelValueText()

template<typename _channels_type_ , int _channels_nb_, int _alpha_pos_>
static QString KoColorSpaceTrait< _channels_type_, _channels_nb_, _alpha_pos_ >::normalisedChannelValueText ( const quint8 * pixel,
quint32 channelIndex )
inlinestatic

Definition at line 152 of file KoColorSpaceTraits.h.

152 {
153 if (channelIndex > channels_nb) return QString("Error");
154 channels_type c = nativeArray(pixel)[channelIndex];
155 return QString().setNum(100. *((qreal)c) / KoColorSpaceMathsTraits< channels_type>::unitValue);
156 }

References KoColorSpaceTrait< _channels_type_, _channels_nb_, _alpha_pos_ >::channels_nb, and KoColorSpaceTrait< _channels_type_, _channels_nb_, _alpha_pos_ >::nativeArray().

◆ opacityF()

template<typename _channels_type_ , int _channels_nb_, int _alpha_pos_>
static qreal KoColorSpaceTrait< _channels_type_, _channels_nb_, _alpha_pos_ >::opacityF ( const quint8 * U8_pixel)
inlinestatic

◆ opacityU8()

template<typename _channels_type_ , int _channels_nb_, int _alpha_pos_>
static quint8 KoColorSpaceTrait< _channels_type_, _channels_nb_, _alpha_pos_ >::opacityU8 ( const quint8 * U8_pixel)
inlinestatic

◆ setOpacity() [1/2]

template<typename _channels_type_ , int _channels_nb_, int _alpha_pos_>
static void KoColorSpaceTrait< _channels_type_, _channels_nb_, _alpha_pos_ >::setOpacity ( quint8 * pixels,
qreal alpha,
qint32 nPixels )
inlinestatic

◆ setOpacity() [2/2]

template<typename _channels_type_ , int _channels_nb_, int _alpha_pos_>
static void KoColorSpaceTrait< _channels_type_, _channels_nb_, _alpha_pos_ >::setOpacity ( quint8 * pixels,
quint8 alpha,
qint32 nPixels )
inlinestatic

Set the alpha channel for this pixel from a value in the 0..255 range

Definition at line 83 of file KoColorSpaceTraits.h.

83 {
84 if (alpha_pos < 0) return;
85 qint32 psize = pixelSize;
87 for (; nPixels > 0; --nPixels, pixels += psize) {
88 nativeArray(pixels)[alpha_pos] = valpha;
89 }
90 }

References KoColorSpaceTrait< _channels_type_, _channels_nb_, _alpha_pos_ >::alpha_pos, KoColorSpaceTrait< _channels_type_, _channels_nb_, _alpha_pos_ >::nativeArray(), KoColorSpaceTrait< _channels_type_, _channels_nb_, _alpha_pos_ >::pixelSize, and KoColorSpaceMaths< _T, _Tdst >::scaleToA().

◆ singleChannelPixel()

template<typename _channels_type_ , int _channels_nb_, int _alpha_pos_>
static void KoColorSpaceTrait< _channels_type_, _channels_nb_, _alpha_pos_ >::singleChannelPixel ( quint8 * dstPixel,
const quint8 * srcPixel,
quint32 channelIndex )
inlinestatic

Definition at line 134 of file KoColorSpaceTraits.h.

134 {
135 const channels_type* src = nativeArray(srcPixel);
136 channels_type* dst = nativeArray(dstPixel);
137 for (uint i = 0; i < channels_nb; i++) {
138 if (i != channelIndex) {
139 dst[i] = 0;
140 } else {
141 dst[i] = src[i];
142 }
143 }
144 }

References KoColorSpaceTrait< _channels_type_, _channels_nb_, _alpha_pos_ >::channels_nb, and KoColorSpaceTrait< _channels_type_, _channels_nb_, _alpha_pos_ >::nativeArray().

Member Data Documentation

◆ alpha_pos

template<typename _channels_type_ , int _channels_nb_, int _alpha_pos_>
const qint32 KoColorSpaceTrait< _channels_type_, _channels_nb_, _alpha_pos_ >::alpha_pos = _alpha_pos_
static

the position of the alpha channel in the channels of the pixel (or -1 if no alpha channel.

Definition at line 52 of file KoColorSpaceTraits.h.

◆ channels_nb

template<typename _channels_type_ , int _channels_nb_, int _alpha_pos_>
const quint32 KoColorSpaceTrait< _channels_type_, _channels_nb_, _alpha_pos_ >::channels_nb = _channels_nb_
static

the number of channels in this color space

Definition at line 48 of file KoColorSpaceTraits.h.

◆ depth

template<typename _channels_type_ , int _channels_nb_, int _alpha_pos_>
const int KoColorSpaceTrait< _channels_type_, _channels_nb_, _alpha_pos_ >::depth = KoColorSpaceMathsTraits<_channels_type_>::bits
static

the number of bit for each channel

Definition at line 55 of file KoColorSpaceTraits.h.

◆ pixelSize

template<typename _channels_type_ , int _channels_nb_, int _alpha_pos_>
const quint32 KoColorSpaceTrait< _channels_type_, _channels_nb_, _alpha_pos_ >::pixelSize = channels_nb * sizeof(channels_type)
static
Returns
the size in byte of one pixel

Definition at line 63 of file KoColorSpaceTraits.h.


The documentation for this struct was generated from the following file: