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 bool userLocked {false};
134
135 int labelColor {0};
136
138 QDomDocument fillConfig;
139
142 QDomDocument vectorStroke;
144
146 qint32 top {0};
147 qint32 left {0};
148 qint32 bottom {0};
149 qint32 right {0};
150 quint8 defaultColor {255}; // 0 or 255
151 bool positionedRelativeToLayer {false};
152 bool disabled {false};
153 bool invertLayerMaskWhenBlending {false};
154 quint8 userMaskDensity {0};
155 double userMaskFeather {0.0};
156 quint8 vectorMaskDensity {0};
157 double vectorMaskFeather {0.0};
158 };
159
161
164 std::array<quint8, 2> blackValues;
165 std::array<quint8, 2> whiteValues;
166 };
167
168 QByteArray data;
169
170 QPair<LayerBlendingRange, LayerBlendingRange> compositeGrayRange;
172 };
173
175
176 QString layerName {"UNINITIALIZED"}; // pascal, not unicode!
177
179
180private:
181 template<psd_byte_order byteOrder = psd_byte_order::psdBigEndian>
182 bool readImpl(QIODevice &io);
183
184 template<psd_byte_order byteOrder = psd_byte_order::psdBigEndian>
185 void writeImpl(QIODevice &io,
186 KisPaintDeviceSP layerContentDevice,
187 KisNodeSP onlyTransparencyMask,
188 const QRect &maskRect,
189 psd_section_type sectionType,
190 const QDomDocument &stylesXmlDoc,
191 bool useLfxsLayerStyleFormat);
192
193 template<psd_byte_order = psd_byte_order::psdBigEndian>
194 void writeTransparencyMaskPixelData(QIODevice &io);
195
196 template<psd_byte_order = psd_byte_order::psdBigEndian>
197 void writePixelDataImpl(QIODevice &io, psd_compression_type compressionType);
198
199 KisPaintDeviceSP convertMaskDeviceIfNeeded(KisPaintDeviceSP dev);
200
201 quint16 psdLabelColor(int colorLabelIndex);
202 int kritaColorLabelIndex(quint16 labelColor);
203
204private:
208 qint64 m_transparencyMaskSizeOffset {0};
209
211};
212
213KRITAPSD_EXPORT QDebug operator<<(QDebug dbg, const PSDLayerRecord &layer);
214KRITAPSD_EXPORT QDebug operator<<(QDebug dbg, const ChannelInfo &layer);
215
217{
218 return dbg << data.blackValues[0] << data.blackValues[1] << data.whiteValues[0] << data.whiteValues[1];
219}
220
221#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