HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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 <UT/UT_Array.h>
332 #include <UT/UT_Map.h>
333 #include <PXL/PXL_Fill.h>
334 
337 
338 struct IMG_PSDLayerRecords;
339 struct IMG_PSDChannelInfo;
340 struct IMG_PSDLayerMaskData;
341 
343 {
344  // Version, should always be 1 for .psd files or version 2 for .psb files.
345  // .psb files will not be supported.
347 
348  // Value should be 0, unless updated by the Adobe spec.
350 
351  // Number of channels in image, including alpha channels. Official
352  // supported range by .psd spec is 1 - 56, for our purposes only 3/4
353  // are currently supported.
355 
356  // Height of the image.
358 
359  // Width of the image.
361 
362  // Number of bits per channel. 8/16 supported but 1 and 32 are not.
364 
365  // Color mode of the file: Valid values are RGB. There are other color
366  // modes which will not be supported as of now, including Bitmap,
367  // Grayscale, Indexed, CMYK, Multichannel, Duotone, and Lab.
369 
370  // Is the file psd or psb format? Not part of the official psd header,
371  // but a convenience bool instead of having to check if myVersion == 1
372  // every time we need this check.
373  bool isPSD;
374 };
375 
377 {
378  // Length of the layer info section in bytes.
380 
381  // Total number of layers in the psd.
383 
384  // Information for each individual layer.
386 };
387 
388 // Not sure if the rest of the global layer mask info data is needed
389 // currently.
391 {
392  // The length of this section in bytes.
394 };
395 
397 {
398  // Signature which needs to be either 8BIM or 8B64
399  char mySignature[4];
400 
401  // 4 character key code such as LMsk, Lr16 etc. Rest can
402  // be found in psd spec.
403  char myKey[4];
404 
405  // Length of the data.
407 
408  // Data here. (Not included yet, if ever)
409 };
410 
411 // Channel information which corresponds to the third section within
412 // the Layer Records section.
414 {
415  // ID 0 = Red, 1 = Green, 2 = Blue, etc. PSD_ChannelType has the various
416  // types.
418 
419  // Compression type, 0 = RAW, 1 = RLE, 3 = ZIP with prediction.
421 
422  // The length of the image data for the channel ID.
424 
425  // Position within the file that this channel's image data starts, including
426  // the compression type.
428 
429  // Used as a temporary buffer when handling RLE compressed data.
431 };
432 
434 {
437  TransparencyMask = -1, // Alpha
438  Red = 0,
439  Green = 1,
440  Blue = 2,
441 };
442 
444 {
449 };
450 
452 {
454 
455  // Boundaries of layer mask, next 7 fields are used for when ChannelID = -2.
457 
459 
461 
462  // Next 7 fields are used for when ChannelID = -3.
464 
466 
468 };
469 
470 // Information about each layer.
472 {
473  // Image data boundaries. At which pixel does top/left/bottom/right
474  // data start.
476 
477  // Number of channels for the layer.
479 
480  // Channel ID and the length of data and positions for each channel.
482 
483  // The order in which channel data is read is important, so we use this
484  // to keep track of the insertion order into myChannelInfo.
486 
487  // Should always be "8BIM".
489 
490  // Blend mode type, examples include 'norm', 'mul ', 'diss' etc. The
491  // rest can be found on the psd spec.
493 
494  // TODO: 0 = transparent, 255 = opaque. not used at the moment
496 
497  // TODO: 0 = base, 1 = non-base not used at the moment. please see psd spec
499 
500  // TODO: Not used at the moment - for extra info only.
501  // Bit 0 = transparency protected, bit 1 = visible, bit 2 = obsolete,
502  // bit 3 = 1 for Photoshop 5.0 and later, tells if bit 4 has useful info.
503  // Bit 4 = pixel data irrelevant to appearance of document.
505 
506  // Filler here, no variable.
507 
508  // Data length for Layer Mask, Layer Blending Ranges, Layer Name and
509  // some additional info after (I'm not quite sure what that additional
510  // info is.).
512 
514 
515  // Name of the layer.
517 
518  // Next three fields are not official spec, LayerRecord fields. These three
519  // are used for convenience purposes.
520 
521  // Determines if the layer is a folder or not.
523 
524  // Length of layer name WITHOUT any suffixes. For example
525  // LayerName = length 9, LayerName(2) = length 9
527 
528  // Do the RGBA channels have image data? This is used to determine how many
529  // additional mask layers will be created.
531 
532  // Ignoring Layer blending ranges for now.
533 
535  {
539  }
540 };
541 
542 class IMG_API IMG_PSD : public IMG_File
543 {
544 public:
545  IMG_PSD();
546  ~IMG_PSD();
547 
548  static void registerFormat();
549 
550  virtual const char *className() const { return "IMG_FilePSD"; }
551 
552  /// @brief Opens a .psd type file to prepare for reading
553  ///
554  virtual int open();
555 
556  /// @brief Reads a single scanline for given row y into the buffer buf.
557  /// A scanline is all the image data required to draw a single row.
558  ///
559  /// @param[in] y
560  /// Row number to be read starting ranging from 0 to
561  /// the images height - 1 (inclusive).
562  ///
563  /// @param[out] buf
564  /// Buffer where the image data needs to be passed into
565  ///
566  virtual int readScanline(int y, void *buf);
567 
568  // TODO: TBD whether this will be implemented.
569  virtual int create(const IMG_Stat &stat);
570 
571  // TODO: TBD whether this will be implemented.
572  virtual int writeScanline(int scan, const void *buf);
573 
574  /// @brief Flushes any open buffers, and releases all allocated memory.
575  /// Gets called by the destructor to do any cleanup.
576  ///
577  virtual int closeFile();
578 
579  const UT_Array<IMG_PSDLayerRecords> &getRawLayerRecords();
580 
581  UT_Array<int> getTreeLevelsFromRawLayerRecords();
582 
583 private:
584  /// @brief Read the contents of the header section into the field
585  /// myHeader. Assumes that the file pointer is currently pointing
586  /// to the beginning of the file.
587  ///
588  bool readHeader();
589 
590  /// @brief Reads the header sections of the file for each major section.
591  /// i.e. Color mode data header, image resources header, layer and
592  /// mask info header.
593  ///
594  bool readFileSummary();
595 
596  // TODO: TBD whether this will be implemented.
597  bool writeHeader();
598 
599  // CONVERSIONS / DECOMPRESSION ------------------------------------------
600 
601  /// @brief Converts the header to the appropriate endianness.
602  ///
603  /// @param[in] h
604  /// The header to be converted.
605  ///
606  void convertHeader(IMG_PSDHeader &h);
607 
608  /// @brief Converts a given buffer stream's endianness. This uses
609  /// myHeader.myChannelsCount, myDepth and myStat.getXres() to do
610  /// the calculations which need to be set before calling this.
611  /// This version of the method will be used for any pixel data
612  /// usage.
613  ///
614  /// @param[in] buf
615  /// Stream that needs to be converted.
616  ///
617  /// @param[in] length
618  /// Number of data elements in the buffer to be converted.
619  /// NOTE: This is NOT the number of bytes.
620  ///
621  bool convertStreamEndian(void *buf, int length);
622 
623  /// @brief Converts a given buffer stream's endianness. General version
624  /// which can be used given a stream, the number of elements to
625  /// be converted and the number of bytes for each element.
626  ///
627  /// @param[in] buf
628  /// Stream that needs to be converted.
629  ///
630  /// @param[in] length
631  /// Number of data elements in the buffer to be converted.
632  /// NOTE: This is NOT the number of bytes.
633  ///
634  /// @param[in] bytesPerElement
635  /// How many bytes that each element is.
636  ///
637  bool convertStreamEndian(void *buf, int length, int bytesPerElement);
638 
639  /// @brief Delta decoding, or data differencing method which takes the
640  /// buffer and then decodes it. This is used in the decompression
641  /// of ZIP with prediction-compressed data.
642  /// See the top of this file for details.
643  ///
644  /// @param[in/out] buf
645  /// Buffer that will be decoded as input, then output
646  /// when decoded.
647  ///
648  /// @param[in] width
649  /// Width of the given buffer layer. Needed to know
650  /// how large the data is.
651  ///
652  /// @param[in] height
653  /// Height of the given buffer layer. Needed to know how
654  /// large the data is.
655  ///
656  bool decodeDelta(void *buf, int width, int height = 1);
657 
658  /// @brief Decoding RLE data, based off of IMG_RLEncode::decode, modified
659  /// to follow PackBits version of RLE decompression which can be found at
660  /// http://en.wikipedia.org/wiki/PackBits
661  /// Detailed information at
662  /// http://web.archive.org/web/20080705155158/http://developer.apple.co
663  /// m/technotes/tn/tn1023.html
664  ///
665  /// @param[out] result
666  /// Output, uncompressed stream.
667  ///
668  /// @param[in] length
669  /// The length of the expected uncompressed data.
670  ///
671  /// @param[in] data
672  /// Compressed RLE data input.
673  ///
674  void decodeRLE(char *result, int length, const char *data);
675 
676  /// @brief Given the starting position within the file, the length of the
677  /// zip compressed data and the file we are writing to; this
678  /// functions takes the zip data and deflates it using zlib. This
679  /// is a modified version of inf() from zpipe.c located at
680  /// http://www.zlib.net/zpipe.c
681  ///
682  /// @param[in] zipStartPosition
683  /// Starting position of the zip compressed data in the psd
684  ///
685  /// @param[in] zipDataLength
686  /// The expected length of the zip compressed data.
687  ///
688  /// @param[out] dest
689  /// The destination file of the decompressed zip data.
690  ///
691  int decompressZipChannel(uint64 zipStartPosition, psd_bytes_t zipDataLength,
692  FILE *dest);
693 
694  /// @brief Conversion from straight RGBA data to premultiplied RGBA data.
695  /// Houdini expects data to be passed in premultiplied. For psd
696  /// layer data, the data is stored without the multiplication,
697  /// hence this method needs to be called whenever a layer with
698  /// alpha is parsed. This does not need to be called for the
699  /// composite layer. (More info at the top of this file.)
700  ///
701  /// @param[in/out] data
702  /// Data to be multiplied.
703  ///
704  /// @param[in] size
705  /// How many pixels(NOT bytes) to be converted.
706  ///
707  /// @param[in] do_multiply
708  /// Do we multiply the data, or divide?
709  ///
710  void processAlpha(void *data, int size, bool do_multiply);
711 
712  // SEEKING TO CERTAIN FILE LOCATIONS ------------------------------------
713 
714  /// @brief Makes the file pointer point to the very beginning of the
715  /// color mode data. Assumes header data length already
716  /// initialized.
717  ///
718  bool seekToColorModeData();
719 
720  /// @brief Makes the file pointer point to the very beginning of the
721  /// resource mode data. Assumes header data length and color
722  /// mode length already initialized.
723  ///
724  bool seekToResourceData();
725 
726  /// @brief Makes the file pointer point to the very beginning of the
727  /// layer mask data. Assumes header data length, color mode
728  /// length and image resource data length already initialized.
729  ///
730  bool seekToLayerMaskData();
731 
732  /// @brief Attempts to seek to the layer info block. This will return
733  /// 1 navigation is successful to the first block, 2 if
734  /// the second block and 0 if failed. For info on what these
735  /// "first" and "second" blocks are, read the Layer and Mask
736  /// Information Section summary at the top of this file.
737  ///
738  int seekToLayerInfo();
739 
740  /// @brief Makes the file pointer point to the very beginning of the
741  /// image data. Assumes header data length, color mode length,
742  /// image resource data length amd layer mask data length
743  /// are already initialized. This includes the compression
744  /// type which are the first two bytes, while the method
745  /// seekToCompleteImageData() does not.
746  ///
747  bool seekToCompleteCompositeImageData();
748 
749  /// @brief Assumes header data length, color mode length, image reource
750  /// data length and layer mask data length already initialized.
751  /// Does not include the compression data which are the first
752  /// two bytes in this section. Call seekToCompleteImagedata()
753  /// if compression value is required.
754  ///
755  bool seekToCompositeImageDataOnly();
756 
757  /// @brief Pointer is moved to the first scanline of compressed RLE data.
758  /// This data does not include the length of each scanlines
759  /// length. Refer to the top of IMG_PSD.h for a overview of RLE
760  /// compression and the way its used in .psd
761  ///
762  /// As an example, for a 3px x 4px image with 3 channels and 8 bits
763  /// per channel the first 24 bytes (4 (height) x 3 (channels) x 2
764  /// bytes for each length) of data are the lengths of each scanline.
765  /// This method will skip this length data and move onto the
766  /// compressed data itself.
767  ///
768  bool seekToFirstRLEScanline();
769 
770  /// @brief Within the file stream, reposition the pointer to point at the
771  /// given scanline row and channel for composite data.
772  ///
773  /// @param[in] y
774  /// Row number.
775  ///
776  /// @param[in] channel
777  /// Channel number (R = 0, G = 1, B = 2 etc)
778  ///
779  bool seekToScanLineComposite(int y, int channel);
780 
781  /// @brief Within the relevant file, seek to beginning of the correct
782  /// scanline. Returns an integer of either value 0, 1 or 2.
783  /// If the return is 0, the method failed. If 1, success. If 2,
784  /// the seek failed because there is no image data for the given
785  /// y. However, the scanline itself is valid.
786  ///
787  /// @param[in] y
788  /// Row number.
789  ///
790  /// @param[in] layer
791  /// Layer number.
792  ///
793  /// @param[in] channel
794  /// Channel type. Look at the PSD_ChannelType enum
795  /// for which values to enter.
796  ///
797  int seekToScanLineLayerChannel(int y, int layer_index,
798  PSD_ChannelType channel);
799 
800  /// @brief Within the relevant file, seek to beginning of the correct
801  /// scanline. Returns an integer of either value 0, 1 or 2.
802  /// If the return is 0, the method failed. If 1, success. If 2,
803  /// the seek failed because there is no image data for the given
804  /// y. However, the scanline itself is valid.
805  ///
806  /// @param[in] y
807  /// Row number.
808  ///
809  /// @param[in] layer
810  /// Layer number.
811  ///
812  /// @param[in] channel
813  /// Channel number. Look at the PSD_ChannelType enum
814  /// for which values to enter.
815  ///
816  int seekToScanLineLayerChannel(int y, int layer_index, int channel);
817 
818  /// @brief Seek within the psd file to the beginning given layer/channel's
819  /// image data.
820  ///
821  /// @param[in] layer
822  /// Layer number.
823  ///
824  /// @paramp[in] channel
825  /// Channel type. Look at the PSD_ChannelType enum
826  /// for which values to enter.
827  ///
828  bool seekToChannelImageData(int layer_index = 0,
830 
831  /// @brief Seek within the psd file to the beginning given layer/channel's
832  /// image data.
833  ///
834  /// @param[in] layer
835  /// Layer number.
836  ///
837  /// @paramp[in] channel
838  /// Channel number. Look at the PSD_ChannelType enum
839  /// for which values to enter.
840  ///
841  bool seekToChannelImageData(int layer_index = 0, int channel = 0);
842 
843  // CONVENIENCE METHODS FOR READING CERTAIN DATA ------------------------
844 
845  /// @brief Read the compression type from COMPOSITE data in the
846  /// image data section.
847  /// 0 = Raw image data
848  /// 1 = RLE compression
849  /// 2 = ZIP without prediction (not implemented, unable to find
850  /// psd with ZIP w/o prediction on composite image data.)
851  /// 3 = ZIP with prediction (not implemented, unable to find
852  /// psd with ZIP w/ prediction on composite image data.)
853  ///
854  bool readCompositeCompressionType();
855 
856  /// @brief Navigate to color mode data, read in the data length of
857  /// the color mode section.
858  ///
859  bool readColorModeDataLength();
860 
861  /// @brief Navigate to image resource data, read in the data length of
862  /// the image resource data section.
863  ///
864  bool readImageResourceDataLength();
865 
866  /// @brief Navigate to layer mask data, read in the data length of
867  /// the layer mask section.
868  ///
869  bool readLayerMaskDataLength();
870 
871  /// @brief Simply call all the functions for reading a section's data
872  /// length.
873  ///
874  bool readAllSectionLengths();
875 
876  /// @brief Read the relevant contents of the major Layer and Mask
877  /// information section.
878  ///
879  bool readLayerMaskInfo();
880 
881  /// @brief Read the relevant contents of the Layer Info section, which
882  /// is a subsection of the Layer and Mask information section.
883  ///
884  bool readLayerInfo();
885 
886  /// @brief Reads the Layer Record Data section, which is a subsection
887  /// of the Layer Info section. Assumes file pointer is already
888  /// at the correct location.
889  ///
890  bool readLayerRecordData();
891 
892  /// @brief Reads in the layer/mask adjustment data section for the given
893  /// layer record.
894  ///
895  /// @param[in] record
896  /// The layer record we are reading the layer mask data
897  /// into.
898  ///
899  bool readLayerMaskAdjustmentData(IMG_PSDLayerRecords *record);
900 
901  /// @brief Read the relevant contents of the Global Layer Mask info
902  /// section, which is a subsection of the Layer and Mask
903  /// information section.
904  ///
905  bool readGlobalLayerMaskInfo();
906 
907  /// @brief Read the relevant contents of the Additional Layer info
908  /// section, which is a subsection of the Layer and Mask
909  /// information section.
910  ///
911  bool readAdditionalLayerInfo();
912 
913  /// @brief When loading the file contents, the raw image data will
914  /// be decompressed into myLayerInfo.myLayerImageData(layerNum).
915  /// myImageData[Channel ID]. This method fetches the scanline
916  /// data for height y, and layer layer_index into the buffer.
917  ///
918  /// @param[in] y
919  /// Row number.
920  ///
921  /// @param[out] buf
922  /// Where to output the data, this should be pointing at the
923  /// beginning of layer data already.
924  ///
925  /// @param[in] layer_index
926  /// Layer number. Layer immediately after the composite
927  /// is considered to be layer 0.
928  /// C
929  /// A
930  /// LayerHere <---- Layer 0
931  /// LayerHere2 <---- Layer 1
932  ///
933  /// @param[in] isMaskPlane
934  /// Is the plane we're reading image data into a dedicated
935  /// mask plane?
936  ///
937  bool readLayerScanline(int y, void *buf, int layer_index);
938 
939  /// @brief When loading the file contents, the raw image data will
940  /// be decompressed into myLayerInfo.myLayerImageData(layerNum).
941  /// myImageData[Channel ID]. This method fetches the scanline
942  /// data for height y, and layer layer_index into the buffer.
943  ///
944  /// @param[in] y
945  /// Row number.
946  ///
947  /// @param[out] buf
948  /// Where to output the data, this should be pointing at the
949  /// beginning of layer data already.
950  ///
951  /// @param[in] layer_name
952  /// The name of the layer we're getting the scanline for.
953  ///
954  /// @param[in] isMaskPlane
955  /// Is the plane we're reading image data into a dedicated
956  /// mask plane?
957  ///
958  bool readLayerScanline(int y, void *buf, const UT_String layer_name);
959 
960  /// @brief We handle dedicated mask layers differently from a regular RGBA
961  /// image plane. So this method will fill the RGB planes with black
962  /// and reask in mask data into buf, for scanline y, given the
963  /// index of the "parent" plane. We also need to know the channel
964  /// type of the mask.
965  ///
966  /// @param[in] y
967  /// Row number.
968  ///
969  /// @param[in] buf
970  /// Where to output the data, this should be pointing at the
971  /// beginning of layer data already.
972  ///
973  /// @param[in] parent_layer_index
974  /// Within the psd, the mask data is stored along with RGBA
975  /// data on a single layer. In Houdini there is no standard
976  /// way to display > 4 channels, so we need to know the
977  /// "parent" layer where we retrieve the mask data from.
978  ///
979  /// @param[in] channel
980  /// Which kind of mask the data is. Should either be
981  /// PSD_ChannelType::UserSuppliedLayerMask or
982  /// PSD_ChannelType::RealUserSuppliedLayerMask
983  ///
984  bool readMaskLayerScanline(int y, void *buf, int parent_layer_index,
985  PSD_ChannelType channel);
986 
987  /// @brief We handle dedicated mask layers differently from a regular RGBA
988  /// image plane. So this method will fill the RGB planes with black
989  /// and reask in mask data into buf, for scanline y, given the
990  /// index of the "parent" plane. We also need to know the channel
991  /// type of the mask.
992  ///
993  /// @param[in] y
994  /// Row number.
995  ///
996  /// @param[in] buf
997  /// Where to output the data, this should be pointing at the
998  /// beginning of layer data already.
999  ///
1000  /// @param[in] parent_layer_name
1001  /// Within the psd, the mask data is stored along with RGBA
1002  /// data on a single layer. In Houdini there is no standard
1003  /// way to display > 4 channels, so we need to know the
1004  /// "parent" layer where we retrieve the mask data from.
1005  ///
1006  /// @param[in] channel
1007  /// Which kind of mask the data is. Should either be
1008  /// PSD_ChannelType::UserSuppliedLayerMask or
1009  /// PSD_ChannelType::RealUserSuppliedLayerMask
1010  ///
1011  bool readMaskLayerScanline(int y, void *buf,
1012  const UT_String parent_layer_name, PSD_ChannelType channel);
1013 
1014  /// @brief Given a layer, a channel, the row to scan and the buffer;
1015  /// we read in a channel's worth of data for a scanline into
1016  /// buf.
1017  ///
1018  /// @param[in] y
1019  /// row
1020  ///
1021  /// @param[in] buf
1022  /// Where to store the channel data.
1023  ///
1024  /// @param[in] layer_index
1025  /// Which layer are we reading the channel image data for.
1026  ///
1027  /// @param[in] channel
1028  /// Which channel are we reading the data from.
1029  ///
1030  bool readChannelScanline(int y, void *buf, int layer_index,
1031  PSD_ChannelType channel);
1032 
1033  /// @brief Given a layer, a channel, the row to scan and the buffer;
1034  /// we read in a channel's worth of data for a scanline into
1035  /// buf.
1036  ///
1037  /// @param[in] y
1038  /// row
1039  ///
1040  /// @param[in] buf
1041  /// Where to store the channel data.
1042  ///
1043  /// @param[in] layer_name
1044  /// Which layer are we reading the channel image data for.
1045  ///
1046  /// @param[in] channel
1047  /// Which channel are we reading the data from.
1048  ///
1049  bool readChannelScanline(int y, void *buf, const UT_String layer_name,
1050  PSD_ChannelType channel);
1051 
1052  /// @brief If compatibility mode is enabled, a single scanline's
1053  /// worth of data will be read into the output buffer doing the
1054  /// endian conversions. Assumes that addDefaultPlane() has been
1055  /// called by this point.
1056  ///
1057  /// @param[in] y
1058  /// Row number.
1059  ///
1060  /// @param[out] buf
1061  /// Where the scanline data will be stored.
1062  ///
1063  bool readCompositeScanline(int y, void *buf);
1064 
1065  /// @brief Read a Pascal string, stores the string into str_dest
1066  /// and the length of the string into length_dest.
1067  ///
1068  /// @param[out] str_dest
1069  /// Where to store the string.
1070  ///
1071  /// @param[out] length_dest
1072  /// Where to tstore the length.
1073  ///
1074  bool readPascalString(UT_String *str_dest, uint8 *length_dest);
1075 
1076  /// @brief Reads in the correct number of bytes for a variable that can
1077  /// either be 4 or 8 bytes long. If the file is in PSD format
1078  /// 4 bytes are read; if it's in PSB format 8 bytes are read.
1079  ///
1080  /// @param[in] buffer
1081  /// Where to read the data into.
1082  ///
1083  bool readPSDBytes(psd_bytes_t *buffer);
1084 
1085  /// @brief Reads in the correct number of bytes for a variable that can
1086  /// either be 2 or 4 bytes long. If the file is in PSD format
1087  /// 2 bytes are read; if it's in PSB format 4 bytes are read.
1088  ///
1089  /// @param[in] buffer
1090  /// Where to read the data into.
1091  ///
1092  bool readPSDHalfBytes(psd_half_bytes_t *buffer);
1093 
1094  /// @brief Converts the endian value for the correct number of bytes.
1095  /// If the file is PSD, 4 bytes are converted; if in PSB format
1096  /// 8 bytes are converted.
1097  ///
1098  /// @param[in] buffer
1099  /// Value to be converted.
1100  ///
1101  void convertEndianPSDBytes(psd_bytes_t *buffer);
1102 
1103  /// @brief Converts the endian value for the correct number of bytes.
1104  /// If the file is PSD, 2 bytes are converted; if in PSB format
1105  /// 4 bytes are converted.
1106  ///
1107  /// @param[in] buffer
1108  /// Value to be converted.
1109  ///
1110  void convertEndianPSDHalfBytes(psd_half_bytes_t *buffer);
1111 
1112  /// @brief Determines if the length data for the given key is either
1113  /// four or eight bytes. If the given key is 4 bytes, true is
1114  /// returned, false otherwise.
1115  ///
1116  /// @param[in] myKey
1117  /// Key to be checked.
1118  ///
1119  bool isKeyLengthFourBytes(const char myKey[4]);
1120 
1121  /// @brief Reads in a rows worth of channel data for the given row, layer
1122  /// and channel into buf. buf should have a size set at this point.
1123  /// A "rows" worth of data is given by whatever the boundary is
1124  /// within the .psd. getChannelBoundaries() will find the row
1125  /// data to be of size right - left. This row can be larger or
1126  /// smaller than the visible image data within Houdini.
1127  ///
1128  /// @param[in] layer
1129  /// Layer number.
1130  ///
1131  /// @param[in] channel
1132  /// Type of channel. Look at PSD_ChannelType enum for
1133  /// appropriate values.
1134  ///
1135  /// @param[im] y
1136  /// Row number.
1137  ///
1138  /// @param[out] buf
1139  /// Buffer where the data for the layer/channel/row is
1140  /// put into.
1141  ///
1142  bool readFullLayerChannelScanline(int layer_index, PSD_ChannelType channel,
1143  int y, UT_Array<uint8> *buf);
1144 
1145  /// @brief readFullLayerChannelScanline's buffer should be passed into this
1146  /// function. This will extract only the image data that is required
1147  /// for Houdini.
1148  ///
1149  /// @param[in] layer
1150  /// Layer number.
1151  ///
1152  /// @param[in] channel
1153  /// Type of channel. Look at PSD_ChannelType enum for
1154  /// appropriate values.
1155  ///
1156  /// @param[in] in
1157  /// Input buffer of a row's worth of data for the given
1158  /// layer/channel. This can be smaller/larger than the
1159  /// image data we need to pass into Houdini.
1160  ///
1161  /// @param[out] out
1162  /// Where to put the data that we extracted.
1163  ///
1164  bool extractVisibleLayerChannelScanline(int layer_index,
1165  PSD_ChannelType channel, const uint8 *in, uint8 *out);
1166 
1167  // CONVENIENCE METHODS --------------------------------------------------
1168 
1169  /// @brief After all channel image data is read, we can call this method
1170  /// to remove any folder layers to ignore them within Houdini.
1171  /// Returns the number of layers removed.
1172  ///
1173  int removeFolderLayers();
1174 
1175  /// @brief Adds the default, composite plane for the full image
1176  ///
1177  bool addDefaultPlane();
1178 
1179  /// @brief Adds a plane corresponding to each layer into Houdini.
1180  /// Returns 0 on fail, 1 on success.
1181  ///
1182  bool addPlanes();
1183 
1184  /// @brief Adds any additional layers with mask channel data into Houdini
1185  /// with a _m suffix.
1186  ///
1187  bool addMaskPlanes();
1188 
1189  /// @brief Checks to see if there's any mask data for the given layer.
1190  ///
1191  /// @param[in] layer_index
1192  /// The layer that we're checking.
1193  ///
1194  bool doesLayerHaveMasks(int layer_index);
1195 
1196  /// @brief Given a desired plane name, we check to see if there are any
1197  /// other layers with the same name. If there aren't any, the
1198  /// given name is returned. If there is a duplicate, we add a
1199  /// suffix with the format (number) where number is an actual
1200  /// number.
1201  ///
1202  /// @param[in] base_name
1203  /// The name to check for.
1204  ///
1205  UT_String getUniquePlaneName(const UT_String base_name);
1206 
1207  /// @brief Given a layer, and an output buffer we return how many mask
1208  /// channels there are and store the contents of which types of
1209  /// channels they are into out.
1210  ///
1211  /// @param[in] layer_index
1212  /// Which layer to check for masks.
1213  ///
1214  /// @param[in] out
1215  /// Where to store what channel types are in the mask.
1216  ///
1217  int getLayerMaskChannels(int layer_index, UT_Array<PSD_ChannelType> *out);
1218 
1219  /// @brief When the file pointer is at the beginning of the additional
1220  /// layer info section, this method can be called to iterate through
1221  /// each additional layer info block to determine the current
1222  /// layer's folder group's type. Returns -1 on fail, 0 if the layer
1223  /// is not a folder, or a value from 1 - 3 if the layer is
1224  /// some sort of folder. If the method fails it will set the file
1225  /// pointer to the end of the additional layer info section. This
1226  /// is dependant on additionalLayerInfoLength being correct.
1227  ///
1228  /// @param[in] additionalLayerInfoLength
1229  /// Length of the additional layer info section, to know
1230  /// the max amount of data we need to parse.
1231  ///
1232  /// @param[in] layer_group_type
1233  /// Where we will put our result in enum form.
1234  ///
1235  int determineLayerGroupType(int additionalLayerInfoLength,
1236  PSD_LayerGroupType *layer_group_type);
1237 
1238  /// @brief Checks to see if the composite/flattened image data exists
1239  /// within the PSD file. The image will only exist if compatibility
1240  /// mode is enabled when the PSD file is saved. Without
1241  /// compatibility mode enabled, the Image Data section will have
1242  /// the whole image be white.
1243  ///
1244  bool doesCompositeImageExist();
1245 
1246  /// @brief Determines if the given scanline is all white. This is used to
1247  /// determine if compatibility mode is off/on for the PSD.
1248  ///
1249  /// @param[in] y
1250  /// The scanline to check.
1251  ///
1252  bool isCompositeScanlineAllWhite(int y);
1253 
1254  /// @brief Initialization to get minimal amount of data we need to know in
1255  /// regards to adding planes. We know how many planes/plane names/
1256  /// bit depth of each plane/number of channels for each plane after
1257  /// this method is called. At the very least, readLayerMaskInfo
1258  /// needs to be called before this is called.
1259  ///
1260  bool initializeAllLayers();
1261 
1262  /// @brief Takes the boundaries of the image data stored in the psd fpr
1263  /// the given channel/layer (from record) and stores them in
1264  /// top, bottom, left, right.
1265  ///
1266  /// @param[in] record
1267  /// The PSD_LayerRecord for the layer.
1268  ///
1269  /// @param[in] channel
1270  /// Type of channel. Look at PSD_ChannelType enum for
1271  /// appropriate values.
1272  ///
1273  /// @param[out] top
1274  /// Top boundary.
1275  ///
1276  /// @param[out] bottom
1277  /// Bottom boundary.
1278  ///
1279  /// @param[out] left
1280  /// Left boundary.
1281  ///
1282  /// @param[out] Right
1283  /// Right boundary.
1284  ///
1285  void getChannelBoundaries(const IMG_PSDLayerRecords *record,
1286  PSD_ChannelType channelID, int *top, int *bottom,
1287  int *left, int *right);
1288 
1289  /// @brief Takes the boundaries of the image data stored in the psd fpr
1290  /// the given channel/layer (from record) and stores them in
1291  /// top, bottom, left, right.
1292  ///
1293  /// @param[in] record
1294  /// The PSD_LayerRecord for the layer.
1295  ///
1296  /// @param[in] channel
1297  /// Type of channel. Look at PSD_ChannelType enum for
1298  /// appropriate values.
1299  ///
1300  /// @param[out] top
1301  /// Top boundary.
1302  ///
1303  /// @param[out] bottom
1304  /// Bottom boundary.
1305  ///
1306  /// @param[out] left
1307  /// Left boundary.
1308  ///
1309  /// @param[out] Right
1310  /// Right boundary.
1311  ///
1312  void getChannelBoundaries(const IMG_PSDLayerRecords *record,
1313  int channel, int *top, int *bottom, int *left, int *right);
1314 
1315  /// @brief Takes the boundaries of the image data stored in the psd fpr
1316  /// the given channel/layer and stores them in top, bottom, left,
1317  /// right.
1318  ///
1319  /// @param[in] record
1320  /// The layer number.
1321  ///
1322  /// @param[in] channel
1323  /// Type of channel. Look at PSD_ChannelType enum for
1324  /// appropriate values.
1325  ///
1326  /// @param[out] top
1327  /// Top boundary.
1328  ///
1329  /// @param[out] bottom
1330  /// Bottom boundary.
1331  ///
1332  /// @param[out] left
1333  /// Left boundary.
1334  ///
1335  /// @param[out] Right
1336  /// Right boundary.
1337  ///
1338  void getChannelBoundaries(int layer_index, int channel, int *top,
1339  int *bottom, int *left, int *right);
1340 
1341  /// @brief Takes the boundaries of the image data stored in the psd fpr
1342  /// the given channel/layer and stores them in top, bottom, left,
1343  /// right.
1344  ///
1345  /// @param[in] record
1346  /// The layer number.
1347  ///
1348  /// @param[in] channel
1349  /// Type of channel. Look at PSD_ChannelType enum for
1350  /// appropriate values.
1351  ///
1352  /// @param[out] top
1353  /// Top boundary.
1354  ///
1355  /// @param[out] bottom
1356  /// Bottom boundary.
1357  ///
1358  /// @param[out] left
1359  /// Left boundary.
1360  ///
1361  /// @param[out] Right
1362  /// Right boundary.
1363  ///
1364  void getChannelBoundaries(int layer_index, PSD_ChannelType channelID,
1365  int *top, int *bottom, int *left, int *right);
1366 
1367  /// @brief Gets an array layer index for myLayerInfo.myLayerRecords
1368  /// given a name. The array is necessary because we need to know
1369  /// the order in which the layers have been read. A layer name
1370  /// cam return a max of 1 index because each layer name is unique.
1371  /// Returns a positive integer on success, -1 on fail.
1372  ///
1373  /// @param[in] layer_name
1374  /// The layer we're looking for.
1375  ///
1376  int getLayerIndexFromName(const UT_String layer_name);
1377 
1378  // FIELDS ---------------------------------------------------------------
1379 
1380  // Header data for .psd
1381  IMG_PSDHeader myHeader;
1382 
1383  // Layer info for Layer and Mask Information section.
1384  IMG_PSDLayerInfo myLayerInfo;
1385 
1386  // Global layer mask info for Layer and Mask Information section.
1387  IMG_PSDGlobalLayerMaskInfo myGlobalLayerMaskInfo;
1388 
1389  // Additional layer info for Layer and Mask Information section.
1390  IMG_PSDAdditionalLayerInfo myAdditionalLayerInfo;
1391 
1392  // Length of each compressed data for a single channel's scanline row.
1393  // 2 dimensional, 1 dimension for each channel, 2nd dimension for each
1394  // individual group of data. Look at the top of IMG_PSD.h for more
1395  // info on RLE compression. For composite data.
1396  psd_half_bytes_t** myRLELengths;
1397 
1398  // Total length of the compressed data for each channel.
1399  // For composite data.
1400  uint64* myRLEChannelLengths;
1401 
1402  // Length of header data section.
1403  uint32 myHeaderDataLength;
1404 
1405  // Length of color mode data section.
1406  uint32 myColorModeDataLength;
1407 
1408  // Length of image resource data section.
1409  uint32 myImageResourceDataLength;
1410 
1411  // Length of layer mask data section.
1412  psd_bytes_t myLayerMaskDataLength;
1413 
1414  // Starting position for the "Channel Image Data" section.
1415  uint64 myChannelImageDataPosition;
1416 
1417  // Compression mode of composite data.
1418  uint16 myCompressionMethod;
1419 
1420  // Bool to keep track of if the composite/flattened image exists or not.
1421  bool myCompositeImageExists;
1422 
1423  // Temporary files to write image data into, for ZIP compressed channels.
1424  UT_Map<PSD_ChannelType, FILE *> myZipDecompressedChannelFiles;
1425 
1426  // Int is the layer record index. This needs to be in this scope and not
1427  // within the IMG_PSDLayerRecord struct, because we need to know the index
1428  // and IMG_PSDLayerRecords does not know its own index.
1430 };
1431 
1432 #endif
static IMG_File * create(const char *filename, const IMG_Stat &stat, const IMG_FileParms *options=nullptr, const IMG_Format *fmt=nullptr)
Create a new image file Create a new image file with the pathname 'filename' according to the paramet...
UT_Array< psd_half_bytes_t > myRLELengths
Definition: IMG_FilePSD.h:430
uint32 myHeight
Definition: IMG_FilePSD.h:357
GLint left
Definition: glcorearb.h:2004
virtual int readScanline(int scanline, void *data)=0
uint32 psd_half_bytes_t
Definition: IMG_FilePSD.h:336
UT_String myLayerName
Definition: IMG_FilePSD.h:516
virtual int closeFile()=0
uint32 myWidth
Definition: IMG_FilePSD.h:360
GLint y
Definition: glcorearb.h:102
virtual int writeScanline(int scanline, const void *data)=0
uint64 myImageDataPosition
Definition: IMG_FilePSD.h:427
GLuint buffer
Definition: glcorearb.h:659
GLsizeiptr size
Definition: glcorearb.h:663
PSD_ChannelType
Definition: IMG_FilePSD.h:433
GLint GLsizei width
Definition: glcorearb.h:102
#define IMG_API
Definition: IMG_API.h:10
PSD_LayerGroupType
Definition: IMG_FilePSD.h:443
unsigned long long uint64
Definition: SYS_Types.h:101
uint16 myChannelsCount
Definition: IMG_FilePSD.h:354
uint8 myBlendSignature[4]
Definition: IMG_FilePSD.h:488
psd_bytes_t myLength
Definition: IMG_FilePSD.h:379
uint64 myReserved
Definition: IMG_FilePSD.h:349
IMG_PSDLayerMaskData myLayerMaskData
Definition: IMG_FilePSD.h:513
uint16 myVersion
Definition: IMG_FilePSD.h:346
Generic interface for reading and writing image files. This class handles the reading and writing of ...
Definition: IMG_File.h:54
GLboolean * data
Definition: glcorearb.h:130
GLint GLint bottom
Definition: glcorearb.h:2004
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glcorearb.h:2539
GLint GLsizei GLsizei height
Definition: glcorearb.h:102
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2001
unsigned short uint16
Definition: SYS_Types.h:27
unsigned char uint8
Definition: SYS_Types.h:25
UT_Array< int > myChannelInfoInsertionOrder
Definition: IMG_FilePSD.h:485
virtual const char * className() const
Definition: IMG_FilePSD.h:550
PSD_LayerGroupType myLayerGroupType
Definition: IMG_FilePSD.h:522
UT_SortedMap< PSD_ChannelType, IMG_PSDChannelInfo > myChannelInfo
Definition: IMG_FilePSD.h:481
uint16 myColorMode
Definition: IMG_FilePSD.h:368
virtual int open()
Only called by format class.
Contains the details of a specific image file, used by IMG_File. This class contains all the high-lev...
Definition: IMG_Stat.h:40
uint64 psd_bytes_t
Definition: IMG_FilePSD.h:335
uint16 myDepth
Definition: IMG_FilePSD.h:363
psd_bytes_t myChannelDataLength
Definition: IMG_FilePSD.h:423
short int16
Definition: SYS_Types.h:26
uint16 myCompressionType
Definition: IMG_FilePSD.h:420
UT_Array< IMG_PSDLayerRecords > myLayerRecords
Definition: IMG_FilePSD.h:385
GLuint GLsizei GLsizei * length
Definition: glcorearb.h:794
unsigned int uint32
Definition: SYS_Types.h:29