Krita Source Code Documentation
Loading...
Searching...
No Matches
psd_resource_section.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2009 Boudewijn Rempt <boud@valdyas.org>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
7
8#include <QBuffer>
9#include <QIODevice>
10#include <kis_debug.h>
11
12#include "psd.h"
13#include "psd_resource_block.h"
14#include "psd_utils.h"
15
19
24
26{
27 quint32 resourceSectionLength = 0;
28 if (!psdread(io, resourceSectionLength)) {
29 error = "Could not read image resource section length";
30 return false;
31 }
32
33 dbgFile << "Image Resource Sectionlength:" << resourceSectionLength << ", starts at:" << io.pos();
34
35 QByteArray ba = io.read(resourceSectionLength);
36 if ((quint32)ba.size() != resourceSectionLength) {
37 error = "Could not read all resources";
38 return false;
39 }
40
41 QBuffer buf;
42 buf.setBuffer(&ba);
43 buf.open(QBuffer::ReadOnly);
44
45 while (!buf.atEnd()) {
47 if (!block->read(buf)) {
48 error = "Error reading block: " + block->error;
49 dbgFile << error << ", skipping.";
50 delete block;
51 continue;
52 }
53 dbgFile << "resource block created. Type:" << block->identifier << "name" << block->name << "size" << block->dataSize << "," << buf.bytesAvailable()
54 << "bytes to go";
55
56 resources[(PSDResourceID)block->identifier] = block;
57 }
58
59 dbgFile << "Read" << resources.size() << "Image Resource Blocks";
60
61 return valid();
62}
63
65{
66 Q_UNUSED(io);
67
68 if (!valid()) {
69 error = "Resource Section is Invalid";
70 return false;
71 }
72 // First write all the sections
73 QByteArray ba;
74 QBuffer buf;
75 buf.setBuffer(&ba);
76 buf.open(QBuffer::WriteOnly);
77
78 Q_FOREACH (PSDResourceBlock *block, resources) {
79 if (!block->write(buf)) {
80 error = block->error;
81 return false;
82 }
83 }
84
85 buf.close();
86
87 // Then get the size
88 quint32 resourceBlockLength = ba.size();
89 dbgFile << "resource section has size" << resourceBlockLength;
90 psdwrite(io, resourceBlockLength);
91
92 // and write the whole buffer;
93 return (io.write(ba.constData(), ba.size()) == resourceBlockLength);
94}
95
97{
98 return true;
99}
100
102{
103 switch (id) {
104 case UNKNOWN:
105 return "Unknown";
106
107 case PS2_IMAGE_INFO:
108 return "0x03e8 - Obsolete - ps 2.0 image info";
109 case MAC_PRINT_INFO:
110 return "0x03e9 - Optional - Mac print manager print info record";
111 case PS2_COLOR_TAB:
112 return "0x03eb - Obsolete - ps 2.0 indexed color table";
113 case RESN_INFO:
114 return "0x03ed - ResolutionInfo structure";
115 case ALPHA_NAMES:
116 return "0x03ee - Alpha channel names";
117 case DISPLAY_INFO:
118 return "0x03ef - DisplayInfo structure";
119 case CAPTION:
120 return "0x03f0 - Optional - Caption string";
121 case BORDER_INFO:
122 return "0x03f1 - Border info";
123
124 case BACKGROUND_COL:
125 return "0x03f2 - Background color";
126 case PRINT_FLAGS:
127 return "0x03f3 - Print flags";
128 case GREY_HALFTONE:
129 return "0x03f4 - Greyscale and multichannel halftoning info";
130 case COLOR_HALFTONE:
131 return "0x03f5 - Color halftoning info";
132 case DUOTONE_HALFTONE:
133 return "0x03f6 - Duotone halftoning info";
134 case GREY_XFER:
135 return "0x03f7 - Greyscale and multichannel transfer functions";
136 case COLOR_XFER:
137 return "0x03f8 - Color transfer functions";
138 case DUOTONE_XFER:
139 return "0x03f9 - Duotone transfer functions";
140 case DUOTONE_INFO:
141 return "0x03fa - Duotone image information";
142 case EFFECTIVE_BW:
143 return "0x03fb - Effective black & white values for dot range";
144
145 case OBSOLETE_01:
146 return "0x03fc - Obsolete";
147 case EPS_OPT:
148 return "0x03fd - EPS options";
149 case QUICK_MASK:
150 return "0x03fe - Quick mask info";
151 case OBSOLETE_02:
152 return "0x03ff - Obsolete";
153 case LAYER_STATE:
154 return "0x0400 - Layer state info";
155 case WORKING_PATH:
156 return "0x0401 - Working path (not saved)";
157 case LAYER_GROUP:
158 return "0x0402 - Layers group info";
159 case OBSOLETE_03:
160 return "0x0403 - Obsolete";
161 case IPTC_NAA_DATA:
162 return "0x0404 - IPTC-NAA record (IMV4.pdf)";
163 case IMAGE_MODE_RAW:
164 return "0x0405 - Image mode for raw format files";
165
166 case JPEG_QUAL:
167 return "0x0406 - JPEG quality";
168 case GRID_GUIDE:
169 return "0x0408 - Grid & guide info";
170 case THUMB_RES:
171 return "0x0409 - Thumbnail resource";
172 case COPYRIGHT_FLG:
173 return "0x040a - Copyright flag";
174 case URL:
175 return "0x040b - URL string";
176 case THUMB_RES2:
177 return "0x040c - Thumbnail resource";
178 case GLOBAL_ANGLE:
179 return "0x040d - Global angle";
180 case COLOR_SAMPLER:
181 return "0x040e - Color samplers resource";
182 case ICC_PROFILE:
183 return "0x040f - ICC Profile";
184
185 case WATERMARK:
186 return "0x0410 - Watermark";
187 case ICC_UNTAGGED:
188 return "0x0411 - Do not use ICC profile flag";
189 case EFFECTS_VISIBLE:
190 return "0x0412 - Show / hide all effects layers";
191 case SPOT_HALFTONE:
192 return "0x0413 - Spot halftone";
193 case DOC_IDS:
194 return "0x0414 - Document specific IDs";
195 case ALPHA_NAMES_UNI:
196 return "0x0415 - Unicode alpha names";
197 case IDX_COL_TAB_CNT:
198 return "0x0416 - Indexed color table count";
199 case IDX_TRANSPARENT:
200 return "0x0417 - Index of transparent color (if any)";
201 case GLOBAL_ALT:
202 return "0x0419 - Global altitude";
203
204 case SLICES:
205 return "0x041a - Slices";
206 case WORKFLOW_URL_UNI:
207 return "0x041b - Workflow URL - Unicode string";
208 case JUMP_TO_XPEP:
209 return "0x041c - Jump to XPEP (?)";
210 case ALPHA_ID:
211 return "0x041d - Alpha IDs";
212 case URL_LIST_UNI:
213 return "0x041e - URL list - unicode";
214 case VERSION_INFO:
215 return "0x0421 - Version info";
216 case EXIF_DATA:
217 return "0x0422 - (Photoshop 7.0) EXIF data 1. See http://www.kodak.com/global/plugins/acrobat/en/service/digCam/exifStandard2.pdf";
218 case EXIF_DATA_3:
219 return "0x0423 - (Photoshop 7.0) EXIF data 3. See http://www.kodak.com/global/plugins/acrobat/en/service/digCam/exifStandard2.pdf";
220
221 case XMP_DATA:
222 return "0x0424 - XMP data block";
223 case CAPTION_DIGEST:
224 return "0x0425 - (Photoshop 7.0) Caption digest. 16 bytes: RSA Data Security, MD5 message-digest algorithm";
225 case PRINT_SCALE:
226 return "0x0426 - (Photoshop 7.0) Print scale. 2 bytes style (0 = centered, 1 = size to fit, 2 = user defined). 4 bytes x location (floating point). 4 "
227 "bytes y location (floating point). 4 bytes scale (floating point)";
229 return "0x0428 - (Photoshop CS) Pixel Aspect Ratio. 4 bytes (version = 1 or 2), 8 bytes double, x / y of a pixel. Version 2, attempting to correct "
230 "values for NTSC and PAL, previously off by a factor of approx. 5%.";
231 case LAYER_COMPS:
232 return "0x0429 - (Photoshop CS) Layer Comps. 4 bytes (descriptor version = 16), Descriptor (see Descriptor structure)";
234 return "0x042A - (Photoshop CS) Alternate Duotone Colors. 2 bytes (version = 1), 2 bytes count, following is repeated for each count: [ Color: 2 bytes "
235 "for space followed by 4 * 2 byte color component ], following this is another 2 byte count, usually 256, followed by Lab colors one byte each "
236 "for L, a, b. This resource is not read or used by Photoshop.";
237 case ALTERNATE_SPOT:
238 return "0x042B - (Photoshop CS)Alternate Spot Colors. 2 bytes (version = 1), 2 bytes channel count, following is repeated for each count: 4 bytes "
239 "channel ID, Color: 2 bytes for space followed by 4 * 2 byte color component. This resource is not read or used by Photoshop.";
241 return "0x042D - (Photoshop CS2) Layer Selection ID(s). 2 bytes count, following is repeated for each count: 4 bytes layer ID";
242
243 case HDR_TONING:
244 return "0x042E - (Photoshop CS2) HDR Toning information";
245 case CS2_PRINT_INFO:
246 return "0x042F - (Photoshop CS2) Print info";
248 return "0x0430 - (Photoshop CS2) Layer Group(s) Enabled ID. 1 byte for each layer in the document, repeated by length of the resource. NOTE: Layer "
249 "groups have start and end markers";
250 case COLOR_SAMPLERS:
251 return "0x0431 - (Photoshop CS3) Color samplers resource. Also see ID 1038 for old format. See Color samplers resource format.";
253 return "0x0432 - (Photoshop CS3) Measurement Scale. 4 bytes (descriptor version = 16), Descriptor (see See Descriptor structure)";
254 case TIMELINE_INFO:
255 return "0x0433 - (Photoshop CS3) Timeline Information. 4 bytes (descriptor version = 16), Descriptor (see See Descriptor structure)";
256 case SHEET_DISCLOSURE:
257 return "0x0434 - (Photoshop CS3) Sheet Disclosure. 4 bytes (descriptor version = 16), Descriptor (see See Descriptor structure)";
258 case CS3_DISPLAY_INFO:
259 return "0x0435 - (Photoshop CS3) DisplayInfo structure to support floating point colors. Also see ID 1007. See Appendix A in Photoshop API Guide.pdf .";
260 case ONION_SKINS:
261 return "0x0436 - (Photoshop CS3) Onion Skins. 4 bytes (descriptor version = 16), Descriptor (see See Descriptor structure)";
262
263 case COUNT_INFO:
264 return "0x0438 - (Photoshop CS4) Count Information. 4 bytes (descriptor version = 16), Descriptor (see See Descriptor structure) Information about the "
265 "count in the document. See the Count Tool.";
266 case CS5_PRINT_INFO:
267 return "0x043A - (Photoshop CS5) Print Information. 4 bytes (descriptor version = 16), Descriptor (see See Descriptor structure) Information about the "
268 "current print settings in the document. The color management options.";
269 case CS5_PRINT_STYLE:
270 return "0x043B - (Photoshop CS5) Print Style. 4 bytes (descriptor version = 16), Descriptor (see See Descriptor structure) Information about the "
271 "current print style in the document. The printing marks, labels, ornaments, etc.";
272 case CS5_NSPrintInfo:
273 return "0x043C - (Photoshop CS5) Macintosh NSPrintInfo. Variable OS specific info for Macintosh. NSPrintInfo. It is recommended that you do not "
274 "interpret or use this data.";
275 case CS5_WIN_DEVMODE:
276 return "0x043D - (Photoshop CS5) Windows DEVMODE. Variable OS specific info for Windows. DEVMODE. It is recommended that you do not interpret or use "
277 "this data.";
279 return "0x043E - (Photoshop CS6) Auto Save File Path. Unicode string. It is recommended that you do not interpret or use this data.";
281 return "0x043F - (Photoshop CS6) Auto Save Format. Unicode string. It is recommended that you do not interpret or use this data.";
283 return "0x0440 - (Photoshop CC) Path Selection State. 4 bytes (descriptor version = 16), Descriptor (see See Descriptor structure) Information about "
284 "the current path selection state.";
285
286 case PATH_INFO_FIRST:
287 return "0x07d0 - First path info block";
288 case PATH_INFO_LAST:
289 return "0x0bb6 - Last path info block";
290 case CLIPPING_PATH:
291 return "0x0bb7 - Name of clipping path";
292
294 return "0x0BB8 (Photoshop CC) Origin Path Info. 4 bytes (descriptor version = 16), Descriptor (see See Descriptor structure) Information about the "
295 "origin path data.";
296
298 return "0x0FA0-0x1387 Plug-In resource(s). Resources added by a plug-in. See the plug-in API found in the SDK documentation ";
300 return "Last plug-in resource";
301
302 case IMAGE_READY_VARS:
303 return "0x1B58 Image Ready variables. XML representation of variables definition";
305 return "0x1B59 Image Ready data sets";
306
308 return "0x1F40 (Photoshop CS3) Lightroom workflow, if present the document is in the middle of a Lightroom workflow.";
309
310 case PRINT_FLAGS_2:
311 return "0x2710 - Print flags";
312 default: {
313 if (id > PATH_INFO_FIRST && id < PATH_INFO_LAST)
314 return "Path Info Block";
316 return "Plug-In Resource";
317 }
318 };
319 return QString("Unknown Resource Block: %1").arg(id);
320}
QMap< PSDResourceID, PSDResourceBlock * > resources
static QString idToString(PSDResourceID id)
#define dbgFile
Definition kis_debug.h:53
std::enable_if_t< std::is_arithmetic< T >::value, bool > psdread(QIODevice &io, T &v)
Definition psd_utils.h:397
std::enable_if_t< std::is_arithmetic< T >::value, bool > psdwrite(QIODevice &io, T v)
Definition psd_utils.h:170