Krita Source Code Documentation
Loading...
Searching...
No Matches
KoLabTraits< _channels_type_ > Struct Template Reference

#include <KoLabColorSpaceTraits.h>

+ Inheritance diagram for KoLabTraits< _channels_type_ >:

Classes

struct  Pixel
 

Public Types

typedef _channels_type_ channels_type
 
typedef KoLabColorSpaceMathsTraits< channels_typemath_trait
 
typedef KoColorSpaceTrait< _channels_type_, 4, 3 > parent
 
- Public Types inherited from KoColorSpaceTrait< _channels_type_, 4, 3 >
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 channels_type a (quint8 *data)
 
static channels_type b (quint8 *data)
 
static void fromNormalisedChannelsValue (quint8 *pixel, const QVector< float > &values)
 
static channels_type L (quint8 *data)
 
static void normalisedChannelsValue (const quint8 *pixel, QVector< float > &v)
 
static QString normalisedChannelValueText (const quint8 *pixel, quint32 channelIndex)
 
static void setA (quint8 *data, channels_type nv)
 Set the a component.
 
static void setB (quint8 *data, channels_type nv)
 Set the a component.
 
static void setL (quint8 *data, channels_type nv)
 Set the L component.
 
- Static Public Member Functions inherited from KoColorSpaceTrait< _channels_type_, 4, 3 >
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)
 
static void fromNormalisedChannelsValueImpl (quint8 *pixel, const QVector< float > &values)
 
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)
 
static void normalisedChannelsValueImpl (const quint8 *pixel, QVector< float > &v)
 
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 a_pos = 1
 
static const qint32 b_pos = 2
 
static const qint32 L_pos = 0
 
- Static Public Attributes inherited from KoColorSpaceTrait< _channels_type_, 4, 3 >
static const qint32 alpha_pos
 
static const quint32 channels_nb
 the number of channels in this color space
 
static const int depth
 the number of bit for each channel
 
static const quint32 pixelSize
 

Detailed Description

template<typename _channels_type_>
struct KoLabTraits< _channels_type_ >

LAB traits, it provides some convenient functions to access LAB channels through an explicit API.

Use this class in conjunction with KoColorSpace::toLabA16 and KoColorSpace::fromLabA16 data.

Example: quint8* p = KoLabU16Traits::allocate(1); oneKoColorSpace->toLabA16(somepointertodata, p, 1); KoLabU16Traits::setL( p, KoLabU16Traits::L(p) / 10 ); oneKoColorSpace->fromLabA16(p, somepointertodata, 1);

Definition at line 27 of file KoLabColorSpaceTraits.h.

Member Typedef Documentation

◆ channels_type

template<typename _channels_type_ >
typedef _channels_type_ KoLabTraits< _channels_type_ >::channels_type

Definition at line 28 of file KoLabColorSpaceTraits.h.

◆ math_trait

template<typename _channels_type_ >
typedef KoLabColorSpaceMathsTraits<channels_type> KoLabTraits< _channels_type_ >::math_trait

Definition at line 30 of file KoLabColorSpaceTraits.h.

◆ parent

template<typename _channels_type_ >
typedef KoColorSpaceTrait<_channels_type_, 4, 3> KoLabTraits< _channels_type_ >::parent

Definition at line 29 of file KoLabColorSpaceTraits.h.

Member Function Documentation

◆ a()

template<typename _channels_type_ >
static channels_type KoLabTraits< _channels_type_ >::a ( quint8 * data)
inlinestatic
Returns
the a component

Definition at line 56 of file KoLabColorSpaceTraits.h.

56 {
58 return d[a_pos];
59 }
static const channels_type * nativeArray(const quint8 *a)
static const qint32 a_pos
_channels_type_ channels_type

References KoLabTraits< _channels_type_ >::a_pos, and KoColorSpaceTrait< _channels_type_, 4, 3 >::nativeArray().

◆ b()

template<typename _channels_type_ >
static channels_type KoLabTraits< _channels_type_ >::b ( quint8 * data)
inlinestatic
Returns
the b component

