byte-codec 1.5.7 → 1.5.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -453,15 +453,19 @@ function channelsForColorType(colorType) {
453
453
  function filterBpp(bitDepth, channels) {
454
454
  return Math.max(1, Math.ceil(bitDepth * channels / 8));
455
455
  }
456
- function unpackRow(rowBytes, width, channels, bitDepth) {
457
- const sampleCount = width * channels;
458
- if (bitDepth === 16) return Array.from({ length: sampleCount }, (_, i) => rowBytes[i * 2]);
456
+ function unpackRow(rowBytes, samples, bitDepth) {
457
+ if (bitDepth === 16) {
458
+ samples.forEach((_sample, i) => {
459
+ samples[i] = rowBytes[i * 2];
460
+ });
461
+ return;
462
+ }
459
463
  const mask = (1 << bitDepth) - 1;
460
- return Array.from({ length: sampleCount }, (_, i) => {
464
+ samples.forEach((_sample, i) => {
461
465
  const bitOffset = i * bitDepth;
462
466
  const byteIndex = bitOffset >> 3;
463
467
  const shift = 8 - bitDepth - (bitOffset & 7);
464
- return rowBytes[byteIndex] >> shift & mask;
468
+ samples[i] = rowBytes[byteIndex] >> shift & mask;
465
469
  });
466
470
  }
467
471
  function readTrnsGrayValue(trns) {
@@ -507,10 +511,12 @@ function buildRawImage(ihdr, channels, bytesPerRow, unfiltered, palette, trns) {
507
511
  const alpha = colorType === 4 || colorType === 6 || trns !== void 0 ? new Uint8Array(width * height).fill(255) : void 0;
508
512
  const trnsGray = colorType === 0 && trns !== void 0 ? readTrnsGrayValue(trns) : void 0;
509
513
  const trnsRgb = colorType === 2 && trns !== void 0 ? readTrnsRgbKey(trns) : void 0;
510
- for (const y of Array.from({ length: height }, (_, i) => i)) {
514
+ const samples = new Uint8Array(width * channels);
515
+ const columns = new Uint32Array(width);
516
+ Array.from({ length: height }).forEach((_row, y) => {
511
517
  const rowStart = y * bytesPerRow;
512
- const samples = unpackRow(unfiltered.subarray(rowStart, rowStart + bytesPerRow), width, channels, bitDepth);
513
- for (const x of Array.from({ length: width }, (_, i) => i)) {
518
+ unpackRow(unfiltered.subarray(rowStart, rowStart + bytesPerRow), samples, bitDepth);
519
+ columns.forEach((_column, x) => {
514
520
  const pixelBase = x * channels;
515
521
  const outBase = (y * width + x) * outChannels;
516
522
  const alphaIndex = y * width + x;
@@ -546,8 +552,8 @@ function buildRawImage(ihdr, channels, bytesPerRow, unfiltered, palette, trns) {
546
552
  data[outBase + 2] = samples[pixelBase + 2];
547
553
  if (alpha !== void 0) alpha[alphaIndex] = samples[pixelBase + 3];
548
554
  }
549
- }
550
- }
555
+ });
556
+ });
551
557
  return alpha === void 0 ? {
552
558
  width,
553
559
  height,
package/dist/index.js CHANGED
@@ -452,15 +452,19 @@ function channelsForColorType(colorType) {
452
452
  function filterBpp(bitDepth, channels) {
453
453
  return Math.max(1, Math.ceil(bitDepth * channels / 8));
454
454
  }
455
- function unpackRow(rowBytes, width, channels, bitDepth) {
456
- const sampleCount = width * channels;
457
- if (bitDepth === 16) return Array.from({ length: sampleCount }, (_, i) => rowBytes[i * 2]);
455
+ function unpackRow(rowBytes, samples, bitDepth) {
456
+ if (bitDepth === 16) {
457
+ samples.forEach((_sample, i) => {
458
+ samples[i] = rowBytes[i * 2];
459
+ });
460
+ return;
461
+ }
458
462
  const mask = (1 << bitDepth) - 1;
459
- return Array.from({ length: sampleCount }, (_, i) => {
463
+ samples.forEach((_sample, i) => {
460
464
  const bitOffset = i * bitDepth;
461
465
  const byteIndex = bitOffset >> 3;
462
466
  const shift = 8 - bitDepth - (bitOffset & 7);
463
- return rowBytes[byteIndex] >> shift & mask;
467
+ samples[i] = rowBytes[byteIndex] >> shift & mask;
464
468
  });
465
469
  }
466
470
  function readTrnsGrayValue(trns) {
@@ -506,10 +510,12 @@ function buildRawImage(ihdr, channels, bytesPerRow, unfiltered, palette, trns) {
506
510
  const alpha = colorType === 4 || colorType === 6 || trns !== void 0 ? new Uint8Array(width * height).fill(255) : void 0;
507
511
  const trnsGray = colorType === 0 && trns !== void 0 ? readTrnsGrayValue(trns) : void 0;
508
512
  const trnsRgb = colorType === 2 && trns !== void 0 ? readTrnsRgbKey(trns) : void 0;
509
- for (const y of Array.from({ length: height }, (_, i) => i)) {
513
+ const samples = new Uint8Array(width * channels);
514
+ const columns = new Uint32Array(width);
515
+ Array.from({ length: height }).forEach((_row, y) => {
510
516
  const rowStart = y * bytesPerRow;
511
- const samples = unpackRow(unfiltered.subarray(rowStart, rowStart + bytesPerRow), width, channels, bitDepth);
512
- for (const x of Array.from({ length: width }, (_, i) => i)) {
517
+ unpackRow(unfiltered.subarray(rowStart, rowStart + bytesPerRow), samples, bitDepth);
518
+ columns.forEach((_column, x) => {
513
519
  const pixelBase = x * channels;
514
520
  const outBase = (y * width + x) * outChannels;
515
521
  const alphaIndex = y * width + x;
@@ -545,8 +551,8 @@ function buildRawImage(ihdr, channels, bytesPerRow, unfiltered, palette, trns) {
545
551
  data[outBase + 2] = samples[pixelBase + 2];
546
552
  if (alpha !== void 0) alpha[alphaIndex] = samples[pixelBase + 3];
547
553
  }
548
- }
549
- }
554
+ });
555
+ });
550
556
  return alpha === void 0 ? {
551
557
  width,
552
558
  height,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "byte-codec",
3
- "version": "1.5.7",
3
+ "version": "1.5.8",
4
4
  "description": "Generic byte-level primitives (ByteWriter, ByteReader, CRC-32, deflate/inflate) and PNG/JPEG image encoding/decoding with zero PDF knowledge — the shared utility package for the documents.js family.",
5
5
  "type": "module",
6
6
  "repository": {