Krita Source Code Documentation
Loading...
Searching...
No Matches
KisDesaturateAdjustment< _channel_type_, traits > Class Template Reference
+ Inheritance diagram for KisDesaturateAdjustment< _channel_type_, traits >:

Public Member Functions

 KisDesaturateAdjustment ()
 
int parameterId (const QString &name) const override
 
QList< QString > parameters () const override
 
void setParameter (int id, const QVariant &parameter) override
 
void transform (const quint8 *srcU8, quint8 *dstU8, qint32 nPixels) const override
 
- Public Member Functions inherited from KoColorTransformation
virtual bool isValid () const
 
void setParameters (const QHash< QString, QVariant > &parameters)
 
virtual ~KoColorTransformation ()
 

Private Types

typedef RGBTrait::Pixel RGBPixel
 
typedef traits RGBTrait
 

Private Attributes

int m_type {0}
 

Detailed Description

template<typename _channel_type_, typename traits>
class KisDesaturateAdjustment< _channel_type_, traits >

Definition at line 25 of file kis_desaturate_adjustment.cpp.

Member Typedef Documentation

◆ RGBPixel

template<typename _channel_type_ , typename traits >
typedef RGBTrait::Pixel KisDesaturateAdjustment< _channel_type_, traits >::RGBPixel
private

Definition at line 28 of file kis_desaturate_adjustment.cpp.

◆ RGBTrait

template<typename _channel_type_ , typename traits >
typedef traits KisDesaturateAdjustment< _channel_type_, traits >::RGBTrait
private

Definition at line 27 of file kis_desaturate_adjustment.cpp.

Constructor & Destructor Documentation

◆ KisDesaturateAdjustment()

template<typename _channel_type_ , typename traits >
KisDesaturateAdjustment< _channel_type_, traits >::KisDesaturateAdjustment ( )
inline

Definition at line 31 of file kis_desaturate_adjustment.cpp.

32 {
33 }

Member Function Documentation

◆ parameterId()

template<typename _channel_type_ , typename traits >
int KisDesaturateAdjustment< _channel_type_, traits >::parameterId ( const QString & name) const
inlineoverridevirtual

Get the parameter id for a parameter name

Reimplemented from KoColorTransformation.

Definition at line 105 of file kis_desaturate_adjustment.cpp.

106 {
107 if (name == "type") {
108 return 0;
109 }
110 return -1;
111 }

◆ parameters()

template<typename _channel_type_ , typename traits >
QList< QString > KisDesaturateAdjustment< _channel_type_, traits >::parameters ( ) const
inlineoverridevirtual
Returns
the list of parameters

Reimplemented from KoColorTransformation.

Definition at line 98 of file kis_desaturate_adjustment.cpp.

99 {
100 QList<QString> list;
101 list << "type";
102 return list;
103 }

◆ setParameter()

template<typename _channel_type_ , typename traits >
void KisDesaturateAdjustment< _channel_type_, traits >::setParameter ( int id,
const QVariant & parameter )
inlineoverridevirtual

name - "type": 0: lightness 1: luminosity 2: average

Reimplemented from KoColorTransformation.

Definition at line 119 of file kis_desaturate_adjustment.cpp.

120 {
121 switch(id)
122 {
123 case 0:
124 m_type = parameter.toDouble();
125 break;
126 default:
127 ;
128 }
129 }

References KisDesaturateAdjustment< _channel_type_, traits >::m_type.

◆ transform()

template<typename _channel_type_ , typename traits >
void KisDesaturateAdjustment< _channel_type_, traits >::transform ( const quint8 * src,
quint8 * dst,
qint32 nPixels ) const
inlineoverridevirtual

This function apply the transformation on a given number of pixels.

Parameters
srca pointer to the source pixels
dsta pointer to the destination pixels
nPixelsthe number of pixels

This function may or may not be thread safe. You need to create one KoColorTransformation per thread.

Implements KoColorTransformation.

Definition at line 37 of file kis_desaturate_adjustment.cpp.

38 {
39 const RGBPixel* src = reinterpret_cast<const RGBPixel*>(srcU8);
40 RGBPixel* dst = reinterpret_cast<RGBPixel*>(dstU8);
41 float r, g, b, gray;
42 while (nPixels > 0) {
43
44 r = SCALE_TO_FLOAT(src->red);
45 g = SCALE_TO_FLOAT(src->green);
46 b = SCALE_TO_FLOAT(src->blue);
47
48 // https://www.tannerhelland.com/3643/grayscale-image-algorithm-vb6/
49 switch(m_type) {
50 case 0: // lightness
51 {
52 gray = (qMax(qMax(r, g), b) + qMin(qMin(r, g), b)) / 2;
53 break;
54 }
55 case 1: // luminosity BT 709
56 {
57 gray = r * 0.2126 + g * 0.7152 + b * 0.0722;
58 break;
59
60 }
61
62 case 2: // luminosity BT 601
63 {
64 gray = r * 0.299 + g * 0.587 + b * 0.114;
65 break;
66
67 }
68 case 3: // average
69 {
70 gray = (r + g + b) / 3;
71 break;
72 }
73 case 4: // min
74 {
75 gray = qMin(qMin(r, g), b);
76 break;
77 }
78 case 5: // min
79 {
80 gray = qMax(qMax(r, g), b);
81 break;
82 }
83
84 default:
85 gray = 0;
86 }
87 dst->red = SCALE_FROM_FLOAT(gray);
88 dst->green = SCALE_FROM_FLOAT(gray);
89 dst->blue = SCALE_FROM_FLOAT(gray);
90 dst->alpha = src->alpha;
91
92 --nPixels;
93 ++src;
94 ++dst;
95 }
96 }
#define SCALE_FROM_FLOAT(v)
#define SCALE_TO_FLOAT(v)

References KisDesaturateAdjustment< _channel_type_, traits >::m_type, SCALE_FROM_FLOAT, and SCALE_TO_FLOAT.

Member Data Documentation

◆ m_type

template<typename _channel_type_ , typename traits >
int KisDesaturateAdjustment< _channel_type_, traits >::m_type {0}
private

Definition at line 133 of file kis_desaturate_adjustment.cpp.

133{0};

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