Commit 7a2b8377 authored by Dmitry Kazakov's avatar Dmitry Kazakov

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 :)
parent 8cff6d8a
......@@ -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;
......
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