Definition at line 66 of file KoLabColorSpaceTraits.h.

66 {
68 return d[b_pos];
69 }
static const qint32 b_pos

References KoLabTraits< _channels_type_ >::b_pos, and KoColorSpaceTrait< _channels_type_, 4, 3 >::nativeArray().

◆ fromNormalisedChannelsValue()

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

Definition at line 125 of file KoLabColorSpaceTraits.h.

126 {
127 Q_ASSERT((int)values.count() >= (int)parent::channels_nb);
129 for (uint i = 0; i < parent::channels_nb; i++) {
130 float b = 0;
131 switch (i) {
132 case L_pos:
133 b = qBound((float)math_trait::zeroValueL,
134 (float)math_trait::unitValueL * values[i],
135 (float)math_trait::unitValueL);
136 break;
137 case a_pos:
138 case b_pos:
139 if (values[i] <= 0.5) {
140 b = qBound((float)math_trait::zeroValueAB,
141 (float)(math_trait::zeroValueAB + 2.0 * values[i] * (math_trait::halfValueAB - math_trait::zeroValueAB)),
142 (float)math_trait::halfValueAB);
143 }
144 else {
145 b = qBound((float)math_trait::halfValueAB,
146 (float)(math_trait::halfValueAB + 2.0 * (values[i] - 0.5) * (math_trait::unitValueAB - math_trait::halfValueAB)),
147 (float)math_trait::unitValueAB);
148 }
149 break;
150 case 3:
151 b = qBound((float)math_trait::min,
152 (float)math_trait::unitValue * values[i],
153 (float)math_trait::unitValue);
154 default:
155 break;
156 }
157 c = (channels_type)b;
158 parent::nativeArray(pixel)[i] = c;
159 }
160 }
unsigned int uint
static const quint32 channels_nb
the number of channels in this color space
static channels_type b(quint8 *data)
static const qint32 L_pos

References KoLabTraits< _channels_type_ >::a_pos, KoLabTraits< _channels_type_ >::b(), KoLabTraits< _channels_type_ >::b_pos, KoColorSpaceTrait< _channels_type_, 4, 3 >::channels_nb, KoLabTraits< _channels_type_ >::L_pos, and KoColorSpaceTrait< _channels_type_, 4, 3 >::nativeArray().

◆ L()

template<typename _channels_type_ >
static channels_type KoLabTraits< _channels_type_ >::L ( quint8 * data)
inlinestatic
Returns
the L component

Definition at line 46 of file KoLabColorSpaceTraits.h.

46 {
48 return d[L_pos];
49 }

References KoLabTraits< _channels_type_ >::L_pos, and KoColorSpaceTrait< _channels_type_, 4, 3 >::nativeArray().

◆ normalisedChannelsValue()

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

Definition at line 98 of file KoLabColorSpaceTraits.h.

99 {
100 Q_ASSERT((int)v.count() >= (int)parent::channels_nb);
102 float *channels = v.data();
103 for (uint i = 0; i < parent::channels_nb; i++) {
104 c = parent::nativeArray(pixel)[i];
105 switch (i) {
106 case L_pos:
107 channels[i] = (qreal)c / math_trait::unitValueL;
108 break;
109 case a_pos:
110 case b_pos:
111 if (c <= math_trait::halfValueAB) {
112 channels[i] = ((qreal)c - math_trait::zeroValueAB) / (2.0 * (math_trait::halfValueAB - math_trait::zeroValueAB));
113 } else {
114 channels[i] = 0.5 + ((qreal)c - math_trait::halfValueAB) / (2.0 * (math_trait::unitValueAB - math_trait::halfValueAB));
115 }
116 break;
117 // As per KoChannelInfo alpha channels are [0..1]
118 case 3:
119 default:
120 channels[i] = (qreal)c / math_trait::unitValue;
121 break;
122 }
123 }
124 }
qreal v

