@yft-design/psd-lib 1.0.1 → 1.1.0
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/dist/abr.d.ts +57 -4
- package/dist/abr.js +95 -18
- package/dist/additionalInfo.js +92 -10
- package/dist/ase.d.ts +32 -0
- package/dist/ase.js +78 -0
- package/dist/descriptor.d.ts +35 -0
- package/dist/helpers.d.ts +3 -18
- package/dist/helpers.js +16 -15
- package/dist/index.d.ts +2 -1
- package/dist/index.js +4 -1
- package/dist/psd.d.ts +51 -0
- package/dist/psdReader.d.ts +4 -5
- package/dist/psdReader.js +150 -108
- package/package.json +2 -5
- package/dist/initializeCanvas.d.ts +0 -1
- package/dist/initializeCanvas.js +0 -21
package/dist/abr.d.ts
CHANGED
|
@@ -20,17 +20,68 @@ export interface BrushDynamics {
|
|
|
20
20
|
jitter: number;
|
|
21
21
|
minimum: number;
|
|
22
22
|
}
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
type DynamicBrushShapeShape = 'round point' | 'round blunt' | 'round curve' | 'round angle' | 'round fan' | 'flat point' | 'flat blunt' | 'flat curve' | 'flat angle' | 'flat fan';
|
|
24
|
+
type TipsBrushShapeShape = 'erodible point' | 'erodible flat' | 'erodible round' | 'erodible square' | 'erodible triangle' | 'custom';
|
|
25
|
+
export type BrushShape = ComputedBrushShape | SampledBrushShape | TipsBrushShape | DynamicBrushShape;
|
|
26
|
+
interface ComputedBrushShape {
|
|
27
|
+
type: 'computed';
|
|
25
28
|
size: number;
|
|
26
29
|
angle: number;
|
|
27
30
|
roundness: number;
|
|
28
|
-
hardness
|
|
31
|
+
hardness: number;
|
|
29
32
|
spacingOn: boolean;
|
|
30
33
|
spacing: number;
|
|
31
34
|
flipX: boolean;
|
|
32
35
|
flipY: boolean;
|
|
33
|
-
|
|
36
|
+
}
|
|
37
|
+
interface SampledBrushShape {
|
|
38
|
+
type: 'sampled';
|
|
39
|
+
name: string;
|
|
40
|
+
size: number;
|
|
41
|
+
angle: number;
|
|
42
|
+
roundness: number;
|
|
43
|
+
spacingOn: boolean;
|
|
44
|
+
spacing: number;
|
|
45
|
+
flipX: boolean;
|
|
46
|
+
flipY: boolean;
|
|
47
|
+
sampledData: string;
|
|
48
|
+
}
|
|
49
|
+
interface TipsBrushShape {
|
|
50
|
+
type: 'tips';
|
|
51
|
+
angle: number;
|
|
52
|
+
size: number;
|
|
53
|
+
shape: DynamicBrushShapeShape;
|
|
54
|
+
physics: boolean;
|
|
55
|
+
spacing: number;
|
|
56
|
+
spacingOn: boolean;
|
|
57
|
+
flipX: boolean;
|
|
58
|
+
flipY: boolean;
|
|
59
|
+
tipsType: TipsBrushShapeShape;
|
|
60
|
+
tipsLengthRatio: number;
|
|
61
|
+
tipsHardness: number;
|
|
62
|
+
tipsGridSize?: number;
|
|
63
|
+
tipsErodibleTipHeightMap?: number[];
|
|
64
|
+
tipsAirbrushCutoffAngle: number;
|
|
65
|
+
tipsAirbrushGranularity: number;
|
|
66
|
+
tipsAirbrushStreakiness: number;
|
|
67
|
+
tipsAirbrushSplatSize: number;
|
|
68
|
+
tipsAirbrushSplatCount: number;
|
|
69
|
+
}
|
|
70
|
+
interface DynamicBrushShape {
|
|
71
|
+
type: 'dynamic';
|
|
72
|
+
size: number;
|
|
73
|
+
angle: number;
|
|
74
|
+
shape: DynamicBrushShapeShape;
|
|
75
|
+
density: number;
|
|
76
|
+
length: number;
|
|
77
|
+
clumping: number;
|
|
78
|
+
thickness: number;
|
|
79
|
+
stiffness: number;
|
|
80
|
+
physics: boolean;
|
|
81
|
+
spacing: number;
|
|
82
|
+
spacingOn: boolean;
|
|
83
|
+
flipX: boolean;
|
|
84
|
+
flipY: boolean;
|
|
34
85
|
}
|
|
35
86
|
export interface Brush {
|
|
36
87
|
name: string;
|
|
@@ -63,6 +114,7 @@ export interface Brush {
|
|
|
63
114
|
depth: number;
|
|
64
115
|
depthMinimum: number;
|
|
65
116
|
depthDynamics: BrushDynamics;
|
|
117
|
+
textureEachTip: boolean;
|
|
66
118
|
};
|
|
67
119
|
dualBrush?: {
|
|
68
120
|
flip: boolean;
|
|
@@ -141,3 +193,4 @@ export interface Brush {
|
|
|
141
193
|
export declare function readAbr(buffer: ArrayBufferView, options?: {
|
|
142
194
|
logMissingFeatures?: boolean;
|
|
143
195
|
}): Abr;
|
|
196
|
+
export {};
|
package/dist/abr.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { BlnM, parseAngle, parsePercent, parseUnitsToNumber, readVersionAndDescriptor } from './descriptor';
|
|
2
2
|
import { checkSignature, createReader, readBytes, readDataRLE, readInt16, readInt32, readPascalString, readPattern, readSignature, readUint16, readUint32, readUint8, skipBytes } from './psdReader';
|
|
3
3
|
const dynamicsControl = ['off', 'fade', 'pen pressure', 'pen tilt', 'stylus wheel', 'initial direction', 'direction', 'initial rotation', 'rotation'];
|
|
4
|
+
const dynamicBrushShapeShapes = ['round point', 'round blunt', 'round curve', 'round angle', 'round fan', 'flat point', 'flat blunt', 'flat curve', 'flat angle', 'flat fan'];
|
|
5
|
+
const tipsBrushShapeShapes = ['erodible point', 'erodible flat', 'erodible round', 'erodible square', 'erodible triangle', 'custom'];
|
|
4
6
|
const toBrushType = {
|
|
5
7
|
_: 'brush',
|
|
6
8
|
MixB: 'mixer brush',
|
|
@@ -17,22 +19,95 @@ function parseDynamics(desc) {
|
|
|
17
19
|
};
|
|
18
20
|
}
|
|
19
21
|
function parseBrushShape(desc) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
22
|
+
switch (desc._classID) {
|
|
23
|
+
case 'computedBrush': {
|
|
24
|
+
return {
|
|
25
|
+
type: 'computed',
|
|
26
|
+
size: parseUnitsToNumber(desc.Dmtr, 'Pixels'),
|
|
27
|
+
angle: parseAngle(desc.Angl),
|
|
28
|
+
roundness: parsePercent(desc.Rndn),
|
|
29
|
+
spacingOn: desc.Intr,
|
|
30
|
+
spacing: parsePercent(desc.Spcn),
|
|
31
|
+
flipX: desc.flipX,
|
|
32
|
+
flipY: desc.flipY,
|
|
33
|
+
hardness: parsePercent(desc.Hrdn),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
case 'sampledBrush': {
|
|
37
|
+
return {
|
|
38
|
+
type: 'sampled',
|
|
39
|
+
size: parseUnitsToNumber(desc.Dmtr, 'Pixels'),
|
|
40
|
+
angle: parseAngle(desc.Angl),
|
|
41
|
+
roundness: parsePercent(desc.Rndn),
|
|
42
|
+
spacingOn: desc.Intr,
|
|
43
|
+
spacing: parsePercent(desc.Spcn),
|
|
44
|
+
flipX: desc.flipX,
|
|
45
|
+
flipY: desc.flipY,
|
|
46
|
+
name: desc['Nm '],
|
|
47
|
+
sampledData: desc.sampledData,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
case 'dBrush':
|
|
51
|
+
return {
|
|
52
|
+
type: 'dynamic',
|
|
53
|
+
shape: dynamicBrushShapeShapes[desc['Shp ']],
|
|
54
|
+
angle: parseAngle(desc.Angl),
|
|
55
|
+
size: parseUnitsToNumber(desc.Dmtr, 'Pixels'),
|
|
56
|
+
density: parsePercent(desc.Dnst),
|
|
57
|
+
length: parsePercent(desc.Lngt),
|
|
58
|
+
clumping: parsePercent(desc.clumping),
|
|
59
|
+
thickness: parsePercent(desc.thickness),
|
|
60
|
+
stiffness: parsePercent(desc.stiffness),
|
|
61
|
+
physics: desc.physics,
|
|
62
|
+
spacing: parsePercent(desc.Spcn),
|
|
63
|
+
spacingOn: desc.Intr,
|
|
64
|
+
flipX: desc.flipX,
|
|
65
|
+
flipY: desc.flipY,
|
|
66
|
+
};
|
|
67
|
+
case 'dTips': {
|
|
68
|
+
return {
|
|
69
|
+
type: 'tips',
|
|
70
|
+
angle: parseAngle(desc.Angl),
|
|
71
|
+
size: parseUnitsToNumber(desc.Dmtr, 'Pixels'),
|
|
72
|
+
shape: dynamicBrushShapeShapes[desc['Shp ']],
|
|
73
|
+
physics: desc.physics,
|
|
74
|
+
spacing: parsePercent(desc.Spcn),
|
|
75
|
+
spacingOn: desc.Intr,
|
|
76
|
+
flipX: desc.flipX,
|
|
77
|
+
flipY: desc.flipY,
|
|
78
|
+
// tips:
|
|
79
|
+
tipsType: tipsBrushShapeShapes[desc.dtipsType],
|
|
80
|
+
tipsLengthRatio: parsePercent(desc.dtipsLengthRatio),
|
|
81
|
+
tipsHardness: parsePercent(desc.dtipsHardness),
|
|
82
|
+
...(desc.dtipsGridSize && desc.dtipsErodibleTipHeightMap ? {
|
|
83
|
+
tipsGridSize: desc.dtipsGridSize,
|
|
84
|
+
tipsErodibleTipHeightMap: parseHeightmap(desc.dtipsErodibleTipHeightMap),
|
|
85
|
+
} : {}),
|
|
86
|
+
// airbrush
|
|
87
|
+
tipsAirbrushCutoffAngle: desc.dtipsAirbrushCutoffAngle,
|
|
88
|
+
tipsAirbrushGranularity: parsePercent(desc.dtipsAirbrushGranularity),
|
|
89
|
+
tipsAirbrushStreakiness: parsePercent(desc.dtipsAirbrushStreakiness),
|
|
90
|
+
tipsAirbrushSplatSize: parsePercent(desc.dtipsAirbrushSplatSize),
|
|
91
|
+
tipsAirbrushSplatCount: desc.dtipsAirbrushSplatCount,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
default:
|
|
95
|
+
console.log(require('util').inspect(desc, false, 99, true));
|
|
96
|
+
throw new Error(`Unknown brush classId: ${desc._classID}`);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
function parseHeightmap(array) {
|
|
100
|
+
const result = [];
|
|
101
|
+
for (let i = 0; i < array.byteLength; i++) {
|
|
102
|
+
result.push(array[i]);
|
|
103
|
+
}
|
|
104
|
+
return result;
|
|
105
|
+
// const view = new DataView(array.buffer, array.byteOffset, array.byteLength);
|
|
106
|
+
// const result: number[] = [];
|
|
107
|
+
// for (let i = 0, len = (array.byteLength / 4) | 0; i < len; i++) {
|
|
108
|
+
// result.push(view.getInt32(i * 4)); ????
|
|
109
|
+
// }
|
|
110
|
+
// return result;
|
|
36
111
|
}
|
|
37
112
|
export function readAbr(buffer, options = {}) {
|
|
38
113
|
const reader = createReader(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
@@ -107,6 +182,7 @@ export function readAbr(buffer, options = {}) {
|
|
|
107
182
|
case 'desc': {
|
|
108
183
|
const desc = readVersionAndDescriptor(reader, true);
|
|
109
184
|
// console.log(require('util').inspect(desc, false, 99, true));
|
|
185
|
+
// require('fs').writeFileSync('test.log', require('util').inspect(desc, false, 99, false), 'utf8');
|
|
110
186
|
for (const brush of desc.Brsh) {
|
|
111
187
|
const b = {
|
|
112
188
|
name: brush['Nm '],
|
|
@@ -156,6 +232,7 @@ export function readAbr(buffer, options = {}) {
|
|
|
156
232
|
invert: brush.InvT,
|
|
157
233
|
brightness: brush.textureBrightness,
|
|
158
234
|
contrast: brush.textureContrast,
|
|
235
|
+
textureEachTip: !!brush.TxtC,
|
|
159
236
|
};
|
|
160
237
|
}
|
|
161
238
|
const db = brush.dualBrush;
|
|
@@ -258,10 +335,10 @@ export function readAbr(buffer, options = {}) {
|
|
|
258
335
|
break;
|
|
259
336
|
}
|
|
260
337
|
case 'patt': {
|
|
261
|
-
|
|
338
|
+
while (reader.offset < end) {
|
|
262
339
|
patterns.push(readPattern(reader));
|
|
263
|
-
reader.offset = end;
|
|
264
340
|
}
|
|
341
|
+
reader.offset = end;
|
|
265
342
|
break;
|
|
266
343
|
}
|
|
267
344
|
case 'phry': {
|
package/dist/additionalInfo.js
CHANGED
|
@@ -315,7 +315,7 @@ addHandler('vogk', hasKey('vectorOrigination'), (reader, target, left) => {
|
|
|
315
315
|
}
|
|
316
316
|
const trnf = i.Trnf;
|
|
317
317
|
if (trnf) {
|
|
318
|
-
item.transform = [trnf.xx, trnf.xy, trnf.
|
|
318
|
+
item.transform = [trnf.xx, trnf.xy, trnf.yx, trnf.yy, trnf.tx, trnf.ty];
|
|
319
319
|
}
|
|
320
320
|
target.vectorOrigination.keyDescriptorList.push(item);
|
|
321
321
|
}
|
|
@@ -733,6 +733,70 @@ target => target.timestamp !== undefined || target.animationFrames !== undefined
|
|
|
733
733
|
}, true);
|
|
734
734
|
}
|
|
735
735
|
});
|
|
736
|
+
addHandler('PxSc', () => false, (reader, target) => {
|
|
737
|
+
const desc = readVersionAndDescriptor(reader, true);
|
|
738
|
+
// console.log('PxSc', require('util').inspect(desc, false, 99, true));
|
|
739
|
+
if (desc.pixelSourceType === 1986285651) {
|
|
740
|
+
target.pixelSource = {
|
|
741
|
+
type: 'vdPS',
|
|
742
|
+
origin: { x: desc.origin.Hrzn, y: desc.origin.Vrtc },
|
|
743
|
+
interpretation: {
|
|
744
|
+
interpretAlpha: desc.interpretation.interpretAlpha.split('.')[1],
|
|
745
|
+
profile: desc.interpretation.profile,
|
|
746
|
+
},
|
|
747
|
+
frameReader: {
|
|
748
|
+
type: 'QTFR',
|
|
749
|
+
link: {
|
|
750
|
+
name: desc.frameReader['Lnk ']['Nm '],
|
|
751
|
+
fullPath: desc.frameReader['Lnk '].fullPath,
|
|
752
|
+
originalPath: desc.frameReader['Lnk '].originalPath,
|
|
753
|
+
relativePath: desc.frameReader['Lnk '].relPath,
|
|
754
|
+
alias: desc.frameReader['Lnk '].alis,
|
|
755
|
+
},
|
|
756
|
+
mediaDescriptor: desc.frameReader.mediaDescriptor,
|
|
757
|
+
},
|
|
758
|
+
showAlteredVideo: desc.showAlteredVideo,
|
|
759
|
+
};
|
|
760
|
+
}
|
|
761
|
+
else {
|
|
762
|
+
reader.log(`Unknown pixelSourceType`);
|
|
763
|
+
}
|
|
764
|
+
}, (writer, target) => {
|
|
765
|
+
const source = target.pixelSource;
|
|
766
|
+
const desc = {
|
|
767
|
+
_name: '',
|
|
768
|
+
_classID: 'PixelSource',
|
|
769
|
+
pixelSourceType: 1986285651, // vdP
|
|
770
|
+
descVersion: 1,
|
|
771
|
+
origin: { Hrzn: source.origin.x, Vrtc: source.origin.y },
|
|
772
|
+
interpretation: {
|
|
773
|
+
_name: '',
|
|
774
|
+
_classID: 'footageInterpretation',
|
|
775
|
+
Vrsn: 1,
|
|
776
|
+
interpretAlpha: `alphaInterpretation.${source.interpretation.interpretAlpha}`,
|
|
777
|
+
profile: source.interpretation.profile,
|
|
778
|
+
},
|
|
779
|
+
frameReader: {
|
|
780
|
+
_name: '',
|
|
781
|
+
_classID: 'FrameReader',
|
|
782
|
+
frameReaderType: 1364477522, // QTF
|
|
783
|
+
descVersion: 1,
|
|
784
|
+
'Lnk ': {
|
|
785
|
+
_name: '',
|
|
786
|
+
_classID: 'ExternalFileLink',
|
|
787
|
+
descVersion: 2,
|
|
788
|
+
'Nm ': source.frameReader.link.name,
|
|
789
|
+
fullPath: source.frameReader.link.fullPath,
|
|
790
|
+
originalPath: source.frameReader.link.originalPath,
|
|
791
|
+
alis: source.frameReader.link.alias,
|
|
792
|
+
relPath: source.frameReader.link.relativePath,
|
|
793
|
+
},
|
|
794
|
+
mediaDescriptor: source.frameReader.mediaDescriptor,
|
|
795
|
+
},
|
|
796
|
+
showAlteredVideo: source.showAlteredVideo,
|
|
797
|
+
};
|
|
798
|
+
writeVersionAndDescriptor(writer, '', 'PixelSource', desc);
|
|
799
|
+
});
|
|
736
800
|
addHandler('vstk', hasKey('vectorStroke'), (reader, target, left) => {
|
|
737
801
|
const desc = readVersionAndDescriptor(reader);
|
|
738
802
|
// console.log(require('util').inspect(desc, false, 99, true));
|
|
@@ -2527,6 +2591,8 @@ else {
|
|
|
2527
2591
|
}
|
|
2528
2592
|
/*
|
|
2529
2593
|
interface CAIDesc {
|
|
2594
|
+
_name: '';
|
|
2595
|
+
_classID: 'null';
|
|
2530
2596
|
enab: boolean;
|
|
2531
2597
|
generationalGuid: string;
|
|
2532
2598
|
}
|
|
@@ -2536,15 +2602,15 @@ addHandler(
|
|
|
2536
2602
|
() => false,
|
|
2537
2603
|
(reader, _target, left) => {
|
|
2538
2604
|
const version = readUint32(reader); // 3
|
|
2539
|
-
const desc = readVersionAndDescriptor(reader) as CAIDesc;
|
|
2605
|
+
const desc = readVersionAndDescriptor(reader, true) as CAIDesc;
|
|
2606
|
+
console.log('CAI version', version);
|
|
2540
2607
|
console.log('CAI', require('util').inspect(desc, false, 99, true));
|
|
2541
|
-
console.log('CAI', { version });
|
|
2542
2608
|
console.log('CAI left', readBytes(reader, left())); // 8 bytes left, all zeroes
|
|
2543
2609
|
},
|
|
2544
2610
|
(_writer, _target) => {
|
|
2545
2611
|
},
|
|
2546
2612
|
);
|
|
2547
|
-
*/
|
|
2613
|
+
// */
|
|
2548
2614
|
if (MOCK_HANDLERS) {
|
|
2549
2615
|
addHandler('CAI ', target => target._CAI_ !== undefined, (reader, target, left) => {
|
|
2550
2616
|
target._CAI_ = readBytes(reader, left());
|
|
@@ -2552,25 +2618,41 @@ if (MOCK_HANDLERS) {
|
|
|
2552
2618
|
writeBytes(writer, target._CAI_);
|
|
2553
2619
|
});
|
|
2554
2620
|
}
|
|
2621
|
+
// interface OCIODescriptor {
|
|
2622
|
+
// _name: '';
|
|
2623
|
+
// _classID: 'documentColorManagementInfo';
|
|
2624
|
+
// 'Knd ': 'icc';
|
|
2625
|
+
// ocio_display_view: {
|
|
2626
|
+
// _name: '';
|
|
2627
|
+
// _classID: 'viewColorManagementInfo';
|
|
2628
|
+
// display: string;
|
|
2629
|
+
// view: string;
|
|
2630
|
+
// };
|
|
2631
|
+
// }
|
|
2555
2632
|
if (MOCK_HANDLERS) {
|
|
2556
|
-
addHandler('OCIO', //
|
|
2557
|
-
//
|
|
2633
|
+
addHandler('OCIO', // document color management info
|
|
2634
|
+
// document color management info
|
|
2558
2635
|
target => target._OCIO !== undefined, (reader, target, left) => {
|
|
2636
|
+
// const desc = readVersionAndDescriptor(reader, true) as OCIODescriptor;
|
|
2637
|
+
// console.log('OCIO', require('util').inspect(desc, false, 99, true));
|
|
2559
2638
|
target._OCIO = readBytes(reader, left());
|
|
2560
2639
|
}, (writer, target) => {
|
|
2561
2640
|
writeBytes(writer, target._OCIO);
|
|
2562
2641
|
});
|
|
2563
2642
|
}
|
|
2564
|
-
// interface
|
|
2643
|
+
// interface GenIDescriptor {
|
|
2644
|
+
// _name: '';
|
|
2645
|
+
// _classID: 'genTechInfo';
|
|
2565
2646
|
// isUsingGenTech: number;
|
|
2647
|
+
// externalModelList?: [];
|
|
2566
2648
|
// }
|
|
2567
2649
|
if (MOCK_HANDLERS) {
|
|
2568
2650
|
addHandler('GenI', // generative tech
|
|
2569
2651
|
// generative tech
|
|
2570
2652
|
target => target._GenI !== undefined, (reader, target, left) => {
|
|
2653
|
+
const desc = readVersionAndDescriptor(reader, true); // as GenIDescriptor;
|
|
2654
|
+
console.log('GenI', require('util').inspect(desc, false, 99, true));
|
|
2571
2655
|
target._GenI = readBytes(reader, left());
|
|
2572
|
-
// const desc = readVersionAndDescriptor(reader) as GenIDesc;
|
|
2573
|
-
// console.log('GenI', require('util').inspect(desc, false, 99, true));
|
|
2574
2656
|
}, (writer, target) => {
|
|
2575
2657
|
writeBytes(writer, target._GenI);
|
|
2576
2658
|
});
|
|
@@ -2768,7 +2850,7 @@ function createLnkHandler(tag) {
|
|
|
2768
2850
|
version = 6;
|
|
2769
2851
|
else if (file.childDocumentID != null)
|
|
2770
2852
|
version = 5;
|
|
2771
|
-
else if (tag
|
|
2853
|
+
else if (tag === 'lnkE')
|
|
2772
2854
|
version = 3;
|
|
2773
2855
|
writeLength64(writer, 0);
|
|
2774
2856
|
const sizeOffset = writer.offset;
|
package/dist/ase.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export type AseColorType = 'global' | 'spot' | 'normal';
|
|
2
|
+
export interface AseColor {
|
|
3
|
+
name: string;
|
|
4
|
+
color: {
|
|
5
|
+
r: number;
|
|
6
|
+
g: number;
|
|
7
|
+
b: number;
|
|
8
|
+
type: AseColorType;
|
|
9
|
+
} | {
|
|
10
|
+
c: number;
|
|
11
|
+
m: number;
|
|
12
|
+
y: number;
|
|
13
|
+
k: number;
|
|
14
|
+
type: AseColorType;
|
|
15
|
+
} | {
|
|
16
|
+
k: number;
|
|
17
|
+
type: AseColorType;
|
|
18
|
+
} | {
|
|
19
|
+
l: number;
|
|
20
|
+
a: number;
|
|
21
|
+
b: number;
|
|
22
|
+
type: AseColorType;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export interface AseGroup {
|
|
26
|
+
name: string;
|
|
27
|
+
colors: AseColor[];
|
|
28
|
+
}
|
|
29
|
+
export interface Ase {
|
|
30
|
+
colors: (AseGroup | AseColor)[];
|
|
31
|
+
}
|
|
32
|
+
export declare function readAse(buffer: ArrayBufferView): Ase;
|
package/dist/ase.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { createReader, readFloat32, readSignature, readUint16, readUint32, readUnicodeStringWithLength } from './psdReader';
|
|
2
|
+
export function readAse(buffer) {
|
|
3
|
+
const reader = createReader(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
4
|
+
const signature = readSignature(reader); // ASEF
|
|
5
|
+
if (signature !== 'ASEF')
|
|
6
|
+
throw new Error('Invalid signature');
|
|
7
|
+
const versionMajor = readUint16(reader); // 1
|
|
8
|
+
const versionMinor = readUint16(reader); // 0
|
|
9
|
+
if (versionMajor !== 1 || versionMinor !== 0)
|
|
10
|
+
throw new Error('Invalid version');
|
|
11
|
+
const blocksCount = readUint32(reader);
|
|
12
|
+
const colorTypes = ['global', 'spot', 'normal'];
|
|
13
|
+
const ase = { colors: [] };
|
|
14
|
+
let group = ase;
|
|
15
|
+
for (let i = 0; i < blocksCount; i++) {
|
|
16
|
+
const type = readUint16(reader);
|
|
17
|
+
const length = readUint32(reader);
|
|
18
|
+
const end = reader.offset + length;
|
|
19
|
+
switch (type) {
|
|
20
|
+
case 0x0001: { // color
|
|
21
|
+
const nameLength = readUint16(reader);
|
|
22
|
+
const name = readUnicodeStringWithLength(reader, nameLength);
|
|
23
|
+
const colorMode = readSignature(reader);
|
|
24
|
+
let color;
|
|
25
|
+
switch (colorMode) {
|
|
26
|
+
case 'RGB ':
|
|
27
|
+
color = {
|
|
28
|
+
r: readFloat32(reader),
|
|
29
|
+
g: readFloat32(reader),
|
|
30
|
+
b: readFloat32(reader),
|
|
31
|
+
type: colorTypes[readUint16(reader)],
|
|
32
|
+
};
|
|
33
|
+
break;
|
|
34
|
+
case 'CMYK':
|
|
35
|
+
color = {
|
|
36
|
+
c: readFloat32(reader),
|
|
37
|
+
m: readFloat32(reader),
|
|
38
|
+
y: readFloat32(reader),
|
|
39
|
+
k: readFloat32(reader),
|
|
40
|
+
type: colorTypes[readUint16(reader)],
|
|
41
|
+
};
|
|
42
|
+
break;
|
|
43
|
+
case 'Gray':
|
|
44
|
+
color = {
|
|
45
|
+
k: readFloat32(reader),
|
|
46
|
+
type: colorTypes[readUint16(reader)],
|
|
47
|
+
};
|
|
48
|
+
break;
|
|
49
|
+
case 'LAB ':
|
|
50
|
+
color = {
|
|
51
|
+
l: readFloat32(reader),
|
|
52
|
+
a: readFloat32(reader),
|
|
53
|
+
b: readFloat32(reader),
|
|
54
|
+
type: colorTypes[readUint16(reader)],
|
|
55
|
+
};
|
|
56
|
+
break;
|
|
57
|
+
default:
|
|
58
|
+
throw new Error('Invalid color mode');
|
|
59
|
+
}
|
|
60
|
+
group.colors.push({ name, color });
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
case 0xC001: { // group start
|
|
64
|
+
const nameLength = readUint16(reader);
|
|
65
|
+
const name = readUnicodeStringWithLength(reader, nameLength);
|
|
66
|
+
ase.colors.push(group = { name, colors: [] });
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
case 0xC002: // group end
|
|
70
|
+
group = ase;
|
|
71
|
+
break;
|
|
72
|
+
default:
|
|
73
|
+
throw new Error('Invalid block type');
|
|
74
|
+
}
|
|
75
|
+
reader.offset = end;
|
|
76
|
+
}
|
|
77
|
+
return ase;
|
|
78
|
+
}
|
package/dist/descriptor.d.ts
CHANGED
|
@@ -216,6 +216,41 @@ export interface FrameListDescriptor {
|
|
|
216
216
|
LaID: number;
|
|
217
217
|
LaSt: FrameDescriptor[];
|
|
218
218
|
}
|
|
219
|
+
export interface PxScDescriptor {
|
|
220
|
+
_name: '';
|
|
221
|
+
_classID: 'PixelSource';
|
|
222
|
+
pixelSourceType: 1986285651;
|
|
223
|
+
descVersion: 1;
|
|
224
|
+
origin: {
|
|
225
|
+
Hrzn: number;
|
|
226
|
+
Vrtc: number;
|
|
227
|
+
};
|
|
228
|
+
interpretation: {
|
|
229
|
+
_name: '';
|
|
230
|
+
_classID: 'footageInterpretation';
|
|
231
|
+
Vrsn: 1;
|
|
232
|
+
interpretAlpha: 'alphaInterpretation.straight';
|
|
233
|
+
profile: Uint8Array;
|
|
234
|
+
};
|
|
235
|
+
frameReader: {
|
|
236
|
+
_name: '';
|
|
237
|
+
_classID: 'FrameReader';
|
|
238
|
+
frameReaderType: 1364477522;
|
|
239
|
+
descVersion: 1;
|
|
240
|
+
'Lnk ': {
|
|
241
|
+
_name: '';
|
|
242
|
+
_classID: 'ExternalFileLink';
|
|
243
|
+
descVersion: 2;
|
|
244
|
+
'Nm ': string;
|
|
245
|
+
fullPath: string;
|
|
246
|
+
originalPath: string;
|
|
247
|
+
alis: string;
|
|
248
|
+
relPath: string;
|
|
249
|
+
};
|
|
250
|
+
mediaDescriptor: string;
|
|
251
|
+
};
|
|
252
|
+
showAlteredVideo: boolean;
|
|
253
|
+
}
|
|
219
254
|
export declare function horzVrtcToXY(hv: HrznVrtcDescriptor): {
|
|
220
255
|
x: number;
|
|
221
256
|
y: number;
|
package/dist/helpers.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Layer, BlendMode, LayerColor, PixelData, PixelArray } from './psd';
|
|
1
|
+
import { Layer, BlendMode, LayerColor, PixelData, PixelArray, ChannelID, Compression } from './psd';
|
|
2
2
|
export declare const MOCK_HANDLERS = false;
|
|
3
3
|
export declare const RAW_IMAGE_DATA = false;
|
|
4
4
|
export declare const fromBlendMode: {
|
|
@@ -37,21 +37,6 @@ export declare const enum MaskParams {
|
|
|
37
37
|
VectorMaskDensity = 4,
|
|
38
38
|
VectorMaskFeather = 8
|
|
39
39
|
}
|
|
40
|
-
export declare const enum ChannelID {
|
|
41
|
-
Color0 = 0,// red (rgb) / cyan (cmyk)
|
|
42
|
-
Color1 = 1,// green (rgb) / magenta (cmyk)
|
|
43
|
-
Color2 = 2,// blue (rgb) / yellow (cmyk)
|
|
44
|
-
Color3 = 3,// - (rgb) / black (cmyk)
|
|
45
|
-
Transparency = -1,
|
|
46
|
-
UserMask = -2,
|
|
47
|
-
RealUserMask = -3
|
|
48
|
-
}
|
|
49
|
-
export declare const enum Compression {
|
|
50
|
-
RawData = 0,
|
|
51
|
-
RleCompressed = 1,
|
|
52
|
-
ZipWithoutPrediction = 2,
|
|
53
|
-
ZipWithPrediction = 3
|
|
54
|
-
}
|
|
55
40
|
export interface ChannelData {
|
|
56
41
|
channelId: ChannelID;
|
|
57
42
|
compression: Compression;
|
|
@@ -83,7 +68,7 @@ export declare function decodeBitmap(input: PixelArray, output: PixelArray, widt
|
|
|
83
68
|
export declare function writeDataRaw(data: PixelData, offset: number, width: number, height: number): Uint8Array<ArrayBuffer> | undefined;
|
|
84
69
|
export declare function writeDataRLE(buffer: Uint8Array, { data, width, height }: PixelData, offsets: number[], large: boolean): Uint8Array<ArrayBuffer> | undefined;
|
|
85
70
|
export declare function writeDataZipWithoutPrediction({ data, width, height }: PixelData, offsets: number[]): Uint8Array<ArrayBufferLike>;
|
|
71
|
+
export declare function createCanvasFromData(data: Uint8Array): HTMLCanvasElement;
|
|
86
72
|
export declare let createCanvas: (width: number, height: number) => HTMLCanvasElement;
|
|
87
|
-
export declare let createCanvasFromData: (data: Uint8Array) => HTMLCanvasElement;
|
|
88
73
|
export declare let createImageData: (width: number, height: number) => ImageData;
|
|
89
|
-
export declare function initializeCanvas(createCanvasMethod: (width: number, height: number) => HTMLCanvasElement,
|
|
74
|
+
export declare function initializeCanvas(createCanvasMethod: (width: number, height: number) => HTMLCanvasElement, createImageDataMethod?: (width: number, height: number) => ImageData): void;
|
package/dist/helpers.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { fromByteArray } from 'base64-js';
|
|
2
1
|
import { deflate as deflateSync } from 'pako';
|
|
2
|
+
import { decodeJpeg } from './jpeg';
|
|
3
3
|
export const MOCK_HANDLERS = false;
|
|
4
4
|
export const RAW_IMAGE_DATA = false;
|
|
5
5
|
export const fromBlendMode = {};
|
|
@@ -264,12 +264,23 @@ export function writeDataZipWithoutPrediction({ data, width, height }, offsets)
|
|
|
264
264
|
return buffers[0];
|
|
265
265
|
}
|
|
266
266
|
}
|
|
267
|
+
export function createCanvasFromData(data) {
|
|
268
|
+
const canvas = createCanvas(100, 100);
|
|
269
|
+
try {
|
|
270
|
+
const context = canvas.getContext('2d');
|
|
271
|
+
const imageData = decodeJpeg(data, (w, h) => context.createImageData(w, h));
|
|
272
|
+
canvas.width = imageData.width;
|
|
273
|
+
canvas.height = imageData.height;
|
|
274
|
+
context.putImageData(imageData, 0, 0);
|
|
275
|
+
}
|
|
276
|
+
catch (e) {
|
|
277
|
+
console.error('JPEG decompression error', e.message);
|
|
278
|
+
}
|
|
279
|
+
return canvas;
|
|
280
|
+
}
|
|
267
281
|
export let createCanvas = () => {
|
|
268
282
|
throw new Error('Canvas not initialized, use initializeCanvas method to set up createCanvas method');
|
|
269
283
|
};
|
|
270
|
-
export let createCanvasFromData = () => {
|
|
271
|
-
throw new Error('Canvas not initialized, use initializeCanvas method to set up createCanvasFromData method');
|
|
272
|
-
};
|
|
273
284
|
let tempCanvas = undefined;
|
|
274
285
|
export let createImageData = (width, height) => {
|
|
275
286
|
if (!tempCanvas)
|
|
@@ -283,18 +294,8 @@ if (typeof document !== 'undefined') {
|
|
|
283
294
|
canvas.height = height;
|
|
284
295
|
return canvas;
|
|
285
296
|
};
|
|
286
|
-
createCanvasFromData = (data) => {
|
|
287
|
-
const image = new Image();
|
|
288
|
-
image.src = 'data:image/jpeg;base64,' + fromByteArray(data);
|
|
289
|
-
const canvas = document.createElement('canvas');
|
|
290
|
-
canvas.width = image.width;
|
|
291
|
-
canvas.height = image.height;
|
|
292
|
-
canvas.getContext('2d').drawImage(image, 0, 0);
|
|
293
|
-
return canvas;
|
|
294
|
-
};
|
|
295
297
|
}
|
|
296
|
-
export function initializeCanvas(createCanvasMethod,
|
|
298
|
+
export function initializeCanvas(createCanvasMethod, createImageDataMethod) {
|
|
297
299
|
createCanvas = createCanvasMethod;
|
|
298
|
-
createCanvasFromData = createCanvasFromDataMethod || createCanvasFromData;
|
|
299
300
|
createImageData = createImageDataMethod || createImageData;
|
|
300
301
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Psd, ReadOptions, WriteOptions } from './psd';
|
|
1
|
+
import { Layer, Psd, ReadOptions, WriteOptions } from './psd';
|
|
2
2
|
import { PsdWriter } from './psdWriter';
|
|
3
3
|
import { PsdReader } from './psdReader';
|
|
4
4
|
import { fromByteArray } from 'base64-js';
|
|
@@ -17,3 +17,4 @@ export declare function readPsd(buffer: ArrayBuffer | BufferLike, options?: Read
|
|
|
17
17
|
export declare function writePsd(psd: Psd, options?: WriteOptions): ArrayBuffer;
|
|
18
18
|
export declare function writePsdUint8Array(psd: Psd, options?: WriteOptions): Uint8Array;
|
|
19
19
|
export declare function writePsdBuffer(psd: Psd, options?: WriteOptions): Buffer;
|
|
20
|
+
export declare function decodeLayerPixels(layer: Layer, useImageData?: boolean): void;
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { writePsd as writePsdInternal, getWriterBuffer, createWriter, getWriterBufferNoCopy } from './psdWriter';
|
|
2
|
-
import { readPsd as readPsdInternal, createReader } from './psdReader';
|
|
2
|
+
import { readPsd as readPsdInternal, createReader, decodeLayerImageData } from './psdReader';
|
|
3
3
|
import { fromByteArray } from 'base64-js';
|
|
4
4
|
export * from './abr';
|
|
5
5
|
export * from './csh';
|
|
@@ -28,3 +28,6 @@ export function writePsdBuffer(psd, options) {
|
|
|
28
28
|
}
|
|
29
29
|
return Buffer.from(writePsdUint8Array(psd, options));
|
|
30
30
|
}
|
|
31
|
+
export function decodeLayerPixels(layer, useImageData) {
|
|
32
|
+
decodeLayerImageData(layer, useImageData);
|
|
33
|
+
}
|