Commit bba9188e authored by Dmitry Kazakov's avatar Dmitry Kazakov
Browse files

Added simple implementation of the texturing with real paper effect

CCBUG:313831
parent 8a0b5599
......@@ -40,6 +40,8 @@
#include <kis_compositeop_option.h>
#include <kis_pressure_flow_opacity_option_widget.h>
#include <kis_texture_option.h>
#include "kis_pressure_texture_strength_option.h"
KisBrushOpSettingsWidget::KisBrushOpSettingsWidget(QWidget* parent)
: KisBrushBasedPaintopOptionWidget(parent)
......@@ -70,6 +72,7 @@ KisBrushOpSettingsWidget::KisBrushOpSettingsWidget(QWidget* parent)
// Texture options
addPaintOpOption(new KisTextureOption());
addPaintOpOption(new KisCurveOptionWidget(new KisPressureTextureStrengthOption()));
}
KisBrushOpSettingsWidget::~KisBrushOpSettingsWidget()
......
......@@ -52,6 +52,7 @@ set(kritalibpaintop_LIB_SRCS
kis_brush_based_paintop_settings.cpp
kis_compositeop_option.cpp
kis_texture_option.cpp
kis_pressure_texture_strength_option.cpp
sensors/kis_dynamic_sensors.cc
sensors/kis_dynamic_sensor_distance.cc
sensors/kis_dynamic_sensor_list.cc
......
......@@ -310,6 +310,6 @@ void KisDabCache::postProcessDab(KisFixedPaintDeviceSP dab,
}
if (m_d->textureOption) {
m_d->textureOption->apply(dab, info.pos().toPoint());
m_d->textureOption->apply(dab, info.pos().toPoint(), info);
}
}
/*
* Copyright (c) 2013 Dmitry Kazakov <dimula73@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "kis_pressure_texture_strength_option.h"
#include <klocale.h>
KisPressureTextureStrengthOption::KisPressureTextureStrengthOption()
: KisCurveOption(i18n("Strength"), "Texture/Strength", KisPaintOpOption::textureCategory(), false)
{
setMinimumLabel(i18n("Weak"));
setMaximumLabel(i18n("Strong"));
}
double KisPressureTextureStrengthOption::apply(const KisPaintInformation & info) const
{
if (!isChecked()) return 1.0;
return computeValue(info);
}
/*
* Copyright (c) 2013 Dmitry Kazakov <dimula73@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef __KIS_PRESSURE_TEXTURE_STRENGTH_OPTION_H
#define __KIS_PRESSURE_TEXTURE_STRENGTH_OPTION_H
#include "kis_curve_option.h"
#include <kis_paint_information.h>
#include <krita_export.h>
/**
* This curve defines how deep the ink (or a pointer) of a brush
* penetrates the surface of the canvas, that is how strong we
* press on the paper
*/
class PAINTOP_EXPORT KisPressureTextureStrengthOption : public KisCurveOption
{
public:
KisPressureTextureStrengthOption();
double apply(const KisPaintInformation & info) const;
};
#endif /* __KIS_PRESSURE_TEXTURE_STRENGTH_OPTION_H */
......@@ -322,10 +322,12 @@ void KisTextureProperties::fillProperties(const KisPropertiesConfiguration *sett
cutoffRight = setting->getInt("Texture/Pattern/CutoffRight", 255);
cutoffPolicy = setting->getInt("Texture/Pattern/CutoffPolicy", 0);
m_strengthOption.readOptionSetting(setting);
recalculateMask();
}
void KisTextureProperties::apply(KisFixedPaintDeviceSP dab, const QPoint &offset)
void KisTextureProperties::apply(KisFixedPaintDeviceSP dab, const QPoint &offset, const KisPaintInformation & info)
{
if (!enabled) return;
......@@ -342,19 +344,28 @@ void KisTextureProperties::apply(KisFixedPaintDeviceSP dab, const QPoint &offset
fillPainter.fillRect(x - 1, y - 1, rect.width() + 2, rect.height() + 2, m_mask, m_maskBounds);
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);
//dab->colorSpace()->multiplyAlpha(dabData, *iter->oldRawData(), 1);
int maskA = *iter->oldRawData() + pressureOffset;
quint8 dabA = dab->colorSpace()->opacityU8(dabData);
dabA = qMax(0, (int)dabA - maskA);
dab->colorSpace()->setOpacity(dabData, dabA, 1);
}
iter->nextPixel();
dabData += dab->pixelSize();
}
iter->nextRow();
}
}
......@@ -25,6 +25,7 @@
#include <kis_paint_device.h>
#include <kis_types.h>
#include "kis_paintop_option.h"
#include "kis_pressure_texture_strength_option.h"
#include <QRect>
......@@ -78,10 +79,11 @@ public:
* @param dab the colored, final representation of the dab, after mirroring and everything.
* @param offset the position of the dab on the image. used to calculate the position of the mask pattern
*/
void apply(KisFixedPaintDeviceSP dab, const QPoint& offset);
void apply(KisFixedPaintDeviceSP dab, const QPoint& offset, const KisPaintInformation & info);
void fillProperties(const KisPropertiesConfiguration *setting);
private:
KisPressureTextureStrengthOption m_strengthOption;
QRect m_maskBounds; // this can be different from the extent if we mask out too many pixels in a big mask!
KisPaintDeviceSP m_mask;
void recalculateMask();
......
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