Commit 6ed82cac authored by Dmitry Kazakov's avatar Dmitry Kazakov
Browse files

Added an option for switching between Subtract and Multiply modes of the texturing

1) Added a switch  Subtract/Multiply
2) Removed the Strength slider. Now the curve is used for
   it (backward-compatible).

CCBUG:313831
parent bba9188e
......@@ -21,7 +21,7 @@
#include <klocale.h>
KisPressureTextureStrengthOption::KisPressureTextureStrengthOption()
: KisCurveOption(i18n("Strength"), "Texture/Strength", KisPaintOpOption::textureCategory(), false)
: KisCurveOption(i18n("Strength"), "Texture/Strength/", KisPaintOpOption::textureCategory(), false)
{
setMinimumLabel(i18n("Weak"));
setMaximumLabel(i18n("Strong"));
......@@ -32,3 +32,37 @@ double KisPressureTextureStrengthOption::apply(const KisPaintInformation & info)
if (!isChecked()) return 1.0;
return computeValue(info);
}
void KisPressureTextureStrengthOption::readOptionSetting(const KisPropertiesConfiguration* setting)
{
KisCurveOption::readOptionSetting(setting);
/**
* Backward compatibility with Krita < 2.7.
*
* Process the presets created with the old UI, when the
* strength was a part of Texture/Pattern option.
*/
int strengthVersion = setting->getInt("Texture/Strength/StrengthVersion", 1);
if (strengthVersion == 1) {
double legacyStrength = setting->getDouble("Texture/Pattern/Strength", 1.0);
setChecked(true);
setValue(legacyStrength);
}
}
void KisPressureTextureStrengthOption::writeOptionSetting(KisPropertiesConfiguration* setting) const
{
KisCurveOption::writeOptionSetting(setting);
/**
* Forward compatibility with the Krita < 2.7
*
* Duplicate the value of the maximum strength into the
* property used by older versions of Krita.
*/
setting->setProperty("Texture/Strength/StrengthVersion", 2);
if (isChecked()) {
setting->setProperty("Texture/Pattern/Strength", value());
}
}
......@@ -33,6 +33,9 @@ class PAINTOP_EXPORT KisPressureTextureStrengthOption : public KisCurveOption
public:
KisPressureTextureStrengthOption();
double apply(const KisPaintInformation & info) const;
void readOptionSetting(const KisPropertiesConfiguration* setting);
void writeOptionSetting(KisPropertiesConfiguration* setting) const;
};
#endif /* __KIS_PRESSURE_TEXTURE_STRENGTH_OPTION_H */
......@@ -77,16 +77,18 @@ public:
offsetSliderY->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
formLayout->addRow(i18n("Vertical Offset:"), offsetSliderY);
strengthSlider = new KisDoubleSliderSpinBox(this);
strengthSlider->setRange(0.0, 1.0, 2);
strengthSlider->setValue(1);
strengthSlider->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
formLayout->addRow(i18n("Strength:"), strengthSlider);
cmbTexturingMode = new QComboBox(this);
cmbTexturingMode->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
QStringList texturingModes;
texturingModes << i18n("Multiply") << i18n("Subtract");
cmbTexturingMode->addItems(texturingModes);
formLayout->addRow(i18n("Texturing Mode:"), cmbTexturingMode);
cmbTexturingMode->setCurrentIndex(KisTextureProperties::SUBTRACT);
cmbCutoffPolicy = new QComboBox(this);
cmbCutoffPolicy->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
QStringList cutOffPolicies;
cutOffPolicies << i18n("Disregard Cutoff") << i18n("Mask Out") << i18n("Disregard Pattern");
cutOffPolicies << i18n("Cut Off Disabled") << i18n("Cut Off Brush") << i18n("Cut Off Pattern");
cmbCutoffPolicy->addItems(cutOffPolicies);
formLayout->addRow(i18n("Cutoff Policy"), cmbCutoffPolicy);
......@@ -108,7 +110,7 @@ public:
KisMultipliersDoubleSliderSpinBox *scaleSlider;
KisSliderSpinBox *offsetSliderX;
KisSliderSpinBox *offsetSliderY;
KisDoubleSliderSpinBox *strengthSlider;
QComboBox *cmbTexturingMode;
KisGradientSlider *cutoffSlider;
QComboBox *cmbCutoffPolicy;
QCheckBox *chkInvert;
......@@ -127,7 +129,7 @@ KisTextureOption::KisTextureOption(QObject *)
connect(m_optionWidget->scaleSlider, SIGNAL(valueChanged(qreal)), SIGNAL(sigSettingChanged()));
connect(m_optionWidget->offsetSliderX, SIGNAL(valueChanged(int)), SIGNAL(sigSettingChanged()));
connect(m_optionWidget->offsetSliderY, SIGNAL(valueChanged(int)), SIGNAL(sigSettingChanged()));
connect(m_optionWidget->strengthSlider, SIGNAL(valueChanged(qreal)), SIGNAL(sigSettingChanged()));
connect(m_optionWidget->cmbTexturingMode, SIGNAL(currentIndexChanged(int)), SIGNAL(sigSettingChanged()));
connect(m_optionWidget->cmbCutoffPolicy, SIGNAL(currentIndexChanged(int)), SIGNAL(sigSettingChanged()));
connect(m_optionWidget->cutoffSlider, SIGNAL(sigModifiedBlack(int)), SIGNAL(sigSettingChanged()));
connect(m_optionWidget->cutoffSlider, SIGNAL(sigModifiedWhite(int)), SIGNAL(sigSettingChanged()));
......@@ -149,14 +151,13 @@ void KisTextureOption::writeOptionSetting(KisPropertiesConfiguration* setting) c
qreal scale = m_optionWidget->scaleSlider->value();
int offsetX = m_optionWidget->offsetSliderX->value();
int offsetY = m_optionWidget->offsetSliderY->value();
qreal strength = m_optionWidget->strengthSlider->value();
int texturingMode = m_optionWidget->cmbTexturingMode->currentIndex();
bool invert = (m_optionWidget->chkInvert->checkState() == Qt::Checked);
setting->setProperty("Texture/Pattern/Scale", scale);
setting->setProperty("Texture/Pattern/OffsetX", offsetX);
setting->setProperty("Texture/Pattern/OffsetY", offsetY);
setting->setProperty("Texture/Pattern/Strength", strength);
setting->setProperty("Texture/Pattern/TexturingMode", texturingMode);
setting->setProperty("Texture/Pattern/CutoffLeft", m_optionWidget->cutoffSlider->black());
setting->setProperty("Texture/Pattern/CutoffRight", m_optionWidget->cutoffSlider->white());
setting->setProperty("Texture/Pattern/CutoffPolicy", m_optionWidget->cmbCutoffPolicy->currentIndex());
......@@ -215,7 +216,7 @@ void KisTextureOption::readOptionSetting(const KisPropertiesConfiguration* setti
m_optionWidget->scaleSlider->setValue(setting->getDouble("Texture/Pattern/Scale", 1.0));
m_optionWidget->offsetSliderX->setValue(setting->getInt("Texture/Pattern/OffsetX"));
m_optionWidget->offsetSliderY->setValue(setting->getInt("Texture/Pattern/OffsetY"));
m_optionWidget->strengthSlider->setValue(setting->getDouble("Texture/Pattern/Strength", 1.0));
m_optionWidget->cmbTexturingMode->setCurrentIndex(setting->getInt("Texture/Pattern/TexturingMode", KisTextureProperties::MULTIPLY));
m_optionWidget->cmbCutoffPolicy->setCurrentIndex(setting->getInt("Texture/Pattern/CutoffPolicy"));
m_optionWidget->cutoffSlider->slotModifyBlack(setting->getInt("Texture/Pattern/CutoffLeft", 0));
m_optionWidget->cutoffSlider->slotModifyWhite(setting->getInt("Texture/Pattern/CutoffRight", 255));
......@@ -265,7 +266,7 @@ void KisTextureProperties::recalculateMask()
float alpha = qAlpha(currentPixel) / 255.0;
const int grayValue = (red * 11 + green * 16 + blue * 5) / 32;
float maskValue = (grayValue / 255.0) * strength * alpha + (1 - alpha);
float maskValue = (grayValue / 255.0) * alpha + (1 - alpha);
if (invert) {
maskValue = 1 - maskValue;
......@@ -273,7 +274,9 @@ void KisTextureProperties::recalculateMask()
if (cutoffPolicy == 1 && (maskValue < (cutoffLeft / 255.0) || maskValue > (cutoffRight / 255.0))) {
// mask out the dab if it's outside the pattern's cuttoff points
maskValue = OPACITY_TRANSPARENT_U8;
maskValue = OPACITY_TRANSPARENT_F;
} else if (cutoffPolicy == 2 && (maskValue < (cutoffLeft / 255.0) || maskValue > (cutoffRight / 255.0))) {
maskValue = OPACITY_OPAQUE_F;
}
cs->setOpacity(iter->rawData(), maskValue, 1);
......@@ -316,7 +319,7 @@ void KisTextureProperties::fillProperties(const KisPropertiesConfiguration *sett
scale = setting->getDouble("Texture/Pattern/Scale", 1.0);
offsetX = setting->getInt("Texture/Pattern/OffsetX");
offsetY = setting->getInt("Texture/Pattern/OffsetY");
strength = setting->getDouble("Texture/Pattern/Strength");
texturingMode = (TexturingMode) setting->getInt("Texture/Pattern/TexturingMode", MULTIPLY);
invert = setting->getBool("Texture/Pattern/Invert");
cutoffLeft = setting->getInt("Texture/Pattern/CutoffLeft", 0);
cutoffRight = setting->getInt("Texture/Pattern/CutoffRight", 255);
......@@ -345,23 +348,23 @@ void KisTextureProperties::apply(KisFixedPaintDeviceSP dab, const QPoint &offset
fillPainter.end();
qreal pressure = m_strengthOption.apply(info);
int pressureOffset = (1.0 - pressure) * 255;
quint8 *dabData = dab->data();
KisHLineIteratorSP iter = fillDevice->createHLineIteratorNG(x, y, rect.width());
for (int row = 0; row < rect.height(); ++row) {
for (int col = 0; col < rect.width(); ++col) {
if (!(cutoffPolicy == 2 && (*iter->oldRawData() < cutoffLeft || *iter->oldRawData() > cutoffRight))) {
//dab->colorSpace()->multiplyAlpha(dabData, *iter->oldRawData(), 1);
if (texturingMode == MULTIPLY) {
dab->colorSpace()->multiplyAlpha(dabData, quint8(*iter->oldRawData() * pressure), 1);
} else {
int pressureOffset = (1.0 - pressure) * 255;
int maskA = *iter->oldRawData() + pressureOffset;
qint16 maskA = *iter->oldRawData() + pressureOffset;
quint8 dabA = dab->colorSpace()->opacityU8(dabData);
dabA = qMax(0, (int)dabA - maskA);
dabA = qMax(0, (qint16)dabA - maskA);
dab->colorSpace()->setOpacity(dabData, dabA, 1);
}
iter->nextPixel();
dabData += dab->pixelSize();
}
......
......@@ -64,11 +64,16 @@ public:
: pattern(0)
{}
enum TexturingMode {
MULTIPLY,
SUBTRACT
};
bool enabled;
qreal scale;
int offsetX;
int offsetY;
qreal strength;
TexturingMode texturingMode;
bool invert;
KisPattern *pattern;
int cutoffLeft;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment