ag-psd 15.0.3 → 15.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/csh.ts ADDED
@@ -0,0 +1,44 @@
1
+ import { readVectorMask } from './additionalInfo';
2
+ import { LayerVectorMask } from './psd';
3
+ import { readUint32, checkSignature, createReader, readPascalString, readUnicodeString } from './psdReader';
4
+
5
+ export interface Csh {
6
+ shapes: (LayerVectorMask & {
7
+ name: string;
8
+ id: string;
9
+ width: number;
10
+ height: number;
11
+ })[];
12
+ }
13
+
14
+ export function readCsh(buffer: ArrayBufferView): Csh {
15
+ const reader = createReader(buffer.buffer, buffer.byteOffset, buffer.byteLength);
16
+ const csh: Csh = { shapes: [] };
17
+
18
+ checkSignature(reader, 'cush');
19
+ if (readUint32(reader) !== 2) throw new Error('Invalid version');
20
+ const count = readUint32(reader);
21
+
22
+ for (let i = 0; i < count; i++) {
23
+ const name = readUnicodeString(reader);
24
+ while (reader.offset % 4) reader.offset++; // pad to 4byte bounds
25
+ if (readUint32(reader) !== 1) throw new Error('Invalid shape version');
26
+ const size = readUint32(reader);
27
+ const end = reader.offset + size;
28
+ const id = readPascalString(reader, 1);
29
+ // this might not be correct ???
30
+ const y1 = readUint32(reader);
31
+ const x1 = readUint32(reader);
32
+ const y2 = readUint32(reader);
33
+ const x2 = readUint32(reader);
34
+ const width = x2 - x1;
35
+ const height = y2 - y1;
36
+ const mask: LayerVectorMask = { paths: [] };
37
+ readVectorMask(reader, mask, width, height, end - reader.offset);
38
+ csh.shapes.push({ name, id, width, height, ...mask });
39
+
40
+ reader.offset = end;
41
+ }
42
+
43
+ return csh;
44
+ }