Krita Source Code Documentation
Loading...
Searching...
No Matches
KisNormalizeTransformation Class Reference

#include <kis_normalize.h>

+ Inheritance diagram for KisNormalizeTransformation:

Public Member Functions

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

Private Attributes

const KoColorSpacem_colorSpace
 
quint32 m_psize
 

Detailed Description

Definition at line 30 of file kis_normalize.h.

Constructor & Destructor Documentation

◆ KisNormalizeTransformation()

KisNormalizeTransformation::KisNormalizeTransformation ( const KoColorSpace * cs)

Definition at line 59 of file kis_normalize.cpp.

59 : m_colorSpace(cs), m_psize(cs->pixelSize())
60{
61
62}
const KoColorSpace * m_colorSpace
virtual quint32 pixelSize() const =0

Member Function Documentation

◆ transform()

void KisNormalizeTransformation::transform ( const quint8 * src,
quint8 * dst,
qint32 nPixels ) const
overridevirtual

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 64 of file kis_normalize.cpp.

65{
66 // if the color space is not RGBA o something like that, just
67 // pass the values through
68 if (m_colorSpace->channelCount() != 4) {
69 memcpy(dst, src, nPixels * m_colorSpace->pixelSize());
70 return;
71 }
72
73 QVector3D normal_vector;
74 QVector<float> channelValues(4);
75 //if (m_colorSpace->colorDepthId().id()!="F16" && m_colorSpace->colorDepthId().id()!="F32" && m_colorSpace->colorDepthId().id()!="F64") {
76 /* I don't know why, but the results of this are unexpected with a floating point space.
77 * And manipulating the pixels gives strange results.
78 */
79 while (nPixels--) {
80 m_colorSpace->normalisedChannelsValue(src, channelValues);
81 normal_vector.setX(channelValues[2]*2-1.0);
82 normal_vector.setY(channelValues[1]*2-1.0);
83 normal_vector.setZ(channelValues[0]*2-1.0);
84 normal_vector.normalize();
85
86 channelValues[0]=normal_vector.z()*0.5+0.5;
87 channelValues[1]=normal_vector.y()*0.5+0.5;
88 channelValues[2]=normal_vector.x()*0.5+0.5;
89 //channelValues[3]=1.0;
90
91 m_colorSpace->fromNormalisedChannelsValue(dst, channelValues);
92
93 dst[3]=src[3];
94 src += m_psize;
95 dst += m_psize;
96 }
97 /* } else {
98 while (nPixels--) {
99 m_colorSpace->normalisedChannelsValue(src, channelValues);
100 qreal max = qMax(channelValues[2], qMax(channelValues[1], channelValues[0]));
101 qreal min = qMin(channelValues[2], qMin(channelValues[1], channelValues[0]));
102 qreal range = max-min;
103 normal_vector.setX( ((channelValues[2]-min)/range) *2.0-1.0);
104 normal_vector.setY( ((channelValues[1]-min)/range) *2.0-1.0);
105 normal_vector.setZ( ((channelValues[0]-min)/range) *2.0-1.0);
106 normal_vector.normalize();
107
108 channelValues[2]=normal_vector.x()*0.5+0.5;
109 channelValues[1]=normal_vector.y()*0.5+0.5;
110 channelValues[0]=normal_vector.z()*0.5+0.5;
111 //channelValues[3]=1.0;
112
113 m_colorSpace->fromNormalisedChannelsValue(dst, channelValues);
114 dst[3]=src[3];
115 //hack to truncate values.
116 m_colorSpace->toRgbA16(dst, reinterpret_cast<quint8 *>(m_rgba), 1);
117 m_colorSpace->fromRgbA16(reinterpret_cast<quint8 *>(m_rgba), dst, 1);
118
119 src += m_psize;
120 dst += m_psize;
121 }
122 }*/
123}
virtual quint32 channelCount() const =0
virtual void normalisedChannelsValue(const quint8 *pixel, QVector< float > &channels) const =0
virtual void fromNormalisedChannelsValue(quint8 *pixel, const QVector< float > &values) const =0

References KoColorSpace::channelCount(), KoColorSpace::fromNormalisedChannelsValue(), m_colorSpace, m_psize, KoColorSpace::normalisedChannelsValue(), and KoColorSpace::pixelSize().

Member Data Documentation

◆ m_colorSpace

const KoColorSpace* KisNormalizeTransformation::m_colorSpace
private

Definition at line 36 of file kis_normalize.h.

◆ m_psize

quint32 KisNormalizeTransformation::m_psize
private

Definition at line 37 of file kis_normalize.h.


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