File indexing completed on 2024-05-12 15:59:39

0001 /*
0002  *  SPDX-FileCopyrightText: 2009 Boudewijn Rempt <boud@valdyas.org>
0003  *  SPDX-FileCopyrightText: 2021 L. E. Segovia <amy@amyspark.me>
0004  *
0005  *  SPDX-License-Identifier: GPL-2.0-or-later
0006  */
0007 #ifndef PSD_LAYER_SECTION_H
0008 #define PSD_LAYER_SECTION_H
0009 
0010 #include "kritapsd_export.h"
0011 
0012 #include <QString>
0013 
0014 class QIODevice;
0015 
0016 #include <kis_types.h>
0017 #include <psd.h>
0018 
0019 #include "psd_header.h"
0020 #include "psd_layer_record.h"
0021 
0022 class KRITAPSD_EXPORT PSDLayerMaskSection
0023 {
0024 public:
0025     PSDLayerMaskSection(const PSDHeader &header);
0026     ~PSDLayerMaskSection();
0027 
0028     bool read(QIODevice &io);
0029     bool write(QIODevice &io, KisNodeSP rootLayer, psd_compression_type compressionType);
0030 
0031     QString error;
0032 
0033     // layer info: https://www.adobe.com/devnet-apps/photoshop/fileformatashtml/#50577409_16000
0034     bool hasTransparency{false};
0035 
0036     qint16 nLayers{0}; // If layer count is a negative number, its absolute value is the number of layers and the first alpha channel contains the transparency
0037                        // data for the merged result.
0038     QVector<PSDLayerRecord *> layers;
0039 
0040     // mask info: https://www.adobe.com/devnet-apps/photoshop/fileformatashtml/#50577409_17115
0041     struct GlobalLayerMaskInfo {
0042         quint16 overlayColorSpace{0}; // Overlay color space (undocumented).
0043         quint16 colorComponents[4]{0, 0, 0, 0}; // 4 * 2 byte color components
0044         quint16 opacity{0}; // Opacity. 0 = transparent, 100 = opaque.
0045         quint8 kind{0}; // Kind. 0 = Color selected--i.e. inverted; 1 = Color protected;128 = use value stored per layer. This value is preferred. The others
0046                         // are for backward compatibility with beta versions.
0047     };
0048     GlobalLayerMaskInfo globalLayerMaskInfo;
0049     PsdAdditionalLayerInfoBlock globalInfoSection;
0050 
0051 private:
0052     template<psd_byte_order byteOrder = psd_byte_order::psdBigEndian>
0053     bool readLayerInfoImpl(QIODevice &io);
0054     bool readPsdImpl(QIODevice &io);
0055     template<psd_byte_order byteOrder = psd_byte_order::psdBigEndian>
0056     bool readTiffImpl(QIODevice &io);
0057     template<psd_byte_order byteOrder = psd_byte_order::psdBigEndian>
0058     bool readGlobalMask(QIODevice &io);
0059     void writePsdImpl(QIODevice &io, KisNodeSP rootLayer, psd_compression_type compressionType);
0060     template<psd_byte_order byteOrder = psd_byte_order::psdBigEndian>
0061     void writeTiffImpl(QIODevice &io, KisNodeSP rootLayer, psd_compression_type compressionType);
0062 private:
0063     const PSDHeader m_header;
0064 };
0065 
0066 #endif // PSD_LAYER_SECTION_H