pixel-data-js 0.10.0 → 0.10.1

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.
@@ -1760,10 +1760,12 @@ function writeImageDataPixels(imageData, data, _x, _y, _w, _h) {
1760
1760
  }
1761
1761
 
1762
1762
  // src/IndexedImage/IndexedImage.ts
1763
- function makeIndexedImage(imageData) {
1764
- const width = imageData.width;
1765
- const height = imageData.height;
1766
- const rawData = new Uint32Array(imageData.data.buffer);
1763
+ function makeIndexedImage(imageOrData, width, height) {
1764
+ const isImageData = "width" in imageOrData;
1765
+ const actualWidth = isImageData ? imageOrData.width : width;
1766
+ const actualHeight = isImageData ? imageOrData.height : height;
1767
+ const buffer = isImageData ? imageOrData.data.buffer : imageOrData.buffer;
1768
+ const rawData = new Uint32Array(buffer);
1767
1769
  const indexedData = new Int32Array(rawData.length);
1768
1770
  const colorMap = /* @__PURE__ */ new Map();
1769
1771
  const transparentColor = 0;
@@ -1773,7 +1775,7 @@ function makeIndexedImage(imageData) {
1773
1775
  const pixel = rawData[i];
1774
1776
  const alpha = pixel >>> 24 & 255;
1775
1777
  const isTransparent = alpha === 0;
1776
- const colorKey = isTransparent ? transparentColor : pixel;
1778
+ const colorKey = isTransparent ? transparentColor : pixel >>> 0;
1777
1779
  let id = colorMap.get(colorKey);
1778
1780
  if (id === void 0) {
1779
1781
  id = colorMap.size;
@@ -1781,10 +1783,10 @@ function makeIndexedImage(imageData) {
1781
1783
  }
1782
1784
  indexedData[i] = id;
1783
1785
  }
1784
- const palette = new Uint32Array(colorMap.keys());
1786
+ const palette = Uint32Array.from(colorMap.keys());
1785
1787
  return {
1786
- width,
1787
- height,
1788
+ width: actualWidth,
1789
+ height: actualHeight,
1788
1790
  data: indexedData,
1789
1791
  transparentPalletIndex,
1790
1792
  palette