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.prod.d.ts
CHANGED
|
@@ -510,7 +510,7 @@ declare function copyImageDataLike({ data, width, height }: ImageDataLike): Imag
|
|
|
510
510
|
* @param rect - A {@link Rect} object defining the region to extract.
|
|
511
511
|
* @returns A {@link Uint8ClampedArray} containing the RGBA pixel data of the region.
|
|
512
512
|
*/
|
|
513
|
-
declare function
|
|
513
|
+
declare function extractImageDataBuffer(imageData: ImageDataLike, rect: Rect): Uint8ClampedArray;
|
|
514
514
|
/**
|
|
515
515
|
* @param imageData - The source image data to read from.
|
|
516
516
|
* @param x - The starting horizontal coordinate.
|
|
@@ -519,7 +519,7 @@ declare function extractImageDataPixels(imageData: ImageDataLike, rect: Rect): U
|
|
|
519
519
|
* @param h - The height of the region to extract.
|
|
520
520
|
* @returns A {@link Uint8ClampedArray} containing the RGBA pixel data of the region.
|
|
521
521
|
*/
|
|
522
|
-
declare function
|
|
522
|
+
declare function extractImageDataBuffer(imageData: ImageDataLike, x: number, y: number, w: number, h: number): Uint8ClampedArray;
|
|
523
523
|
|
|
524
524
|
/**
|
|
525
525
|
* Extracts the alpha channel from raw ImageData into an AlphaMask.
|
|
@@ -934,6 +934,13 @@ declare function blendPixelData(dst: PixelData, src: PixelData, opts: PixelBlend
|
|
|
934
934
|
*/
|
|
935
935
|
declare function clearPixelData(dst: PixelData, rect?: Partial<Rect>): void;
|
|
936
936
|
|
|
937
|
+
/**
|
|
938
|
+
* Extracts a rectangular region of pixels from PixelData.
|
|
939
|
+
* Returns a new Uint32Array containing the extracted pixels.
|
|
940
|
+
*/
|
|
941
|
+
declare function extractPixelDataBuffer(source: PixelData, rect: Rect): Uint32Array;
|
|
942
|
+
declare function extractPixelDataBuffer(source: PixelData, x: number, y: number, w: number, h: number): Uint32Array;
|
|
943
|
+
|
|
937
944
|
/**
|
|
938
945
|
* Fills a region or the {@link PixelData} buffer with a solid color.
|
|
939
946
|
*
|
|
@@ -998,4 +1005,4 @@ declare function rotatePixelData(pixelData: PixelData): void;
|
|
|
998
1005
|
*/
|
|
999
1006
|
declare function trimRectBounds<T extends Rect | SelectionRect>(target: T, bounds: Rect): void;
|
|
1000
1007
|
|
|
1001
|
-
export { type AlphaMask, type AnyMask, type ApplyMaskOptions, type Base64EncodedUInt8Array, type BinaryMask, type BlendColor32, BlendMode, type BlendModeIndex, type BlendToIndexGetter, type Color32, type ColorBlendOptions, FAST_BLENDER_REGISTRY, FAST_BLEND_MODES, FAST_BLEND_MODE_BY_NAME, FAST_BLEND_TO_INDEX, type FastBlendModes, type FloodFillImageDataOptions, type FloodFillResult, INDEX_TO_FAST_BLEND, INDEX_TO_PERFECT_BLEND, type ImageDataLike, type IndexToBlendGetter, IndexedImage, MaskType, PERFECT_BLENDER_REGISTRY, PERFECT_BLEND_MODES, PERFECT_BLEND_MODE_BY_NAME, PERFECT_BLEND_TO_INDEX, type PerfectBlendModes, type PixelBlendOptions, type PixelCanvas, PixelData, type PixelOptions, type Point, type RGBA, type Rect, type RegisteredFastBlender, type RegisteredPerfectBlender, type ReusableCanvas, type ReusableImageData, type SelectionRect, type SerializedImageData, UnsupportedFormatError, applyMaskToPixelData, base64DecodeArrayBuffer, base64EncodeArrayBuffer, blendColorPixelData, blendPixelData, clearPixelData, color32ToCssRGBA, color32ToHex, colorBurnFast, colorBurnPerfect, colorDistance, colorDodgeFast, colorDodgePerfect, copyImageData, copyImageDataLike, copyMask, darkenFast, darkenPerfect, darkerFast, darkerPerfect, deserializeImageData, deserializeNullableImageData, deserializeRawImageData, differenceFast, differencePerfect, divideFast, dividePerfect, exclusionFast, exclusionPerfect,
|
|
1008
|
+
export { type AlphaMask, type AnyMask, type ApplyMaskOptions, type Base64EncodedUInt8Array, type BinaryMask, type BlendColor32, BlendMode, type BlendModeIndex, type BlendToIndexGetter, type Color32, type ColorBlendOptions, FAST_BLENDER_REGISTRY, FAST_BLEND_MODES, FAST_BLEND_MODE_BY_NAME, FAST_BLEND_TO_INDEX, type FastBlendModes, type FloodFillImageDataOptions, type FloodFillResult, INDEX_TO_FAST_BLEND, INDEX_TO_PERFECT_BLEND, type ImageDataLike, type IndexToBlendGetter, IndexedImage, MaskType, PERFECT_BLENDER_REGISTRY, PERFECT_BLEND_MODES, PERFECT_BLEND_MODE_BY_NAME, PERFECT_BLEND_TO_INDEX, type PerfectBlendModes, type PixelBlendOptions, type PixelCanvas, PixelData, type PixelOptions, type Point, type RGBA, type Rect, type RegisteredFastBlender, type RegisteredPerfectBlender, type ReusableCanvas, type ReusableImageData, type SelectionRect, type SerializedImageData, UnsupportedFormatError, applyMaskToPixelData, base64DecodeArrayBuffer, base64EncodeArrayBuffer, blendColorPixelData, blendPixelData, clearPixelData, color32ToCssRGBA, color32ToHex, colorBurnFast, colorBurnPerfect, colorDistance, colorDodgeFast, colorDodgePerfect, copyImageData, copyImageDataLike, copyMask, darkenFast, darkenPerfect, darkerFast, darkerPerfect, deserializeImageData, deserializeNullableImageData, deserializeRawImageData, differenceFast, differencePerfect, divideFast, dividePerfect, exclusionFast, exclusionPerfect, extractImageDataBuffer, extractMask, extractPixelDataBuffer, fileInputChangeToImageData, fileToImageData, fillPixelData, floodFillSelection, getImageDataFromClipboard, getIndexedImageColorCounts, getSupportedPixelFormats, hardLightFast, hardLightPerfect, hardMixFast, hardMixPerfect, imageDataToAlphaMask, imageDataToDataUrl, imageDataToImgBlob, imageDataToUInt32Array, imgBlobToImageData, indexedImageToAverageColor, indexedImageToImageData, invertAlphaMask, invertBinaryMask, invertImageData, invertPixelData, lerpColor32, lerpColor32Fast, lightenFast, lightenPerfect, lighterFast, lighterPerfect, linearBurnFast, linearBurnPerfect, linearDodgeFast, linearDodgePerfect, linearLightFast, linearLightPerfect, makePixelCanvas, makeReusableCanvas, makeReusableImageData, mergeMasks, multiplyFast, multiplyPerfect, overlayFast, overlayPerfect, overwriteFast, overwritePerfect, packColor, packRGBA, pinLightFast, pinLightPerfect, pixelDataToAlphaMask, reflectPixelDataHorizontal, reflectPixelDataVertical, resampleImageData, resampleIndexedImage, resamplePixelData, resizeImageData, rotatePixelData, screenFast, screenPerfect, serializeImageData, serializeNullableImageData, softLightFast, softLightPerfect, sourceOverFast, sourceOverPerfect, subtractFast, subtractPerfect, trimRectBounds, unpackAlpha, unpackBlue, unpackColor, unpackColorTo, unpackGreen, unpackRed, vividLightFast, vividLightPerfect, writeImageData, writeImageDataPixels, writeImageDataToClipboard, writeImgBlobToClipboard };
|
package/dist/index.prod.js
CHANGED
|
@@ -554,8 +554,8 @@ function color32ToCssRGBA(color) {
|
|
|
554
554
|
return `rgba(${r},${g},${b},${alpha})`;
|
|
555
555
|
}
|
|
556
556
|
|
|
557
|
-
// src/ImageData/
|
|
558
|
-
function
|
|
557
|
+
// src/ImageData/extractImageDataBuffer.ts
|
|
558
|
+
function extractImageDataBuffer(imageData, _x, _y, _w, _h) {
|
|
559
559
|
const { x, y, w, h } = typeof _x === "object" ? _x : { x: _x, y: _y, w: _w, h: _h };
|
|
560
560
|
const { width: srcW, height: srcH, data: src } = imageData;
|
|
561
561
|
if (w <= 0 || h <= 0) return new Uint8ClampedArray(0);
|
|
@@ -828,7 +828,7 @@ function floodFillSelection(img, startX, startY, {
|
|
|
828
828
|
selectionRect,
|
|
829
829
|
{ x: 0, y: 0, w: width, h: height }
|
|
830
830
|
);
|
|
831
|
-
const extracted =
|
|
831
|
+
const extracted = extractImageDataBuffer(
|
|
832
832
|
imageData,
|
|
833
833
|
selectionRect.x,
|
|
834
834
|
selectionRect.y,
|
|
@@ -2457,6 +2457,38 @@ function clearPixelData(dst, rect) {
|
|
|
2457
2457
|
fillPixelData(dst, 0, rect);
|
|
2458
2458
|
}
|
|
2459
2459
|
|
|
2460
|
+
// src/PixelData/extractPixelDataBuffer.ts
|
|
2461
|
+
function extractPixelDataBuffer(source, _x, _y, _w, _h) {
|
|
2462
|
+
const { x, y, w, h } = typeof _x === "object" ? _x : { x: _x, y: _y, w: _w, h: _h };
|
|
2463
|
+
const srcW = source.width;
|
|
2464
|
+
const srcH = source.height;
|
|
2465
|
+
const srcData = source.data32;
|
|
2466
|
+
if (w <= 0 || h <= 0) {
|
|
2467
|
+
return new Uint32Array(0);
|
|
2468
|
+
}
|
|
2469
|
+
const dstImageData = new ImageData(w, h);
|
|
2470
|
+
const dstData = new Uint32Array(dstImageData.data.buffer);
|
|
2471
|
+
const x0 = Math.max(0, x);
|
|
2472
|
+
const y0 = Math.max(0, y);
|
|
2473
|
+
const x1 = Math.min(srcW, x + w);
|
|
2474
|
+
const y1 = Math.min(srcH, y + h);
|
|
2475
|
+
if (x1 <= x0 || y1 <= y0) {
|
|
2476
|
+
return dstData;
|
|
2477
|
+
}
|
|
2478
|
+
const copyWidth = x1 - x0;
|
|
2479
|
+
const copyHeight = y1 - y0;
|
|
2480
|
+
for (let row = 0; row < copyHeight; row++) {
|
|
2481
|
+
const srcRow = y0 + row;
|
|
2482
|
+
const srcStart = srcRow * srcW + x0;
|
|
2483
|
+
const dstRow = y0 - y + row;
|
|
2484
|
+
const dstCol = x0 - x;
|
|
2485
|
+
const dstStart = dstRow * w + dstCol;
|
|
2486
|
+
const chunk = srcData.subarray(srcStart, srcStart + copyWidth);
|
|
2487
|
+
dstData.set(chunk, dstStart);
|
|
2488
|
+
}
|
|
2489
|
+
return dstData;
|
|
2490
|
+
}
|
|
2491
|
+
|
|
2460
2492
|
// src/PixelData/invertPixelData.ts
|
|
2461
2493
|
function invertPixelData(pixelData) {
|
|
2462
2494
|
const data32 = pixelData.data32;
|
|
@@ -2602,8 +2634,9 @@ export {
|
|
|
2602
2634
|
dividePerfect,
|
|
2603
2635
|
exclusionFast,
|
|
2604
2636
|
exclusionPerfect,
|
|
2605
|
-
|
|
2637
|
+
extractImageDataBuffer,
|
|
2606
2638
|
extractMask,
|
|
2639
|
+
extractPixelDataBuffer,
|
|
2607
2640
|
fileInputChangeToImageData,
|
|
2608
2641
|
fileToImageData,
|
|
2609
2642
|
fillPixelData,
|