Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_normalize.cpp
Go to the documentation of this file.
1/*
2 *
3 * SPDX-FileCopyrightText: 2015 Wolthera van Hövell tot Westerflier <griffinvalley@gmail.com>
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7#include "kis_normalize.h"
8#include <stdlib.h>
9#include <vector>
10
11#include <QPoint>
12#include <QTime>
13#include <QVector3D>
14
15#include <kpluginfactory.h>
16#include <klocalizedstring.h>
17
18#include <kis_debug.h>
19
21#include <kis_types.h>
22#include <kis_selection.h>
23#include <kis_layer.h>
26#include <kis_global.h>
27
28#include <KoColorSpaceMaths.h>
30
31K_PLUGIN_FACTORY_WITH_JSON(KritaNormalizeFilterFactory, "kritanormalize.json", registerPlugin<KritaNormalizeFilter>();)
32
33KritaNormalizeFilter::KritaNormalizeFilter(QObject *parent, const QVariantList &)
34 : QObject(parent)
35{
37}
38
42
43
52
54{
55 Q_UNUSED(config);
56 return new KisNormalizeTransformation(cs);
57}
58
59KisNormalizeTransformation::KisNormalizeTransformation(const KoColorSpace* cs) : m_colorSpace(cs), m_psize(cs->pixelSize())
60{
61
62}
63
64void KisNormalizeTransformation::transform(const quint8* src, quint8* dst, qint32 nPixels) const
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}
124
125#include "kis_normalize.moc"
@ FULLY_INDEPENDENT
KoColorTransformation * createTransformation(const KoColorSpace *cs, const KisFilterConfigurationSP config) const override
void add(KisFilterSP item)
static KisFilterRegistry * instance()
void transform(const quint8 *src, quint8 *dst, qint32 nPixels) const override
KisNormalizeTransformation(const KoColorSpace *cs)
const KoColorSpace * m_colorSpace
virtual quint32 pixelSize() const =0
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
Definition KoID.h:30
~KritaNormalizeFilter() override
KritaNormalizeFilter(QObject *parent, const QVariantList &)
K_PLUGIN_FACTORY_WITH_JSON(KritaASCCDLFactory, "kritaasccdl.json", registerPlugin< KritaASCCDL >();) KritaASCCDL
const KoID FiltersCategoryMapId("map_filters", ki18nc("The category of mapping filters, like bump map or gradient filter map. Verb.", "Map"))
KisSharedPtr< KisFilter > KisFilterSP
Definition kis_types.h:167
void setShowConfigurationWidget(bool v)
void setSupportsPainting(bool v)
void setColorSpaceIndependence(ColorSpaceIndependence v)