Skip to content

armgit / krita

Public Imported from GitHub
0

Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.

C++

Fix bogus offset when saving EXR with moved layers

Dmitry Kazakovf8b4dce837ad
diff --git a/plugins/impex/exr/exr_converter.cc b/plugins/impex/exr/exr_converter.cc
index 629fd12086..865146f761 100644
--- a/plugins/impex/exr/exr_converter.cc
+++ b/plugins/impex/exr/exr_converter.cc
@@ -1358,7 +1358,12 @@ QString EXRConverter::Private::fetchExtraLayersInfo(QList<ExrPaintLayerSaveInfo>
ExrPaintLayerSaveInfo &info = informationObjects[i];
quint32 unused;
KisSaveXmlVisitor visitor(doc, rootElement, unused, QString(), false);
- QDomElement el = visitor.savePaintLayerAttributes(info.layer.data(), doc);
+
+ // EXR data is saved without the offset, saving code uses normal iterators
+ // that don't know about the layer offset, hence passing `false` for saving
+ // the offsets
+ QDomElement el = visitor.savePaintLayerAttributes(info.layer.data(), doc, false);
+
// cut the ending '.'
QString strippedName = info.name.left(info.name.size() - 1);
diff --git a/plugins/impex/exr/kis_exr_layers_sorter.cpp b/plugins/impex/exr/kis_exr_layers_sorter.cpp
index 1beb828f95..5de97da354 100644
--- a/plugins/impex/exr/kis_exr_layers_sorter.cpp
+++ b/plugins/impex/exr/kis_exr_layers_sorter.cpp
@@ -94,7 +94,17 @@ void KisExrLayersSorter::Private::processLayers(KisNodeSP root)
nodeToOrderingMap.insert(root, fetchMapValueLazy(pathToOrderingMap, path));
if (KisPaintLayer *paintLayer = dynamic_cast<KisPaintLayer*>(root.data())) {
- KisSaveXmlVisitor::loadPaintLayerAttributes(pathToElementMap[path], paintLayer);
+ QDomElement el = pathToElementMap[path];
+
+ /**
+ * In older files (before Krita 5.2.7) we used to save the layer offset
+ * into the XML metadata, while loading the pixel data at the origin.
+ * Since 5.2.7 we stopped saving offsets (we save null instead of them),
+ * we let's just make sure we don't load garbage from older files).
+ *
+ * Hence, we pass `false` for loading the offset
+ */
+ KisSaveXmlVisitor::loadPaintLayerAttributes(el, paintLayer, false);
}
}
diff --git a/plugins/impex/libkra/kis_kra_savexml_visitor.cpp b/plugins/impex/libkra/kis_kra_savexml_visitor.cpp
index cff17603da..8829a4f7d1 100644
--- a/plugins/impex/libkra/kis_kra_savexml_visitor.cpp
+++ b/plugins/impex/libkra/kis_kra_savexml_visitor.cpp
@@ -108,7 +108,7 @@ bool KisSaveXmlVisitor::visit(KisExternalLayer * layer)
return false;
}
-QDomElement KisSaveXmlVisitor::savePaintLayerAttributes(KisPaintLayer *layer, QDomDocument &doc)
+QDomElement KisSaveXmlVisitor::savePaintLayerAttributes(KisPaintLayer *layer, QDomDocument &doc, bool saveLayerOffset)
{
QDomElement element = doc.createElement(LAYER);
saveLayer(element, PAINT_LAYER, layer);
@@ -118,21 +118,33 @@ QDomElement KisSaveXmlVisitor::savePaintLayerAttributes(KisPaintLayer *layer, QD
element.setAttribute(ONION_SKIN_ENABLED, layer->onionSkinEnabled());
element.setAttribute(VISIBLE_IN_TIMELINE, layer->isPinnedToTimeline());
+ if (!saveLayerOffset) {
+ element.removeAttribute(X);
+ element.removeAttribute(Y);
+ }
+
return element;
}
-void KisSaveXmlVisitor::loadPaintLayerAttributes(const QDomElement &el, KisPaintLayer *layer)
+void KisSaveXmlVisitor::loadPaintLayerAttributes(const QDomElement &el, KisPaintLayer *layer, bool loadLayerOffset)
{
- loadLayerAttributes(el, layer);
+ QDomElement copy = el;
+
+ if (!loadLayerOffset) {
+ copy.removeAttribute(X);
+ copy.removeAttribute(Y);
+ }
+
+ loadLayerAttributes(copy, layer);
- if (el.hasAttribute(CHANNEL_LOCK_FLAGS)) {
- layer->setChannelLockFlags(stringToFlags(el.attribute(CHANNEL_LOCK_FLAGS)));
+ if (copy.hasAttribute(CHANNEL_LOCK_FLAGS)) {
+ layer->setChannelLockFlags(stringToFlags(copy.attribute(CHANNEL_LOCK_FLAGS)));
}
}
bool KisSaveXmlVisitor::visit(KisPaintLayer *layer)
{
- QDomElement layerElement = savePaintLayerAttributes(layer, m_doc);
+ QDomElement layerElement = savePaintLayerAttributes(layer, m_doc, true);
m_elem.appendChild(layerElement);
m_count++;
return saveMasks(layer, layerElement);
diff --git a/plugins/impex/libkra/kis_kra_savexml_visitor.h b/plugins/impex/libkra/kis_kra_savexml_visitor.h
index 78cec21e04..6cf3c33d77 100644
--- a/plugins/impex/libkra/kis_kra_savexml_visitor.h
+++ b/plugins/impex/libkra/kis_kra_savexml_visitor.h
@@ -52,10 +52,10 @@ public:
}
public:
- QDomElement savePaintLayerAttributes(KisPaintLayer *layer, QDomDocument &doc);
+ QDomElement savePaintLayerAttributes(KisPaintLayer *layer, QDomDocument &doc, bool saveLayerOffset);
// used by EXR to save properties of Krita layers inside .exr
- static void loadPaintLayerAttributes(const QDomElement &el, KisPaintLayer *layer);
+ static void loadPaintLayerAttributes(const QDomElement &el, KisPaintLayer *layer, bool loadLayerOffset);
private:
static void loadLayerAttributes(const QDomElement &el, KisLayer *layer);