pixel-data-js 0.9.1 → 0.10.0
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 +94 -1
- package/dist/index.dev.cjs.map +1 -1
- package/dist/index.dev.js +90 -1
- package/dist/index.dev.js.map +1 -1
- package/dist/index.prod.cjs +94 -1
- package/dist/index.prod.cjs.map +1 -1
- package/dist/index.prod.d.ts +28 -2
- package/dist/index.prod.js +90 -1
- package/dist/index.prod.js.map +1 -1
- package/package.json +1 -1
- package/src/ImageData/resampleImageData.ts +35 -0
- package/src/IndexedImage/IndexedImage.ts +2 -2
- package/src/IndexedImage/resampleIndexedImage.ts +36 -0
- package/src/PixelData/resamplePixelData.ts +29 -0
- package/src/index.ts +4 -0
package/dist/index.dev.cjs
CHANGED
|
@@ -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,
|
|
@@ -113,6 +114,9 @@ __export(src_exports, {
|
|
|
113
114
|
pixelDataToAlphaMask: () => pixelDataToAlphaMask,
|
|
114
115
|
reflectPixelDataHorizontal: () => reflectPixelDataHorizontal,
|
|
115
116
|
reflectPixelDataVertical: () => reflectPixelDataVertical,
|
|
117
|
+
resampleImageData: () => resampleImageData,
|
|
118
|
+
resampleIndexedImage: () => resampleIndexedImage,
|
|
119
|
+
resamplePixelData: () => resamplePixelData,
|
|
116
120
|
resizeImageData: () => resizeImageData,
|
|
117
121
|
rotatePixelData: () => rotatePixelData,
|
|
118
122
|
screenFast: () => screenFast,
|
|
@@ -1637,6 +1641,31 @@ function invertImageData(imageData) {
|
|
|
1637
1641
|
return imageData;
|
|
1638
1642
|
}
|
|
1639
1643
|
|
|
1644
|
+
// src/ImageData/resampleImageData.ts
|
|
1645
|
+
function resampleImageData(source, factor) {
|
|
1646
|
+
const srcW = source.width;
|
|
1647
|
+
const srcH = source.height;
|
|
1648
|
+
const dstW = Math.max(1, srcW * factor | 0);
|
|
1649
|
+
const dstH = Math.max(1, srcH * factor | 0);
|
|
1650
|
+
const srcData = source.data;
|
|
1651
|
+
const dstData = new Uint8ClampedArray(dstW * dstH * 4);
|
|
1652
|
+
for (let y = 0; y < dstH; y++) {
|
|
1653
|
+
const srcY = y / factor | 0;
|
|
1654
|
+
const srcRowOffset = srcY * srcW * 4;
|
|
1655
|
+
const dstRowOffset = y * dstW * 4;
|
|
1656
|
+
for (let x = 0; x < dstW; x++) {
|
|
1657
|
+
const srcX = x / factor | 0;
|
|
1658
|
+
const srcIdx = srcRowOffset + srcX * 4;
|
|
1659
|
+
const dstIdx = dstRowOffset + x * 4;
|
|
1660
|
+
dstData[dstIdx] = srcData[srcIdx];
|
|
1661
|
+
dstData[dstIdx + 1] = srcData[srcIdx + 1];
|
|
1662
|
+
dstData[dstIdx + 2] = srcData[srcIdx + 2];
|
|
1663
|
+
dstData[dstIdx + 3] = srcData[srcIdx + 3];
|
|
1664
|
+
}
|
|
1665
|
+
}
|
|
1666
|
+
return new ImageData(dstData, dstW, dstH);
|
|
1667
|
+
}
|
|
1668
|
+
|
|
1640
1669
|
// src/ImageData/resizeImageData.ts
|
|
1641
1670
|
function resizeImageData(current, newWidth, newHeight, offsetX = 0, offsetY = 0) {
|
|
1642
1671
|
const result = new ImageData(newWidth, newHeight);
|
|
@@ -1752,7 +1781,7 @@ function makeIndexedImage(imageData) {
|
|
|
1752
1781
|
}
|
|
1753
1782
|
indexedData[i] = id;
|
|
1754
1783
|
}
|
|
1755
|
-
const palette = new
|
|
1784
|
+
const palette = new Uint32Array(colorMap.keys());
|
|
1756
1785
|
return {
|
|
1757
1786
|
width,
|
|
1758
1787
|
height,
|
|
@@ -1762,6 +1791,18 @@ function makeIndexedImage(imageData) {
|
|
|
1762
1791
|
};
|
|
1763
1792
|
}
|
|
1764
1793
|
|
|
1794
|
+
// src/IndexedImage/getIndexedImageColorCounts.ts
|
|
1795
|
+
function getIndexedImageColorCounts(indexedImage) {
|
|
1796
|
+
const data = indexedImage.data;
|
|
1797
|
+
const palette = indexedImage.palette;
|
|
1798
|
+
const frequencies = new Int32Array(palette.length);
|
|
1799
|
+
for (let i = 0; i < data.length; i++) {
|
|
1800
|
+
const colorIndex = data[i];
|
|
1801
|
+
frequencies[colorIndex]++;
|
|
1802
|
+
}
|
|
1803
|
+
return frequencies;
|
|
1804
|
+
}
|
|
1805
|
+
|
|
1765
1806
|
// src/IndexedImage/indexedImageToAverageColor.ts
|
|
1766
1807
|
function indexedImageToAverageColor(indexedImage, includeTransparent = false) {
|
|
1767
1808
|
const { data, palette, transparentPalletIndex } = indexedImage;
|
|
@@ -1804,6 +1845,32 @@ function indexedImageToAverageColor(indexedImage, includeTransparent = false) {
|
|
|
1804
1845
|
return packColor(r, g, b, a);
|
|
1805
1846
|
}
|
|
1806
1847
|
|
|
1848
|
+
// src/IndexedImage/resampleIndexedImage.ts
|
|
1849
|
+
function resampleIndexedImage(source, factor) {
|
|
1850
|
+
const srcW = source.width;
|
|
1851
|
+
const srcH = source.height;
|
|
1852
|
+
const dstW = srcW * factor;
|
|
1853
|
+
const dstH = srcH * factor;
|
|
1854
|
+
const srcData = source.data;
|
|
1855
|
+
const dstData = new Int32Array(dstW * dstH);
|
|
1856
|
+
for (let y = 0; y < dstH; y++) {
|
|
1857
|
+
const srcY = y / factor | 0;
|
|
1858
|
+
const rowOffset = srcY * srcW;
|
|
1859
|
+
const dstOffset = y * dstW;
|
|
1860
|
+
for (let x = 0; x < dstW; x++) {
|
|
1861
|
+
const srcX = x / factor | 0;
|
|
1862
|
+
dstData[dstOffset + x] = srcData[rowOffset + srcX];
|
|
1863
|
+
}
|
|
1864
|
+
}
|
|
1865
|
+
return {
|
|
1866
|
+
width: dstW,
|
|
1867
|
+
height: dstH,
|
|
1868
|
+
data: dstData,
|
|
1869
|
+
palette: source.palette,
|
|
1870
|
+
transparentPalletIndex: source.transparentPalletIndex
|
|
1871
|
+
};
|
|
1872
|
+
}
|
|
1873
|
+
|
|
1807
1874
|
// src/Input/fileInputChangeToImageData.ts
|
|
1808
1875
|
async function fileInputChangeToImageData(event) {
|
|
1809
1876
|
const target = event.target;
|
|
@@ -2428,6 +2495,28 @@ function reflectPixelDataVertical(pixelData) {
|
|
|
2428
2495
|
}
|
|
2429
2496
|
}
|
|
2430
2497
|
|
|
2498
|
+
// src/PixelData/resamplePixelData.ts
|
|
2499
|
+
function resamplePixelData(pixelData, factor) {
|
|
2500
|
+
const dstW = Math.max(1, pixelData.width * factor | 0);
|
|
2501
|
+
const dstH = Math.max(1, pixelData.height * factor | 0);
|
|
2502
|
+
const dstBuffer = new Uint8ClampedArray(dstW * dstH * 4);
|
|
2503
|
+
const dstData32 = new Uint32Array(dstBuffer.buffer);
|
|
2504
|
+
for (let y = 0; y < dstH; y++) {
|
|
2505
|
+
const srcY = y / factor | 0;
|
|
2506
|
+
const srcRowOffset = srcY * pixelData.width;
|
|
2507
|
+
const dstRowOffset = y * dstW;
|
|
2508
|
+
for (let x = 0; x < dstW; x++) {
|
|
2509
|
+
const srcX = x / factor | 0;
|
|
2510
|
+
dstData32[dstRowOffset + x] = pixelData.data32[srcRowOffset + srcX];
|
|
2511
|
+
}
|
|
2512
|
+
}
|
|
2513
|
+
return new PixelData({
|
|
2514
|
+
data: dstBuffer,
|
|
2515
|
+
width: dstW,
|
|
2516
|
+
height: dstH
|
|
2517
|
+
});
|
|
2518
|
+
}
|
|
2519
|
+
|
|
2431
2520
|
// src/PixelData/rotatePixelData.ts
|
|
2432
2521
|
function rotatePixelData(pixelData) {
|
|
2433
2522
|
const width = pixelData.width;
|
|
@@ -2522,6 +2611,7 @@ function rotateSquareInPlace(pixelData) {
|
|
|
2522
2611
|
fillPixelData,
|
|
2523
2612
|
floodFillSelection,
|
|
2524
2613
|
getImageDataFromClipboard,
|
|
2614
|
+
getIndexedImageColorCounts,
|
|
2525
2615
|
getSupportedPixelFormats,
|
|
2526
2616
|
hardLightFast,
|
|
2527
2617
|
hardLightPerfect,
|
|
@@ -2565,6 +2655,9 @@ function rotateSquareInPlace(pixelData) {
|
|
|
2565
2655
|
pixelDataToAlphaMask,
|
|
2566
2656
|
reflectPixelDataHorizontal,
|
|
2567
2657
|
reflectPixelDataVertical,
|
|
2658
|
+
resampleImageData,
|
|
2659
|
+
resampleIndexedImage,
|
|
2660
|
+
resamplePixelData,
|
|
2568
2661
|
resizeImageData,
|
|
2569
2662
|
rotatePixelData,
|
|
2570
2663
|
screenFast,
|