pixel-data-js 0.8.0 → 0.9.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.
@@ -1734,24 +1734,22 @@ function makeIndexedImage(imageData) {
1734
1734
  const rawData = new Uint32Array(imageData.data.buffer);
1735
1735
  const indexedData = new Int32Array(rawData.length);
1736
1736
  const colorMap = /* @__PURE__ */ new Map();
1737
- const tempPalette = [];
1738
1737
  const transparentColor = 0;
1739
1738
  const transparentPalletIndex = 0;
1740
1739
  colorMap.set(transparentColor, transparentPalletIndex);
1741
- tempPalette.push(transparentColor);
1742
1740
  for (let i = 0; i < rawData.length; i++) {
1743
1741
  const pixel = rawData[i];
1744
- const isTransparent = pixel >>> 24 === 0;
1742
+ const alpha = pixel >>> 24 & 255;
1743
+ const isTransparent = alpha === 0;
1745
1744
  const colorKey = isTransparent ? transparentColor : pixel;
1746
1745
  let id = colorMap.get(colorKey);
1747
1746
  if (id === void 0) {
1748
1747
  id = colorMap.size;
1749
- tempPalette.push(colorKey);
1750
1748
  colorMap.set(colorKey, id);
1751
1749
  }
1752
1750
  indexedData[i] = id;
1753
1751
  }
1754
- const palette = new Int32Array(tempPalette);
1752
+ const palette = new Int32Array(colorMap.keys());
1755
1753
  return {
1756
1754
  width,
1757
1755
  height,
@@ -1764,7 +1762,7 @@ function makeIndexedImage(imageData) {
1764
1762
  // src/IndexedImage/indexedImageToAverageColor.ts
1765
1763
  function indexedImageToAverageColor(indexedImage, includeTransparent = false) {
1766
1764
  const { data, palette, transparentPalletIndex } = indexedImage;
1767
- const counts = new Uint32Array(palette.length / 4);
1765
+ const counts = new Uint32Array(palette.length);
1768
1766
  for (let i = 0; i < data.length; i++) {
1769
1767
  const id = data[i];
1770
1768
  counts[id]++;
@@ -1782,11 +1780,11 @@ function indexedImageToAverageColor(indexedImage, includeTransparent = false) {
1782
1780
  if (!includeTransparent && id === transparentPalletIndex) {
1783
1781
  continue;
1784
1782
  }
1785
- const pIdx = id * 4;
1786
- const r2 = palette[pIdx];
1787
- const g2 = palette[pIdx + 1];
1788
- const b2 = palette[pIdx + 2];
1789
- const a2 = palette[pIdx + 3];
1783
+ const color = palette[id] >>> 0;
1784
+ const r2 = color & 255;
1785
+ const g2 = color >> 8 & 255;
1786
+ const b2 = color >> 16 & 255;
1787
+ const a2 = color >> 24 & 255;
1790
1788
  rSum += r2 * weight;
1791
1789
  gSum += g2 * weight;
1792
1790
  bSum += b2 * weight;