diff --git a/libs/image/kis_properties_configuration.cc b/libs/image/kis_properties_configuration.cc
index e5a6baddf3..ade808b394 100644
--- a/libs/image/kis_properties_configuration.cc
+++ b/libs/image/kis_properties_configuration.cc
@@ -1,319 +1,328 @@
/*
* Copyright (c) 2006 Boudewijn Rempt
* Copyright (c) 2007,2010 Cyrille Berger
*
* 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_properties_configuration.h"
#include
#include
#include
#include "kis_image.h"
#include "kis_transaction.h"
#include "kis_undo_adapter.h"
#include "kis_painter.h"
#include "kis_selection.h"
#include "KoID.h"
#include "kis_types.h"
#include
#include
struct Q_DECL_HIDDEN KisPropertiesConfiguration::Private {
QMap properties;
QStringList notSavedProperties;
};
KisPropertiesConfiguration::KisPropertiesConfiguration() : d(new Private)
{
}
KisPropertiesConfiguration::~KisPropertiesConfiguration()
{
delete d;
}
KisPropertiesConfiguration::KisPropertiesConfiguration(const KisPropertiesConfiguration& rhs)
: KisSerializableConfiguration(rhs)
, d(new Private(*rhs.d))
{
}
+KisPropertiesConfiguration &KisPropertiesConfiguration::operator=(const KisPropertiesConfiguration &rhs)
+{
+ if (&rhs != this) {
+ *d = *rhs.d;
+ }
+
+ return *this;
+}
+
bool KisPropertiesConfiguration::fromXML(const QString & xml, bool clear)
{
if (clear) {
clearProperties();
}
QDomDocument doc;
bool retval = doc.setContent(xml);
if (retval) {
QDomElement e = doc.documentElement();
fromXML(e);
}
return retval;
}
void KisPropertiesConfiguration::fromXML(const QDomElement& e)
{
QDomNode n = e.firstChild();
while (!n.isNull()) {
// We don't nest elements in filter configuration. For now...
QDomElement e = n.toElement();
if (!e.isNull()) {
if (e.tagName() == "param") {
// If the file contains the new type parameter introduced in Krita act on it
// Else invoke old behaviour
if(e.attributes().contains("type"))
{
QString type = e.attribute("type");
QString name = e.attribute("name");
QString value = e.text();
if(type == "bytearray")
{
d->properties[name] = QVariant(QByteArray::fromBase64(value.toLatin1()));
}
else
d->properties[name] = value;
}
else
d->properties[e.attribute("name")] = QVariant(e.text());
}
}
n = n.nextSibling();
}
//dump();
}
void KisPropertiesConfiguration::toXML(QDomDocument& doc, QDomElement& root) const
{
QMap::Iterator it;
for (it = d->properties.begin(); it != d->properties.end(); ++it) {
if(d->notSavedProperties.contains(it.key())) {
continue;
}
QDomElement e = doc.createElement("param");
e.setAttribute("name", QString(it.key().toLatin1()));
QString type = "string";
QVariant v = it.value();
QDomText text;
if (v.type() == QVariant::UserType && v.userType() == qMetaTypeId()) {
text = doc.createCDATASection(v.value().toString());
} else if (v.type() == QVariant::UserType && v.userType() == qMetaTypeId()) {
QDomDocument doc = QDomDocument("color");
QDomElement root = doc.createElement("color");
doc.appendChild(root);
v.value().toXML(doc, root);
text = doc.createCDATASection(doc.toString());
type = "color";
} else if(v.type() == QVariant::String ) {
text = doc.createCDATASection(v.toString()); // XXX: Unittest this!
type = "string";
} else if(v.type() == QVariant::ByteArray ) {
text = doc.createTextNode(QString::fromLatin1(v.toByteArray().toBase64())); // Arbitrary Data
type = "bytearray";
} else {
text = doc.createTextNode(v.toString());
type = "internal";
}
e.setAttribute("type", type);
e.appendChild(text);
root.appendChild(e);
}
}
QString KisPropertiesConfiguration::toXML() const
{
QDomDocument doc = QDomDocument("params");
QDomElement root = doc.createElement("params");
doc.appendChild(root);
toXML(doc, root);
return doc.toString();
}
bool KisPropertiesConfiguration::hasProperty(const QString& name) const
{
return d->properties.contains(name);
}
void KisPropertiesConfiguration::setProperty(const QString & name, const QVariant & value)
{
if (d->properties.find(name) == d->properties.end()) {
d->properties.insert(name, value);
} else {
d->properties[name] = value;
}
}
bool KisPropertiesConfiguration::getProperty(const QString & name, QVariant & value) const
{
if (d->properties.find(name) == d->properties.end()) {
return false;
} else {
value = d->properties[name];
return true;
}
}
QVariant KisPropertiesConfiguration::getProperty(const QString & name) const
{
if (d->properties.find(name) == d->properties.end()) {
return QVariant();
} else {
return d->properties[name];
}
}
int KisPropertiesConfiguration::getInt(const QString & name, int def) const
{
QVariant v = getProperty(name);
if (v.isValid())
return v.toInt();
else
return def;
}
double KisPropertiesConfiguration::getDouble(const QString & name, double def) const
{
QVariant v = getProperty(name);
if (v.isValid())
return v.toDouble();
else
return def;
}
float KisPropertiesConfiguration::getFloat(const QString & name, float def) const
{
QVariant v = getProperty(name);
if (v.isValid())
return (float)v.toDouble();
else
return def;
}
bool KisPropertiesConfiguration::getBool(const QString & name, bool def) const
{
QVariant v = getProperty(name);
if (v.isValid())
return v.toBool();
else
return def;
}
QString KisPropertiesConfiguration::getString(const QString & name, const QString & def) const
{
QVariant v = getProperty(name);
if (v.isValid())
return v.toString();
else
return def;
}
KisCubicCurve KisPropertiesConfiguration::getCubicCurve(const QString & name, const KisCubicCurve & curve) const
{
QVariant v = getProperty(name);
if (v.isValid()) {
if (v.type() == QVariant::UserType && v.userType() == qMetaTypeId()) {
return v.value();
} else {
KisCubicCurve c;
c.fromString(v.toString());
return c;
}
} else
return curve;
}
KoColor KisPropertiesConfiguration::getColor(const QString& name, const KoColor& color) const
{
QVariant v = getProperty(name);
if (v.isValid()) {
if (v.type() == QVariant::UserType && v.userType() == qMetaTypeId()) {
return v.value();
} else {
QDomDocument doc;
doc.setContent(v.toString());
QDomElement e = doc.documentElement().firstChild().toElement();
return KoColor::fromXML(e, Integer16BitsColorDepthID.id());
}
} else {
return color;
}
}
void KisPropertiesConfiguration::dump() const
{
QMap::Iterator it;
for (it = d->properties.begin(); it != d->properties.end(); ++it) {
dbgKrita << it.key() << " = " << it.value();
}
}
void KisPropertiesConfiguration::clearProperties()
{
d->properties.clear();
}
void KisPropertiesConfiguration::setPropertyNotSaved(const QString& name)
{
d->notSavedProperties.append(name);
}
QMap KisPropertiesConfiguration::getProperties() const
{
return d->properties;
}
void KisPropertiesConfiguration::removeProperty(const QString & name)
{
d->properties.remove(name);
}
// --- factory ---
struct Q_DECL_HIDDEN KisPropertiesConfigurationFactory::Private {
};
KisPropertiesConfigurationFactory::KisPropertiesConfigurationFactory() : d(new Private)
{
}
KisPropertiesConfigurationFactory::~KisPropertiesConfigurationFactory()
{
delete d;
}
KisSerializableConfigurationSP KisPropertiesConfigurationFactory::createDefault()
{
return new KisPropertiesConfiguration();
}
KisSerializableConfigurationSP KisPropertiesConfigurationFactory::create(const QDomElement& e)
{
KisPropertiesConfigurationSP pc = new KisPropertiesConfiguration();
pc->fromXML(e);
return pc;
}
diff --git a/libs/image/kis_properties_configuration.h b/libs/image/kis_properties_configuration.h
index c7e6004dc3..d8e444f897 100644
--- a/libs/image/kis_properties_configuration.h
+++ b/libs/image/kis_properties_configuration.h
@@ -1,164 +1,169 @@
/*
* Copyright (c) 2006 Boudewijn Rempt
*
* 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_PROPERTIES_CONFIGURATION_H_
#define _KIS_PROPERTIES_CONFIGURATION_H_
#include
#include
#include
#include
#include
#include
class QDomElement;
class QDomDocument;
#include "kis_serializable_configuration.h"
#include "kritaimage_export.h"
#include "kis_types.h"
/**
* KisPropertiesConfiguration is a map-based properties class that can
* be serialized and deserialized.
*
* It differs from the base class KisSerializableConfiguration in that
* it provides a number of convenience methods to get at the data and
*/
class KRITAIMAGE_EXPORT KisPropertiesConfiguration : public KisSerializableConfiguration
{
public:
/**
* Create a new properties config.
*/
KisPropertiesConfiguration();
virtual ~KisPropertiesConfiguration();
/**
- * Deep copy the properties configFile
+ * Deep copy the properties \p rhs
*/
KisPropertiesConfiguration(const KisPropertiesConfiguration& rhs);
+ /**
+ * Deep copy the properties \p rhs
+ */
+ KisPropertiesConfiguration& operator=(const KisPropertiesConfiguration& rhs);
+
public:
/**
* Fill the properties configuration object from the XML encoded representation in s.
* This function use the "Legacy" style XML of the 1.x .kra file format.
* @param xml the string that will be parsed as xml
* @param clear if true, the properties map will be emptied.
* @return true is the xml document could be parsed
*/
virtual bool fromXML(const QString& xml, bool clear = true);
/**
* Fill the properties configuration object from the XML encoded representation in s.
* This function use the "Legacy" style XML of the 1.x .kra file format.
*
* Note: the existing properties will not be cleared
*/
virtual void fromXML(const QDomElement&);
/**
* Create a serialized version of this properties config
* This function use the "Legacy" style XML of the 1.x .kra file format.
*/
virtual void toXML(QDomDocument&, QDomElement&) const;
/**
* Create a serialized version of this properties config
* This function use the "Legacy" style XML of the 1.x .kra file format.
*/
virtual QString toXML() const;
/**
* @return true if the map contains a property with the specified name
*/
bool hasProperty(const QString& name) const;
/**
* Set the property with name to value.
*/
virtual void setProperty(const QString & name, const QVariant & value);
/**
* Set value to the value associated with property name
*
* XXX: API alert: a setter that is prefixed with get?
*
* @return false if the specified property did not exist.
*/
virtual bool getProperty(const QString & name, QVariant & value) const;
virtual QVariant getProperty(const QString & name) const;
template
T getPropertyLazy(const QString & name, const T &defaultValue) const {
QVariant value = getProperty(name);
return value.isValid() ? value.value() : defaultValue;
}
int getInt(const QString & name, int def = 0) const;
double getDouble(const QString & name, double def = 0.0) const;
float getFloat(const QString& name, float def = 0.0) const;
bool getBool(const QString & name, bool def = false) const;
QString getString(const QString & name, const QString & def = QString()) const;
KisCubicCurve getCubicCurve(const QString & name, const KisCubicCurve & curve = KisCubicCurve()) const;
KoColor getColor(const QString& name, const KoColor& color = KoColor()) const;
QMap getProperties() const;
/// Clear the map of properties
void clearProperties();
/// Marks a property that should not be saved by toXML
void setPropertyNotSaved(const QString & name);
void removeProperty(const QString & name);
public:
void dump() const;
private:
struct Private;
Private* const d;
};
class KRITAIMAGE_EXPORT KisPropertiesConfigurationFactory : public KisSerializableConfigurationFactory
{
public:
KisPropertiesConfigurationFactory();
virtual ~KisPropertiesConfigurationFactory();
virtual KisSerializableConfigurationSP createDefault();
virtual KisSerializableConfigurationSP create(const QDomElement& e);
private:
struct Private;
Private* const d;
};
#endif
diff --git a/libs/image/tests/kis_properties_configuration_test.cpp b/libs/image/tests/kis_properties_configuration_test.cpp
index 87ca007a4e..7a42fda3b4 100644
--- a/libs/image/tests/kis_properties_configuration_test.cpp
+++ b/libs/image/tests/kis_properties_configuration_test.cpp
@@ -1,111 +1,125 @@
/*
* Copyright (c) 2007 Cyrille Berger
*
* 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_properties_configuration_test.h"
#include
#include "kis_properties_configuration.h"
KisPropertiesConfigurationTest::KisPropertiesConfigurationTest() :
v1(10), v2("hello"), v3(1242.0), v4(true)
{
QList pts; pts.push_back(QPointF(0.2, 0.3)); pts.push_back(QPointF(0.5, 0.7));
v5.setPoints(pts);
}
void KisPropertiesConfigurationTest::testSerialization()
{
KisPropertiesConfigurationSP config = createConfig();
QString xml = config->toXML();
KisPropertiesConfigurationSP decodedConfig = new KisPropertiesConfiguration();
decodedConfig->fromXML(xml);
testConfig(decodedConfig);
}
void KisPropertiesConfigurationTest::testSetGet()
{
KisPropertiesConfigurationSP config = createConfig();
testConfig(config);
}
void KisPropertiesConfigurationTest::testDefaultValues()
{
KisPropertiesConfigurationSP config = new KisPropertiesConfiguration();
QVERIFY(config->getInt("bouh", v1) == v1);
QVERIFY(config->getString("bouh", v2) == v2);
QVERIFY(config->getDouble("bouh", v3) == v3);
QVERIFY(config->getBool("bouh", v4) == v4);
QVERIFY(config->getCubicCurve("bouh", v5) == v5);
}
KisPropertiesConfigurationSP KisPropertiesConfigurationTest::createConfig()
{
KisPropertiesConfigurationSP config = new KisPropertiesConfiguration();
config->setProperty("v1", v1);
config->setProperty("v2", v2);
config->setProperty("v3", v3);
config->setProperty("v4", v4);
config->setProperty("v5", qVariantFromValue(v5));
return config;
}
void KisPropertiesConfigurationTest::testConfig(KisPropertiesConfigurationSP config)
{
QVERIFY(config->getInt("v1", 0) == v1);
QVERIFY(config->getString("v2", QString()) == v2);
QVERIFY(config->getDouble("v3", 0.0) == v3);
QVERIFY(config->getBool("v4", !v4) == v4);
QVERIFY(config->getCubicCurve("v5") == v5);
}
void KisPropertiesConfigurationTest::testNotSavedValues()
{
KisPropertiesConfigurationSP config = createConfig();
config->setPropertyNotSaved("v3");
testConfig(config);
QString s = config->toXML();
config = new KisPropertiesConfiguration();
config->fromXML(s);
QVERIFY(config->getInt("v1", 0) == v1);
QVERIFY(config->getString("v2", QString()) == v2);
QVERIFY(config->hasProperty("v3") == false);
QVERIFY(config->getBool("v4", !v4) == v4);
QVERIFY(config->getCubicCurve("v5") == v5);
}
void KisPropertiesConfigurationTest::testCopy()
{
KisPropertiesConfigurationSP p1 = createConfig();
p1->setProperty("v6", "bla");
p1->setPropertyNotSaved("v6");
KisPropertiesConfiguration config = KisPropertiesConfiguration(*p1.data());
QVERIFY(config.getInt("v1", 0) == v1);
QVERIFY(config.getString("v2", QString()) == v2);
QVERIFY(config.getDouble("v3", 0.0) == v3);
QVERIFY(config.getBool("v4", !v4) == v4);
QVERIFY(config.getCubicCurve("v5") == v5);
- QVERIFY(config.hasProperty("v6") == false);
-
+ QVERIFY(config.hasProperty("v6") == true); // copying works!
+
+ p1->setProperty("testBool1", true);
+ p1->setProperty("testBool2", false);
+
+ QString string = p1->toXML();
+
+ KisPropertiesConfiguration p2;
+ p2.fromXML(string);
+ QVERIFY(p2.getInt("v1", 0) == v1);
+ QVERIFY(p2.getString("v2", QString()) == v2);
+ QVERIFY(p2.getDouble("v3", 0.0) == v3);
+ QVERIFY(p2.getBool("v4", !v4) == v4);
+ QVERIFY(p2.hasProperty("v6") == false); // round-tripping -- no
+ QCOMPARE(p2.getBool("testBool1", false), true);
+ QCOMPARE(p2.getBool("testBool2", true), false);
}
QTEST_MAIN(KisPropertiesConfigurationTest)
diff --git a/libs/ui/KisImportExportFilter.cpp b/libs/ui/KisImportExportFilter.cpp
index bde881b408..dadc307cb7 100644
--- a/libs/ui/KisImportExportFilter.cpp
+++ b/libs/ui/KisImportExportFilter.cpp
@@ -1,283 +1,289 @@
/* This file is part of the KDE libraries
Copyright (C) 2001 Werner Trobin
2002 Werner Trobin
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "KisImportExportFilter.h"
#include
#include
#include
#include "KisImportExportManager.h"
#include
#include
#include
#include
#include "KoUpdater.h"
#include
+#include "kis_config.h"
const QString KisImportExportFilter::ImageContainsTransparencyTag = "ImageContainsTransparency";
const QString KisImportExportFilter::ColorModelIDTag = "ColorModelID";
const QString KisImportExportFilter::ColorDepthIDTag = "ColorDepthID";
const QString KisImportExportFilter::sRGBTag = "sRGB";
class Q_DECL_HIDDEN KisImportExportFilter::Private
{
public:
QPointer updater;
QByteArray mime;
QString filename;
QString realFilename;
bool batchmode;
QMap capabilities;
Private()
: updater(0), mime("")
, batchmode(false)
{}
~Private()
{
qDeleteAll(capabilities);
}
};
KisImportExportFilter::KisImportExportFilter(QObject *parent)
: QObject(parent)
, d(new Private)
{
}
KisImportExportFilter::~KisImportExportFilter()
{
if (d->updater) {
d->updater->setProgress(100);
}
delete d;
}
QString KisImportExportFilter::filename() const
{
return d->filename;
}
QString KisImportExportFilter::realFilename() const
{
return d->realFilename;
}
bool KisImportExportFilter::batchMode() const
{
return d->batchmode;
}
void KisImportExportFilter::setBatchMode(bool batchmode)
{
d->batchmode = batchmode;
}
void KisImportExportFilter::setFilename(const QString &filename)
{
d->filename = filename;
}
void KisImportExportFilter::setRealFilename(const QString &filename)
{
d->realFilename = filename;
}
void KisImportExportFilter::setMimeType(const QString &mime)
{
d->mime = mime.toLatin1();
}
QByteArray KisImportExportFilter::mimeType() const
{
return d->mime;
}
QString KisImportExportFilter::conversionStatusString(ConversionStatus status)
{
QString msg;
switch (status) {
case OK: break;
case FilterCreationError:
msg = i18n("Could not create the filter plugin"); break;
case CreationError:
msg = i18n("Could not create the output document"); break;
case FileNotFound:
msg = i18n("File not found"); break;
case StorageCreationError:
msg = i18n("Cannot create storage"); break;
case BadMimeType:
msg = i18n("Bad MIME type"); break;
case WrongFormat:
msg = i18n("Format not recognized"); break;
case NotImplemented:
msg = i18n("Not implemented"); break;
case ParsingError:
msg = i18n("Parsing error"); break;
case InvalidFormat:
msg = i18n("Invalid file format"); break;
case InternalError:
case UsageError:
msg = i18n("Internal error"); break;
case ProgressCancelled:
msg = i18n("Cancelled by user"); break;
case BadConversionGraph:
msg = i18n("Unknown file type"); break;
case UnsupportedVersion:
msg = i18n("Unsupported file version"); break;
case UserCancelled:
// intentionally we do not prompt the error message here
break;
default: msg = i18n("Unknown error"); break;
}
return msg;
}
KisPropertiesConfigurationSP KisImportExportFilter::defaultConfiguration(const QByteArray &from, const QByteArray &to) const
{
Q_UNUSED(from);
Q_UNUSED(to);
return 0;
}
KisPropertiesConfigurationSP KisImportExportFilter::lastSavedConfiguration(const QByteArray &from, const QByteArray &to) const
{
- return defaultConfiguration(from, to);
+ KisPropertiesConfigurationSP cfg = defaultConfiguration(from, to);
+ const QString filterConfig = KisConfig().exportConfiguration(to);
+ if (!filterConfig.isEmpty()) {
+ cfg->fromXML(filterConfig, false);
+ }
+ return cfg;
}
KisConfigWidget *KisImportExportFilter::createConfigurationWidget(QWidget *, const QByteArray &from, const QByteArray &to) const
{
Q_UNUSED(from);
Q_UNUSED(to);
return 0;
}
QMap KisImportExportFilter::exportChecks()
{
qDeleteAll(d->capabilities);
initializeCapabilities();
return d->capabilities;
}
void KisImportExportFilter::setUpdater(QPointer updater)
{
d->updater = updater;
}
void KisImportExportFilter::setProgress(int value)
{
if (d->updater) {
d->updater->setValue(value);
}
}
void KisImportExportFilter::initializeCapabilities()
{
// XXX: Initialize everything to fully supported?
}
void KisImportExportFilter::addCapability(KisExportCheckBase *capability)
{
d->capabilities[capability->id()] = capability;
}
void KisImportExportFilter::addSupportedColorModels(QList > supportedColorModels, const QString &name, KisExportCheckBase::Level level)
{
Q_ASSERT(level != KisExportCheckBase::SUPPORTED);
QString layerMessage;
QString imageMessage;
QList allColorModels = KoColorSpaceRegistry::instance()->colorModelsList(KoColorSpaceRegistry::AllColorSpaces);
Q_FOREACH(const KoID &colorModelID, allColorModels) {
QList allColorDepths = KoColorSpaceRegistry::instance()->colorDepthList(colorModelID.id(), KoColorSpaceRegistry::AllColorSpaces);
Q_FOREACH(const KoID &colorDepthID, allColorDepths) {
KisExportCheckFactory *colorModelCheckFactory =
KisExportCheckRegistry::instance()->get("ColorModelCheck/" + colorModelID.id() + "/" + colorDepthID.id());
KisExportCheckFactory *colorModelPerLayerCheckFactory =
KisExportCheckRegistry::instance()->get("ColorModelPerLayerCheck/" + colorModelID.id() + "/" + colorDepthID.id());
if(!colorModelCheckFactory || !colorModelPerLayerCheckFactory) {
qDebug() << "No factory for" << colorModelID << colorDepthID;
continue;
}
if (supportedColorModels.contains(QPair(colorModelID, colorDepthID))) {
addCapability(colorModelCheckFactory->create(KisExportCheckBase::SUPPORTED));
addCapability(colorModelPerLayerCheckFactory->create(KisExportCheckBase::SUPPORTED));
}
else {
if (level == KisExportCheckBase::PARTIALLY) {
imageMessage = i18nc("image conversion warning",
"%1 cannot save images with color model %2 and depth %3. The image will be converted."
,name, colorModelID.name(), colorDepthID.name());
layerMessage =
i18nc("image conversion warning",
"%1 cannot save layers with color model %2 and depth %3. The layers will be converted or skipped."
,name, colorModelID.name(), colorDepthID.name());
}
else {
imageMessage = i18nc("image conversion warning",
"%1 cannot save images with color model %2 and depth %3. The image will not be saved."
,name, colorModelID.name(), colorDepthID.name());
layerMessage =
i18nc("image conversion warning",
"%1 cannot save layers with color model %2 and depth %3. The layers will be skipped."
, name, colorModelID.name(), colorDepthID.name());
}
addCapability(colorModelCheckFactory->create(level, imageMessage));
addCapability(colorModelPerLayerCheckFactory->create(level, layerMessage));
}
}
}
}
diff --git a/libs/ui/KisImportExportManager.cpp b/libs/ui/KisImportExportManager.cpp
index ac933da8e3..cee4193915 100644
--- a/libs/ui/KisImportExportManager.cpp
+++ b/libs/ui/KisImportExportManager.cpp
@@ -1,527 +1,527 @@
/*
* Copyright (C) 2016 Boudewijn Rempt
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "KisImportExportManager.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "kis_config.h"
#include "KisImportExportFilter.h"
#include "KisDocument.h"
#include
#include
#include "kis_painter.h"
#include "kis_guides_config.h"
#include "kis_grid_config.h"
#include "kis_popup_button.h"
#include
#include "kis_async_action_feedback.h"
// static cache for import and export mimetypes
QStringList KisImportExportManager::m_importMimeTypes;
QStringList KisImportExportManager::m_exportMimeTypes;
class Q_DECL_HIDDEN KisImportExportManager::Private
{
public:
bool batchMode {false};
QPointer progressUpdater {0};
};
KisImportExportManager::KisImportExportManager(KisDocument* document)
: m_document(document)
, d(new Private)
{
}
KisImportExportManager::~KisImportExportManager()
{
delete d;
}
KisImportExportFilter::ConversionStatus KisImportExportManager::importDocument(const QString& location, const QString& mimeType)
{
return convert(Import, location, location, mimeType, false, 0);
}
KisImportExportFilter::ConversionStatus KisImportExportManager::exportDocument(const QString& location, const QString& realLocation, QByteArray& mimeType, bool showWarnings, KisPropertiesConfigurationSP exportConfiguration)
{
return convert(Export, location, realLocation, mimeType, showWarnings, exportConfiguration);
}
// The static method to figure out to which parts of the
// graph this mimetype has a connection to.
QStringList KisImportExportManager::mimeFilter(Direction direction)
{
// Find the right mimetype by the extension
QSet mimeTypes;
// mimeTypes << KisDocument::nativeFormatMimeType() << "application/x-krita-paintoppreset" << "image/openraster";
if (direction == KisImportExportManager::Import) {
if (m_importMimeTypes.isEmpty()) {
KoJsonTrader trader;
QListlist = trader.query("Krita/FileFilter", "");
Q_FOREACH(QPluginLoader *loader, list) {
QJsonObject json = loader->metaData().value("MetaData").toObject();
Q_FOREACH(const QString &mimetype, json.value("X-KDE-Import").toString().split(",", QString::SkipEmptyParts)) {
//qDebug() << "Adding import mimetype" << mimetype << KisMimeDatabase::descriptionForMimeType(mimetype) << "from plugin" << loader;
mimeTypes << mimetype;
}
}
qDeleteAll(list);
m_importMimeTypes = mimeTypes.toList();
}
return m_importMimeTypes;
}
else if (direction == KisImportExportManager::Export) {
if (m_exportMimeTypes.isEmpty()) {
KoJsonTrader trader;
QListlist = trader.query("Krita/FileFilter", "");
Q_FOREACH(QPluginLoader *loader, list) {
QJsonObject json = loader->metaData().value("MetaData").toObject();
Q_FOREACH(const QString &mimetype, json.value("X-KDE-Export").toString().split(",", QString::SkipEmptyParts)) {
//qDebug() << "Adding export mimetype" << mimetype << KisMimeDatabase::descriptionForMimeType(mimetype) << "from plugin" << loader;
mimeTypes << mimetype;
}
}
qDeleteAll(list);
m_exportMimeTypes = mimeTypes.toList();
}
return m_exportMimeTypes;
}
return QStringList();
}
KisImportExportFilter *KisImportExportManager::filterForMimeType(const QString &mimetype, KisImportExportManager::Direction direction)
{
int weight = -1;
KisImportExportFilter *filter = 0;
QListlist = KoJsonTrader::instance()->query("Krita/FileFilter", "");
Q_FOREACH(QPluginLoader *loader, list) {
QJsonObject json = loader->metaData().value("MetaData").toObject();
QString directionKey = direction == Export ? "X-KDE-Export" : "X-KDE-Import";
if (json.value(directionKey).toString().split(",", QString::SkipEmptyParts).contains(mimetype)) {
KLibFactory *factory = qobject_cast(loader->instance());
if (!factory) {
warnUI << loader->errorString();
continue;
}
QObject* obj = factory->create(0);
if (!obj || !obj->inherits("KisImportExportFilter")) {
delete obj;
continue;
}
KisImportExportFilter *f = qobject_cast(obj);
if (!f) {
delete obj;
continue;
}
int w = json.value("X-KDE-Weight").toInt();
if (w > weight) {
delete filter;
filter = f;
f->setObjectName(loader->fileName());
weight = w;
}
}
}
qDeleteAll(list);
if (filter) {
filter->setMimeType(mimetype);
}
return filter;
}
void KisImportExportManager::setBatchMode(const bool batch)
{
d->batchMode = batch;
}
bool KisImportExportManager::batchMode(void) const
{
return d->batchMode;
}
void KisImportExportManager::setProgresUpdater(KoProgressUpdater *updater)
{
d->progressUpdater = updater;
}
QString KisImportExportManager::askForAudioFileName(const QString &defaultDir, QWidget *parent)
{
KoFileDialog dialog(parent, KoFileDialog::ImportFiles, "ImportAudio");
if (!defaultDir.isEmpty()) {
dialog.setDefaultDir(defaultDir);
}
QStringList mimeTypes;
mimeTypes << "audio/mpeg";
mimeTypes << "audio/ogg";
mimeTypes << "audio/vorbis";
mimeTypes << "audio/vnd.wave";
mimeTypes << "audio/flac";
dialog.setMimeTypeFilters(mimeTypes);
dialog.setCaption(i18nc("@titile:window", "Open Audio"));
return dialog.filename();
}
KisImportExportFilter::ConversionStatus KisImportExportManager::convert(KisImportExportManager::Direction direction, const QString &location, const QString& realLocation, const QString &mimeType, bool showWarnings, KisPropertiesConfigurationSP exportConfiguration)
{
// export configuration is supported for export only
KIS_SAFE_ASSERT_RECOVER_NOOP(direction == Export || !bool(exportConfiguration));
QString typeName = mimeType;
if (typeName.isEmpty()) {
typeName = KisMimeDatabase::mimeTypeForFile(location);
}
QSharedPointer filter(filterForMimeType(typeName, direction));
if (!filter) {
return KisImportExportFilter::FilterCreationError;
}
filter->setFilename(location);
filter->setRealFilename(realLocation);
filter->setBatchMode(batchMode());
filter->setMimeType(typeName);
if (d->progressUpdater) {
filter->setUpdater(d->progressUpdater->startSubtask());
}
QByteArray from, to;
if (direction == Export) {
from = m_document->nativeFormatMimeType();
to = typeName.toLatin1();
}
else {
from = typeName.toLatin1();
to = m_document->nativeFormatMimeType();
}
KIS_ASSERT_RECOVER_RETURN_VALUE(
direction == Import || direction == Export,
KisImportExportFilter::BadConversionGraph);
KisImportExportFilter::ConversionStatus status = KisImportExportFilter::OK;
if (direction == Import) {
if (!batchMode()) {
KisAsyncActionFeedback f(i18n("Opening document..."), 0);
status = f.runAction(std::bind(&KisImportExportManager::doImport, this, location, filter));
} else {
status = doImport(location, filter);
}
} else /* if (direction == Export) */ {
if (!exportConfiguration) {
exportConfiguration = filter->lastSavedConfiguration(from, to);
}
if (exportConfiguration) {
fillStaticExportConfigurationProperties(exportConfiguration);
}
bool alsoAsKra = false;
if (!askUserAboutExportConfiguration(filter, exportConfiguration,
from, to,
batchMode(), showWarnings,
&alsoAsKra)) {
return KisImportExportFilter::UserCancelled;
}
if (!batchMode()) {
KisAsyncActionFeedback f(i18n("Saving document..."), 0);
status = f.runAction(std::bind(&KisImportExportManager::doExport, this, location, filter, exportConfiguration, alsoAsKra));
} else {
status = doExport(location, filter, exportConfiguration, alsoAsKra);
}
- }
- if (exportConfiguration) {
- KisConfig().setExportConfiguration(typeName, exportConfiguration);
+ if (exportConfiguration) {
+ KisConfig().setExportConfiguration(typeName, exportConfiguration);
+ }
}
return status;
}
void KisImportExportManager::fillStaticExportConfigurationProperties(KisPropertiesConfigurationSP exportConfiguration)
{
// Fill with some meta information about the image
KisImageSP image = m_document->image();
KisPaintDeviceSP dev = image->projection();
const KoColorSpace* cs = dev->colorSpace();
const bool isThereAlpha =
KisPainter::checkDeviceHasTransparency(image->projection());
exportConfiguration->setProperty(KisImportExportFilter::ImageContainsTransparencyTag, isThereAlpha);
exportConfiguration->setProperty(KisImportExportFilter::ColorModelIDTag, cs->colorModelId().id());
exportConfiguration->setProperty(KisImportExportFilter::ColorDepthIDTag, cs->colorDepthId().id());
const bool sRGB =
(cs->profile()->name().contains(QLatin1String("srgb"), Qt::CaseInsensitive) &&
!cs->profile()->name().contains(QLatin1String("g10")));
exportConfiguration->setProperty(KisImportExportFilter::sRGBTag, sRGB);
}
bool
KisImportExportManager::askUserAboutExportConfiguration(
QSharedPointer filter,
KisPropertiesConfigurationSP exportConfiguration,
const QByteArray &from,
const QByteArray &to,
const bool batchMode, const bool showWarnings,
bool *alsoAsKra)
{
const QString mimeUserDescription = KisMimeDatabase::descriptionForMimeType(to);
QStringList warnings;
QStringList errors;
{
KisPreExportChecker checker;
checker.check(m_document->image(), filter->exportChecks());
warnings = checker.warnings();
errors = checker.errors();
}
KisConfigWidget *wdg = filter->createConfigurationWidget(0, from, to);
// Extra checks that cannot be done by the checker, because the checker only has access to the image.
if (!m_document->assistants().isEmpty() && to != m_document->nativeFormatMimeType()) {
warnings.append(i18nc("image conversion warning", "The image contains assistants. The assistants will not be saved."));
}
if (m_document->guidesConfig().hasGuides() && to != m_document->nativeFormatMimeType()) {
warnings.append(i18nc("image conversion warning", "The image contains guides. The guides will not be saved."));
}
if (!m_document->gridConfig().isDefault() && to != m_document->nativeFormatMimeType()) {
warnings.append(i18nc("image conversion warning", "The image contains a custom grid configuration. The configuration will not be saved."));
}
if (!batchMode && !errors.isEmpty()) {
QString error = ""
+ i18n("Error: cannot save this image as a %1.", mimeUserDescription)
+ " Reasons:
"
+ "";
Q_FOREACH(const QString &w, errors) {
error += "\n- " + w + "
";
}
error += "
";
QMessageBox::critical(KisPart::instance()->currentMainwindow(), i18nc("@title:window", "Krita: Export Error"), error);
return false;
}
if (!batchMode && (wdg || !warnings.isEmpty())) {
KoDialog dlg;
dlg.setButtons(KoDialog::Ok | KoDialog::Cancel);
dlg.setWindowTitle(mimeUserDescription);
QWidget *page = new QWidget(&dlg);
QVBoxLayout *layout = new QVBoxLayout(page);
if (showWarnings && !warnings.isEmpty()) {
QHBoxLayout *hLayout = new QHBoxLayout();
QLabel *labelWarning = new QLabel();
labelWarning->setPixmap(KisIconUtils::loadIcon("dialog-warning").pixmap(32, 32));
hLayout->addWidget(labelWarning);
KisPopupButton *bn = new KisPopupButton(0);
bn->setText(i18nc("Keep the extra space at the end of the sentence, please", "Warning: saving as %1 will lose information from your image. ", mimeUserDescription));
hLayout->addWidget(bn);
layout->addLayout(hLayout);
QTextBrowser *browser = new QTextBrowser();
browser->setMinimumWidth(bn->width());
bn->setPopupWidget(browser);
QString warning = ""
+ i18n("You will lose information when saving this image as a %1.", mimeUserDescription);
if (warnings.size() == 1) {
warning += " Reason:
";
}
else {
warning += " Reasons:
";
}
warning += "";
Q_FOREACH(const QString &w, warnings) {
warning += "\n- " + w + "
";
}
warning += "
";
browser->setHtml(warning);
}
if (wdg) {
QGroupBox *box = new QGroupBox(i18n("Options"));
QVBoxLayout *boxLayout = new QVBoxLayout(box);
wdg->setConfiguration(exportConfiguration);
boxLayout->addWidget(wdg);
layout->addWidget(box);
}
QCheckBox *chkAlsoAsKra = 0;
if (showWarnings && !warnings.isEmpty()) {
chkAlsoAsKra = new QCheckBox(i18n("Also save your image as a Krita file."));
chkAlsoAsKra->setChecked(KisConfig().readEntry("AlsoSaveAsKra", false));
layout->addWidget(chkAlsoAsKra);
}
dlg.setMainWidget(page);
dlg.resize(dlg.minimumSize());
if (showWarnings || wdg) {
if (!dlg.exec()) {
return false;
}
}
*alsoAsKra = false;
if (chkAlsoAsKra) {
KisConfig().writeEntry("AlsoSaveAsKra", chkAlsoAsKra->isChecked());
*alsoAsKra = chkAlsoAsKra->isChecked();
}
if (wdg) {
- exportConfiguration = wdg->configuration();
+ *exportConfiguration = *wdg->configuration();
}
}
return true;
}
KisImportExportFilter::ConversionStatus KisImportExportManager::doImport(const QString &location, QSharedPointer filter)
{
QFile file(location);
if (!file.exists()) {
return KisImportExportFilter::FileNotFound;
}
if (filter->supportsIO() && !file.open(QFile::ReadOnly)) {
return KisImportExportFilter::FileNotFound;
}
KisImportExportFilter::ConversionStatus status =
filter->convert(m_document, &file, KisPropertiesConfigurationSP());
if (file.isOpen()) {
file.close();
}
return status;
}
KisImportExportFilter::ConversionStatus KisImportExportManager::doExport(const QString &location, QSharedPointer filter, KisPropertiesConfigurationSP exportConfiguration, bool alsoAsKra)
{
KisImportExportFilter::ConversionStatus status =
doExportImpl(location, filter, exportConfiguration);
if (alsoAsKra && status == KisImportExportFilter::OK) {
QString kraLocation = location + ".kra";
QByteArray mime = m_document->nativeFormatMimeType();
QSharedPointer filter(
filterForMimeType(QString::fromLatin1(mime), Export));
KIS_SAFE_ASSERT_RECOVER_NOOP(filter);
if (filter) {
filter->setFilename(kraLocation);
KisPropertiesConfigurationSP kraExportConfiguration =
filter->lastSavedConfiguration(mime, mime);
status = doExportImpl(kraLocation, filter, kraExportConfiguration);
} else {
status = KisImportExportFilter::FilterCreationError;
}
}
return status;
}
KisImportExportFilter::ConversionStatus KisImportExportManager::doExportImpl(const QString &location, QSharedPointer filter, KisPropertiesConfigurationSP exportConfiguration)
{
QSaveFile file(location);
file.setDirectWriteFallback(true);
if (filter->supportsIO() && !file.open(QFile::WriteOnly)) {
file.cancelWriting();
return KisImportExportFilter::CreationError;
}
KisImportExportFilter::ConversionStatus status =
filter->convert(m_document, &file, exportConfiguration);
if (status != KisImportExportFilter::OK) {
file.cancelWriting();
} else {
file.commit();
}
return status;
}
#include
diff --git a/plugins/impex/brush/kis_brush_export.cpp b/plugins/impex/brush/kis_brush_export.cpp
index fdc3217065..9b75cfe699 100644
--- a/plugins/impex/brush/kis_brush_export.cpp
+++ b/plugins/impex/brush/kis_brush_export.cpp
@@ -1,232 +1,224 @@
/*
* Copyright (c) 2016 Boudewijn Rempt
*
* 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_brush_export.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
struct KisBrushExportOptions {
qreal spacing;
bool mask;
int brushStyle;
int selectionMode;
QString name;
};
K_PLUGIN_FACTORY_WITH_JSON(KisBrushExportFactory, "krita_brush_export.json", registerPlugin();)
KisBrushExport::KisBrushExport(QObject *parent, const QVariantList &) : KisImportExportFilter(parent)
{
}
KisBrushExport::~KisBrushExport()
{
}
KisImportExportFilter::ConversionStatus KisBrushExport::convert(KisDocument *document, QIODevice *io, KisPropertiesConfigurationSP configuration)
{
// XXX: Loading the parasite itself was commented out -- needs investigation
// KisAnnotationSP annotation = document->savingImage()->annotation("ImagePipe Parasite");
// KisPipeBrushParasite parasite;
// if (annotation) {
// QBuffer buf(const_cast(&annotation->annotation()));
// buf.open(QBuffer::ReadOnly);
// parasite.loadFromDevice(&buf);
// buf.close();
// }
KisBrushExportOptions exportOptions;
if (document->savingImage()->dynamicPropertyNames().contains("brushspacing")) {
exportOptions.spacing = document->savingImage()->property("brushspacing").toFloat();
}
else {
exportOptions.spacing = configuration->getInt("spacing");
}
if (!configuration->getString("name").isEmpty()) {
exportOptions.name = configuration->getString("name");
}
else {
exportOptions.name = document->savingImage()->objectName();
}
exportOptions.mask = configuration->getBool("mask");
exportOptions.selectionMode = configuration->getInt("selectionMode");
exportOptions.brushStyle = configuration->getInt("brushStyle");
KisGbrBrush *brush = 0;
if (mimeType() == "image/x-gimp-brush") {
brush = new KisGbrBrush(filename());
}
else if (mimeType() == "image/x-gimp-brush-animated") {
brush = new KisImagePipeBrush(filename());
}
else {
return KisImportExportFilter::BadMimeType;
}
qApp->processEvents(); // For vector layers to be updated
QRect rc = document->savingImage()->bounds();
brush->setName(exportOptions.name);
brush->setSpacing(exportOptions.spacing);
brush->setUseColorAsMask(exportOptions.mask);
int w = document->savingImage()->width();
int h = document->savingImage()->height();
KisImagePipeBrush *pipeBrush = dynamic_cast(brush);
if (pipeBrush) {
// Create parasite. XXX: share with KisCustomBrushWidget
QVector< QVector > devices;
devices.push_back(QVector());
KoProperties properties;
properties.setProperty("visible", true);
QList layers = document->savingImage()->root()->childNodes(QStringList("KisLayer"), properties);
Q_FOREACH (KisNodeSP node, layers) {
devices[0].push_back(node->projection().data());
}
QVector modes;
switch (exportOptions.selectionMode) {
case 0: modes.push_back(KisParasite::Constant); break;
case 1: modes.push_back(KisParasite::Random); break;
case 2: modes.push_back(KisParasite::Incremental); break;
case 3: modes.push_back(KisParasite::Pressure); break;
case 4: modes.push_back(KisParasite::Angular); break;
default: modes.push_back(KisParasite::Incremental);
}
KisPipeBrushParasite parasite;
// XXX: share code with KisImagePipeBrush, when we figure out how to support more gih features
parasite.dim = devices.count();
// XXX Change for multidim! :
parasite.ncells = devices.at(0).count();
parasite.rank[0] = parasite.ncells; // ### This can mask some bugs, be careful here in the future
parasite.selection[0] = modes.at(0);
// XXX needsmovement!
parasite.setBrushesCount();
pipeBrush->setParasite(parasite);
pipeBrush->setDevices(devices, w, h);
}
else {
QImage image = document->savingImage()->projection()->convertToQImage(0, 0, 0, rc.width(), rc.height(), KoColorConversionTransformation::internalRenderingIntent(), KoColorConversionTransformation::internalConversionFlags());
brush->setImage(image);
}
brush->setWidth(w);
brush->setHeight(h);
brush->saveToDevice(io);
return KisImportExportFilter::OK;
}
KisPropertiesConfigurationSP KisBrushExport::defaultConfiguration(const QByteArray &/*from*/, const QByteArray &/*to*/) const
{
KisPropertiesConfigurationSP cfg = new KisPropertiesConfiguration();
cfg->setProperty("spacing", 1.0);
cfg->setProperty("name", "");
cfg->setProperty("mask", true);
cfg->setProperty("selectionMode", 0);
cfg->setProperty("brushStyle", 0);
return cfg;
}
-KisPropertiesConfigurationSP KisBrushExport::lastSavedConfiguration(const QByteArray &from, const QByteArray &to) const
-{
- KisPropertiesConfigurationSP cfg = defaultConfiguration(from, to);
- QString filterConfig = KisConfig().exportConfiguration(mimeType());
- cfg->fromXML(filterConfig, false);
- return cfg;
-}
-
KisConfigWidget *KisBrushExport::createConfigurationWidget(QWidget *parent, const QByteArray &/*from*/, const QByteArray &to) const
{
KisWdgOptionsBrush *wdg = new KisWdgOptionsBrush(parent);
if (to == "image/x-gimp-brush") {
wdg->groupBox->setVisible(false);
}
else if (to == "image/x-gimp-brush-animated") {
wdg->groupBox->setVisible(true);
}
return wdg;
}
void KisBrushExport::initializeCapabilities()
{
QList > supportedColorModels;
supportedColorModels << QPair()
<< QPair(RGBAColorModelID, Integer8BitsColorDepthID)
<< QPair(GrayAColorModelID, Integer8BitsColorDepthID);
addSupportedColorModels(supportedColorModels, "Gimp Brushes");
if (mimeType() == "image/x-gimp-brush-animated") {
addCapability(KisExportCheckRegistry::instance()->get("MultiLayerCheck")->create(KisExportCheckBase::SUPPORTED));
}
}
void KisWdgOptionsBrush::setConfiguration(const KisPropertiesConfigurationSP cfg)
{
spacingWidget->setSpacing(false, cfg->getBool("spacing"));
nameLineEdit->setText(cfg->getString("name"));
brushNameLbl->setText(cfg->getString("name"));
colorAsMask->setChecked(cfg->getBool("mask"));
brushStyle->setCurrentIndex(cfg->getInt("selectionMode"));
cmbSelectionMode->setCurrentIndex(cfg->getInt("brushStyle"));
}
KisPropertiesConfigurationSP KisWdgOptionsBrush::configuration() const
{
KisPropertiesConfigurationSP cfg = new KisPropertiesConfiguration();
cfg->setProperty("spacing", spacingWidget->spacing());
cfg->setProperty("name", brushNameLbl->text());
cfg->setProperty("mask", colorAsMask->isChecked());
cfg->setProperty("selectionMode", brushStyle->currentIndex());
cfg->setProperty("brushStyle", cmbSelectionMode->currentIndex());
return cfg;
}
#include "kis_brush_export.moc"
diff --git a/plugins/impex/brush/kis_brush_export.h b/plugins/impex/brush/kis_brush_export.h
index e901009b46..9de2e6a44f 100644
--- a/plugins/impex/brush/kis_brush_export.h
+++ b/plugins/impex/brush/kis_brush_export.h
@@ -1,61 +1,60 @@
/*
* Copyright (c) 2016 Boudewijn Rempt
*
* 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_Brush_EXPORT_H_
#define _KIS_Brush_EXPORT_H_
#include
#include
#include
#include
#include
class KisWdgOptionsBrush : public KisConfigWidget, public Ui::WdgExportGih
{
Q_OBJECT
public:
KisWdgOptionsBrush(QWidget *parent)
: KisConfigWidget(parent)
{
setupUi(this);
}
void setConfiguration(const KisPropertiesConfigurationSP cfg);
KisPropertiesConfigurationSP configuration() const;
};
class KisBrushExport : public KisImportExportFilter
{
Q_OBJECT
public:
KisBrushExport(QObject *parent, const QVariantList &);
virtual ~KisBrushExport();
virtual bool supportsIO() const { return false; }
virtual KisImportExportFilter::ConversionStatus convert(KisDocument *document, QIODevice *io, KisPropertiesConfigurationSP configuration = 0);
KisPropertiesConfigurationSP defaultConfiguration(const QByteArray& from = "", const QByteArray& to = "") const;
- KisPropertiesConfigurationSP lastSavedConfiguration(const QByteArray &from = "", const QByteArray &to = "") const;
KisConfigWidget *createConfigurationWidget(QWidget *parent, const QByteArray& from = "", const QByteArray& to = "") const;
void initializeCapabilities();
};
#endif
diff --git a/plugins/impex/exr/exr_export.cc b/plugins/impex/exr/exr_export.cc
index d8efa42058..54441ef43a 100644
--- a/plugins/impex/exr/exr_export.cc
+++ b/plugins/impex/exr/exr_export.cc
@@ -1,164 +1,156 @@
/*
* Copyright (c) 2010 Cyrille Berger
*
* 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 "exr_export.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "exr_converter.h"
class KisExternalLayer;
K_PLUGIN_FACTORY_WITH_JSON(ExportFactory, "krita_exr_export.json", registerPlugin();)
EXRExport::EXRExport(QObject *parent, const QVariantList &) : KisImportExportFilter(parent)
{
}
EXRExport::~EXRExport()
{
}
KisPropertiesConfigurationSP EXRExport::defaultConfiguration(const QByteArray &/*from*/, const QByteArray &/*to*/) const
{
KisPropertiesConfigurationSP cfg = new KisPropertiesConfiguration();
cfg->setProperty("flatten", false);
return cfg;
}
-KisPropertiesConfigurationSP EXRExport::lastSavedConfiguration(const QByteArray &from, const QByteArray &to) const
-{
- KisPropertiesConfigurationSP cfg = defaultConfiguration(from, to);
- QString filterConfig = KisConfig().exportConfiguration(mimeType());
- cfg->fromXML(filterConfig, false);
- return cfg;
-}
-
KisConfigWidget *EXRExport::createConfigurationWidget(QWidget *parent, const QByteArray &/*from*/, const QByteArray &/*to*/) const
{
return new KisWdgOptionsExr(parent);
}
KisImportExportFilter::ConversionStatus EXRExport::convert(KisDocument *document, QIODevice */*io*/, KisPropertiesConfigurationSP configuration)
{
KisImageSP image = document->savingImage();
EXRConverter exrConverter(document, !batchMode());
KisImageBuilder_Result res;
if (configuration->getBool("flatten")) {
KisPaintDeviceSP pd = new KisPaintDevice(*image->projection());
KisPaintLayerSP l = new KisPaintLayer(image, "projection", OPACITY_OPAQUE_U8, pd);
res = exrConverter.buildFile(filename(), l);
}
else {
res = exrConverter.buildFile(filename(), image->rootLayer());
}
dbgFile << " Result =" << res;
switch (res) {
case KisImageBuilder_RESULT_INVALID_ARG:
document->setErrorMessage(i18n("This layer cannot be saved to EXR."));
return KisImportExportFilter::WrongFormat;
case KisImageBuilder_RESULT_EMPTY:
document->setErrorMessage(i18n("The layer does not have an image associated with it."));
return KisImportExportFilter::WrongFormat;
case KisImageBuilder_RESULT_NO_URI:
document->setErrorMessage(i18n("The filename is empty."));
return KisImportExportFilter::CreationError;
case KisImageBuilder_RESULT_NOT_LOCAL:
document->setErrorMessage(i18n("EXR images cannot be saved remotely."));
return KisImportExportFilter::InternalError;
case KisImageBuilder_RESULT_UNSUPPORTED_COLORSPACE:
document->setErrorMessage(i18n("Colorspace not supported: EXR images must be 16 or 32 bits floating point RGB."));
return KisImportExportFilter::WrongFormat;
case KisImageBuilder_RESULT_OK:
document->setErrorMessage(exrConverter.errorMessage());
return KisImportExportFilter::OK;
default:
break;
}
document->setErrorMessage(i18n("Internal Error"));
return KisImportExportFilter::InternalError;
}
void EXRExport::initializeCapabilities()
{
addCapability(KisExportCheckRegistry::instance()->get("NodeTypeCheck/KisGroupLayer")->create(KisExportCheckBase::SUPPORTED));
addCapability(KisExportCheckRegistry::instance()->get("MultiLayerCheck")->create(KisExportCheckBase::SUPPORTED));
addCapability(KisExportCheckRegistry::instance()->get("sRGBProfileCheck")->create(KisExportCheckBase::SUPPORTED));
QList > supportedColorModels;
supportedColorModels << QPair()
<< QPair(RGBAColorModelID, Float16BitsColorDepthID)
<< QPair(RGBAColorModelID, Float32BitsColorDepthID)
<< QPair(GrayAColorModelID, Float16BitsColorDepthID)
<< QPair(GrayAColorModelID, Float32BitsColorDepthID)
<< QPair(GrayColorModelID, Float16BitsColorDepthID)
<< QPair(GrayColorModelID, Float32BitsColorDepthID)
<< QPair(XYZAColorModelID, Float16BitsColorDepthID)
<< QPair(XYZAColorModelID, Float32BitsColorDepthID);
addSupportedColorModels(supportedColorModels, "TIFF");
}
void KisWdgOptionsExr::setConfiguration(const KisPropertiesConfigurationSP cfg)
{
chkFlatten->setChecked(cfg->getBool("flatten", false));
}
KisPropertiesConfigurationSP KisWdgOptionsExr::configuration() const
{
KisPropertiesConfigurationSP cfg = new KisPropertiesConfiguration();
cfg->setProperty("flatten", chkFlatten->isChecked());
return cfg;
}
#include
diff --git a/plugins/impex/exr/exr_export.h b/plugins/impex/exr/exr_export.h
index 23cd869859..c58f139944 100644
--- a/plugins/impex/exr/exr_export.h
+++ b/plugins/impex/exr/exr_export.h
@@ -1,60 +1,59 @@
/*
* Copyright (c) 2010 Cyrille Berger
*
* 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 _EXR_EXPORT_H_
#define _EXR_EXPORT_H_
#include
#include
#include
#include "ui_exr_export_widget.h"
class KisWdgOptionsExr : public KisConfigWidget, public Ui::ExrExportWidget
{
Q_OBJECT
public:
KisWdgOptionsExr(QWidget *parent)
: KisConfigWidget(parent)
{
setupUi(this);
}
void setConfiguration(const KisPropertiesConfigurationSP cfg);
KisPropertiesConfigurationSP configuration() const;
};
class EXRExport : public KisImportExportFilter
{
Q_OBJECT
public:
EXRExport(QObject *parent, const QVariantList &);
virtual ~EXRExport();
virtual bool supportsIO() const { return false; }
virtual KisImportExportFilter::ConversionStatus convert(KisDocument *document, QIODevice *io, KisPropertiesConfigurationSP configuration = 0);
KisPropertiesConfigurationSP defaultConfiguration(const QByteArray& from = "", const QByteArray& to = "") const;
- KisPropertiesConfigurationSP lastSavedConfiguration(const QByteArray &from = "", const QByteArray &to = "") const;
KisConfigWidget *createConfigurationWidget(QWidget *parent, const QByteArray& from = "", const QByteArray& to = "") const;
void initializeCapabilities();
};
#endif
diff --git a/plugins/impex/heightmap/kis_heightmap_export.cpp b/plugins/impex/heightmap/kis_heightmap_export.cpp
index afae3f1452..fb965db532 100644
--- a/plugins/impex/heightmap/kis_heightmap_export.cpp
+++ b/plugins/impex/heightmap/kis_heightmap_export.cpp
@@ -1,148 +1,140 @@
/*
* Copyright (c) 2014 Boudewijn Rempt
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; version 2.1 of the License.
*
* This library 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser 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_heightmap_export.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
K_PLUGIN_FACTORY_WITH_JSON(KisHeightMapExportFactory, "krita_heightmap_export.json", registerPlugin();)
KisHeightMapExport::KisHeightMapExport(QObject *parent, const QVariantList &) : KisImportExportFilter(parent)
{
}
KisHeightMapExport::~KisHeightMapExport()
{
}
KisPropertiesConfigurationSP KisHeightMapExport::defaultConfiguration(const QByteArray &/*from*/, const QByteArray &/*to*/) const
{
KisPropertiesConfigurationSP cfg = new KisPropertiesConfiguration();
cfg->setProperty("endianness", 0);
return cfg;
}
-KisPropertiesConfigurationSP KisHeightMapExport::lastSavedConfiguration(const QByteArray &from, const QByteArray &to) const
-{
- KisPropertiesConfigurationSP cfg = defaultConfiguration(from, to);
- QString filterConfig = KisConfig().exportConfiguration("HeightMap");
- cfg->fromXML(filterConfig, false);
- return cfg;
-}
-
KisConfigWidget *KisHeightMapExport::createConfigurationWidget(QWidget *parent, const QByteArray &/*from*/, const QByteArray &/*to*/) const
{
return new KisWdgOptionsHeightmap(parent);
}
void KisHeightMapExport::initializeCapabilities()
{
if (mimeType() == "image/x-r8") {
QList > supportedColorModels;
supportedColorModels << QPair()
<< QPair(GrayAColorModelID, Integer8BitsColorDepthID);
addSupportedColorModels(supportedColorModels, "R8 Heightmap");
}
else if (mimeType() == "image/x-r16") {
QList > supportedColorModels;
supportedColorModels << QPair()
<< QPair(GrayAColorModelID, Integer16BitsColorDepthID);
addSupportedColorModels(supportedColorModels, "R16 Heightmap");
}
}
KisImportExportFilter::ConversionStatus KisHeightMapExport::convert(KisDocument *document, QIODevice *io, KisPropertiesConfigurationSP configuration)
{
KisImageSP image = document->savingImage();
if (image->width() != image->height()) {
document->setErrorMessage(i18n("Cannot export this image to a heightmap: it is not square"));
return KisImportExportFilter::WrongFormat;
}
configuration->setProperty("width", image->width());
QDataStream::ByteOrder bo = configuration->getInt("endianness", 0) ? QDataStream::BigEndian : QDataStream::LittleEndian;
bool downscale = false;
KisPaintDeviceSP pd = new KisPaintDevice(*image->projection());
QDataStream s(io);
s.setByteOrder(bo);
KisRandomConstAccessorSP it = pd->createRandomConstAccessorNG(0, 0);
bool r16 = ((image->colorSpace()->colorDepthId() == Integer16BitsColorDepthID) && !downscale);
for (int i = 0; i < image->height(); ++i) {
for (int j = 0; j < image->width(); ++j) {
it->moveTo(i, j);
if (r16) {
s << KoGrayU16Traits::gray(const_cast(it->rawDataConst()));
}
else {
s << KoGrayU8Traits::gray(const_cast(it->rawDataConst()));
}
}
}
return KisImportExportFilter::OK;
}
void KisWdgOptionsHeightmap::setConfiguration(const KisPropertiesConfigurationSP cfg)
{
intSize->setValue(cfg->getInt("width"));
int endianness = cfg->getInt("endianness", 0);
radioMac->setChecked(endianness == 0);
}
KisPropertiesConfigurationSP KisWdgOptionsHeightmap::configuration() const
{
KisPropertiesConfigurationSP cfg = new KisPropertiesConfiguration();
if (radioMac->isChecked()) {
cfg->setProperty("endianness", 0);
}
else {
cfg->setProperty("endianness", 1);
}
return cfg;
}
#include "kis_heightmap_export.moc"
diff --git a/plugins/impex/heightmap/kis_heightmap_export.h b/plugins/impex/heightmap/kis_heightmap_export.h
index 1bfd9f0e45..e994135479 100644
--- a/plugins/impex/heightmap/kis_heightmap_export.h
+++ b/plugins/impex/heightmap/kis_heightmap_export.h
@@ -1,58 +1,57 @@
/*
* Copyright (c) 2014 Boudewijn Rempt
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; version 2.1 of the License.
*
* This library 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser 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_HeightMap_EXPORT_H_
#define _KIS_HeightMap_EXPORT_H_
#include
#include
#include
#include "ui_kis_wdg_options_heightmap.h"
class KisWdgOptionsHeightmap : public KisConfigWidget, public Ui::WdgOptionsHeightMap
{
Q_OBJECT
public:
KisWdgOptionsHeightmap(QWidget *parent)
: KisConfigWidget(parent)
{
setupUi(this);
}
void setConfiguration(const KisPropertiesConfigurationSP cfg);
KisPropertiesConfigurationSP configuration() const;
};
class KisHeightMapExport : public KisImportExportFilter
{
Q_OBJECT
public:
KisHeightMapExport(QObject *parent, const QVariantList &);
virtual ~KisHeightMapExport();
KisPropertiesConfigurationSP defaultConfiguration(const QByteArray& from = "", const QByteArray& to = "") const;
- KisPropertiesConfigurationSP lastSavedConfiguration(const QByteArray &from = "", const QByteArray &to = "") const;
KisConfigWidget *createConfigurationWidget(QWidget *parent, const QByteArray& from = "", const QByteArray& to = "") const;
void initializeCapabilities();
virtual KisImportExportFilter::ConversionStatus convert(KisDocument *document, QIODevice *io, KisPropertiesConfigurationSP configuration = 0);
};
#endif
diff --git a/plugins/impex/jpeg/kis_jpeg_export.cc b/plugins/impex/jpeg/kis_jpeg_export.cc
index b55c4fecb9..b03fb7983f 100644
--- a/plugins/impex/jpeg/kis_jpeg_export.cc
+++ b/plugins/impex/jpeg/kis_jpeg_export.cc
@@ -1,230 +1,222 @@
/*
* Copyright (c) 2005 Cyrille Berger
*
* 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_jpeg_export.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "kis_jpeg_converter.h"
class KisExternalLayer;
K_PLUGIN_FACTORY_WITH_JSON(KisJPEGExportFactory, "krita_jpeg_export.json", registerPlugin();)
KisJPEGExport::KisJPEGExport(QObject *parent, const QVariantList &) : KisImportExportFilter(parent)
{
}
KisJPEGExport::~KisJPEGExport()
{
}
KisImportExportFilter::ConversionStatus KisJPEGExport::convert(KisDocument *document, QIODevice *io, KisPropertiesConfigurationSP configuration)
{
KisImageSP image = document->savingImage();
Q_CHECK_PTR(image);
// An extra option to pass to the config widget to set the state correctly, this isn't saved
const KoColorSpace* cs = image->projection()->colorSpace();
bool sRGB = cs->profile()->name().contains(QLatin1String("srgb"), Qt::CaseInsensitive);
configuration->setProperty("is_sRGB", sRGB);
KisJPEGOptions options;
options.progressive = configuration->getBool("progressive", false);
options.quality = configuration->getInt("quality", 80);
options.forceSRGB = configuration->getBool("forceSRGB", false);
options.saveProfile = configuration->getBool("saveProfile", true);
options.optimize = configuration->getBool("optimize", true);
options.smooth = configuration->getInt("smoothing", 0);
options.baseLineJPEG = configuration->getBool("baseline", true);
options.subsampling = configuration->getInt("subsampling", 0);
options.exif = configuration->getBool("exif", true);
options.iptc = configuration->getBool("iptc", true);
options.xmp = configuration->getBool("xmp", true);
options.transparencyFillColor = configuration->getColor("transparencyFillcolor").toQColor();
KisMetaData::FilterRegistryModel m;
m.setEnabledFilters(configuration->getString("filters").split(","));
options.filters = m.enabledFilters();
KisPaintDeviceSP pd = new KisPaintDevice(*image->projection());
KisJPEGConverter kpc(document, batchMode());
KisPaintLayerSP l = new KisPaintLayer(image, "projection", OPACITY_OPAQUE_U8, pd);
KisExifInfoVisitor eIV;
eIV.visit(image->rootLayer().data());
KisMetaData::Store* eI = 0;
if (eIV.countPaintLayer() == 1) {
eI = eIV.exifInfo();
}
if (eI) {
KisMetaData::Store* copy = new KisMetaData::Store(*eI);
eI = copy;
}
KisImageBuilder_Result res = kpc.buildFile(io, l, options, eI);
if (res == KisImageBuilder_RESULT_OK) {
delete eI;
return KisImportExportFilter::OK;
}
delete eI;
dbgFile << " Result =" << res;
return KisImportExportFilter::InternalError;
}
KisPropertiesConfigurationSP KisJPEGExport::defaultConfiguration(const QByteArray &/*from*/, const QByteArray &/*to*/) const
{
KisPropertiesConfigurationSP cfg = new KisPropertiesConfiguration();
cfg->setProperty("progressive", false);
cfg->setProperty("quality", 80);
cfg->setProperty("forceSRGB", false);
cfg->setProperty("saveProfile", true);
cfg->setProperty("optimize", true);
cfg->setProperty("smoothing", 0);
cfg->setProperty("baseline", true);
cfg->setProperty("subsampling", 0);
cfg->setProperty("exif", true);
cfg->setProperty("iptc", true);
cfg->setProperty("xmp", true);
cfg->setProperty("transparencyFillcolor", QString("255,255,255"));
cfg->setProperty("filters", "");
return cfg;
}
-KisPropertiesConfigurationSP KisJPEGExport::lastSavedConfiguration(const QByteArray &from, const QByteArray &to) const
-{
- KisPropertiesConfigurationSP cfg = defaultConfiguration(from, to);
- QString filterConfig = KisConfig().exportConfiguration(to);
- cfg->fromXML(filterConfig, false);
- return cfg;
-}
-
KisConfigWidget *KisJPEGExport::createConfigurationWidget(QWidget *parent, const QByteArray &/*from*/, const QByteArray &/*to*/) const
{
return new KisWdgOptionsJPEG(parent);
}
void KisJPEGExport::initializeCapabilities()
{
addCapability(KisExportCheckRegistry::instance()->get("sRGBProfileCheck")->create(KisExportCheckBase::SUPPORTED));
addCapability(KisExportCheckRegistry::instance()->get("ExifCheck")->create(KisExportCheckBase::SUPPORTED));
QList > supportedColorModels;
supportedColorModels << QPair()
<< QPair(RGBAColorModelID, Integer8BitsColorDepthID)
<< QPair(GrayAColorModelID, Integer8BitsColorDepthID)
<< QPair(CMYKAColorModelID, Integer8BitsColorDepthID);
addSupportedColorModels(supportedColorModels, "JPEG");
}
KisWdgOptionsJPEG::KisWdgOptionsJPEG(QWidget *parent)
: KisConfigWidget(parent)
{
setupUi(this);
metaDataFilters->setModel(&m_filterRegistryModel);
qualityLevel->setRange(0, 100, 0);
qualityLevel->setSuffix("%");
smoothLevel->setRange(0, 100, 0);
smoothLevel->setSuffix("%");
}
void KisWdgOptionsJPEG::setConfiguration(const KisPropertiesConfigurationSP cfg)
{
progressive->setChecked(cfg->getBool("progressive", false));
qualityLevel->setValue(cfg->getInt("quality", 80));
optimize->setChecked(cfg->getBool("optimize", true));
smoothLevel->setValue(cfg->getInt("smoothing", 0));
baseLineJPEG->setChecked(cfg->getBool("baseline", true));
subsampling->setCurrentIndex(cfg->getInt("subsampling", 0));
exif->setChecked(cfg->getBool("exif", true));
iptc->setChecked(cfg->getBool("iptc", true));
xmp->setChecked(cfg->getBool("xmp", true));
chkForceSRGB->setVisible(cfg->getBool("is_sRGB"));
chkForceSRGB->setChecked(cfg->getBool("forceSRGB", false));
chkSaveProfile->setChecked(cfg->getBool("saveProfile", true));
QStringList rgb = cfg->getString("transparencyFillcolor", "255,255,255").split(',');
KoColor background(KoColorSpaceRegistry::instance()->rgb8());
background.fromQColor(Qt::white);
bnTransparencyFillColor->setDefaultColor(background);
background.fromQColor(QColor(rgb[0].toInt(), rgb[1].toInt(), rgb[2].toInt()));
bnTransparencyFillColor->setColor(background);
m_filterRegistryModel.setEnabledFilters(cfg->getString("filters").split(','));
}
KisPropertiesConfigurationSP KisWdgOptionsJPEG::configuration() const
{
KisPropertiesConfigurationSP cfg = new KisPropertiesConfiguration();
cfg->setProperty("progressive", progressive->isChecked());
cfg->setProperty("quality", (int)qualityLevel->value());
cfg->setProperty("forceSRGB", chkForceSRGB->isChecked());
cfg->setProperty("saveProfile", chkSaveProfile->isChecked());
cfg->setProperty("optimize", optimize->isChecked());
cfg->setProperty("smoothing", (int)smoothLevel->value());
cfg->setProperty("baseline", baseLineJPEG->isChecked());
cfg->setProperty("subsampling", subsampling->currentIndex());
cfg->setProperty("exif", exif->isChecked());
cfg->setProperty("iptc", iptc->isChecked());
cfg->setProperty("xmp", xmp->isChecked());
QColor c = bnTransparencyFillColor->color().toQColor();
cfg->setProperty("transparencyFillcolor", QString("%1,%2,%3").arg(c.red()).arg(c.green()).arg(c.blue()));
QString enabledFilters;
Q_FOREACH (const KisMetaData::Filter* filter, m_filterRegistryModel.enabledFilters()) {
enabledFilters = enabledFilters + filter->id() + ',';
}
cfg->setProperty("filters", enabledFilters);
return cfg;
}
#include
diff --git a/plugins/impex/jpeg/kis_jpeg_export.h b/plugins/impex/jpeg/kis_jpeg_export.h
index c7687f5485..231018b45e 100644
--- a/plugins/impex/jpeg/kis_jpeg_export.h
+++ b/plugins/impex/jpeg/kis_jpeg_export.h
@@ -1,59 +1,58 @@
/*
* Copyright (c) 2005 Cyrille Berger
*
* 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_JPEG_EXPORT_H_
#define _KIS_JPEG_EXPORT_H_
#include
#include
#include
#include "ui_kis_wdg_options_jpeg.h"
#include
#include
class KisWdgOptionsJPEG : public KisConfigWidget, public Ui::WdgOptionsJPEG
{
Q_OBJECT
public:
KisWdgOptionsJPEG(QWidget *parent);
void setConfiguration(const KisPropertiesConfigurationSP cfg);
KisPropertiesConfigurationSP configuration() const;
private:
KisMetaData::FilterRegistryModel m_filterRegistryModel;
};
class KisJPEGExport : public KisImportExportFilter
{
Q_OBJECT
public:
KisJPEGExport(QObject *parent, const QVariantList &);
virtual ~KisJPEGExport();
public:
virtual KisImportExportFilter::ConversionStatus convert(KisDocument *document, QIODevice *io, KisPropertiesConfigurationSP configuration = 0);
KisPropertiesConfigurationSP defaultConfiguration(const QByteArray& from = "", const QByteArray& to = "") const;
- KisPropertiesConfigurationSP lastSavedConfiguration(const QByteArray &from = "", const QByteArray &to = "") const;
KisConfigWidget *createConfigurationWidget(QWidget *parent, const QByteArray& from = "", const QByteArray& to = "") const;
void initializeCapabilities();
};
#endif
diff --git a/plugins/impex/png/kis_png_export.cc b/plugins/impex/png/kis_png_export.cc
index 598fc69e30..f942a39304 100644
--- a/plugins/impex/png/kis_png_export.cc
+++ b/plugins/impex/png/kis_png_export.cc
@@ -1,232 +1,224 @@
/*
* Copyright (c) 2005 Cyrille Berger
*
* 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_png_export.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "kis_png_converter.h"
#include
K_PLUGIN_FACTORY_WITH_JSON(KisPNGExportFactory, "krita_png_export.json", registerPlugin();)
KisPNGExport::KisPNGExport(QObject *parent, const QVariantList &) : KisImportExportFilter(parent)
{
}
KisPNGExport::~KisPNGExport()
{
}
bool hasVisibleWidgets()
{
QWidgetList wl = QApplication::allWidgets();
Q_FOREACH (QWidget* w, wl) {
if (w->isVisible() && strcmp(w->metaObject()->className(), "QDesktopWidget")) {
dbgFile << "Widget " << w << " " << w->objectName() << " " << w->metaObject()->className() << " is visible";
return true;
}
}
return false;
}
KisImportExportFilter::ConversionStatus KisPNGExport::convert(KisDocument *document, QIODevice *io, KisPropertiesConfigurationSP configuration)
{
KisImageSP image = document->savingImage();
KisPNGOptions options;
options.alpha = configuration->getBool("alpha", true);
options.interlace = configuration->getBool("interlaced", false);
options.compression = configuration->getInt("compression", 3);
options.tryToSaveAsIndexed = configuration->getBool("indexed", false);
options.transparencyFillColor = configuration->getColor("transparencyFillColor").toQColor();
options.saveSRGBProfile = configuration->getBool("saveSRGBProfile", false);
options.forceSRGB = configuration->getBool("forceSRGB", true);
vKisAnnotationSP_it beginIt = image->beginAnnotations();
vKisAnnotationSP_it endIt = image->endAnnotations();
KisExifInfoVisitor eIV;
eIV.visit(image->rootLayer().data());
KisMetaData::Store *eI = 0;
if (eIV.countPaintLayer() == 1) {
eI = eIV.exifInfo();
}
if (eI) {
KisMetaData::Store* copy = new KisMetaData::Store(*eI);
eI = copy;
}
KisPNGConverter pngConverter(document);
KisImageBuilder_Result res = pngConverter.buildFile(io, image->bounds(), image->xRes(), image->yRes(), image->projection(), beginIt, endIt, options, eI);
if (res == KisImageBuilder_RESULT_OK) {
delete eI;
return KisImportExportFilter::OK;
}
delete eI;
dbgFile << " Result =" << res;
return KisImportExportFilter::InternalError;
}
KisPropertiesConfigurationSP KisPNGExport::defaultConfiguration(const QByteArray &, const QByteArray &) const
{
KisPropertiesConfigurationSP cfg = new KisPropertiesConfiguration();
cfg->setProperty("alpha", true);
cfg->setProperty("indexed", false);
cfg->setProperty("compression", 3);
cfg->setProperty("interlaced", false);
cfg->setProperty("transparencyFillcolor", QString("255,255,255"));
cfg->setProperty("saveSRGBProfile", false);
cfg->setProperty("forceSRGB", true);
return cfg;
}
-KisPropertiesConfigurationSP KisPNGExport::lastSavedConfiguration(const QByteArray &from, const QByteArray &to) const
-{
- QString filterConfig = KisConfig().exportConfiguration("PNG");
- KisPropertiesConfigurationSP cfg = defaultConfiguration(from, to);
- cfg->fromXML(filterConfig, false);
- return cfg;
-}
-
KisConfigWidget *KisPNGExport::createConfigurationWidget(QWidget *parent, const QByteArray &, const QByteArray &) const
{
return new KisWdgOptionsPNG(parent);
}
void KisPNGExport::initializeCapabilities()
{
addCapability(KisExportCheckRegistry::instance()->get("sRGBProfileCheck")->create(KisExportCheckBase::SUPPORTED));
QList > supportedColorModels;
supportedColorModels << QPair()
<< QPair(RGBAColorModelID, Integer8BitsColorDepthID)
<< QPair(RGBAColorModelID, Integer16BitsColorDepthID)
<< QPair(GrayAColorModelID, Integer8BitsColorDepthID)
<< QPair(GrayAColorModelID, Integer16BitsColorDepthID);
addSupportedColorModels(supportedColorModels, "PNG");
}
void KisWdgOptionsPNG::setConfiguration(const KisPropertiesConfigurationSP cfg)
{
// the export manager should have prepared some info for us!
KIS_SAFE_ASSERT_RECOVER_NOOP(cfg->hasProperty(KisImportExportFilter::ImageContainsTransparencyTag));
KIS_SAFE_ASSERT_RECOVER_NOOP(cfg->hasProperty(KisImportExportFilter::ColorModelIDTag));
KIS_SAFE_ASSERT_RECOVER_NOOP(cfg->hasProperty(KisImportExportFilter::sRGBTag));
const bool isThereAlpha = cfg->getBool(KisImportExportFilter::ImageContainsTransparencyTag);
alpha->setChecked(cfg->getBool("alpha", isThereAlpha));
if (cfg->getString(KisImportExportFilter::ColorModelIDTag) == RGBAColorModelID.id()) {
tryToSaveAsIndexed->setVisible(true);
if (alpha->isChecked()) {
tryToSaveAsIndexed->setChecked(false);
}
else {
tryToSaveAsIndexed->setChecked(cfg->getBool("indexed", false));
}
}
else {
tryToSaveAsIndexed->setVisible(false);
}
interlacing->setChecked(cfg->getBool("interlaced", false));
compressionLevel->setValue(cfg->getInt("compression", 3));
compressionLevel->setRange(1, 9 , 0);
alpha->setEnabled(isThereAlpha);
tryToSaveAsIndexed->setVisible(!isThereAlpha);
bnTransparencyFillColor->setEnabled(!alpha->isChecked());
const bool sRGB = cfg->getBool(KisImportExportFilter::sRGBTag, false);
chkSRGB->setEnabled(sRGB);
chkSRGB->setChecked(cfg->getBool("saveSRGBProfile", true));
chkForceSRGB->setEnabled(!sRGB);
chkForceSRGB->setChecked(cfg->getBool("forceSRGB", false));
QStringList rgb = cfg->getString("transparencyFillcolor", "0,0,0").split(',');
KoColor c(KoColorSpaceRegistry::instance()->rgb8());
c.fromQColor(Qt::white);
bnTransparencyFillColor->setDefaultColor(c);
c.fromQColor(QColor(rgb[0].toInt(), rgb[1].toInt(), rgb[2].toInt()));
bnTransparencyFillColor->setColor(c);
}
KisPropertiesConfigurationSP KisWdgOptionsPNG::configuration() const
{
KisPropertiesConfigurationSP cfg(new KisPropertiesConfiguration());
bool alpha = this->alpha->isChecked();
bool interlace = interlacing->isChecked();
int compression = (int)compressionLevel->value();
bool tryToSaveAsIndexed = this->tryToSaveAsIndexed->isChecked();
QColor c = bnTransparencyFillColor->color().toQColor();
bool saveSRGB = chkSRGB->isChecked();
bool forceSRGB = chkForceSRGB->isChecked();
cfg->setProperty("alpha", alpha);
cfg->setProperty("indexed", tryToSaveAsIndexed);
cfg->setProperty("compression", compression);
cfg->setProperty("interlaced", interlace);
cfg->setProperty("transparencyFillcolor", QString("%1,%2,%3").arg(c.red()).arg(c.green()).arg(c.blue()));
cfg->setProperty("saveSRGBProfile", saveSRGB);
cfg->setProperty("forceSRGB", forceSRGB);
return cfg;
}
void KisWdgOptionsPNG::on_alpha_toggled(bool checked)
{
bnTransparencyFillColor->setEnabled(!checked);
}
#include "kis_png_export.moc"
diff --git a/plugins/impex/png/kis_png_export.h b/plugins/impex/png/kis_png_export.h
index 8fcddb1f1d..ea32d8c544 100644
--- a/plugins/impex/png/kis_png_export.h
+++ b/plugins/impex/png/kis_png_export.h
@@ -1,63 +1,62 @@
/*
* Copyright (c) 2005 Cyrille Berger
*
* 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_PNG_EXPORT_H_
#define _KIS_PNG_EXPORT_H_
#include "ui_kis_wdg_options_png.h"
#include
#include
class KisWdgOptionsPNG : public KisConfigWidget, public Ui::KisWdgOptionsPNG
{
Q_OBJECT
public:
KisWdgOptionsPNG(QWidget *parent)
: KisConfigWidget(parent)
{
setupUi(this);
}
void setConfiguration(const KisPropertiesConfigurationSP config);
KisPropertiesConfigurationSP configuration() const;
private Q_SLOTS:
void on_alpha_toggled(bool checked);
};
class KisPNGExport : public KisImportExportFilter
{
Q_OBJECT
public:
KisPNGExport(QObject *parent, const QVariantList &);
virtual ~KisPNGExport();
public:
virtual KisImportExportFilter::ConversionStatus convert(KisDocument *document, QIODevice *io, KisPropertiesConfigurationSP configuration = 0);
KisPropertiesConfigurationSP defaultConfiguration(const QByteArray& from = "", const QByteArray& to = "") const;
- KisPropertiesConfigurationSP lastSavedConfiguration(const QByteArray &from = "", const QByteArray &to = "") const;
KisConfigWidget *createConfigurationWidget(QWidget *parent, const QByteArray& from = "", const QByteArray& to = "") const;
void initializeCapabilities();
};
#endif
diff --git a/plugins/impex/ppm/kis_ppm_export.cpp b/plugins/impex/ppm/kis_ppm_export.cpp
index 09df627cba..b93eb05a09 100644
--- a/plugins/impex/ppm/kis_ppm_export.cpp
+++ b/plugins/impex/ppm/kis_ppm_export.cpp
@@ -1,291 +1,283 @@
/*
* Copyright (c) 2009 Cyrille Berger
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; version 2.1 of the License.
*
* This library 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser 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_ppm_export.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "kis_iterator_ng.h"
#include
K_PLUGIN_FACTORY_WITH_JSON(KisPPMExportFactory, "krita_ppm_export.json", registerPlugin();)
KisPPMExport::KisPPMExport(QObject *parent, const QVariantList &) : KisImportExportFilter(parent)
{
}
KisPPMExport::~KisPPMExport()
{
}
class KisPPMFlow
{
public:
KisPPMFlow() {
}
virtual ~KisPPMFlow() {
}
virtual void writeBool(quint8 v) = 0;
virtual void writeBool(quint16 v) = 0;
virtual void writeNumber(quint8 v) = 0;
virtual void writeNumber(quint16 v) = 0;
virtual void flush() = 0;
private:
};
class KisPPMAsciiFlow : public KisPPMFlow
{
public:
KisPPMAsciiFlow(QIODevice* device) : m_device(device) {
}
~KisPPMAsciiFlow() override {
}
void writeBool(quint8 v) override {
if (v > 127) {
m_device->write("1 ");
} else {
m_device->write("0 ");
}
}
void writeBool(quint16 v) override {
writeBool(quint8(v >> 8));
}
void writeNumber(quint8 v) override {
m_device->write(QByteArray::number(v));
m_device->write(" ");
}
void writeNumber(quint16 v) override {
m_device->write(QByteArray::number(v));
m_device->write(" ");
}
void flush() override {
}
private:
QIODevice* m_device;
};
class KisPPMBinaryFlow : public KisPPMFlow
{
public:
KisPPMBinaryFlow(QIODevice* device) : m_device(device), m_pos(0), m_current(0) {
}
~KisPPMBinaryFlow() override {
}
void writeBool(quint8 v) override {
m_current = m_current << 1;
m_current |= (v > 127);
++m_pos;
if (m_pos >= 8) {
m_current = 0;
m_pos = 0;
flush();
}
}
void writeBool(quint16 v) override {
writeBool(quint8(v >> 8));
}
void writeNumber(quint8 v) override {
m_device->write((char*)&v, 1);
}
void writeNumber(quint16 v) override {
quint16 vo = qToBigEndian(v);
m_device->write((char*)&vo, 2);
}
void flush() override {
m_device->write((char*)&m_current, 1);
}
private:
QIODevice* m_device;
int m_pos;
quint8 m_current;
};
KisImportExportFilter::ConversionStatus KisPPMExport::convert(KisDocument *document, QIODevice *io, KisPropertiesConfigurationSP configuration)
{
bool rgb = (mimeType() == "image/x-portable-pixmap");
bool binary = (configuration->getInt("type") == 0);
bool bitmap = (mimeType() == "image/x-portable-bitmap");
KisImageSP image = document->savingImage();
KisPaintDeviceSP pd = new KisPaintDevice(*image->projection());
// Test color space
if (((rgb && (pd->colorSpace()->id() != "RGBA" && pd->colorSpace()->id() != "RGBA16"))
|| (!rgb && (pd->colorSpace()->id() != "GRAYA" && pd->colorSpace()->id() != "GRAYA16" && pd->colorSpace()->id() != "GRAYAU16")))) {
if (rgb) {
pd->convertTo(KoColorSpaceRegistry::instance()->rgb8(0), KoColorConversionTransformation::internalRenderingIntent(), KoColorConversionTransformation::internalConversionFlags());
}
else {
pd->convertTo(KoColorSpaceRegistry::instance()->colorSpace(GrayAColorModelID.id(), Integer8BitsColorDepthID.id(), 0), KoColorConversionTransformation::internalRenderingIntent(), KoColorConversionTransformation::internalConversionFlags());
}
}
bool is16bit = pd->colorSpace()->id() == "RGBA16" || pd->colorSpace()->id() == "GRAYAU16";
// Write the magic
if (rgb) {
if (binary) io->write("P6");
else io->write("P3");
} else if (bitmap) {
if (binary) io->write("P4");
else io->write("P1");
} else {
if (binary) io->write("P5");
else io->write("P2");
}
io->write("\n");
// Write the header
io->write(QByteArray::number(image->width()));
io->write(" ");
io->write(QByteArray::number(image->height()));
if (!bitmap) {
if (is16bit) io->write(" 65535\n");
else io->write(" 255\n");
} else {
io->write("\n");
}
// Write the data
KisPPMFlow* flow = 0;
if (binary) flow = new KisPPMBinaryFlow(io);
else flow = new KisPPMAsciiFlow(io);
for (int y = 0; y < image->height(); ++y) {
KisHLineIteratorSP it = pd->createHLineIteratorNG(0, y, image->width());
if (is16bit) {
if (rgb) {
do {
flow->writeNumber(KoBgrU16Traits::red(it->rawData()));
flow->writeNumber(KoBgrU16Traits::green(it->rawData()));
flow->writeNumber(KoBgrU16Traits::blue(it->rawData()));
} while (it->nextPixel());
} else if (bitmap) {
do {
flow->writeBool(*reinterpret_cast(it->rawData()));
} while (it->nextPixel());
} else {
do {
flow->writeNumber(*reinterpret_cast(it->rawData()));
} while (it->nextPixel());
}
} else {
if (rgb) {
do {
flow->writeNumber(KoBgrTraits::red(it->rawData()));
flow->writeNumber(KoBgrTraits::green(it->rawData()));
flow->writeNumber(KoBgrTraits::blue(it->rawData()));
} while (it->nextPixel());
} else if (bitmap) {
do {
flow->writeBool(*reinterpret_cast(it->rawData()));
} while (it->nextPixel());
} else {
do {
flow->writeNumber(*reinterpret_cast(it->rawData()));
} while (it->nextPixel());
}
}
}
if (bitmap) {
flow->flush();
}
delete flow;
return KisImportExportFilter::OK;
}
KisPropertiesConfigurationSP KisPPMExport::defaultConfiguration(const QByteArray &/*from*/, const QByteArray &/*to*/) const
{
KisPropertiesConfigurationSP cfg = new KisPropertiesConfiguration();
cfg->setProperty("type", 0);
return cfg;
}
-KisPropertiesConfigurationSP KisPPMExport::lastSavedConfiguration(const QByteArray &from, const QByteArray &to) const
-{
- KisPropertiesConfigurationSP cfg = defaultConfiguration(from, to);
- QString filterConfig = KisConfig().exportConfiguration("PPM");
- cfg->fromXML(filterConfig, false);
- return cfg;
-}
-
KisConfigWidget *KisPPMExport::createConfigurationWidget(QWidget *parent, const QByteArray &/*from*/, const QByteArray &/*to*/) const
{
return new KisWdgOptionsPPM(parent);
}
void KisWdgOptionsPPM::setConfiguration(const KisPropertiesConfigurationSP cfg)
{
cmbType->setCurrentIndex(cfg->getInt("type", 0));
}
KisPropertiesConfigurationSP KisWdgOptionsPPM::configuration() const
{
KisPropertiesConfigurationSP cfg = new KisPropertiesConfiguration();
cfg->setProperty("type", cmbType->currentIndex());
return cfg;
}
void KisPPMExport::initializeCapabilities()
{
addCapability(KisExportCheckRegistry::instance()->get("ColorModelCheck/" + RGBAColorModelID.id() + "/" + Integer8BitsColorDepthID.id())->create(KisExportCheckBase::SUPPORTED));
addCapability(KisExportCheckRegistry::instance()->get("ColorModelCheck/" + RGBAColorModelID.id() + "/" + Integer16BitsColorDepthID.id())->create(KisExportCheckBase::SUPPORTED));
addCapability(KisExportCheckRegistry::instance()->get("ColorModelCheck/" + GrayAColorModelID.id() + "/" + Integer8BitsColorDepthID.id())->create(KisExportCheckBase::SUPPORTED));
addCapability(KisExportCheckRegistry::instance()->get("ColorModelCheck/" + GrayAColorModelID.id() + "/" + Integer16BitsColorDepthID.id())->create(KisExportCheckBase::SUPPORTED));
QList > supportedColorModels;
supportedColorModels << QPair()
<< QPair(RGBAColorModelID, Integer8BitsColorDepthID)
<< QPair(RGBAColorModelID, Integer16BitsColorDepthID)
<< QPair(GrayAColorModelID, Integer8BitsColorDepthID)
<< QPair(GrayAColorModelID, Integer16BitsColorDepthID);
addSupportedColorModels(supportedColorModels, "PPM");
}
#include "kis_ppm_export.moc"
diff --git a/plugins/impex/ppm/kis_ppm_export.h b/plugins/impex/ppm/kis_ppm_export.h
index 9341b76bb6..010061659f 100644
--- a/plugins/impex/ppm/kis_ppm_export.h
+++ b/plugins/impex/ppm/kis_ppm_export.h
@@ -1,59 +1,58 @@
/*
* Copyright (c) 2009 Cyrille Berger
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; version 2.1 of the License.
*
* This library 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser 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_PPM_EXPORT_H_
#define _KIS_PPM_EXPORT_H_
#include
#include
#include
#include "ui_kis_wdg_options_ppm.h"
class KisWdgOptionsPPM : public KisConfigWidget, public Ui::WdgOptionsPPM
{
Q_OBJECT
public:
KisWdgOptionsPPM(QWidget *parent)
: KisConfigWidget(parent)
{
setupUi(this);
}
void setConfiguration(const KisPropertiesConfigurationSP cfg);
KisPropertiesConfigurationSP configuration() const;
};
class KisPPMExport : public KisImportExportFilter
{
Q_OBJECT
public:
KisPPMExport(QObject *parent, const QVariantList &);
virtual ~KisPPMExport();
public:
virtual KisImportExportFilter::ConversionStatus convert(KisDocument *document, QIODevice *io, KisPropertiesConfigurationSP configuration = 0);
KisPropertiesConfigurationSP defaultConfiguration(const QByteArray& from = "", const QByteArray& to = "") const;
- KisPropertiesConfigurationSP lastSavedConfiguration(const QByteArray &from = "", const QByteArray &to = "") const;
KisConfigWidget *createConfigurationWidget(QWidget *parent, const QByteArray& from = "", const QByteArray& to = "") const;
void initializeCapabilities();
};
#endif
diff --git a/plugins/impex/tiff/kis_tiff_export.cc b/plugins/impex/tiff/kis_tiff_export.cc
index 3495df6dda..73f41a2bba 100644
--- a/plugins/impex/tiff/kis_tiff_export.cc
+++ b/plugins/impex/tiff/kis_tiff_export.cc
@@ -1,191 +1,183 @@
/*
* Copyright (c) 2005 Cyrille Berger
*
* 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_tiff_export.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "kis_tiff_converter.h"
#include "kis_dlg_options_tiff.h"
#include "ui_kis_wdg_options_tiff.h"
K_PLUGIN_FACTORY_WITH_JSON(KisTIFFExportFactory, "krita_tiff_export.json", registerPlugin();)
KisTIFFExport::KisTIFFExport(QObject *parent, const QVariantList &) : KisImportExportFilter(parent)
{
}
KisTIFFExport::~KisTIFFExport()
{
}
KisImportExportFilter::ConversionStatus KisTIFFExport::convert(KisDocument *document, QIODevice */*io*/, KisPropertiesConfigurationSP configuration)
{
// If a configuration object was passed to the convert method, we use that, otherwise we load from the settings
KisPropertiesConfigurationSP cfg(new KisPropertiesConfiguration());
if (configuration) {
cfg->fromXML(configuration->toXML());
}
else {
cfg = lastSavedConfiguration(KisDocument::nativeFormatMimeType(), "image/tiff");
}
const KoColorSpace* cs = document->savingImage()->colorSpace();
cfg->setProperty("type", (int)cs->channels()[0]->channelValueType());
cfg->setProperty("isCMYK", (cs->colorModelId() == CMYKAColorModelID));
KisTIFFOptions options;
switch (configuration->getInt("compressiontype")) {
case 0:
options.compressionType = COMPRESSION_NONE;
break;
case 1:
options.compressionType = COMPRESSION_JPEG;
break;
case 2:
options.compressionType = COMPRESSION_DEFLATE;
break;
case 3:
options.compressionType = COMPRESSION_LZW;
break;
case 4:
options.compressionType = COMPRESSION_JP2000;
break;
case 5:
options.compressionType = COMPRESSION_CCITTRLE;
break;
case 6:
options.compressionType = COMPRESSION_CCITTFAX3;
break;
case 7:
options.compressionType = COMPRESSION_CCITTFAX4;
break;
case 8:
options.compressionType = COMPRESSION_PIXARLOG;
break;
default:
options.compressionType = COMPRESSION_NONE;
}
options.predictor = configuration->getInt("predictor");
options.alpha = configuration->getBool("alpha");
options.flatten = configuration->getBool("flatten");
options.jpegQuality = configuration->getInt("quality");
options.deflateCompress = configuration->getInt("deflate");
options.faxMode = configuration->getInt("faxmode");
options.pixarLogCompress = configuration->getInt("pixarlog");
options.saveProfile = configuration->getBool("saveProfile");
if ((cs->channels()[0]->channelValueType() == KoChannelInfo::FLOAT16
|| cs->channels()[0]->channelValueType() == KoChannelInfo::FLOAT32) && options.predictor == 2) {
// FIXME THIS IS AN HACK FIX THAT IN 2.0 !! (62456a7b47636548c6507593df3e2bdf440f7544, BUG:135649)
options.predictor = 3;
}
KisImageSP image;
if (options.flatten) {
image = new KisImage(0, document->savingImage()->width(), document->savingImage()->height(), document->savingImage()->colorSpace(), "");
image->setResolution(document->savingImage()->xRes(), document->savingImage()->yRes());
KisPaintDeviceSP pd = KisPaintDeviceSP(new KisPaintDevice(*document->savingImage()->projection()));
KisPaintLayerSP l = KisPaintLayerSP(new KisPaintLayer(image.data(), "projection", OPACITY_OPAQUE_U8, pd));
image->addNode(KisNodeSP(l.data()), image->rootLayer().data());
} else {
image = document->savingImage();
}
KisTIFFConverter tiffConverter(document);
KisImageBuilder_Result res;
if ((res = tiffConverter.buildFile(filename(), image, options)) == KisImageBuilder_RESULT_OK) {
dbgFile << "success !";
return KisImportExportFilter::OK;
}
dbgFile << " Result =" << res;
return KisImportExportFilter::InternalError;
}
KisPropertiesConfigurationSP KisTIFFExport::defaultConfiguration(const QByteArray &/*from*/, const QByteArray &/*to*/) const
{
KisPropertiesConfigurationSP cfg = new KisPropertiesConfiguration();
cfg->setProperty("compressiontype", 0);
cfg->setProperty("predictor", 0);
cfg->setProperty("alpha", true);
cfg->setProperty("flatten", true);
cfg->setProperty("quality", 80);
cfg->setProperty("deflate", 6);
cfg->setProperty("faxmode", 0);
cfg->setProperty("pixarlog", 6);
cfg->setProperty("saveProfile", true);
return cfg;
}
-KisPropertiesConfigurationSP KisTIFFExport::lastSavedConfiguration(const QByteArray &from, const QByteArray &to) const
-{
- QString filterConfig = KisConfig().exportConfiguration(to);
- KisPropertiesConfigurationSP cfg = defaultConfiguration(from, to);
- cfg->fromXML(filterConfig, false);
- return cfg;
-}
-
KisConfigWidget *KisTIFFExport::createConfigurationWidget(QWidget *parent, const QByteArray &/*from*/, const QByteArray &/*to*/) const
{
return new KisTIFFOptionsWidget(parent);
}
void KisTIFFExport::initializeCapabilities()
{
addCapability(KisExportCheckRegistry::instance()->get("NodeTypeCheck/KisGroupLayer")->create(KisExportCheckBase::UNSUPPORTED));
addCapability(KisExportCheckRegistry::instance()->get("MultiLayerCheck")->create(KisExportCheckBase::SUPPORTED));
addCapability(KisExportCheckRegistry::instance()->get("sRGBProfileCheck")->create(KisExportCheckBase::SUPPORTED));
QList > supportedColorModels;
supportedColorModels << QPair()
<< QPair(RGBAColorModelID, Integer8BitsColorDepthID)
<< QPair(RGBAColorModelID, Integer16BitsColorDepthID)
<< QPair(RGBAColorModelID, Float16BitsColorDepthID)
<< QPair(RGBAColorModelID, Float32BitsColorDepthID)
<< QPair(GrayAColorModelID, Integer8BitsColorDepthID)
<< QPair(GrayAColorModelID, Integer16BitsColorDepthID)
<< QPair(CMYKAColorModelID, Integer8BitsColorDepthID)
<< QPair(CMYKAColorModelID, Integer16BitsColorDepthID)
<< QPair(LABAColorModelID, Integer16BitsColorDepthID);
addSupportedColorModels(supportedColorModels, "TIFF");
}
#include
diff --git a/plugins/impex/tiff/kis_tiff_export.h b/plugins/impex/tiff/kis_tiff_export.h
index 6def27cfac..1798e59170 100644
--- a/plugins/impex/tiff/kis_tiff_export.h
+++ b/plugins/impex/tiff/kis_tiff_export.h
@@ -1,42 +1,41 @@
/*
* Copyright (c) 2005 Cyrille Berger
*
* 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_TIFF_EXPORT_H_
#define _KIS_TIFF_EXPORT_H_
#include
#include
#include