[graphics/krita] /: Feature: Add a krz krita archival file format
Halla Rempt
null at kde.org
Fri Feb 12 10:45:21 GMT 2021
Git commit 3ff173292a751dd9b6bf82ecb722df386a7ee349 by Halla Rempt.
Committed on 12/02/2021 at 10:44.
Pushed by rempt into branch 'master'.
Feature: Add a krz krita archival file format
Basically, a .kra file without a mergedimage.png and always
compressed.
CCMAIL:kimageshop at kde.org
M +6 -0 libs/koplugin/KisMimeDatabase.cpp
M +2 -0 plugins/impex/CMakeLists.txt
M +0 -2 plugins/impex/kra/CMakeLists.txt
M +1 -1 plugins/impex/kra/kra_export.cpp
M +2 -2 plugins/impex/kra/krita_kra_import.json
A +11 -0 plugins/impex/krz/CMakeLists.txt
A +76 -0 plugins/impex/krz/krita_krz.desktop
A +13 -0 plugins/impex/krz/krita_krz_export.json
C +17 -12 plugins/impex/krz/krz_export.cpp [from: plugins/impex/kra/kra_export.cpp - 068% similarity]
A +26 -0 plugins/impex/krz/krz_export.h [License: LGPL(v2.0+)]
M +1 -0 plugins/impex/libkra/CMakeLists.txt
M +5 -3 plugins/impex/libkra/kis_kra_saver.cpp
M +2 -2 plugins/impex/libkra/kis_kra_saver.h
R +3 -3 plugins/impex/libkra/kra_converter.cpp [from: plugins/impex/kra/kra_converter.cpp - 098% similarity]
R +3 -2 plugins/impex/libkra/kra_converter.h [from: plugins/impex/kra/kra_converter.h - 093% similarity]
https://invent.kde.org/graphics/krita/commit/3ff173292a751dd9b6bf82ecb722df386a7ee349
diff --git a/libs/koplugin/KisMimeDatabase.cpp b/libs/koplugin/KisMimeDatabase.cpp
index 48b5f2b797..46156820f6 100644
--- a/libs/koplugin/KisMimeDatabase.cpp
+++ b/libs/koplugin/KisMimeDatabase.cpp
@@ -325,6 +325,12 @@ void KisMimeDatabase::fillMimeData()
mimeType.suffixes = QStringList() << "kse";
s_mimeDatabase << mimeType;
+ mimeType.mimeType = "application/x-krita-archive";
+ mimeType.description = i18nc("description of a file type", "Krita Archival Image Foramt");
+ mimeType.suffixes = QStringList() << "krz";
+ s_mimeDatabase << mimeType;
+
+
debugPlugin << "Filled mimedatabase with" << s_mimeDatabase.count() << "special mimetypes";
}
}
diff --git a/plugins/impex/CMakeLists.txt b/plugins/impex/CMakeLists.txt
index 499b1c97d0..63df1fd69a 100644
--- a/plugins/impex/CMakeLists.txt
+++ b/plugins/impex/CMakeLists.txt
@@ -54,3 +54,5 @@ endif()
if (HEIF_FOUND)
add_subdirectory(heif)
endif()
+
+add_subdirectory(krz)
diff --git a/plugins/impex/kra/CMakeLists.txt b/plugins/impex/kra/CMakeLists.txt
index 6dadc41399..0e9f64d63a 100644
--- a/plugins/impex/kra/CMakeLists.txt
+++ b/plugins/impex/kra/CMakeLists.txt
@@ -1,6 +1,5 @@
set(kritakraimport_SOURCES
kra_import.cpp
- kra_converter.cpp
)
add_library(kritakraimport MODULE ${kritakraimport_SOURCES})
@@ -11,7 +10,6 @@ install(TARGETS kritakraimport DESTINATION ${KRITA_PLUGIN_INSTALL_DIR})
set(kritakraexport_SOURCES
kra_export.cpp
- kra_converter.cpp
)
add_library(kritakraexport MODULE ${kritakraexport_SOURCES})
diff --git a/plugins/impex/kra/kra_export.cpp b/plugins/impex/kra/kra_export.cpp
index 12dcbf41ee..b5d23b313d 100644
--- a/plugins/impex/kra/kra_export.cpp
+++ b/plugins/impex/kra/kra_export.cpp
@@ -46,7 +46,7 @@ KisImportExportErrorCode KraExport::convert(KisDocument *document, QIODevice *io
KIS_ASSERT_RECOVER_RETURN_VALUE(image, ImportExportCodes::InternalError);
KraConverter kraConverter(document, updater());
- KisImportExportErrorCode res = kraConverter.buildFile(io, filename());
+ KisImportExportErrorCode res = kraConverter.buildFile(io, filename(), !document->isAutosaving());
dbgFile << "KraExport::convert result =" << res;
return res;
}
diff --git a/plugins/impex/kra/krita_kra_import.json b/plugins/impex/kra/krita_kra_import.json
index b56cd63604..70b09ac950 100644
--- a/plugins/impex/kra/krita_kra_import.json
+++ b/plugins/impex/kra/krita_kra_import.json
@@ -3,11 +3,11 @@
"Id": "Krita Native Import Filter",
"NoDisplay": "true",
"Type": "Service",
- "X-KDE-Import": "application/x-krita",
+ "X-KDE-Import": "application/x-krita,application/x-krita-archive",
"X-KDE-Library": "kritakraimport",
"X-KDE-ServiceTypes": [
"Krita/FileFilter"
],
"X-KDE-Weight": "1",
- "X-KDE-Extensions" : "kra"
+ "X-KDE-Extensions" : "kra, krz"
}
diff --git a/plugins/impex/krz/CMakeLists.txt b/plugins/impex/krz/CMakeLists.txt
new file mode 100644
index 0000000000..b8079d8dd6
--- /dev/null
+++ b/plugins/impex/krz/CMakeLists.txt
@@ -0,0 +1,11 @@
+set(kritakrzexport_SOURCES
+ krz_export.cpp
+)
+
+add_library(kritakrzexport MODULE ${kritakrzexport_SOURCES})
+
+target_link_libraries(kritakrzexport kritaui kritalibkra kritaimpex)
+
+install(TARGETS kritakrzexport DESTINATION ${KRITA_PLUGIN_INSTALL_DIR})
+
+install( PROGRAMS krita_krz.desktop DESTINATION ${XDG_APPS_INSTALL_DIR})
diff --git a/plugins/impex/krz/krita_krz.desktop b/plugins/impex/krz/krita_krz.desktop
new file mode 100644
index 0000000000..a263c1da7b
--- /dev/null
+++ b/plugins/impex/krz/krita_krz.desktop
@@ -0,0 +1,76 @@
+[Desktop Entry]
+Categories=Qt;KDE;Office;Graphics;
+Comment=
+Exec=krita %F
+Icon=krita
+MimeType=application/x-krita;
+Name=Krita
+Name[af]=Krita
+Name[ar]=كريتا
+Name[bg]=Krita
+Name[br]=Krita
+Name[bs]=Krita
+Name[ca]=Krita
+Name[ca at valencia]=Krita
+Name[cs]=Krita
+Name[cy]=Krita
+Name[da]=Krita
+Name[de]=Krita
+Name[el]=Krita
+Name[en_GB]=Krita
+Name[eo]=Krita
+Name[es]=Krita
+Name[et]=Krita
+Name[eu]=Krita
+Name[fi]=Krita
+Name[fr]=Krita
+Name[fy]=Krita
+Name[ga]=Krita
+Name[gl]=Krita
+Name[he]=Krita
+Name[hi]=क्रिता
+Name[hne]=केरिता
+Name[hr]=Krita
+Name[hu]=Krita
+Name[ia]=Krita
+Name[is]=Krita
+Name[it]=Krita
+Name[ja]=Krita
+Name[kk]=Krita
+Name[ko]=Krita
+Name[lt]=Krita
+Name[lv]=Krita
+Name[mr]=क्रिटा
+Name[ms]=Krita
+Name[nb]=Krita
+Name[nds]=Krita
+Name[ne]=क्रिता
+Name[nl]=Krita
+Name[nn]=Krita
+Name[pl]=Krita
+Name[pt]=Krita
+Name[pt_BR]=Krita
+Name[ro]=Krita
+Name[ru]=Krita
+Name[se]=Krita
+Name[sk]=Krita
+Name[sl]=Krita
+Name[sv]=Krita
+Name[ta]=கிரிட்டா
+Name[tg]=Krita
+Name[tr]=Krita
+Name[ug]=Krita
+Name[uk]=Krita
+Name[uz]=Krita
+Name[uz at cyrillic]=Krita
+Name[wa]=Krita
+Name[xh]=Krita
+Name[x-test]=xxKritaxx
+Name[zh_CN]=Krita
+Name[zh_TW]=Krita
+StartupNotify=true
+Terminal=false
+Type=Application
+X-KDE-SubstituteUID=false
+X-KDE-Username=
+NoDisplay=true
diff --git a/plugins/impex/krz/krita_krz_export.json b/plugins/impex/krz/krita_krz_export.json
new file mode 100644
index 0000000000..302474dc1d
--- /dev/null
+++ b/plugins/impex/krz/krita_krz_export.json
@@ -0,0 +1,13 @@
+{
+ "Icon": "",
+ "Id": "Krita Archival Export Filter",
+ "NoDisplay": "true",
+ "Type": "Service",
+ "X-KDE-Export": "application/x-krita-archive",
+ "X-KDE-Library": "kritakrzexport",
+ "X-KDE-ServiceTypes": [
+ "Krita/FileFilter"
+ ],
+ "X-KDE-Weight": "1",
+ "X-KDE-Extensions" : "krz"
+}
diff --git a/plugins/impex/kra/kra_export.cpp b/plugins/impex/krz/krz_export.cpp
similarity index 68%
copy from plugins/impex/kra/kra_export.cpp
copy to plugins/impex/krz/krz_export.cpp
index 12dcbf41ee..368b26c758 100644
--- a/plugins/impex/kra/kra_export.cpp
+++ b/plugins/impex/krz/krz_export.cpp
@@ -4,7 +4,7 @@
* SPDX-License-Identifier: LGPL-2.0-or-later
*/
-#include "kra_export.h"
+#include "krz_export.h"
#include <QCheckBox>
#include <QSlider>
@@ -25,33 +25,38 @@
#include <kis_paint_layer.h>
#include <kis_shape_layer.h>
#include <KoProperties.h>
-
+#include <kis_config.h>
#include "kra_converter.h"
class KisExternalLayer;
-K_PLUGIN_FACTORY_WITH_JSON(ExportFactory, "krita_kra_export.json", registerPlugin<KraExport>();)
+K_PLUGIN_FACTORY_WITH_JSON(KrzExportFactory, "krita_krz_export.json", registerPlugin<KrzExport>();)
-KraExport::KraExport(QObject *parent, const QVariantList &) : KisImportExportFilter(parent)
+KrzExport::KrzExport(QObject *parent, const QVariantList &)
+ : KisImportExportFilter(parent)
{
}
-KraExport::~KraExport()
+KrzExport::~KrzExport()
{
}
-KisImportExportErrorCode KraExport::convert(KisDocument *document, QIODevice *io, KisPropertiesConfigurationSP /*configuration*/)
+KisImportExportErrorCode KrzExport::convert(KisDocument *document, QIODevice *io, KisPropertiesConfigurationSP /*configuration*/)
{
KisImageSP image = document->savingImage();
KIS_ASSERT_RECOVER_RETURN_VALUE(image, ImportExportCodes::InternalError);
- KraConverter kraConverter(document, updater());
- KisImportExportErrorCode res = kraConverter.buildFile(io, filename());
- dbgFile << "KraExport::convert result =" << res;
+ KisConfig cfg(true);
+ bool compress = cfg.compressKra();
+ cfg.setCompressKra(true);
+ KraConverter krzConverter(document, updater());
+ KisImportExportErrorCode res = krzConverter.buildFile(io, filename(), false);
+ cfg.setCompressKra(compress);
+ dbgFile << "KrzExport::convert result =" << res;
return res;
}
-void KraExport::initializeCapabilities()
+void KrzExport::initializeCapabilities()
{
// Kra supports everything, by definition
KisExportCheckFactory *factory = 0;
@@ -61,7 +66,7 @@ void KraExport::initializeCapabilities()
}
}
-QString KraExport::verify(const QString &fileName) const
+QString KrzExport::verify(const QString &fileName) const
{
QString error = KisImportExportFilter::verify(fileName);
if (error.isEmpty()) {
@@ -76,5 +81,5 @@ QString KraExport::verify(const QString &fileName) const
}
-#include <kra_export.moc>
+#include <krz_export.moc>
diff --git a/plugins/impex/krz/krz_export.h b/plugins/impex/krz/krz_export.h
new file mode 100644
index 0000000000..282ef87acb
--- /dev/null
+++ b/plugins/impex/krz/krz_export.h
@@ -0,0 +1,26 @@
+/*
+ * SPDX-FileCopyrightText: 2021 Halla Rempt <halla at valdyas.org>
+ *
+ * SPDX-License-Identifier: LGPL-2.0-or-later
+ */
+
+#ifndef _KRZ_EXPORT_H_
+#define _KRZ_EXPORT_H_
+
+#include <QVariant>
+
+#include <KisImportExportFilter.h>
+
+class KrzExport : public KisImportExportFilter
+{
+ Q_OBJECT
+public:
+ KrzExport(QObject *parent, const QVariantList &);
+ ~KrzExport() override;
+public:
+ KisImportExportErrorCode convert(KisDocument *document, QIODevice *io, KisPropertiesConfigurationSP configuration = 0) override;
+ void initializeCapabilities() override;
+ QString verify(const QString &fileName) const override;
+};
+
+#endif
diff --git a/plugins/impex/libkra/CMakeLists.txt b/plugins/impex/libkra/CMakeLists.txt
index 2b840c1e8a..f1bd1b733b 100644
--- a/plugins/impex/libkra/CMakeLists.txt
+++ b/plugins/impex/libkra/CMakeLists.txt
@@ -16,6 +16,7 @@ set(kritalibkra_LIB_SRCS
kis_kra_tags.h
kis_kra_utils.cpp
kis_kra_utils.h
+ kra_converter.cpp
)
add_library(kritalibkra SHARED ${kritalibkra_LIB_SRCS})
diff --git a/plugins/impex/libkra/kis_kra_saver.cpp b/plugins/impex/libkra/kis_kra_saver.cpp
index ef9247010d..8bea2850ab 100644
--- a/plugins/impex/libkra/kis_kra_saver.cpp
+++ b/plugins/impex/libkra/kis_kra_saver.cpp
@@ -68,6 +68,7 @@ struct KisKraSaver::Private
QString filename;
QStringList errorMessages;
QStringList specialAnnotations;
+ bool addMergedImage;
Private() {
specialAnnotations << "exif" << "icc";
@@ -75,11 +76,12 @@ struct KisKraSaver::Private
};
-KisKraSaver::KisKraSaver(KisDocument* document, const QString &filename)
+KisKraSaver::KisKraSaver(KisDocument* document, const QString &filename, bool addMergedImage)
: m_d(new Private)
{
m_d->doc = document;
m_d->filename = filename;
+ m_d->addMergedImage = addMergedImage;
m_d->imageName = m_d->doc->documentInfo()->aboutInfo("title");
if (m_d->imageName.isEmpty()) {
@@ -355,7 +357,7 @@ bool KisKraSaver::saveNodeKeyframes(KoStore *store, QString location, const KisN
return true;
}
-bool KisKraSaver::saveBinaryData(KoStore* store, KisImageSP image, const QString &uri, bool external, bool autosave)
+bool KisKraSaver::saveBinaryData(KoStore* store, KisImageSP image, const QString &uri, bool external, bool addMergedImage)
{
QString location;
@@ -473,7 +475,7 @@ bool KisKraSaver::saveBinaryData(KoStore* store, KisImageSP image, const QString
}
}
- if (!autosave) {
+ if (addMergedImage) {
KisPaintDeviceSP dev = image->projection();
store->setCompressionEnabled(false);
KisPNGConverter::saveDeviceToStore("mergedimage.png", image->bounds(), image->xRes(), image->yRes(), dev, store);
diff --git a/plugins/impex/libkra/kis_kra_saver.h b/plugins/impex/libkra/kis_kra_saver.h
index e67f0aa80d..3a7ca84f71 100644
--- a/plugins/impex/libkra/kis_kra_saver.h
+++ b/plugins/impex/libkra/kis_kra_saver.h
@@ -21,7 +21,7 @@ class KRITALIBKRA_EXPORT KisKraSaver
{
public:
- KisKraSaver(KisDocument* document, const QString &filename);
+ KisKraSaver(KisDocument* document, const QString &filename, bool addMergedImage = true);
~KisKraSaver();
@@ -29,7 +29,7 @@ public:
bool saveKeyframes(KoStore *store, const QString &uri, bool external);
- bool saveBinaryData(KoStore* store, KisImageSP image, const QString & uri, bool external, bool includeMerge);
+ bool saveBinaryData(KoStore* store, KisImageSP image, const QString & uri, bool external, bool addMergedImage);
bool savePalettes(KoStore *store, KisImageSP image, const QString &uri);
diff --git a/plugins/impex/kra/kra_converter.cpp b/plugins/impex/libkra/kra_converter.cpp
similarity index 98%
rename from plugins/impex/kra/kra_converter.cpp
rename to plugins/impex/libkra/kra_converter.cpp
index e8ead3891c..9f5823d12b 100644
--- a/plugins/impex/kra/kra_converter.cpp
+++ b/plugins/impex/libkra/kra_converter.cpp
@@ -135,7 +135,7 @@ QVector<StoryboardComment> KraConverter::storyboardCommentList()
return m_storyboardCommentList;
}
-KisImportExportErrorCode KraConverter::buildFile(QIODevice *io, const QString &filename)
+KisImportExportErrorCode KraConverter::buildFile(QIODevice *io, const QString &filename, bool addMergedImage)
{
if (m_image->size().isEmpty()) {
return ImportExportCodes::Failure;
@@ -151,7 +151,7 @@ KisImportExportErrorCode KraConverter::buildFile(QIODevice *io, const QString &f
setProgress(20);
- m_kraSaver = new KisKraSaver(m_doc, filename);
+ m_kraSaver = new KisKraSaver(m_doc, filename, addMergedImage);
KisImportExportErrorCode resultCode = saveRootDocuments(m_store);
@@ -167,7 +167,7 @@ KisImportExportErrorCode KraConverter::buildFile(QIODevice *io, const QString &f
qWarning() << "saving key frames failed";
}
setProgress(60);
- result = m_kraSaver->saveBinaryData(m_store, m_image, m_doc->url().toLocalFile(), true, m_doc->isAutosaving());
+ result = m_kraSaver->saveBinaryData(m_store, m_image, m_doc->url().toLocalFile(), true, addMergedImage);
if (!result) {
qWarning() << "saving binary data failed";
}
diff --git a/plugins/impex/kra/kra_converter.h b/plugins/impex/libkra/kra_converter.h
similarity index 93%
rename from plugins/impex/kra/kra_converter.h
rename to plugins/impex/libkra/kra_converter.h
index 1375ff6562..5fb50db6d8 100644
--- a/plugins/impex/kra/kra_converter.h
+++ b/plugins/impex/libkra/kra_converter.h
@@ -21,10 +21,11 @@
#include <QPointer>
#include <KoUpdater.h>
+#include "kritalibkra_export.h"
class KisDocument;
-class KraConverter : public QObject
+class KRITALIBKRA_EXPORT KraConverter : public QObject
{
Q_OBJECT
@@ -35,7 +36,7 @@ public:
~KraConverter() override;
KisImportExportErrorCode buildImage(QIODevice *io);
- KisImportExportErrorCode buildFile(QIODevice *io, const QString &filename);
+ KisImportExportErrorCode buildFile(QIODevice *io, const QString &filename, bool addMergedImage = true);
/**
* Retrieve the constructed image
*/
More information about the kimageshop
mailing list