[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [calligra/calligra/2.9] krita/plugins/formats/psd: Explicitly save layers data if the only layer of 
From:       Dmitry Kazakov <dimula73 () gmail ! com>
Date:       2015-08-13 17:15:19
Message-ID: E1ZPw63-0001eb-Vl () scm ! kde ! org
[Download RAW message or body]

Git commit efd245b2ac89ad4c5874cb649454571148eb9d39 by Dmitry Kazakov.
Committed on 13/08/2015 at 15:46.
Pushed by dkazakov into branch 'calligra/2.9'.

Explicitly save layers data if the only layer of the image has transparency

This is exactly what PS does. Indeed, to show that your image projection
has transparency, according to PSD spec you should set the number of layers
to -1, and you cannot do that if you don't have a layer info block at all :)

M  +30   -1    krita/plugins/formats/psd/psd_saver.cpp

http://commits.kde.org/calligra/efd245b2ac89ad4c5874cb649454571148eb9d39

diff --git a/krita/plugins/formats/psd/psd_saver.cpp b/krita/plugins/formats/psd/psd_saver.cpp
index 4c42c62..9098f67 100644
--- a/krita/plugins/formats/psd/psd_saver.cpp
+++ b/krita/plugins/formats/psd/psd_saver.cpp
@@ -99,6 +99,31 @@ KisImageWSP PSDSaver::image()
     return m_image;
 }
 
+#include "kis_sequential_iterator.h"
+
+
+bool checkIfHasTransparency(KisPaintDeviceSP dev)
+{
+    const QRect deviceBounds = dev->exactBounds();
+    const QRect imageBounds = dev->defaultBounds()->bounds();
+
+    if (deviceBounds.isEmpty() ||
+        (deviceBounds & imageBounds) != imageBounds) {
+
+        return true;
+    }
+
+    const KoColorSpace *cs = dev->colorSpace();
+    KisSequentialConstIterator it(dev, deviceBounds);
+
+    do {
+        if (cs->opacityU8(it.rawDataConst()) != OPACITY_OPAQUE_U8) {
+            return true;
+        }
+    } while(it.nextPixel());
+
+    return false;
+}
 
 KisImageBuilder_Result PSDSaver::buildFile(const KUrl& uri)
 {
@@ -214,7 +239,11 @@ KisImageBuilder_Result PSDSaver::buildFile(const KUrl& uri)
     // LAYER AND MASK DATA
     // Only save layers and masks if there is more than one layer
     dbgFile << "m_image->rootLayer->childCount" << m_image->rootLayer()->childCount() << f.pos();
-    if (m_image->rootLayer()->childCount() > 1) {
+
+    bool haveLayers = m_image->rootLayer()->childCount() > 1 ||
+        checkIfHasTransparency(m_image->rootLayer()->firstChild()->projection());
+
+    if (haveLayers) {
 
         PSDLayerMaskSection layerSection(header);
         layerSection.hasTransparency = true;

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic