Commit 8e0a5ea2 authored by Halla Rempt's avatar Halla Rempt

BUG:351223 Don't save embedded patterns to disk

This cleans up the pattern option a bit and makes the
embedded pattern manager work much harder to find out
whether the embedded pattern exists. And if it really
doesn't exist, we do add it to the resource manager,
but do not save it to disk.
parent 71cb40b0
......@@ -198,7 +198,7 @@ KisFixedPaintDeviceSP KisDabCache::fetchDab(const KoColorSpace *cs,
bool KisDabCache::needSeparateOriginal()
{
return (m_d->textureOption && m_d->textureOption->enabled) ||
return (m_d->textureOption && m_d->textureOption->m_enabled) ||
(m_d->sharpnessOption && m_d->sharpnessOption->isChecked());
}
......
......@@ -54,9 +54,18 @@ struct KisEmbeddedPatternManager::Private {
KoResourceServer<KoPattern> *server = KoResourceServerProvider::instance()->patternServer();
return server->resourceByMD5(md5);
}
};
static KoPattern* tryFetchPatternByName(const QString &name) {
KoResourceServer<KoPattern> *server = KoResourceServerProvider::instance()->patternServer();
return server->resourceByName(name);
}
static KoPattern* tryFetchPatternByFileName(const QString &fileName) {
KoResourceServer<KoPattern> *server = KoResourceServerProvider::instance()->patternServer();
return server->resourceByFilename(fileName);
}
};
void KisEmbeddedPatternManager::saveEmbeddedPattern(KisPropertiesConfiguration* setting, const KoPattern *pattern)
{
......@@ -70,22 +79,21 @@ void KisEmbeddedPatternManager::saveEmbeddedPattern(KisPropertiesConfiguration*
QByteArray existingMD5 = QByteArray::fromBase64(setting->getString("Texture/Pattern/PatternMD5").toLatin1());
QString existingPatternBase64 = setting->getString("Texture/Pattern/PatternMD5").toLatin1();
if (patternMD5 == existingMD5 &&
!existingPatternBase64.isEmpty()) {
if (patternMD5 == existingMD5 && !existingPatternBase64.isEmpty()) {
return;
}
setting->setProperty("Texture/Pattern/PatternMD5", patternMD5.toBase64());
setting->setProperty("Texture/Pattern/PatternFileName", pattern->filename());
setting->setProperty("Texture/Pattern/Name", pattern->name());
QByteArray ba;
QBuffer buffer(&ba);
buffer.open(QIODevice::WriteOnly);
pattern->pattern().save(&buffer, "PNG");
setting->setProperty("Texture/Pattern/Pattern", ba.toBase64());
setting->setProperty("Texture/Pattern/PatternFileName", pattern->filename());
setting->setProperty("Texture/Pattern/Name", pattern->name());
}
KoPattern* KisEmbeddedPatternManager::loadEmbeddedPattern(const KisPropertiesConfiguration* setting)
......@@ -94,20 +102,29 @@ KoPattern* KisEmbeddedPatternManager::loadEmbeddedPattern(const KisPropertiesCon
QByteArray md5 = QByteArray::fromBase64(setting->getString("Texture/Pattern/PatternMD5").toLatin1());
pattern = Private::tryFetchPatternByMd5(md5);
if (pattern) return pattern;
if (!pattern) {
pattern = Private::tryLoadEmbeddedPattern(setting);
if (pattern) {
KoPattern *existingPattern = Private::tryFetchPatternByMd5(pattern->md5());
if (existingPattern) {
delete pattern;
pattern = existingPattern;
}
else {
KoResourceServerProvider::instance()->patternServer()->addResource(pattern, true);
}
QString name = setting->getString("Texture/Pattern/Name");
pattern = Private::tryFetchPatternByName(name);
if (pattern) return pattern;
QString fileName = setting->getString("Texture/Pattern/PatternFileName");
pattern = Private::tryFetchPatternByFileName(fileName);
if (pattern) return pattern;
pattern = Private::tryLoadEmbeddedPattern(setting);
if (pattern) {
KoPattern *existingPattern = Private::tryFetchPatternByMd5(pattern->md5());
if (existingPattern) {
delete pattern;
pattern = existingPattern;
}
else {
KoResourceServerProvider::instance()->patternServer()->addResource(pattern, false);
}
}
return pattern;
}
......@@ -225,8 +225,6 @@ void KisTextureOption::writeOptionSetting(KisPropertiesConfiguration* setting) c
KisEmbeddedPatternManager::saveEmbeddedPattern(setting, pattern);
}
void KisTextureOption::readOptionSetting(const KisPropertiesConfiguration* setting)
{
setChecked(setting->getBool("Texture/Pattern/Enabled"));
......@@ -262,11 +260,11 @@ void KisTextureOption::resetGUI(KoResource* res)
void KisTextureProperties::recalculateMask()
{
if (!pattern) return;
if (!m_pattern) return;
m_mask = 0;
QImage mask = pattern->pattern();
QImage mask = m_pattern->pattern();
if (mask.format() != QImage::Format_RGB32 ||
mask.format() != QImage::Format_ARGB32) {
......@@ -274,9 +272,9 @@ void KisTextureProperties::recalculateMask()
mask = mask.convertToFormat(QImage::Format_ARGB32);
}
if (!qFuzzyCompare(scale, 0.0)) {
if (!qFuzzyCompare(m_scale, 0.0)) {
QTransform tf;
tf.scale(scale, scale);
tf.scale(m_scale, m_scale);
QRect rc = KisAlgebra2D::ensureRectNotSmaller(tf.mapRect(mask.rect()), QSize(2,2));
mask = mask.scaled(rc.size(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
}
......@@ -305,15 +303,15 @@ void KisTextureProperties::recalculateMask()
const int grayValue = (red * 11 + green * 16 + blue * 5) / 32;
float maskValue = (grayValue / 255.0) * alpha + (1 - alpha);
if (invert) {
if (m_invert) {
maskValue = 1 - maskValue;
}
if (cutoffPolicy == 1 && (maskValue < (cutoffLeft / 255.0) || maskValue > (cutoffRight / 255.0))) {
if (m_cutoffPolicy == 1 && (maskValue < (m_cutoffLeft / 255.0) || maskValue > (m_cutoffRight / 255.0))) {
// mask out the dab if it's outside the pattern's cuttoff points
maskValue = OPACITY_TRANSPARENT_F;
}
else if (cutoffPolicy == 2 && (maskValue < (cutoffLeft / 255.0) || maskValue > (cutoffRight / 255.0))) {
else if (m_cutoffPolicy == 2 && (maskValue < (m_cutoffLeft / 255.0) || maskValue > (m_cutoffRight / 255.0))) {
maskValue = OPACITY_OPAQUE_F;
}
......@@ -330,27 +328,27 @@ void KisTextureProperties::recalculateMask()
void KisTextureProperties::fillProperties(const KisPropertiesConfiguration *setting)
{
if (!setting->hasProperty("Texture/Pattern/PatternMD5")) {
enabled = false;
m_enabled = false;
return;
}
pattern = KisEmbeddedPatternManager::loadEmbeddedPattern(setting);
m_pattern = KisEmbeddedPatternManager::loadEmbeddedPattern(setting);
if (!pattern) {
if (!m_pattern) {
qWarning() << "WARNING: Couldn't load the pattern for a stroke";
enabled = false;
m_enabled = false;
return;
}
enabled = setting->getBool("Texture/Pattern/Enabled", false);
scale = setting->getDouble("Texture/Pattern/Scale", 1.0);
offsetX = setting->getInt("Texture/Pattern/OffsetX");
offsetY = setting->getInt("Texture/Pattern/OffsetY");
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);
cutoffPolicy = setting->getInt("Texture/Pattern/CutoffPolicy", 0);
m_enabled = setting->getBool("Texture/Pattern/Enabled", false);
m_scale = setting->getDouble("Texture/Pattern/Scale", 1.0);
m_offsetX = setting->getInt("Texture/Pattern/OffsetX");
m_offsetY = setting->getInt("Texture/Pattern/OffsetY");
m_texturingMode = (TexturingMode) setting->getInt("Texture/Pattern/TexturingMode", MULTIPLY);
m_invert = setting->getBool("Texture/Pattern/Invert");
m_cutoffLeft = setting->getInt("Texture/Pattern/CutoffLeft", 0);
m_cutoffRight = setting->getInt("Texture/Pattern/CutoffRight", 255);
m_cutoffPolicy = setting->getInt("Texture/Pattern/CutoffPolicy", 0);
m_strengthOption.readOptionSetting(setting);
m_strengthOption.resetAllSensors();
......@@ -360,13 +358,13 @@ void KisTextureProperties::fillProperties(const KisPropertiesConfiguration *sett
void KisTextureProperties::apply(KisFixedPaintDeviceSP dab, const QPoint &offset, const KisPaintInformation & info)
{
if (!enabled) return;
if (!m_enabled) return;
KisPaintDeviceSP fillDevice = new KisPaintDevice(KoColorSpaceRegistry::instance()->alpha8());
QRect rect = dab->bounds();
int x = offset.x() % m_maskBounds.width() - offsetX;
int y = offset.y() % m_maskBounds.height() - offsetY;
int x = offset.x() % m_maskBounds.width() - m_offsetX;
int y = offset.y() % m_maskBounds.height() - m_offsetY;
KisFillPainter fillPainter(fillDevice);
fillPainter.fillRect(x - 1, y - 1, rect.width() + 2, rect.height() + 2, m_mask, m_maskBounds);
......@@ -378,7 +376,7 @@ void KisTextureProperties::apply(KisFixedPaintDeviceSP dab, const QPoint &offset
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 (texturingMode == MULTIPLY) {
if (m_texturingMode == MULTIPLY) {
dab->colorSpace()->multiplyAlpha(dabData, quint8(*iter->oldRawData() * pressure), 1);
}
else {
......
......@@ -61,7 +61,7 @@ class PAINTOP_EXPORT KisTextureProperties
{
public:
KisTextureProperties()
: pattern(0)
: m_pattern(0)
{}
enum TexturingMode {
......@@ -69,7 +69,7 @@ public:
SUBTRACT
};
bool enabled;
bool m_enabled;
/**
* @brief apply combine the texture map with the dab
......@@ -81,15 +81,15 @@ public:
private:
qreal scale;
int offsetX;
int offsetY;
TexturingMode texturingMode;
bool invert;
KoPattern *pattern;
int cutoffLeft;
int cutoffRight;
int cutoffPolicy;
qreal m_scale;
int m_offsetX;
int m_offsetY;
TexturingMode m_texturingMode;
bool m_invert;
KoPattern *m_pattern;
int m_cutoffLeft;
int m_cutoffRight;
int m_cutoffPolicy;
private:
KisPressureTextureStrengthOption m_strengthOption;
......
Markdown is supported
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