[calligra/krita-animation-pentikainen] krita/plugins/formats/psd: Fix saving PSD when the image has a non-transparent background
Dmitry Kazakov
dimula73 at gmail.com
Thu Sep 3 13:42:05 UTC 2015
Git commit faf0ac09b8c21449b22ba43fe89126a4d381c6a4 by Dmitry Kazakov.
Committed on 03/09/2015 at 13:41.
Pushed by dkazakov into branch 'krita-animation-pentikainen'.
Fix saving PSD when the image has a non-transparent background
When Krita file has a non-transparent background a special background layer
will be created while saving to PSD
Fixes T590
CC:kimageshop at kde.org
M +28 -0 krita/plugins/formats/psd/psd_layer_section.cpp
http://commits.kde.org/calligra/faf0ac09b8c21449b22ba43fe89126a4d381c6a4
diff --git a/krita/plugins/formats/psd/psd_layer_section.cpp b/krita/plugins/formats/psd/psd_layer_section.cpp
index 5a8eea0..88bf109 100644
--- a/krita/plugins/formats/psd/psd_layer_section.cpp
+++ b/krita/plugins/formats/psd/psd_layer_section.cpp
@@ -21,6 +21,7 @@
#include <QIODevice>
+#include <KoColor.h>
#include <KoColorSpace.h>
#include <kis_debug.h>
@@ -28,6 +29,8 @@
#include <kis_paint_layer.h>
#include <kis_group_layer.h>
#include <kis_effect_mask.h>
+#include <kis_image.h>
+
#include "kis_dom_utils.h"
@@ -300,6 +303,30 @@ struct FlattenedNode {
Type type;
};
+void addBackgroundIfNeeded(KisNodeSP root, QList<FlattenedNode> &nodes)
+{
+ KisGroupLayer *group = dynamic_cast<KisGroupLayer*>(root.data());
+ if (!group) return;
+
+ KoColor projectionColor = group->defaultProjectionColor();
+ if (projectionColor.opacityU8() == OPACITY_TRANSPARENT_U8) return;
+
+ KisPaintLayerSP layer =
+ new KisPaintLayer(group->image(),
+ i18nc("Automatically created layer name when saving into PSD", "Background"),
+ OPACITY_OPAQUE_U8);
+
+ projectionColor.convertTo(layer->paintDevice()->colorSpace());
+ layer->paintDevice()->setDefaultPixel(projectionColor.data());
+
+ {
+ FlattenedNode item;
+ item.node = layer;
+ item.type = FlattenedNode::RASTER_LAYER;
+ nodes << item;
+ }
+}
+
void flattenNodes(KisNodeSP node, QList<FlattenedNode> &nodes)
{
KisNodeSP child = node->firstChild();
@@ -414,6 +441,7 @@ void PSDLayerMaskSection::writeImpl(QIODevice* io, KisNodeSP rootLayer)
// Build the whole layer structure
QList<FlattenedNode> nodes;
+ addBackgroundIfNeeded(rootLayer, nodes);
flattenNodes(rootLayer, nodes);
if (nodes.isEmpty()) {
More information about the kimageshop
mailing list