pixel-data-js 0.9.0 → 0.9.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
@@ -1662,6 +1662,18 @@ function indexedImageToAverageColor(indexedImage, includeTransparent = false) {
1662
1662
  return packColor(r, g, b, a);
1663
1663
  }
1664
1664
 
1665
+ // src/IndexedImage/getIndexedImageColorCounts.ts
1666
+ function getIndexedImageColorCounts(indexedImage) {
1667
+ const data = indexedImage.data;
1668
+ const palette = indexedImage.palette;
1669
+ const frequencies = new Int32Array(palette.length);
1670
+ for (let i = 0; i < data.length; i++) {
1671
+ const colorIndex = data[i];
1672
+ frequencies[colorIndex]++;
1673
+ }
1674
+ return frequencies;
1675
+ }
1676
+
1665
1677
  // src/Input/fileInputChangeToImageData.ts
1666
1678
  async function fileInputChangeToImageData(event) {
1667
1679
  const target = event.target;
@@ -2250,6 +2262,84 @@ function invertPixelData(pixelData) {
2250
2262
  }
2251
2263
  return pixelData;
2252
2264
  }
2265
+
2266
+ // src/PixelData/reflectPixelData.ts
2267
+ function reflectPixelDataHorizontal(pixelData) {
2268
+ const width = pixelData.width;
2269
+ const height = pixelData.height;
2270
+ const data = pixelData.data32;
2271
+ const halfWidth = Math.floor(width / 2);
2272
+ for (let y = 0; y < height; y++) {
2273
+ const rowOffset = y * width;
2274
+ for (let x = 0; x < halfWidth; x++) {
2275
+ const leftIdx = rowOffset + x;
2276
+ const rightIdx = rowOffset + (width - 1 - x);
2277
+ const temp = data[leftIdx];
2278
+ data[leftIdx] = data[rightIdx];
2279
+ data[rightIdx] = temp;
2280
+ }
2281
+ }
2282
+ }
2283
+ function reflectPixelDataVertical(pixelData) {
2284
+ const width = pixelData.width;
2285
+ const height = pixelData.height;
2286
+ const data = pixelData.data32;
2287
+ const halfHeight = Math.floor(height / 2);
2288
+ for (let y = 0; y < halfHeight; y++) {
2289
+ const topRowOffset = y * width;
2290
+ const bottomRowOffset = (height - 1 - y) * width;
2291
+ for (let x = 0; x < width; x++) {
2292
+ const topIdx = topRowOffset + x;
2293
+ const bottomIdx = bottomRowOffset + x;
2294
+ const temp = data[topIdx];
2295
+ data[topIdx] = data[bottomIdx];
2296
+ data[bottomIdx] = temp;
2297
+ }
2298
+ }
2299
+ }
2300
+
2301
+ // src/PixelData/rotatePixelData.ts
2302
+ function rotatePixelData(pixelData) {
2303
+ const width = pixelData.width;
2304
+ const height = pixelData.height;
2305
+ const data = pixelData.data32;
2306
+ if (width === height) {
2307
+ rotateSquareInPlace(pixelData);
2308
+ return;
2309
+ }
2310
+ const newWidth = height;
2311
+ const newHeight = width;
2312
+ const newData = new Uint32Array(data.length);
2313
+ for (let y = 0; y < height; y++) {
2314
+ for (let x = 0; x < width; x++) {
2315
+ const oldIdx = y * width + x;
2316
+ const newX = height - 1 - y;
2317
+ const newY = x;
2318
+ const newIdx = newY * newWidth + newX;
2319
+ newData[newIdx] = data[oldIdx];
2320
+ }
2321
+ }
2322
+ pixelData.width = newWidth;
2323
+ pixelData.height = newHeight;
2324
+ pixelData.data32 = newData;
2325
+ }
2326
+ function rotateSquareInPlace(pixelData) {
2327
+ const n = pixelData.width;
2328
+ const data = pixelData.data32;
2329
+ for (let i = 0; i < n / 2; i++) {
2330
+ for (let j = i; j < n - i - 1; j++) {
2331
+ const temp = data[i * n + j];
2332
+ const top = i * n + j;
2333
+ const right = j * n + (n - 1 - i);
2334
+ const bottom = (n - 1 - i) * n + (n - 1 - j);
2335
+ const left = (n - 1 - j) * n + i;
2336
+ data[top] = data[left];
2337
+ data[left] = data[bottom];
2338
+ data[bottom] = data[right];
2339
+ data[right] = temp;
2340
+ }
2341
+ }
2342
+ }
2253
2343
  export {
2254
2344
  BlendMode,
2255
2345
  FAST_BLENDER_REGISTRY,
@@ -2301,6 +2391,7 @@ export {
2301
2391
  fillPixelData,
2302
2392
  floodFillSelection,
2303
2393
  getImageDataFromClipboard,
2394
+ getIndexedImageColorCounts,
2304
2395
  getSupportedPixelFormats,
2305
2396
  hardLightFast,
2306
2397
  hardLightPerfect,
@@ -2342,7 +2433,10 @@ export {
2342
2433
  pinLightFast,
2343
2434
  pinLightPerfect,
2344
2435
  pixelDataToAlphaMask,
2436
+ reflectPixelDataHorizontal,
2437
+ reflectPixelDataVertical,
2345
2438
  resizeImageData,
2439
+ rotatePixelData,
2346
2440
  screenFast,
2347
2441
  screenPerfect,
2348
2442
  serializeImageData,