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

List:       kde-commits
Subject:    [calligra/calligra/2.9] krita/plugins/formats/psd: Implement a placeholder for loading layer info bl
From:       Dmitry Kazakov <dimula73 () gmail ! com>
Date:       2015-08-13 17:15:19
Message-ID: E1ZPw63-0001eb-6u () scm ! kde ! org
[Download RAW message or body]

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

Implement a placeholder for loading layer info block from 'Lr16' and 'Lr32' additional sections

M  +13   -1    krita/plugins/formats/psd/psd_additional_layer_info_block.cpp
M  +10   -0    krita/plugins/formats/psd/psd_additional_layer_info_block.h
M  +1    -1    krita/plugins/formats/psd/psd_layer_record.cpp
M  +58   -34   krita/plugins/formats/psd/psd_layer_section.cpp
M  +1    -0    krita/plugins/formats/psd/psd_layer_section.h

http://commits.kde.org/calligra/2772c60b9a12d4945e9d06bbc7408ab1933c58a6

diff --git a/krita/plugins/formats/psd/psd_additional_layer_info_block.cpp \
b/krita/plugins/formats/psd/psd_additional_layer_info_block.cpp index 1c08d09..c0d4bb7 100644
--- a/krita/plugins/formats/psd/psd_additional_layer_info_block.cpp
+++ b/krita/plugins/formats/psd/psd_additional_layer_info_block.cpp
@@ -34,6 +34,11 @@ PsdAdditionalLayerInfoBlock::PsdAdditionalLayerInfoBlock(const PSDHeader& \
header  {
 }
 
+void PsdAdditionalLayerInfoBlock::setExtraLayerInfoBlockHandler(ExtraLayerInfoBlockHandler \
handler) +{
+    m_layerInfoBlockHandler = handler;
+}
+
 bool PsdAdditionalLayerInfoBlock::read(QIODevice *io)
 {
     bool result = true;
@@ -90,7 +95,14 @@ void PsdAdditionalLayerInfoBlock::readImpl(QIODevice* io)
         }
         keys << key;
 
-        if (key == "SoCo") {
+        if (key == "Lr16" || key == "Lr32") {
+            if (m_layerInfoBlockHandler) {
+                int offset = m_header.version > 1 ? 8 : 4;
+                io->seek(io->pos() - offset);
+                m_layerInfoBlockHandler(io);
+            }
+        }
+        else if (key == "SoCo") {
 
         }
         else if (key == "GdFl") {
diff --git a/krita/plugins/formats/psd/psd_additional_layer_info_block.h \
b/krita/plugins/formats/psd/psd_additional_layer_info_block.h index dfa8e73..72a6374 100644
--- a/krita/plugins/formats/psd/psd_additional_layer_info_block.h
+++ b/krita/plugins/formats/psd/psd_additional_layer_info_block.h
@@ -30,6 +30,9 @@
 #include <kis_paint_device.h>
 #include <kis_node.h>
 
+#include <boost/function.hpp>
+
+
 #include "psd.h"
 #include "psd_header.h"
 
@@ -255,6 +258,11 @@ class PsdAdditionalLayerInfoBlock
 {
 public:
     PsdAdditionalLayerInfoBlock(const PSDHeader& header);
+
+    typedef boost::function<bool(QIODevice*)> ExtraLayerInfoBlockHandler;
+
+    void setExtraLayerInfoBlockHandler(ExtraLayerInfoBlockHandler handler);
+
     bool read(QIODevice* io);
     bool write(QIODevice* io, KisNodeSP node);
 
@@ -280,6 +288,8 @@ public:
 private:
     void readImpl(QIODevice* io);
 
+private:
+    ExtraLayerInfoBlockHandler m_layerInfoBlockHandler;
 };
 
 #endif // PSD_ADDITIONAL_LAYER_INFO_BLOCK_H
diff --git a/krita/plugins/formats/psd/psd_layer_record.cpp \
b/krita/plugins/formats/psd/psd_layer_record.cpp index f9ea866..16fc808 100644
--- a/krita/plugins/formats/psd/psd_layer_record.cpp
+++ b/krita/plugins/formats/psd/psd_layer_record.cpp
@@ -885,7 +885,7 @@ QMap<quint16, QByteArray> fetchChannelsBytes(QIODevice *io, \
QVector<ChannelInfo*  channelInfo->channelOffset += rleLength;
         }
         else {
-            QString error = "Unsupported Compression mode: " + channelInfo->compressionType;
+            QString error = QString("Unsupported Compression mode: \
%1").arg(channelInfo->compressionType);  dbgFile << "ERROR: fetchChannelsBytes:" << error;
             throw KisAslReaderUtils::ASLParseException(error);
         }
diff --git a/krita/plugins/formats/psd/psd_layer_section.cpp \
b/krita/plugins/formats/psd/psd_layer_section.cpp index 758e526..b12c79d 100644
--- a/krita/plugins/formats/psd/psd_layer_section.cpp
+++ b/krita/plugins/formats/psd/psd_layer_section.cpp
@@ -17,6 +17,8 @@
  */
 #include "psd_layer_section.h"
 
+#include <boost/bind.hpp>
+
 #include <QIODevice>
 
 #include <KoColorSpace.h>
@@ -68,39 +70,8 @@ bool PSDLayerMaskSection::read(QIODevice* io)
     return retval;
 }
 
-bool PSDLayerMaskSection::readImpl(QIODevice* io)
+bool PSDLayerMaskSection::readLayerInfoImpl(QIODevice* io)
 {
-    dbgFile << "reading layer section. Pos:" << io->pos() <<  "bytes left:" << \
                io->bytesAvailable();
-
-    layerMaskBlockSize = 0;
-    if (m_header.version == 1) {
-        quint32 _layerMaskBlockSize = 0;
-        if (!psdread(io, &_layerMaskBlockSize) || _layerMaskBlockSize > \
                (quint64)io->bytesAvailable()) {
-            error = QString("Could not read layer + mask block size. Got %1. Bytes left %2")
-                .arg(_layerMaskBlockSize).arg(io->bytesAvailable());
-            return false;
-        }
-        layerMaskBlockSize = _layerMaskBlockSize;
-    }
-    else if (m_header.version == 2) {
-        if (!psdread(io, &layerMaskBlockSize) || layerMaskBlockSize > \
                (quint64)io->bytesAvailable()) {
-            error = QString("Could not read layer + mask block size. Got %1. Bytes left %2")
-                .arg(layerMaskBlockSize).arg(io->bytesAvailable());
-            return false;
-        }
-    }
-
-    quint64 start = io->pos();
-
-    dbgFile << "layer + mask section size" << layerMaskBlockSize;
-
-    if (layerMaskBlockSize == 0) {
-        dbgFile << "No layer + mask info, so no layers, only a background layer";
-        return true;
-    }
-
-    KIS_ASSERT_RECOVER(m_header.version == 1) { return false; }
-
     quint32 layerInfoSectionSize = 0;
     SAFE_READ_EX(io, layerInfoSectionSize);
 
@@ -109,7 +80,6 @@ bool PSDLayerMaskSection::readImpl(QIODevice* io)
         layerInfoSectionSize++;
     }
 
-
     {
         SETUP_OFFSET_VERIFIER(layerInfoSectionTag, io, layerInfoSectionSize, 0);
         dbgFile << "Layer info block size" << layerInfoSectionSize;
@@ -224,6 +194,46 @@ bool PSDLayerMaskSection::readImpl(QIODevice* io)
         }
     }
 
+    return true;
+}
+
+bool PSDLayerMaskSection::readImpl(QIODevice* io)
+{
+    dbgFile << "reading layer section. Pos:" << io->pos() <<  "bytes left:" << \
io->bytesAvailable(); +
+    layerMaskBlockSize = 0;
+    if (m_header.version == 1) {
+        quint32 _layerMaskBlockSize = 0;
+        if (!psdread(io, &_layerMaskBlockSize) || _layerMaskBlockSize > \
(quint64)io->bytesAvailable()) { +            error = QString("Could not read layer + mask \
block size. Got %1. Bytes left %2") +                \
.arg(_layerMaskBlockSize).arg(io->bytesAvailable()); +            return false;
+        }
+        layerMaskBlockSize = _layerMaskBlockSize;
+    }
+    else if (m_header.version == 2) {
+        if (!psdread(io, &layerMaskBlockSize) || layerMaskBlockSize > \
(quint64)io->bytesAvailable()) { +            error = QString("Could not read layer + mask \
block size. Got %1. Bytes left %2") +                \
.arg(layerMaskBlockSize).arg(io->bytesAvailable()); +            return false;
+        }
+    }
+
+    quint64 start = io->pos();
+
+    dbgFile << "layer + mask section size" << layerMaskBlockSize;
+
+    if (layerMaskBlockSize == 0) {
+        dbgFile << "No layer + mask info, so no layers, only a background layer";
+        return true;
+    }
+
+    KIS_ASSERT_RECOVER(m_header.version == 1) { return false; }
+
+    if (!readLayerInfoImpl(io)) {
+        return false;
+    }
+
     quint32 globalMaskBlockLength;
     if (!psdread(io, &globalMaskBlockLength)) {
         error = "Could not read global mask info block";
@@ -255,7 +265,21 @@ bool PSDLayerMaskSection::readImpl(QIODevice* io)
         }
     }
 
