Krita Source Code Documentation
Loading...
Searching...
No Matches
psd_layer_record.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2009 Boudewijn Rempt <boud@valdyas.org>
3 * SPDX-FileCopyrightText: 2021 L. E. Segovia <amy@amyspark.me>
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 */
7#ifndef PSD_LAYER_RECORD_H
8#define PSD_LAYER_RECORD_H
9
10#include "kritapsd_export.h"
11
12#include <QByteArray>
13#include <QString>
14#include <QVector>
15
16#include <kis_node.h>
17#include <kis_paint_device.h>
18#include <kis_types.h>
19#include <psd.h>
20
22#include "psd_header.h"
23
24class QIODevice;
25class KoPathShape;
26
47
48struct KRITAPSD_EXPORT ChannelInfo {
50 : channelId(0)
51 , compressionType(psd_compression_type::Unknown)
52 , channelDataStart(0)
53 , channelDataLength(0)
54 , channelOffset(0)
55 , channelInfoPosition(0)
56 {
57 }
58
59 qint16 channelId; // 0 red, 1 green, 2 blue, -1 transparency, -2 user-supplied layer mask
64 int channelOffset; // where the channel data starts
65 int channelInfoPosition; // where the channelinfo record is saved in the file
66};
67
68class KRITAPSD_EXPORT PSDLayerRecord
69{
70public:
71 PSDLayerRecord(const PSDHeader &header);
72
74 {
75 qDeleteAll(channelInfoRecords);
76 }
77
78 QRect channelRect(ChannelInfo *channel) const;
79
80 bool read(QIODevice &io);
81 bool readPixelData(QIODevice &io, KisPaintDeviceSP device);
82 bool readMask(QIODevice &io, KisPaintDeviceSP dev, ChannelInfo *channel);
83
93 KoPathShape *constructPathShape(psd_path path, double shapeWidth, double shapeHeight);
94
101 void addPathShapeToPSDPath(psd_path &path, KoPathShape *shape, double shapeWidth, double shapeHeight);
102
103 void write(QIODevice &io,
104 KisPaintDeviceSP layerContentDevice,
105 KisNodeSP onlyTransparencyMask,
106 const QRect &maskRect,
107 psd_section_type sectionType,
108 const QDomDocument &stylesXmlDoc,
109 bool useLfxsLayerStyleFormat);
110 void writePixelData(QIODevice &io, psd_compression_type compressionType);
111
112 bool valid();
113
114 QString error;
115
116 qint32 top {0};
117 qint32 left {0};
118 qint32 bottom {0};
119 qint32 right {0};
120
121 quint16 nChannels {0};
122
124
126 bool isPassThrough {false};
127
128 quint8 opacity {0};
129 quint8 clipping {0};
130 bool transparencyProtected {false};
131 bool visible {true};
132 bool irrelevant {false};
133
134 int labelColor {0};
135
137 QDomDocument fillConfig;
138
141 QDomDocument vectorStroke;
143
145 qint32 top {0};
146 qint32 left {0};
147 qint32 bottom {0};
148 qint32 right {0};
149 quint8 defaultColor {255}; // 0 or 255
150 bool positionedRelativeToLayer {false};
151 bool disabled {false};
152 bool invertLayerMaskWhenBlending {false};
153 quint8 userMaskDensity {0};
154 double userMaskFeather {0.0};
155 quint8 vectorMaskDensity {0};
156 double vectorMaskFeather {0.0};
157 };
158
160
163 std::array<quint8, 2> blackValues;
164 std::array<quint8, 2> whiteValues;
165 };
166
167 QByteArray data;
168
169 QPair<LayerBlendingRange, LayerBlendingRange> compositeGrayRange;
171 };
172
174
175 QString layerName {"UNINITIALIZED"}; // pascal, not unicode!
176
178
179private:
180 template<psd_byte_order byteOrder = psd_byte_order::psdBigEndian>
181 bool readImpl(QIODevice &io);
182
183 template<psd_byte_order byteOrder = psd_byte_order::psdBigEndian>
184 void writeImpl(QIODevice &io,
185 KisPaintDeviceSP layerContentDevice,
186 KisNodeSP onlyTransparencyMask,
187 const QRect &maskRect,
188 psd_section_type sectionType,
189 const QDomDocument &stylesXmlDoc,
190 bool useLfxsLayerStyleFormat);
191
192 template<psd_byte_order = psd_byte_order::psdBigEndian>
193 void writeTransparencyMaskPixelData(QIODevice &io);
194
195 template<psd_byte_order = psd_byte_order::psdBigEndian>
196 void writePixelDataImpl(QIODevice &io, psd_compression_type compressionType);
197
198 KisPaintDeviceSP convertMaskDeviceIfNeeded(KisPaintDeviceSP dev);
199
200 quint16 psdLabelColor(int colorLabelIndex);
201 int kritaColorLabelIndex(quint16 labelColor);
202
203private:
207 qint64 m_transparencyMaskSizeOffset {0};
208
210};
211
212KRITAPSD_EXPORT QDebug operator<<(QDebug dbg, const PSDLayerRecord &layer);
213KRITAPSD_EXPORT QDebug operator<<(QDebug dbg, const ChannelInfo &layer);
214
216{
217 return dbg << data.blackValues[0] << data.blackValues[1] << data.whiteValues[0] << data.whiteValues[1];
218}
219
220#endif // PSD_LAYER_RECORD_H
The position of a path point within a path shape.
Definition KoPathShape.h:63
PsdAdditionalLayerInfoBlock infoBlocks
QRect m_onlyTransparencyMaskRect
psd_vector_mask vectorMask
psd_layer_type_shape textShape
QDomDocument vectorOriginationData
const PSDHeader m_header
KisPaintDeviceSP m_layerContentDevice
LayerBlendingRanges blendingRanges
QVector< ChannelInfo * > channelInfoRecords
QDomDocument vectorStroke
QDomDocument fillConfig
KisNodeSP m_onlyTransparencyMask
LayerMaskData layerMask
The PsdAdditionalLayerInfoBlock class implements the Additional Layer Information block.
psd_compression_type
Definition psd.h:39
@ Unknown
Definition psd.h:44
psd_section_type
Definition psd.h:144
psd_fill_type
Definition psd.h:123
@ psd_fill_solid_color
Definition psd.h:124
psd_layer_type
@ psd_layer_type_brightness_contrast
@ psd_layer_type_channel_mixer
@ psd_layer_type_levels
@ psd_layer_type_hue_saturation
@ psd_layer_type_color_balance
@ psd_layer_type_photo_filter
@ psd_layer_type_gradient_map
@ psd_layer_type_invert
@ psd_layer_type_threshold
@ psd_layer_type_posterize
@ psd_layer_type_pattern_fill
@ psd_layer_type_curves
@ psd_layer_type_gradient_fill
@ psd_layer_type_normal
@ psd_layer_type_selective_color
@ psd_layer_type_folder
@ psd_layer_type_solid_color
@ psd_layer_type_hidden
KRITAPSD_EXPORT QDebug operator<<(QDebug dbg, const PSDLayerRecord &layer)
QVector< quint32 > rleRowLengths
psd_compression_type compressionType
quint64 channelDataLength
quint64 channelDataStart
QVector< QPair< LayerBlendingRange, LayerBlendingRange > > sourceDestinationRanges
QPair< LayerBlendingRange, LayerBlendingRange > compositeGrayRange