pixel-data-js 0.13.0 → 0.14.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 +49 -28
- package/dist/index.dev.cjs.map +1 -1
- package/dist/index.dev.js +48 -28
- package/dist/index.dev.js.map +1 -1
- package/dist/index.prod.cjs +49 -28
- package/dist/index.prod.cjs.map +1 -1
- package/dist/index.prod.d.ts +17 -8
- package/dist/index.prod.js +48 -28
- package/dist/index.prod.js.map +1 -1
- package/package.json +2 -1
- package/src/ImageData/imageDataToUInt32Array.ts +13 -0
- package/src/ImageData/resizeImageData.ts +4 -2
- package/src/PixelData/PixelData.ts +36 -23
- package/src/PixelData/resamplePixelData.ts +3 -3
- package/src/PixelData/rotatePixelData.ts +13 -7
- package/src/index.ts +1 -0
package/dist/index.dev.cjs
CHANGED
|
@@ -80,6 +80,7 @@ __export(src_exports, {
|
|
|
80
80
|
imageDataToAlphaMask: () => imageDataToAlphaMask,
|
|
81
81
|
imageDataToDataUrl: () => imageDataToDataUrl,
|
|
82
82
|
imageDataToImgBlob: () => imageDataToImgBlob,
|
|
83
|
+
imageDataToUInt32Array: () => imageDataToUInt32Array,
|
|
83
84
|
imgBlobToImageData: () => imgBlobToImageData,
|
|
84
85
|
indexedImageToAverageColor: () => indexedImageToAverageColor,
|
|
85
86
|
indexedImageToImageData: () => indexedImageToImageData,
|
|
@@ -1650,6 +1651,16 @@ function imageDataToDataUrl(imageData) {
|
|
|
1650
1651
|
}
|
|
1651
1652
|
imageDataToDataUrl.reset = get.reset;
|
|
1652
1653
|
|
|
1654
|
+
// src/ImageData/imageDataToUInt32Array.ts
|
|
1655
|
+
function imageDataToUInt32Array(imageData) {
|
|
1656
|
+
return new Uint32Array(
|
|
1657
|
+
imageData.data.buffer,
|
|
1658
|
+
imageData.data.byteOffset,
|
|
1659
|
+
// Shift right by 2 is a fast bitwise division by 4.
|
|
1660
|
+
imageData.data.byteLength >> 2
|
|
1661
|
+
);
|
|
1662
|
+
}
|
|
1663
|
+
|
|
1653
1664
|
// src/ImageData/invertImageData.ts
|
|
1654
1665
|
function invertImageData(imageData) {
|
|
1655
1666
|
const data = imageData.data;
|
|
@@ -2185,28 +2196,34 @@ function mergeMasks(dst, dstWidth, src, opts) {
|
|
|
2185
2196
|
|
|
2186
2197
|
// src/PixelData/PixelData.ts
|
|
2187
2198
|
var PixelData = class _PixelData {
|
|
2199
|
+
data32;
|
|
2200
|
+
imageData;
|
|
2201
|
+
get width() {
|
|
2202
|
+
return this.imageData.width;
|
|
2203
|
+
}
|
|
2204
|
+
get height() {
|
|
2205
|
+
return this.imageData.height;
|
|
2206
|
+
}
|
|
2188
2207
|
constructor(imageData) {
|
|
2208
|
+
this.data32 = imageDataToUInt32Array(imageData);
|
|
2189
2209
|
this.imageData = imageData;
|
|
2190
|
-
this.width = imageData.width;
|
|
2191
|
-
this.height = imageData.height;
|
|
2192
|
-
this.data32 = new Uint32Array(
|
|
2193
|
-
imageData.data.buffer,
|
|
2194
|
-
imageData.data.byteOffset,
|
|
2195
|
-
// Shift right by 2 is a fast bitwise division by 4.
|
|
2196
|
-
imageData.data.byteLength >> 2
|
|
2197
|
-
);
|
|
2198
2210
|
}
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2211
|
+
set(imageData) {
|
|
2212
|
+
this.imageData = imageData;
|
|
2213
|
+
this.data32 = imageDataToUInt32Array(imageData);
|
|
2214
|
+
}
|
|
2215
|
+
/**
|
|
2216
|
+
* Creates a deep copy of the PixelData using the environment's ImageData constructor.
|
|
2217
|
+
*/
|
|
2202
2218
|
copy() {
|
|
2203
|
-
const buffer = new Uint8ClampedArray(this.
|
|
2204
|
-
const
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2219
|
+
const buffer = new Uint8ClampedArray(this.imageData.data);
|
|
2220
|
+
const ImageConstructor = typeof ImageData !== "undefined" ? ImageData : this.imageData.constructor;
|
|
2221
|
+
const newImageData = new ImageConstructor(
|
|
2222
|
+
buffer,
|
|
2223
|
+
this.width,
|
|
2224
|
+
this.height
|
|
2225
|
+
);
|
|
2226
|
+
return new _PixelData(newImageData);
|
|
2210
2227
|
}
|
|
2211
2228
|
};
|
|
2212
2229
|
|
|
@@ -2638,11 +2655,11 @@ function reflectPixelDataVertical(pixelData) {
|
|
|
2638
2655
|
// src/PixelData/resamplePixelData.ts
|
|
2639
2656
|
function resamplePixelData(pixelData, factor) {
|
|
2640
2657
|
const { data, width, height } = resample32(pixelData.data32, pixelData.width, pixelData.height, factor);
|
|
2641
|
-
return new PixelData(
|
|
2658
|
+
return new PixelData(new ImageData(
|
|
2659
|
+
new Uint8ClampedArray(data.buffer),
|
|
2642
2660
|
width,
|
|
2643
|
-
height
|
|
2644
|
-
|
|
2645
|
-
});
|
|
2661
|
+
height
|
|
2662
|
+
));
|
|
2646
2663
|
}
|
|
2647
2664
|
|
|
2648
2665
|
// src/PixelData/rotatePixelData.ts
|
|
@@ -2656,30 +2673,33 @@ function rotatePixelData(pixelData) {
|
|
|
2656
2673
|
}
|
|
2657
2674
|
const newWidth = height;
|
|
2658
2675
|
const newHeight = width;
|
|
2659
|
-
const
|
|
2676
|
+
const newData32 = new Uint32Array(data.length);
|
|
2660
2677
|
for (let y = 0; y < height; y++) {
|
|
2661
2678
|
for (let x = 0; x < width; x++) {
|
|
2662
2679
|
const oldIdx = y * width + x;
|
|
2663
2680
|
const newX = height - 1 - y;
|
|
2664
2681
|
const newY = x;
|
|
2665
2682
|
const newIdx = newY * newWidth + newX;
|
|
2666
|
-
|
|
2683
|
+
newData32[newIdx] = data[oldIdx];
|
|
2667
2684
|
}
|
|
2668
2685
|
}
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
|
|
2686
|
+
const newImageData = new ImageData(
|
|
2687
|
+
new Uint8ClampedArray(newData32.buffer),
|
|
2688
|
+
newWidth,
|
|
2689
|
+
newHeight
|
|
2690
|
+
);
|
|
2691
|
+
pixelData.set(newImageData);
|
|
2672
2692
|
}
|
|
2673
2693
|
function rotateSquareInPlace(pixelData) {
|
|
2674
2694
|
const n = pixelData.width;
|
|
2675
2695
|
const data = pixelData.data32;
|
|
2676
2696
|
for (let i = 0; i < n / 2; i++) {
|
|
2677
2697
|
for (let j = i; j < n - i - 1; j++) {
|
|
2678
|
-
const temp = data[i * n + j];
|
|
2679
2698
|
const top = i * n + j;
|
|
2680
2699
|
const right = j * n + (n - 1 - i);
|
|
2681
2700
|
const bottom = (n - 1 - i) * n + (n - 1 - j);
|
|
2682
2701
|
const left = (n - 1 - j) * n + i;
|
|
2702
|
+
const temp = data[top];
|
|
2683
2703
|
data[top] = data[left];
|
|
2684
2704
|
data[left] = data[bottom];
|
|
2685
2705
|
data[bottom] = data[right];
|
|
@@ -2749,6 +2769,7 @@ function rotateSquareInPlace(pixelData) {
|
|
|
2749
2769
|
imageDataToAlphaMask,
|
|
2750
2770
|
imageDataToDataUrl,
|
|
2751
2771
|
imageDataToImgBlob,
|
|
2772
|
+
imageDataToUInt32Array,
|
|
2752
2773
|
imgBlobToImageData,
|
|
2753
2774
|
indexedImageToAverageColor,
|
|
2754
2775
|
indexedImageToImageData,
|