-    // second try to read additional sections
+    // global additional sections
+
+    /**
+     * Newer versions of PSD have layers info block wrapped into
+     * 'Lr16' or 'Lr32' additional section, while the main block is
+     * absent.
+     *
+     * Here we pass the callback which should be used when such
+     * additional section is recognized.
+     *
+     * NOTE: atm, we do not support ZIP compression, which is used in
+     *       this block, so we just comment it out for now!
+     */
+    // globalInfoSection.setExtraLayerInfoBlockHandler(boost::bind(&PSDLayerMaskSection::readLayerInfoImpl, \
this, _1)); +
     globalInfoSection.read(io);
 
     /* put us after this section so reading the next section will work even if we mess up */
diff --git a/krita/plugins/formats/psd/psd_layer_section.h \
b/krita/plugins/formats/psd/psd_layer_section.h index f599f64..55db74f 100644
--- a/krita/plugins/formats/psd/psd_layer_section.h
+++ b/krita/plugins/formats/psd/psd_layer_section.h
@@ -60,6 +60,7 @@ public:
     PsdAdditionalLayerInfoBlock globalInfoSection;
 
 private:
+    bool readLayerInfoImpl(QIODevice* io);
     bool readImpl(QIODevice* io);
     void writeImpl(QIODevice* io, KisNodeSP rootLayer);
 private:


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

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