References KoLabTraits< _channels_type_ >::a_pos, KoLabTraits< _channels_type_ >::b_pos, KoColorSpaceTrait< _channels_type_, 4, 3 >::channels_nb, KoLabTraits< _channels_type_ >::L_pos, KoColorSpaceTrait< _channels_type_, 4, 3 >::nativeArray(), and v.

◆ normalisedChannelValueText()

template<typename _channels_type_ >
static QString KoLabTraits< _channels_type_ >::normalisedChannelValueText ( const quint8 * pixel,
quint32 channelIndex )
inlinestatic

Definition at line 77 of file KoLabColorSpaceTraits.h.

78 {
79 if (channelIndex > parent::channels_nb)
80 return QString("Error");
81 channels_type c = parent::nativeArray(pixel)[channelIndex];
82 switch (channelIndex) {
83 case L_pos:
84 return QString().setNum(100.0 * qBound((qreal)0, ((qreal)c) / math_trait::unitValueL, (qreal)math_trait::unitValueL));
85 case a_pos:
86 case b_pos:
87 if (c <= math_trait::halfValueAB) {
88 return QString().setNum(100.0 * (qreal)((c - math_trait::zeroValueAB) / (2.0 * (math_trait::halfValueAB - math_trait::zeroValueAB))));
89 } else {
90 return QString().setNum(100.0 * (qreal)(0.5 + (c - math_trait::halfValueAB) / (2.0 * (math_trait::unitValueAB - math_trait::halfValueAB))));
91 }
92 case 3:
93 return QString().setNum(100.0 * qBound((qreal)0, ((qreal)c) / math_trait::unitValue, (qreal)math_trait::unitValue));
94 default:
95 return QString("Error");
96 }
97 }

References KoLabTraits< _channels_type_ >::a_pos, KoLabTraits< _channels_type_ >::b_pos, KoColorSpaceTrait< _channels_type_, 4, 3 >::channels_nb, KoLabTraits< _channels_type_ >::L_pos, and KoColorSpaceTrait< _channels_type_, 4, 3 >::nativeArray().

◆ setA()

template<typename _channels_type_ >
static void KoLabTraits< _channels_type_ >::setA ( quint8 * data,
channels_type nv )
inlinestatic

Set the a component.

Definition at line 61 of file KoLabColorSpaceTraits.h.

61 {
63 d[a_pos] = nv;
64 }

References KoLabTraits< _channels_type_ >::a_pos, and KoColorSpaceTrait< _channels_type_, 4, 3 >::nativeArray().

◆ setB()

template<typename _channels_type_ >
static void KoLabTraits< _channels_type_ >::setB ( quint8 * data,
channels_type nv )
inlinestatic

Set the a component.

Definition at line 71 of file KoLabColorSpaceTraits.h.

71 {
73 d[b_pos] = nv;
74 }

References KoLabTraits< _channels_type_ >::b_pos, and KoColorSpaceTrait< _channels_type_, 4, 3 >::nativeArray().

◆ setL()

template<typename _channels_type_ >
static void KoLabTraits< _channels_type_ >::setL ( quint8 * data,
channels_type nv )
inlinestatic

Set the L component.

Definition at line 51 of file KoLabColorSpaceTraits.h.

51 {
53 d[L_pos] = nv;
54 }

References KoLabTraits< _channels_type_ >::L_pos, and KoColorSpaceTrait< _channels_type_, 4, 3 >::nativeArray().

Member Data Documentation

◆ a_pos

template<typename _channels_type_ >
const qint32 KoLabTraits< _channels_type_ >::a_pos = 1
static

Definition at line 32 of file KoLabColorSpaceTraits.h.

◆ b_pos

template<typename _channels_type_ >
const qint32 KoLabTraits< _channels_type_ >::b_pos = 2
static

Definition at line 33 of file KoLabColorSpaceTraits.h.

◆ L_pos

template<typename _channels_type_ >
const qint32 KoLabTraits< _channels_type_ >::L_pos = 0
static

Definition at line 31 of file KoLabColorSpaceTraits.h.


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