1 
2 //
3 //          IMAGE RESOURCES
4 //
5 module psd.image_resources;
6 import utils.io;
7 import utils;
8 import psd;
9 import std.exception;
10 import std.format;
11 
12 /**
13     An image resource block
14 */
15 struct ImageResourceBlock {
16     /**
17         Unique ID
18     */
19     ushort uid;
20 
21     /**
22         Name of resource
23     */
24     string name;
25 
26     /**
27         Data of resource
28     */
29     ubyte[] data;
30 }
31 
32 /**
33     A struct representing a thumbnail as stored in the image resources section.
34 */
35 struct Thumbnail
36 {
37 	uint width;
38 	uint height;
39 	uint binaryJpegSize;
40 	ubyte[] binaryJpeg;
41 }
42 
43 /**
44     A struct representing an alpha channel as stored in the image resources section.
45     NOTE: Note that the image data for alpha channels is stored in the image data section.
46 */
47 struct AlphaChannel
48 {
49     enum Mode : ubyte
50     {
51         ALPHA = 0,			// The channel stores alpha data.
52         INVERTED_ALPHA = 1,	// The channel stores inverted alpha data.
53         SPOT = 2			// The channel stores spot color data.
54     }
55 
56     /**
57         The channel's ASCII name.
58     */
59     string asciiName;
60 	
61     /**
62         The color space the colors are stored in.
63     */
64     ushort colorSpace;
65 	
66     /**
67         16-bit color data with 0 being black and 65535 being white (assuming RGBA).
68     */
69     ushort[4] color;
70 	
71     /**
72         The channel's opacity in the range [0, 100].
73     */
74     ushort opacity;
75 	
76     /**
77         The channel's mode, one of AlphaChannel::Mode.
78     */
79     Mode mode;
80 }
81 
82 /**
83     A struct representing the information extracted from the Image Resources section.
84 */
85 struct ImageResourcesData
86 {
87 	/**
88         An array of alpha channels, having alphaChannelCount entries.
89     */
90     AlphaChannel[] alphaChannels;
91 
92 	/**
93         The number of alpha channels stored in the array.
94     */
95     uint alphaChannelCount;
96 
97 	/**
98         Raw data of the ICC profile.
99     */
100     ubyte[] iccProfile;
101 	uint sizeOfICCProfile;
102 
103 	/**
104         Raw EXIF data.
105     */
106     ubyte[] exifData;
107 	uint sizeOfExifData;
108 
109 	/**
110         Whether the PSD contains real merged data.
111     */
112     bool containsRealMergedData;
113 
114 	/**
115         Raw XMP metadata.
116     */
117     ubyte[] xmpMetadata;
118 
119 	/**
120         JPEG thumbnail.
121     */
122     Thumbnail thumbnail;
123 }
124 
125 
126 enum ImageResourceType
127 {
128     IPTC_NAA = 1028,
129     CAPTION_DIGEST = 1061,
130     XMP_METADATA = 1060,
131     PRINT_INFORMATION = 1082,
132     PRINT_STYLE = 1083,
133     PRINT_SCALE = 1062,
134     PRINT_FLAGS = 1011,
135     PRINT_FLAGS_INFO = 10000,
136     PRINT_INFO = 1071,
137     RESOLUTION_INFO = 1005,
138     DISPLAY_INFO = 1077,
139     GLOBAL_ANGLE = 1037,
140     GLOBAL_ALTITUDE = 1049,
141     COLOR_HALFTONING_INFO = 1013,
142     COLOR_TRANSFER_FUNCTIONS = 1016,
143     MULTICHANNEL_HALFTONING_INFO = 1012,
144     MULTICHANNEL_TRANSFER_FUNCTIONS = 1015,
145     LAYER_STATE_INFORMATION = 1024,
146     LAYER_GROUP_INFORMATION = 1026,
147     LAYER_GROUP_ENABLED_ID = 1072,
148     LAYER_SELECTION_ID = 1069,
149     GRID_GUIDES_INFO = 1032,
150     URL_LIST = 1054,
151     SLICES = 1050,
152     PIXEL_ASPECT_RATIO = 1064,
153     ICC_PROFILE = 1039,
154     ICC_UNTAGGED_PROFILE = 1041,
155     ID_SEED_NUMBER = 1044,
156     THUMBNAIL_RESOURCE = 1036,
157     VERSION_INFO = 1057,
158     EXIF_DATA = 1058,
159     BACKGROUND_COLOR = 1010,
160     ALPHA_CHANNEL_ASCII_NAMES = 1006,
161     ALPHA_CHANNEL_UNICODE_NAMES = 1045,
162     ALPHA_IDENTIFIERS = 1053,
163     COPYRIGHT_FLAG = 1034,
164     PATH_SELECTION_STATE = 1088,
165     ONION_SKINS = 1078,
166     TIMELINE_INFO = 1075,
167     SHEET_DISCLOSURE = 1076,
168     WORKING_PATH = 1025,
169     MAC_PRINT_MANAGER_INFO = 1001,
170     WINDOWS_DEVMODE = 1085
171 }