Commit a1e59d2d authored by Dmitry Kazakov's avatar Dmitry Kazakov

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

parent 306229a9
......@@ -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") {
......
......@@ -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
......@@ -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);
}
......
......@@ -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 */
......
......@@ -60,6 +60,7 @@ public:
PsdAdditionalLayerInfoBlock globalInfoSection;
private:
bool readLayerInfoImpl(QIODevice* io);
bool readImpl(QIODevice* io);
void writeImpl(QIODevice* io, KisNodeSP rootLayer);
private:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment