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.
@@ -70,6 +70,7 @@ __export(src_exports, {
70
70
  fillPixelData: () => fillPixelData,
71
71
  floodFillSelection: () => floodFillSelection,
72
72
  getImageDataFromClipboard: () => getImageDataFromClipboard,
73
+ getIndexedImageColorCounts: () => getIndexedImageColorCounts,
73
74
  getSupportedPixelFormats: () => getSupportedPixelFormats,
74
75
  hardLightFast: () => hardLightFast,
75
76
  hardLightPerfect: () => hardLightPerfect,
@@ -111,7 +112,10 @@ __export(src_exports, {
111
112
  pinLightFast: () => pinLightFast,
112
113
  pinLightPerfect: () => pinLightPerfect,
113
114
  pixelDataToAlphaMask: () => pixelDataToAlphaMask,
115
+ reflectPixelDataHorizontal: () => reflectPixelDataHorizontal,
116
+ reflectPixelDataVertical: () => reflectPixelDataVertical,
114
117
  resizeImageData: () => resizeImageData,
118
+ rotatePixelData: () => rotatePixelData,
115
119
  screenFast: () => screenFast,
116
120
  screenPerfect: () => screenPerfect,
117
121
  serializeImageData: () => serializeImageData,
@@ -1801,6 +1805,18 @@ function indexedImageToAverageColor(indexedImage, includeTransparent = false) {
1801
1805
  return packColor(r, g, b, a);
1802
1806
  }
1803
1807
 
1808
+ // src/IndexedImage/getIndexedImageColorCounts.ts
1809
+ function getIndexedImageColorCounts(indexedImage) {
1810
+ const data = indexedImage.data;
1811
+ const palette = indexedImage.palette;
1812
+ const frequencies = new Int32Array(palette.length);
1813
+ for (let i = 0; i < data.length; i++) {
1814
+ const colorIndex = data[i];
1815
+ frequencies[colorIndex]++;
1816
+ }
1817
+ return frequencies;
1818
+ }
1819
+
1804
1820
  // src/Input/fileInputChangeToImageData.ts
1805
1821
  async function fileInputChangeToImageData(event) {
1806
1822
  const target = event.target;
@@ -2389,6 +2405,84 @@ function invertPixelData(pixelData) {
2389
2405
  }
2390
2406
  return pixelData;
2391
2407
  }
2408
+
2409
+ // src/PixelData/reflectPixelData.ts
2410
+ function reflectPixelDataHorizontal(pixelData) {
2411
+ const width = pixelData.width;
2412
+ const height = pixelData.height;
2413
+ const data = pixelData.data32;
2414
+ const halfWidth = Math.floor(width / 2);
2415
+ for (let y = 0; y < height; y++) {
2416
+ const rowOffset = y * width;
2417
+ for (let x = 0; x < halfWidth; x++) {
2418
+ const leftIdx = rowOffset + x;
2419
+ const rightIdx = rowOffset + (width - 1 - x);
2420
+ const temp = data[leftIdx];
2421
+ data[leftIdx] = data[rightIdx];
2422
+ data[rightIdx] = temp;
2423
+ }
2424
+ }
2425
+ }
2426
+ function reflectPixelDataVertical(pixelData) {
2427
+ const width = pixelData.width;
2428
+ const height = pixelData.height;
2429
+ const data = pixelData.data32;
2430
+ const halfHeight = Math.floor(height / 2);
2431
+ for (let y = 0; y < halfHeight; y++) {
2432
+ const topRowOffset = y * width;
2433
+ const bottomRowOffset = (height - 1 - y) * width;
2434
+ for (let x = 0; x < width; x++) {
2435
+ const topIdx = topRowOffset + x;
2436
+ const bottomIdx = bottomRowOffset + x;
2437
+ const temp = data[topIdx];
2438
+ data[topIdx] = data[bottomIdx];
2439
+ data[bottomIdx] = temp;
2440
+ }
2441
+ }
2442
+ }
2443
+
2444
+ // src/PixelData/rotatePixelData.ts
2445
+ function rotatePixelData(pixelData) {
2446
+ const width = pixelData.width;
2447
+ const height = pixelData.height;
2448
+ const data = pixelData.data32;
2449
+ if (width === height) {
2450
+ rotateSquareInPlace(pixelData);
2451
+ return;
2452
+ }
2453
+ const newWidth = height;
2454
+ const newHeight = width;
2455
+ const newData = new Uint32Array(data.length);
2456
+ for (let y = 0; y < height; y++) {
2457
+ for (let x = 0; x < width; x++) {
2458
+ const oldIdx = y * width + x;
2459
+ const newX = height - 1 - y;
2460
+ const newY = x;
2461
+ const newIdx = newY * newWidth + newX;
2462
+ newData[newIdx] = data[oldIdx];
2463
+ }
2464
+ }
2465
+ pixelData.width = newWidth;
2466
+ pixelData.height = newHeight;
2467
+ pixelData.data32 = newData;
2468
+ }
2469
+ function rotateSquareInPlace(pixelData) {
2470
+ const n = pixelData.width;
2471
+ const data = pixelData.data32;
2472
+ for (let i = 0; i < n / 2; i++) {
2473
+ for (let j = i; j < n - i - 1; j++) {
2474
+ const temp = data[i * n + j];
2475
+ const top = i * n + j;
2476
+ const right = j * n + (n - 1 - i);
2477
+ const bottom = (n - 1 - i) * n + (n - 1 - j);
2478
+ const left = (n - 1 - j) * n + i;
2479
+ data[top] = data[left];
2480
+ data[left] = data[bottom];
2481
+ data[bottom] = data[right];
2482
+ data[right] = temp;
2483
+ }
2484
+ }
2485
+ }
2392
2486
  // Annotate the CommonJS export names for ESM import in node:
2393
2487
  0 && (module.exports = {
2394
2488
  BlendMode,
@@ -2441,6 +2535,7 @@ function invertPixelData(pixelData) {
2441
2535
  fillPixelData,
2442
2536
  floodFillSelection,
2443
2537
  getImageDataFromClipboard,
2538
+ getIndexedImageColorCounts,
2444
2539
  getSupportedPixelFormats,
2445
2540
  hardLightFast,
2446
2541
  hardLightPerfect,
@@ -2482,7 +2577,10 @@ function invertPixelData(pixelData) {
2482
2577
  pinLightFast,
2483
2578
  pinLightPerfect,
2484
2579
  pixelDataToAlphaMask,
2580
+ reflectPixelDataHorizontal,
2581
+ reflectPixelDataVertical,
2485
2582
  resizeImageData,
2583
+ rotatePixelData,
2486
2584
  screenFast,
2487
2585
  screenPerfect,
2488
2586
  serializeImageData,