1
// ==========================================================
4
// Design and implementation by
5
// - Hervé Drolon (drolon@infonie.fr)
6
// - Mihail Naydenov (mnaydenov@users.sourceforge.net)
8
// Based on LGPL code created and published by http://sourceforge.net/projects/elynx/
10
// This file is part of FreeImage 3
12
// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY
13
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES
14
// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE
15
// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED
16
// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT
17
// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY
18
// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL
19
// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER
22
// Use at your own risk!
23
// ==========================================================
29
Table 2-12: File header section.
30
The file header contains the basic properties of the image.
32
typedef struct psdHeader {
33
BYTE Signature[4]; //! Always equal 8BPS, do not try to read the file if the signature does not match this value.
34
BYTE Version[2]; //! Always equal 1, do not read file if the version does not match this value.
35
char Reserved[6]; //! Must be zero.
36
BYTE Channels[2]; //! Number of channels including any alpha channels, supported range is 1 to 24.
37
BYTE Rows[4]; //! The height of the image in pixels. Supported range is 1 to 30,000.
38
BYTE Columns[4]; //! The width of the image in pixels. Supported range is 1 to 30,000.
39
BYTE Depth[2]; //! The number of bits per channel. Supported values are 1, 8, and 16.
40
BYTE Mode[2]; //! Colour mode of the file, Bitmap=0, Grayscale=1, Indexed=2, RGB=3, CMYK=4, Multichannel=7, Duotone=8, Lab=9.
44
Table 2-12: HeaderInfo Color spaces
49
short _Channels; //! Numer of channels including any alpha channels, supported range is 1 to 24.
50
int _Height; //! The height of the image in pixels. Supported range is 1 to 30,000.
51
int _Width; //! The width of the image in pixels. Supported range is 1 to 30,000.
52
short _BitsPerChannel;//! The number of bits per channel. Supported values are 1, 8, and 16.
53
short _ColourMode; //! Colour mode of the file, Bitmap=0, Grayscale=1, Indexed=2, RGB=3, CMYK=4, Multichannel=7, Duotone=8, Lab=9.
59
@return Returns the number of bytes read
61
bool Read(FreeImageIO *io, fi_handle handle);
65
Table 2-13 Color mode data section
67
Only indexed color and duotone have color mode data. For all other modes,
68
this section is just 4 bytes: the length field, which is set to zero.
69
For indexed color images, the length will be equal to 768, and the color data
70
will contain the color table for the image, in non-interleaved order.
71
For duotone images, the color data will contain the duotone specification,
72
the format of which is not documented. Other applications that read
73
Photoshop files can treat a duotone image as a grayscale image, and just
74
preserve the contents of the duotone information when reading and writing
77
class psdColourModeData {
79
int _Length; //! The length of the following color data
80
BYTE * _plColourData; //! The color data
86
@return Returns the number of bytes read
88
bool Read(FreeImageIO *io, fi_handle handle);
89
bool FillPalette(FIBITMAP *dib);
93
Table 2-1: Image resource block
94
NB: Resource data is padded to make size even
96
class psdImageResource {
99
char _OSType[4]; //! Photoshop always uses its signature, 8BIM
100
short _ID; //! Unique identifier. Image resource IDs on page 8
101
BYTE * _plName; //! A pascal string, padded to make size even (a null name consists of two bytes of 0)
102
int _Size; //! Actual size of resource data. This does not include the Type, ID, Name or Size fields.
111
Table A-6: ResolutionInfo structure
112
This structure contains information about the resolution of an image. It is
113
written as an image resource. See the Document file formats chapter for more
116
class psdResolutionInfo {
118
short _widthUnit; //! Display width as 1=inches; 2=cm; 3=points; 4=picas; 5=columns.
119
short _heightUnit; //! Display height as 1=inches; 2=cm; 3=points; 4=picas; 5=columns.
120
short _hRes; //! Horizontal resolution in pixels per inch.
121
short _vRes; //! Vertical resolution in pixels per inch.
122
int _hResUnit; //! 1=display horizontal resolution in pixels per inch; 2=display horizontal resolution in pixels per cm.
123
int _vResUnit; //! 1=display vertical resolution in pixels per inch; 2=display vertical resolution in pixels per cm.
127
~psdResolutionInfo();
129
@return Returns the number of bytes read
131
int Read(FreeImageIO *io, fi_handle handle);
133
@param res_x [out] X resolution in pixels/meter
134
@param res_y [out] Y resolution in pixels/meter
136
void GetResolutionInfo(unsigned &res_x, unsigned &res_y);
139
// Obsolete - Photoshop 2.0
140
class psdResolutionInfo_v2 {
149
psdResolutionInfo_v2();
150
~psdResolutionInfo_v2();
152
@return Returns the number of bytes read
154
int Read(FreeImageIO *io, fi_handle handle);
158
Table A-7: DisplayInfo Color spaces
159
This structure contains display information about each channel. It is written as an image resource.
161
class psdDisplayInfo {
165
short _Opacity; //! 0..100
166
BYTE _Kind; //! selected = 0, protected = 1
167
BYTE _padding; //! should be zero
173
@return Returns the number of bytes read
175
int Read(FreeImageIO *io, fi_handle handle);
179
Table 2-5: Thumbnail resource header
180
Adobe Photoshop 5.0 and later stores thumbnail information for preview
181
display in an image resource block. These resource blocks consist of an initial
182
28 byte header, followed by a JFIF thumbnail in RGB (red, green, blue) order
183
for both Macintosh and Windows. Adobe Photoshop 4.0 stored the
184
thumbnail information in the same format except the data section is BGR
185
(blue, green, red). The Adobe Photoshop 4.0 format is at resource ID 1033
186
and the Adobe Photoshop 5.0 format is at resource ID 1036.
190
int _Format; //! = 1 (kJpegRGB). Also supports kRawRGB (0).
191
int _Width; //! Width of thumbnail in pixels.
192
int _Height; //! Height of thumbnail in pixels.
193
int _WidthBytes; //! Padded row bytes as (width * bitspixel + 31) / 32 * 4.
194
int _Size; //! Total size as widthbytes * height * planes
195
int _CompressedSize; //! Size after compression. Used for consistentcy check.
196
short _BitPerPixel; //! = 24. Bits per pixel.
197
short _Planes; //! = 1. Number of planes.
198
FIBITMAP * _dib; //! JFIF data as uncompressed dib. Note: For resource ID 1033 the data is in BGR format.
203
FIBITMAP* getDib() { return _dib; }
205
@return Returns the number of bytes read
207
int Read(FreeImageIO *io, fi_handle handle, int iResourceSize, bool isBGR);
210
psdThumbnail(const psdThumbnail&);
211
psdThumbnail& operator=(const psdThumbnail&);
214
class psdICCProfile {
223
@return Returns the number of bytes read
225
int Read(FreeImageIO *io, fi_handle handle, int size);
233
psdHeaderInfo _headerInfo;
234
psdColourModeData _colourModeData;
235
psdResolutionInfo _resolutionInfo;
236
psdResolutionInfo_v2 _resolutionInfo_v2;
237
psdDisplayInfo _displayInfo;
238
psdThumbnail _thumbnail;
239
psdICCProfile _iccProfile;
242
short _TransparentIndex;
244
bool _bResolutionInfoFilled;
245
bool _bResolutionInfoFilled_v2;
246
bool _bDisplayInfoFilled;
247
bool _bThumbnailFilled;
254
/** Actually ignore it */
255
bool ReadLayerAndMaskInfoSection(FreeImageIO *io, fi_handle handle);
256
FIBITMAP* ReadImageData(FreeImageIO *io, fi_handle handle);
261
FIBITMAP* Load(FreeImageIO *io, fi_handle handle, int s_format_id, int flags=0);
262
/** Also used by the TIFF plugin */
263
bool ReadImageResources(FreeImageIO *io, fi_handle handle, LONG length=0);
264
/** Used by the TIFF plugin */
265
FIBITMAP* GetThumbnail() {
266
return _thumbnail.getDib();
270
#endif // PSDPARSER_H
1
// ==========================================================
4
// Design and implementation by
5
// - Hervé Drolon (drolon@infonie.fr)
6
// - Mihail Naydenov (mnaydenov@users.sourceforge.net)
8
// Based on LGPL code created and published by http://sourceforge.net/projects/elynx/
10
// This file is part of FreeImage 3
12
// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY
13
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES
14
// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE
15
// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED
16
// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT
17
// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY
18
// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL
19
// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER
22
// Use at your own risk!
23
// ==========================================================
29
Table 2-12: File header section.
30
The file header contains the basic properties of the image.
32
typedef struct psdHeader {
33
BYTE Signature[4]; //! Always equal 8BPS, do not try to read the file if the signature does not match this value.
34
BYTE Version[2]; //! Always equal 1, do not read file if the version does not match this value.
35
char Reserved[6]; //! Must be zero.
36
BYTE Channels[2]; //! Number of channels including any alpha channels, supported range is 1 to 24.
37
BYTE Rows[4]; //! The height of the image in pixels. Supported range is 1 to 30,000.
38
BYTE Columns[4]; //! The width of the image in pixels. Supported range is 1 to 30,000.
39
BYTE Depth[2]; //! The number of bits per channel. Supported values are 1, 8, and 16.
40
BYTE Mode[2]; //! Colour mode of the file, Bitmap=0, Grayscale=1, Indexed=2, RGB=3, CMYK=4, Multichannel=7, Duotone=8, Lab=9.
44
Table 2-12: HeaderInfo Color spaces
49
short _Channels; //! Numer of channels including any alpha channels, supported range is 1 to 24.
50
int _Height; //! The height of the image in pixels. Supported range is 1 to 30,000.
51
int _Width; //! The width of the image in pixels. Supported range is 1 to 30,000.
52
short _BitsPerChannel;//! The number of bits per channel. Supported values are 1, 8, and 16.
53
short _ColourMode; //! Colour mode of the file, Bitmap=0, Grayscale=1, Indexed=2, RGB=3, CMYK=4, Multichannel=7, Duotone=8, Lab=9.
59
@return Returns the number of bytes read
61
bool Read(FreeImageIO *io, fi_handle handle);
65
Table 2-13 Color mode data section
67
Only indexed color and duotone have color mode data. For all other modes,
68
this section is just 4 bytes: the length field, which is set to zero.
69
For indexed color images, the length will be equal to 768, and the color data
70
will contain the color table for the image, in non-interleaved order.
71
For duotone images, the color data will contain the duotone specification,
72
the format of which is not documented. Other applications that read
73
Photoshop files can treat a duotone image as a grayscale image, and just
74
preserve the contents of the duotone information when reading and writing
77
class psdColourModeData {
79
int _Length; //! The length of the following color data
80
BYTE * _plColourData; //! The color data
86
@return Returns the number of bytes read
88
bool Read(FreeImageIO *io, fi_handle handle);
89
bool FillPalette(FIBITMAP *dib);
93
Table 2-1: Image resource block
94
NB: Resource data is padded to make size even
96
class psdImageResource {
99
char _OSType[4]; //! Photoshop always uses its signature, 8BIM
100
short _ID; //! Unique identifier. Image resource IDs on page 8
101
BYTE * _plName; //! A pascal string, padded to make size even (a null name consists of two bytes of 0)
102
int _Size; //! Actual size of resource data. This does not include the Type, ID, Name or Size fields.
111
Table A-6: ResolutionInfo structure
112
This structure contains information about the resolution of an image. It is
113
written as an image resource. See the Document file formats chapter for more
116
class psdResolutionInfo {
118
short _widthUnit; //! Display width as 1=inches; 2=cm; 3=points; 4=picas; 5=columns.
119
short _heightUnit; //! Display height as 1=inches; 2=cm; 3=points; 4=picas; 5=columns.
120
short _hRes; //! Horizontal resolution in pixels per inch.
121
short _vRes; //! Vertical resolution in pixels per inch.
122
int _hResUnit; //! 1=display horizontal resolution in pixels per inch; 2=display horizontal resolution in pixels per cm.
123
int _vResUnit; //! 1=display vertical resolution in pixels per inch; 2=display vertical resolution in pixels per cm.
127
~psdResolutionInfo();
129
@return Returns the number of bytes read
131
int Read(FreeImageIO *io, fi_handle handle);
133
@param res_x [out] X resolution in pixels/meter
134
@param res_y [out] Y resolution in pixels/meter
136
void GetResolutionInfo(unsigned &res_x, unsigned &res_y);
139
// Obsolete - Photoshop 2.0
140
class psdResolutionInfo_v2 {
149
psdResolutionInfo_v2();
150
~psdResolutionInfo_v2();
152
@return Returns the number of bytes read
154
int Read(FreeImageIO *io, fi_handle handle);
158
Table A-7: DisplayInfo Color spaces
159
This structure contains display information about each channel. It is written as an image resource.
161
class psdDisplayInfo {
165
short _Opacity; //! 0..100
166
BYTE _Kind; //! selected = 0, protected = 1
167
BYTE _padding; //! should be zero
173
@return Returns the number of bytes read
175
int Read(FreeImageIO *io, fi_handle handle);
179
Table 2-5: Thumbnail resource header
180
Adobe Photoshop 5.0 and later stores thumbnail information for preview
181
display in an image resource block. These resource blocks consist of an initial
182
28 byte header, followed by a JFIF thumbnail in RGB (red, green, blue) order
183
for both Macintosh and Windows. Adobe Photoshop 4.0 stored the
184
thumbnail information in the same format except the data section is BGR
185
(blue, green, red). The Adobe Photoshop 4.0 format is at resource ID 1033
186
and the Adobe Photoshop 5.0 format is at resource ID 1036.
190
int _Format; //! = 1 (kJpegRGB). Also supports kRawRGB (0).
191
int _Width; //! Width of thumbnail in pixels.
192
int _Height; //! Height of thumbnail in pixels.
193
int _WidthBytes; //! Padded row bytes as (width * bitspixel + 31) / 32 * 4.
194
int _Size; //! Total size as widthbytes * height * planes
195
int _CompressedSize; //! Size after compression. Used for consistentcy check.
196
short _BitPerPixel; //! = 24. Bits per pixel.
197
short _Planes; //! = 1. Number of planes.
198
FIBITMAP * _dib; //! JFIF data as uncompressed dib. Note: For resource ID 1033 the data is in BGR format.
203
FIBITMAP* getDib() { return _dib; }
205
@return Returns the number of bytes read
207
int Read(FreeImageIO *io, fi_handle handle, int iResourceSize, bool isBGR);
210
psdThumbnail(const psdThumbnail&);
211
psdThumbnail& operator=(const psdThumbnail&);
214
class psdICCProfile {
223
@return Returns the number of bytes read
225
int Read(FreeImageIO *io, fi_handle handle, int size);
233
psdHeaderInfo _headerInfo;
234
psdColourModeData _colourModeData;
235
psdResolutionInfo _resolutionInfo;
236
psdResolutionInfo_v2 _resolutionInfo_v2;
237
psdDisplayInfo _displayInfo;
238
psdThumbnail _thumbnail;
239
psdICCProfile _iccProfile;
242
short _TransparentIndex;
244
bool _bResolutionInfoFilled;
245
bool _bResolutionInfoFilled_v2;
246
bool _bDisplayInfoFilled;
247
bool _bThumbnailFilled;
254
/** Actually ignore it */
255
bool ReadLayerAndMaskInfoSection(FreeImageIO *io, fi_handle handle);
256
FIBITMAP* ReadImageData(FreeImageIO *io, fi_handle handle);
261
FIBITMAP* Load(FreeImageIO *io, fi_handle handle, int s_format_id, int flags=0);
262
/** Also used by the TIFF plugin */
263
bool ReadImageResources(FreeImageIO *io, fi_handle handle, LONG length=0);
264
/** Used by the TIFF plugin */
265
FIBITMAP* GetThumbnail() {
266
return _thumbnail.getDib();
270
#endif // PSDPARSER_H