ag-psd 34.2.2 → 34.2.4
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/v26.13.0-x64-310b2ce3/4511bacf +0 -0
- package/.v8-cache/v26.13.0-x64-310b2ce3/71df9cb3 +0 -0
- package/.v8-cache/v26.13.0-x64-310b2ce3/7ea06cea +0 -0
- package/.v8-cache/v26.13.0-x64-310b2ce3/932f0770 +0 -0
- package/.v8-cache/v26.13.0-x64-310b2ce3/a7e80865 +0 -0
- package/.v8-cache/v26.13.0-x64-310b2ce3/acc36e66 +0 -0
- package/.v8-cache/v26.13.0-x64-310b2ce3/b3c2fab7 +0 -0
- package/.v8-cache/v26.13.0-x64-310b2ce3/c314aece +0 -0
- package/.v8-cache/v26.13.0-x64-310b2ce3/dc86f000 +0 -0
- package/.v8-cache/v26.13.0-x64-310b2ce3/e03e2acd +0 -0
- package/.v8-cache/v26.13.0-x64-310b2ce3/e6735171 +0 -0
- package/CHANGELOG.md +9 -0
- package/README.md +23 -4
- package/dist/abr.js +12 -5
- package/dist/abr.js.map +1 -1
- package/dist/additionalInfo.js +1 -1
- package/dist/additionalInfo.js.map +1 -1
- package/dist/bundle.js +256 -78
- package/dist/descriptor.js +51 -16
- package/dist/descriptor.js.map +1 -1
- package/dist/engineData.d.ts +1 -0
- package/dist/engineData.js +4 -3
- package/dist/engineData.js.map +1 -1
- package/dist/helpers.d.ts +4 -0
- package/dist/helpers.js +11 -0
- package/dist/helpers.js.map +1 -1
- package/dist/imageResources.js +1 -1
- package/dist/imageResources.js.map +1 -1
- package/dist/psd.d.ts +1 -1
- package/dist/psdReader.d.ts +1 -0
- package/dist/psdReader.js +170 -46
- package/dist/psdReader.js.map +1 -1
- package/dist/text.js +5 -5
- package/dist/text.js.map +1 -1
- package/dist-es/abr.js +12 -5
- package/dist-es/abr.js.map +1 -1
- package/dist-es/additionalInfo.js +1 -1
- package/dist-es/additionalInfo.js.map +1 -1
- package/dist-es/descriptor.js +51 -16
- package/dist-es/descriptor.js.map +1 -1
- package/dist-es/engineData.d.ts +1 -0
- package/dist-es/engineData.js +4 -3
- package/dist-es/engineData.js.map +1 -1
- package/dist-es/helpers.d.ts +4 -0
- package/dist-es/helpers.js +11 -0
- package/dist-es/helpers.js.map +1 -1
- package/dist-es/imageResources.js +1 -1
- package/dist-es/imageResources.js.map +1 -1
- package/dist-es/psd.d.ts +1 -1
- package/dist-es/psdReader.d.ts +1 -0
- package/dist-es/psdReader.js +170 -46
- package/dist-es/psdReader.js.map +1 -1
- package/dist-es/text.js +5 -5
- package/dist-es/text.js.map +1 -1
- package/package.json +1 -1
- package/src/abr.ts +11 -5
- package/src/additionalInfo.ts +2 -2
- package/src/descriptor.ts +55 -19
- package/src/engineData.ts +1 -1
- package/src/helpers.ts +11 -0
- package/src/imageResources.ts +2 -2
- package/src/psd.ts +1 -1
- package/src/psdReader.ts +178 -43
- package/src/text.ts +5 -5
package/dist-es/psdReader.js
CHANGED
|
@@ -1079,7 +1079,8 @@ function readImageData(reader, psd) {
|
|
|
1079
1079
|
const { width, height } = psd;
|
|
1080
1080
|
if (exports.supportedColorModes.indexOf(psd.colorMode) === -1)
|
|
1081
1081
|
throw new Error(`Color mode not supported: ${psd.colorMode}`);
|
|
1082
|
-
if (compression !== 0 /* Compression.RawData */ && compression !== 1 /* Compression.RleCompressed */
|
|
1082
|
+
if (compression !== 0 /* Compression.RawData */ && compression !== 1 /* Compression.RleCompressed */ &&
|
|
1083
|
+
compression !== 2 /* Compression.ZipWithoutPrediction */ && compression !== 3 /* Compression.ZipWithPrediction */)
|
|
1083
1084
|
throw new Error(`Compression type not supported: ${compression}`);
|
|
1084
1085
|
const imageData = createImageDataBitDepth(width, height, bitsPerChannel, 4, reader.totalMemoryLimit);
|
|
1085
1086
|
if (reader.totalMemoryLimit !== undefined)
|
|
@@ -1096,7 +1097,7 @@ function readImageData(reader, psd) {
|
|
|
1096
1097
|
}
|
|
1097
1098
|
else {
|
|
1098
1099
|
bytes = new Uint8Array(rowBytes * height);
|
|
1099
|
-
|
|
1100
|
+
readCompositeChannels(reader, compression, { data: bytes, width: rowBytes, height }, 8, 1, [0]);
|
|
1100
1101
|
}
|
|
1101
1102
|
(0, helpers_1.decodeBitmap)(bytes, imageData.data, width, height);
|
|
1102
1103
|
break;
|
|
@@ -1185,10 +1186,74 @@ function readCompositeChannels(reader, compression, pixelData, bitsPerChannel, s
|
|
|
1185
1186
|
else if (compression === 1 /* Compression.RleCompressed */) {
|
|
1186
1187
|
readDataRLE(reader, pixelData, pixelData.width, pixelData.height, bitsPerChannel, step, offsets, reader.large);
|
|
1187
1188
|
}
|
|
1189
|
+
else if (compression === 2 /* Compression.ZipWithoutPrediction */ || compression === 3 /* Compression.ZipWithPrediction */) {
|
|
1190
|
+
readCompositeChannelsZip(reader, pixelData, bitsPerChannel, step, offsets, compression === 3 /* Compression.ZipWithPrediction */);
|
|
1191
|
+
}
|
|
1188
1192
|
else {
|
|
1189
1193
|
throw new Error(`Compression not supported: ${compression}`);
|
|
1190
1194
|
}
|
|
1191
1195
|
}
|
|
1196
|
+
// Zip compressed composite image data has no lengths of channels. Applications that write it (Photoshop writes RLE)
|
|
1197
|
+
// store each channel as a separate zlib stream, like channels of layers, or all the channels in one stream. Reads all
|
|
1198
|
+
// the remaining data, the composite image is the last section of the file.
|
|
1199
|
+
function readCompositeChannelsZip(reader, pixelData, bitsPerChannel, step, offsets, prediction) {
|
|
1200
|
+
const { width, height } = pixelData;
|
|
1201
|
+
const bpv = bytesPerValue(bitsPerChannel);
|
|
1202
|
+
const channelSize = width * height * bpv;
|
|
1203
|
+
verifyArrayType(pixelData.data, bpv);
|
|
1204
|
+
const input = readBytes(reader, Math.max(0, reader.view.byteLength - reader.offset));
|
|
1205
|
+
consumeMemory(reader, channelSize);
|
|
1206
|
+
try {
|
|
1207
|
+
const channel = new Uint8Array(channelSize);
|
|
1208
|
+
for (let i = 0, position = 0; i < offsets.length && position < input.length; i++) {
|
|
1209
|
+
if (i)
|
|
1210
|
+
channel.fill(0);
|
|
1211
|
+
const stream = inflateZlibStream(input.subarray(position), channel);
|
|
1212
|
+
if (i === 0 && stream.overflow) {
|
|
1213
|
+
readCompositeChannelsZipSingleStream(reader, input, pixelData, bpv, step, offsets, prediction);
|
|
1214
|
+
return;
|
|
1215
|
+
}
|
|
1216
|
+
if (stream.overflow) {
|
|
1217
|
+
warnOrThrow(reader, zipOverflow.message);
|
|
1218
|
+
}
|
|
1219
|
+
else if (!stream.complete) {
|
|
1220
|
+
warnOrThrow(reader, 'Invalid zip data: unexpected end of data');
|
|
1221
|
+
}
|
|
1222
|
+
if (offsets[i] >= 0)
|
|
1223
|
+
writeZipChannel(channel, pixelData, width, height, bpv, step, offsets[i], prediction);
|
|
1224
|
+
position += stream.length;
|
|
1225
|
+
}
|
|
1226
|
+
}
|
|
1227
|
+
finally {
|
|
1228
|
+
recoverMemory(reader, channelSize);
|
|
1229
|
+
}
|
|
1230
|
+
}
|
|
1231
|
+
// all the channels in one zlib stream, one after another
|
|
1232
|
+
function readCompositeChannelsZipSingleStream(reader, input, pixelData, bpv, step, offsets, prediction) {
|
|
1233
|
+
const { width, height } = pixelData;
|
|
1234
|
+
const channelSize = width * height * bpv;
|
|
1235
|
+
const size = channelSize * offsets.length;
|
|
1236
|
+
consumeMemory(reader, size);
|
|
1237
|
+
try {
|
|
1238
|
+
const channels = new Uint8Array(size);
|
|
1239
|
+
const stream = inflateZlibStream(input, channels);
|
|
1240
|
+
if (stream.overflow) {
|
|
1241
|
+
warnOrThrow(reader, zipOverflow.message);
|
|
1242
|
+
}
|
|
1243
|
+
else if (!stream.complete) {
|
|
1244
|
+
warnOrThrow(reader, 'Invalid zip data: unexpected end of data');
|
|
1245
|
+
}
|
|
1246
|
+
for (let i = 0; i < offsets.length; i++) {
|
|
1247
|
+
if (offsets[i] < 0)
|
|
1248
|
+
continue;
|
|
1249
|
+
const channel = channels.subarray(i * channelSize, (i + 1) * channelSize);
|
|
1250
|
+
writeZipChannel(channel, pixelData, width, height, bpv, step, offsets[i], prediction);
|
|
1251
|
+
}
|
|
1252
|
+
}
|
|
1253
|
+
finally {
|
|
1254
|
+
recoverMemory(reader, size);
|
|
1255
|
+
}
|
|
1256
|
+
}
|
|
1192
1257
|
// un-premultiplies colors from white matte, used for composite image of documents with global alpha
|
|
1193
1258
|
function removeWhiteMatte({ data, width, height }) {
|
|
1194
1259
|
const size = width * height * 4;
|
|
@@ -1377,66 +1442,117 @@ function inflateLimited(compressed, expectedSize, reader, raw = false) {
|
|
|
1377
1442
|
}
|
|
1378
1443
|
return output;
|
|
1379
1444
|
}
|
|
1445
|
+
// Inflates the zlib stream at the start of `input` into `output`. Returns the length of the stream in `input`
|
|
1446
|
+
// (header and checksum included) and whether the stream ended within `input` without exceeding `output`.
|
|
1447
|
+
// The data is inflated as raw deflate data, because in zlib mode pako continues into the stream that follows as if
|
|
1448
|
+
// it was part of the same data. The checksum is not verified.
|
|
1449
|
+
function inflateZlibStream(input, output) {
|
|
1450
|
+
const cmf = input[0], flg = input[1];
|
|
1451
|
+
// deflate compression method, valid header check bits, no preset dictionary
|
|
1452
|
+
if (input.length < 2 || (cmf & 0x0f) !== 8 || ((cmf << 8) | flg) % 31 !== 0 || (flg & 0x20) !== 0) {
|
|
1453
|
+
throw new Error('Invalid zip data: incorrect header check');
|
|
1454
|
+
}
|
|
1455
|
+
let written = 0;
|
|
1456
|
+
let overflow = false;
|
|
1457
|
+
let ended = false;
|
|
1458
|
+
let deflateLength = 0;
|
|
1459
|
+
const inflator = new pako_1.Inflate({ chunkSize: Math.max(1024, Math.min(output.length, 0x10000)), raw: true });
|
|
1460
|
+
inflator.onData = (chunk) => {
|
|
1461
|
+
const data = chunk;
|
|
1462
|
+
const count = Math.min(data.length, output.length - written);
|
|
1463
|
+
if (count > 0)
|
|
1464
|
+
output.set(count === data.length ? data : data.subarray(0, count), written);
|
|
1465
|
+
written += count;
|
|
1466
|
+
if (count < data.length) {
|
|
1467
|
+
overflow = true;
|
|
1468
|
+
throw zipOverflow;
|
|
1469
|
+
}
|
|
1470
|
+
};
|
|
1471
|
+
inflator.onEnd = (status) => {
|
|
1472
|
+
var _a, _b, _c;
|
|
1473
|
+
inflator.err = status;
|
|
1474
|
+
inflator.msg = ((_a = inflator.strm) === null || _a === void 0 ? void 0 : _a.msg) || '';
|
|
1475
|
+
ended = true;
|
|
1476
|
+
deflateLength = (_c = (_b = inflator.strm) === null || _b === void 0 ? void 0 : _b.next_in) !== null && _c !== void 0 ? _c : 0;
|
|
1477
|
+
};
|
|
1478
|
+
try {
|
|
1479
|
+
inflator.push(input.subarray(2), true);
|
|
1480
|
+
}
|
|
1481
|
+
catch (e) {
|
|
1482
|
+
if (e !== zipOverflow)
|
|
1483
|
+
throw e;
|
|
1484
|
+
}
|
|
1485
|
+
if (overflow)
|
|
1486
|
+
return { length: input.length, complete: false, overflow };
|
|
1487
|
+
if (inflator.err)
|
|
1488
|
+
throw new Error(`Invalid zip data: ${inflator.msg}`);
|
|
1489
|
+
if (!ended)
|
|
1490
|
+
return { length: input.length, complete: false, overflow }; // data ends before the stream does
|
|
1491
|
+
return { length: Math.min(input.length, 2 + deflateLength + 4), complete: true, overflow };
|
|
1492
|
+
}
|
|
1380
1493
|
function readDataZip(compressed, pixelData, width, height, bitDepth, step, offset, prediction, reader) {
|
|
1381
1494
|
const bpv = bytesPerValue(bitDepth);
|
|
1382
1495
|
if (!pixelData || offset < 0 || offset >= step)
|
|
1383
1496
|
return;
|
|
1384
|
-
|
|
1385
|
-
verifyArrayType(data, bpv);
|
|
1497
|
+
verifyArrayType(pixelData.data, bpv);
|
|
1386
1498
|
const expectedSize = width * height * bpv;
|
|
1387
1499
|
if (reader)
|
|
1388
1500
|
consumeMemory(reader, expectedSize);
|
|
1389
1501
|
try {
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1502
|
+
writeZipChannel(inflateLimited(compressed, expectedSize, reader), pixelData, width, height, bpv, step, offset, prediction);
|
|
1503
|
+
}
|
|
1504
|
+
finally {
|
|
1505
|
+
if (reader)
|
|
1506
|
+
recoverMemory(reader, expectedSize);
|
|
1507
|
+
}
|
|
1508
|
+
}
|
|
1509
|
+
// writes inflated values of one channel to `pixelData` (modifies `decompressed` when decoding 32bit prediction)
|
|
1510
|
+
function writeZipChannel(decompressed, pixelData, width, height, bpv, step, offset, prediction) {
|
|
1511
|
+
const data = pixelData.data;
|
|
1512
|
+
if (bpv === 1) {
|
|
1513
|
+
for (let y = 0, i = 0; y < height; y++) {
|
|
1514
|
+
let prev = 0;
|
|
1515
|
+
for (let x = 0, p = offset + y * width * step; x < width; x++, i++, p += step) {
|
|
1516
|
+
let v = decompressed[i];
|
|
1517
|
+
if (prediction)
|
|
1518
|
+
v = prev = (prev + v) & 0xff;
|
|
1519
|
+
data[p] = v;
|
|
1400
1520
|
}
|
|
1401
1521
|
}
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1522
|
+
}
|
|
1523
|
+
else if (bpv === 2) {
|
|
1524
|
+
for (let y = 0, i = 0; y < height; y++) {
|
|
1525
|
+
let prev = 0;
|
|
1526
|
+
for (let x = 0, p = offset + y * width * step; x < width; x++, i += 2, p += step) {
|
|
1527
|
+
let v = (decompressed[i] << 8) | decompressed[i + 1];
|
|
1528
|
+
if (prediction)
|
|
1529
|
+
v = prev = (prev + v) & 0xffff;
|
|
1530
|
+
data[p] = v;
|
|
1411
1531
|
}
|
|
1412
1532
|
}
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1533
|
+
}
|
|
1534
|
+
else {
|
|
1535
|
+
const dst = new Uint32Array(data.buffer, data.byteOffset, data.length);
|
|
1536
|
+
if (prediction) {
|
|
1537
|
+
// bytes are delta encoded per row and stored in planar order (all 1st bytes, all 2nd bytes, ...)
|
|
1538
|
+
decodePredicted(decompressed, width * 4, height);
|
|
1539
|
+
for (let y = 0, di = offset; y < height; y++) {
|
|
1540
|
+
let a = width * 4 * y;
|
|
1541
|
+
for (let x = 0; x < width; x++, a++, di += step) {
|
|
1542
|
+
const b = a + width;
|
|
1543
|
+
const c = b + width;
|
|
1544
|
+
const d = c + width;
|
|
1545
|
+
dst[di] = ((decompressed[a] << 24) | (decompressed[b] << 16) | (decompressed[c] << 8) | decompressed[d]) >>> 0;
|
|
1426
1546
|
}
|
|
1427
1547
|
}
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1548
|
+
}
|
|
1549
|
+
else {
|
|
1550
|
+
const view = new DataView(decompressed.buffer, decompressed.byteOffset, decompressed.byteLength);
|
|
1551
|
+
for (let i = 0, j = 0, di = offset, size = width * height; i < size; i++, j += 4, di += step) {
|
|
1552
|
+
dst[di] = view.getUint32(j, false);
|
|
1433
1553
|
}
|
|
1434
1554
|
}
|
|
1435
1555
|
}
|
|
1436
|
-
finally {
|
|
1437
|
-
if (reader)
|
|
1438
|
-
recoverMemory(reader, expectedSize);
|
|
1439
|
-
}
|
|
1440
1556
|
}
|
|
1441
1557
|
// decodes single PackBits row into byte buffer, returns number of decoded bytes
|
|
1442
1558
|
function decodeRLERow(src, i, end, dst, count) {
|
|
@@ -1605,7 +1721,15 @@ function readSection(reader, round, func, skipEmpty = true, eightBytes = false)
|
|
|
1605
1721
|
let end = reader.offset + length;
|
|
1606
1722
|
if (end > reader.view.byteLength)
|
|
1607
1723
|
throw new Error('Section exceeds file size');
|
|
1608
|
-
const
|
|
1724
|
+
const parentSectionEnd = reader.sectionEnd;
|
|
1725
|
+
reader.sectionEnd = end;
|
|
1726
|
+
let result;
|
|
1727
|
+
try {
|
|
1728
|
+
result = func(() => end - reader.offset);
|
|
1729
|
+
}
|
|
1730
|
+
finally {
|
|
1731
|
+
reader.sectionEnd = parentSectionEnd;
|
|
1732
|
+
}
|
|
1609
1733
|
if (reader.offset !== end) {
|
|
1610
1734
|
if (reader.offset > end) {
|
|
1611
1735
|
warnOrThrow(reader, 'Exceeded section limits');
|