File indexing completed on 2024-06-16 04:17:09

0001 /*
0002  * This file is part of Krita
0003  *
0004  * SPDX-FileCopyrightText: 2021 L. E. Segovia <amy@amyspark.me>
0005  *
0006  * SPDX-License-Identifier: GPL-2.0-or-later
0007  */
0008 
0009 #ifndef _KIS_TIFF_PSD_LAYER_RECORD_H
0010 #define _KIS_TIFF_PSD_LAYER_RECORD_H
0011 
0012 #include <cstdint>
0013 #include <memory>
0014 #include <psd.h>
0015 #include <psd_layer_section.h>
0016 
0017 #include "kritatiffpsd_export.h"
0018 
0019 class KRITATIFFPSD_EXPORT KisTiffPsdLayerRecord
0020 {
0021 public:
0022     KisTiffPsdLayerRecord(bool isBigEndian,
0023                           uint32_t width,
0024                           uint32_t height,
0025                           uint16_t channelDepth,
0026                           uint16_t nChannels,
0027                           uint16_t photometricInterpretation,
0028                           bool hasTransparency = false);
0029 
0030     bool read(QIODevice &io);
0031 
0032     bool write(QIODevice &io, KisNodeSP rootLayer, psd_compression_type compressionType);
0033 
0034     std::shared_ptr<PSDLayerMaskSection> record() const;
0035 
0036     psd_color_mode colorMode() const
0037     {
0038         return m_colorMode;
0039     }
0040 
0041     uint16_t channelDepth() const
0042     {
0043         return m_channelDepth;
0044     }
0045 
0046     bool valid() const;
0047 
0048 private:
0049     psd_byte_order m_byteOrder;
0050     uint32_t m_width;
0051     uint32_t m_height;
0052     uint16_t m_channelDepth;
0053     uint16_t m_nChannels;
0054     psd_color_mode m_colorMode;
0055     std::shared_ptr<PSDLayerMaskSection> m_record;
0056     bool m_hasTransparency;
0057     bool m_valid;
0058 
0059 private:
0060     template<psd_byte_order byteOrder = psd_byte_order::psdBigEndian>
0061     bool readImpl(QIODevice &device);
0062 
0063     template<psd_byte_order byteOrder = psd_byte_order::psdBigEndian>
0064     bool writeImpl(QIODevice &device, KisNodeSP rootLayer, psd_compression_type compressionType);
0065 };
0066 
0067 #endif // _KIS_TIFF_PSD_LAYER_RECORD_H