HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
IMG_FilePSD.h
Go to the documentation of this file.
1 /*
2 * PROPRIETARY INFORMATION. This software is proprietary to
3 * Side Effects Software Inc., and is not to be reproduced,
4 * transmitted, or disclosed in any way without written permission.
5 *
6 * NAME: IMG_PSD.h ( IMG Library, C++ )
7 *
8 * COMMENTS: Read/Write Photoshop Document (.psd) files
9 */
10 
11 /*
12 * Overview
13 * -----------------------------------------------------------------------------
14 * This class enables the ability to read and write Photshop Document files
15 * into/from Houdini. Currently, 8 bit and 16 bit files with compatibility mode
16 * enabled and RGB color space can be read.
17 * TODO: Add more details when more fleshed out.
18 *
19 * The class is based off the Adobe specification dated October 2013 which can be
20 * found at http://www.adobe.com/devnet-apps/photoshop/fileformatashtml/
21 *
22 * TODO: Update when more fleshed out
23 * Supported:
24 * - .psd file format
25 * - .psb file format
26 * - RGB color mode
27 * - 8 bits per channel images with RLE compression (compatibility mode enabled)
28 * - 16 bits per channel images with raw data (compatibility mode enabled)
29 * - Simple Layer data
30 * - Layer names
31 * - Layer data, if it's a standard image layer.
32 * - Folders
33 * - Text layers
34 * - Masks***
35 *
36 * *** There is information at the bottom of this section of how masks are
37 * handled.
38 *
39 * Not Supported
40 * - Color modes: Bitmap, grayscale, indexed, CMYK, multichannel, duotone, lab
41 * - 1 bit per channel images
42 * - 32 bits per channel images
43 * - Images compressed with ZIP without prediction (I have not seen any images
44 * that use this compression method however!)
45 * - Blending modes
46 *
47 * The overall structure of a .psd file looks like the following:
48 *
49 * * * * * * * * * * * * * * * * *
50 * * Header Data *
51 * * * * * * * * * * * * * * * * *
52 * * Color Mode Data *
53 * * * * * * * * * * * * * * * * *
54 * * Image Resources *
55 * * * * * * * * * * * * * * * * *
56 * * Layer and Mask Information *
57 * * * * * * * * * * * * * * * * *
58 * * Image Data *
59 * * * * * * * * * * * * * * * * *
60 *
61 * TODO: Update when more fleshed out
62 * Each section starts with Length data, which is the amount of bytes within the
63 * given section. Apart from this information, we only care about the header,
64 * layer and mask information and image data sections at this point.
65 *
66 * Notes: - Compatibility mode needs to be enabled to read, because composite
67 * image data is not stored unless enabled.
68 * - Data is stored in Planar order within a .psd, which means all the
69 * Red channel data is stored first, then all the Green channel data,
70 * then all the Blue channel data. RRRRRRGGGGGGBBBBBB
71 *
72 * Header Section
73 * ---------------
74 * Consists of a summary of important data for the file.
75 *
76 * Layer and Mask Information Section
77 * -----------------------------------
78 * Note that the finer details should be referred to within the official spec,
79 * this will be a basic summary.
80 *
81 * Information is stored a bit oddly (in my opinion) for this section. We have
82 * 4 main sections of Length, Layer Info, Global Layer Mask Info, then
83 * Additional Layer Information. It looks as if for Photoshop 4.0 and later
84 * .psds, the layer info is organized as the following, if we only pay
85 * attention to important parts.
86 *
87 * - Length
88 * - Layer Info (Sometimes this section is length 0, followed by no data.)
89 * - Global Layer Mask Info (Sometimes this section is length 0, followed by
90 * no data.)
91 * - Additional Layer Info
92 * - If Key code is Lr16, Lr32 or Layr, then
93 * - Layer Info
94 * - Layer info length (in bytes)
95 * - Number of layers (or n)
96 * - n Number of Layer Records (or Layer information)
97 * - Top/left/bottom/right coordinates for start of image data
98 * boundaries.
99 * - Number of channels for the layer (or m)
100 * - m number of Channel Information
101 * - 2 bytes for Channel ID
102 * - 4 bytes for length of Channel Data
103 * - Layer name (as a Pascal string)
104 * - n * m number of Channel Image Data (the actual color data)
105 *
106 * As you can see, there is a possibility of there being 2 Layer Info blocks,
107 * where 1 can be a subsection of Additional Layer Info.
108 *
109 * Image Data Section
110 * -------------------
111 * This section only exists with compatibility mode enabled when saved. This
112 * section starts with 2 bytes for the compression method, followed by the image
113 * data.
114 *
115 * RLE Compression Summary
116 * -----------------------------------------------------------------------------
117 * Lossless compression that can be efficient for data that has frequently
118 * repeated data. However, for data that rarely has repeats the "compressed"
119 * data can actually turn out larger than it's uncompressed size.
120 *
121 * Photoshop uses this compression method for 8 bits/channel images. The Adobe
122 * spec does not specify this, however I haven't seen it used in other cases.
123 *
124 * RLE Data format with compatibility mode ENABLED
125 * ------------------------------------------------
126 * In the image data section, immediately after the compression mode the data
127 * starts off with all the length values which are 2 bytes each. These 2 byte
128 * values refers to the length of a single channel's scanline data.
129 *
130 * After all the length data, the rest of the file consists of compressed
131 * image data. For decompression, the PackBits method is used. More info can
132 * be found at http://en.wikipedia.org/wiki/PackBits and
133 * http://web.archive.org/web/20080705155158/http://developer.apple.co
134 * m/technotes/tn/tn1023.html
135 *
136 * As an example, for an image with height of 3 pixels and an unknown width
137 * (you won't be able to tell the width of an image just based off the RLE
138 * data until uncompressed, however you should know the width beforehand
139 * from header data.) The data will appear in this format in the image data
140 * section.
141 *
142 * LR1 LR1 LR2 LR2 LR3 LR3
143 * LG1 LG1 LG2 LG2 LG3 LG3
144 * LB1 LB1 LB2 LB2 LB3 LB3
145 * R1D R1D R1D R1D
146 * R2D R2D R2D R2D R2D R2D
147 * R3D R3D .... B3D B3D
148 *
149 * L(R/G/B)n = Length for Red/Green/Blue channel data, row "n"
150 * (R/G/B)nD = Red/Green/Blue channel, compressed data for row "n"
151 *
152 * In the above example, LR1 = 4, LR2 = 6, LR3 = 3 and LB3 = 2
153 * ------------------------------------------------
154 * TODO: When using layers, explain how layer data is stored
155 *
156 * ZIP without Prediction Summary
157 * -----------------------------------------------------------------------------
158 * In .psd files, ZIP without prediction SEEMS to be just using the DEFLATE data
159 * compression algorithm based off of other programs. However, I personally have
160 * not seen any files which uses this method of compression.
161 *
162 * ZIP with Prediction Summary
163 * -----------------------------------------------------------------------------
164 * In .psd files, ZIP with prediction is a combination of using the DEFLATE data
165 * compression algorithm and Delta encoding; which is also known as data
166 * differencing.
167 *
168 * DEFLATE Terminology:
169 * - Deflate: to compress data
170 * - Inflate: to decompress data
171 *
172 * As a note, I have only seen this compression used to compress individual layer
173 * data but not used for the composite image. This seems to be the case based
174 * off of observation, but this may not actually be the case as the psd spec
175 * does not go into details on which types of files uses which types of
176 * compression. So as of now ZIP is not supported when it comes to the composite
177 * image.
178 *
179 * TODO: Change this tidbit when composite will only be built off of layer data.
180 *
181 * Within the psd, we know the length of each channels data based off of the
182 * Channel Information, within the Layer Records section which is a subsection
183 * of the Layer and Mask information section. In the ZIP case, we know exactly
184 * how many bytes the compressed data is. So to get the raw image data, we simply
185 * need to read LENGTH amount of bytes to get the ZIP data, decompress the ZIP
186 * data, then decode the delta encoded portion.
187 *
188 * It is not required to understand DEFLATE to understand the code within
189 * IMG_PSD.c because ZLib is used to handle the complex decompression, hence it
190 * will not be explained. If you are interested however, you can find details at
191 * https://www.ietf.org/rfc/rfc1951.txt
192 *
193 * Delta Encoding/Data Differencing Summary
194 * ------------------------------------------------
195 * The prediction portion of ZIP with prediction refers to the delta encoding
196 * that is used. This is a simple encoding which stores the values as
197 * differences instead of just the raw data. As an example, the raw data form
198 * 7 5 3 4 2 1 8, would be stored as 7 -2 -2 1 -2 -1 7 in delta encoded form.
199 * More details can be found at https://en.wikipedia.org/wiki/Delta_encoding
200 *
201 * After the data is inflated after zip decompression each individual row
202 * starts off with a non-delta value, instead of building off the previous
203 * rows last value. So, for a 5px (width) x 3px (height) image we could have:
204 *
205 * 15 1 0 0 -2 will be 15 16 16 16 14
206 * 13 1 2 0 -3 decoded as 13 14 16 16 13
207 * 15 0 0 -3 4 15 15 15 12 16
208 *
209 * This decoding below is WRONG
210 * 15 16 16 16 14
211 * 27 28 30 30 27
212 * 42 42 42 39 43
213 *
214 * Planar Image Data Summary
215 * -----------------------------------------------------------------------------
216 * Photoshop stores image data in PLANAR form. This means all the image data for
217 * a single channel is stored, followed by all of the image data for the second
218 * channel, followed by the third channel etc. You can tell how much data exists
219 * by using the height, width, number of channels which should have been read
220 * earlier by the readHeader() method.
221 *
222 * As an example for a 4px(width) x 3px(height) image, with 16 bits per channel,
223 * and 3 channels (RGB) the image will be stored in the following format:
224 *
225 * RR RR RR RR RR RR RR RR
226 * RR RR RR RR RR RR RR RR
227 * RR RR RR RR RR RR RR RR
228 * GG GG GG GG GG GG GG GG
229 * GG GG GG GG GG GG GG GG
230 * GG GG GG GG GG GG GG GG
231 * BB BB BB BB BB BB BB BB
232 * BB BB BB BB BB BB BB BB
233 * BB BB BB BB BB BB BB BB
234 *
235 * Interleaved Image Data Summary
236 * -----------------------------------------------------------------------------
237 * Interleaved data simply means the data alternates between channels. Using the
238 * same example case as above, the image will be in the following format:
239 *
240 * RR RR GG GG BB BB RR RR GG GG BB BB RR RR GG GG BB BB RR RR GG GG BB BB
241 * RR RR GG GG BB BB RR RR GG GG BB BB RR RR GG GG BB BB RR RR GG GG BB BB
242 * RR RR GG GG BB BB RR RR GG GG BB BB RR RR GG GG BB BB RR RR GG GG BB BB
243 *
244 * Layers/Folders Summary
245 * -----------------------------------------------------------------------------
246 * Layers are treated as a stack and are stored within psds starting with the
247 * lowest z-index, followed by each layer with a higher z-index.
248 *
249 * Folders are treated as a Layer within psds, each Folder having a "Start"
250 * and "End" indication Layer. For example:
251 *
252 * ** Where Group n represents a folder.
253 * Visual Representation in Photoshop
254 * ------------------------------------------------------------------------
255 * Group 0 Group 0
256 * Image Layer 2 Image Layer 3
257 * Image Layer 1 Group 1
258 * Image Layer 0 Image Layer 2
259 * Image Layer 1
260 * Image Layer 0
261 *
262 * Stored in PSDs with the Order
263 * ------------------------------------------------------------------------
264 * Image Layer 0 Image Layer 0
265 * </End of Group 0> <End of Group 0>
266 * Image Layer 1 <End of Group 1>
267 * Image Layer 2 Image Layer 1
268 * <Start of Group 0> Image Layer 2
269 * <Start of Group 1>
270 * Image Layer 3
271 * <Start of Group 0>
272 *
273 * Premultiplied Images
274 * -----------------------------------------------------------------------------
275 * If an image is premultiplied, as the name suggests; means that the image data
276 * we receive is already multiplied. This is important to note with alpha data,
277 * since the final image result will be drastically different depending on if
278 * the data was already premultiplied or not.
279 *
280 * Houdini expects data to be passed in premultiplied form. Within individual
281 * layer data in psds, the data is not premultiplied, hence we need to do
282 * multiplication before passing it into Houdini. However, for the composite
283 * image the data is already premultiplied, BUT the areas which are supposed
284 * to be transparent are passed in as white data. This means we need to do a
285 * seperate compensation calculation to get the correct output for the
286 * composite image within Houdini.
287 *
288 * Reference: http://microsoft.github.io/Win2D/html/PremultipliedAlpha.htm
289 *
290 * Mask Data
291 * -----------------------------------------------------------------------------
292 * We have mask data on a layer when a single layer has either
293 * PSD_ChannelType::UserSuppliedLayerMask; ID -2 or
294 * PSD_ChannelType::RealUserSuppliedLayerMask; ID -3 or a combination of the two.
295 *
296 * When all layers are loaded into Houdini, there are 3 overall cases of how
297 * masks are loaded.
298 *
299 * First case: RGBA channels have no image data, but has mask data.
300 * Method for handling: Mask data put into the alpha channel of the plane. If
301 * there are multiple mask channels, the additional
302 * masks channels will have a new plane added with suffix
303 * _m and the alpha channel of these additioanl planes
304 * containing any additional mask data.
305 *
306 * Second case: RGB channels have image data, Alpha channel has no data,
307 * and has mask data.
308 * Method for handling: RGB data loaded into the plane, new plane with a suffix
309 * _m is added for each plane, with the mask data in the
310 * alpha channel for the appropriate planes.
311 *
312 * Third case: RGBA channels have image data, and has mask data.
313 * Method for handling: Same as second case with alpha image data loaded into
314 * original plane.
315 *
316 * The very important field myMaskLayers is used to keep track of any mask
317 * channels that have their own plane. myMaskLayers maps a layer index to
318 * a PSD_ChannelType to a plane name, so we can see if a channel has their own
319 * dedicated plane by checking
320 * myMaskLayers[layer_index].count(PSD_ChannelType::maskChannel). This was not
321 * left in IMG_PSDLayerRecords because we needed to know the index which was not
322 * known by IMG_PSDLayerRecords.
323 */
324 
325 #ifndef __IMG_PSD__
326 #define __IMG_PSD__
327 
328 #include "IMG_API.h"
329 #include "IMG_File.h"
330 
331 #include <PXL/PXL_Fill.h>
332 #include <UT/UT_Array.h>
333 #include <UT/UT_Map.h>
334 #include <UT/UT_NonCopyable.h>
335 
338 
339 struct IMG_PSDLayerRecords;
340 struct IMG_PSDChannelInfo;
341 struct IMG_PSDLayerMaskData;
342 
344 {
345  // Version, should always be 1 for .psd files or version 2 for .psb files.
346  // .psb files will not be supported.
348 
349  // Value should be 0, unless updated by the Adobe spec.
351 
352  // Number of channels in image, including alpha channels. Official
353  // supported range by .psd spec is 1 - 56, for our purposes only 3/4
354  // are currently supported.
356 
357  // Height of the image.
359 
360  // Width of the image.
362 
363  // Number of bits per channel. 8/16 supported but 1 and 32 are not.
365 
366  // Color mode of the file: Valid values are RGB. There are other color
367  // modes which will not be supported as of now, including Bitmap,
368  // Grayscale, Indexed, CMYK, Multichannel, Duotone, and Lab.
370 
371  // Is the file psd or psb format? Not part of the official psd header,
372  // but a convenience bool instead of having to check if myVersion == 1
373  // every time we need this check.
374  bool isPSD;
375 };
376 
378 {
379  // Length of the layer info section in bytes.
381 
382  // Total number of layers in the psd.
384 
385  // Information for each individual layer.
387 };
388 
389 // Not sure if the rest of the global layer mask info data is needed
390 // currently.
392 {
393  // The length of this section in bytes.
395 };
396 
398 {
399  // Signature which needs to be either 8BIM or 8B64
400  char mySignature[4];
401 
402  // 4 character key code such as LMsk, Lr16 etc. Rest can
403  // be found in psd spec.
404  char myKey[4];
405 
406  // Length of the data.
408 
409  // Data here. (Not included yet, if ever)
410 };
411 
412 // Channel information which corresponds to the third section within
413 // the Layer Records section.
415 {
416  // ID 0 = Red, 1 = Green, 2 = Blue, etc. PSD_ChannelType has the various
417  // types.
419 
420  // Compression type, 0 = RAW, 1 = RLE, 3 = ZIP with prediction.
422 
423  // The length of the image data for the channel ID.
425 
426  // Position within the file that this channel's image data starts, including
427  // the compression type.
429 
430  // Used as a temporary buffer when handling RLE compressed data.
432 };
433 
435 {
438  TransparencyMask = -1, // Alpha
439  Red = 0,
440  Green = 1,
441  Blue = 2,
442 };
443 
445 {
450 };
451 
453 {
455 
456  // Boundaries of layer mask, next 7 fields are used for when ChannelID = -2.
458 
460 
462 
463  // Next 7 fields are used for when ChannelID = -3.
465 
467 
469 };
470 
471 // Information about each layer.
473 {
474  // Image data boundaries. At which pixel does top/left/bottom/right
475  // data start.
477 
478  // Number of channels for the layer.
480 
481  // Channel ID and the length of data and positions for each channel.
483 
484  // The order in which channel data is read is important, so we use this
485  // to keep track of the insertion order into myChannelInfo.
487 
488  // Should always be "8BIM".
490 
491  // Blend mode type, examples include 'norm', 'mul ', 'diss' etc. The
492  // rest can be found on the psd spec.
494 
495  // TODO: 0 = transparent, 255 = opaque. not used at the moment
497 
498  // TODO: 0 = base, 1 = non-base not used at the moment. please see psd spec
500 
501  // TODO: Not used at the moment - for extra info only.
502  // Bit 0 = transparency protected, bit 1 = visible, bit 2 = obsolete,
503  // bit 3 = 1 for Photoshop 5.0 and later, tells if bit 4 has useful info.
504  // Bit 4 = pixel data irrelevant to appearance of document.
506 
507  // Filler here, no variable.
508 
509  // Data length for Layer Mask, Layer Blending Ranges, Layer Name and
510  // some additional info after (I'm not quite sure what that additional
511  // info is.).
513 
515 
516  // Name of the layer.
518 
519  // Next three fields are not official spec, LayerRecord fields. These three
520  // are used for convenience purposes.
521 
522  // Determines if the layer is a folder or not.
524 
525  // Length of layer name WITHOUT any suffixes. For example
526  // LayerName = length 9, LayerName(2) = length 9
528 
529  // Do the RGBA channels have image data? This is used to determine how many
530  // additional mask layers will be created.
532 
533  // Ignoring Layer blending ranges for now.
534 
536  {
540  }
541 };
542 
543 class IMG_API IMG_PSD : public IMG_File
544 {
545 public:
546  IMG_PSD();
547  ~IMG_PSD() override;
548 
550 
551  static void registerFormat();
552 
553  const char *className() const override { return "IMG_FilePSD"; }
554 
555  /// @brief Opens a .psd type file to prepare for reading
556  ///
557  int open() override;
558 
559  /// @brief Reads a single scanline for given row y into the buffer buf.
560  /// A scanline is all the image data required to draw a single row.
561  ///
562  /// @param[in] y
563  /// Row number to be read starting ranging from 0 to
564  /// the images height - 1 (inclusive).
565  ///
566  /// @param[out] buf
567  /// Buffer where the image data needs to be passed into
568  ///
569  int readScanline(int y, void *buf) override;
570 
571  // TODO: TBD whether this will be implemented.
572  int create(const IMG_Stat &stat) override;
573 
574  // TODO: TBD whether this will be implemented.
575  int writeScanline(int scan, const void *buf) override;
576 
577  /// @brief Flushes any open buffers, and releases all allocated memory.
578  /// Gets called by the destructor to do any cleanup.
579  ///
580  int closeFile() override;
581 
582  const UT_Array<IMG_PSDLayerRecords> &getRawLayerRecords();
583 
584  UT_Array<int> getTreeLevelsFromRawLayerRecords();
585 
586 private:
587  /// @brief Read the contents of the header section into the field
588  /// myHeader. Assumes that the file pointer is currently pointing
589  /// to the beginning of the file.
590  ///
591  bool readHeader();
592 
593  /// @brief Reads the header sections of the file for each major section.
594  /// i.e. Color mode data header, image resources header, layer and
595  /// mask info header.
596  ///
597  bool readFileSummary();
598 
599  // TODO: TBD whether this will be implemented.
600  bool writeHeader();
601 
602  // CONVERSIONS / DECOMPRESSION ------------------------------------------
603 
604  /// @brief Converts the header to the appropriate endianness.
605  ///
606  /// @param[in] h
607  /// The header to be converted.
608  ///
609  void convertHeader(IMG_PSDHeader &h);
610 
611  /// @brief Converts a given buffer stream's endianness. This uses
612  /// myHeader.myChannelsCount, myDepth and myStat.getXres() to do
613  /// the calculations which need to be set before calling this.
614  /// This version of the method will be used for any pixel data
615  /// usage.
616  ///
617  /// @param[in] buf
618  /// Stream that needs to be converted.
619  ///
620  /// @param[in] length
621  /// Number of data elements in the buffer to be converted.
622  /// NOTE: This is NOT the number of bytes.
623  ///
624  bool convertStreamEndian(void *buf, int length);
625 
626  /// @brief Converts a given buffer stream's endianness. General version
627  /// which can be used given a stream, the number of elements to
628  /// be converted and the number of bytes for each element.
629  ///
630  /// @param[in] buf
631  /// Stream that needs to be converted.
632  ///
633  /// @param[in] length
634  /// Number of data elements in the buffer to be converted.
635  /// NOTE: This is NOT the number of bytes.
636  ///
637  /// @param[in] bytesPerElement
638  /// How many bytes that each element is.
639  ///
640  bool convertStreamEndian(void *buf, int length, int bytesPerElement);
641 
642  /// @brief Delta decoding, or data differencing method which takes the
643  /// buffer and then decodes it. This is used in the decompression
644  /// of ZIP with prediction-compressed data.
645  /// See the top of this file for details.
646  ///
647  /// @param[in/out] buf
648  /// Buffer that will be decoded as input, then output
649  /// when decoded.
650  ///
651  /// @param[in] width
652  /// Width of the given buffer layer. Needed to know
653  /// how large the data is.
654  ///
655  /// @param[in] height
656  /// Height of the given buffer layer. Needed to know how
657  /// large the data is.
658  ///
659  bool decodeDelta(void *buf, int width, int height = 1);
660 
661  /// @brief Decoding RLE data, based off of IMG_RLEncode::decode, modified
662  /// to follow PackBits version of RLE decompression which can be found at
663  /// http://en.wikipedia.org/wiki/PackBits
664  /// Detailed information at
665  /// http://web.archive.org/web/20080705155158/http://developer.apple.co
666  /// m/technotes/tn/tn1023.html
667  ///
668  /// @param[out] result
669  /// Output, uncompressed stream.
670  ///
671  /// @param[in] length
672  /// The length of the expected uncompressed data.
673  ///
674  /// @param[in] data
675  /// Compressed RLE data input.
676  ///
677  void decodeRLE(char *result, int length, const char *data);
678 
679  /// @brief Given the starting position within the file, the length of the
680  /// zip compressed data and the file we are writing to; this
681  /// functions takes the zip data and deflates it using zlib. This
682  /// is a modified version of inf() from zpipe.c located at
683  /// http://www.zlib.net/zpipe.c
684  ///
685  /// @param[in] zipStartPosition
686  /// Starting position of the zip compressed data in the psd
687  ///
688  /// @param[in] zipDataLength
689  /// The expected length of the zip compressed data.
690  ///
691  /// @param[out] dest
692  /// The destination file of the decompressed zip data.
693  ///
694  int decompressZipChannel(uint64 zipStartPosition, psd_bytes_t zipDataLength,
695  FILE *dest);
696 
697  /// @brief Conversion from straight RGBA data to premultiplied RGBA data.
698  /// Houdini expects data to be passed in premultiplied. For psd
699  /// layer data, the data is stored without the multiplication,
700  /// hence this method needs to be called whenever a layer with
701  /// alpha is parsed. This does not need to be called for the
702  /// composite layer. (More info at the top of this file.)
703  ///
704  /// @param[in/out] data
705  /// Data to be multiplied.
706  ///
707  /// @param[in] size
708  /// How many pixels(NOT bytes) to be converted.
709  ///
710  /// @param[in] do_multiply
711  /// Do we multiply the data, or divide?
712  ///
713  void processAlpha(void *data, int size, bool do_multiply);
714 
715  // SEEKING TO CERTAIN FILE LOCATIONS ------------------------------------
716 
717  /// @brief Makes the file pointer point to the very beginning of the
718  /// color mode data. Assumes header data length already
719  /// initialized.
720  ///
721  bool seekToColorModeData();
722 
723  /// @brief Makes the file pointer point to the very beginning of the
724  /// resource mode data. Assumes header data length and color
725  /// mode length already initialized.
726  ///
727  bool seekToResourceData();
728 
729  /// @brief Makes the file pointer point to the very beginning of the
730  /// layer mask data. Assumes header data length, color mode
731  /// length and image resource data length already initialized.
732  ///
733  bool seekToLayerMaskData();
734 
735  /// @brief Attempts to seek to the layer info block. This will return
736  /// 1 navigation is successful to the first block, 2 if
737  /// the second block and 0 if failed. For info on what these
738  /// "first" and "second" blocks are, read the Layer and Mask
739  /// Information Section summary at the top of this file.
740  ///
741  int seekToLayerInfo();
742 
743  /// @brief Makes the file pointer point to the very beginning of the
744  /// image data. Assumes header data length, color mode length,
745  /// image resource data length amd layer mask data length
746  /// are already initialized. This includes the compression
747  /// type which are the first two bytes, while the method
748  /// seekToCompleteImageData() does not.
749  ///
750  bool seekToCompleteCompositeImageData();
751 
752  /// @brief Assumes header data length, color mode length, image reource
753  /// data length and layer mask data length already initialized.
754  /// Does not include the compression data which are the first
755  /// two bytes in this section. Call seekToCompleteImagedata()
756  /// if compression value is required.
757  ///
758  bool seekToCompositeImageDataOnly();
759 
760  /// @brief Pointer is moved to the first scanline of compressed RLE data.
761  /// This data does not include the length of each scanlines
762  /// length. Refer to the top of IMG_PSD.h for a overview of RLE
763  /// compression and the way its used in .psd
764  ///
765  /// As an example, for a 3px x 4px image with 3 channels and 8 bits
766  /// per channel the first 24 bytes (4 (height) x 3 (channels) x 2
767  /// bytes for each length) of data are the lengths of each scanline.
768  /// This method will skip this length data and move onto the
769  /// compressed data itself.
770  ///
771  bool seekToFirstRLEScanline();
772 
773  /// @brief Within the file stream, reposition the pointer to point at the
774  /// given scanline row and channel for composite data.
775  ///
776  /// @param[in] y
777  /// Row number.
778  ///
779  /// @param[in] channel
780  /// Channel number (R = 0, G = 1, B = 2 etc)
781  ///
782  bool seekToScanLineComposite(int y, int channel);
783 
784  /// @brief Within the relevant file, seek to beginning of the correct
785  /// scanline. Returns an integer of either value 0, 1 or 2.
786  /// If the return is 0, the method failed. If 1, success. If 2,
787  /// the seek failed because there is no image data for the given
788  /// y. However, the scanline itself is valid.
789  ///
790  /// @param[in] y
791  /// Row number.
792  ///
793  /// @param[in] layer
794  /// Layer number.
795  ///
796  /// @param[in] channel
797  /// Channel type. Look at the PSD_ChannelType enum
798  /// for which values to enter.
799  ///
800  int seekToScanLineLayerChannel(int y, int layer_index,
801  PSD_ChannelType channel);
802 
803  /// @brief Within the relevant file, seek to beginning of the correct
804  /// scanline. Returns an integer of either value 0, 1 or 2.
805  /// If the return is 0, the method failed. If 1, success. If 2,
806  /// the seek failed because there is no image data for the given
807  /// y. However, the scanline itself is valid.
808  ///
809  /// @param[in] y
810  /// Row number.
811  ///
812  /// @param[in] layer
813  /// Layer number.
814  ///
815  /// @param[in] channel
816  /// Channel number. Look at the PSD_ChannelType enum
817  /// for which values to enter.
818  ///
819  int seekToScanLineLayerChannel(int y, int layer_index, int channel);
820 
821  /// @brief Seek within the psd file to the beginning given layer/channel's
822  /// image data.
823  ///
824  /// @param[in] layer
825  /// Layer number.
826  ///
827  /// @paramp[in] channel
828  /// Channel type. Look at the PSD_ChannelType enum
829  /// for which values to enter.
830  ///
831  bool seekToChannelImageData(int layer_index = 0,
833 
834  /// @brief Seek within the psd file to the beginning given layer/channel's
835  /// image data.
836  ///
837  /// @param[in] layer
838  /// Layer number.
839  ///
840  /// @paramp[in] channel
841  /// Channel number. Look at the PSD_ChannelType enum
842  /// for which values to enter.
843  ///
844  bool seekToChannelImageData(int layer_index = 0, int channel = 0);
845 
846  // CONVENIENCE METHODS FOR READING CERTAIN DATA ------------------------
847 
848  /// @brief Read the compression type from COMPOSITE data in the
849  /// image data section.
850  /// 0 = Raw image data
851  /// 1 = RLE compression
852  /// 2 = ZIP without prediction (not implemented, unable to find
853  /// psd with ZIP w/o prediction on composite image data.)
854  /// 3 = ZIP with prediction (not implemented, unable to find
855  /// psd with ZIP w/ prediction on composite image data.)
856  ///
857  bool readCompositeCompressionType();
858 
859  /// @brief Navigate to color mode data, read in the data length of
860  /// the color mode section.
861  ///
862  bool readColorModeDataLength();
863 
864  /// @brief Navigate to image resource data, read in the data length of
865  /// the image resource data section.
866  ///
867  bool readImageResourceDataLength();
868 
869  /// @brief Navigate to layer mask data, read in the data length of
870  /// the layer mask section.
871  ///
872  bool readLayerMaskDataLength();
873 
874  /// @brief Simply call all the functions for reading a section's data
875  /// length.
876  ///
877  bool readAllSectionLengths();
878 
879  /// @brief Read the relevant contents of the major Layer and Mask
880  /// information section.
881  ///
882  bool readLayerMaskInfo();
883 
884  /// @brief Read the relevant contents of the Layer Info section, which
885  /// is a subsection of the Layer and Mask information section.
886  ///
887  bool readLayerInfo();
888 
889  /// @brief Reads the Layer Record Data section, which is a subsection
890  /// of the Layer Info section. Assumes file pointer is already
891  /// at the correct location.
892  ///
893  bool readLayerRecordData();
894 
895  /// @brief Reads in the layer/mask adjustment data section for the given
896  /// layer record.
897  ///
898  /// @param[in] record
899  /// The layer record we are reading the layer mask data
900  /// into.
901  ///
902  bool readLayerMaskAdjustmentData(IMG_PSDLayerRecords *record);
903 
904  /// @brief Read the relevant contents of the Global Layer Mask info
905  /// section, which is a subsection of the Layer and Mask
906  /// information section.
907  ///
908  bool readGlobalLayerMaskInfo();
909 
910  /// @brief Read the relevant contents of the Additional Layer info
911  /// section, which is a subsection of the Layer and Mask
912  /// information section.
913  ///
914  bool readAdditionalLayerInfo();
915 
916  /// @brief When loading the file contents, the raw image data will
917  /// be decompressed into myLayerInfo.myLayerImageData(layerNum).
918  /// myImageData[Channel ID]. This method fetches the scanline
919  /// data for height y, and layer layer_index into the buffer.
920  ///
921  /// @param[in] y
922  /// Row number.
923  ///
924  /// @param[out] buf
925  /// Where to output the data, this should be pointing at the
926  /// beginning of layer data already.
927  ///
928  /// @param[in] layer_index
929  /// Layer number. Layer immediately after the composite
930  /// is considered to be layer 0.
931  /// C
932  /// A
933  /// LayerHere <---- Layer 0
934  /// LayerHere2 <---- Layer 1
935  ///
936  /// @param[in] isMaskPlane
937  /// Is the plane we're reading image data into a dedicated
938  /// mask plane?
939  ///
940  bool readLayerScanline(int y, void *buf, int layer_index);
941 
942  /// @brief When loading the file contents, the raw image data will
943  /// be decompressed into myLayerInfo.myLayerImageData(layerNum).
944  /// myImageData[Channel ID]. This method fetches the scanline
945  /// data for height y, and layer layer_index into the buffer.
946  ///
947  /// @param[in] y
948  /// Row number.
949  ///
950  /// @param[out] buf
951  /// Where to output the data, this should be pointing at the
952  /// beginning of layer data already.
953  ///
954  /// @param[in] layer_name
955  /// The name of the layer we're getting the scanline for.
956  ///
957  /// @param[in] isMaskPlane
958  /// Is the plane we're reading image data into a dedicated
959  /// mask plane?
960  ///
961  bool readLayerScanline(int y, void *buf, const UT_StringRef &layer_name);
962 
963  /// @brief We handle dedicated mask layers differently from a regular RGBA
964  /// image plane. So this method will fill the RGB planes with black
965  /// and reask in mask data into buf, for scanline y, given the
966  /// index of the "parent" plane. We also need to know the channel
967  /// type of the mask.
968  ///
969  /// @param[in] y
970  /// Row number.
971  ///
972  /// @param[in] buf
973  /// Where to output the data, this should be pointing at the
974  /// beginning of layer data already.
975  ///
976  /// @param[in] parent_layer_index
977  /// Within the psd, the mask data is stored along with RGBA
978  /// data on a single layer. In Houdini there is no standard
979  /// way to display > 4 channels, so we need to know the
980  /// "parent" layer where we retrieve the mask data from.
981  ///
982  /// @param[in] channel
983  /// Which kind of mask the data is. Should either be
984  /// PSD_ChannelType::UserSuppliedLayerMask or
985  /// PSD_ChannelType::RealUserSuppliedLayerMask
986  ///
987  bool readMaskLayerScanline(int y, void *buf, int parent_layer_index,
988  PSD_ChannelType channel);
989 
990  /// @brief We handle dedicated mask layers differently from a regular RGBA
991  /// image plane. So this method will fill the RGB planes with black
992  /// and reask in mask data into buf, for scanline y, given the
993  /// index of the "parent" plane. We also need to know the channel
994  /// type of the mask.
995  ///
996  /// @param[in] y
997  /// Row number.
998  ///
999  /// @param[in] buf
1000  /// Where to output the data, this should be pointing at the
1001  /// beginning of layer data already.
1002  ///
1003  /// @param[in] parent_layer_name
1004  /// Within the psd, the mask data is stored along with RGBA
1005  /// data on a single layer. In Houdini there is no standard
1006  /// way to display > 4 channels, so we need to know the
1007  /// "parent" layer where we retrieve the mask data from.
1008  ///
1009  /// @param[in] channel
1010  /// Which kind of mask the data is. Should either be
1011  /// PSD_ChannelType::UserSuppliedLayerMask or
1012  /// PSD_ChannelType::RealUserSuppliedLayerMask
1013  ///
1014  bool readMaskLayerScanline(int y, void *buf,
1015  const UT_StringRef &parent_layer_name, PSD_ChannelType channel);
1016 
1017  /// @brief Given a layer, a channel, the row to scan and the buffer;
1018  /// we read in a channel's worth of data for a scanline into
1019  /// buf.
1020  ///
1021  /// @param[in] y
1022  /// row
1023  ///
1024  /// @param[in] buf
1025  /// Where to store the channel data.
1026  ///
1027  /// @param[in] layer_index
1028  /// Which layer are we reading the channel image data for.
1029  ///
1030  /// @param[in] channel
1031  /// Which channel are we reading the data from.
1032  ///
1033  bool readChannelScanline(int y, void *buf, int layer_index,
1034  PSD_ChannelType channel);
1035 
1036  /// @brief Given a layer, a channel, the row to scan and the buffer;
1037  /// we read in a channel's worth of data for a scanline into
1038  /// buf.
1039  ///
1040  /// @param[in] y
1041  /// row
1042  ///
1043  /// @param[in] buf
1044  /// Where to store the channel data.
1045  ///
1046  /// @param[in] layer_name
1047  /// Which layer are we reading the channel image data for.
1048  ///
1049  /// @param[in] channel
1050  /// Which channel are we reading the data from.
1051  ///
1052  bool readChannelScanline(int y, void *buf, const UT_StringRef &layer_name,
1053  PSD_ChannelType channel);
1054 
1055  /// @brief If compatibility mode is enabled, a single scanline's
1056  /// worth of data will be read into the output buffer doing the
1057  /// endian conversions. Assumes that addDefaultPlane() has been
1058  /// called by this point.
1059  ///
1060  /// @param[in] y
1061  /// Row number.
1062  ///
1063  /// @param[out] buf
1064  /// Where the scanline data will be stored.
1065  ///
1066  bool readCompositeScanline(int y, void *buf);
1067 
1068  /// @brief Read a Pascal string, stores the string into str_dest
1069  /// and the length of the string into length_dest.
1070  ///
1071  /// @param[out] str_dest
1072  /// Where to store the string.
1073  ///
1074  /// @param[out] length_dest
1075  /// Where to tstore the length.
1076  ///
1077  bool readPascalString(UT_StringHolder &str_dest, uint8 *length_dest);
1078 
1079  /// @brief Reads in the correct number of bytes for a variable that can
1080  /// either be 4 or 8 bytes long. If the file is in PSD format
1081  /// 4 bytes are read; if it's in PSB format 8 bytes are read.
1082  ///
1083  /// @param[in] buffer
1084  /// Where to read the data into.
1085  ///
1086  bool readPSDBytes(psd_bytes_t *buffer);
1087 
1088  /// @brief Reads in the correct number of bytes for a variable that can
1089  /// either be 2 or 4 bytes long. If the file is in PSD format
1090  /// 2 bytes are read; if it's in PSB format 4 bytes are read.
1091  ///
1092  /// @param[in] buffer
1093  /// Where to read the data into.
1094  ///
1095  bool readPSDHalfBytes(psd_half_bytes_t *buffer);
1096 
1097  /// @brief Converts the endian value for the correct number of bytes.
1098  /// If the file is PSD, 4 bytes are converted; if in PSB format
1099  /// 8 bytes are converted.
1100  ///
1101  /// @param[in] buffer
1102  /// Value to be converted.
1103  ///
1104  void convertEndianPSDBytes(psd_bytes_t *buffer);
1105 
1106  /// @brief Converts the endian value for the correct number of bytes.
1107  /// If the file is PSD, 2 bytes are converted; if in PSB format
1108  /// 4 bytes are converted.
1109  ///
1110  /// @param[in] buffer
1111  /// Value to be converted.
1112  ///
1113  void convertEndianPSDHalfBytes(psd_half_bytes_t *buffer);
1114 
1115  /// @brief Determines if the length data for the given key is either
1116  /// four or eight bytes. If the given key is 4 bytes, true is
1117  /// returned, false otherwise.
1118  ///
1119  /// @param[in] myKey
1120  /// Key to be checked.
1121  ///
1122  bool isKeyLengthFourBytes(const char myKey[4]);
1123 
1124  /// @brief Reads in a rows worth of channel data for the given row, layer
1125  /// and channel into buf. buf should have a size set at this point.
1126  /// A "rows" worth of data is given by whatever the boundary is
1127  /// within the .psd. getChannelBoundaries() will find the row
1128  /// data to be of size right - left. This row can be larger or
1129  /// smaller than the visible image data within Houdini.
1130  ///
1131  /// @param[in] layer
1132  /// Layer number.
1133  ///
1134  /// @param[in] channel
1135  /// Type of channel. Look at PSD_ChannelType enum for
1136  /// appropriate values.
1137  ///
1138  /// @param[im] y
1139  /// Row number.
1140  ///
1141  /// @param[out] buf
1142  /// Buffer where the data for the layer/channel/row is
1143  /// put into.
1144  ///
1145  bool readFullLayerChannelScanline(int layer_index, PSD_ChannelType channel,
1146  int y, UT_Array<uint8> *buf);
1147 
1148  /// @brief readFullLayerChannelScanline's buffer should be passed into this
1149  /// function. This will extract only the image data that is required
1150  /// for Houdini.
1151  ///
1152  /// @param[in] layer
1153  /// Layer number.
1154  ///
1155  /// @param[in] channel
1156  /// Type of channel. Look at PSD_ChannelType enum for
1157  /// appropriate values.
1158  ///
1159  /// @param[in] in
1160  /// Input buffer of a row's worth of data for the given
1161  /// layer/channel. This can be smaller/larger than the
1162  /// image data we need to pass into Houdini.
1163  ///
1164  /// @param[out] out
1165  /// Where to put the data that we extracted.
1166  ///
1167  bool extractVisibleLayerChannelScanline(int layer_index,
1168  PSD_ChannelType channel, const uint8 *in, uint8 *out);
1169 
1170  // CONVENIENCE METHODS --------------------------------------------------
1171 
1172  /// @brief After all channel image data is read, we can call this method
1173  /// to remove any folder layers to ignore them within Houdini.
1174  /// Returns the number of layers removed.
1175  ///
1176  int removeFolderLayers();
1177 
1178  /// @brief Adds the default, composite plane for the full image
1179  ///
1180  bool addDefaultPlane();
1181 
1182  /// @brief Adds a plane corresponding to each layer into Houdini.
1183  /// Returns 0 on fail, 1 on success.
1184  ///
1185  bool addPlanes();
1186 
1187  /// @brief Adds any additional layers with mask channel data into Houdini
1188  /// with a _m suffix.
1189  ///
1190  bool addMaskPlanes();
1191 
1192  /// @brief Checks to see if there's any mask data for the given layer.
1193  ///
1194  /// @param[in] layer_index
1195  /// The layer that we're checking.
1196  ///
1197  bool doesLayerHaveMasks(int layer_index);
1198 
1199  /// @brief Given a desired plane name, we check to see if there are any
1200  /// other layers with the same name. If there aren't any, the
1201  /// given name is returned. If there is a duplicate, we add a
1202  /// suffix with the format (number) where number is an actual
1203  /// number.
1204  ///
1205  /// @param[in] base_name
1206  /// The name to check for.
1207  ///
1208  UT_StringHolder getUniquePlaneName(const UT_StringHolder &base_name);
1209 
1210  /// @brief Given a layer, and an output buffer we return how many mask
1211  /// channels there are and store the contents of which types of
1212  /// channels they are into out.
1213  ///
1214  /// @param[in] layer_index
1215  /// Which layer to check for masks.
1216  ///
1217  /// @param[in] out
1218  /// Where to store what channel types are in the mask.
1219  ///
1220  int getLayerMaskChannels(int layer_index, UT_Array<PSD_ChannelType> *out);
1221 
1222  /// @brief When the file pointer is at the beginning of the additional
1223  /// layer info section, this method can be called to iterate through
1224  /// each additional layer info block to determine the current
1225  /// layer's folder group's type. Returns -1 on fail, 0 if the layer
1226  /// is not a folder, or a value from 1 - 3 if the layer is
1227  /// some sort of folder. If the method fails it will set the file
1228  /// pointer to the end of the additional layer info section. This
1229  /// is dependant on additionalLayerInfoLength being correct.
1230  ///
1231  /// @param[in] additionalLayerInfoLength
1232  /// Length of the additional layer info section, to know
1233  /// the max amount of data we need to parse.
1234  ///
1235  /// @param[in] layer_group_type
1236  /// Where we will put our result in enum form.
1237  ///
1238  int determineLayerGroupType(int additionalLayerInfoLength,
1239  PSD_LayerGroupType *layer_group_type);
1240 
1241  /// @brief Checks to see if the composite/flattened image data exists
1242  /// within the PSD file. The image will only exist if compatibility
1243  /// mode is enabled when the PSD file is saved. Without
1244  /// compatibility mode enabled, the Image Data section will have
1245  /// the whole image be white.
1246  ///
1247  bool doesCompositeImageExist();
1248 
1249  /// @brief Determines if the given scanline is all white. This is used to
1250  /// determine if compatibility mode is off/on for the PSD.
1251  ///
1252  /// @param[in] y
1253  /// The scanline to check.
1254  ///
1255  bool isCompositeScanlineAllWhite(int y);
1256 
1257  /// @brief Initialization to get minimal amount of data we need to know in
1258  /// regards to adding planes. We know how many planes/plane names/
1259  /// bit depth of each plane/number of channels for each plane after
1260  /// this method is called. At the very least, readLayerMaskInfo
1261  /// needs to be called before this is called.
1262  ///
1263  bool initializeAllLayers();
1264 
1265  /// @brief Takes the boundaries of the image data stored in the psd fpr
1266  /// the given channel/layer (from record) and stores them in
1267  /// top, bottom, left, right.
1268  ///
1269  /// @param[in] record
1270  /// The PSD_LayerRecord for the layer.
1271  ///
1272  /// @param[in] channel
1273  /// Type of channel. Look at PSD_ChannelType enum for
1274  /// appropriate values.
1275  ///
1276  /// @param[out] top
1277  /// Top boundary.
1278  ///
1279  /// @param[out] bottom
1280  /// Bottom boundary.
1281  ///
1282  /// @param[out] left
1283  /// Left boundary.
1284  ///
1285  /// @param[out] Right
1286  /// Right boundary.
1287  ///
1288  void getChannelBoundaries(const IMG_PSDLayerRecords *record,
1289  PSD_ChannelType channelID, int *top, int *bottom,
1290  int *left, int *right);
1291 
1292  /// @brief Takes the boundaries of the image data stored in the psd fpr
1293  /// the given channel/layer (from record) and stores them in
1294  /// top, bottom, left, right.
1295  ///
1296  /// @param[in] record
1297  /// The PSD_LayerRecord for the layer.
1298  ///
1299  /// @param[in] channel
1300  /// Type of channel. Look at PSD_ChannelType enum for
1301  /// appropriate values.
1302  ///
1303  /// @param[out] top
1304  /// Top boundary.
1305  ///
1306  /// @param[out] bottom
1307  /// Bottom boundary.
1308  ///
1309  /// @param[out] left
1310  /// Left boundary.
1311  ///
1312  /// @param[out] Right
1313  /// Right boundary.
1314  ///
1315  void getChannelBoundaries(const IMG_PSDLayerRecords *record,
1316  int channel, int *top, int *bottom, int *left, int *right);
1317 
1318  /// @brief Takes the boundaries of the image data stored in the psd fpr
1319  /// the given channel/layer and stores them in top, bottom, left,
1320  /// right.
1321  ///
1322  /// @param[in] record
1323  /// The layer number.
1324  ///
1325  /// @param[in] channel
1326  /// Type of channel. Look at PSD_ChannelType enum for
1327  /// appropriate values.
1328  ///
1329  /// @param[out] top
1330  /// Top boundary.
1331  ///
1332  /// @param[out] bottom
1333  /// Bottom boundary.
1334  ///
1335  /// @param[out] left
1336  /// Left boundary.
1337  ///
1338  /// @param[out] Right
1339  /// Right boundary.
1340  ///
1341  void getChannelBoundaries(int layer_index, int channel, int *top,
1342  int *bottom, int *left, int *right);
1343 
1344  /// @brief Takes the boundaries of the image data stored in the psd fpr
1345  /// the given channel/layer and stores them in top, bottom, left,
1346  /// right.
1347  ///
1348  /// @param[in] record
1349  /// The layer number.
1350  ///
1351  /// @param[in] channel
1352  /// Type of channel. Look at PSD_ChannelType enum for
1353  /// appropriate values.
1354  ///
1355  /// @param[out] top
1356  /// Top boundary.
1357  ///
1358  /// @param[out] bottom
1359  /// Bottom boundary.
1360  ///
1361  /// @param[out] left
1362  /// Left boundary.
1363  ///
1364  /// @param[out] Right
1365  /// Right boundary.
1366  ///
1367  void getChannelBoundaries(int layer_index, PSD_ChannelType channelID,
1368  int *top, int *bottom, int *left, int *right);
1369 
1370  /// @brief Gets an array layer index for myLayerInfo.myLayerRecords
1371  /// given a name. The array is necessary because we need to know
1372  /// the order in which the layers have been read. A layer name
1373  /// cam return a max of 1 index because each layer name is unique.
1374  /// Returns a positive integer on success, -1 on fail.
1375  ///
1376  /// @param[in] layer_name
1377  /// The layer we're looking for.
1378  ///
1379  int getLayerIndexFromName(const UT_StringRef &layer_name);
1380 
1381  // FIELDS ---------------------------------------------------------------
1382 
1383  // Header data for .psd
1384  IMG_PSDHeader myHeader;
1385 
1386  // Layer info for Layer and Mask Information section.
1387  IMG_PSDLayerInfo myLayerInfo;
1388 
1389  // Global layer mask info for Layer and Mask Information section.
1390  IMG_PSDGlobalLayerMaskInfo myGlobalLayerMaskInfo;
1391 
1392  // Additional layer info for Layer and Mask Information section.
1393  IMG_PSDAdditionalLayerInfo myAdditionalLayerInfo;
1394 
1395  // Length of each compressed data for a single channel's scanline row.
1396  // 2 dimensional, 1 dimension for each channel, 2nd dimension for each
1397  // individual group of data. Look at the top of IMG_PSD.h for more
1398  // info on RLE compression. For composite data.
1399  psd_half_bytes_t** myRLELengths;
1400 
1401  // Total length of the compressed data for each channel.
1402  // For composite data.
1403  uint64* myRLEChannelLengths;
1404 
1405  // Length of header data section.
1406  uint32 myHeaderDataLength;
1407 
1408  // Length of color mode data section.
1409  uint32 myColorModeDataLength;
1410 
1411  // Length of image resource data section.
1412  uint32 myImageResourceDataLength;
1413 
1414  // Length of layer mask data section.
1415  psd_bytes_t myLayerMaskDataLength;
1416 
1417  // Starting position for the "Channel Image Data" section.
1418  uint64 myChannelImageDataPosition;
1419 
1420  // Compression mode of composite data.
1421  uint16 myCompressionMethod;
1422 
1423  // Bool to keep track of if the composite/flattened image exists or not.
1424  bool myCompositeImageExists;
1425 
1426  // Temporary files to write image data into, for ZIP compressed channels.
1427  UT_Map<PSD_ChannelType, FILE *> myZipDecompressedChannelFiles;
1428 
1429  // Int is the layer record index. This needs to be in this scope and not
1430  // within the IMG_PSDLayerRecord struct, because we need to know the index
1431  // and IMG_PSDLayerRecords does not know its own index.
1433 };
1434 
1435 #endif
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glcorearb.h:2540
unsigned short uint16
Definition: SYS_Types.h:38
UT_Array< psd_half_bytes_t > myRLELengths
Definition: IMG_FilePSD.h:431
uint32 myHeight
Definition: IMG_FilePSD.h:358
GLint left
Definition: glcorearb.h:2005
uint32 psd_half_bytes_t
Definition: IMG_FilePSD.h:337
GLdouble right
Definition: glad.h:2817
GLuint GLsizei GLsizei * length
Definition: glcorearb.h:795
uint32 myWidth
Definition: IMG_FilePSD.h:361
GLint y
Definition: glcorearb.h:103
**But if you need a result
Definition: thread.h:613
uint64 myImageDataPosition
Definition: IMG_FilePSD.h:428
unsigned long long uint64
Definition: SYS_Types.h:117
PSD_ChannelType
Definition: IMG_FilePSD.h:434
unsigned char uint8
Definition: SYS_Types.h:36
#define IMG_API
Definition: IMG_API.h:10
GLint GLsizei GLsizei height
Definition: glcorearb.h:103
PSD_LayerGroupType
Definition: IMG_FilePSD.h:444
Definition: core.h:760
int open(float queuesize) override
uint16 myChannelsCount
Definition: IMG_FilePSD.h:355
uint8 myBlendSignature[4]
Definition: IMG_FilePSD.h:489
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
psd_bytes_t myLength
Definition: IMG_FilePSD.h:380
uint64 myReserved
Definition: IMG_FilePSD.h:350
IMG_PSDLayerMaskData myLayerMaskData
Definition: IMG_FilePSD.h:514
uint16 myVersion
Definition: IMG_FilePSD.h:347
UT_StringHolder myLayerName
Definition: IMG_FilePSD.h:517
GLint GLint bottom
Definition: glcorearb.h:2005
GLsizeiptr size
Definition: glcorearb.h:664
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2002
short int16
Definition: SYS_Types.h:37
UT_Array< int > myChannelInfoInsertionOrder
Definition: IMG_FilePSD.h:486
PSD_LayerGroupType myLayerGroupType
Definition: IMG_FilePSD.h:523
UT_SortedMap< PSD_ChannelType, IMG_PSDChannelInfo > myChannelInfo
Definition: IMG_FilePSD.h:482
uint16 myColorMode
Definition: IMG_FilePSD.h:369
unsigned int uint32
Definition: SYS_Types.h:40
Contains the details of a specific image file, used by IMG_File. This class contains all the high-lev...
Definition: IMG_Stat.h:38
uint64 psd_bytes_t
Definition: IMG_FilePSD.h:336
GLint GLsizei width
Definition: glcorearb.h:103
GLdouble GLdouble GLdouble top
Definition: glad.h:2817
uint16 myDepth
Definition: IMG_FilePSD.h:364
psd_bytes_t myChannelDataLength
Definition: IMG_FilePSD.h:424
uint16 myCompressionType
Definition: IMG_FilePSD.h:421
Definition: format.h:895
UT_Array< IMG_PSDLayerRecords > myLayerRecords
Definition: IMG_FilePSD.h:386
const char * className() const override
Definition: IMG_FilePSD.h:553