1 module psd.layer;
2 import psd.res;
3 
4 import asdf;
5 
6 /**
7     A layer
8 */
9 struct Layer {
10 
11     /**
12         Name of layer
13     */
14     string name;
15 
16     /**
17         Bounding box for layer
18     */
19     union {
20 
21         /**
22             Bounds of the layer
23         */
24         uint[4] bounds;
25 
26         struct {
27             /**
28                 Y/Top coordinate
29             */
30             uint y;
31             
32             /**
33                 X/Left coordinate
34             */
35             uint x;
36 
37             /**
38                 Y+Height/Bottom coordinate
39             */
40             uint bottom;
41 
42             /**
43                 X+Width/Right coordinate
44             */
45             uint right;
46         }
47 
48     }
49 
50     /**
51         Width
52     */
53     uint width() {
54         return right-x;
55     }
56 
57     /**
58         Height
59     */
60     uint height() {
61         return bottom-y;
62     }
63 
64     /**
65         Gets the center coordinates of the layer
66     */
67     uint[2] center() {
68         return [
69             x+(width/2),
70             y+(height/2),
71         ];
72     }
73 
74     /**
75         Blending mode
76     */
77     BlendingMode blending;
78 
79     /**
80         Channels in layer
81     */
82     ChannelInfo[] channels;
83 
84     /**
85         Opacity of the layer
86     */
87     ubyte opacity;
88 
89     /**
90         Whether clipping is base or non-base
91     */
92     bool clipping;
93 
94     /**
95         Whether this layer is a group
96     */
97     bool isGroup;
98 
99     /**
100         Flags for the layer
101     */
102     @serdeProxy!uint
103     LayerFlags flags;
104 
105     /**
106         Layers that are the children of this layer
107     */
108     Layer[] children;
109 
110     /**
111         The data of the layer
112     */
113     @serdeIgnore
114     ubyte[] data;
115 
116     /**
117         Length of data
118     */
119     size_t dataLengthUncompressed() {
120         return this.area()*channels.length;
121     }
122 
123     /**
124         Area of the layer
125     */
126     size_t area() {
127         return width * height;
128     }
129 }
130