pixel-data-js 0.5.1 → 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.cjs +49 -0
- package/dist/index.dev.cjs.map +1 -1
- package/dist/index.dev.js +48 -0
- package/dist/index.dev.js.map +1 -1
- package/dist/index.prod.cjs +49 -0
- package/dist/index.prod.cjs.map +1 -1
- package/dist/index.prod.d.ts +36 -1
- package/dist/index.prod.js +48 -0
- package/dist/index.prod.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +2 -0
package/dist/index.dev.cjs
CHANGED
|
@@ -74,6 +74,7 @@ __export(src_exports, {
|
|
|
74
74
|
linearBurnColor32: () => linearBurnColor32,
|
|
75
75
|
linearDodgeColor32: () => linearDodgeColor32,
|
|
76
76
|
linearLightColor32: () => linearLightColor32,
|
|
77
|
+
makeIndexedImage: () => makeIndexedImage,
|
|
77
78
|
makePixelCanvas: () => makePixelCanvas,
|
|
78
79
|
makeReusableCanvas: () => makeReusableCanvas,
|
|
79
80
|
mergeMasks: () => mergeMasks,
|
|
@@ -1182,6 +1183,53 @@ function writeImageDataPixels(imageData, data, _x, _y, _w, _h) {
|
|
|
1182
1183
|
}
|
|
1183
1184
|
}
|
|
1184
1185
|
|
|
1186
|
+
// src/IndexedImage/IndexedImage.ts
|
|
1187
|
+
function makeIndexedImage(imageData) {
|
|
1188
|
+
const width = imageData.width;
|
|
1189
|
+
const height = imageData.height;
|
|
1190
|
+
const rawData = imageData.data;
|
|
1191
|
+
const indexedData = new Int32Array(rawData.length / 4);
|
|
1192
|
+
const colorMap = /* @__PURE__ */ new Map();
|
|
1193
|
+
const tempPalette = [];
|
|
1194
|
+
const transparentKey = "0,0,0,0";
|
|
1195
|
+
const transparentPalletIndex = 0;
|
|
1196
|
+
colorMap.set(transparentKey, transparentPalletIndex);
|
|
1197
|
+
tempPalette.push(0);
|
|
1198
|
+
tempPalette.push(0);
|
|
1199
|
+
tempPalette.push(0);
|
|
1200
|
+
tempPalette.push(0);
|
|
1201
|
+
for (let i = 0; i < indexedData.length; i++) {
|
|
1202
|
+
const r = rawData[i * 4];
|
|
1203
|
+
const g = rawData[i * 4 + 1];
|
|
1204
|
+
const b = rawData[i * 4 + 2];
|
|
1205
|
+
const a = rawData[i * 4 + 3];
|
|
1206
|
+
let key;
|
|
1207
|
+
if (a === 0) {
|
|
1208
|
+
key = transparentKey;
|
|
1209
|
+
} else {
|
|
1210
|
+
key = `${r},${g},${b},${a}`;
|
|
1211
|
+
}
|
|
1212
|
+
let id = colorMap.get(key);
|
|
1213
|
+
if (id === void 0) {
|
|
1214
|
+
id = colorMap.size;
|
|
1215
|
+
tempPalette.push(r);
|
|
1216
|
+
tempPalette.push(g);
|
|
1217
|
+
tempPalette.push(b);
|
|
1218
|
+
tempPalette.push(a);
|
|
1219
|
+
colorMap.set(key, id);
|
|
1220
|
+
}
|
|
1221
|
+
indexedData[i] = id;
|
|
1222
|
+
}
|
|
1223
|
+
const palette = new Uint8Array(tempPalette);
|
|
1224
|
+
return {
|
|
1225
|
+
width,
|
|
1226
|
+
height,
|
|
1227
|
+
data: indexedData,
|
|
1228
|
+
transparentPalletIndex,
|
|
1229
|
+
palette
|
|
1230
|
+
};
|
|
1231
|
+
}
|
|
1232
|
+
|
|
1185
1233
|
// src/Input/fileInputChangeToImageData.ts
|
|
1186
1234
|
async function fileInputChangeToImageData(event) {
|
|
1187
1235
|
const target = event.target;
|
|
@@ -1816,6 +1864,7 @@ function invertPixelData(pixelData) {
|
|
|
1816
1864
|
linearBurnColor32,
|
|
1817
1865
|
linearDodgeColor32,
|
|
1818
1866
|
linearLightColor32,
|
|
1867
|
+
makeIndexedImage,
|
|
1819
1868
|
makePixelCanvas,
|
|
1820
1869
|
makeReusableCanvas,
|
|
1821
1870
|
mergeMasks,
|