pixel-data-js 0.14.0 → 0.15.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 +39 -5
- package/dist/index.dev.cjs.map +1 -1
- package/dist/index.dev.js +37 -4
- package/dist/index.dev.js.map +1 -1
- package/dist/index.prod.cjs +39 -5
- package/dist/index.prod.cjs.map +1 -1
- package/dist/index.prod.d.ts +10 -3
- package/dist/index.prod.js +37 -4
- package/dist/index.prod.js.map +1 -1
- package/package.json +1 -1
- package/src/Algorithm/floodFillSelection.ts +2 -2
- package/src/ImageData/{extractImageDataPixels.ts → extractImageDataBuffer.ts} +3 -3
- package/src/PixelData/extractPixelDataBuffer.ts +61 -0
- package/src/index.ts +2 -1
package/dist/index.dev.cjs
CHANGED
|
@@ -64,8 +64,9 @@ __export(src_exports, {
|
|
|
64
64
|
dividePerfect: () => dividePerfect,
|
|
65
65
|
exclusionFast: () => exclusionFast,
|
|
66
66
|
exclusionPerfect: () => exclusionPerfect,
|
|
67
|
-
|
|
67
|
+
extractImageDataBuffer: () => extractImageDataBuffer,
|
|
68
68
|
extractMask: () => extractMask,
|
|
69
|
+
extractPixelDataBuffer: () => extractPixelDataBuffer,
|
|
69
70
|
fileInputChangeToImageData: () => fileInputChangeToImageData,
|
|
70
71
|
fileToImageData: () => fileToImageData,
|
|
71
72
|
fillPixelData: () => fillPixelData,
|
|
@@ -704,8 +705,8 @@ function color32ToCssRGBA(color) {
|
|
|
704
705
|
return `rgba(${r},${g},${b},${alpha})`;
|
|
705
706
|
}
|
|
706
707
|
|
|
707
|
-
// src/ImageData/
|
|
708
|
-
function
|
|
708
|
+
// src/ImageData/extractImageDataBuffer.ts
|
|
709
|
+
function extractImageDataBuffer(imageData, _x, _y, _w, _h) {
|
|
709
710
|
const { x, y, w, h } = typeof _x === "object" ? _x : { x: _x, y: _y, w: _w, h: _h };
|
|
710
711
|
const { width: srcW, height: srcH, data: src } = imageData;
|
|
711
712
|
if (w <= 0 || h <= 0) return new Uint8ClampedArray(0);
|
|
@@ -978,7 +979,7 @@ function floodFillSelection(img, startX, startY, {
|
|
|
978
979
|
selectionRect,
|
|
979
980
|
{ x: 0, y: 0, w: width, h: height }
|
|
980
981
|
);
|
|
981
|
-
const extracted =
|
|
982
|
+
const extracted = extractImageDataBuffer(
|
|
982
983
|
imageData,
|
|
983
984
|
selectionRect.x,
|
|
984
985
|
selectionRect.y,
|
|
@@ -2607,6 +2608,38 @@ function clearPixelData(dst, rect) {
|
|
|
2607
2608
|
fillPixelData(dst, 0, rect);
|
|
2608
2609
|
}
|
|
2609
2610
|
|
|
2611
|
+
// src/PixelData/extractPixelDataBuffer.ts
|
|
2612
|
+
function extractPixelDataBuffer(source, _x, _y, _w, _h) {
|
|
2613
|
+
const { x, y, w, h } = typeof _x === "object" ? _x : { x: _x, y: _y, w: _w, h: _h };
|
|
2614
|
+
const srcW = source.width;
|
|
2615
|
+
const srcH = source.height;
|
|
2616
|
+
const srcData = source.data32;
|
|
2617
|
+
if (w <= 0 || h <= 0) {
|
|
2618
|
+
return new Uint32Array(0);
|
|
2619
|
+
}
|
|
2620
|
+
const dstImageData = new ImageData(w, h);
|
|
2621
|
+
const dstData = new Uint32Array(dstImageData.data.buffer);
|
|
2622
|
+
const x0 = Math.max(0, x);
|
|
2623
|
+
const y0 = Math.max(0, y);
|
|
2624
|
+
const x1 = Math.min(srcW, x + w);
|
|
2625
|
+
const y1 = Math.min(srcH, y + h);
|
|
2626
|
+
if (x1 <= x0 || y1 <= y0) {
|
|
2627
|
+
return dstData;
|
|
2628
|
+
}
|
|
2629
|
+
const copyWidth = x1 - x0;
|
|
2630
|
+
const copyHeight = y1 - y0;
|
|
2631
|
+
for (let row = 0; row < copyHeight; row++) {
|
|
2632
|
+
const srcRow = y0 + row;
|
|
2633
|
+
const srcStart = srcRow * srcW + x0;
|
|
2634
|
+
const dstRow = y0 - y + row;
|
|
2635
|
+
const dstCol = x0 - x;
|
|
2636
|
+
const dstStart = dstRow * w + dstCol;
|
|
2637
|
+
const chunk = srcData.subarray(srcStart, srcStart + copyWidth);
|
|
2638
|
+
dstData.set(chunk, dstStart);
|
|
2639
|
+
}
|
|
2640
|
+
return dstData;
|
|
2641
|
+
}
|
|
2642
|
+
|
|
2610
2643
|
// src/PixelData/invertPixelData.ts
|
|
2611
2644
|
function invertPixelData(pixelData) {
|
|
2612
2645
|
const data32 = pixelData.data32;
|
|
@@ -2753,8 +2786,9 @@ function rotateSquareInPlace(pixelData) {
|
|
|
2753
2786
|
dividePerfect,
|
|
2754
2787
|
exclusionFast,
|
|
2755
2788
|
exclusionPerfect,
|
|
2756
|
-
|
|
2789
|
+
extractImageDataBuffer,
|
|
2757
2790
|
extractMask,
|
|
2791
|
+
extractPixelDataBuffer,
|
|
2758
2792
|
fileInputChangeToImageData,
|
|
2759
2793
|
fileToImageData,
|
|
2760
2794
|
fillPixelData,
|