ag-psd 33.0.0 → 34.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/.v8-cache/v24.7.0-x64-ef5a0af0/05135617 +0 -0
- package/.v8-cache/v24.7.0-x64-ef5a0af0/226e2801 +0 -0
- package/.v8-cache/v24.7.0-x64-ef5a0af0/4511bacf +0 -0
- package/.v8-cache/v24.7.0-x64-ef5a0af0/68416cb2 +0 -0
- package/.v8-cache/v24.7.0-x64-ef5a0af0/71df9cb3 +0 -0
- package/.v8-cache/v24.7.0-x64-ef5a0af0/7ea06cea +0 -0
- package/.v8-cache/v24.7.0-x64-ef5a0af0/87cf2209 +0 -0
- package/.v8-cache/v24.7.0-x64-ef5a0af0/932f0770 +0 -0
- package/.v8-cache/v24.7.0-x64-ef5a0af0/acc36e66 +0 -0
- package/.v8-cache/v24.7.0-x64-ef5a0af0/b3c2fab7 +0 -0
- package/.v8-cache/v24.7.0-x64-ef5a0af0/c0b789d2 +0 -0
- package/.v8-cache/v24.7.0-x64-ef5a0af0/c314aece +0 -0
- package/.v8-cache/v24.7.0-x64-ef5a0af0/cfc49f4f +0 -0
- package/.v8-cache/v24.7.0-x64-ef5a0af0/d13d7610 +0 -0
- package/.v8-cache/v24.7.0-x64-ef5a0af0/dc86f000 +0 -0
- package/.v8-cache/v24.7.0-x64-ef5a0af0/e03e2acd +0 -0
- package/.v8-cache/v24.7.0-x64-ef5a0af0/e6b99945 +0 -0
- package/CHANGELOG.md +28 -0
- package/README.md +12 -1
- package/README_PSD.md +26 -10
- package/TODO.md +9 -94
- package/dist/abr.js +12 -7
- package/dist/abr.js.map +1 -1
- package/dist/additionalInfo.d.ts +2 -0
- package/dist/additionalInfo.js +375 -78
- package/dist/additionalInfo.js.map +1 -1
- package/dist/bundle.js +1661 -407
- package/dist/descriptor.d.ts +14 -5
- package/dist/descriptor.js +102 -64
- package/dist/descriptor.js.map +1 -1
- package/dist/helpers.d.ts +6 -0
- package/dist/helpers.js +242 -2
- package/dist/helpers.js.map +1 -1
- package/dist/imageResources.d.ts +2 -0
- package/dist/imageResources.js +113 -7
- package/dist/imageResources.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.js +6 -1
- package/dist/index.js.map +1 -1
- package/dist/psd.d.ts +171 -22
- package/dist/psd.js.map +1 -1
- package/dist/psdReader.d.ts +5 -1
- package/dist/psdReader.js +295 -120
- package/dist/psdReader.js.map +1 -1
- package/dist/psdWriter.d.ts +1 -0
- package/dist/psdWriter.js +336 -91
- package/dist/psdWriter.js.map +1 -1
- package/dist/text.d.ts +32 -1
- package/dist/text.js +58 -0
- package/dist/text.js.map +1 -1
- package/dist-es/abr.js +12 -7
- package/dist-es/abr.js.map +1 -1
- package/dist-es/additionalInfo.d.ts +2 -0
- package/dist-es/additionalInfo.js +375 -78
- package/dist-es/additionalInfo.js.map +1 -1
- package/dist-es/descriptor.d.ts +14 -5
- package/dist-es/descriptor.js +102 -64
- package/dist-es/descriptor.js.map +1 -1
- package/dist-es/helpers.d.ts +6 -0
- package/dist-es/helpers.js +242 -2
- package/dist-es/helpers.js.map +1 -1
- package/dist-es/imageResources.d.ts +2 -0
- package/dist-es/imageResources.js +113 -7
- package/dist-es/imageResources.js.map +1 -1
- package/dist-es/index.d.ts +3 -2
- package/dist-es/index.js +6 -1
- package/dist-es/index.js.map +1 -1
- package/dist-es/psd.d.ts +171 -22
- package/dist-es/psd.js.map +1 -1
- package/dist-es/psdReader.d.ts +5 -1
- package/dist-es/psdReader.js +295 -120
- package/dist-es/psdReader.js.map +1 -1
- package/dist-es/psdWriter.d.ts +1 -0
- package/dist-es/psdWriter.js +336 -91
- package/dist-es/psdWriter.js.map +1 -1
- package/dist-es/text.d.ts +32 -1
- package/dist-es/text.js +58 -0
- package/dist-es/text.js.map +1 -1
- package/fuzz.js +808 -0
- package/package.json +1 -1
- package/perf.js +312 -9
- package/src/abr.ts +14 -7
- package/src/additionalInfo.ts +448 -91
- package/src/descriptor.ts +103 -58
- package/src/helpers.ts +262 -2
- package/src/imageResources.ts +138 -7
- package/src/index.ts +3 -2
- package/src/psd.ts +145 -22
- package/src/psdReader.ts +315 -118
- package/src/psdWriter.ts +345 -90
- package/src/text.ts +76 -1
package/dist/bundle.js
CHANGED
|
@@ -245,7 +245,7 @@ function readSampleBitmap(reader, brushEnd, id) {
|
|
|
245
245
|
if (minDataSize > brushEnd - reader.offset) {
|
|
246
246
|
throw new Error('Brush sample data out of bounds');
|
|
247
247
|
}
|
|
248
|
-
(0, psdReader_1.consumeMemory)(reader, w * h * (
|
|
248
|
+
(0, psdReader_1.consumeMemory)(reader, w * h * (bithDepth === 16 ? 3 : 1));
|
|
249
249
|
const alpha = new Uint8Array(w * h);
|
|
250
250
|
if (bithDepth === 8) {
|
|
251
251
|
if (compression === 0) {
|
|
@@ -259,21 +259,26 @@ function readSampleBitmap(reader, brushEnd, id) {
|
|
|
259
259
|
}
|
|
260
260
|
}
|
|
261
261
|
else if (bithDepth === 16) {
|
|
262
|
+
const data = new Uint16Array(w * h);
|
|
262
263
|
if (compression === 0) {
|
|
263
|
-
for (let i = 0; i <
|
|
264
|
-
|
|
264
|
+
for (let i = 0; i < data.length; i++) {
|
|
265
|
+
data[i] = (0, psdReader_1.readUint16)(reader);
|
|
265
266
|
}
|
|
266
267
|
}
|
|
267
268
|
else if (compression === 1) {
|
|
268
|
-
const data = new Uint16Array(w * h);
|
|
269
269
|
(0, psdReader_1.readDataRLE)(reader, { width: w, height: h, data }, w, h, bithDepth, 1, [0], false);
|
|
270
|
-
for (let i = 0; i < alpha.byteLength; i++) {
|
|
271
|
-
alpha[i] = data[i] >> 8; // convert to 8bit values
|
|
272
|
-
}
|
|
273
270
|
}
|
|
274
271
|
else {
|
|
275
272
|
throw new Error('Invalid compression');
|
|
276
273
|
}
|
|
274
|
+
// Photoshop uses 0-32768 range for 16bit values internally, use full 0-65535 range only if there are values outside of it
|
|
275
|
+
let max = 0;
|
|
276
|
+
for (let i = 0; i < data.length; i++)
|
|
277
|
+
max = Math.max(max, data[i]);
|
|
278
|
+
const scale = max > 32768 ? 255 / 65535 : 255 / 32768;
|
|
279
|
+
for (let i = 0; i < alpha.byteLength; i++) {
|
|
280
|
+
alpha[i] = Math.round(data[i] * scale); // convert to 8bit values
|
|
281
|
+
}
|
|
277
282
|
}
|
|
278
283
|
else {
|
|
279
284
|
throw new Error('Invalid depth');
|
|
@@ -494,7 +499,7 @@ function parseBrush(brush) {
|
|
|
494
499
|
return b;
|
|
495
500
|
}
|
|
496
501
|
|
|
497
|
-
},{"./descriptor":
|
|
502
|
+
},{"./descriptor":5,"./psdReader":14}],2:[function(require,module,exports){
|
|
498
503
|
"use strict";
|
|
499
504
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
500
505
|
exports.booleanOperations = exports.infoHandlersMap = exports.infoHandlers = void 0;
|
|
@@ -605,11 +610,77 @@ addHandler('TySh', hasKey('text'), (reader, target, leftBytes) => {
|
|
|
605
610
|
(0, psdWriter_1.writeFloat32)(writer, (_d = text.bottom) !== null && _d !== void 0 ? _d : 0);
|
|
606
611
|
// writeZeros(writer, 2);
|
|
607
612
|
});
|
|
613
|
+
// type tool info from Photoshop 5.0 and 5.5, converted to regular text data (written as 'TySh')
|
|
614
|
+
addHandler('tySh', () => false, (reader, target, left) => {
|
|
615
|
+
if ((0, psdReader_1.readInt16)(reader) !== 1)
|
|
616
|
+
throw new Error(`Invalid tySh version`);
|
|
617
|
+
const transform = [];
|
|
618
|
+
for (let i = 0; i < 6; i++)
|
|
619
|
+
transform.push((0, psdReader_1.readFloat64)(reader));
|
|
620
|
+
if ((0, psdReader_1.readInt16)(reader) !== 6)
|
|
621
|
+
throw new Error(`Invalid tySh font version`);
|
|
622
|
+
const data = { transform, faces: [], styles: [], lines: [], color: { r: 0, g: 0, b: 0 }, antiAlias: false };
|
|
623
|
+
const facesCount = (0, psdReader_1.readInt16)(reader);
|
|
624
|
+
for (let i = 0; i < facesCount; i++) {
|
|
625
|
+
const mark = (0, psdReader_1.readInt16)(reader);
|
|
626
|
+
(0, psdReader_1.readInt32)(reader); // font type
|
|
627
|
+
const name = (0, psdReader_1.readPascalString)(reader, 1);
|
|
628
|
+
const familyName = (0, psdReader_1.readPascalString)(reader, 1);
|
|
629
|
+
const styleName = (0, psdReader_1.readPascalString)(reader, 1);
|
|
630
|
+
const script = (0, psdReader_1.readInt16)(reader);
|
|
631
|
+
const axesCount = (0, psdReader_1.readInt32)(reader);
|
|
632
|
+
if (axesCount < 0 || axesCount * 4 > left())
|
|
633
|
+
throw new Error(`Invalid tySh design axes count`);
|
|
634
|
+
(0, psdReader_1.skipBytes)(reader, axesCount * 4);
|
|
635
|
+
data.faces.push({ mark, name, familyName, styleName, script });
|
|
636
|
+
}
|
|
637
|
+
const stylesCount = (0, psdReader_1.readInt16)(reader);
|
|
638
|
+
for (let i = 0; i < stylesCount; i++) {
|
|
639
|
+
const mark = (0, psdReader_1.readInt16)(reader);
|
|
640
|
+
const faceMark = (0, psdReader_1.readInt16)(reader);
|
|
641
|
+
const size = (0, psdReader_1.readInt32)(reader);
|
|
642
|
+
const tracking = (0, psdReader_1.readInt32)(reader);
|
|
643
|
+
const kerning = (0, psdReader_1.readInt32)(reader);
|
|
644
|
+
const leading = (0, psdReader_1.readInt32)(reader);
|
|
645
|
+
const baselineShift = (0, psdReader_1.readInt32)(reader);
|
|
646
|
+
const autoKerning = !!(0, psdReader_1.readUint8)(reader);
|
|
647
|
+
(0, psdReader_1.readUint8)(reader); // rotate
|
|
648
|
+
data.styles.push({ mark, faceMark, size, tracking, kerning, leading, baselineShift, autoKerning });
|
|
649
|
+
}
|
|
650
|
+
(0, psdReader_1.readInt16)(reader); // type (0 = point, 1 = paragraph)
|
|
651
|
+
(0, psdReader_1.readInt32)(reader); // scaling factor
|
|
652
|
+
(0, psdReader_1.readInt32)(reader); // character count
|
|
653
|
+
(0, psdReader_1.readInt32)(reader); // horizontal placement
|
|
654
|
+
(0, psdReader_1.readInt32)(reader); // vertical placement
|
|
655
|
+
(0, psdReader_1.readInt32)(reader); // select start
|
|
656
|
+
(0, psdReader_1.readInt32)(reader); // select end
|
|
657
|
+
const linesCount = (0, psdReader_1.readInt16)(reader);
|
|
658
|
+
for (let i = 0; i < linesCount; i++) {
|
|
659
|
+
const charCount = (0, psdReader_1.readInt32)(reader);
|
|
660
|
+
const orientation = (0, psdReader_1.readInt16)(reader);
|
|
661
|
+
const alignment = (0, psdReader_1.readInt16)(reader);
|
|
662
|
+
if (charCount < 0 || charCount * 4 > left())
|
|
663
|
+
throw new Error(`Invalid tySh character count`);
|
|
664
|
+
const chars = [];
|
|
665
|
+
for (let j = 0; j < charCount; j++) {
|
|
666
|
+
const code = (0, psdReader_1.readUint16)(reader);
|
|
667
|
+
const style = (0, psdReader_1.readInt16)(reader);
|
|
668
|
+
chars.push({ code, style });
|
|
669
|
+
}
|
|
670
|
+
data.lines.push({ orientation, alignment, chars });
|
|
671
|
+
}
|
|
672
|
+
data.color = (0, psdReader_1.readColor)(reader);
|
|
673
|
+
data.antiAlias = !!(0, psdReader_1.readUint8)(reader);
|
|
674
|
+
if (!target.text)
|
|
675
|
+
target.text = (0, text_1.decodeLegacyTextData)(data);
|
|
676
|
+
(0, psdReader_1.skipBytes)(reader, left());
|
|
677
|
+
}, () => { });
|
|
608
678
|
// vector fills
|
|
609
679
|
addHandler('SoCo', target => target.vectorFill !== undefined && target.vectorStroke === undefined &&
|
|
610
|
-
target.vectorFill.type === 'color', (reader, target) => {
|
|
680
|
+
target.vectorFill.type === 'color', (reader, target, left) => {
|
|
611
681
|
const descriptor = (0, descriptor_1.readVersionAndDescriptor)(reader);
|
|
612
682
|
target.vectorFill = (0, descriptor_1.parseVectorContent)(descriptor);
|
|
683
|
+
(0, psdReader_1.skipBytes)(reader, left());
|
|
613
684
|
}, (writer, target) => {
|
|
614
685
|
const { descriptor } = (0, descriptor_1.serializeVectorContent)(target.vectorFill);
|
|
615
686
|
(0, descriptor_1.writeVersionAndDescriptor)(writer, '', 'null', descriptor);
|
|
@@ -686,6 +757,8 @@ function readVectorMask(reader, vectorMask, width, height, size) {
|
|
|
686
757
|
case 2: // Closed subpath Bezier knot, unlinked
|
|
687
758
|
case 4: // Open subpath Bezier knot, linked
|
|
688
759
|
case 5: // Open subpath Bezier knot, unlinked
|
|
760
|
+
if (!path)
|
|
761
|
+
throw new Error('Bezier knot record without subpath length record');
|
|
689
762
|
path.knots.push({ linked: (selector === 1 || selector === 4), points: readBezierKnot(reader, width, height) });
|
|
690
763
|
break;
|
|
691
764
|
case 6: // Path fill rule record
|
|
@@ -898,10 +971,10 @@ addHandler('lmfx', target => target.effects !== undefined && !isGroupLayer(targe
|
|
|
898
971
|
const desc = (0, descriptor_1.readVersionAndDescriptor)(reader);
|
|
899
972
|
// console.log('READ', require('util').inspect(desc, false, 99, true));
|
|
900
973
|
// discard if read in 'lrFX' or 'lfx2' section
|
|
901
|
-
target.effects = (0, descriptor_1.parseEffects)(desc,
|
|
974
|
+
target.effects = (0, descriptor_1.parseEffects)(desc, reader);
|
|
902
975
|
(0, psdReader_1.skipBytes)(reader, left());
|
|
903
|
-
}, (writer, target
|
|
904
|
-
const desc = (0, descriptor_1.serializeEffects)(target.effects,
|
|
976
|
+
}, (writer, target) => {
|
|
977
|
+
const desc = (0, descriptor_1.serializeEffects)(target.effects, writer, true);
|
|
905
978
|
// console.log('WRITE', require('util').inspect(desc, false, 99, true));
|
|
906
979
|
(0, psdWriter_1.writeUint32)(writer, 0); // version
|
|
907
980
|
(0, descriptor_1.writeVersionAndDescriptor)(writer, '', 'null', desc);
|
|
@@ -1036,6 +1109,58 @@ addHandler('lmgm', hasKey('layerMaskAsGlobalMask'), (reader, target) => {
|
|
|
1036
1109
|
(0, psdWriter_1.writeUint8)(writer, target.layerMaskAsGlobalMask ? 1 : 0);
|
|
1037
1110
|
(0, psdWriter_1.writeZeros)(writer, 3);
|
|
1038
1111
|
});
|
|
1112
|
+
addHandler('vmgm', hasKey('vectorMaskAsGlobalMask'), (reader, target) => {
|
|
1113
|
+
target.vectorMaskAsGlobalMask = !!(0, psdReader_1.readUint8)(reader);
|
|
1114
|
+
(0, psdReader_1.skipBytes)(reader, 3);
|
|
1115
|
+
}, (writer, target) => {
|
|
1116
|
+
(0, psdWriter_1.writeUint8)(writer, target.vectorMaskAsGlobalMask ? 1 : 0);
|
|
1117
|
+
(0, psdWriter_1.writeZeros)(writer, 3);
|
|
1118
|
+
});
|
|
1119
|
+
addHandler('ffxi', hasKey('foreignEffectId'), (reader, target) => {
|
|
1120
|
+
target.foreignEffectId = (0, psdReader_1.readInt32)(reader);
|
|
1121
|
+
}, (writer, target) => {
|
|
1122
|
+
(0, psdWriter_1.writeInt32)(writer, target.foreignEffectId);
|
|
1123
|
+
});
|
|
1124
|
+
addHandler('shpa', hasKey('patternData'), (reader, target, left) => {
|
|
1125
|
+
if ((0, psdReader_1.readInt32)(reader) !== 0)
|
|
1126
|
+
throw new Error(`Invalid shpa version`);
|
|
1127
|
+
const count = (0, psdReader_1.readInt32)(reader);
|
|
1128
|
+
target.patternData = [];
|
|
1129
|
+
for (let i = 0; i < count && left() > 0; i++) {
|
|
1130
|
+
const signature = (0, psdReader_1.readSignature)(reader);
|
|
1131
|
+
const key = (0, psdReader_1.readSignature)(reader);
|
|
1132
|
+
const patternsCount = (0, psdReader_1.readInt32)(reader);
|
|
1133
|
+
const copyOnSheetDuplication = !!(0, psdReader_1.readUint8)(reader);
|
|
1134
|
+
(0, psdReader_1.skipBytes)(reader, 3);
|
|
1135
|
+
const patterns = [];
|
|
1136
|
+
for (let j = 0; j < patternsCount && left() > 0; j++) {
|
|
1137
|
+
const colorHandling = descriptor_1.patternColorHandling.decode('.' + (0, psdReader_1.readSignature)(reader));
|
|
1138
|
+
(0, psdReader_1.readPascalString)(reader, 1); // name
|
|
1139
|
+
const name = (0, psdReader_1.readUnicodeString)(reader);
|
|
1140
|
+
const id = (0, psdReader_1.readPascalString)(reader, 1);
|
|
1141
|
+
patterns.push({ colorHandling, name, id });
|
|
1142
|
+
}
|
|
1143
|
+
target.patternData.push({ signature, key, copyOnSheetDuplication, patterns });
|
|
1144
|
+
}
|
|
1145
|
+
(0, psdReader_1.skipBytes)(reader, left());
|
|
1146
|
+
}, (writer, target) => {
|
|
1147
|
+
const sets = target.patternData;
|
|
1148
|
+
(0, psdWriter_1.writeInt32)(writer, 0); // version
|
|
1149
|
+
(0, psdWriter_1.writeInt32)(writer, sets.length);
|
|
1150
|
+
for (const set of sets) {
|
|
1151
|
+
(0, psdWriter_1.writeSignature)(writer, set.signature);
|
|
1152
|
+
(0, psdWriter_1.writeSignature)(writer, set.key);
|
|
1153
|
+
(0, psdWriter_1.writeInt32)(writer, set.patterns.length);
|
|
1154
|
+
(0, psdWriter_1.writeUint8)(writer, set.copyOnSheetDuplication ? 1 : 0);
|
|
1155
|
+
(0, psdWriter_1.writeZeros)(writer, 3);
|
|
1156
|
+
for (const pattern of set.patterns) {
|
|
1157
|
+
(0, psdWriter_1.writeSignature)(writer, descriptor_1.patternColorHandling.encode(pattern.colorHandling).split('.')[1]);
|
|
1158
|
+
(0, psdWriter_1.writePascalString)(writer, pattern.name.replace(/[^\x20-\x7e]/g, '?'), 1);
|
|
1159
|
+
(0, psdWriter_1.writeUnicodeString)(writer, pattern.name);
|
|
1160
|
+
(0, psdWriter_1.writePascalString)(writer, pattern.id, 1);
|
|
1161
|
+
}
|
|
1162
|
+
}
|
|
1163
|
+
});
|
|
1039
1164
|
addHandler('lspf', hasKey('protected'), (reader, target) => {
|
|
1040
1165
|
const flags = (0, psdReader_1.readUint32)(reader);
|
|
1041
1166
|
target.protected = {
|
|
@@ -1140,7 +1265,7 @@ target => target.timestamp !== undefined || target.animationFrames !== undefined
|
|
|
1140
1265
|
if (f.FXRf)
|
|
1141
1266
|
frame.referencePoint = (0, descriptor_1.horzVrtcToXY)(f.FXRf);
|
|
1142
1267
|
if (f.Lefx)
|
|
1143
|
-
frame.effects = (0, descriptor_1.parseEffects)(f.Lefx,
|
|
1268
|
+
frame.effects = (0, descriptor_1.parseEffects)(f.Lefx, reader);
|
|
1144
1269
|
if (f.blendOptions && f.blendOptions.Opct)
|
|
1145
1270
|
frame.opacity = (0, descriptor_1.parsePercent)(f.blendOptions.Opct);
|
|
1146
1271
|
target.animationFrames.push(frame);
|
|
@@ -1171,7 +1296,7 @@ target => target.timestamp !== undefined || target.animationFrames !== undefined
|
|
|
1171
1296
|
audioLevel: desc.audioLevel,
|
|
1172
1297
|
};
|
|
1173
1298
|
if (desc.trackList) {
|
|
1174
|
-
timeline.tracks = (0, descriptor_1.parseTrackList)(desc.trackList,
|
|
1299
|
+
timeline.tracks = (0, descriptor_1.parseTrackList)(desc.trackList, reader);
|
|
1175
1300
|
}
|
|
1176
1301
|
target.timeline = timeline;
|
|
1177
1302
|
// console.log('tmln:result', target.name, target.id, require('util').inspect(timeline, false, 99, true));
|
|
@@ -1253,7 +1378,7 @@ target => target.timestamp !== undefined || target.animationFrames !== undefined
|
|
|
1253
1378
|
if (f.referencePoint)
|
|
1254
1379
|
frame.FXRf = (0, descriptor_1.xyToHorzVrtc)(f.referencePoint);
|
|
1255
1380
|
if (f.effects)
|
|
1256
|
-
frame.Lefx = (0, descriptor_1.serializeEffects)(f.effects,
|
|
1381
|
+
frame.Lefx = (0, descriptor_1.serializeEffects)(f.effects, writer, hasMultiEffects(f.effects));
|
|
1257
1382
|
if (f.opacity !== undefined)
|
|
1258
1383
|
frame.blendOptions = { Opct: (0, descriptor_1.unitsPercentF)(f.opacity) };
|
|
1259
1384
|
desc.LaSt.push(frame);
|
|
@@ -1293,7 +1418,7 @@ target => target.timestamp !== undefined || target.animationFrames !== undefined
|
|
|
1293
1418
|
audioLevel: timeline.audioLevel,
|
|
1294
1419
|
};
|
|
1295
1420
|
if (timeline.tracks) {
|
|
1296
|
-
desc.trackList = (0, descriptor_1.serializeTrackList)(timeline.tracks);
|
|
1421
|
+
desc.trackList = (0, descriptor_1.serializeTrackList)(timeline.tracks, writer);
|
|
1297
1422
|
}
|
|
1298
1423
|
desc.LyrI = getLayerId(target, options);
|
|
1299
1424
|
// console.log('WRITE:tmln', target.name, target.id, require('util').inspect(desc, false, 99, true));
|
|
@@ -1672,6 +1797,86 @@ function pointToHrznVrtc(point) {
|
|
|
1672
1797
|
Vrtc: (0, descriptor_1.unitsValue)(point.y, 'y'),
|
|
1673
1798
|
};
|
|
1674
1799
|
}
|
|
1800
|
+
// Camera Raw Filter setting paths (in CameraRawFilterSettings) and their descriptor keys
|
|
1801
|
+
const cameraRawColorKeys = [
|
|
1802
|
+
['red', 'R'], ['orange', 'O'], ['yellow', 'Y'], ['green', 'G'], ['aqua', 'A'], ['blue', 'B'], ['purple', 'P'], ['magenta', 'M'],
|
|
1803
|
+
];
|
|
1804
|
+
const cameraRawSettings = [
|
|
1805
|
+
['version', 'CrVe'], ['processVersion', 'PrVN'], ['processVersionCode', 'PrVe'], ['whiteBalance', 'WBal'],
|
|
1806
|
+
['temperature', 'Temp'], ['tint', 'Tint'], ['exposure', 'Ex12'], ['contrast', 'Cr12'], ['highlights', 'Hi12'],
|
|
1807
|
+
['shadows', 'Sh12'], ['whites', 'Wh12'], ['blacks', 'Bk12'], ['texture', 'CrTx'], ['clarity', 'Cl12'],
|
|
1808
|
+
['dehaze', 'Dhze'], ['vibrance', 'Vibr'], ['saturation', 'Strt'],
|
|
1809
|
+
['parametricCurve.shadows', 'PC_S'], ['parametricCurve.darks', 'PC_D'], ['parametricCurve.lights', 'PC_L'],
|
|
1810
|
+
['parametricCurve.highlights', 'PC_H'], ['parametricCurve.shadowSplit', 'PC_1'], ['parametricCurve.midtoneSplit', 'PC_2'],
|
|
1811
|
+
['parametricCurve.highlightSplit', 'PC_3'],
|
|
1812
|
+
['pointCurve.composite', 'Crv '], ['pointCurve.red', 'CrvR'], ['pointCurve.green', 'CrvG'], ['pointCurve.blue', 'CrvB'],
|
|
1813
|
+
...cameraRawColorKeys.map(([name, key]) => [`hsl.hue.${name}`, `HA_${key}`]),
|
|
1814
|
+
...cameraRawColorKeys.map(([name, key]) => [`hsl.saturation.${name}`, `SA_${key}`]),
|
|
1815
|
+
...cameraRawColorKeys.map(([name, key]) => [`hsl.luminance.${name}`, `LA_${key}`]),
|
|
1816
|
+
['colorGrading.shadows.hue', 'STSH'], ['colorGrading.shadows.saturation', 'STSS'], ['colorGrading.shadows.luminance', 'CgSL'],
|
|
1817
|
+
['colorGrading.midtones.hue', 'CgMH'], ['colorGrading.midtones.saturation', 'CgMS'], ['colorGrading.midtones.luminance', 'CgML'],
|
|
1818
|
+
['colorGrading.highlights.hue', 'STHH'], ['colorGrading.highlights.saturation', 'STHS'], ['colorGrading.highlights.luminance', 'CgHL'],
|
|
1819
|
+
['colorGrading.global.hue', 'CgGH'], ['colorGrading.global.saturation', 'CgGS'], ['colorGrading.global.luminance', 'CgGL'],
|
|
1820
|
+
['colorGrading.blending', 'CgBl'], ['colorGrading.balance', 'STB '],
|
|
1821
|
+
['sharpening.amount', 'Shrp'], ['sharpening.radius', 'ShpR'], ['sharpening.detail', 'ShpD'], ['sharpening.masking', 'ShpM'],
|
|
1822
|
+
['noiseReduction.luminance', 'LNR '], ['noiseReduction.luminanceDetail', 'LNRD'], ['noiseReduction.luminanceContrast', 'LNRC'],
|
|
1823
|
+
['noiseReduction.color', 'CNR '], ['noiseReduction.colorDetail', 'CNRD'], ['noiseReduction.colorSmoothness', 'CNRS'],
|
|
1824
|
+
['grain.amount', 'GRNA'], ['grain.size', 'GRNS'], ['grain.roughness', 'GRNF'],
|
|
1825
|
+
['postCropVignette.amount', 'PCVA'], ['postCropVignette.midpoint', 'PCVM'], ['postCropVignette.feather', 'PCVF'],
|
|
1826
|
+
['postCropVignette.roundness', 'PCVR'],
|
|
1827
|
+
];
|
|
1828
|
+
const cameraRawCurveKeys = ['Crv ', 'CrvR', 'CrvG', 'CrvB'];
|
|
1829
|
+
const cameraRawFilterID = 2783;
|
|
1830
|
+
function parseCameraRawSettings(desc, reader) {
|
|
1831
|
+
var _a;
|
|
1832
|
+
const settings = {};
|
|
1833
|
+
for (const [path, key] of cameraRawSettings) {
|
|
1834
|
+
let value = desc[key];
|
|
1835
|
+
if (value === undefined)
|
|
1836
|
+
continue;
|
|
1837
|
+
if (key === 'WBal') {
|
|
1838
|
+
value = value.split('.')[1];
|
|
1839
|
+
}
|
|
1840
|
+
else if (cameraRawCurveKeys.includes(key)) {
|
|
1841
|
+
const values = value;
|
|
1842
|
+
value = [];
|
|
1843
|
+
for (let i = 0; i + 1 < values.length; i += 2)
|
|
1844
|
+
value.push({ input: values[i], output: values[i + 1] });
|
|
1845
|
+
}
|
|
1846
|
+
const parts = path.split('.');
|
|
1847
|
+
let target = settings;
|
|
1848
|
+
for (let i = 0; i < parts.length - 1; i++)
|
|
1849
|
+
target = target[parts[i]] = (_a = target[parts[i]]) !== null && _a !== void 0 ? _a : {};
|
|
1850
|
+
target[parts[parts.length - 1]] = value;
|
|
1851
|
+
}
|
|
1852
|
+
for (const key of Object.keys(desc)) {
|
|
1853
|
+
if (key !== '_name' && key !== '_classID' && !cameraRawSettings.some(s => s[1] === key)) {
|
|
1854
|
+
reader.logMissingFeatures && reader.log(`Unhandled Camera Raw Filter setting: ${key}`);
|
|
1855
|
+
}
|
|
1856
|
+
}
|
|
1857
|
+
return settings;
|
|
1858
|
+
}
|
|
1859
|
+
function serializeCameraRawSettings(settings) {
|
|
1860
|
+
const desc = { _name: '', _classID: descriptor_1.cameraRawFilterClassID };
|
|
1861
|
+
for (const [path, key] of cameraRawSettings) {
|
|
1862
|
+
let value = settings;
|
|
1863
|
+
for (const part of path.split('.'))
|
|
1864
|
+
value = value === null || value === void 0 ? void 0 : value[part];
|
|
1865
|
+
if (value === undefined)
|
|
1866
|
+
continue;
|
|
1867
|
+
if (key === 'WBal') {
|
|
1868
|
+
value = `WBal.${value}`;
|
|
1869
|
+
}
|
|
1870
|
+
else if (cameraRawCurveKeys.includes(key)) {
|
|
1871
|
+
value = value.flatMap(p => [Math.round(p.input), Math.round(p.output)]);
|
|
1872
|
+
}
|
|
1873
|
+
else if (typeof value === 'number' && key !== 'Ex12' && key !== 'ShpR') {
|
|
1874
|
+
value = Math.round(value);
|
|
1875
|
+
}
|
|
1876
|
+
desc[key] = value;
|
|
1877
|
+
}
|
|
1878
|
+
return desc;
|
|
1879
|
+
}
|
|
1675
1880
|
function parseFilterFXItem(f, reader) {
|
|
1676
1881
|
const base = {
|
|
1677
1882
|
name: f['Nm '],
|
|
@@ -1682,6 +1887,9 @@ function parseFilterFXItem(f, reader) {
|
|
|
1682
1887
|
foregroundColor: (0, descriptor_1.parseColor)(f.FrgC),
|
|
1683
1888
|
backgroundColor: (0, descriptor_1.parseColor)(f.BckC),
|
|
1684
1889
|
};
|
|
1890
|
+
if ('Fltr' in f && f.Fltr._classID === descriptor_1.cameraRawFilterClassID) {
|
|
1891
|
+
return Object.assign(Object.assign({}, base), { type: 'camera raw', filter: parseCameraRawSettings(f.Fltr, reader) });
|
|
1892
|
+
}
|
|
1685
1893
|
if ('Fltr' in f) {
|
|
1686
1894
|
switch (f.Fltr._classID) {
|
|
1687
1895
|
case 'boxblur': return Object.assign(Object.assign({}, base), { type: 'box blur', filter: {
|
|
@@ -2580,6 +2788,7 @@ function serializeFilterFXItem(f) {
|
|
|
2580
2788
|
return adjustment;
|
|
2581
2789
|
}),
|
|
2582
2790
|
} : {})), filterID: 1282829427 });
|
|
2791
|
+
case 'camera raw': return Object.assign(Object.assign({}, base), { Fltr: serializeCameraRawSettings(f.filter), filterID: cameraRawFilterID });
|
|
2583
2792
|
case 'brightness/contrast': return Object.assign(Object.assign({}, base), { Fltr: {
|
|
2584
2793
|
_name: 'Brightness/Contrast',
|
|
2585
2794
|
_classID: 'BrgC',
|
|
@@ -2805,31 +3014,23 @@ addHandler('LMsk', hasKey('userMask'), (reader, target) => {
|
|
|
2805
3014
|
(0, psdWriter_1.writeUint8)(writer, 128);
|
|
2806
3015
|
(0, psdWriter_1.writeZeros)(writer, 1);
|
|
2807
3016
|
});
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
}
|
|
2826
|
-
}, (writer, target, _, _options) => {
|
|
2827
|
-
const patterns = target.patterns || [];
|
|
2828
|
-
for (const pattern of patterns) {
|
|
2829
|
-
(0, psdWriter_1.writePattern)(writer, pattern);
|
|
2830
|
-
}
|
|
2831
|
-
});
|
|
2832
|
-
}
|
|
3017
|
+
addHandler('Patt', // 'Pat2' and 'Pat3' (16 and 32 bit documents) are aliases, patterns are always written as 8 bit
|
|
3018
|
+
// 'Pat2' and 'Pat3' (16 and 32 bit documents) are aliases, patterns are always written as 8 bit
|
|
3019
|
+
target => !!(target.patterns && target.patterns.length > 0), (reader, target, left) => {
|
|
3020
|
+
while (left() > 0) {
|
|
3021
|
+
const pattern = (0, psdReader_1.readPatternSafe)(reader);
|
|
3022
|
+
if (!pattern)
|
|
3023
|
+
continue;
|
|
3024
|
+
if (target.patterns === undefined)
|
|
3025
|
+
target.patterns = [];
|
|
3026
|
+
target.patterns.push(pattern);
|
|
3027
|
+
}
|
|
3028
|
+
}, (writer, target, _, _options) => {
|
|
3029
|
+
const patterns = target.patterns || [];
|
|
3030
|
+
for (const pattern of patterns) {
|
|
3031
|
+
(0, psdWriter_1.writePattern)(writer, pattern);
|
|
3032
|
+
}
|
|
3033
|
+
});
|
|
2833
3034
|
addHandlerAlias('Pat2', 'Patt');
|
|
2834
3035
|
addHandlerAlias('Pat3', 'Patt');
|
|
2835
3036
|
/*
|
|
@@ -3059,7 +3260,12 @@ function createLnkHandler(tag) {
|
|
|
3059
3260
|
const seconds = (0, psdReader_1.readFloat64)(reader);
|
|
3060
3261
|
const wholeSeconds = Math.floor(seconds);
|
|
3061
3262
|
const ms = (seconds - wholeSeconds) * 1000;
|
|
3062
|
-
|
|
3263
|
+
try {
|
|
3264
|
+
file.time = (new Date(Date.UTC(year, month, day, hour, minute, wholeSeconds, ms))).toISOString();
|
|
3265
|
+
}
|
|
3266
|
+
catch (_a) {
|
|
3267
|
+
file.time = (new Date(0)).toISOString(); // invalid date
|
|
3268
|
+
}
|
|
3063
3269
|
}
|
|
3064
3270
|
const fileSize = type === 'liFE' ? readLength64(reader) : 0;
|
|
3065
3271
|
if (type === 'liFA')
|
|
@@ -3186,6 +3392,10 @@ addHandlerAlias('lnk3', 'lnk2');
|
|
|
3186
3392
|
// unicode names of saved paths (path data is stored in image resources 2000-2998)
|
|
3187
3393
|
addHandler('pths', target => { var _a; return ((_a = target.imageResources) === null || _a === void 0 ? void 0 : _a.savedPaths) !== undefined; }, (reader, _target, left, psd) => {
|
|
3188
3394
|
var _a, _b;
|
|
3395
|
+
if (reader.imageResourcesWhitelist && !reader.imageResourcesWhitelist.includes('savedPaths')) {
|
|
3396
|
+
(0, psdReader_1.skipBytes)(reader, left());
|
|
3397
|
+
return;
|
|
3398
|
+
}
|
|
3189
3399
|
const desc = (0, descriptor_1.readVersionAndDescriptor)(reader, true);
|
|
3190
3400
|
const imageResources = (_a = psd.imageResources) !== null && _a !== void 0 ? _a : (psd.imageResources = {});
|
|
3191
3401
|
const savedPaths = (_b = imageResources.savedPaths) !== null && _b !== void 0 ? _b : (imageResources.savedPaths = []);
|
|
@@ -3221,10 +3431,10 @@ target => target.effects !== undefined && isGroupLayer(target), (reader, target,
|
|
|
3221
3431
|
if (version !== 0)
|
|
3222
3432
|
throw new Error(`Invalid lfxs version`);
|
|
3223
3433
|
const desc = (0, descriptor_1.readVersionAndDescriptor)(reader);
|
|
3224
|
-
target.effects = (0, descriptor_1.parseEffects)(desc,
|
|
3434
|
+
target.effects = (0, descriptor_1.parseEffects)(desc, reader);
|
|
3225
3435
|
(0, psdReader_1.skipBytes)(reader, left());
|
|
3226
|
-
}, (writer, target
|
|
3227
|
-
const desc = (0, descriptor_1.serializeEffects)(target.effects,
|
|
3436
|
+
}, (writer, target) => {
|
|
3437
|
+
const desc = (0, descriptor_1.serializeEffects)(target.effects, writer, true);
|
|
3228
3438
|
(0, psdWriter_1.writeUint32)(writer, 0); // version
|
|
3229
3439
|
(0, descriptor_1.writeVersionAndDescriptor)(writer, '', 'null', desc);
|
|
3230
3440
|
});
|
|
@@ -3279,11 +3489,19 @@ addHandler('levl', adjustmentType('levels'), (reader, target, left) => {
|
|
|
3279
3489
|
channels.push(readLevelsChannel(reader));
|
|
3280
3490
|
}
|
|
3281
3491
|
if (left() >= 8) {
|
|
3282
|
-
|
|
3283
|
-
|
|
3284
|
-
if (
|
|
3285
|
-
|
|
3286
|
-
|
|
3492
|
+
const signature = (0, psdReader_1.readSignature)(reader);
|
|
3493
|
+
let totalChannelRecords;
|
|
3494
|
+
if (signature === 'ls\x00\x03') {
|
|
3495
|
+
// Clip Studio Paint writes 'ls' instead of 'Lvls' signature (version is part of the read signature)
|
|
3496
|
+
totalChannelRecords = (0, psdReader_1.readUint16)(reader);
|
|
3497
|
+
}
|
|
3498
|
+
else {
|
|
3499
|
+
if (signature !== 'Lvls')
|
|
3500
|
+
throw new Error(`Invalid levl signature`);
|
|
3501
|
+
if ((0, psdReader_1.readUint16)(reader) !== 3)
|
|
3502
|
+
throw new Error(`Invalid levl version`);
|
|
3503
|
+
totalChannelRecords = (0, psdReader_1.readUint16)(reader);
|
|
3504
|
+
}
|
|
3287
3505
|
while (channels.length < totalChannelRecords && left() >= 10) {
|
|
3288
3506
|
channels.push(readLevelsChannel(reader));
|
|
3289
3507
|
}
|
|
@@ -3324,58 +3542,78 @@ function writeCurveChannel(writer, channel) {
|
|
|
3324
3542
|
}
|
|
3325
3543
|
}
|
|
3326
3544
|
addHandler('curv', adjustmentType('curves'), (reader, target, left) => {
|
|
3327
|
-
(0, psdReader_1.readUint8)(reader);
|
|
3328
|
-
|
|
3545
|
+
const isMap = !!(0, psdReader_1.readUint8)(reader); // curves drawn with pencil tool (lookup tables instead of points)
|
|
3546
|
+
const version = (0, psdReader_1.readUint16)(reader);
|
|
3547
|
+
if (version !== 1 && version !== 4)
|
|
3329
3548
|
throw new Error('Invalid curv version');
|
|
3330
|
-
(0, psdReader_1.
|
|
3331
|
-
const channelsMask = (0, psdReader_1.readUint16)(reader);
|
|
3549
|
+
const countOrMask = (0, psdReader_1.readUint32)(reader);
|
|
3332
3550
|
const channels = [];
|
|
3333
|
-
|
|
3334
|
-
|
|
3335
|
-
|
|
3551
|
+
const readChannel = () => isMap ? Array.from((0, psdReader_1.readBytes)(reader, 256)) : readCurveChannel(reader);
|
|
3552
|
+
if (version === 1) {
|
|
3553
|
+
for (let i = 0; i < 32; i++) {
|
|
3554
|
+
if (countOrMask & (1 << i)) {
|
|
3555
|
+
while (channels.length < i)
|
|
3556
|
+
channels.push([]);
|
|
3557
|
+
channels.push(readChannel());
|
|
3558
|
+
}
|
|
3559
|
+
}
|
|
3560
|
+
}
|
|
3561
|
+
else {
|
|
3562
|
+
if (countOrMask > 64)
|
|
3563
|
+
throw new Error('Invalid curv channel count');
|
|
3564
|
+
for (let i = 0; i < countOrMask; i++)
|
|
3565
|
+
channels.push(readChannel());
|
|
3566
|
+
}
|
|
3567
|
+
// extra section stores curves for all channels (including ones that don't fit in the mask)
|
|
3568
|
+
if (version === 1 && left() >= 10 && (0, psdReader_1.readSignature)(reader) === 'Crv ') {
|
|
3569
|
+
(0, psdReader_1.readUint16)(reader); // version
|
|
3570
|
+
const count = (0, psdReader_1.readUint32)(reader);
|
|
3571
|
+
for (let i = 0; i < count && left() >= 2; i++) {
|
|
3572
|
+
const index = (0, psdReader_1.readUint16)(reader);
|
|
3573
|
+
const channel = readChannel();
|
|
3574
|
+
while (channels.length < index)
|
|
3336
3575
|
channels.push([]);
|
|
3337
|
-
channels
|
|
3338
|
-
}
|
|
3339
|
-
}
|
|
3340
|
-
target.adjustment = Object.assign(Object.assign({}, target.adjustment), { type: 'curves', channels });
|
|
3341
|
-
// ignoring, duplicate information
|
|
3342
|
-
// checkSignature(reader, 'Crv ');
|
|
3343
|
-
// const cVersion = readUint16(reader);
|
|
3344
|
-
// readUint16(reader);
|
|
3345
|
-
// const channelCount = readUint16(reader);
|
|
3346
|
-
// for (let i = 0; i < channelCount; i++) {
|
|
3347
|
-
// const index = readUint16(reader);
|
|
3348
|
-
// const nodes = readUint16(reader);
|
|
3349
|
-
// for (let j = 0; j < nodes; j++) {
|
|
3350
|
-
// const output = readInt16(reader);
|
|
3351
|
-
// const input = readInt16(reader);
|
|
3352
|
-
// }
|
|
3353
|
-
// }
|
|
3576
|
+
channels[index] = channel;
|
|
3577
|
+
}
|
|
3578
|
+
}
|
|
3579
|
+
target.adjustment = Object.assign(Object.assign(Object.assign({}, target.adjustment), { type: 'curves' }), (isMap ? { values: channels } : { channels: channels }));
|
|
3354
3580
|
(0, psdReader_1.skipBytes)(reader, left());
|
|
3355
3581
|
}, (writer, target) => {
|
|
3356
3582
|
var _a;
|
|
3357
|
-
const
|
|
3583
|
+
const adjustment = target.adjustment;
|
|
3584
|
+
const isMap = !!adjustment.values;
|
|
3585
|
+
const channels = (isMap ? adjustment.values : adjustment.channels) || [];
|
|
3358
3586
|
const used = [];
|
|
3359
3587
|
let channelsMask = 0;
|
|
3360
3588
|
for (let i = 0; i < channels.length; i++) {
|
|
3361
3589
|
if ((_a = channels[i]) === null || _a === void 0 ? void 0 : _a.length) {
|
|
3362
|
-
|
|
3590
|
+
if (i < 32)
|
|
3591
|
+
channelsMask |= 1 << i;
|
|
3363
3592
|
used.push(i);
|
|
3364
3593
|
}
|
|
3365
3594
|
}
|
|
3366
|
-
(
|
|
3595
|
+
const writeChannel = (channel) => {
|
|
3596
|
+
var _a;
|
|
3597
|
+
if (isMap) {
|
|
3598
|
+
for (let i = 0; i < 256; i++)
|
|
3599
|
+
(0, psdWriter_1.writeUint8)(writer, (0, helpers_1.clamp)(Math.round((_a = channel[i]) !== null && _a !== void 0 ? _a : i), 0, 255));
|
|
3600
|
+
}
|
|
3601
|
+
else {
|
|
3602
|
+
writeCurveChannel(writer, channel);
|
|
3603
|
+
}
|
|
3604
|
+
};
|
|
3605
|
+
(0, psdWriter_1.writeUint8)(writer, isMap ? 1 : 0);
|
|
3367
3606
|
(0, psdWriter_1.writeUint16)(writer, 1); // version
|
|
3368
|
-
(0, psdWriter_1.
|
|
3369
|
-
(0, psdWriter_1.writeUint16)(writer, channelsMask);
|
|
3607
|
+
(0, psdWriter_1.writeUint32)(writer, channelsMask >>> 0);
|
|
3370
3608
|
for (const i of used)
|
|
3371
|
-
|
|
3609
|
+
if (i < 32)
|
|
3610
|
+
writeChannel(channels[i]);
|
|
3372
3611
|
(0, psdWriter_1.writeSignature)(writer, 'Crv ');
|
|
3373
3612
|
(0, psdWriter_1.writeUint16)(writer, 4); // version
|
|
3374
|
-
(0, psdWriter_1.
|
|
3375
|
-
(0, psdWriter_1.writeUint16)(writer, used.length);
|
|
3613
|
+
(0, psdWriter_1.writeUint32)(writer, used.length);
|
|
3376
3614
|
for (const i of used) {
|
|
3377
3615
|
(0, psdWriter_1.writeUint16)(writer, i);
|
|
3378
|
-
|
|
3616
|
+
writeChannel(channels[i]);
|
|
3379
3617
|
}
|
|
3380
3618
|
});
|
|
3381
3619
|
addHandler('expA', adjustmentType('exposure'), (reader, target, left) => {
|
|
@@ -3975,7 +4213,7 @@ addHandler('Txt2', hasKey('engineData'), (reader, target, left, psd) => {
|
|
|
3975
4213
|
const buffer = (0, base64_js_1.toByteArray)(target.engineData);
|
|
3976
4214
|
(0, psdWriter_1.writeBytes)(writer, buffer);
|
|
3977
4215
|
});
|
|
3978
|
-
addHandler('FEid', hasKey('filterEffectsMasks'), (reader, target, leftBytes) => {
|
|
4216
|
+
addHandler('FEid', hasKey('filterEffectsMasks'), (reader, target, leftBytes, psd) => {
|
|
3979
4217
|
const version = (0, psdReader_1.readInt32)(reader);
|
|
3980
4218
|
if (version < 1 || version > 3)
|
|
3981
4219
|
throw new Error(`Invalid filterEffects version ${version}`);
|
|
@@ -4017,7 +4255,7 @@ addHandler('FEid', hasKey('filterEffectsMasks'), (reader, target, leftBytes) =>
|
|
|
4017
4255
|
channels.push(undefined);
|
|
4018
4256
|
}
|
|
4019
4257
|
}
|
|
4020
|
-
target.filterEffectsMasks.push({ id, top, left, bottom, right, depth, channels });
|
|
4258
|
+
target.filterEffectsMasks.push({ id, top, left, bottom, right, depth, colorMode: psd.colorMode, channels });
|
|
4021
4259
|
if (reader.offset < end && (0, psdReader_1.readUint8)(reader)) {
|
|
4022
4260
|
const top = (0, psdReader_1.readInt32)(reader);
|
|
4023
4261
|
const left = (0, psdReader_1.readInt32)(reader);
|
|
@@ -4087,6 +4325,10 @@ addHandler('FEid', hasKey('filterEffectsMasks'), (reader, target, leftBytes) =>
|
|
|
4087
4325
|
}
|
|
4088
4326
|
});
|
|
4089
4327
|
addHandlerAlias('FXid', 'FEid');
|
|
4328
|
+
addHandlerAlias('FELS', 'FEid'); // filter effects 3
|
|
4329
|
+
addHandlerAlias('hue ', 'hue2'); // old hue/saturation (Photoshop 4.0), same structure as 'hue2'
|
|
4330
|
+
addHandlerAlias('plLd', 'PlLd'); // old placed layer key
|
|
4331
|
+
addHandlerAlias('abdd', 'artb'); // artboard data 3
|
|
4090
4332
|
addHandler('FMsk', hasKey('filterMask'), (reader, target) => {
|
|
4091
4333
|
target.filterMask = {
|
|
4092
4334
|
colorSpace: (0, psdReader_1.readColor)(reader),
|
|
@@ -4147,10 +4389,10 @@ addHandler('lfx2', target => target.effects !== undefined && !isGroupLayer(targe
|
|
|
4147
4389
|
const desc = (0, descriptor_1.readVersionAndDescriptor)(reader);
|
|
4148
4390
|
// console.log('READ', require('util').inspect(desc, false, 99, true));
|
|
4149
4391
|
// discard if read in 'lrFX' section ('lmfx' and 'lfx2' are never stored together)
|
|
4150
|
-
target.effects = (0, descriptor_1.parseEffects)(desc,
|
|
4392
|
+
target.effects = (0, descriptor_1.parseEffects)(desc, reader);
|
|
4151
4393
|
(0, psdReader_1.skipBytes)(reader, left());
|
|
4152
|
-
}, (writer, target
|
|
4153
|
-
const desc = (0, descriptor_1.serializeEffects)(target.effects,
|
|
4394
|
+
}, (writer, target) => {
|
|
4395
|
+
const desc = (0, descriptor_1.serializeEffects)(target.effects, writer, true);
|
|
4154
4396
|
// console.log('WRITE', require('util').inspect(desc, false, 99, true));
|
|
4155
4397
|
(0, psdWriter_1.writeUint32)(writer, 0); // version
|
|
4156
4398
|
(0, descriptor_1.writeVersionAndDescriptor)(writer, '', 'null', desc);
|
|
@@ -4212,6 +4454,66 @@ addHandler('extn', target => target.generatorSettings !== undefined && isDocumen
|
|
|
4212
4454
|
}, (writer, target) => {
|
|
4213
4455
|
(0, descriptor_1.writeVersionAndDescriptor)(writer, '', 'null', serializeGeneratorSettings(target.generatorSettings));
|
|
4214
4456
|
});
|
|
4457
|
+
// generator settings stored by older versions of Photoshop (written back in 'shmd' or 'extn' section)
|
|
4458
|
+
addHandler('extd', () => false, (reader, target, left) => {
|
|
4459
|
+
const desc = (0, descriptor_1.readVersionAndDescriptor)(reader);
|
|
4460
|
+
if (desc.generatorSettings && target.generatorSettings === undefined) {
|
|
4461
|
+
target.generatorSettings = parseGeneratorSettings(desc.generatorSettings);
|
|
4462
|
+
}
|
|
4463
|
+
(0, psdReader_1.skipBytes)(reader, left());
|
|
4464
|
+
}, () => { });
|
|
4465
|
+
addHandler('frgb', // frame tool group
|
|
4466
|
+
hasKey('framedGroup'), (reader, target, left) => {
|
|
4467
|
+
const desc = (0, descriptor_1.readVersionAndDescriptor)(reader);
|
|
4468
|
+
const rect = desc.framedGroupRect;
|
|
4469
|
+
target.framedGroup = {
|
|
4470
|
+
rect: { top: rect['Top '], left: rect.Left, bottom: rect.Btom, right: rect.Rght },
|
|
4471
|
+
type: desc.framedGroupType,
|
|
4472
|
+
};
|
|
4473
|
+
if (desc.LockPPI !== undefined)
|
|
4474
|
+
target.framedGroup.lockPPI = desc.LockPPI;
|
|
4475
|
+
if (desc.PreferredResolution !== undefined)
|
|
4476
|
+
target.framedGroup.preferredResolution = desc.PreferredResolution;
|
|
4477
|
+
if (desc.SavedIteratedName !== undefined)
|
|
4478
|
+
target.framedGroup.savedIteratedName = desc.SavedIteratedName;
|
|
4479
|
+
(0, psdReader_1.skipBytes)(reader, left());
|
|
4480
|
+
}, (writer, target) => {
|
|
4481
|
+
const group = target.framedGroup;
|
|
4482
|
+
const rect = group.rect;
|
|
4483
|
+
const desc = {
|
|
4484
|
+
framedGroupRect: { _name: '', _classID: 'classFloatRect', 'Top ': rect.top, Left: rect.left, Btom: rect.bottom, Rght: rect.right },
|
|
4485
|
+
framedGroupType: group.type,
|
|
4486
|
+
};
|
|
4487
|
+
if (group.lockPPI !== undefined)
|
|
4488
|
+
desc.LockPPI = group.lockPPI;
|
|
4489
|
+
if (group.preferredResolution !== undefined)
|
|
4490
|
+
desc.PreferredResolution = group.preferredResolution;
|
|
4491
|
+
if (group.savedIteratedName !== undefined)
|
|
4492
|
+
desc.SavedIteratedName = group.savedIteratedName;
|
|
4493
|
+
(0, descriptor_1.writeVersionAndDescriptor)(writer, '', 'framedGroup', desc);
|
|
4494
|
+
});
|
|
4495
|
+
addHandler('anFX', hasKey('animationEffects'), (reader, target, left) => {
|
|
4496
|
+
target.animationEffects = (0, psdReader_1.readBytes)(reader, left());
|
|
4497
|
+
}, (writer, target) => {
|
|
4498
|
+
(0, psdWriter_1.writeBytes)(writer, target.animationEffects);
|
|
4499
|
+
});
|
|
4500
|
+
addHandler('PxSD', // pixel source data 2 (video layer frames)
|
|
4501
|
+
hasKey('pixelSourceData'), (reader, target, left) => {
|
|
4502
|
+
target.pixelSourceData = [];
|
|
4503
|
+
while (left() >= 8) {
|
|
4504
|
+
const length = readLength64(reader);
|
|
4505
|
+
if (length > left())
|
|
4506
|
+
throw new Error('Invalid PxSD data length');
|
|
4507
|
+
target.pixelSourceData.push((0, psdReader_1.readBytes)(reader, length));
|
|
4508
|
+
}
|
|
4509
|
+
(0, psdReader_1.skipBytes)(reader, left());
|
|
4510
|
+
}, (writer, target) => {
|
|
4511
|
+
for (const data of target.pixelSourceData) {
|
|
4512
|
+
(0, psdWriter_1.writeUint32)(writer, 0);
|
|
4513
|
+
(0, psdWriter_1.writeUint32)(writer, data.byteLength);
|
|
4514
|
+
(0, psdWriter_1.writeBytes)(writer, data);
|
|
4515
|
+
}
|
|
4516
|
+
});
|
|
4215
4517
|
addHandler('iOpa', hasKey('fillOpacity'), (reader, target) => {
|
|
4216
4518
|
target.fillOpacity = (0, psdReader_1.readUint8)(reader) / 0xff;
|
|
4217
4519
|
(0, psdReader_1.skipBytes)(reader, 3);
|
|
@@ -4237,7 +4539,92 @@ addHandler('tsly', hasKey('transparencyShapesLayer'), (reader, target) => {
|
|
|
4237
4539
|
(0, psdWriter_1.writeZeros)(writer, 3);
|
|
4238
4540
|
});
|
|
4239
4541
|
|
|
4240
|
-
},{"./descriptor":
|
|
4542
|
+
},{"./descriptor":5,"./effectsHelpers":6,"./engineData":7,"./engineData2":8,"./helpers":9,"./psdReader":14,"./psdWriter":15,"./text":16,"base64-js":18}],3:[function(require,module,exports){
|
|
4543
|
+
"use strict";
|
|
4544
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4545
|
+
exports.readAse = readAse;
|
|
4546
|
+
const psdReader_1 = require("./psdReader");
|
|
4547
|
+
function readAse(buffer, options = {}) {
|
|
4548
|
+
const reader = (0, psdReader_1.createReader)(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
4549
|
+
const signature = (0, psdReader_1.readSignature)(reader); // ASEF
|
|
4550
|
+
if (signature !== 'ASEF')
|
|
4551
|
+
throw new Error('Invalid signature');
|
|
4552
|
+
const versionMajor = (0, psdReader_1.readUint16)(reader); // 1
|
|
4553
|
+
(0, psdReader_1.readUint16)(reader); // minor version: 0
|
|
4554
|
+
if (versionMajor !== 1)
|
|
4555
|
+
throw new Error('Invalid version');
|
|
4556
|
+
const blocksCount = (0, psdReader_1.readUint32)(reader);
|
|
4557
|
+
const ase = { colors: [] };
|
|
4558
|
+
let group = ase;
|
|
4559
|
+
for (let i = 0; i < blocksCount && reader.offset + 6 <= reader.view.byteLength; i++) {
|
|
4560
|
+
const type = (0, psdReader_1.readUint16)(reader);
|
|
4561
|
+
const length = (0, psdReader_1.readUint32)(reader);
|
|
4562
|
+
const end = Math.min(reader.offset + length, reader.view.byteLength);
|
|
4563
|
+
// block reader, so invalid lengths can't make us read data of following blocks
|
|
4564
|
+
const block = (0, psdReader_1.createReader)(reader.view.buffer, reader.view.byteOffset + reader.offset, end - reader.offset);
|
|
4565
|
+
try {
|
|
4566
|
+
switch (type) {
|
|
4567
|
+
case 0x0001: { // color
|
|
4568
|
+
const color = readAseColor(block);
|
|
4569
|
+
if (color) {
|
|
4570
|
+
group.colors.push(color);
|
|
4571
|
+
}
|
|
4572
|
+
else {
|
|
4573
|
+
if (options.throwForMissingFeatures)
|
|
4574
|
+
throw new Error('Unsupported color mode');
|
|
4575
|
+
options.logMissingFeatures && reader.log('Skipped color with unsupported color mode');
|
|
4576
|
+
}
|
|
4577
|
+
break;
|
|
4578
|
+
}
|
|
4579
|
+
case 0xC001: { // group start
|
|
4580
|
+
const nameLength = (0, psdReader_1.readUint16)(block);
|
|
4581
|
+
const name = (0, psdReader_1.readUnicodeStringWithLength)(block, nameLength);
|
|
4582
|
+
ase.colors.push(group = { name, colors: [] });
|
|
4583
|
+
break;
|
|
4584
|
+
}
|
|
4585
|
+
case 0xC002: // group end
|
|
4586
|
+
group = ase;
|
|
4587
|
+
break;
|
|
4588
|
+
default:
|
|
4589
|
+
if (options.throwForMissingFeatures)
|
|
4590
|
+
throw new Error(`Invalid block type: ${type}`);
|
|
4591
|
+
options.logMissingFeatures && reader.log(`Skipped unknown block type: ${type}`);
|
|
4592
|
+
}
|
|
4593
|
+
}
|
|
4594
|
+
catch (e) {
|
|
4595
|
+
if (options.throwForMissingFeatures)
|
|
4596
|
+
throw e;
|
|
4597
|
+
options.logMissingFeatures && reader.log(`Skipped invalid block: ${e.message}`);
|
|
4598
|
+
}
|
|
4599
|
+
reader.offset = end;
|
|
4600
|
+
}
|
|
4601
|
+
return ase;
|
|
4602
|
+
}
|
|
4603
|
+
function readAseColor(reader) {
|
|
4604
|
+
const nameLength = (0, psdReader_1.readUint16)(reader);
|
|
4605
|
+
const name = (0, psdReader_1.readUnicodeStringWithLength)(reader, nameLength);
|
|
4606
|
+
const colorMode = (0, psdReader_1.readSignature)(reader);
|
|
4607
|
+
// NaN and infinite values are replaced with 0
|
|
4608
|
+
const value = () => {
|
|
4609
|
+
const v = (0, psdReader_1.readFloat32)(reader);
|
|
4610
|
+
return isFinite(v) ? v : 0;
|
|
4611
|
+
};
|
|
4612
|
+
// color type is sometimes missing, unknown types are treated as process (normal) colors
|
|
4613
|
+
const colorType = () => {
|
|
4614
|
+
const index = reader.offset + 2 <= reader.view.byteLength ? (0, psdReader_1.readUint16)(reader) : 2;
|
|
4615
|
+
return colorTypes[index] || 'normal';
|
|
4616
|
+
};
|
|
4617
|
+
switch (colorMode) {
|
|
4618
|
+
case 'RGB ': return { name, color: { r: value(), g: value(), b: value(), type: colorType() } };
|
|
4619
|
+
case 'CMYK': return { name, color: { c: value(), m: value(), y: value(), k: value(), type: colorType() } };
|
|
4620
|
+
case 'Gray': return { name, color: { k: value(), type: colorType() } };
|
|
4621
|
+
case 'LAB ': return { name, color: { l: value(), a: value(), b: value(), type: colorType() } };
|
|
4622
|
+
default: return undefined;
|
|
4623
|
+
}
|
|
4624
|
+
}
|
|
4625
|
+
const colorTypes = ['global', 'spot', 'normal'];
|
|
4626
|
+
|
|
4627
|
+
},{"./psdReader":14}],4:[function(require,module,exports){
|
|
4241
4628
|
"use strict";
|
|
4242
4629
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4243
4630
|
exports.readCsh = readCsh;
|
|
@@ -4274,7 +4661,7 @@ function readCsh(buffer) {
|
|
|
4274
4661
|
return csh;
|
|
4275
4662
|
}
|
|
4276
4663
|
|
|
4277
|
-
},{"./additionalInfo":2,"./psdReader":
|
|
4664
|
+
},{"./additionalInfo":2,"./psdReader":14}],5:[function(require,module,exports){
|
|
4278
4665
|
"use strict";
|
|
4279
4666
|
var __rest = (this && this.__rest) || function (s, e) {
|
|
4280
4667
|
var t = {};
|
|
@@ -4288,9 +4675,8 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
4288
4675
|
return t;
|
|
4289
4676
|
};
|
|
4290
4677
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4291
|
-
exports.
|
|
4292
|
-
exports.presetKindType = exports.prjM = exports.FlMd = exports.IntC = exports.IntE = void 0;
|
|
4293
|
-
exports.setLogErrors = setLogErrors;
|
|
4678
|
+
exports.CntE = exports.FlCl = exports.ExtR = exports.ExtT = exports.DfsM = exports.blurType = exports.Lns = exports.MztT = exports.Chnl = exports.Dstr = exports.ZZTy = exports.Wvtp = exports.SphM = exports.RplS = exports.Cnvr = exports.UndA = exports.DspM = exports.SmBQ = exports.SmBM = exports.BlrQ = exports.BlrM = exports.strokeStyleLineAlignment = exports.strokeStyleLineJoinType = exports.strokeStyleLineCapType = exports.ESliceBGColorType = exports.ESliceOrigin = exports.ESliceVertAlign = exports.ESliceHorzAlign = exports.ESliceType = exports.FrFl = exports.FStl = exports.ClrS = exports.Clry = exports.gradientInterpolationMethodType = exports.stdTrackID = exports.animInterpStyleEnum = exports.GrdT = exports.IGSr = exports.BETE = exports.BESs = exports.bvlT = exports.BESl = exports.BlnM = exports.warpStyle = exports.Annt = exports.Ornt = exports.textGridding = exports.outputSettingsRoot = exports.cameraRawFilterKeyTypes = exports.cameraRawFilterClassID = void 0;
|
|
4679
|
+
exports.patternColorHandling = exports.presetKindType = exports.prjM = exports.FlMd = exports.IntC = exports.IntE = exports.Drct = exports.WndM = void 0;
|
|
4294
4680
|
exports.readAsciiStringOrClassId = readAsciiStringOrClassId;
|
|
4295
4681
|
exports.writeAsciiStringOrClassId = writeAsciiStringOrClassId;
|
|
4296
4682
|
exports.readDescriptorStructure = readDescriptorStructure;
|
|
@@ -4344,10 +4730,6 @@ const unitsMap = {
|
|
|
4344
4730
|
'RrCm': 'Centimeters',
|
|
4345
4731
|
};
|
|
4346
4732
|
const unitsMapRev = revMap(unitsMap);
|
|
4347
|
-
let logErrors = false;
|
|
4348
|
-
function setLogErrors(value) {
|
|
4349
|
-
logErrors = value;
|
|
4350
|
-
}
|
|
4351
4733
|
function makeType(name, classID) {
|
|
4352
4734
|
return { name, classID };
|
|
4353
4735
|
}
|
|
@@ -4393,6 +4775,7 @@ const fieldToExtType = {
|
|
|
4393
4775
|
psVersion: nullType,
|
|
4394
4776
|
docDefaultNewArtboardBackgroundColor: makeType('', 'RGBC'),
|
|
4395
4777
|
artboardRect: makeType('', 'classFloatRect'),
|
|
4778
|
+
framedGroupRect: makeType('', 'classFloatRect'),
|
|
4396
4779
|
keyOriginRRectRadii: makeType('', 'radii'),
|
|
4397
4780
|
keyOriginBoxCorners: nullType,
|
|
4398
4781
|
rectangleCornerA: makeType('', 'Pnt '),
|
|
@@ -4478,7 +4861,7 @@ const fieldToArrayExtType = {
|
|
|
4478
4861
|
const typeToField = {
|
|
4479
4862
|
'TEXT': [
|
|
4480
4863
|
'Txt ', 'printerName', 'Nm ', 'Idnt', 'blackAndWhitePresetFileName', 'LUT3DFileName', 'exportOption', 'scaleSettings',
|
|
4481
|
-
'BackgroundImagePath', 'ImageSubfolderName',
|
|
4864
|
+
'BackgroundImagePath', 'ImageSubfolderName', 'SavedIteratedName',
|
|
4482
4865
|
'presetFileName', 'curvesPresetFileName', 'mixerPresetFileName', 'placed', 'description', 'reason',
|
|
4483
4866
|
'artboardPresetName', 'json', 'clipID', 'relPath', 'fullPath', 'mediaDescriptor', 'Msge',
|
|
4484
4867
|
'altTag', 'url', 'cellText', 'preset', 'KnNm', 'FPth', 'comment', 'originalPath', 'Bk ', 'pathUnicodeName',
|
|
@@ -4505,7 +4888,7 @@ const typeToField = {
|
|
|
4505
4888
|
'meshExpansion', 'meshRigidity', 'VrsM', 'VrsN', 'NmbG', 'WLMn', 'WLMx', 'AmMn', 'AmMx', 'SclH', 'SclV',
|
|
4506
4889
|
'Lvl ', 'TlNm', 'TlOf', 'FlRs', 'Thsh', 'ShrS', 'ShrE', 'FlRs', 'Vrnc', 'Strg', 'ExtS', 'ExtD',
|
|
4507
4890
|
'HrzS', 'VrtS', 'NmbR', 'EdgF', 'Ang1', 'Ang2', 'Ang3', 'Ang4', 'lastAppliedComp', 'capturedInfo',
|
|
4508
|
-
'pixelSourceType',
|
|
4891
|
+
'pixelSourceType', 'framedGroupType',
|
|
4509
4892
|
],
|
|
4510
4893
|
'enum': [
|
|
4511
4894
|
'textGridding', 'Ornt', 'warpStyle', 'warpRotate', 'Inte', 'Bltn', 'ClrS', 'BlrQ',
|
|
@@ -4529,7 +4912,7 @@ const typeToField = {
|
|
|
4529
4912
|
'materialsDisclosed', 'hasMotion', 'muted', 'Effc', 'selected', 'autoScope', 'fillCanvas',
|
|
4530
4913
|
'cellTextIsHTML', 'Smoo', 'Clsp', 'validAtPosition', 'rigidType', 'hasoptions', 'filterMaskEnable',
|
|
4531
4914
|
'filterMaskLinked', 'filterMaskExtendWithWhite', 'removeJPEGArtifact', 'Mnch', 'ExtF', 'ExtM',
|
|
4532
|
-
'moreAccurate', 'GpuY', 'LIWy', 'Cnty', 'Lnkd', 'showAlteredVideo', 'lightingOn',
|
|
4915
|
+
'moreAccurate', 'GpuY', 'LIWy', 'Cnty', 'Lnkd', 'showAlteredVideo', 'lightingOn', 'LockPPI',
|
|
4533
4916
|
],
|
|
4534
4917
|
'doub': [
|
|
4535
4918
|
'warpValue', 'warpPerspective', 'warpPerspectiveOther', 'Intr', 'Wdth', 'Hght', 'Gmm ',
|
|
@@ -4537,7 +4920,7 @@ const typeToField = {
|
|
|
4537
4920
|
'xx', 'xy', 'yx', 'yy', 'tx', 'ty', 'FrGA', 'frameRate', 'audioLevel', 'rotation',
|
|
4538
4921
|
'X ', 'Y ', 'redFloat', 'greenFloat', 'blueFloat', 'imageResolution',
|
|
4539
4922
|
'PuX0', 'PuX1', 'PuX2', 'PuX3', 'PuY0', 'PuY1', 'PuY2', 'PuY3',
|
|
4540
|
-
'stylization', 'cleanliness', 'brushScale', 'microBrush', 'specularity',
|
|
4923
|
+
'stylization', 'cleanliness', 'brushScale', 'microBrush', 'specularity', 'PreferredResolution',
|
|
4541
4924
|
],
|
|
4542
4925
|
'UntF': [
|
|
4543
4926
|
'sdwO', 'hglO', 'lagl', 'Lald', 'srgR', 'blur', 'Sftn', 'Opct', 'Dstn', 'Angl',
|
|
@@ -4566,6 +4949,12 @@ const channels = [
|
|
|
4566
4949
|
// color classes whose channel values are written as doubles ('GRYC' and 'LABC' are kept for backwards compatibility)
|
|
4567
4950
|
const doubleColorClasses = ['Grsc', 'LbCl', 'GRYC', 'LABC'];
|
|
4568
4951
|
// fallback for unknown keys, based on the type of the value
|
|
4952
|
+
exports.cameraRawFilterClassID = 'Adobe Camera Raw Filter';
|
|
4953
|
+
// types of Camera Raw Filter settings (keys clash with other descriptors so they're typed by class)
|
|
4954
|
+
exports.cameraRawFilterKeyTypes = {
|
|
4955
|
+
CrVe: 'TEXT', PrVN: 'long', PrVe: 'long', WBal: 'enum', Ex12: 'doub', ShpR: 'doub',
|
|
4956
|
+
'Crv ': 'VlLs', CrvR: 'VlLs', CrvG: 'VlLs', CrvB: 'VlLs',
|
|
4957
|
+
};
|
|
4569
4958
|
function guessOSType(value) {
|
|
4570
4959
|
if (typeof value === 'boolean')
|
|
4571
4960
|
return 'bool';
|
|
@@ -4741,8 +5130,9 @@ function readDescriptorStructure(reader, includeClass) {
|
|
|
4741
5130
|
}
|
|
4742
5131
|
exports.outputSettingsRoot = 'outputSettings';
|
|
4743
5132
|
function writeDescriptorStructure(writer, name, classId, value, root) {
|
|
4744
|
-
|
|
4745
|
-
|
|
5133
|
+
var _a;
|
|
5134
|
+
if (writer.logMissingFeatures && !classId)
|
|
5135
|
+
writer.log('Missing classId for: ', name, classId, value);
|
|
4746
5136
|
// write class structure
|
|
4747
5137
|
(0, psdWriter_1.writeUnicodeStringWithPadding)(writer, name);
|
|
4748
5138
|
if (root === exports.outputSettingsRoot && classId === 'null') {
|
|
@@ -4760,6 +5150,10 @@ function writeDescriptorStructure(writer, name, classId, value, root) {
|
|
|
4760
5150
|
let type = getTypeByKey(key, value[key], root, value);
|
|
4761
5151
|
let childRoot = root;
|
|
4762
5152
|
let extType = fieldToExtType[key];
|
|
5153
|
+
if (classId === exports.cameraRawFilterClassID) {
|
|
5154
|
+
type = (_a = exports.cameraRawFilterKeyTypes[key]) !== null && _a !== void 0 ? _a : 'long'; // other settings are integer levels
|
|
5155
|
+
childRoot = exports.cameraRawFilterClassID; // lists (curves) contain integer levels
|
|
5156
|
+
}
|
|
4763
5157
|
if (key === 'bounds' && root === 'text') {
|
|
4764
5158
|
extType = makeType('', 'bounds');
|
|
4765
5159
|
}
|
|
@@ -4856,7 +5250,7 @@ function writeDescriptorStructure(writer, name, classId, value, root) {
|
|
|
4856
5250
|
extType = makeType('', 'patternLayer');
|
|
4857
5251
|
}
|
|
4858
5252
|
else {
|
|
4859
|
-
|
|
5253
|
+
writer.logMissingFeatures && writer.log('Invalid strokeStyleContent value', value[key]);
|
|
4860
5254
|
}
|
|
4861
5255
|
}
|
|
4862
5256
|
else if (key === 'bounds' && root === 'quiltWarp') {
|
|
@@ -4878,8 +5272,8 @@ function writeDescriptorStructure(writer, name, classId, value, root) {
|
|
|
4878
5272
|
writeAsciiStringOrClassId(writer, key);
|
|
4879
5273
|
(0, psdWriter_1.writeSignature)(writer, type || 'long');
|
|
4880
5274
|
writeOSType(writer, type || 'long', value[key], key, extType, childRoot);
|
|
4881
|
-
if (
|
|
4882
|
-
|
|
5275
|
+
if (writer.logMissingFeatures && !type)
|
|
5276
|
+
writer.log(`Missing descriptor field type for: '${key}' in`, value);
|
|
4883
5277
|
}
|
|
4884
5278
|
}
|
|
4885
5279
|
function readOSType(reader, type, includeClass) {
|
|
@@ -5000,11 +5394,11 @@ function writeOSType(writer, type, value, key, extType, root) {
|
|
|
5000
5394
|
throw new Error(`Invalid list value: ${JSON.stringify(value)}, key: ${key}`);
|
|
5001
5395
|
(0, psdWriter_1.writeInt32)(writer, value.length);
|
|
5002
5396
|
for (let i = 0; i < value.length; i++) {
|
|
5003
|
-
const type = (_a = fieldToArrayType[key]) !== null && _a !== void 0 ? _a : guessOSType(value[i]);
|
|
5397
|
+
const type = root === exports.cameraRawFilterClassID ? 'long' : ((_a = fieldToArrayType[key]) !== null && _a !== void 0 ? _a : guessOSType(value[i]));
|
|
5004
5398
|
(0, psdWriter_1.writeSignature)(writer, type || 'long');
|
|
5005
5399
|
writeOSType(writer, type || 'long', value[i], `${key}[]`, fieldToArrayExtType[key], root);
|
|
5006
|
-
if (
|
|
5007
|
-
|
|
5400
|
+
if (writer.logMissingFeatures && !type)
|
|
5401
|
+
writer.log(`Missing descriptor array type for: '${key}' in`, value);
|
|
5008
5402
|
}
|
|
5009
5403
|
break;
|
|
5010
5404
|
case 'doub': // Double
|
|
@@ -5304,7 +5698,7 @@ function serializeFxObject(stroke) {
|
|
|
5304
5698
|
FrFX.overprint = !!stroke.overprint;
|
|
5305
5699
|
return FrFX;
|
|
5306
5700
|
}
|
|
5307
|
-
function serializeEffects(e,
|
|
5701
|
+
function serializeEffects(e, writer, multi) {
|
|
5308
5702
|
var _a, _b, _c;
|
|
5309
5703
|
const info = multi ? {
|
|
5310
5704
|
'Scl ': unitsPercentF((_a = e.scale) !== null && _a !== void 0 ? _a : 1),
|
|
@@ -5321,33 +5715,33 @@ function serializeEffects(e, log, multi) {
|
|
|
5321
5715
|
const useMulti = (arr) => !!arr && arr.length > 1 && multi;
|
|
5322
5716
|
const useSingle = (arr) => !!arr && arr.length >= 1 && (!multi || arr.length === 1);
|
|
5323
5717
|
if (useSingle(e.dropShadow))
|
|
5324
|
-
info.DrSh = serializeEffectObject(e.dropShadow[0], 'dropShadow',
|
|
5718
|
+
info.DrSh = serializeEffectObject(e.dropShadow[0], 'dropShadow', writer);
|
|
5325
5719
|
if (useMulti(e.dropShadow))
|
|
5326
|
-
info.dropShadowMulti = e.dropShadow.map(i => serializeEffectObject(i, 'dropShadow',
|
|
5720
|
+
info.dropShadowMulti = e.dropShadow.map(i => serializeEffectObject(i, 'dropShadow', writer));
|
|
5327
5721
|
if (useSingle(e.innerShadow))
|
|
5328
|
-
info.IrSh = serializeEffectObject(e.innerShadow[0], 'innerShadow',
|
|
5722
|
+
info.IrSh = serializeEffectObject(e.innerShadow[0], 'innerShadow', writer);
|
|
5329
5723
|
if (useMulti(e.innerShadow))
|
|
5330
|
-
info.innerShadowMulti = e.innerShadow.map(i => serializeEffectObject(i, 'innerShadow',
|
|
5724
|
+
info.innerShadowMulti = e.innerShadow.map(i => serializeEffectObject(i, 'innerShadow', writer));
|
|
5331
5725
|
if (e.outerGlow)
|
|
5332
|
-
info.OrGl = serializeEffectObject(e.outerGlow, 'outerGlow',
|
|
5726
|
+
info.OrGl = serializeEffectObject(e.outerGlow, 'outerGlow', writer);
|
|
5333
5727
|
if (useMulti(e.solidFill))
|
|
5334
|
-
info.solidFillMulti = e.solidFill.map(i => serializeEffectObject(i, 'solidFill',
|
|
5728
|
+
info.solidFillMulti = e.solidFill.map(i => serializeEffectObject(i, 'solidFill', writer));
|
|
5335
5729
|
if (useMulti(e.gradientOverlay))
|
|
5336
|
-
info.gradientFillMulti = e.gradientOverlay.map(i => serializeEffectObject(i, 'gradientOverlay',
|
|
5730
|
+
info.gradientFillMulti = e.gradientOverlay.map(i => serializeEffectObject(i, 'gradientOverlay', writer));
|
|
5337
5731
|
if (useMulti(e.stroke))
|
|
5338
5732
|
info.frameFXMulti = e.stroke.map(i => serializeFxObject(i));
|
|
5339
5733
|
if (e.innerGlow)
|
|
5340
|
-
info.IrGl = serializeEffectObject(e.innerGlow, 'innerGlow',
|
|
5734
|
+
info.IrGl = serializeEffectObject(e.innerGlow, 'innerGlow', writer);
|
|
5341
5735
|
if (e.bevel)
|
|
5342
|
-
info.ebbl = serializeEffectObject(e.bevel, 'bevel',
|
|
5736
|
+
info.ebbl = serializeEffectObject(e.bevel, 'bevel', writer);
|
|
5343
5737
|
if (useSingle(e.solidFill))
|
|
5344
|
-
info.SoFi = serializeEffectObject(e.solidFill[0], 'solidFill',
|
|
5738
|
+
info.SoFi = serializeEffectObject(e.solidFill[0], 'solidFill', writer);
|
|
5345
5739
|
if (e.patternOverlay)
|
|
5346
|
-
info.patternFill = serializeEffectObject(e.patternOverlay, 'patternOverlay',
|
|
5740
|
+
info.patternFill = serializeEffectObject(e.patternOverlay, 'patternOverlay', writer);
|
|
5347
5741
|
if (useSingle(e.gradientOverlay))
|
|
5348
|
-
info.GrFl = serializeEffectObject(e.gradientOverlay[0], 'gradientOverlay',
|
|
5742
|
+
info.GrFl = serializeEffectObject(e.gradientOverlay[0], 'gradientOverlay', writer);
|
|
5349
5743
|
if (e.satin)
|
|
5350
|
-
info.ChFX = serializeEffectObject(e.satin, 'satin',
|
|
5744
|
+
info.ChFX = serializeEffectObject(e.satin, 'satin', writer);
|
|
5351
5745
|
if (useSingle(e.stroke))
|
|
5352
5746
|
info.FrFX = serializeFxObject((_c = e.stroke) === null || _c === void 0 ? void 0 : _c[0]);
|
|
5353
5747
|
if (multi) {
|
|
@@ -5369,7 +5763,7 @@ function serializeEffects(e, log, multi) {
|
|
|
5369
5763
|
}
|
|
5370
5764
|
return info;
|
|
5371
5765
|
}
|
|
5372
|
-
function parseEffects(info,
|
|
5766
|
+
function parseEffects(info, reader) {
|
|
5373
5767
|
const effects = {};
|
|
5374
5768
|
const _a = info, { _name, _classID, 'Scl ': scale, masterFXSwitch, DrSh, dropShadowMulti, IrSh, innerShadowMulti, OrGl, IrGl, ebbl, SoFi, solidFillMulti, patternFill, GrFl, gradientFillMulti, ChFX, FrFX, frameFXMulti, numModifyingFX } = _a, rest = __rest(_a, ["_name", "_classID", 'Scl ', "masterFXSwitch", "DrSh", "dropShadowMulti", "IrSh", "innerShadowMulti", "OrGl", "IrGl", "ebbl", "SoFi", "solidFillMulti", "patternFill", "GrFl", "gradientFillMulti", "ChFX", "FrFX", "frameFXMulti", "numModifyingFX"]);
|
|
5375
5769
|
if (!masterFXSwitch)
|
|
@@ -5377,40 +5771,40 @@ function parseEffects(info, log) {
|
|
|
5377
5771
|
if (scale)
|
|
5378
5772
|
effects.scale = parsePercent(scale);
|
|
5379
5773
|
if (DrSh)
|
|
5380
|
-
effects.dropShadow = [parseEffectObject(DrSh,
|
|
5774
|
+
effects.dropShadow = [parseEffectObject(DrSh, reader)];
|
|
5381
5775
|
if (dropShadowMulti)
|
|
5382
|
-
effects.dropShadow = dropShadowMulti.map(i => parseEffectObject(i,
|
|
5776
|
+
effects.dropShadow = dropShadowMulti.map(i => parseEffectObject(i, reader));
|
|
5383
5777
|
if (IrSh)
|
|
5384
|
-
effects.innerShadow = [parseEffectObject(IrSh,
|
|
5778
|
+
effects.innerShadow = [parseEffectObject(IrSh, reader)];
|
|
5385
5779
|
if (innerShadowMulti)
|
|
5386
|
-
effects.innerShadow = innerShadowMulti.map(i => parseEffectObject(i,
|
|
5780
|
+
effects.innerShadow = innerShadowMulti.map(i => parseEffectObject(i, reader));
|
|
5387
5781
|
if (OrGl)
|
|
5388
|
-
effects.outerGlow = parseEffectObject(OrGl,
|
|
5782
|
+
effects.outerGlow = parseEffectObject(OrGl, reader);
|
|
5389
5783
|
if (IrGl)
|
|
5390
|
-
effects.innerGlow = parseEffectObject(IrGl,
|
|
5784
|
+
effects.innerGlow = parseEffectObject(IrGl, reader);
|
|
5391
5785
|
if (ebbl)
|
|
5392
|
-
effects.bevel = parseEffectObject(ebbl,
|
|
5786
|
+
effects.bevel = parseEffectObject(ebbl, reader, 'bevel');
|
|
5393
5787
|
if (SoFi)
|
|
5394
|
-
effects.solidFill = [parseEffectObject(SoFi,
|
|
5788
|
+
effects.solidFill = [parseEffectObject(SoFi, reader)];
|
|
5395
5789
|
if (solidFillMulti)
|
|
5396
|
-
effects.solidFill = solidFillMulti.map(i => parseEffectObject(i,
|
|
5790
|
+
effects.solidFill = solidFillMulti.map(i => parseEffectObject(i, reader));
|
|
5397
5791
|
if (patternFill)
|
|
5398
|
-
effects.patternOverlay = parseEffectObject(patternFill,
|
|
5792
|
+
effects.patternOverlay = parseEffectObject(patternFill, reader);
|
|
5399
5793
|
if (GrFl)
|
|
5400
|
-
effects.gradientOverlay = [parseEffectObject(GrFl,
|
|
5794
|
+
effects.gradientOverlay = [parseEffectObject(GrFl, reader)];
|
|
5401
5795
|
if (gradientFillMulti)
|
|
5402
|
-
effects.gradientOverlay = gradientFillMulti.map(i => parseEffectObject(i,
|
|
5796
|
+
effects.gradientOverlay = gradientFillMulti.map(i => parseEffectObject(i, reader));
|
|
5403
5797
|
if (ChFX)
|
|
5404
|
-
effects.satin = parseEffectObject(ChFX,
|
|
5798
|
+
effects.satin = parseEffectObject(ChFX, reader);
|
|
5405
5799
|
if (FrFX)
|
|
5406
5800
|
effects.stroke = [parseFxObject(FrFX)];
|
|
5407
5801
|
if (frameFXMulti)
|
|
5408
5802
|
effects.stroke = frameFXMulti.map(i => parseFxObject(i));
|
|
5409
|
-
if (
|
|
5410
|
-
|
|
5803
|
+
if (reader.logMissingFeatures && Object.keys(rest).length)
|
|
5804
|
+
reader.log('Unhandled effect keys:', rest);
|
|
5411
5805
|
return effects;
|
|
5412
5806
|
}
|
|
5413
|
-
function parseKeyList(keyList,
|
|
5807
|
+
function parseKeyList(keyList, reader) {
|
|
5414
5808
|
const keys = [];
|
|
5415
5809
|
for (let j = 0; j < keyList.length; j++) {
|
|
5416
5810
|
const key = keyList[j];
|
|
@@ -5433,7 +5827,7 @@ function parseKeyList(keyList, logMissingFeatures) {
|
|
|
5433
5827
|
case 'keyType.sheetStyle': {
|
|
5434
5828
|
const key = { interpolation, time, selected, type: 'style' };
|
|
5435
5829
|
if (animKey.sheetStyle.Lefx)
|
|
5436
|
-
key.style = parseEffects(animKey.sheetStyle.Lefx,
|
|
5830
|
+
key.style = parseEffects(animKey.sheetStyle.Lefx, reader);
|
|
5437
5831
|
keys.push(key);
|
|
5438
5832
|
break;
|
|
5439
5833
|
}
|
|
@@ -5449,7 +5843,7 @@ function parseKeyList(keyList, logMissingFeatures) {
|
|
|
5449
5843
|
}
|
|
5450
5844
|
return keys;
|
|
5451
5845
|
}
|
|
5452
|
-
function serializeKeyList(keys) {
|
|
5846
|
+
function serializeKeyList(keys, writer) {
|
|
5453
5847
|
const keyList = [];
|
|
5454
5848
|
for (let j = 0; j < keys.length; j++) {
|
|
5455
5849
|
const key = keys[j];
|
|
@@ -5469,7 +5863,7 @@ function serializeKeyList(keys) {
|
|
|
5469
5863
|
case 'style':
|
|
5470
5864
|
animKey = { Type: 'keyType.sheetStyle', sheetStyle: { Vrsn: 1, blendOptions: {} } };
|
|
5471
5865
|
if (key.style)
|
|
5472
|
-
animKey.sheetStyle = { Vrsn: 1, Lefx: serializeEffects(key.style,
|
|
5866
|
+
animKey.sheetStyle = { Vrsn: 1, Lefx: serializeEffects(key.style, writer, false), blendOptions: {} };
|
|
5473
5867
|
break;
|
|
5474
5868
|
case 'globalLighting': {
|
|
5475
5869
|
animKey = { Type: 'keyType.globalLighting', gblA: key.globalAngle, globalAltitude: key.globalAltitude };
|
|
@@ -5481,41 +5875,41 @@ function serializeKeyList(keys) {
|
|
|
5481
5875
|
}
|
|
5482
5876
|
return keyList;
|
|
5483
5877
|
}
|
|
5484
|
-
function parseTrackList(trackList,
|
|
5878
|
+
function parseTrackList(trackList, reader) {
|
|
5485
5879
|
const tracks = [];
|
|
5486
5880
|
for (let i = 0; i < trackList.length; i++) {
|
|
5487
5881
|
const tr = trackList[i];
|
|
5488
5882
|
const track = {
|
|
5489
5883
|
type: exports.stdTrackID.decode(tr.trackID),
|
|
5490
5884
|
enabled: tr.enab,
|
|
5491
|
-
keys: parseKeyList(tr.keyList,
|
|
5885
|
+
keys: parseKeyList(tr.keyList, reader),
|
|
5492
5886
|
};
|
|
5493
5887
|
if (tr.effectParams) {
|
|
5494
5888
|
track.effectParams = {
|
|
5495
5889
|
fillCanvas: tr.effectParams.fillCanvas,
|
|
5496
5890
|
zoomOrigin: tr.effectParams.zoomOrigin,
|
|
5497
|
-
keys: parseKeyList(tr.effectParams.keyList,
|
|
5891
|
+
keys: parseKeyList(tr.effectParams.keyList, reader),
|
|
5498
5892
|
};
|
|
5499
5893
|
}
|
|
5500
5894
|
tracks.push(track);
|
|
5501
5895
|
}
|
|
5502
5896
|
return tracks;
|
|
5503
5897
|
}
|
|
5504
|
-
function serializeTrackList(tracks) {
|
|
5898
|
+
function serializeTrackList(tracks, writer) {
|
|
5505
5899
|
const trackList = [];
|
|
5506
5900
|
for (let i = 0; i < tracks.length; i++) {
|
|
5507
5901
|
const t = tracks[i];
|
|
5508
5902
|
trackList.push(Object.assign(Object.assign({ trackID: exports.stdTrackID.encode(t.type), Vrsn: 1, enab: !!t.enabled, Effc: !!t.effectParams }, (t.effectParams ? {
|
|
5509
5903
|
effectParams: {
|
|
5510
|
-
keyList: serializeKeyList(t.effectParams.keys),
|
|
5904
|
+
keyList: serializeKeyList(t.effectParams.keys, writer),
|
|
5511
5905
|
fillCanvas: t.effectParams.fillCanvas,
|
|
5512
5906
|
zoomOrigin: t.effectParams.zoomOrigin,
|
|
5513
5907
|
}
|
|
5514
|
-
} : {})), { keyList: serializeKeyList(t.keys) }));
|
|
5908
|
+
} : {})), { keyList: serializeKeyList(t.keys, writer) }));
|
|
5515
5909
|
}
|
|
5516
5910
|
return trackList;
|
|
5517
5911
|
}
|
|
5518
|
-
function parseEffectObject(obj,
|
|
5912
|
+
function parseEffectObject(obj, reader, objName) {
|
|
5519
5913
|
const result = {};
|
|
5520
5914
|
for (const key of Object.keys(obj)) {
|
|
5521
5915
|
const val = obj[key];
|
|
@@ -5668,12 +6062,12 @@ function parseEffectObject(obj, reportErrors, objName) {
|
|
|
5668
6062
|
case '_classID':
|
|
5669
6063
|
break;
|
|
5670
6064
|
default:
|
|
5671
|
-
|
|
6065
|
+
reader.logMissingFeatures && reader.log(`Invalid effect key: '${key}', value:`, val);
|
|
5672
6066
|
}
|
|
5673
6067
|
}
|
|
5674
6068
|
return result;
|
|
5675
6069
|
}
|
|
5676
|
-
function serializeEffectObject(obj, objName,
|
|
6070
|
+
function serializeEffectObject(obj, objName, writer) {
|
|
5677
6071
|
const result = {
|
|
5678
6072
|
enab: false,
|
|
5679
6073
|
};
|
|
@@ -5823,7 +6217,7 @@ function serializeEffectObject(obj, objName, reportErrors) {
|
|
|
5823
6217
|
result[key] = val;
|
|
5824
6218
|
break;
|
|
5825
6219
|
default:
|
|
5826
|
-
|
|
6220
|
+
writer.logMissingFeatures && writer.log(`Invalid effect key: '${key}', value:`, val);
|
|
5827
6221
|
}
|
|
5828
6222
|
}
|
|
5829
6223
|
return result;
|
|
@@ -6068,6 +6462,21 @@ function isBookColor(color) {
|
|
|
6068
6462
|
return color._classID === 'BkCl' || 'Bk ' in color || 'bookID' in color;
|
|
6069
6463
|
}
|
|
6070
6464
|
function parseColor(color) {
|
|
6465
|
+
var _a, _b, _c;
|
|
6466
|
+
const result = parseColorValues(color);
|
|
6467
|
+
if (isBookColor(color)) {
|
|
6468
|
+
const book = color;
|
|
6469
|
+
const key = book.bookKey;
|
|
6470
|
+
result.book = {
|
|
6471
|
+
book: (_a = book['Bk ']) !== null && _a !== void 0 ? _a : '',
|
|
6472
|
+
name: (_b = book['Nm ']) !== null && _b !== void 0 ? _b : '',
|
|
6473
|
+
bookID: (_c = book.bookID) !== null && _c !== void 0 ? _c : 0,
|
|
6474
|
+
bookKey: typeof key === 'string' ? key : (key ? String.fromCharCode(...Array.from(key)) : ''),
|
|
6475
|
+
};
|
|
6476
|
+
}
|
|
6477
|
+
return result;
|
|
6478
|
+
}
|
|
6479
|
+
function parseColorValues(color) {
|
|
6071
6480
|
if ('H ' in color) {
|
|
6072
6481
|
return { h: parsePercentOrAngle(color['H ']), s: color.Strt / 100, b: color.Brgh / 100 };
|
|
6073
6482
|
}
|
|
@@ -6092,13 +6501,24 @@ function parseColor(color) {
|
|
|
6092
6501
|
return { fr: color.redFloat, fg: color.greenFloat, fb: color.blueFloat };
|
|
6093
6502
|
}
|
|
6094
6503
|
else if (isBookColor(color)) {
|
|
6095
|
-
return { r: 0, g: 0, b: 0 }; // book (Pantone)
|
|
6504
|
+
return { r: 0, g: 0, b: 0 }; // book (Pantone) color without color values
|
|
6096
6505
|
}
|
|
6097
6506
|
else {
|
|
6098
6507
|
throw new Error('Unsupported color descriptor');
|
|
6099
6508
|
}
|
|
6100
6509
|
}
|
|
6101
6510
|
function serializeColor(color) {
|
|
6511
|
+
const result = serializeColorValues(color);
|
|
6512
|
+
if (color === null || color === void 0 ? void 0 : color.book) {
|
|
6513
|
+
const { book, name, bookID, bookKey } = color.book;
|
|
6514
|
+
const key = new Uint8Array(bookKey.length);
|
|
6515
|
+
for (let i = 0; i < key.length; i++)
|
|
6516
|
+
key[i] = bookKey.charCodeAt(i) & 0xff;
|
|
6517
|
+
Object.assign(result, { 'Bk ': book, 'Nm ': name, bookID, bookKey: key });
|
|
6518
|
+
}
|
|
6519
|
+
return result;
|
|
6520
|
+
}
|
|
6521
|
+
function serializeColorValues(color) {
|
|
6102
6522
|
if (!color) {
|
|
6103
6523
|
return { _name: '', _classID: 'RGBC', 'Rd ': 0, 'Grn ': 0, 'Bl ': 0 };
|
|
6104
6524
|
}
|
|
@@ -6524,8 +6944,13 @@ exports.presetKindType = (0, helpers_1.createEnum)('presetKindType', 'custom', {
|
|
|
6524
6944
|
custom: 'presetKindCustom',
|
|
6525
6945
|
default: 'presetKindDefault',
|
|
6526
6946
|
});
|
|
6947
|
+
exports.patternColorHandling = (0, helpers_1.createEnum)('', 'convert', {
|
|
6948
|
+
'convert': 'conv',
|
|
6949
|
+
'avoid conversion': 'avod',
|
|
6950
|
+
'luminance only': 'lumi',
|
|
6951
|
+
});
|
|
6527
6952
|
|
|
6528
|
-
},{"./helpers":
|
|
6953
|
+
},{"./helpers":9,"./psdReader":14,"./psdWriter":15}],6:[function(require,module,exports){
|
|
6529
6954
|
"use strict";
|
|
6530
6955
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6531
6956
|
exports.readEffects = readEffects;
|
|
@@ -6813,7 +7238,7 @@ function writeEffects(writer, effects) {
|
|
|
6813
7238
|
}
|
|
6814
7239
|
}
|
|
6815
7240
|
|
|
6816
|
-
},{"./helpers":
|
|
7241
|
+
},{"./helpers":9,"./psdReader":14,"./psdWriter":15}],7:[function(require,module,exports){
|
|
6817
7242
|
"use strict";
|
|
6818
7243
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6819
7244
|
exports.setProperty = setProperty;
|
|
@@ -7174,7 +7599,7 @@ function serializeEngineData(data, condensed = false) {
|
|
|
7174
7599
|
return buffer.slice(0, offset);
|
|
7175
7600
|
}
|
|
7176
7601
|
|
|
7177
|
-
},{}],
|
|
7602
|
+
},{}],8:[function(require,module,exports){
|
|
7178
7603
|
"use strict";
|
|
7179
7604
|
/// Engine data 2 experiments
|
|
7180
7605
|
// /test/engineData2.json:1109 is character codes
|
|
@@ -7614,7 +8039,7 @@ function decodeEngineData2(data) {
|
|
|
7614
8039
|
return result;
|
|
7615
8040
|
}
|
|
7616
8041
|
|
|
7617
|
-
},{"./engineData":
|
|
8042
|
+
},{"./engineData":7}],9:[function(require,module,exports){
|
|
7618
8043
|
"use strict";
|
|
7619
8044
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7620
8045
|
exports.createImageData = exports.createCanvas = exports.MaskParams = exports.LayerMaskFlags = exports.ColorSpace = exports.largeAdditionalInfoKeys = exports.largeAdditionalInfoKeysObserved = exports.layerColors = exports.toBlendMode = exports.fromBlendMode = exports.MOCK_HANDLERS = void 0;
|
|
@@ -7625,11 +8050,16 @@ exports.normalizeLabAB = normalizeLabAB;
|
|
|
7625
8050
|
exports.denormalizeLabAB = denormalizeLabAB;
|
|
7626
8051
|
exports.clamp = clamp;
|
|
7627
8052
|
exports.hasAlpha = hasAlpha;
|
|
8053
|
+
exports.cmykToRgbValues = cmykToRgbValues;
|
|
8054
|
+
exports.rgbToCmykValues = rgbToCmykValues;
|
|
7628
8055
|
exports.resetImageData = resetImageData;
|
|
7629
8056
|
exports.imageDataToCanvas = imageDataToCanvas;
|
|
7630
8057
|
exports.decodeBitmap = decodeBitmap;
|
|
7631
8058
|
exports.writeDataRaw = writeDataRaw;
|
|
7632
8059
|
exports.writeDataRLE = writeDataRLE;
|
|
8060
|
+
exports.planarToBytes = planarToBytes;
|
|
8061
|
+
exports.writeDataRLEBytes = writeDataRLEBytes;
|
|
8062
|
+
exports.writeDataZipWithPrediction = writeDataZipWithPrediction;
|
|
7633
8063
|
exports.writeDataZipWithoutPrediction = writeDataZipWithoutPrediction;
|
|
7634
8064
|
exports.createCanvasFromData = createCanvasFromData;
|
|
7635
8065
|
exports.initializeCanvas = initializeCanvas;
|
|
@@ -7669,7 +8099,7 @@ exports.toBlendMode = {
|
|
|
7669
8099
|
};
|
|
7670
8100
|
Object.keys(exports.toBlendMode).forEach(key => exports.fromBlendMode[exports.toBlendMode[key]] = key);
|
|
7671
8101
|
exports.layerColors = [
|
|
7672
|
-
'none', 'red', 'orange', 'yellow', 'green', 'blue', 'violet', 'gray'
|
|
8102
|
+
'none', 'red', 'orange', 'yellow', 'green', 'blue', 'violet', 'gray', 'seafoam', 'indigo', 'magenta', 'fuchsia',
|
|
7673
8103
|
];
|
|
7674
8104
|
// keys not listed in documentation that Photoshop writes with 64bit length in PSB files (with 8B64 signature)
|
|
7675
8105
|
exports.largeAdditionalInfoKeysObserved = ['lnk3', 'lnkE', 'pths', 'extd', 'extn', 'FELS', 'artd'];
|
|
@@ -7756,13 +8186,152 @@ function clamp(value, min, max) {
|
|
|
7756
8186
|
}
|
|
7757
8187
|
function hasAlpha(data) {
|
|
7758
8188
|
const size = data.width * data.height * 4;
|
|
8189
|
+
const max = data.data instanceof Float32Array ? 1 : (data.data instanceof Uint16Array ? 0xffff : 0xff);
|
|
7759
8190
|
for (let i = 3; i < size; i += 4) {
|
|
7760
|
-
if (data.data[i] !==
|
|
8191
|
+
if (data.data[i] !== max) {
|
|
7761
8192
|
return true;
|
|
7762
8193
|
}
|
|
7763
8194
|
}
|
|
7764
8195
|
return false;
|
|
7765
8196
|
}
|
|
8197
|
+
// Polynomial approximation of U.S. Web Coated (SWOP) v2 CMYK to RGB conversion (default CMYK profile of Photoshop).
|
|
8198
|
+
// Coefficients are taken from pdf.js (DeviceCmykCS in src/core/colorspace.js, https://github.com/mozilla/pdf.js),
|
|
8199
|
+
// Copyright 2012 Mozilla Foundation, licensed under the Apache License, Version 2.0
|
|
8200
|
+
// (http://www.apache.org/licenses/LICENSE-2.0)
|
|
8201
|
+
// c, m, y, k - ink values (0 - 1), output - RGB values (0 - 255, not rounded or clamped)
|
|
8202
|
+
function cmykToRgbValues(c, m, y, k, out) {
|
|
8203
|
+
out[0] = 255 +
|
|
8204
|
+
c * (-4.387332384609988 * c + 54.48615194189176 * m + 18.82290502165302 * y + 212.25662451639585 * k - 285.2331026137004) +
|
|
8205
|
+
m * (1.7149763477362134 * m - 5.6096736904047315 * y - 17.873870861415444 * k - 5.497006427196366) +
|
|
8206
|
+
y * (-2.5217340131683033 * y - 21.248923337353073 * k + 17.5119270841813) +
|
|
8207
|
+
k * (-21.86122147463605 * k - 189.48180835922747);
|
|
8208
|
+
out[1] = 255 +
|
|
8209
|
+
c * (8.841041422036149 * c + 60.118027045597366 * m + 6.871425592049007 * y + 31.159100130055922 * k - 79.2970844816548) +
|
|
8210
|
+
m * (-15.310361306967817 * m + 17.575251261109482 * y + 131.35250912493976 * k - 190.9453302588951) +
|
|
8211
|
+
y * (4.444339102852739 * y + 9.8632861493405 * k - 24.86741582555878) +
|
|
8212
|
+
k * (-20.737325471181034 * k - 187.80453709719578);
|
|
8213
|
+
out[2] = 255 +
|
|
8214
|
+
c * (0.8842522430003296 * c + 8.078677503112928 * m + 30.89978309703729 * y - 0.23883238689178934 * k - 14.183576799673286) +
|
|
8215
|
+
m * (10.49593273432072 * m + 63.02378494754052 * y + 50.606957656360734 * k - 112.23884253719248) +
|
|
8216
|
+
y * (0.03296041114873217 * y + 115.60384449646641 * k - 193.58209356861505) +
|
|
8217
|
+
k * (-22.33816807309886 * k - 180.12613974708367);
|
|
8218
|
+
}
|
|
8219
|
+
const clamp01 = (v) => v < 0 ? 0 : (v > 1 ? 1 : v);
|
|
8220
|
+
// finds c, m, y (with fixed k) for given RGB color using Gauss-Newton method, returns squared error
|
|
8221
|
+
function solveCmy(r, g, b, k, x) {
|
|
8222
|
+
const f = [0, 0, 0], f2 = [0, 0, 0], e = [0, 0, 0];
|
|
8223
|
+
const J = [[0, 0, 0], [0, 0, 0], [0, 0, 0]];
|
|
8224
|
+
const h = 1e-4;
|
|
8225
|
+
for (let iteration = 0; iteration < 20; iteration++) {
|
|
8226
|
+
cmykToRgbValues(x[0], x[1], x[2], k, f);
|
|
8227
|
+
e[0] = f[0] - r;
|
|
8228
|
+
e[1] = f[1] - g;
|
|
8229
|
+
e[2] = f[2] - b;
|
|
8230
|
+
if ((e[0] * e[0] + e[1] * e[1] + e[2] * e[2]) < 1e-6)
|
|
8231
|
+
break;
|
|
8232
|
+
for (let j = 0; j < 3; j++) {
|
|
8233
|
+
const s = x[j];
|
|
8234
|
+
x[j] = s + h;
|
|
8235
|
+
cmykToRgbValues(x[0], x[1], x[2], k, f2);
|
|
8236
|
+
x[j] = s;
|
|
8237
|
+
for (let i = 0; i < 3; i++)
|
|
8238
|
+
J[i][j] = (f2[i] - f[i]) / h;
|
|
8239
|
+
}
|
|
8240
|
+
const [[a, b_, c], [d, e_, f_], [g_, h_, i_]] = J;
|
|
8241
|
+
const det = a * (e_ * i_ - f_ * h_) - b_ * (d * i_ - f_ * g_) + c * (d * h_ - e_ * g_);
|
|
8242
|
+
if (Math.abs(det) < 1e-12)
|
|
8243
|
+
break;
|
|
8244
|
+
const inverse = [
|
|
8245
|
+
[(e_ * i_ - f_ * h_), (c * h_ - b_ * i_), (b_ * f_ - c * e_)],
|
|
8246
|
+
[(f_ * g_ - d * i_), (a * i_ - c * g_), (c * d - a * f_)],
|
|
8247
|
+
[(d * h_ - e_ * g_), (b_ * g_ - a * h_), (a * e_ - b_ * d)],
|
|
8248
|
+
];
|
|
8249
|
+
let changed = 0;
|
|
8250
|
+
for (let j = 0; j < 3; j++) {
|
|
8251
|
+
const delta = -(inverse[j][0] * e[0] + inverse[j][1] * e[1] + inverse[j][2] * e[2]) / det;
|
|
8252
|
+
const value = clamp01(x[j] + delta);
|
|
8253
|
+
changed += Math.abs(value - x[j]);
|
|
8254
|
+
x[j] = value;
|
|
8255
|
+
}
|
|
8256
|
+
if (changed < 1e-9)
|
|
8257
|
+
break;
|
|
8258
|
+
}
|
|
8259
|
+
cmykToRgbValues(x[0], x[1], x[2], k, f);
|
|
8260
|
+
return (f[0] - r) * (f[0] - r) + (f[1] - g) * (f[1] - g) + (f[2] - b) * (f[2] - b);
|
|
8261
|
+
}
|
|
8262
|
+
// finds CMYK ink values (0 - 1) for RGB color (0 - 255), out of gamut colors are approximated
|
|
8263
|
+
function rgbToCmykExact(r, g, b, out) {
|
|
8264
|
+
const max = Math.max(r, g, b) / 255;
|
|
8265
|
+
const blackGeneration = Math.pow(clamp01((1 - max - 0.2) / 0.8), 1.3);
|
|
8266
|
+
const x = [0, 0, 0];
|
|
8267
|
+
let bestScore = Infinity, bestError = Infinity;
|
|
8268
|
+
const tryBlack = (k) => {
|
|
8269
|
+
x[0] = clamp01(1 - r / 255 - k);
|
|
8270
|
+
x[1] = clamp01(1 - g / 255 - k);
|
|
8271
|
+
x[2] = clamp01(1 - b / 255 - k);
|
|
8272
|
+
const error = solveCmy(r, g, b, k, x);
|
|
8273
|
+
// prefer solutions close to black generation value if the error is small enough
|
|
8274
|
+
const score = Math.max(error, 0.1) + Math.abs(k - blackGeneration) * 0.01;
|
|
8275
|
+
if (score < bestScore) {
|
|
8276
|
+
bestScore = score;
|
|
8277
|
+
bestError = error;
|
|
8278
|
+
out[0] = x[0];
|
|
8279
|
+
out[1] = x[1];
|
|
8280
|
+
out[2] = x[2];
|
|
8281
|
+
out[3] = k;
|
|
8282
|
+
}
|
|
8283
|
+
};
|
|
8284
|
+
tryBlack(blackGeneration);
|
|
8285
|
+
if (bestError > 0.1) {
|
|
8286
|
+
for (let i = 0; i <= 10; i++)
|
|
8287
|
+
tryBlack(i / 10);
|
|
8288
|
+
}
|
|
8289
|
+
if (bestError > 0.1) {
|
|
8290
|
+
const k = out[3];
|
|
8291
|
+
for (let i = -5; i <= 5; i++)
|
|
8292
|
+
tryBlack(clamp01(k + i / 100));
|
|
8293
|
+
}
|
|
8294
|
+
}
|
|
8295
|
+
const cmykLutSize = 33;
|
|
8296
|
+
let cmykLut;
|
|
8297
|
+
function getCmykLut() {
|
|
8298
|
+
if (!cmykLut) {
|
|
8299
|
+
const n = cmykLutSize;
|
|
8300
|
+
const lut = new Float32Array(n * n * n * 4);
|
|
8301
|
+
const out = [0, 0, 0, 0];
|
|
8302
|
+
for (let r = 0, o = 0; r < n; r++) {
|
|
8303
|
+
for (let g = 0; g < n; g++) {
|
|
8304
|
+
for (let b = 0; b < n; b++, o += 4) {
|
|
8305
|
+
rgbToCmykExact(r * 255 / (n - 1), g * 255 / (n - 1), b * 255 / (n - 1), out);
|
|
8306
|
+
lut[o] = out[0];
|
|
8307
|
+
lut[o + 1] = out[1];
|
|
8308
|
+
lut[o + 2] = out[2];
|
|
8309
|
+
lut[o + 3] = out[3];
|
|
8310
|
+
}
|
|
8311
|
+
}
|
|
8312
|
+
}
|
|
8313
|
+
cmykLut = lut;
|
|
8314
|
+
}
|
|
8315
|
+
return cmykLut;
|
|
8316
|
+
}
|
|
8317
|
+
// inverse of cmykToRgbValues, r, g, b - RGB values (0 - 1), output - CMYK ink values (0 - 1)
|
|
8318
|
+
function rgbToCmykValues(r, g, b, out) {
|
|
8319
|
+
const lut = getCmykLut();
|
|
8320
|
+
const n1 = cmykLutSize - 1;
|
|
8321
|
+
const fr = clamp01(r) * n1, fg = clamp01(g) * n1, fb = clamp01(b) * n1;
|
|
8322
|
+
const r0 = Math.min(n1 - 1, Math.floor(fr)), g0 = Math.min(n1 - 1, Math.floor(fg)), b0 = Math.min(n1 - 1, Math.floor(fb));
|
|
8323
|
+
const dr = fr - r0, dg = fg - g0, db = fb - b0;
|
|
8324
|
+
out[0] = out[1] = out[2] = out[3] = 0;
|
|
8325
|
+
for (let i = 0; i < 8; i++) {
|
|
8326
|
+
const ir = i >> 2, ig = (i >> 1) & 1, ib = i & 1;
|
|
8327
|
+
const w = (ir ? dr : 1 - dr) * (ig ? dg : 1 - dg) * (ib ? db : 1 - db);
|
|
8328
|
+
const o = (((r0 + ir) * cmykLutSize + g0 + ig) * cmykLutSize + b0 + ib) * 4;
|
|
8329
|
+
out[0] += w * lut[o];
|
|
8330
|
+
out[1] += w * lut[o + 1];
|
|
8331
|
+
out[2] += w * lut[o + 2];
|
|
8332
|
+
out[3] += w * lut[o + 3];
|
|
8333
|
+
}
|
|
8334
|
+
}
|
|
7766
8335
|
function resetImageData({ data }) {
|
|
7767
8336
|
const alpha = (data instanceof Float32Array) ? 1.0 : ((data instanceof Uint16Array) ? 0xffff : 0xff);
|
|
7768
8337
|
for (let p = 0, size = data.length | 0; p < size; p = (p + 4) | 0) {
|
|
@@ -7921,6 +8490,102 @@ function writeDataRLE(buffer, { data, width, height }, offsets, large) {
|
|
|
7921
8490
|
// returns view of the buffer, copy the data if the buffer is going to be reused
|
|
7922
8491
|
return buffer.subarray(0, o);
|
|
7923
8492
|
}
|
|
8493
|
+
// converts channel values to big-endian bytes
|
|
8494
|
+
function planarToBytes(values) {
|
|
8495
|
+
if (values instanceof Uint8Array)
|
|
8496
|
+
return values;
|
|
8497
|
+
const bytes = new Uint8Array(values.byteLength);
|
|
8498
|
+
const view = new DataView(bytes.buffer);
|
|
8499
|
+
if (values instanceof Uint16Array) {
|
|
8500
|
+
for (let i = 0; i < values.length; i++)
|
|
8501
|
+
view.setUint16(i * 2, values[i], false);
|
|
8502
|
+
}
|
|
8503
|
+
else {
|
|
8504
|
+
for (let i = 0; i < values.length; i++)
|
|
8505
|
+
view.setFloat32(i * 4, values[i], false);
|
|
8506
|
+
}
|
|
8507
|
+
return bytes;
|
|
8508
|
+
}
|
|
8509
|
+
// RLE (PackBits) compression of rows of bytes, prefixed with byte counts of each row
|
|
8510
|
+
function writeDataRLEBytes(bytes, rowBytes, height, large) {
|
|
8511
|
+
const countSize = large ? 4 : 2;
|
|
8512
|
+
const buffer = new Uint8Array(height * (countSize + rowBytes + Math.ceil(rowBytes / 128)));
|
|
8513
|
+
let o = countSize * height;
|
|
8514
|
+
for (let y = 0; y < height; y++) {
|
|
8515
|
+
const start = o;
|
|
8516
|
+
const rowStart = y * rowBytes;
|
|
8517
|
+
const rowEnd = rowStart + rowBytes;
|
|
8518
|
+
let i = rowStart;
|
|
8519
|
+
while (i < rowEnd) {
|
|
8520
|
+
let run = 1;
|
|
8521
|
+
while (i + run < rowEnd && run < 128 && bytes[i + run] === bytes[i])
|
|
8522
|
+
run++;
|
|
8523
|
+
if (run > 1) {
|
|
8524
|
+
buffer[o++] = 257 - run;
|
|
8525
|
+
buffer[o++] = bytes[i];
|
|
8526
|
+
i += run;
|
|
8527
|
+
}
|
|
8528
|
+
else {
|
|
8529
|
+
// literal bytes until a run of at least 3 equal bytes
|
|
8530
|
+
const countIndex = o++;
|
|
8531
|
+
let count = 0;
|
|
8532
|
+
while (i < rowEnd && count < 128) {
|
|
8533
|
+
if (i + 2 < rowEnd && bytes[i] === bytes[i + 1] && bytes[i] === bytes[i + 2])
|
|
8534
|
+
break;
|
|
8535
|
+
buffer[o++] = bytes[i++];
|
|
8536
|
+
count++;
|
|
8537
|
+
}
|
|
8538
|
+
buffer[countIndex] = count - 1;
|
|
8539
|
+
}
|
|
8540
|
+
}
|
|
8541
|
+
const length = o - start;
|
|
8542
|
+
for (let j = 0; j < countSize; j++) {
|
|
8543
|
+
buffer[y * countSize + j] = (length >>> ((countSize - j - 1) * 8)) & 0xff;
|
|
8544
|
+
}
|
|
8545
|
+
}
|
|
8546
|
+
return buffer.subarray(0, o);
|
|
8547
|
+
}
|
|
8548
|
+
// zip compression with prediction (values are delta encoded per row, 32bit values are split into byte planes first)
|
|
8549
|
+
function writeDataZipWithPrediction(values, width, height) {
|
|
8550
|
+
let bytes;
|
|
8551
|
+
if (values instanceof Uint8Array) {
|
|
8552
|
+
bytes = new Uint8Array(width * height);
|
|
8553
|
+
for (let y = 0, i = 0; y < height; y++) {
|
|
8554
|
+
for (let x = 0, prev = 0; x < width; x++, i++) {
|
|
8555
|
+
bytes[i] = values[i] - prev; // Uint8Array wraps values on assignment
|
|
8556
|
+
prev = values[i];
|
|
8557
|
+
}
|
|
8558
|
+
}
|
|
8559
|
+
}
|
|
8560
|
+
else if (values instanceof Uint16Array) {
|
|
8561
|
+
bytes = new Uint8Array(width * height * 2);
|
|
8562
|
+
for (let y = 0, i = 0; y < height; y++) {
|
|
8563
|
+
for (let x = 0, prev = 0; x < width; x++, i++) {
|
|
8564
|
+
const delta = (values[i] - prev) & 0xffff;
|
|
8565
|
+
bytes[i * 2] = delta >> 8;
|
|
8566
|
+
bytes[i * 2 + 1] = delta & 0xff;
|
|
8567
|
+
prev = values[i];
|
|
8568
|
+
}
|
|
8569
|
+
}
|
|
8570
|
+
}
|
|
8571
|
+
else {
|
|
8572
|
+
const rowBytes = width * 4;
|
|
8573
|
+
const source = planarToBytes(values);
|
|
8574
|
+
bytes = new Uint8Array(rowBytes * height);
|
|
8575
|
+
for (let y = 0; y < height; y++) {
|
|
8576
|
+
const row = y * rowBytes;
|
|
8577
|
+
for (let x = 0; x < width; x++) {
|
|
8578
|
+
for (let b = 0; b < 4; b++) {
|
|
8579
|
+
bytes[row + b * width + x] = source[row + x * 4 + b];
|
|
8580
|
+
}
|
|
8581
|
+
}
|
|
8582
|
+
for (let x = rowBytes - 1; x > 0; x--) {
|
|
8583
|
+
bytes[row + x] -= bytes[row + x - 1];
|
|
8584
|
+
}
|
|
8585
|
+
}
|
|
8586
|
+
}
|
|
8587
|
+
return (0, pako_1.deflate)(bytes);
|
|
8588
|
+
}
|
|
7924
8589
|
function writeDataZipWithoutPrediction({ data, width, height }, offsets) {
|
|
7925
8590
|
const size = width * height;
|
|
7926
8591
|
const channel = new Uint8Array(size);
|
|
@@ -7985,10 +8650,11 @@ function initializeCanvas(createCanvasMethod, createImageDataMethod) {
|
|
|
7985
8650
|
exports.createImageData = createImageDataMethod || exports.createImageData;
|
|
7986
8651
|
}
|
|
7987
8652
|
|
|
7988
|
-
},{"./jpeg":
|
|
8653
|
+
},{"./jpeg":12,"pako":21}],10:[function(require,module,exports){
|
|
7989
8654
|
"use strict";
|
|
7990
8655
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7991
8656
|
exports.resourceHandlersMap = exports.resourceHandlers = void 0;
|
|
8657
|
+
exports.shouldReadResource = shouldReadResource;
|
|
7992
8658
|
const base64_js_1 = require("base64-js");
|
|
7993
8659
|
const additionalInfo_1 = require("./additionalInfo");
|
|
7994
8660
|
const psdReader_1 = require("./psdReader");
|
|
@@ -7998,13 +8664,36 @@ const utf8_1 = require("./utf8");
|
|
|
7998
8664
|
const descriptor_1 = require("./descriptor");
|
|
7999
8665
|
exports.resourceHandlers = [];
|
|
8000
8666
|
exports.resourceHandlersMap = {};
|
|
8667
|
+
// fields accessed by `has` function, these are the fields that writer stores in the resource
|
|
8668
|
+
function fieldsCheckedBy(has) {
|
|
8669
|
+
const fields = [];
|
|
8670
|
+
const target = new Proxy({}, {
|
|
8671
|
+
get(_, field) {
|
|
8672
|
+
if (typeof field === 'string' && !fields.includes(field))
|
|
8673
|
+
fields.push(field);
|
|
8674
|
+
return undefined;
|
|
8675
|
+
},
|
|
8676
|
+
});
|
|
8677
|
+
try {
|
|
8678
|
+
has(target);
|
|
8679
|
+
}
|
|
8680
|
+
catch (_a) { }
|
|
8681
|
+
return fields;
|
|
8682
|
+
}
|
|
8001
8683
|
function addHandler(key, has, read, write, options = {}) {
|
|
8002
|
-
var _a;
|
|
8003
|
-
const
|
|
8684
|
+
var _a, _b;
|
|
8685
|
+
const fields = (_a = options.fields) !== null && _a !== void 0 ? _a : fieldsCheckedBy(has);
|
|
8686
|
+
const handler = { key, keyCount: (_b = options.keyCount) !== null && _b !== void 0 ? _b : 1, has, read, write, name: options.name, fields };
|
|
8004
8687
|
exports.resourceHandlers.push(handler);
|
|
8005
8688
|
for (let i = 0; i < handler.keyCount; i++)
|
|
8006
8689
|
exports.resourceHandlersMap[handler.key + i] = handler;
|
|
8007
8690
|
}
|
|
8691
|
+
// resources used when reading layers and composite image, they're always read
|
|
8692
|
+
const requiredFields = ['layersGroup', 'layerGroupsEnabledId', 'alphaChannelNames', 'transparencyIndex'];
|
|
8693
|
+
// returns false if resource should be skipped because none of its fields are listed in `imageResourcesWhitelist` read option
|
|
8694
|
+
function shouldReadResource(handler, whitelist) {
|
|
8695
|
+
return !whitelist || handler.fields.some(field => whitelist.includes(field) || requiredFields.includes(field));
|
|
8696
|
+
}
|
|
8008
8697
|
const LOG_MOCK_HANDLERS = false;
|
|
8009
8698
|
const RESOLUTION_UNITS = [undefined, 'PPI', 'PPCM'];
|
|
8010
8699
|
const MEASUREMENT_UNITS = [undefined, 'Inches', 'Centimeters', 'Points', 'Picas', 'Columns'];
|
|
@@ -8335,7 +9024,7 @@ addHandler(1007, // Display info (obsolete, replaced by 1077), written back as 1
|
|
|
8335
9024
|
// 1077 resource has more precise data and is used if present
|
|
8336
9025
|
if (!target.alphaChannelDisplayInfo)
|
|
8337
9026
|
target.alphaChannelDisplayInfo = info;
|
|
8338
|
-
}, () => { });
|
|
9027
|
+
}, () => { }, { fields: ['alphaChannelDisplayInfo'] });
|
|
8339
9028
|
addHandler(1077, // Display info (alpha and spot channels)
|
|
8340
9029
|
// Display info (alpha and spot channels)
|
|
8341
9030
|
target => target.alphaChannelDisplayInfo !== undefined, (reader, target, left) => {
|
|
@@ -8501,6 +9190,38 @@ function writeTransferFunctions(writer, functions) {
|
|
|
8501
9190
|
(0, psdWriter_1.writeUint16)(writer, f.override ? 1 : 0);
|
|
8502
9191
|
}
|
|
8503
9192
|
}
|
|
9193
|
+
addHandler(1014, // Duotone halftoning information
|
|
9194
|
+
// Duotone halftoning information
|
|
9195
|
+
target => target.duotoneHalftoneScreens !== undefined, (reader, target, left) => target.duotoneHalftoneScreens = readHalftoneScreens(reader, left), (writer, target) => writeHalftoneScreens(writer, target.duotoneHalftoneScreens));
|
|
9196
|
+
addHandler(1017, // Duotone transfer functions
|
|
9197
|
+
// Duotone transfer functions
|
|
9198
|
+
target => target.duotoneTransferFunctions !== undefined, (reader, target, left) => target.duotoneTransferFunctions = readTransferFunctions(reader, left), (writer, target) => writeTransferFunctions(writer, target.duotoneTransferFunctions));
|
|
9199
|
+
addHandler(1018, // Duotone image information
|
|
9200
|
+
// Duotone image information
|
|
9201
|
+
target => target.duotoneImageInformation !== undefined, (reader, target, left) => target.duotoneImageInformation = (0, psdReader_1.readBytes)(reader, left()), (writer, target) => (0, psdWriter_1.writeBytes)(writer, target.duotoneImageInformation));
|
|
9202
|
+
addHandler(1066, // Alternate duotone colors
|
|
9203
|
+
// Alternate duotone colors
|
|
9204
|
+
target => target.alternateDuotoneColors !== undefined, (reader, target, left) => {
|
|
9205
|
+
if ((0, psdReader_1.readUint16)(reader) !== 1)
|
|
9206
|
+
throw new Error('Invalid alternate duotone colors version');
|
|
9207
|
+
const colors = [];
|
|
9208
|
+
const count = (0, psdReader_1.readUint16)(reader);
|
|
9209
|
+
for (let i = 0; i < count && left() >= 10; i++)
|
|
9210
|
+
colors.push((0, psdReader_1.readColor)(reader));
|
|
9211
|
+
const labCount = (0, psdReader_1.readUint16)(reader);
|
|
9212
|
+
if (labCount * 3 > left())
|
|
9213
|
+
throw new Error('Invalid alternate duotone colors Lab table size');
|
|
9214
|
+
const labColors = (0, psdReader_1.readBytes)(reader, labCount * 3);
|
|
9215
|
+
target.alternateDuotoneColors = { colors, labColors };
|
|
9216
|
+
}, (writer, target) => {
|
|
9217
|
+
const { colors, labColors } = target.alternateDuotoneColors;
|
|
9218
|
+
(0, psdWriter_1.writeUint16)(writer, 1); // version
|
|
9219
|
+
(0, psdWriter_1.writeUint16)(writer, colors.length);
|
|
9220
|
+
for (const color of colors)
|
|
9221
|
+
(0, psdWriter_1.writeColor)(writer, color);
|
|
9222
|
+
(0, psdWriter_1.writeUint16)(writer, Math.floor(labColors.byteLength / 3));
|
|
9223
|
+
(0, psdWriter_1.writeBytes)(writer, labColors.subarray(0, Math.floor(labColors.byteLength / 3) * 3));
|
|
9224
|
+
});
|
|
8504
9225
|
addHandler(1015, // Grayscale and multichannel transfer function
|
|
8505
9226
|
// Grayscale and multichannel transfer function
|
|
8506
9227
|
target => target.grayscaleTransferFunctions !== undefined, (reader, target, left) => target.grayscaleTransferFunctions = readTransferFunctions(reader, left), (writer, target) => writeTransferFunctions(writer, target.grayscaleTransferFunctions));
|
|
@@ -8766,7 +9487,7 @@ target => target.timelineInformation !== undefined, (reader, target) => {
|
|
|
8766
9487
|
workOutTime: (0, descriptor_1.frac)(desc.workOutTime),
|
|
8767
9488
|
repeats: desc.LCnt,
|
|
8768
9489
|
hasMotion: desc.hasMotion,
|
|
8769
|
-
globalTracks: (0, descriptor_1.parseTrackList)(desc.globalTrackList,
|
|
9490
|
+
globalTracks: (0, descriptor_1.parseTrackList)(desc.globalTrackList, reader),
|
|
8770
9491
|
};
|
|
8771
9492
|
if ((_b = (_a = desc.audioClipGroupList) === null || _a === void 0 ? void 0 : _a.audioClipGroupList) === null || _b === void 0 ? void 0 : _b.length) {
|
|
8772
9493
|
target.timelineInformation.audioClipGroups = desc.audioClipGroupList.audioClipGroupList.map(g => ({
|
|
@@ -8805,7 +9526,7 @@ target => target.timelineInformation !== undefined, (reader, target) => {
|
|
|
8805
9526
|
workInTime: timeline.workInTime,
|
|
8806
9527
|
workOutTime: timeline.workOutTime,
|
|
8807
9528
|
LCnt: timeline.repeats,
|
|
8808
|
-
globalTrackList: (0, descriptor_1.serializeTrackList)(timeline.globalTracks),
|
|
9529
|
+
globalTrackList: (0, descriptor_1.serializeTrackList)(timeline.globalTracks, writer),
|
|
8809
9530
|
audioClipGroupList: {
|
|
8810
9531
|
audioClipGroupList: ((_a = timeline.audioClipGroups) !== null && _a !== void 0 ? _a : []).map(a => ({
|
|
8811
9532
|
groupID: a.id,
|
|
@@ -8905,6 +9626,7 @@ const sliceAlignments = ['default'];
|
|
|
8905
9626
|
addHandler(1050, // Slices
|
|
8906
9627
|
// Slices
|
|
8907
9628
|
target => target.slices ? target.slices.length : 0, (reader, target, leftBytes) => {
|
|
9629
|
+
var _a;
|
|
8908
9630
|
const version = (0, psdReader_1.readUint32)(reader);
|
|
8909
9631
|
if (version === 6) {
|
|
8910
9632
|
if (!target.slices)
|
|
@@ -8971,7 +9693,7 @@ target => target.slices ? target.slices.length : 0, (reader, target, leftBytes)
|
|
|
8971
9693
|
if (!target.slices)
|
|
8972
9694
|
target.slices = [];
|
|
8973
9695
|
target.slices.push({
|
|
8974
|
-
groupName: desc.baseName,
|
|
9696
|
+
groupName: (_a = desc.baseName) !== null && _a !== void 0 ? _a : '',
|
|
8975
9697
|
bounds: boundsFromBounds(desc.bounds),
|
|
8976
9698
|
slices: desc.slices.map(s => (Object.assign(Object.assign({}, (s['Nm '] ? { name: s['Nm '] } : {})), { id: s.sliceID, groupId: s.groupID, associatedLayerId: 0, origin: descriptor_1.ESliceOrigin.decode(s.origin), type: descriptor_1.ESliceType.decode(s.Type), bounds: boundsFromBounds(s.bounds), url: s.url, target: s.null, message: s.Msge, altTag: s.altTag, cellTextIsHTML: s.cellTextIsHTML, cellText: s.cellText, horizontalAlignment: descriptor_1.ESliceHorzAlign.decode(s.horzAlign), verticalAlignment: descriptor_1.ESliceVertAlign.decode(s.vertAlign), backgroundColorType: descriptor_1.ESliceBGColorType.decode(s.bgColorType), backgroundColor: s.bgColor ? { r: s.bgColor['Rd '], g: s.bgColor['Grn '], b: s.bgColor['Bl '], a: s.bgColor.alpha } : { r: 0, g: 0, b: 0, a: 0 }, topOutset: s.topOutset || 0, leftOutset: s.leftOutset || 0, bottomOutset: s.bottomOutset || 0, rightOutset: s.rightOutset || 0 }))),
|
|
8977
9699
|
});
|
|
@@ -9063,10 +9785,13 @@ target => target.iccProfile !== undefined, (reader, target, left) => {
|
|
|
9063
9785
|
addHandler(1044, target => target.idsSeedNumber !== undefined, (reader, target) => target.idsSeedNumber = (0, psdReader_1.readUint32)(reader), (writer, target) => (0, psdWriter_1.writeUint32)(writer, target.idsSeedNumber));
|
|
9064
9786
|
addHandler(1038, // Color samplers (Photoshop 5.0, replaced by 1073 in CS3)
|
|
9065
9787
|
// Color samplers (Photoshop 5.0, replaced by 1073 in CS3)
|
|
9066
|
-
target => target.colorSamplers !== undefined, (reader, target, left) => {
|
|
9788
|
+
target => target.colorSamplers !== undefined && !target.colorSamplers.some(s => s.depth !== undefined), (reader, target, left) => {
|
|
9789
|
+
var _a;
|
|
9067
9790
|
const version = (0, psdReader_1.readUint32)(reader);
|
|
9068
9791
|
if (version !== 1)
|
|
9069
9792
|
throw new Error(`Invalid color samplers version: ${version}`);
|
|
9793
|
+
if ((_a = target.colorSamplers) === null || _a === void 0 ? void 0 : _a.some(s => s.depth !== undefined))
|
|
9794
|
+
return (0, psdReader_1.skipBytes)(reader, left()); // already read from 1073
|
|
9070
9795
|
const count = (0, psdReader_1.readUint32)(reader);
|
|
9071
9796
|
target.colorSamplers = [];
|
|
9072
9797
|
for (let i = 0; i < count && left() >= 10; i++) {
|
|
@@ -9086,6 +9811,52 @@ target => target.colorSamplers !== undefined, (reader, target, left) => {
|
|
|
9086
9811
|
(0, psdWriter_1.writeInt16)(writer, sampler.colorSpace);
|
|
9087
9812
|
}
|
|
9088
9813
|
});
|
|
9814
|
+
addHandler(1073, // Color samplers (Photoshop CS3)
|
|
9815
|
+
// Color samplers (Photoshop CS3)
|
|
9816
|
+
target => target.colorSamplers !== undefined && target.colorSamplers.some(s => s.depth !== undefined), (reader, target, left) => {
|
|
9817
|
+
const version = (0, psdReader_1.readUint32)(reader);
|
|
9818
|
+
if (version < 1 || version > 3)
|
|
9819
|
+
throw new Error(`Invalid color samplers version: ${version}`);
|
|
9820
|
+
const count = (0, psdReader_1.readUint32)(reader);
|
|
9821
|
+
target.colorSamplers = [];
|
|
9822
|
+
for (let i = 0; i < count && left() >= 10; i++) {
|
|
9823
|
+
// position is fixed point value for sampler version 1 (stored the same way as in 1038 resource) or float for version 2
|
|
9824
|
+
const samplerVersion = version === 3 ? (0, psdReader_1.readUint32)(reader) : version;
|
|
9825
|
+
const y = samplerVersion === 1 ? (0, psdReader_1.readInt32)(reader) / 16 : (0, psdReader_1.readFloat32)(reader);
|
|
9826
|
+
const x = samplerVersion === 1 ? (0, psdReader_1.readInt32)(reader) / 16 : (0, psdReader_1.readFloat32)(reader);
|
|
9827
|
+
const colorSpace = (0, psdReader_1.readInt16)(reader);
|
|
9828
|
+
const depth = version >= 2 ? (0, psdReader_1.readInt16)(reader) : 1;
|
|
9829
|
+
target.colorSamplers.push({ x, y, colorSpace, depth });
|
|
9830
|
+
}
|
|
9831
|
+
}, (writer, target) => {
|
|
9832
|
+
var _a;
|
|
9833
|
+
(0, psdWriter_1.writeUint32)(writer, 3); // version
|
|
9834
|
+
(0, psdWriter_1.writeUint32)(writer, target.colorSamplers.length);
|
|
9835
|
+
for (const sampler of target.colorSamplers) {
|
|
9836
|
+
(0, psdWriter_1.writeUint32)(writer, 1); // sampler version
|
|
9837
|
+
(0, psdWriter_1.writeInt32)(writer, Math.round(sampler.y * 16));
|
|
9838
|
+
(0, psdWriter_1.writeInt32)(writer, Math.round(sampler.x * 16));
|
|
9839
|
+
(0, psdWriter_1.writeInt16)(writer, sampler.colorSpace);
|
|
9840
|
+
(0, psdWriter_1.writeInt16)(writer, (_a = sampler.depth) !== null && _a !== void 0 ? _a : 1);
|
|
9841
|
+
}
|
|
9842
|
+
});
|
|
9843
|
+
addHandler(1022, // Quick Mask information
|
|
9844
|
+
// Quick Mask information
|
|
9845
|
+
target => target.quickMaskInfo !== undefined, (reader, target) => {
|
|
9846
|
+
const channelId = (0, psdReader_1.readUint16)(reader);
|
|
9847
|
+
const initiallyEmpty = !!(0, psdReader_1.readUint8)(reader);
|
|
9848
|
+
target.quickMaskInfo = { channelId, initiallyEmpty };
|
|
9849
|
+
}, (writer, target) => {
|
|
9850
|
+
(0, psdWriter_1.writeUint16)(writer, target.quickMaskInfo.channelId);
|
|
9851
|
+
(0, psdWriter_1.writeUint8)(writer, target.quickMaskInfo.initiallyEmpty ? 1 : 0);
|
|
9852
|
+
});
|
|
9853
|
+
addHandler(1074, // Measurement scale
|
|
9854
|
+
// Measurement scale
|
|
9855
|
+
target => target.measurementScale !== undefined, (reader, target, left) => {
|
|
9856
|
+
target.measurementScale = (0, psdReader_1.readBytes)(reader, left());
|
|
9857
|
+
}, (writer, target) => {
|
|
9858
|
+
(0, psdWriter_1.writeBytes)(writer, target.measurementScale);
|
|
9859
|
+
});
|
|
9089
9860
|
addHandler(1042, // Effects visible (only present when effects are hidden)
|
|
9090
9861
|
// Effects visible (only present when effects are hidden)
|
|
9091
9862
|
target => target.effectsVisible !== undefined, (reader, target) => {
|
|
@@ -9419,7 +10190,7 @@ target => pluginResourceKeys(target).length, (reader, target, left) => {
|
|
|
9419
10190
|
}
|
|
9420
10191
|
}, { keyCount: 1000 });
|
|
9421
10192
|
|
|
9422
|
-
},{"./additionalInfo":2,"./descriptor":
|
|
10193
|
+
},{"./additionalInfo":2,"./descriptor":5,"./helpers":9,"./psdReader":14,"./psdWriter":15,"./utf8":17,"base64-js":18}],11:[function(require,module,exports){
|
|
9423
10194
|
(function (Buffer){(function (){
|
|
9424
10195
|
"use strict";
|
|
9425
10196
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
@@ -9437,7 +10208,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
9437
10208
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
9438
10209
|
};
|
|
9439
10210
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9440
|
-
exports.getCompositeCanvas = exports.getCompositeImageData = exports.getLayerRealMaskCanvas = exports.getLayerMaskCanvas = exports.getLayerCanvas = exports.getLayerRealMaskImageData = exports.getLayerMaskImageData = exports.getLayerImageData = exports.decodeLayerPixels = exports.byteArrayToBase64 = exports.initializeCanvas = void 0;
|
|
10211
|
+
exports.getFilterEffectsMaskExtraCanvas = exports.getFilterEffectsMaskCanvas = exports.getFilterEffectsMaskExtraImageData = exports.getFilterEffectsMaskImageData = exports.getCompositeCanvas = exports.getCompositeImageData = exports.getLayerRealMaskCanvas = exports.getLayerMaskCanvas = exports.getLayerCanvas = exports.getLayerRealMaskImageData = exports.getLayerMaskImageData = exports.getLayerImageData = exports.decodeLayerPixels = exports.byteArrayToBase64 = exports.initializeCanvas = void 0;
|
|
9441
10212
|
exports.readPsd = readPsd;
|
|
9442
10213
|
exports.writePsd = writePsd;
|
|
9443
10214
|
exports.writePsdUint8Array = writePsdUint8Array;
|
|
@@ -9453,9 +10224,14 @@ Object.defineProperty(exports, "getLayerMaskCanvas", { enumerable: true, get: fu
|
|
|
9453
10224
|
Object.defineProperty(exports, "getLayerRealMaskCanvas", { enumerable: true, get: function () { return psdReader_1.getLayerRealMaskCanvas; } });
|
|
9454
10225
|
Object.defineProperty(exports, "getCompositeImageData", { enumerable: true, get: function () { return psdReader_1.getCompositeImageData; } });
|
|
9455
10226
|
Object.defineProperty(exports, "getCompositeCanvas", { enumerable: true, get: function () { return psdReader_1.getCompositeCanvas; } });
|
|
10227
|
+
Object.defineProperty(exports, "getFilterEffectsMaskImageData", { enumerable: true, get: function () { return psdReader_1.getFilterEffectsMaskImageData; } });
|
|
10228
|
+
Object.defineProperty(exports, "getFilterEffectsMaskExtraImageData", { enumerable: true, get: function () { return psdReader_1.getFilterEffectsMaskExtraImageData; } });
|
|
10229
|
+
Object.defineProperty(exports, "getFilterEffectsMaskCanvas", { enumerable: true, get: function () { return psdReader_1.getFilterEffectsMaskCanvas; } });
|
|
10230
|
+
Object.defineProperty(exports, "getFilterEffectsMaskExtraCanvas", { enumerable: true, get: function () { return psdReader_1.getFilterEffectsMaskExtraCanvas; } });
|
|
9456
10231
|
const base64_js_1 = require("base64-js");
|
|
9457
10232
|
__exportStar(require("./abr"), exports);
|
|
9458
10233
|
__exportStar(require("./csh"), exports);
|
|
10234
|
+
__exportStar(require("./ase"), exports);
|
|
9459
10235
|
var helpers_1 = require("./helpers");
|
|
9460
10236
|
Object.defineProperty(exports, "initializeCanvas", { enumerable: true, get: function () { return helpers_1.initializeCanvas; } });
|
|
9461
10237
|
__exportStar(require("./psd"), exports);
|
|
@@ -9485,7 +10261,7 @@ function writePsdBuffer(psd, options) {
|
|
|
9485
10261
|
}
|
|
9486
10262
|
|
|
9487
10263
|
}).call(this)}).call(this,require("buffer").Buffer)
|
|
9488
|
-
},{"./abr":1,"./
|
|
10264
|
+
},{"./abr":1,"./ase":3,"./csh":4,"./helpers":9,"./psd":13,"./psdReader":14,"./psdWriter":15,"base64-js":18,"buffer":19}],12:[function(require,module,exports){
|
|
9489
10265
|
"use strict";
|
|
9490
10266
|
// based on https://github.com/jpeg-js/jpeg-js
|
|
9491
10267
|
/*
|
|
@@ -10539,7 +11315,7 @@ function decodeJpeg(encoded, createImageData) {
|
|
|
10539
11315
|
return imageData;
|
|
10540
11316
|
}
|
|
10541
11317
|
|
|
10542
|
-
},{}],
|
|
11318
|
+
},{}],13:[function(require,module,exports){
|
|
10543
11319
|
"use strict";
|
|
10544
11320
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10545
11321
|
exports.Compression = exports.ChannelID = exports.LayerCompCapturedInfo = exports.SectionDividerType = exports.ColorMode = void 0;
|
|
@@ -10588,7 +11364,7 @@ var Compression;
|
|
|
10588
11364
|
Compression[Compression["ZipWithPrediction"] = 3] = "ZipWithPrediction";
|
|
10589
11365
|
})(Compression || (exports.Compression = Compression = {}));
|
|
10590
11366
|
|
|
10591
|
-
},{}],
|
|
11367
|
+
},{}],14:[function(require,module,exports){
|
|
10592
11368
|
"use strict";
|
|
10593
11369
|
var __rest = (this && this.__rest) || function (s, e) {
|
|
10594
11370
|
var t = {};
|
|
@@ -10641,6 +11417,10 @@ exports.getLayerRealMaskImageData = getLayerRealMaskImageData;
|
|
|
10641
11417
|
exports.getLayerCanvas = getLayerCanvas;
|
|
10642
11418
|
exports.getLayerMaskCanvas = getLayerMaskCanvas;
|
|
10643
11419
|
exports.getLayerRealMaskCanvas = getLayerRealMaskCanvas;
|
|
11420
|
+
exports.getFilterEffectsMaskImageData = getFilterEffectsMaskImageData;
|
|
11421
|
+
exports.getFilterEffectsMaskExtraImageData = getFilterEffectsMaskExtraImageData;
|
|
11422
|
+
exports.getFilterEffectsMaskCanvas = getFilterEffectsMaskCanvas;
|
|
11423
|
+
exports.getFilterEffectsMaskExtraCanvas = getFilterEffectsMaskExtraCanvas;
|
|
10644
11424
|
exports.decodeLayerPixels = decodeLayerPixels;
|
|
10645
11425
|
exports.readGlobalLayerMaskInfo = readGlobalLayerMaskInfo;
|
|
10646
11426
|
exports.readAdditionalLayerInfo = readAdditionalLayerInfo;
|
|
@@ -10756,6 +11536,9 @@ function readFixedPointPath32(reader) {
|
|
|
10756
11536
|
}
|
|
10757
11537
|
// NOTE: returned array may alias the reader's underlying buffer, never write into it
|
|
10758
11538
|
function readBytes(reader, length) {
|
|
11539
|
+
// negative length comes from sizes computed from malformed data (e.g. section shorter than its header)
|
|
11540
|
+
if (!(length >= 0))
|
|
11541
|
+
throw new Error(`Invalid length: ${length}`);
|
|
10759
11542
|
const start = reader.offset;
|
|
10760
11543
|
const viewLength = reader.view.byteLength;
|
|
10761
11544
|
reader.offset += length;
|
|
@@ -10797,6 +11580,8 @@ function readUnicodeString(reader) {
|
|
|
10797
11580
|
return readUnicodeStringWithLength(reader, length);
|
|
10798
11581
|
}
|
|
10799
11582
|
const STRING_CHUNK_SIZE = 0x2000;
|
|
11583
|
+
// shorter strings (most descriptor keys, OSTypes and names) are faster to build with simple loop than String.fromCharCode.apply
|
|
11584
|
+
const SHORT_STRING_LENGTH = 64;
|
|
10800
11585
|
function checkReadBounds(reader, size) {
|
|
10801
11586
|
if (reader.offset < 0 || (reader.offset + size) > reader.view.byteLength) {
|
|
10802
11587
|
throw new RangeError('Offset is outside the bounds of the DataView');
|
|
@@ -10807,9 +11592,18 @@ function readUtf16String(reader, length, littleEndian) {
|
|
|
10807
11592
|
return '';
|
|
10808
11593
|
checkReadBounds(reader, length * 2);
|
|
10809
11594
|
const view = reader.view;
|
|
10810
|
-
const codes = new Uint16Array(Math.min(length, STRING_CHUNK_SIZE));
|
|
10811
11595
|
let offset = reader.offset;
|
|
10812
11596
|
let text = '';
|
|
11597
|
+
if (length <= SHORT_STRING_LENGTH) {
|
|
11598
|
+
for (let i = 0; i < length; i++, offset += 2) {
|
|
11599
|
+
text += String.fromCharCode(view.getUint16(offset, littleEndian));
|
|
11600
|
+
}
|
|
11601
|
+
reader.offset = offset;
|
|
11602
|
+
if (text.charCodeAt(text.length - 1) === 0)
|
|
11603
|
+
text = text.substring(0, text.length - 1);
|
|
11604
|
+
return text;
|
|
11605
|
+
}
|
|
11606
|
+
const codes = new Uint16Array(Math.min(length, STRING_CHUNK_SIZE));
|
|
10813
11607
|
for (let i = 0; i < length; i += STRING_CHUNK_SIZE) {
|
|
10814
11608
|
const count = Math.min(STRING_CHUNK_SIZE, length - i);
|
|
10815
11609
|
for (let j = 0; j < count; j++, offset += 2) {
|
|
@@ -10840,6 +11634,15 @@ function readAsciiString(reader, length) {
|
|
|
10840
11634
|
if (!(length > 0))
|
|
10841
11635
|
return '';
|
|
10842
11636
|
checkReadBounds(reader, length);
|
|
11637
|
+
if (length <= SHORT_STRING_LENGTH) {
|
|
11638
|
+
const view = reader.view;
|
|
11639
|
+
let text = '';
|
|
11640
|
+
for (let i = 0, offset = reader.offset; i < length; i++, offset++) {
|
|
11641
|
+
text += String.fromCharCode(view.getUint8(offset));
|
|
11642
|
+
}
|
|
11643
|
+
reader.offset += length;
|
|
11644
|
+
return text;
|
|
11645
|
+
}
|
|
10843
11646
|
const text = bytesToString(new Uint8Array(reader.view.buffer, reader.view.byteOffset + reader.offset, length));
|
|
10844
11647
|
reader.offset += length;
|
|
10845
11648
|
return text;
|
|
@@ -10855,7 +11658,14 @@ function checkSignature(reader, a, b) {
|
|
|
10855
11658
|
}
|
|
10856
11659
|
}
|
|
10857
11660
|
function readShortString(reader, length) {
|
|
10858
|
-
|
|
11661
|
+
const bytes = readBytes(reader, length);
|
|
11662
|
+
if (length > SHORT_STRING_LENGTH)
|
|
11663
|
+
return bytesToString(bytes);
|
|
11664
|
+
let text = '';
|
|
11665
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
11666
|
+
text += String.fromCharCode(bytes[i]);
|
|
11667
|
+
}
|
|
11668
|
+
return text;
|
|
10859
11669
|
}
|
|
10860
11670
|
function isValidSignature(sig) {
|
|
10861
11671
|
return sig === '8BIM' || sig === 'MeSa' || sig === 'AgHg' || sig === 'PHUT' || sig === 'DCSR';
|
|
@@ -10926,16 +11736,21 @@ function readPsd(reader, readOptions = {}) {
|
|
|
10926
11736
|
skipBytes(reader, (nameLength + 1) % 2); // pad to even size
|
|
10927
11737
|
readSection(reader, 2, left => {
|
|
10928
11738
|
const handler = imageResources_1.resourceHandlersMap[id];
|
|
10929
|
-
|
|
10930
|
-
|
|
10931
|
-
|
|
10932
|
-
handler.read(reader, imageResources, left, { signature, id, name, width, height });
|
|
10933
|
-
}
|
|
10934
|
-
catch (e) {
|
|
10935
|
-
if (reader.throwForMissingFeatures)
|
|
10936
|
-
throw e;
|
|
11739
|
+
if (handler) {
|
|
11740
|
+
const skip = (id === 1036 && !!reader.skipThumbnail) || !(0, imageResources_1.shouldReadResource)(handler, reader.imageResourcesWhitelist);
|
|
11741
|
+
if (skip) {
|
|
10937
11742
|
skipBytes(reader, left());
|
|
10938
11743
|
}
|
|
11744
|
+
else {
|
|
11745
|
+
try {
|
|
11746
|
+
handler.read(reader, imageResources, left, { signature, id, name, width, height });
|
|
11747
|
+
}
|
|
11748
|
+
catch (e) {
|
|
11749
|
+
if (reader.throwForMissingFeatures)
|
|
11750
|
+
throw e;
|
|
11751
|
+
skipBytes(reader, left());
|
|
11752
|
+
}
|
|
11753
|
+
}
|
|
10939
11754
|
}
|
|
10940
11755
|
else {
|
|
10941
11756
|
reader.logMissingFeatures && reader.log(`Unhandled image resource: ${id} (${left()})`);
|
|
@@ -11041,6 +11856,9 @@ function readLayerInfo(reader, psd, imageResources) {
|
|
|
11041
11856
|
if (type === 1 /* SectionDividerType.OpenFolder */ || type === 2 /* SectionDividerType.ClosedFolder */) {
|
|
11042
11857
|
l.opened = type === 1 /* SectionDividerType.OpenFolder */;
|
|
11043
11858
|
l.children = [];
|
|
11859
|
+
// group layers can't have image data, some broken files have it, ignore it like Photoshop does
|
|
11860
|
+
delete l.canvas;
|
|
11861
|
+
delete l.imageData;
|
|
11044
11862
|
if ((_a = l.sectionDivider) === null || _a === void 0 ? void 0 : _a.key) {
|
|
11045
11863
|
l.blendMode = (_b = helpers_1.toBlendMode[l.sectionDivider.key]) !== null && _b !== void 0 ? _b : l.blendMode;
|
|
11046
11864
|
}
|
|
@@ -11239,9 +12057,8 @@ function readLayerChannelImageData(reader, psd, layer, channels) {
|
|
|
11239
12057
|
const start = reader.offset;
|
|
11240
12058
|
let compression = 0 /* Compression.RawData */;
|
|
11241
12059
|
let data = undefined;
|
|
11242
|
-
|
|
11243
|
-
|
|
11244
|
-
if (channel.length) {
|
|
12060
|
+
// channel length of 1 is invalid (should be 0 or at least 2), skip the byte and treat channel as empty
|
|
12061
|
+
if (channel.length >= 2) {
|
|
11245
12062
|
compression = readUint16(reader);
|
|
11246
12063
|
// try to fix broken files where there's 1 byte shift of channel
|
|
11247
12064
|
if (compression > 3) {
|
|
@@ -11263,7 +12080,16 @@ function readLayerChannelImageData(reader, psd, layer, channels) {
|
|
|
11263
12080
|
layer.rawData.channels.push({ id: channel.id, compression, data });
|
|
11264
12081
|
}
|
|
11265
12082
|
if (!reader.useRawData) {
|
|
11266
|
-
|
|
12083
|
+
try {
|
|
12084
|
+
decodeLayerImageData(layer, reader);
|
|
12085
|
+
}
|
|
12086
|
+
catch (e) {
|
|
12087
|
+
// corrupted image data of one layer shouldn't prevent reading rest of the file
|
|
12088
|
+
if (reader.throwForMissingFeatures || e.message === 'Exceeded memory limit')
|
|
12089
|
+
throw e;
|
|
12090
|
+
reader.logMissingFeatures && reader.log(`Failed to decode layer image data: ${e.message}`);
|
|
12091
|
+
delete layer.rawData;
|
|
12092
|
+
}
|
|
11267
12093
|
}
|
|
11268
12094
|
}
|
|
11269
12095
|
function resetAlpha({ data }, cmyk) {
|
|
@@ -11309,6 +12135,67 @@ function getLayerMaskCanvas(layer) {
|
|
|
11309
12135
|
function getLayerRealMaskCanvas(layer) {
|
|
11310
12136
|
return imageDataToCanvasSafe(getLayerRealMaskImageData(layer));
|
|
11311
12137
|
}
|
|
12138
|
+
function getFilterEffectsMaskImageData(mask) {
|
|
12139
|
+
const { depth, channels, colorMode = 3 /* ColorMode.RGB */ } = mask;
|
|
12140
|
+
const width = Math.max(0, mask.right - mask.left);
|
|
12141
|
+
const height = Math.max(0, mask.bottom - mask.top);
|
|
12142
|
+
if (!width || !height)
|
|
12143
|
+
return undefined;
|
|
12144
|
+
const cmyk = colorMode === 4 /* ColorMode.CMYK */;
|
|
12145
|
+
if (cmyk && depth !== 8 && depth !== 16)
|
|
12146
|
+
throw new Error('bitsPerChannel not supported');
|
|
12147
|
+
const step = cmyk ? 5 : 4;
|
|
12148
|
+
// channels are color channels, followed by user mask and transparency
|
|
12149
|
+
const transparencyIndex = channels.length - 1;
|
|
12150
|
+
const colorChannels = Math.min(cmyk ? 4 : (colorMode === 1 /* ColorMode.Grayscale */ ? 1 : 3), channels.length - 2);
|
|
12151
|
+
let imageData = createImageDataBitDepth(width, height, depth, step, undefined);
|
|
12152
|
+
for (let i = 0; i < channels.length; i++) {
|
|
12153
|
+
const channel = channels[i];
|
|
12154
|
+
if (!channel)
|
|
12155
|
+
continue;
|
|
12156
|
+
if (i < colorChannels) {
|
|
12157
|
+
readFilterEffectsChannel(channel, imageData, width, height, depth, i, step);
|
|
12158
|
+
}
|
|
12159
|
+
else if (i === transparencyIndex) {
|
|
12160
|
+
readFilterEffectsChannel(channel, imageData, width, height, depth, step - 1, step);
|
|
12161
|
+
}
|
|
12162
|
+
}
|
|
12163
|
+
if (colorMode === 1 /* ColorMode.Grayscale */)
|
|
12164
|
+
setupGrayscale(imageData);
|
|
12165
|
+
if (!channels[transparencyIndex])
|
|
12166
|
+
resetAlpha(imageData, cmyk);
|
|
12167
|
+
if (cmyk) {
|
|
12168
|
+
const cmykData = imageData;
|
|
12169
|
+
imageData = createImageDataBitDepth(cmykData.width, cmykData.height, depth, 4, undefined);
|
|
12170
|
+
cmykToRgb(cmykData, imageData, false);
|
|
12171
|
+
}
|
|
12172
|
+
return imageData;
|
|
12173
|
+
}
|
|
12174
|
+
function getFilterEffectsMaskExtraImageData(mask) {
|
|
12175
|
+
const { extra, depth } = mask;
|
|
12176
|
+
if (!extra)
|
|
12177
|
+
return undefined;
|
|
12178
|
+
const width = Math.max(0, extra.right - extra.left);
|
|
12179
|
+
const height = Math.max(0, extra.bottom - extra.top);
|
|
12180
|
+
if (!width || !height)
|
|
12181
|
+
return undefined;
|
|
12182
|
+
const maskData = createImageDataBitDepth(width, height, depth, 4, undefined);
|
|
12183
|
+
readFilterEffectsChannel(extra, maskData, width, height, depth, 0, 4);
|
|
12184
|
+
setupGrayscale(maskData);
|
|
12185
|
+
resetAlpha(maskData, false);
|
|
12186
|
+
return maskData;
|
|
12187
|
+
}
|
|
12188
|
+
function getFilterEffectsMaskCanvas(mask) {
|
|
12189
|
+
return imageDataToCanvasSafe(getFilterEffectsMaskImageData(mask));
|
|
12190
|
+
}
|
|
12191
|
+
function getFilterEffectsMaskExtraCanvas(mask) {
|
|
12192
|
+
return imageDataToCanvasSafe(getFilterEffectsMaskExtraImageData(mask));
|
|
12193
|
+
}
|
|
12194
|
+
function readFilterEffectsChannel({ compressionMode, data }, pixels, width, height, depth, offset, step) {
|
|
12195
|
+
const reader = createReader(data.buffer, data.byteOffset, data.byteLength);
|
|
12196
|
+
// RLE row lengths are always 4 bytes, same as in PSB files
|
|
12197
|
+
readData(reader, data.byteLength, pixels, compressionMode, width, height, depth, offset, true, step);
|
|
12198
|
+
}
|
|
11312
12199
|
function imageDataToCanvasSafe(imageData) {
|
|
11313
12200
|
return imageData && (0, helpers_1.imageDataToCanvas)(imageData);
|
|
11314
12201
|
}
|
|
@@ -11467,7 +12354,7 @@ function readGlobalLayerMaskInfo(reader) {
|
|
|
11467
12354
|
const colorSpace2 = readUint16(reader);
|
|
11468
12355
|
const colorSpace3 = readUint16(reader);
|
|
11469
12356
|
const colorSpace4 = readUint16(reader);
|
|
11470
|
-
const opacity = readUint16(reader) / 100; // 0 - 100
|
|
12357
|
+
const opacity = Math.min(readUint16(reader), 100) / 100; // 0 - 100 (some files have values out of range)
|
|
11471
12358
|
const kind = readUint8(reader);
|
|
11472
12359
|
skipBytes(reader, left()); // 3 bytes of padding ?
|
|
11473
12360
|
return { overlayColorSpace, colorSpace1, colorSpace2, colorSpace3, colorSpace4, opacity, kind };
|
|
@@ -11717,10 +12604,7 @@ function toRange(value, max) {
|
|
|
11717
12604
|
value = Math.round(value * (max / 255));
|
|
11718
12605
|
return value <= 0 ? 0 : (value >= max ? max : value);
|
|
11719
12606
|
}
|
|
11720
|
-
//
|
|
11721
|
-
// Coefficients are taken from pdf.js (DeviceCmykCS in src/core/colorspace.js, https://github.com/mozilla/pdf.js),
|
|
11722
|
-
// Copyright 2012 Mozilla Foundation, licensed under the Apache License, Version 2.0
|
|
11723
|
-
// (http://www.apache.org/licenses/LICENSE-2.0)
|
|
12607
|
+
// converts CMYK data to RGB using approximation of U.S. Web Coated (SWOP) v2 profile (see cmykToRgbValues)
|
|
11724
12608
|
// cmyk - 8 or 16 bit data with 5 channels (cmyka), rgb - 8 or 16 bit data with 4 channels (rgba)
|
|
11725
12609
|
// removeMatte - colors are blended with white (no ink), used for composite image of documents with global alpha
|
|
11726
12610
|
function cmykToRgb(cmyk, rgb, removeMatte) {
|
|
@@ -11729,6 +12613,7 @@ function cmykToRgb(cmyk, rgb, removeMatte) {
|
|
|
11729
12613
|
const dstData = rgb.data;
|
|
11730
12614
|
const srcMax = srcData instanceof Uint16Array ? 0xffff : 0xff;
|
|
11731
12615
|
const dstMax = dstData instanceof Uint16Array ? 0xffff : 0xff;
|
|
12616
|
+
const out = [0, 0, 0];
|
|
11732
12617
|
for (let src = 0, dst = 0; dst < size; src += 5, dst += 4) {
|
|
11733
12618
|
const a = srcData[src + 4];
|
|
11734
12619
|
// image data stores inverted values (0 = 100% ink)
|
|
@@ -11743,21 +12628,10 @@ function cmykToRgb(cmyk, rgb, removeMatte) {
|
|
|
11743
12628
|
y = Math.min(1, y * ra);
|
|
11744
12629
|
k = Math.min(1, k * ra);
|
|
11745
12630
|
}
|
|
11746
|
-
|
|
11747
|
-
|
|
11748
|
-
|
|
11749
|
-
|
|
11750
|
-
k * (-21.86122147463605 * k - 189.48180835922747), dstMax);
|
|
11751
|
-
dstData[dst + 1] = toRange(255 +
|
|
11752
|
-
c * (8.841041422036149 * c + 60.118027045597366 * m + 6.871425592049007 * y + 31.159100130055922 * k - 79.2970844816548) +
|
|
11753
|
-
m * (-15.310361306967817 * m + 17.575251261109482 * y + 131.35250912493976 * k - 190.9453302588951) +
|
|
11754
|
-
y * (4.444339102852739 * y + 9.8632861493405 * k - 24.86741582555878) +
|
|
11755
|
-
k * (-20.737325471181034 * k - 187.80453709719578), dstMax);
|
|
11756
|
-
dstData[dst + 2] = toRange(255 +
|
|
11757
|
-
c * (0.8842522430003296 * c + 8.078677503112928 * m + 30.89978309703729 * y - 0.23883238689178934 * k - 14.183576799673286) +
|
|
11758
|
-
m * (10.49593273432072 * m + 63.02378494754052 * y + 50.606957656360734 * k - 112.23884253719248) +
|
|
11759
|
-
y * (0.03296041114873217 * y + 115.60384449646641 * k - 193.58209356861505) +
|
|
11760
|
-
k * (-22.33816807309886 * k - 180.12613974708367), dstMax);
|
|
12631
|
+
(0, helpers_1.cmykToRgbValues)(c, m, y, k, out);
|
|
12632
|
+
dstData[dst] = toRange(out[0], dstMax);
|
|
12633
|
+
dstData[dst + 1] = toRange(out[1], dstMax);
|
|
12634
|
+
dstData[dst + 2] = toRange(out[2], dstMax);
|
|
11761
12635
|
dstData[dst + 3] = srcMax === dstMax ? a : Math.round(a * dstMax / srcMax);
|
|
11762
12636
|
}
|
|
11763
12637
|
}
|
|
@@ -11825,11 +12699,11 @@ function decodePredicted(data, width, height) {
|
|
|
11825
12699
|
}
|
|
11826
12700
|
const zipOverflow = new Error('Decompressed data exceeds expected size');
|
|
11827
12701
|
// inflates data, stopping when output exceeds expected size (protects against zip bombs)
|
|
11828
|
-
function inflateLimited(compressed, expectedSize, reader) {
|
|
12702
|
+
function inflateLimited(compressed, expectedSize, reader, raw = false) {
|
|
11829
12703
|
const output = new Uint8Array(expectedSize);
|
|
11830
12704
|
let position = 0;
|
|
11831
12705
|
let overflow = false;
|
|
11832
|
-
const inflator = new pako_1.Inflate({ chunkSize: Math.max(1024, Math.min(expectedSize, 0x10000)) });
|
|
12706
|
+
const inflator = new pako_1.Inflate({ chunkSize: Math.max(1024, Math.min(expectedSize, 0x10000)), raw });
|
|
11833
12707
|
inflator.onData = (chunk) => {
|
|
11834
12708
|
const data = chunk;
|
|
11835
12709
|
const count = Math.min(data.length, expectedSize - position);
|
|
@@ -11858,6 +12732,12 @@ function inflateLimited(compressed, expectedSize, reader) {
|
|
|
11858
12732
|
if (reader)
|
|
11859
12733
|
warnOrThrow(reader, zipOverflow.message);
|
|
11860
12734
|
}
|
|
12735
|
+
else if (inflator.err && inflator.msg === 'incorrect data check' && !raw) {
|
|
12736
|
+
// some files have zeroed checksum (filter effects masks written by Photoshop), inflate again skipping zlib header and checksum
|
|
12737
|
+
if (reader)
|
|
12738
|
+
warnOrThrow(reader, `Invalid zip data: ${inflator.msg}`);
|
|
12739
|
+
return inflateLimited(compressed.subarray(2), expectedSize, reader, true);
|
|
12740
|
+
}
|
|
11861
12741
|
else if (inflator.err) {
|
|
11862
12742
|
throw new Error(`Invalid zip data: ${inflator.msg}`);
|
|
11863
12743
|
}
|
|
@@ -11924,8 +12804,8 @@ function readDataZip(compressed, pixelData, width, height, bitDepth, step, offse
|
|
|
11924
12804
|
recoverMemory(reader, expectedSize);
|
|
11925
12805
|
}
|
|
11926
12806
|
}
|
|
11927
|
-
// decodes single PackBits row, returns number of decoded
|
|
11928
|
-
function decodeRLERow(src, i, end, dst,
|
|
12807
|
+
// decodes single PackBits row into byte buffer, returns number of decoded bytes
|
|
12808
|
+
function decodeRLERow(src, i, end, dst, count) {
|
|
11929
12809
|
let x = 0;
|
|
11930
12810
|
while (i < end && x < count) {
|
|
11931
12811
|
const header = src[i++];
|
|
@@ -11936,10 +12816,8 @@ function decodeRLERow(src, i, end, dst, p, step, count) {
|
|
|
11936
12816
|
let n = 257 - header;
|
|
11937
12817
|
if (n > count - x)
|
|
11938
12818
|
n = count - x;
|
|
12819
|
+
dst.fill(value, x, x + n);
|
|
11939
12820
|
x += n;
|
|
11940
|
-
for (; n > 0; n--, p += step) {
|
|
11941
|
-
dst[p] = value;
|
|
11942
|
-
}
|
|
11943
12821
|
}
|
|
11944
12822
|
else if (header < 128) {
|
|
11945
12823
|
let n = header + 1;
|
|
@@ -11947,9 +12825,8 @@ function decodeRLERow(src, i, end, dst, p, step, count) {
|
|
|
11947
12825
|
n = count - x;
|
|
11948
12826
|
if (n > end - i)
|
|
11949
12827
|
n = end - i;
|
|
11950
|
-
|
|
11951
|
-
|
|
11952
|
-
dst[p] = src[i++];
|
|
12828
|
+
for (; n > 0; n--) {
|
|
12829
|
+
dst[x++] = src[i++];
|
|
11953
12830
|
}
|
|
11954
12831
|
}
|
|
11955
12832
|
else {
|
|
@@ -11958,6 +12835,47 @@ function decodeRLERow(src, i, end, dst, p, step, count) {
|
|
|
11958
12835
|
}
|
|
11959
12836
|
return x;
|
|
11960
12837
|
}
|
|
12838
|
+
// decodes RLE rows of single 8bit channel, writing values to `data` with `step`
|
|
12839
|
+
// (kept as single function with the loops, inlining row decoder into readDataRLE makes V8 generate much slower code)
|
|
12840
|
+
function decodeRLEChannel8(src, lengths, li, pos, width, height, data, offset, step) {
|
|
12841
|
+
const srcEnd = src.length | 0;
|
|
12842
|
+
for (let y = 0; y < height; y++, li++) {
|
|
12843
|
+
let i = (pos < srcEnd ? pos : srcEnd) | 0;
|
|
12844
|
+
pos += lengths[li];
|
|
12845
|
+
const end = (pos < srcEnd ? pos : srcEnd) | 0;
|
|
12846
|
+
let p = (offset + y * width * step) | 0;
|
|
12847
|
+
let x = 0;
|
|
12848
|
+
while (i < end && x < width) {
|
|
12849
|
+
const header = src[i++] | 0;
|
|
12850
|
+
if (header > 128) {
|
|
12851
|
+
if (i >= end)
|
|
12852
|
+
break;
|
|
12853
|
+
const value = src[i++] | 0;
|
|
12854
|
+
let n = (257 - header) | 0;
|
|
12855
|
+
if (n > width - x)
|
|
12856
|
+
n = (width - x) | 0;
|
|
12857
|
+
x = (x + n) | 0;
|
|
12858
|
+
for (const pe = (p + n * step) | 0; p < pe; p = (p + step) | 0) {
|
|
12859
|
+
data[p] = value;
|
|
12860
|
+
}
|
|
12861
|
+
}
|
|
12862
|
+
else if (header < 128) {
|
|
12863
|
+
let n = (header + 1) | 0;
|
|
12864
|
+
if (n > width - x)
|
|
12865
|
+
n = (width - x) | 0;
|
|
12866
|
+
if (n > end - i)
|
|
12867
|
+
n = (end - i) | 0;
|
|
12868
|
+
x = (x + n) | 0;
|
|
12869
|
+
for (const ie = (i + n) | 0; i < ie; i = (i + 1) | 0, p = (p + step) | 0) {
|
|
12870
|
+
data[p] = src[i];
|
|
12871
|
+
}
|
|
12872
|
+
}
|
|
12873
|
+
else {
|
|
12874
|
+
// ignore 128
|
|
12875
|
+
}
|
|
12876
|
+
}
|
|
12877
|
+
}
|
|
12878
|
+
}
|
|
11961
12879
|
// converts big-endian 16/32-bit values from bytes and writes them to `data` starting at `p` with `step`
|
|
11962
12880
|
function scatterValues(bytes, count, bpv, data, p, step) {
|
|
11963
12881
|
if (bpv === 2) {
|
|
@@ -11972,8 +12890,8 @@ function scatterValues(bytes, count, bpv, data, p, step) {
|
|
|
11972
12890
|
}
|
|
11973
12891
|
}
|
|
11974
12892
|
}
|
|
11975
|
-
// decodes RLE rows of single channel, each row
|
|
11976
|
-
function
|
|
12893
|
+
// decodes RLE rows of single 16bit or 32bit channel, each row is decoded into `row` buffer and then converted to values
|
|
12894
|
+
function decodeRLEChannelWide(src, lengths, li, pos, width, height, data, offset, step, bpv, row) {
|
|
11977
12895
|
const srcEnd = src.length;
|
|
11978
12896
|
const rowSize = width * bpv;
|
|
11979
12897
|
for (let y = 0; y < height; y++, li++) {
|
|
@@ -11982,25 +12900,24 @@ function decodeRLEChannel(src, lengths, li, pos, width, height, data, offset, st
|
|
|
11982
12900
|
const rowEnd = pos < srcEnd ? pos : srcEnd;
|
|
11983
12901
|
if (rowStart >= rowEnd)
|
|
11984
12902
|
continue;
|
|
11985
|
-
|
|
11986
|
-
|
|
11987
|
-
}
|
|
11988
|
-
else {
|
|
11989
|
-
const decoded = decodeRLERow(src, rowStart, rowEnd, row, 0, 1, rowSize);
|
|
11990
|
-
scatterValues(row, Math.floor(decoded / bpv), bpv, data, offset + y * width * step, step);
|
|
11991
|
-
}
|
|
12903
|
+
const decoded = decodeRLERow(src, rowStart, rowEnd, row, rowSize);
|
|
12904
|
+
scatterValues(row, Math.floor(decoded / bpv), bpv, data, offset + y * width * step, step);
|
|
11992
12905
|
}
|
|
11993
12906
|
}
|
|
11994
12907
|
function readDataRLE(reader, pixelData, width, height, bitDepth, step, offsets, large) {
|
|
11995
12908
|
const data = pixelData && pixelData.data;
|
|
11996
12909
|
const rows = offsets.length * height;
|
|
11997
12910
|
const lengthSize = large ? 4 : 2;
|
|
11998
|
-
|
|
12911
|
+
const lengthsMemory = rows * lengthSize;
|
|
12912
|
+
const srcEnd = reader.view.byteLength;
|
|
12913
|
+
const bpv = bytesPerValue(bitDepth); // throws before consuming memory
|
|
12914
|
+
let lengths;
|
|
12915
|
+
consumeMemory(reader, lengthsMemory);
|
|
11999
12916
|
try {
|
|
12000
|
-
if ((reader.offset +
|
|
12917
|
+
if ((reader.offset + lengthsMemory) > srcEnd) {
|
|
12001
12918
|
throw new Error('RLE row lengths exceed buffer length');
|
|
12002
12919
|
}
|
|
12003
|
-
|
|
12920
|
+
lengths = large ? new Uint32Array(rows) : new Uint16Array(rows);
|
|
12004
12921
|
let total = 0;
|
|
12005
12922
|
if (large) {
|
|
12006
12923
|
for (let i = 0; i < rows; i++)
|
|
@@ -12010,32 +12927,37 @@ function readDataRLE(reader, pixelData, width, height, bitDepth, step, offsets,
|
|
|
12010
12927
|
for (let i = 0; i < rows; i++)
|
|
12011
12928
|
total += (lengths[i] = readUint16(reader));
|
|
12012
12929
|
}
|
|
12013
|
-
|
|
12014
|
-
const srcEnd = reader.view.byteLength;
|
|
12015
|
-
if (total > (srcEnd - start)) {
|
|
12930
|
+
if (total > (srcEnd - reader.offset)) {
|
|
12016
12931
|
// broken or truncated file, decode only data that is available
|
|
12017
12932
|
warnOrThrow(reader, 'RLE data exceeds buffer length');
|
|
12018
12933
|
}
|
|
12019
|
-
const bpv = bytesPerValue(bitDepth);
|
|
12020
12934
|
if (data)
|
|
12021
12935
|
verifyArrayType(data, bpv);
|
|
12022
|
-
|
|
12023
|
-
|
|
12024
|
-
|
|
12025
|
-
|
|
12026
|
-
|
|
12027
|
-
|
|
12028
|
-
|
|
12029
|
-
|
|
12030
|
-
|
|
12031
|
-
|
|
12936
|
+
}
|
|
12937
|
+
catch (e) {
|
|
12938
|
+
recoverMemory(reader, lengthsMemory);
|
|
12939
|
+
throw e;
|
|
12940
|
+
}
|
|
12941
|
+
// decoding can't throw, it's kept outside of try block because V8 generates much slower code for loops inlined into try block
|
|
12942
|
+
const src = new Uint8Array(reader.view.buffer, reader.view.byteOffset, srcEnd);
|
|
12943
|
+
const row = (data && bpv > 1) ? new Uint8Array(width * bpv) : undefined;
|
|
12944
|
+
let pos = reader.offset;
|
|
12945
|
+
for (let c = 0, li = 0; c < offsets.length; c++, li += height) {
|
|
12946
|
+
const offset = offsets[c] | 0;
|
|
12947
|
+
const channelStart = pos;
|
|
12948
|
+
for (let y = 0; y < height; y++)
|
|
12949
|
+
pos += lengths[li + y];
|
|
12950
|
+
if (data && offset >= 0 && offset < step) {
|
|
12951
|
+
if (bpv === 1) {
|
|
12952
|
+
decodeRLEChannel8(src, lengths, li, channelStart, width, height, data, offset, step);
|
|
12953
|
+
}
|
|
12954
|
+
else {
|
|
12955
|
+
decodeRLEChannelWide(src, lengths, li, channelStart, width, height, data, offset, step, bpv, row);
|
|
12032
12956
|
}
|
|
12033
12957
|
}
|
|
12034
|
-
reader.offset = pos;
|
|
12035
|
-
}
|
|
12036
|
-
finally {
|
|
12037
|
-
recoverMemory(reader, rows * lengthSize);
|
|
12038
12958
|
}
|
|
12959
|
+
reader.offset = pos;
|
|
12960
|
+
recoverMemory(reader, lengthsMemory);
|
|
12039
12961
|
}
|
|
12040
12962
|
function readSection(reader, round, func, skipEmpty = true, eightBytes = false) {
|
|
12041
12963
|
let length = readUint32(reader);
|
|
@@ -12177,19 +13099,13 @@ function readPattern(reader) {
|
|
|
12177
13099
|
// channels cover whole pattern, each 2 bytes of RLE data can produce at most 128 bytes
|
|
12178
13100
|
if (width * height > (Math.min(end, reader.view.byteLength) - reader.offset) * 64)
|
|
12179
13101
|
throw new Error('Pattern data out of bounds');
|
|
12180
|
-
const size = width * height * 4;
|
|
12181
|
-
consumeMemory(reader, size);
|
|
12182
|
-
const data = new Uint8Array(size);
|
|
12183
|
-
for (let i = 3; i < data.byteLength; i += 4) {
|
|
12184
|
-
data[i] = 255;
|
|
12185
|
-
}
|
|
12186
13102
|
// first written arrays are color channels, next one is transparency (Photoshop stores it in the last, sheet mask, array)
|
|
12187
13103
|
const colorChannels = colorMode === 3 /* ColorMode.RGB */ ? 3 : (colorMode === 4 /* ColorMode.CMYK */ ? 4 : 1);
|
|
12188
|
-
|
|
12189
|
-
const
|
|
12190
|
-
|
|
12191
|
-
|
|
12192
|
-
|
|
13104
|
+
const isCmyk = colorMode === 4 /* ColorMode.CMYK */;
|
|
13105
|
+
const alphaTarget = isCmyk ? 4 : 3;
|
|
13106
|
+
const channels = [];
|
|
13107
|
+
let maxDecodeSize = 0;
|
|
13108
|
+
// validate all channels before allocating any image data
|
|
12193
13109
|
for (let i = 0, ch = 0; i < (channelsCount + 2) && reader.offset + 4 <= end; i++) {
|
|
12194
13110
|
const has = readUint32(reader);
|
|
12195
13111
|
if (!has)
|
|
@@ -12221,72 +13137,107 @@ function readPattern(reader) {
|
|
|
12221
13137
|
const h = cbottom - ctop;
|
|
12222
13138
|
const rowBytes = w * (depth / 8);
|
|
12223
13139
|
const channelSize = rowBytes * h;
|
|
12224
|
-
let bytes;
|
|
12225
13140
|
if (compressionMode === 0) {
|
|
12226
13141
|
if (cdata.byteLength < channelSize)
|
|
12227
13142
|
throw new Error('Pattern channel data out of bounds');
|
|
12228
|
-
bytes = cdata;
|
|
12229
13143
|
}
|
|
12230
13144
|
else if (compressionMode === 1) {
|
|
12231
13145
|
// each 2 bytes of RLE data can produce at most 128 bytes
|
|
12232
13146
|
if (channelSize > cdata.byteLength * 64)
|
|
12233
13147
|
throw new Error('Pattern channel data out of bounds');
|
|
12234
|
-
|
|
12235
|
-
bytes = new Uint8Array(channelSize);
|
|
12236
|
-
const cdataReader = createReader(cdata.buffer, cdata.byteOffset, cdata.byteLength);
|
|
12237
|
-
readDataRLE(cdataReader, { data: bytes, width: rowBytes, height: h }, rowBytes, h, 8, 1, [0], false);
|
|
13148
|
+
maxDecodeSize = Math.max(maxDecodeSize, channelSize);
|
|
12238
13149
|
}
|
|
12239
13150
|
else {
|
|
12240
13151
|
throw new Error('Invalid pattern compression mode');
|
|
12241
13152
|
}
|
|
13153
|
+
channels.push({ target, depth, compressionMode, cdata, ctop, cleft, w, h, rowBytes, channelSize });
|
|
13154
|
+
}
|
|
13155
|
+
// check peak memory up front (image data, CMYK buffer and largest RLE decode buffer),
|
|
13156
|
+
// image data is consumed only after successful decoding so failed patterns don't reduce the limit
|
|
13157
|
+
const size = width * height * 4;
|
|
13158
|
+
const cmykSize = isCmyk ? width * height * 5 : 0;
|
|
13159
|
+
consumeMemory(reader, size + cmykSize + maxDecodeSize);
|
|
13160
|
+
recoverMemory(reader, size + cmykSize + maxDecodeSize);
|
|
13161
|
+
const data = new Uint8Array(size);
|
|
13162
|
+
for (let i = 3; i < data.byteLength; i += 4) {
|
|
13163
|
+
data[i] = 255;
|
|
13164
|
+
}
|
|
13165
|
+
// CMYK channels are decoded into separate buffer (5 values per pixel, inverted, 0 = 100% ink) and converted to RGB at the end
|
|
13166
|
+
const cmyk = isCmyk ? new Uint8Array(cmykSize).fill(255) : undefined;
|
|
13167
|
+
for (const { target, depth, compressionMode, cdata, ctop, cleft, w, h, rowBytes, channelSize } of channels) {
|
|
13168
|
+
let bytes = cdata;
|
|
13169
|
+
if (compressionMode === 1) {
|
|
13170
|
+
bytes = new Uint8Array(channelSize);
|
|
13171
|
+
const cdataReader = createReader(cdata.buffer, cdata.byteOffset, cdata.byteLength);
|
|
13172
|
+
readDataRLE(cdataReader, { data: bytes, width: rowBytes, height: h }, rowBytes, h, 8, 1, [0], false);
|
|
13173
|
+
}
|
|
13174
|
+
if (depth !== 8)
|
|
13175
|
+
bytes = patternChannelTo8bit(bytes, w * h, depth);
|
|
12242
13176
|
const ox = cleft - left;
|
|
12243
13177
|
const oy = ctop - top;
|
|
12244
|
-
|
|
12245
|
-
|
|
12246
|
-
|
|
12247
|
-
|
|
12248
|
-
|
|
12249
|
-
|
|
12250
|
-
|
|
12251
|
-
|
|
12252
|
-
|
|
12253
|
-
|
|
12254
|
-
|
|
12255
|
-
|
|
12256
|
-
|
|
12257
|
-
|
|
12258
|
-
|
|
12259
|
-
|
|
13178
|
+
if (cmyk) {
|
|
13179
|
+
copyPatternChannel(bytes, cmyk, w, h, (ox + oy * width) * 5 + target, width * 5, 5);
|
|
13180
|
+
}
|
|
13181
|
+
else if (target === 3 || colorMode === 3 /* ColorMode.RGB */) {
|
|
13182
|
+
copyPatternChannel(bytes, data, w, h, (ox + oy * width) * 4 + target, width * 4, 4);
|
|
13183
|
+
}
|
|
13184
|
+
else if (colorMode === 2 /* ColorMode.Indexed */) {
|
|
13185
|
+
const colors = new Uint8Array(256 * 3);
|
|
13186
|
+
for (let i = 0; i < 256; i++) {
|
|
13187
|
+
colors[i * 3 + 0] = palette[i].r;
|
|
13188
|
+
colors[i * 3 + 1] = palette[i].g;
|
|
13189
|
+
colors[i * 3 + 2] = palette[i].b;
|
|
13190
|
+
}
|
|
13191
|
+
for (let y = 0; y < h; y++) {
|
|
13192
|
+
for (let x = 0, src = y * w, dst = (ox + (y + oy) * width) * 4; x < w; x++, src++, dst += 4) {
|
|
13193
|
+
const index = bytes[src] * 3;
|
|
13194
|
+
data[dst + 0] = colors[index + 0];
|
|
13195
|
+
data[dst + 1] = colors[index + 1];
|
|
13196
|
+
data[dst + 2] = colors[index + 2];
|
|
12260
13197
|
}
|
|
12261
|
-
|
|
13198
|
+
}
|
|
13199
|
+
}
|
|
13200
|
+
else { // grayscale
|
|
13201
|
+
for (let y = 0; y < h; y++) {
|
|
13202
|
+
for (let x = 0, src = y * w, dst = (ox + (y + oy) * width) * 4; x < w; x++, src++, dst += 4) {
|
|
13203
|
+
const value = bytes[src];
|
|
12262
13204
|
data[dst + 0] = value;
|
|
12263
13205
|
data[dst + 1] = value;
|
|
12264
13206
|
data[dst + 2] = value;
|
|
12265
13207
|
}
|
|
12266
|
-
else {
|
|
12267
|
-
data[dst + target] = value;
|
|
12268
|
-
}
|
|
12269
13208
|
}
|
|
12270
13209
|
}
|
|
12271
|
-
if (compressionMode === 1)
|
|
12272
|
-
recoverMemory(reader, channelSize);
|
|
12273
13210
|
}
|
|
12274
13211
|
if (cmyk) {
|
|
12275
13212
|
cmykToRgb({ width, height, data: cmyk }, { width, height, data }, false);
|
|
12276
|
-
recoverMemory(reader, cmyk.byteLength);
|
|
12277
13213
|
}
|
|
13214
|
+
consumeMemory(reader, size);
|
|
12278
13215
|
reader.offset = end;
|
|
12279
13216
|
return { id, name, x, y, bounds: { x: left, y: top, w: width, h: height }, data };
|
|
12280
13217
|
}
|
|
12281
|
-
// converts big-endian 16bit or 32bit (float)
|
|
12282
|
-
function
|
|
13218
|
+
// converts big-endian 16bit or 32bit (float) values to 8bit values
|
|
13219
|
+
function patternChannelTo8bit(bytes, count, depth) {
|
|
13220
|
+
const result = new Uint8Array(count);
|
|
12283
13221
|
if (depth === 16) {
|
|
12284
|
-
|
|
13222
|
+
for (let i = 0; i < count; i++) {
|
|
13223
|
+
result[i] = Math.round(((bytes[i * 2] << 8) | bytes[i * 2 + 1]) / 257);
|
|
13224
|
+
}
|
|
12285
13225
|
}
|
|
12286
13226
|
else {
|
|
12287
|
-
const view = new DataView(bytes.buffer, bytes.byteOffset
|
|
12288
|
-
|
|
12289
|
-
|
|
13227
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
13228
|
+
for (let i = 0; i < count; i++) {
|
|
13229
|
+
const value = view.getFloat32(i * 4, false);
|
|
13230
|
+
result[i] = value > 0 ? (value < 1 ? Math.round(value * 255) : 255) : 0;
|
|
13231
|
+
}
|
|
13232
|
+
}
|
|
13233
|
+
return result;
|
|
13234
|
+
}
|
|
13235
|
+
// copies w x h channel values into interleaved data starting at `offset`
|
|
13236
|
+
function copyPatternChannel(bytes, data, w, h, offset, stride, step) {
|
|
13237
|
+
for (let y = 0, src = 0; y < h; y++) {
|
|
13238
|
+
for (let x = 0, dst = offset + y * stride; x < w; x++, src++, dst += step) {
|
|
13239
|
+
data[dst] = bytes[src];
|
|
13240
|
+
}
|
|
12290
13241
|
}
|
|
12291
13242
|
}
|
|
12292
13243
|
function consumeMemory(reader, size) {
|
|
@@ -12304,7 +13255,7 @@ function recoverMemory(reader, size) {
|
|
|
12304
13255
|
}
|
|
12305
13256
|
}
|
|
12306
13257
|
|
|
12307
|
-
},{"./additionalInfo":2,"./helpers":
|
|
13258
|
+
},{"./additionalInfo":2,"./helpers":9,"./imageResources":10,"./utf8":17,"pako":21}],15:[function(require,module,exports){
|
|
12308
13259
|
"use strict";
|
|
12309
13260
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12310
13261
|
exports.createWriter = createWriter;
|
|
@@ -12337,6 +13288,7 @@ exports.writePsd = writePsd;
|
|
|
12337
13288
|
exports.writeColor = writeColor;
|
|
12338
13289
|
exports.writePattern = writePattern;
|
|
12339
13290
|
const helpers_1 = require("./helpers");
|
|
13291
|
+
const pako_1 = require("pako");
|
|
12340
13292
|
const additionalInfo_1 = require("./additionalInfo");
|
|
12341
13293
|
const imageResources_1 = require("./imageResources");
|
|
12342
13294
|
const psdReader_1 = require("./psdReader");
|
|
@@ -12509,10 +13461,33 @@ function writeSection(writer, round, func, writeTotalLength = false, large = fal
|
|
|
12509
13461
|
function verifyPixelData(data, name) {
|
|
12510
13462
|
// check element size instead of instanceof, so arrays from other realms (iframes, workers, vm) are accepted
|
|
12511
13463
|
const bytesPerElement = data && data.data.BYTES_PER_ELEMENT;
|
|
12512
|
-
if (bytesPerElement !== undefined && bytesPerElement !== 1) {
|
|
12513
|
-
throw new Error(`${name} has incorrect bitDepth (only
|
|
13464
|
+
if (bytesPerElement !== undefined && bytesPerElement !== 1 && bytesPerElement !== 2 && !(data.data instanceof Float32Array)) {
|
|
13465
|
+
throw new Error(`${name} has incorrect bitDepth (only Uint8Array, Uint8ClampedArray, Uint16Array and Float32Array data is supported for writing)`);
|
|
12514
13466
|
}
|
|
12515
13467
|
}
|
|
13468
|
+
// supported bit depths for each color mode
|
|
13469
|
+
const writeBitDepths = {
|
|
13470
|
+
[0 /* ColorMode.Bitmap */]: [1],
|
|
13471
|
+
[1 /* ColorMode.Grayscale */]: [8, 16, 32],
|
|
13472
|
+
[2 /* ColorMode.Indexed */]: [8],
|
|
13473
|
+
[3 /* ColorMode.RGB */]: [8, 16, 32],
|
|
13474
|
+
[4 /* ColorMode.CMYK */]: [8, 16],
|
|
13475
|
+
};
|
|
13476
|
+
const colorModeNames = {
|
|
13477
|
+
[0 /* ColorMode.Bitmap */]: 'Bitmap', [1 /* ColorMode.Grayscale */]: 'Grayscale', [2 /* ColorMode.Indexed */]: 'Indexed', [3 /* ColorMode.RGB */]: 'RGB',
|
|
13478
|
+
[4 /* ColorMode.CMYK */]: 'CMYK', [7 /* ColorMode.Multichannel */]: 'Multichannel', [8 /* ColorMode.Duotone */]: 'Duotone', [9 /* ColorMode.Lab */]: 'Lab',
|
|
13479
|
+
};
|
|
13480
|
+
function colorChannelsCount(colorMode) {
|
|
13481
|
+
return colorMode === 3 /* ColorMode.RGB */ ? 3 : (colorMode === 4 /* ColorMode.CMYK */ ? 4 : 1);
|
|
13482
|
+
}
|
|
13483
|
+
// HDR toning settings that Photoshop stores in color mode data of 32bit documents (default values of new document),
|
|
13484
|
+
// Photoshop refuses to open 32bit documents without them
|
|
13485
|
+
const hdrToningData = [
|
|
13486
|
+
104, 100, 114, 116, 0, 0, 0, 3, 62, 107, 133, 31, 0, 0, 0, 2, 0, 0, 0, 7, 0, 76, 0, 105, 0, 110, 0, 101, 0, 97, 0, 114, 0, 0,
|
|
13487
|
+
0, 2, 0, 2, 0, 0, 0, 0, 0, 255, 0, 255, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 65, 128, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 63, 128, 0, 0,
|
|
13488
|
+
104, 100, 114, 97, 0, 0, 0, 6, 0, 0, 0, 0, 65, 160, 0, 0, 65, 240, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 63, 128, 0, 0, 0, 0, 0, 0,
|
|
13489
|
+
0, 0,
|
|
13490
|
+
];
|
|
12516
13491
|
function verifyBitCount(target) {
|
|
12517
13492
|
var _a, _b, _c;
|
|
12518
13493
|
(_a = target.children) === null || _a === void 0 ? void 0 : _a.forEach(verifyBitCount);
|
|
@@ -12523,34 +13498,37 @@ function verifyBitCount(target) {
|
|
|
12523
13498
|
verifyPixelData((_c = target.realMask) === null || _c === void 0 ? void 0 : _c.imageData, 'realMask imageData');
|
|
12524
13499
|
}
|
|
12525
13500
|
function writePsd(writer, psd, options = {}) {
|
|
12526
|
-
var _a;
|
|
13501
|
+
var _a, _b, _c, _d;
|
|
12527
13502
|
if (!(+psd.width > 0 && +psd.height > 0))
|
|
12528
13503
|
throw new Error('Invalid document size');
|
|
12529
13504
|
if ((psd.width > 30000 || psd.height > 30000) && !options.psb)
|
|
12530
13505
|
throw new Error('Document size is too large (max is 30000x30000, use PSB format instead)');
|
|
12531
|
-
const
|
|
12532
|
-
|
|
12533
|
-
|
|
13506
|
+
const colorMode = (_a = psd.colorMode) !== null && _a !== void 0 ? _a : 3 /* ColorMode.RGB */;
|
|
13507
|
+
const bitsPerChannel = (_b = psd.bitsPerChannel) !== null && _b !== void 0 ? _b : (colorMode === 0 /* ColorMode.Bitmap */ ? 1 : 8);
|
|
13508
|
+
const bitDepths = writeBitDepths[colorMode];
|
|
13509
|
+
if (!bitDepths)
|
|
13510
|
+
throw new Error(`${(_c = colorModeNames[colorMode]) !== null && _c !== void 0 ? _c : colorMode} color mode is not supported for writing`);
|
|
13511
|
+
if (bitDepths.indexOf(bitsPerChannel) === -1)
|
|
13512
|
+
throw new Error(`bitsPerChannel ${bitsPerChannel} is not supported for writing in ${colorModeNames[colorMode]} color mode`);
|
|
13513
|
+
// Photoshop doesn't support layers in bitmap and indexed color modes
|
|
13514
|
+
const layersAllowed = colorMode !== 0 /* ColorMode.Bitmap */ && colorMode !== 2 /* ColorMode.Indexed */;
|
|
13515
|
+
if (!layersAllowed && ((_d = psd.children) === null || _d === void 0 ? void 0 : _d.length))
|
|
13516
|
+
throw new Error(`Layers are not supported in ${colorModeNames[colorMode]} color mode`);
|
|
13517
|
+
if (colorMode === 2 /* ColorMode.Indexed */ && !psd.palette)
|
|
13518
|
+
throw new Error('Missing color palette for Indexed color mode');
|
|
12534
13519
|
if (options.log)
|
|
12535
13520
|
writer.log = options.log;
|
|
13521
|
+
if (options.logMissingFeatures)
|
|
13522
|
+
writer.logMissingFeatures = true;
|
|
12536
13523
|
const layers = [];
|
|
12537
13524
|
addChildren(layers, psd.children);
|
|
12538
|
-
if (!layers.length)
|
|
13525
|
+
if (!layers.length && layersAllowed)
|
|
12539
13526
|
layers.push({});
|
|
12540
13527
|
verifyBitCount(psd);
|
|
12541
13528
|
const imageResources = Object.assign({}, psd.imageResources);
|
|
12542
|
-
const opt = Object.assign(Object.assign({}, options), { layerIds: new Set(), layerToId: new Map() });
|
|
12543
|
-
//
|
|
12544
|
-
|
|
12545
|
-
delete imageResources.iccProfile;
|
|
12546
|
-
delete imageResources.indexedColorCount;
|
|
12547
|
-
delete imageResources.transparencyIndex;
|
|
12548
|
-
delete imageResources.alphaChannelDisplayInfo;
|
|
12549
|
-
delete imageResources.colorHalftoneScreens;
|
|
12550
|
-
delete imageResources.grayscaleHalftoneScreens;
|
|
12551
|
-
delete imageResources.colorTransferFunctions;
|
|
12552
|
-
delete imageResources.grayscaleTransferFunctions;
|
|
12553
|
-
}
|
|
13529
|
+
const opt = Object.assign(Object.assign({}, options), { layerIds: new Set(), layerToId: new Map(), colorMode, bitsPerChannel });
|
|
13530
|
+
// 16 and 32 bit documents store layers in Lr16 / Lr32 section of global additional info
|
|
13531
|
+
const layersInGlobalInfo = bitsPerChannel === 16 || bitsPerChannel === 32;
|
|
12554
13532
|
if (opt.generateThumbnail) {
|
|
12555
13533
|
imageResources.thumbnail = createThumbnail(psd);
|
|
12556
13534
|
}
|
|
@@ -12563,20 +13541,34 @@ function writePsd(writer, psd, options = {}) {
|
|
|
12563
13541
|
}
|
|
12564
13542
|
if (imageData && (psd.width !== imageData.width || psd.height !== imageData.height))
|
|
12565
13543
|
throw new Error('Document canvas must have the same size as document');
|
|
12566
|
-
const globalAlpha = !!imageData && (0, helpers_1.hasAlpha)(imageData);
|
|
13544
|
+
const globalAlpha = !!imageData && layersAllowed && (0, helpers_1.hasAlpha)(imageData);
|
|
12567
13545
|
// only used for encoding a single layer channel at a time, composite image is encoded directly into the writer buffer
|
|
12568
13546
|
writer.tempBuffer = new Uint8Array(getLargestLayerSize(psd.children, !!options.psb));
|
|
12569
13547
|
// header
|
|
12570
13548
|
writeSignature(writer, '8BPS');
|
|
12571
13549
|
writeUint16(writer, options.psb ? 2 : 1); // version
|
|
12572
13550
|
writeZeros(writer, 6);
|
|
12573
|
-
writeUint16(writer, globalAlpha ?
|
|
13551
|
+
writeUint16(writer, colorChannelsCount(colorMode) + (globalAlpha ? 1 : 0)); // channels
|
|
12574
13552
|
writeUint32(writer, psd.height);
|
|
12575
13553
|
writeUint32(writer, psd.width);
|
|
12576
13554
|
writeUint16(writer, bitsPerChannel); // bits per channel
|
|
12577
|
-
writeUint16(writer,
|
|
12578
|
-
// color mode data
|
|
12579
|
-
|
|
13555
|
+
writeUint16(writer, colorMode);
|
|
13556
|
+
// color mode data
|
|
13557
|
+
writeSection(writer, 1, () => {
|
|
13558
|
+
var _a, _b, _c, _d, _e, _f;
|
|
13559
|
+
if (colorMode === 2 /* ColorMode.Indexed */) {
|
|
13560
|
+
const palette = psd.palette;
|
|
13561
|
+
for (let i = 0; i < 256; i++)
|
|
13562
|
+
writeUint8(writer, (_b = (_a = palette[i]) === null || _a === void 0 ? void 0 : _a.r) !== null && _b !== void 0 ? _b : 0);
|
|
13563
|
+
for (let i = 0; i < 256; i++)
|
|
13564
|
+
writeUint8(writer, (_d = (_c = palette[i]) === null || _c === void 0 ? void 0 : _c.g) !== null && _d !== void 0 ? _d : 0);
|
|
13565
|
+
for (let i = 0; i < 256; i++)
|
|
13566
|
+
writeUint8(writer, (_f = (_e = palette[i]) === null || _e === void 0 ? void 0 : _e.b) !== null && _f !== void 0 ? _f : 0);
|
|
13567
|
+
}
|
|
13568
|
+
else if (bitsPerChannel === 32) {
|
|
13569
|
+
writeBytes(writer, new Uint8Array(hdrToningData));
|
|
13570
|
+
}
|
|
13571
|
+
});
|
|
12580
13572
|
// image resources
|
|
12581
13573
|
imageResources.layersGroup = layers.map(l => l.linkGroup || 0);
|
|
12582
13574
|
imageResources.layerGroupsEnabledId = layers.map(l => l.linkGroupEnabled == false ? 0 : 1);
|
|
@@ -12596,20 +13588,202 @@ function writePsd(writer, psd, options = {}) {
|
|
|
12596
13588
|
});
|
|
12597
13589
|
// layer and mask info
|
|
12598
13590
|
writeSection(writer, 2, () => {
|
|
12599
|
-
|
|
13591
|
+
if (layersInGlobalInfo || !layersAllowed) {
|
|
13592
|
+
writeSection(writer, 4, () => { }, true, opt.psb); // empty layer info
|
|
13593
|
+
}
|
|
13594
|
+
else {
|
|
13595
|
+
writeLayerInfo(writer, layers, psd, globalAlpha, opt);
|
|
13596
|
+
}
|
|
12600
13597
|
writeGlobalLayerMaskInfo(writer, psd.globalLayerMaskInfo);
|
|
13598
|
+
if (layersInGlobalInfo) {
|
|
13599
|
+
if (globalAlpha)
|
|
13600
|
+
writeGlobalInfoSection(writer, bitsPerChannel === 16 ? 'Mt16' : 'Mt32', !!opt.psb, () => { });
|
|
13601
|
+
writeGlobalInfoSection(writer, bitsPerChannel === 16 ? 'Lr16' : 'Lr32', !!opt.psb, () => {
|
|
13602
|
+
writeLayerInfoData(writer, layers, psd, globalAlpha, opt);
|
|
13603
|
+
});
|
|
13604
|
+
}
|
|
12601
13605
|
writeAdditionalLayerInfo(writer, psd, psd, opt);
|
|
12602
13606
|
}, undefined, !!opt.psb);
|
|
12603
13607
|
writer.tempBuffer = undefined;
|
|
12604
13608
|
// image data
|
|
12605
|
-
|
|
12606
|
-
|
|
12607
|
-
|
|
12608
|
-
|
|
12609
|
-
|
|
12610
|
-
|
|
12611
|
-
|
|
12612
|
-
|
|
13609
|
+
if (colorMode === 3 /* ColorMode.RGB */ && bitsPerChannel === 8 && (!imageData || is8bit(imageData))) {
|
|
13610
|
+
writeUint16(writer, 1 /* Compression.RleCompressed */); // Photoshop doesn't support zip compression of composite image data
|
|
13611
|
+
const channels = globalAlpha ? [0, 1, 2, 3] : [0, 1, 2];
|
|
13612
|
+
const data = getCompositeData(imageData, psd.width, psd.height, globalAlpha);
|
|
13613
|
+
// encode directly into the writer buffer
|
|
13614
|
+
const maxSize = channels.length * getRLEChannelBound(data.width, data.height, !!options.psb);
|
|
13615
|
+
ensureSize(writer, writer.offset + maxSize);
|
|
13616
|
+
const buffer = new Uint8Array(writer.buffer, writer.offset, maxSize);
|
|
13617
|
+
writer.offset += (0, helpers_1.writeDataRLE)(buffer, data, channels, !!options.psb).length;
|
|
13618
|
+
}
|
|
13619
|
+
else {
|
|
13620
|
+
writeCompositeImageData(writer, psd, imageData, colorMode, bitsPerChannel, globalAlpha, !!options.psb);
|
|
13621
|
+
}
|
|
13622
|
+
}
|
|
13623
|
+
function writeGlobalInfoSection(writer, key, psb, func) {
|
|
13624
|
+
writeSignature(writer, psb ? '8B64' : '8BIM');
|
|
13625
|
+
writeSignature(writer, key);
|
|
13626
|
+
writeSection(writer, 4, func, false, psb);
|
|
13627
|
+
}
|
|
13628
|
+
function is8bit(data) {
|
|
13629
|
+
return data.data.BYTES_PER_ELEMENT === 1;
|
|
13630
|
+
}
|
|
13631
|
+
// converts image data (8, 16 or 32 bit RGBA data) to channels of the document color mode and bit depth
|
|
13632
|
+
function getPlanarChannels(imageData, colorMode, bitsPerChannel, matte) {
|
|
13633
|
+
const { data, width, height } = imageData;
|
|
13634
|
+
const size = width * height;
|
|
13635
|
+
const srcFloat = data instanceof Float32Array;
|
|
13636
|
+
const srcMax = srcFloat ? 1 : (data instanceof Uint16Array ? 0xffff : 0xff);
|
|
13637
|
+
const dstFloat = bitsPerChannel === 32;
|
|
13638
|
+
const dstMax = dstFloat ? 1 : (bitsPerChannel === 16 ? 0xffff : 0xff);
|
|
13639
|
+
const colorCount = colorChannelsCount(colorMode);
|
|
13640
|
+
const create = () => dstFloat ? new Float32Array(size) : (bitsPerChannel === 16 ? new Uint16Array(size) : new Uint8Array(size));
|
|
13641
|
+
const colors = [];
|
|
13642
|
+
for (let i = 0; i < colorCount; i++)
|
|
13643
|
+
colors.push(create());
|
|
13644
|
+
const alpha = create();
|
|
13645
|
+
// color values are gamma corrected when converting between float (linear) and integer values (same as imageDataToCanvas)
|
|
13646
|
+
const toNormalized = (v) => srcFloat ? Math.pow((0, helpers_1.clamp)(v, 0, 1), 1 / 2.2) : v / srcMax;
|
|
13647
|
+
const fromNormalized = (v) => dstFloat ? Math.pow(v, 2.2) : Math.round((0, helpers_1.clamp)(v, 0, 1) * dstMax);
|
|
13648
|
+
const sameType = srcFloat === dstFloat && srcMax === dstMax;
|
|
13649
|
+
const convertColor = (v) => sameType ? (dstFloat ? v : Math.round(v)) : fromNormalized(toNormalized(v));
|
|
13650
|
+
const convertAlpha = (v) => sameType ? v : (dstFloat ? v / srcMax : Math.round((0, helpers_1.clamp)(v / srcMax, 0, 1) * dstMax));
|
|
13651
|
+
const cmyk = [0, 0, 0, 0];
|
|
13652
|
+
for (let i = 0, p = 0; i < size; i++, p += 4) {
|
|
13653
|
+
const a = data[p + 3];
|
|
13654
|
+
const alphaValue = convertAlpha(a);
|
|
13655
|
+
alpha[i] = alphaValue;
|
|
13656
|
+
// composite image colors are blended with white (or no ink) for documents with transparency
|
|
13657
|
+
const blend = matte && a !== srcMax && a > 0 ? (0, helpers_1.clamp)(a / srcMax, 0, 1) : 1;
|
|
13658
|
+
if (colorMode === 4 /* ColorMode.CMYK */) {
|
|
13659
|
+
(0, helpers_1.rgbToCmykValues)(toNormalized(data[p]), toNormalized(data[p + 1]), toNormalized(data[p + 2]), cmyk);
|
|
13660
|
+
for (let j = 0; j < 4; j++) {
|
|
13661
|
+
colors[j][i] = Math.round((1 - (0, helpers_1.clamp)(cmyk[j] * blend, 0, 1)) * dstMax); // stored inverted (0 = 100% ink)
|
|
13662
|
+
}
|
|
13663
|
+
}
|
|
13664
|
+
else {
|
|
13665
|
+
for (let j = 0; j < colorCount; j++) {
|
|
13666
|
+
let value;
|
|
13667
|
+
if (colorMode === 3 /* ColorMode.RGB */) {
|
|
13668
|
+
value = convertColor(data[p + j]);
|
|
13669
|
+
}
|
|
13670
|
+
else {
|
|
13671
|
+
const r = data[p], g = data[p + 1], b = data[p + 2];
|
|
13672
|
+
value = convertColor((r === g && g === b) ? r : (0.299 * r + 0.587 * g + 0.114 * b));
|
|
13673
|
+
}
|
|
13674
|
+
if (blend !== 1)
|
|
13675
|
+
value = dstFloat ? value * blend + 1 - blend : Math.round(value * blend + dstMax * (1 - blend));
|
|
13676
|
+
colors[j][i] = value;
|
|
13677
|
+
}
|
|
13678
|
+
}
|
|
13679
|
+
}
|
|
13680
|
+
return { colors, alpha };
|
|
13681
|
+
}
|
|
13682
|
+
function encodeChannel(values, width, height, options) {
|
|
13683
|
+
if (!(values instanceof Uint8Array)) {
|
|
13684
|
+
return { data: (0, helpers_1.writeDataZipWithPrediction)(values, width, height), compression: 3 /* Compression.ZipWithPrediction */ };
|
|
13685
|
+
}
|
|
13686
|
+
else if (options.compress) {
|
|
13687
|
+
return { data: (0, pako_1.deflate)(values), compression: 2 /* Compression.ZipWithoutPrediction */ };
|
|
13688
|
+
}
|
|
13689
|
+
else {
|
|
13690
|
+
return { data: (0, helpers_1.writeDataRLEBytes)(values, width, height, !!options.psb), compression: 1 /* Compression.RleCompressed */ };
|
|
13691
|
+
}
|
|
13692
|
+
}
|
|
13693
|
+
function writeCompositeImageData(writer, psd, imageData, colorMode, bitsPerChannel, globalAlpha, psb) {
|
|
13694
|
+
var _a;
|
|
13695
|
+
const { width, height } = psd;
|
|
13696
|
+
const data = imageData !== null && imageData !== void 0 ? imageData : { data: new Uint8Array(width * height * 4), width, height };
|
|
13697
|
+
const parts = [];
|
|
13698
|
+
if (colorMode === 0 /* ColorMode.Bitmap */ || colorMode === 2 /* ColorMode.Indexed */) {
|
|
13699
|
+
const values = colorMode === 0 /* ColorMode.Bitmap */ ?
|
|
13700
|
+
getBitmapData(data) :
|
|
13701
|
+
getIndexedData(data, psd.palette, (_a = psd.imageResources) === null || _a === void 0 ? void 0 : _a.transparencyIndex);
|
|
13702
|
+
const rowBytes = colorMode === 0 /* ColorMode.Bitmap */ ? Math.ceil(width / 8) : width;
|
|
13703
|
+
if (colorMode === 0 /* ColorMode.Bitmap */) {
|
|
13704
|
+
writeUint16(writer, 0 /* Compression.RawData */);
|
|
13705
|
+
parts.push(values);
|
|
13706
|
+
}
|
|
13707
|
+
else {
|
|
13708
|
+
writeUint16(writer, 1 /* Compression.RleCompressed */);
|
|
13709
|
+
parts.push((0, helpers_1.writeDataRLEBytes)(values, rowBytes, height, psb));
|
|
13710
|
+
}
|
|
13711
|
+
}
|
|
13712
|
+
else {
|
|
13713
|
+
const { colors, alpha } = getPlanarChannels(data, colorMode, bitsPerChannel, globalAlpha);
|
|
13714
|
+
const channels = globalAlpha ? [...colors, alpha] : colors;
|
|
13715
|
+
if (bitsPerChannel === 8) {
|
|
13716
|
+
// row byte counts for all channels are stored before data of all channels
|
|
13717
|
+
const encoded = channels.map(c => (0, helpers_1.writeDataRLEBytes)(c, width, height, psb));
|
|
13718
|
+
const countsSize = height * (psb ? 4 : 2);
|
|
13719
|
+
writeUint16(writer, 1 /* Compression.RleCompressed */);
|
|
13720
|
+
for (const e of encoded)
|
|
13721
|
+
parts.push(e.subarray(0, countsSize));
|
|
13722
|
+
for (const e of encoded)
|
|
13723
|
+
parts.push(e.subarray(countsSize));
|
|
13724
|
+
}
|
|
13725
|
+
else {
|
|
13726
|
+
writeUint16(writer, 0 /* Compression.RawData */); // Photoshop writes 16 and 32 bit composite image without compression
|
|
13727
|
+
for (const c of channels)
|
|
13728
|
+
parts.push((0, helpers_1.planarToBytes)(c));
|
|
13729
|
+
}
|
|
13730
|
+
}
|
|
13731
|
+
for (const part of parts)
|
|
13732
|
+
writeBytes(writer, part);
|
|
13733
|
+
}
|
|
13734
|
+
function getBitmapData({ data, width, height }) {
|
|
13735
|
+
const rowBytes = Math.ceil(width / 8);
|
|
13736
|
+
const result = new Uint8Array(rowBytes * height);
|
|
13737
|
+
const max = data instanceof Float32Array ? 1 : (data instanceof Uint16Array ? 0xffff : 0xff);
|
|
13738
|
+
for (let y = 0, p = 0; y < height; y++) {
|
|
13739
|
+
for (let x = 0; x < width; x++, p += 4) {
|
|
13740
|
+
const a = data[p + 3] / max;
|
|
13741
|
+
const value = ((0.299 * data[p] + 0.587 * data[p + 1] + 0.114 * data[p + 2]) / max) * a + (1 - a); // blend with white
|
|
13742
|
+
if (value < 0.5)
|
|
13743
|
+
result[y * rowBytes + (x >> 3)] |= 0x80 >> (x & 7); // 1 = black
|
|
13744
|
+
}
|
|
13745
|
+
}
|
|
13746
|
+
return result;
|
|
13747
|
+
}
|
|
13748
|
+
function getIndexedData({ data, width, height }, palette, transparencyIndex) {
|
|
13749
|
+
const size = width * height;
|
|
13750
|
+
const result = new Uint8Array(size);
|
|
13751
|
+
const shift = data instanceof Uint16Array ? 8 : 0;
|
|
13752
|
+
const cache = new Map();
|
|
13753
|
+
for (let i = 0; i < palette.length && i < 256; i++) {
|
|
13754
|
+
const key = (palette[i].r << 16) | (palette[i].g << 8) | palette[i].b;
|
|
13755
|
+
if (i !== transparencyIndex && !cache.has(key))
|
|
13756
|
+
cache.set(key, i);
|
|
13757
|
+
}
|
|
13758
|
+
for (let i = 0, p = 0; i < size; i++, p += 4) {
|
|
13759
|
+
const read = (v) => data instanceof Float32Array ? Math.round(Math.pow((0, helpers_1.clamp)(v, 0, 1), 1 / 2.2) * 255) : (v >>> shift);
|
|
13760
|
+
const a = data instanceof Float32Array ? data[p + 3] * 255 : (data[p + 3] >>> shift);
|
|
13761
|
+
if (transparencyIndex !== undefined && transparencyIndex >= 0 && a < 128) {
|
|
13762
|
+
result[i] = transparencyIndex;
|
|
13763
|
+
continue;
|
|
13764
|
+
}
|
|
13765
|
+
const r = read(data[p]), g = read(data[p + 1]), b = read(data[p + 2]);
|
|
13766
|
+
const key = (r << 16) | (g << 8) | b;
|
|
13767
|
+
let index = cache.get(key);
|
|
13768
|
+
if (index === undefined) {
|
|
13769
|
+
// use closest color from the palette
|
|
13770
|
+
let best = Infinity;
|
|
13771
|
+
index = 0;
|
|
13772
|
+
for (let j = 0; j < palette.length && j < 256; j++) {
|
|
13773
|
+
if (j === transparencyIndex)
|
|
13774
|
+
continue;
|
|
13775
|
+
const dr = palette[j].r - r, dg = palette[j].g - g, db = palette[j].b - b;
|
|
13776
|
+
const distance = dr * dr + dg * dg + db * db;
|
|
13777
|
+
if (distance < best) {
|
|
13778
|
+
best = distance;
|
|
13779
|
+
index = j;
|
|
13780
|
+
}
|
|
13781
|
+
}
|
|
13782
|
+
cache.set(key, index);
|
|
13783
|
+
}
|
|
13784
|
+
result[i] = index;
|
|
13785
|
+
}
|
|
13786
|
+
return result;
|
|
12613
13787
|
}
|
|
12614
13788
|
function getCompositeData(imageData, width, height, globalAlpha) {
|
|
12615
13789
|
if (!imageData)
|
|
@@ -12635,60 +13809,61 @@ function getCompositeData(imageData, width, height, globalAlpha) {
|
|
|
12635
13809
|
return dst ? { data: dst, width, height } : imageData;
|
|
12636
13810
|
}
|
|
12637
13811
|
function writeLayerInfo(writer, layers, psd, globalAlpha, options) {
|
|
12638
|
-
writeSection(writer, 4, () =>
|
|
12639
|
-
|
|
12640
|
-
|
|
12641
|
-
|
|
12642
|
-
|
|
12643
|
-
|
|
12644
|
-
|
|
12645
|
-
|
|
12646
|
-
|
|
12647
|
-
|
|
12648
|
-
|
|
12649
|
-
|
|
12650
|
-
|
|
12651
|
-
|
|
12652
|
-
|
|
12653
|
-
|
|
12654
|
-
|
|
12655
|
-
|
|
12656
|
-
writeUint32(writer, c.length);
|
|
12657
|
-
}
|
|
13812
|
+
writeSection(writer, 4, () => writeLayerInfoData(writer, layers, psd, globalAlpha, options), true, options.psb);
|
|
13813
|
+
}
|
|
13814
|
+
function writeLayerInfoData(writer, layers, psd, globalAlpha, options) {
|
|
13815
|
+
var _a;
|
|
13816
|
+
writeInt16(writer, globalAlpha ? -layers.length : layers.length);
|
|
13817
|
+
const layersData = layers.map((l, i) => getChannels(writer, l, i === 0, options));
|
|
13818
|
+
// layer records
|
|
13819
|
+
for (const layerData of layersData) {
|
|
13820
|
+
const { layer, top, left, bottom, right, channels } = layerData;
|
|
13821
|
+
writeInt32(writer, top);
|
|
13822
|
+
writeInt32(writer, left);
|
|
13823
|
+
writeInt32(writer, bottom);
|
|
13824
|
+
writeInt32(writer, right);
|
|
13825
|
+
writeUint16(writer, channels.length);
|
|
13826
|
+
for (const c of channels) {
|
|
13827
|
+
writeInt16(writer, c.id);
|
|
13828
|
+
if (options.psb) {
|
|
13829
|
+
writeUint64(writer, c.length);
|
|
12658
13830
|
}
|
|
12659
|
-
|
|
12660
|
-
|
|
12661
|
-
writeUint8(writer, Math.round((0, helpers_1.clamp)((_a = layer.opacity) !== null && _a !== void 0 ? _a : 1, 0, 1) * 255));
|
|
12662
|
-
writeUint8(writer, layer.clipping ? 1 : 0);
|
|
12663
|
-
let flags = 0x08; // 1 for Photoshop 5.0 and later, tells if bit 4 has useful information
|
|
12664
|
-
if (layer.transparencyProtected)
|
|
12665
|
-
flags |= 0x01;
|
|
12666
|
-
if (layer.hidden)
|
|
12667
|
-
flags |= 0x02;
|
|
12668
|
-
if (layer.vectorMask || (layer.sectionDivider && layer.sectionDivider.type !== 0 /* SectionDividerType.Other */) || layer.adjustment) {
|
|
12669
|
-
flags |= 0x10; // pixel data irrelevant to appearance of document
|
|
13831
|
+
else {
|
|
13832
|
+
writeUint32(writer, c.length);
|
|
12670
13833
|
}
|
|
12671
|
-
if (layer.effectsOpen)
|
|
12672
|
-
flags |= 0x20;
|
|
12673
|
-
writeUint8(writer, flags);
|
|
12674
|
-
writeUint8(writer, 0); // filler
|
|
12675
|
-
writeSection(writer, 1, () => {
|
|
12676
|
-
writeLayerMaskData(writer, layer, layerData);
|
|
12677
|
-
writeLayerBlendingRanges(writer, layer);
|
|
12678
|
-
writePascalString(writer, (layer.name || '').substring(0, 255), 4);
|
|
12679
|
-
writeAdditionalLayerInfo(writer, layer, psd, options);
|
|
12680
|
-
});
|
|
12681
13834
|
}
|
|
12682
|
-
|
|
12683
|
-
|
|
12684
|
-
|
|
12685
|
-
|
|
12686
|
-
|
|
12687
|
-
|
|
12688
|
-
|
|
13835
|
+
writeSignature(writer, '8BIM');
|
|
13836
|
+
writeSignature(writer, helpers_1.fromBlendMode[layer.blendMode] || 'norm');
|
|
13837
|
+
writeUint8(writer, Math.round((0, helpers_1.clamp)((_a = layer.opacity) !== null && _a !== void 0 ? _a : 1, 0, 1) * 255));
|
|
13838
|
+
writeUint8(writer, layer.clipping ? 1 : 0);
|
|
13839
|
+
let flags = 0x08; // 1 for Photoshop 5.0 and later, tells if bit 4 has useful information
|
|
13840
|
+
if (layer.transparencyProtected)
|
|
13841
|
+
flags |= 0x01;
|
|
13842
|
+
if (layer.hidden)
|
|
13843
|
+
flags |= 0x02;
|
|
13844
|
+
if (layer.vectorMask || (layer.sectionDivider && layer.sectionDivider.type !== 0 /* SectionDividerType.Other */) || layer.adjustment) {
|
|
13845
|
+
flags |= 0x10; // pixel data irrelevant to appearance of document
|
|
13846
|
+
}
|
|
13847
|
+
if (layer.effectsOpen)
|
|
13848
|
+
flags |= 0x20;
|
|
13849
|
+
writeUint8(writer, flags);
|
|
13850
|
+
writeUint8(writer, 0); // filler
|
|
13851
|
+
writeSection(writer, 1, () => {
|
|
13852
|
+
writeLayerMaskData(writer, layer, layerData);
|
|
13853
|
+
writeLayerBlendingRanges(writer, layer);
|
|
13854
|
+
writePascalString(writer, (layer.name || '').substring(0, 255), 4);
|
|
13855
|
+
writeAdditionalLayerInfo(writer, layer, psd, options);
|
|
13856
|
+
});
|
|
13857
|
+
}
|
|
13858
|
+
// layer channel image data
|
|
13859
|
+
for (const layerData of layersData) {
|
|
13860
|
+
for (const channel of layerData.channels) {
|
|
13861
|
+
writeUint16(writer, channel.compression);
|
|
13862
|
+
if (channel.data) {
|
|
13863
|
+
writeBytes(writer, channel.data);
|
|
12689
13864
|
}
|
|
12690
13865
|
}
|
|
12691
|
-
}
|
|
13866
|
+
}
|
|
12692
13867
|
}
|
|
12693
13868
|
// real mask is only stored separately if layer has both vector and pixel masks, otherwise it's stored as the main mask
|
|
12694
13869
|
function getMasks(layer) {
|
|
@@ -12891,6 +14066,7 @@ function createThumbnail(psd) {
|
|
|
12891
14066
|
return canvas;
|
|
12892
14067
|
}
|
|
12893
14068
|
function getMaskChannels(tempBuffer, layerData, mask, options, realMask) {
|
|
14069
|
+
var _a;
|
|
12894
14070
|
let top = mask.top | 0;
|
|
12895
14071
|
let left = mask.left | 0;
|
|
12896
14072
|
let right = mask.right | 0;
|
|
@@ -12907,10 +14083,15 @@ function getMaskChannels(tempBuffer, layerData, mask, options, realMask) {
|
|
|
12907
14083
|
bottom = top + height;
|
|
12908
14084
|
let buffer;
|
|
12909
14085
|
let compression;
|
|
14086
|
+
const bitsPerChannel = (_a = options.bitsPerChannel) !== null && _a !== void 0 ? _a : 8;
|
|
12910
14087
|
if (!imageData) {
|
|
12911
14088
|
buffer = new Uint8Array(0);
|
|
12912
14089
|
compression = 1 /* Compression.RleCompressed */;
|
|
12913
14090
|
}
|
|
14091
|
+
else if (bitsPerChannel !== 8 || !is8bit(imageData)) {
|
|
14092
|
+
const { colors } = getPlanarChannels(imageData, 3 /* ColorMode.RGB */, bitsPerChannel, false);
|
|
14093
|
+
({ data: buffer, compression } = encodeChannel(colors[0], width, height, options));
|
|
14094
|
+
}
|
|
12914
14095
|
else if (options.compress) {
|
|
12915
14096
|
buffer = (0, helpers_1.writeDataZipWithoutPrediction)(imageData, [0]);
|
|
12916
14097
|
compression = 2 /* Compression.ZipWithoutPrediction */;
|
|
@@ -12931,16 +14112,16 @@ function bounds(obj) {
|
|
|
12931
14112
|
} : undefined;
|
|
12932
14113
|
}
|
|
12933
14114
|
function getChannels(writer, layer, background, options) {
|
|
14115
|
+
var _a, _b;
|
|
12934
14116
|
let source = layer;
|
|
12935
14117
|
if (layer.rawData) {
|
|
12936
14118
|
const { colorMode, bitsPerChannel, large } = layer.rawData;
|
|
12937
|
-
|
|
14119
|
+
const opt = options;
|
|
14120
|
+
if (large === !!options.psb && colorMode === ((_a = opt.colorMode) !== null && _a !== void 0 ? _a : 3 /* ColorMode.RGB */) && bitsPerChannel === ((_b = opt.bitsPerChannel) !== null && _b !== void 0 ? _b : 8)) {
|
|
12938
14121
|
// same mask mapping as in writeLayerMaskData
|
|
12939
14122
|
const { mask, realMask } = getMasks(layer);
|
|
12940
14123
|
return Object.assign(Object.assign({ layer, channels: layer.rawData.channels.map(c => { var _a, _b; return (Object.assign(Object.assign({}, c), { length: 2 + ((_b = (_a = c.data) === null || _a === void 0 ? void 0 : _a.byteLength) !== null && _b !== void 0 ? _b : 0) })); }) }, bounds(layer)), { mask: bounds(mask), realMask: bounds(realMask) });
|
|
12941
14124
|
}
|
|
12942
|
-
if (bitsPerChannel !== 8)
|
|
12943
|
-
throw new Error('Layer raw data with bitsPerChannel other than 8 is not supported for writing');
|
|
12944
14125
|
// raw data is in different format than the one we're writing, decode it so it can be re-encoded
|
|
12945
14126
|
source = Object.assign(Object.assign({}, layer), { rawData: undefined, canvas: undefined, imageData: (0, psdReader_1.getLayerImageData)(layer), mask: layer.mask && Object.assign(Object.assign({}, layer.mask), { canvas: undefined, imageData: (0, psdReader_1.getLayerMaskImageData)(layer) }), realMask: layer.realMask && Object.assign(Object.assign({}, layer.realMask), { canvas: undefined, imageData: (0, psdReader_1.getLayerRealMaskImageData)(layer) }) });
|
|
12946
14127
|
// temp buffer is sized only for layers with image data, grow it and keep it for following layers
|
|
@@ -12966,10 +14147,8 @@ function getLayerDimentions({ canvas, imageData }) {
|
|
|
12966
14147
|
return { width, height };
|
|
12967
14148
|
}
|
|
12968
14149
|
function cropImageData(data, left, top, width, height) {
|
|
12969
|
-
|
|
12970
|
-
|
|
12971
|
-
}
|
|
12972
|
-
const croppedData = (0, helpers_1.createImageData)(width, height);
|
|
14150
|
+
const croppedData = is8bit(data) ? (0, helpers_1.createImageData)(width, height) :
|
|
14151
|
+
{ width, height, data: new data.data.constructor(width * height * 4) };
|
|
12973
14152
|
const srcData = data.data;
|
|
12974
14153
|
const dstData = croppedData.data;
|
|
12975
14154
|
for (let y = 0; y < height; y++) {
|
|
@@ -12985,6 +14164,7 @@ function cropImageData(data, left, top, width, height) {
|
|
|
12985
14164
|
return croppedData;
|
|
12986
14165
|
}
|
|
12987
14166
|
function getLayerChannels(tempBuffer, layer, background, options) {
|
|
14167
|
+
var _a, _b;
|
|
12988
14168
|
let top = layer.top | 0;
|
|
12989
14169
|
let left = layer.left | 0;
|
|
12990
14170
|
let right = layer.right | 0;
|
|
@@ -12997,8 +14177,11 @@ function getLayerChannels(tempBuffer, layer, background, options) {
|
|
|
12997
14177
|
];
|
|
12998
14178
|
let { width, height } = getLayerDimentions(layer);
|
|
12999
14179
|
if (!(layer.canvas || layer.imageData) || !width || !height) {
|
|
13000
|
-
|
|
13001
|
-
|
|
14180
|
+
// layer without image data is empty, keep inverted (negative size) bounds from some files as they are
|
|
14181
|
+
if (layer.right === undefined || right > left)
|
|
14182
|
+
right = left;
|
|
14183
|
+
if (layer.bottom === undefined || bottom > top)
|
|
14184
|
+
bottom = top;
|
|
13002
14185
|
return { layer, top, left, right, bottom, channels };
|
|
13003
14186
|
}
|
|
13004
14187
|
right = left + width;
|
|
@@ -13026,6 +14209,19 @@ function getLayerChannels(tempBuffer, layer, background, options) {
|
|
|
13026
14209
|
if (!background || options.noBackground || layer.mask || (0, helpers_1.hasAlpha)(imageData)) {
|
|
13027
14210
|
channelIds.unshift(-1 /* ChannelID.Transparency */);
|
|
13028
14211
|
}
|
|
14212
|
+
const colorMode = (_a = options.colorMode) !== null && _a !== void 0 ? _a : 3 /* ColorMode.RGB */;
|
|
14213
|
+
const bitsPerChannel = (_b = options.bitsPerChannel) !== null && _b !== void 0 ? _b : 8;
|
|
14214
|
+
if (colorMode !== 3 /* ColorMode.RGB */ || bitsPerChannel !== 8 || !is8bit(imageData)) {
|
|
14215
|
+
const { colors, alpha } = getPlanarChannels(imageData, colorMode, bitsPerChannel, false);
|
|
14216
|
+
const ids = channelIds[0] === -1 /* ChannelID.Transparency */ ? [-1 /* ChannelID.Transparency */] : [];
|
|
14217
|
+
for (let i = 0; i < colors.length; i++)
|
|
14218
|
+
ids.push(i);
|
|
14219
|
+
channels = ids.map(id => {
|
|
14220
|
+
const { data, compression } = encodeChannel(id === -1 /* ChannelID.Transparency */ ? alpha : colors[id], width, height, options);
|
|
14221
|
+
return { id, compression, data, length: 2 + data.length };
|
|
14222
|
+
});
|
|
14223
|
+
return { layer, top, left, right, bottom, channels };
|
|
14224
|
+
}
|
|
13029
14225
|
channels = channelIds.map(id => {
|
|
13030
14226
|
const offset = (0, helpers_1.offsetForChannel)(id, false); // image data is always RGBA
|
|
13031
14227
|
let data;
|
|
@@ -13183,10 +14379,11 @@ function writePattern(writer, pattern) {
|
|
|
13183
14379
|
writer.view.setUint32(pattsOffset - 4, pattsLength, false);
|
|
13184
14380
|
}
|
|
13185
14381
|
|
|
13186
|
-
},{"./additionalInfo":2,"./helpers":
|
|
14382
|
+
},{"./additionalInfo":2,"./helpers":9,"./imageResources":10,"./psdReader":14,"pako":21}],16:[function(require,module,exports){
|
|
13187
14383
|
"use strict";
|
|
13188
14384
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13189
14385
|
exports.decodeEngineData = decodeEngineData;
|
|
14386
|
+
exports.decodeLegacyTextData = decodeLegacyTextData;
|
|
13190
14387
|
exports.encodeEngineData = encodeEngineData;
|
|
13191
14388
|
const helpers_1 = require("./helpers");
|
|
13192
14389
|
const defaultFont = {
|
|
@@ -13613,6 +14810,63 @@ function decodeEngineData(engineData) {
|
|
|
13613
14810
|
delete result.styleRuns;
|
|
13614
14811
|
return result;
|
|
13615
14812
|
}
|
|
14813
|
+
const fixed = (value) => value / 0x10000; // 16.16 fixed point value
|
|
14814
|
+
function decodeLegacyTextData(data) {
|
|
14815
|
+
var _a, _b, _c, _d;
|
|
14816
|
+
const styleRuns = [];
|
|
14817
|
+
let text = '';
|
|
14818
|
+
for (const line of data.lines) {
|
|
14819
|
+
for (const { code, style } of line.chars) {
|
|
14820
|
+
text += String.fromCharCode(code);
|
|
14821
|
+
const last = styleRuns[styleRuns.length - 1];
|
|
14822
|
+
if (last && last.mark === style) {
|
|
14823
|
+
last.length++;
|
|
14824
|
+
}
|
|
14825
|
+
else {
|
|
14826
|
+
styleRuns.push({ length: 1, mark: style });
|
|
14827
|
+
}
|
|
14828
|
+
}
|
|
14829
|
+
}
|
|
14830
|
+
// remove one trailing new line (Photoshop always appends it)
|
|
14831
|
+
if (text.endsWith('\r')) {
|
|
14832
|
+
text = text.slice(0, -1);
|
|
14833
|
+
if (--styleRuns[styleRuns.length - 1].length === 0)
|
|
14834
|
+
styleRuns.pop();
|
|
14835
|
+
}
|
|
14836
|
+
const runs = styleRuns.map(({ length, mark }) => {
|
|
14837
|
+
var _a, _b;
|
|
14838
|
+
const s = (_a = data.styles.find(s => s.mark === mark)) !== null && _a !== void 0 ? _a : data.styles[0];
|
|
14839
|
+
const face = s && ((_b = data.faces.find(f => f.mark === s.faceMark)) !== null && _b !== void 0 ? _b : data.faces[0]);
|
|
14840
|
+
const style = {};
|
|
14841
|
+
if (face)
|
|
14842
|
+
style.font = { name: face.name, script: face.script };
|
|
14843
|
+
if (s) {
|
|
14844
|
+
style.fontSize = fixed(s.size);
|
|
14845
|
+
style.autoLeading = s.leading === 0;
|
|
14846
|
+
if (s.leading)
|
|
14847
|
+
style.leading = fixed(s.leading);
|
|
14848
|
+
style.tracking = Math.round(fixed(s.tracking) * 1000); // stored in ems
|
|
14849
|
+
style.autoKerning = s.autoKerning;
|
|
14850
|
+
style.kerning = Math.round(fixed(s.kerning) * 1000); // stored in ems
|
|
14851
|
+
style.baselineShift = fixed(s.baselineShift);
|
|
14852
|
+
}
|
|
14853
|
+
style.fillColor = data.color;
|
|
14854
|
+
return { length, style };
|
|
14855
|
+
});
|
|
14856
|
+
const result = {
|
|
14857
|
+
text: text.replace(/\r/g, '\n'),
|
|
14858
|
+
transform: data.transform,
|
|
14859
|
+
antiAlias: data.antiAlias ? 'smooth' : 'none',
|
|
14860
|
+
orientation: ((_a = data.lines[0]) === null || _a === void 0 ? void 0 : _a.orientation) === 1 ? 'vertical' : 'horizontal',
|
|
14861
|
+
paragraphStyle: { justification: (_d = justification[(_c = (_b = data.lines[0]) === null || _b === void 0 ? void 0 : _b.alignment) !== null && _c !== void 0 ? _c : 0]) !== null && _d !== void 0 ? _d : 'left' },
|
|
14862
|
+
style: {},
|
|
14863
|
+
styleRuns: runs,
|
|
14864
|
+
};
|
|
14865
|
+
deduplicateValues(result.style, result.styleRuns, styleKeys);
|
|
14866
|
+
if (!result.styleRuns.length)
|
|
14867
|
+
delete result.styleRuns;
|
|
14868
|
+
return result;
|
|
14869
|
+
}
|
|
13616
14870
|
// Adjusts run lengths (specified in terms of the original text) for characters removed from the text
|
|
13617
14871
|
// (\r characters of \r\n pairs that are collapsed into single \r)
|
|
13618
14872
|
function adjustRunLengths(runs, removed) {
|
|
@@ -13851,7 +15105,7 @@ function encodeEngineData(data) {
|
|
|
13851
15105
|
return engineData;
|
|
13852
15106
|
}
|
|
13853
15107
|
|
|
13854
|
-
},{"./helpers":
|
|
15108
|
+
},{"./helpers":9}],17:[function(require,module,exports){
|
|
13855
15109
|
"use strict";
|
|
13856
15110
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13857
15111
|
exports.stringLengthInBytes = stringLengthInBytes;
|
|
@@ -14038,7 +15292,7 @@ function decodeString(value) {
|
|
|
14038
15292
|
return result.join('');
|
|
14039
15293
|
}
|
|
14040
15294
|
|
|
14041
|
-
},{}],
|
|
15295
|
+
},{}],18:[function(require,module,exports){
|
|
14042
15296
|
'use strict'
|
|
14043
15297
|
|
|
14044
15298
|
exports.byteLength = byteLength
|
|
@@ -14190,7 +15444,7 @@ function fromByteArray (uint8) {
|
|
|
14190
15444
|
return parts.join('')
|
|
14191
15445
|
}
|
|
14192
15446
|
|
|
14193
|
-
},{}],
|
|
15447
|
+
},{}],19:[function(require,module,exports){
|
|
14194
15448
|
(function (Buffer){(function (){
|
|
14195
15449
|
/*!
|
|
14196
15450
|
* The buffer module from node.js, for the browser.
|
|
@@ -15971,7 +17225,7 @@ function numberIsNaN (obj) {
|
|
|
15971
17225
|
}
|
|
15972
17226
|
|
|
15973
17227
|
}).call(this)}).call(this,require("buffer").Buffer)
|
|
15974
|
-
},{"base64-js":
|
|
17228
|
+
},{"base64-js":18,"buffer":19,"ieee754":20}],20:[function(require,module,exports){
|
|
15975
17229
|
/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
|
|
15976
17230
|
exports.read = function (buffer, offset, isLE, mLen, nBytes) {
|
|
15977
17231
|
var e, m
|
|
@@ -16058,7 +17312,7 @@ exports.write = function (buffer, value, offset, isLE, mLen, nBytes) {
|
|
|
16058
17312
|
buffer[offset + i - d] |= s * 128
|
|
16059
17313
|
}
|
|
16060
17314
|
|
|
16061
|
-
},{}],
|
|
17315
|
+
},{}],21:[function(require,module,exports){
|
|
16062
17316
|
// Top level file is just a mixin of submodules & constants
|
|
16063
17317
|
'use strict';
|
|
16064
17318
|
|
|
@@ -16078,7 +17332,7 @@ module.exports.inflateRaw = inflateRaw;
|
|
|
16078
17332
|
module.exports.ungzip = ungzip;
|
|
16079
17333
|
module.exports.constants = constants;
|
|
16080
17334
|
|
|
16081
|
-
},{"./lib/deflate":
|
|
17335
|
+
},{"./lib/deflate":22,"./lib/inflate":23,"./lib/zlib/constants":27}],22:[function(require,module,exports){
|
|
16082
17336
|
'use strict';
|
|
16083
17337
|
|
|
16084
17338
|
|
|
@@ -16460,7 +17714,7 @@ module.exports.deflateRaw = deflateRaw;
|
|
|
16460
17714
|
module.exports.gzip = gzip;
|
|
16461
17715
|
module.exports.constants = require('./zlib/constants');
|
|
16462
17716
|
|
|
16463
|
-
},{"./utils/common":
|
|
17717
|
+
},{"./utils/common":24,"./utils/strings":25,"./zlib/constants":27,"./zlib/deflate":29,"./zlib/messages":34,"./zlib/zstream":36}],23:[function(require,module,exports){
|
|
16464
17718
|
'use strict';
|
|
16465
17719
|
|
|
16466
17720
|
|
|
@@ -16881,7 +18135,7 @@ module.exports.inflateRaw = inflateRaw;
|
|
|
16881
18135
|
module.exports.ungzip = inflate;
|
|
16882
18136
|
module.exports.constants = require('./zlib/constants');
|
|
16883
18137
|
|
|
16884
|
-
},{"./utils/common":
|
|
18138
|
+
},{"./utils/common":24,"./utils/strings":25,"./zlib/constants":27,"./zlib/gzheader":30,"./zlib/inflate":32,"./zlib/messages":34,"./zlib/zstream":36}],24:[function(require,module,exports){
|
|
16885
18139
|
'use strict';
|
|
16886
18140
|
|
|
16887
18141
|
|
|
@@ -16931,7 +18185,7 @@ module.exports.flattenChunks = (chunks) => {
|
|
|
16931
18185
|
return result;
|
|
16932
18186
|
};
|
|
16933
18187
|
|
|
16934
|
-
},{}],
|
|
18188
|
+
},{}],25:[function(require,module,exports){
|
|
16935
18189
|
// String encode/decode helpers
|
|
16936
18190
|
'use strict';
|
|
16937
18191
|
|
|
@@ -17107,7 +18361,7 @@ module.exports.utf8border = (buf, max) => {
|
|
|
17107
18361
|
return (pos + _utf8len[buf[pos]] > max) ? pos : max;
|
|
17108
18362
|
};
|
|
17109
18363
|
|
|
17110
|
-
},{}],
|
|
18364
|
+
},{}],26:[function(require,module,exports){
|
|
17111
18365
|
'use strict';
|
|
17112
18366
|
|
|
17113
18367
|
// Note: adler32 takes 12% for level 0 and 2% for level 6.
|
|
@@ -17160,7 +18414,7 @@ const adler32 = (adler, buf, len, pos) => {
|
|
|
17160
18414
|
|
|
17161
18415
|
module.exports = adler32;
|
|
17162
18416
|
|
|
17163
|
-
},{}],
|
|
18417
|
+
},{}],27:[function(require,module,exports){
|
|
17164
18418
|
'use strict';
|
|
17165
18419
|
|
|
17166
18420
|
// (C) 1995-2013 Jean-loup Gailly and Mark Adler
|
|
@@ -17230,7 +18484,7 @@ module.exports = {
|
|
|
17230
18484
|
//Z_NULL: null // Use -1 or null inline, depending on var type
|
|
17231
18485
|
};
|
|
17232
18486
|
|
|
17233
|
-
},{}],
|
|
18487
|
+
},{}],28:[function(require,module,exports){
|
|
17234
18488
|
'use strict';
|
|
17235
18489
|
|
|
17236
18490
|
// Note: we can't get significant speed boost here.
|
|
@@ -17291,7 +18545,7 @@ const crc32 = (crc, buf, len, pos) => {
|
|
|
17291
18545
|
|
|
17292
18546
|
module.exports = crc32;
|
|
17293
18547
|
|
|
17294
|
-
},{}],
|
|
18548
|
+
},{}],29:[function(require,module,exports){
|
|
17295
18549
|
'use strict';
|
|
17296
18550
|
|
|
17297
18551
|
// (C) 1995-2013 Jean-loup Gailly and Mark Adler
|
|
@@ -19341,7 +20595,7 @@ module.exports.deflatePrime = deflatePrime;
|
|
|
19341
20595
|
module.exports.deflateTune = deflateTune;
|
|
19342
20596
|
*/
|
|
19343
20597
|
|
|
19344
|
-
},{"./adler32":
|
|
20598
|
+
},{"./adler32":26,"./constants":27,"./crc32":28,"./messages":34,"./trees":35}],30:[function(require,module,exports){
|
|
19345
20599
|
'use strict';
|
|
19346
20600
|
|
|
19347
20601
|
// (C) 1995-2013 Jean-loup Gailly and Mark Adler
|
|
@@ -19401,7 +20655,7 @@ function GZheader() {
|
|
|
19401
20655
|
|
|
19402
20656
|
module.exports = GZheader;
|
|
19403
20657
|
|
|
19404
|
-
},{}],
|
|
20658
|
+
},{}],31:[function(require,module,exports){
|
|
19405
20659
|
'use strict';
|
|
19406
20660
|
|
|
19407
20661
|
// (C) 1995-2013 Jean-loup Gailly and Mark Adler
|
|
@@ -19747,7 +21001,7 @@ module.exports = function inflate_fast(strm, start) {
|
|
|
19747
21001
|
return;
|
|
19748
21002
|
};
|
|
19749
21003
|
|
|
19750
|
-
},{}],
|
|
21004
|
+
},{}],32:[function(require,module,exports){
|
|
19751
21005
|
'use strict';
|
|
19752
21006
|
|
|
19753
21007
|
// (C) 1995-2013 Jean-loup Gailly and Mark Adler
|
|
@@ -21321,7 +22575,7 @@ module.exports.inflateUndermine = inflateUndermine;
|
|
|
21321
22575
|
module.exports.inflateValidate = inflateValidate;
|
|
21322
22576
|
*/
|
|
21323
22577
|
|
|
21324
|
-
},{"./adler32":
|
|
22578
|
+
},{"./adler32":26,"./constants":27,"./crc32":28,"./inffast":31,"./inftrees":33}],33:[function(require,module,exports){
|
|
21325
22579
|
'use strict';
|
|
21326
22580
|
|
|
21327
22581
|
// (C) 1995-2013 Jean-loup Gailly and Mark Adler
|
|
@@ -21663,7 +22917,7 @@ const inflate_table = (type, lens, lens_index, codes, table, table_index, work,
|
|
|
21663
22917
|
|
|
21664
22918
|
module.exports = inflate_table;
|
|
21665
22919
|
|
|
21666
|
-
},{}],
|
|
22920
|
+
},{}],34:[function(require,module,exports){
|
|
21667
22921
|
'use strict';
|
|
21668
22922
|
|
|
21669
22923
|
// (C) 1995-2013 Jean-loup Gailly and Mark Adler
|
|
@@ -21697,7 +22951,7 @@ module.exports = {
|
|
|
21697
22951
|
'-6': 'incompatible version' /* Z_VERSION_ERROR (-6) */
|
|
21698
22952
|
};
|
|
21699
22953
|
|
|
21700
|
-
},{}],
|
|
22954
|
+
},{}],35:[function(require,module,exports){
|
|
21701
22955
|
'use strict';
|
|
21702
22956
|
|
|
21703
22957
|
// (C) 1995-2013 Jean-loup Gailly and Mark Adler
|
|
@@ -22878,7 +24132,7 @@ module.exports._tr_flush_block = _tr_flush_block;
|
|
|
22878
24132
|
module.exports._tr_tally = _tr_tally;
|
|
22879
24133
|
module.exports._tr_align = _tr_align;
|
|
22880
24134
|
|
|
22881
|
-
},{}],
|
|
24135
|
+
},{}],36:[function(require,module,exports){
|
|
22882
24136
|
'use strict';
|
|
22883
24137
|
|
|
22884
24138
|
// (C) 1995-2013 Jean-loup Gailly and Mark Adler
|
|
@@ -22927,5 +24181,5 @@ function ZStream() {
|
|
|
22927
24181
|
|
|
22928
24182
|
module.exports = ZStream;
|
|
22929
24183
|
|
|
22930
|
-
},{}]},{},[
|
|
24184
|
+
},{}]},{},[11])(11)
|
|
22931
24185
|
});
|