File indexing completed on 2024-09-22 04:08:30

0001 /*
0002  *  SPDX-FileCopyrightText: 2022 Dmitry Kazakov <dimula73@gmail.com>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 #include "KisDynamicSensor.h"
0007 
0008 #include <kis_algebra_2d.h>
0009 #include <KisSensorData.h>
0010 
0011 KisDynamicSensor::KisDynamicSensor(const KoID &id,
0012                                      const KisSensorData &data,
0013                                      std::optional<KisCubicCurve> curveOverride)
0014     : m_id(id),
0015       m_curve(curveOverride ?
0016                   *curveOverride :
0017                   KisCubicCurve(data.curve))
0018 {
0019     KIS_SAFE_ASSERT_RECOVER_NOOP(id == data.id);
0020 
0021     if (m_curve->isIdentity()) {
0022         m_curve = std::nullopt;
0023     }
0024 }
0025 
0026 KisDynamicSensor::~KisDynamicSensor()
0027 {
0028 }
0029 
0030 KoID KisDynamicSensor::id() const
0031 {
0032     return m_id;
0033 }
0034 
0035 qreal KisDynamicSensor::parameter(const KisPaintInformation &info) const
0036 {
0037     const qreal val = value(info);
0038     if (m_curve) {
0039         qreal scaledVal = isAdditive() ? additiveToScaling(val) :
0040                           isAbsoluteRotation() ? KisAlgebra2D::wrapValue(val + 0.5, 0.0, 1.0) : val;
0041 
0042         const QVector<qreal> transfer = m_curve->floatTransfer(256);
0043         scaledVal = KisCubicCurve::interpolateLinear(scaledVal, transfer);
0044 
0045         return isAdditive() ? scalingToAdditive(scaledVal) :
0046                isAbsoluteRotation() ? KisAlgebra2D::wrapValue(scaledVal + 0.5, 0.0, 1.0) : scaledVal;
0047     }
0048     else {
0049         return val;
0050     }
0051 }
0052 
0053 bool KisDynamicSensor::isAdditive() const
0054 {
0055     return false;
0056 }
0057 
0058 bool KisDynamicSensor::isAbsoluteRotation() const
0059 {
0060     return false;
0061 }