9#include <QRegularExpression>
29 , m_transfers(rhs.m_transfers)
30 , m_lightnessTransfer(rhs.m_lightnessTransfer)
55 const QString levelsCurveStr =
getString(
"lightness",
"");
61 for (
int i = 0; i < newLevelsCurves.size(); ++i) {
77 for (
int i = 0; i < lc.size(); i++) {
101 const QString mode =
getString(
"mode",
"");
102 if (mode ==
"lightness") {
104 }
else if (mode ==
"channels") {
112 const QString mode =
getString(
"histogram_mode",
"");
113 if (mode ==
"logarithmic") {
115 }
else if (mode ==
"linear") {
123 setProperty(
"mode", newUseLightnessMode ?
"lightness" :
"channels");
128 setProperty(
"histogram_mode", newShowLogarithmicHistogram ?
"logarithmic" :
"linear");
142 const double inputBlackPoint =
static_cast<double>(
getInt(
"blackvalue", 0)) / 255.0;
143 const double inputWhitePoint =
static_cast<double>(
getInt(
"whitevalue", 255)) / 255.0;
144 const double inputGamma =
getDouble(
"gammavalue", 1.0);
145 const double outputBlackPoint =
static_cast<double>(
getInt(
"outblackvalue", 0)) / 255.0;
146 const double outputWhitePoint =
static_cast<double>(
getInt(
"outwhitevalue", 255)) / 255.0;
149 KisLevelsCurve(inputBlackPoint, inputWhitePoint, inputGamma, outputBlackPoint, outputWhitePoint).toString()
186 if (
name ==
"lightness") {
189 }
else if (
name ==
"blackvalue" ||
name ==
"whitevalue" ||
name ==
"gammavalue" ||
190 name ==
"outblackvalue" ||
name ==
"outwhitevalue") {
193 }
else if (QRegularExpression(
"channel_\\d+").match(
name).hasMatch()) {
200 return getInt(
"number_of_channels", 0);
205 setProperty(
"number_of_channels", newChannelCount);
216 version = root.attribute(
"version").toInt();
218 QDomElement e = root.firstChild().toElement();
219 QString attributeName;
226 while (!e.isNull()) {
227 attributeName = e.attribute(
"name");
228 if (attributeName ==
"gammavalue") {
233 if (attributeName ==
"blackvalue") {
235 }
else if (attributeName ==
"whitevalue") {
237 }
else if (attributeName ==
"outblackvalue") {
239 }
else if (attributeName ==
"outwhitevalue") {
243 e = e.nextSiblingElement();
247 QHash<int, KisLevelsCurve> unsortedLevelsCurves;
250 while (!e.isNull()) {
251 attributeName = e.attribute(
"name");
252 if (attributeName ==
"mode") {
253 lightnessMode = e.text() !=
"channels";
254 }
else if (attributeName ==
"histogram_mode") {
255 logarithmicHistogram = e.text() ==
"logarithmic";
256 }
else if (attributeName ==
"lightness") {
258 }
else if (attributeName ==
"number_of_channels") {
259 numChannels = e.text().toInt();
261 const QRegularExpression rx(
"channel_(\\d+)");
262 const QRegularExpressionMatch match = rx.match(attributeName);
263 if (match.hasMatch()) {
264 const int index = match.captured(1).toInt();
265 if (!e.text().isEmpty()) {
267 unsortedLevelsCurves[index] = levelsCurve;
271 e = e.nextSiblingElement();
274 for (
int i = 0; i < numChannels; ++i) {
275 if (unsortedLevelsCurves.contains(i)) {
293 const QString &
value,
294 bool internal =
false)
296 QDomText text = doc.createTextNode(
value);
297 QDomElement t = doc.createElement(
"param");
298 t.setAttribute(
"name", name);
300 t.setAttribute(
"type",
"internal");
334 root.setAttribute(
"version",
version());
345 for (
int i = 0; i < levelsCurves_.size(); ++i) {
347 const QString
value = levelsCurves_[i].toString();
float value(const T *src, size_t ch)
void addParamNode(QDomDocument &doc, QDomElement &root, const QString &name, const QString &value, bool internal=false)
This class holds the parameters for a levels adjustment. It is modeled after KisCubicCurve and has si...
qreal outputBlackPoint() const
Get the output black point.
void setOutputBlackPoint(qreal newOutputBlackPoint)
Set the output black point.
qreal inputBlackPoint() const
Get the input black point.
void setOutputWhitePoint(qreal newOutputWhitePoint)
Set the output white point.
qreal inputGamma() const
Get the gamma value.
const QVector< quint16 > & uint16Transfer(int size=256) const
Returns a vector of size.
qreal inputWhitePoint() const
Get the input white point.
void setInputGamma(qreal newInputGamma)
Set the gamma value.
void setInputWhitePoint(qreal newInputWhitePoint)
Set the input white point.
QString toString() const
Get a text representation of the parameters. The format is: "input_black_point;input_white_point;inpu...
void fromString(const QString &text, bool *ok=nullptr)
Parses the parameters from a given text.
qreal outputWhitePoint() const
Get the output white point.
void setInputBlackPoint(qreal newInputBlackPoint)
Set the input black point.
bool useLightnessMode() const
void setLevelsCurves(const QVector< KisLevelsCurve > &newLevelsCurves)
const KisLevelsCurve lightnessLevelsCurve() const
QVector< QVector< quint16 > > m_transfers
KisFilterConfigurationSP clone() const override
void setProperty(const QString &name, const QVariant &value) override
void fromLegacyXML(const QDomElement &root) override
static constexpr bool defaultShowLogarithmicHistogram()
void setShowLogarithmicHistogram(bool newShowLogarithmicHistogram)
void updateLightnessTransfer()
static KisLevelsCurve defaultLevelsCurve()
static constexpr bool defaultUseLightnessMode()
QVector< quint16 > m_lightnessTransfer
const QVector< KisLevelsCurve > levelsCurves() const
void setUseLightnessMode(bool newUseLightnessMode)
void setLegacyValuesFromLightnessLevelsCurve()
void setLightnessLevelsCurve(const KisLevelsCurve &newLightnessLevelsCurve)
QString toXML() const override
const QVector< QVector< quint16 > > & transfers() const
void setChannelCount(int newChannelCount)
bool showLogarithmicHistogram() const
void setLightessLevelsCurveFromLegacyValues()
static constexpr qint32 defaultVersion()
const QVector< quint16 > & lightnessTransfer() const
bool isCompatible(const KisPaintDeviceSP) const override
void fromXML(const QDomElement &e) override
KisLevelsFilterConfiguration(int channelCount, qint32 version, KisResourcesInterfaceSP resourcesInterface)
virtual const KoColorSpace * compositionSourceColorSpace() const
virtual quint32 channelCount() const =0
void addParamNode(QDomDocument &doc, QDomElement &root, const QString &name, const QString &value)
double toDouble(const QString &str, bool *ok=nullptr)
QString toString(const QString &value)
void setVersion(qint32 version)
QString getString(const QString &name, const QString &def=QString()) const
int getInt(const QString &name, int def=0) const
double getDouble(const QString &name, double def=0.0) const