pixel-data-js 0.14.0 → 0.15.1

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.
@@ -64,8 +64,10 @@ __export(src_exports, {
64
64
  dividePerfect: () => dividePerfect,
65
65
  exclusionFast: () => exclusionFast,
66
66
  exclusionPerfect: () => exclusionPerfect,
67
- extractImageDataPixels: () => extractImageDataPixels,
67
+ extractImageDataBuffer: () => extractImageDataBuffer,
68
68
  extractMask: () => extractMask,
69
+ extractPixelData: () => extractPixelData,
70
+ extractPixelDataBuffer: () => extractPixelDataBuffer,
69
71
  fileInputChangeToImageData: () => fileInputChangeToImageData,
70
72
  fileToImageData: () => fileToImageData,
71
73
  fillPixelData: () => fillPixelData,
@@ -704,8 +706,8 @@ function color32ToCssRGBA(color) {
704
706
  return `rgba(${r},${g},${b},${alpha})`;
705
707
  }
706
708
 
707
- // src/ImageData/extractImageDataPixels.ts
708
- function extractImageDataPixels(imageData, _x, _y, _w, _h) {
709
+ // src/ImageData/extractImageDataBuffer.ts
710
+ function extractImageDataBuffer(imageData, _x, _y, _w, _h) {
709
711
  const { x, y, w, h } = typeof _x === "object" ? _x : { x: _x, y: _y, w: _w, h: _h };
710
712
  const { width: srcW, height: srcH, data: src } = imageData;
711
713
  if (w <= 0 || h <= 0) return new Uint8ClampedArray(0);
@@ -978,7 +980,7 @@ function floodFillSelection(img, startX, startY, {
978
980
  selectionRect,
979
981
  { x: 0, y: 0, w: width, h: height }
980
982
  );
981
- const extracted = extractImageDataPixels(
983
+ const extracted = extractImageDataBuffer(
982
984
  imageData,
983
985
  selectionRect.x,
984
986
  selectionRect.y,
@@ -2607,6 +2609,47 @@ function clearPixelData(dst, rect) {
2607
2609
  fillPixelData(dst, 0, rect);
2608
2610
  }
2609
2611
 
2612
+ // src/PixelData/extractPixelDataBuffer.ts
2613
+ function extractPixelDataBuffer(source, _x, _y, _w, _h) {
2614
+ const { x, y, w, h } = typeof _x === "object" ? _x : { x: _x, y: _y, w: _w, h: _h };
2615
+ const srcW = source.width;
2616
+ const srcH = source.height;
2617
+ const srcData = source.data32;
2618
+ if (w <= 0 || h <= 0) {
2619
+ return new Uint32Array(0);
2620
+ }
2621
+ const dstImageData = new ImageData(w, h);
2622
+ const dstData = new Uint32Array(dstImageData.data.buffer);
2623
+ const x0 = Math.max(0, x);
2624
+ const y0 = Math.max(0, y);
2625
+ const x1 = Math.min(srcW, x + w);
2626
+ const y1 = Math.min(srcH, y + h);
2627
+ if (x1 <= x0 || y1 <= y0) {
2628
+ return dstData;
2629
+ }
2630
+ const copyWidth = x1 - x0;
2631
+ const copyHeight = y1 - y0;
2632
+ for (let row = 0; row < copyHeight; row++) {
2633
+ const srcRow = y0 + row;
2634
+ const srcStart = srcRow * srcW + x0;
2635
+ const dstRow = y0 - y + row;
2636
+ const dstCol = x0 - x;
2637
+ const dstStart = dstRow * w + dstCol;
2638
+ const chunk = srcData.subarray(srcStart, srcStart + copyWidth);
2639
+ dstData.set(chunk, dstStart);
2640
+ }
2641
+ return dstData;
2642
+ }
2643
+
2644
+ // src/PixelData/extractPixelData.ts
2645
+ function extractPixelData(source, _x, _y, _w, _h) {
2646
+ const { x, y, w, h } = typeof _x === "object" ? _x : { x: _x, y: _y, w: _w, h: _h };
2647
+ const result = new PixelData(new ImageData(w, h));
2648
+ const buffer = extractPixelDataBuffer(source, x, y, w, h);
2649
+ result.data32.set(buffer);
2650
+ return result;
2651
+ }
2652
+
2610
2653
  // src/PixelData/invertPixelData.ts
2611
2654
  function invertPixelData(pixelData) {
2612
2655
  const data32 = pixelData.data32;
@@ -2753,8 +2796,10 @@ function rotateSquareInPlace(pixelData) {
2753
2796
  dividePerfect,
2754
2797
  exclusionFast,
2755
2798
  exclusionPerfect,
2756
- extractImageDataPixels,
2799
+ extractImageDataBuffer,
2757
2800
  extractMask,
2801
+ extractPixelData,
2802
+ extractPixelDataBuffer,
2758
2803
  fileInputChangeToImageData,
2759
2804
  fileToImageData,
2760
2805
  fillPixelData,