pixel-data-js 0.5.0 → 0.5.2

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.dev.js CHANGED
@@ -1075,6 +1075,53 @@ function writeImageDataPixels(imageData, data, _x, _y, _w, _h) {
1075
1075
  }
1076
1076
  }
1077
1077
 
1078
+ // src/IndexedImage/IndexedImage.ts
1079
+ function makeIndexedImage(imageData) {
1080
+ const width = imageData.width;
1081
+ const height = imageData.height;
1082
+ const rawData = imageData.data;
1083
+ const indexedData = new Int32Array(rawData.length / 4);
1084
+ const colorMap = /* @__PURE__ */ new Map();
1085
+ const tempPalette = [];
1086
+ const transparentKey = "0,0,0,0";
1087
+ const transparentPalletIndex = 0;
1088
+ colorMap.set(transparentKey, transparentPalletIndex);
1089
+ tempPalette.push(0);
1090
+ tempPalette.push(0);
1091
+ tempPalette.push(0);
1092
+ tempPalette.push(0);
1093
+ for (let i = 0; i < indexedData.length; i++) {
1094
+ const r = rawData[i * 4];
1095
+ const g = rawData[i * 4 + 1];
1096
+ const b = rawData[i * 4 + 2];
1097
+ const a = rawData[i * 4 + 3];
1098
+ let key;
1099
+ if (a === 0) {
1100
+ key = transparentKey;
1101
+ } else {
1102
+ key = `${r},${g},${b},${a}`;
1103
+ }
1104
+ let id = colorMap.get(key);
1105
+ if (id === void 0) {
1106
+ id = colorMap.size;
1107
+ tempPalette.push(r);
1108
+ tempPalette.push(g);
1109
+ tempPalette.push(b);
1110
+ tempPalette.push(a);
1111
+ colorMap.set(key, id);
1112
+ }
1113
+ indexedData[i] = id;
1114
+ }
1115
+ const palette = new Uint8Array(tempPalette);
1116
+ return {
1117
+ width,
1118
+ height,
1119
+ data: indexedData,
1120
+ transparentPalletIndex,
1121
+ palette
1122
+ };
1123
+ }
1124
+
1078
1125
  // src/Input/fileInputChangeToImageData.ts
1079
1126
  async function fileInputChangeToImageData(event) {
1080
1127
  const target = event.target;
@@ -1708,6 +1755,7 @@ export {
1708
1755
  linearBurnColor32,
1709
1756
  linearDodgeColor32,
1710
1757
  linearLightColor32,
1758
+ makeIndexedImage,
1711
1759
  makePixelCanvas,
1712
1760
  makeReusableCanvas,
1713
1761
  mergeMasks,