pixel-data-js 0.19.2 → 0.20.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.
@@ -42,6 +42,13 @@ type Rect = {
42
42
  w: number;
43
43
  h: number;
44
44
  };
45
+ type BinaryMaskRect = {
46
+ x: number;
47
+ y: number;
48
+ w: number;
49
+ h: number;
50
+ mask: BinaryMask;
51
+ };
45
52
  /**
46
53
  * Defines how mask values should be interpreted during a draw operation.
47
54
  */
@@ -885,10 +892,9 @@ declare const mutatorBlendPixelData: (writer: PixelWriter<any>, deps?: Partial<D
885
892
  *
886
893
  * @param dst - The target {@link PixelData} to modify.
887
894
  * @param color - The {@link Color32} value to apply.
888
- * @param rect - A {@link Rect} defining the area to fill. If omitted, the entire
889
- * buffer is filled.
895
+ * @param rect - A {@link BinaryMaskRect} defining the area to fill.
890
896
  */
891
- declare function fillPixelData(dst: IPixelData, color: Color32, rect?: Partial<Rect>): void;
897
+ declare function fillPixelData(dst: IPixelData, color: Color32, rect?: Partial<BinaryMaskRect>): void;
892
898
  /**
893
899
  * @param dst - The target {@link PixelData} to modify.
894
900
  * @param color - The {@link Color32} value to apply.
@@ -896,8 +902,9 @@ declare function fillPixelData(dst: IPixelData, color: Color32, rect?: Partial<R
896
902
  * @param y - Starting vertical coordinate.
897
903
  * @param w - Width of the fill area.
898
904
  * @param h - Height of the fill area.
905
+ * @param mask - A {@link BinaryMaskRect} defining the area to fill
899
906
  */
900
- declare function fillPixelData(dst: IPixelData, color: Color32, x: number, y: number, w: number, h: number): void;
907
+ declare function fillPixelData(dst: IPixelData, color: Color32, x: number, y: number, w: number, h: number, mask?: BinaryMask): void;
901
908
 
902
909
  declare const defaults$2: {
903
910
  fillPixelData: typeof fillPixelData;
@@ -1426,4 +1433,4 @@ declare function writePixelDataBuffer(target: IPixelData, data: Uint32Array, x:
1426
1433
  */
1427
1434
  declare function trimRectBounds<T extends Rect | SelectionRect>(target: T, bounds: Rect): void;
1428
1435
 
1429
- export { type Alpha, type AlphaMask, type AnyMask, type ApplyMaskToPixelDataOptions, BASE_FAST_BLEND_MODE_FUNCTIONS, BASE_PERFECT_BLEND_MODE_FUNCTIONS, type Base64EncodedUInt8Array, BaseBlendMode, type BaseBlendModes, type BasePixelBlendOptions, type BinaryMask, type BlendColor32, type BlendModeRegistry, CANVAS_CTX_FAILED, type Color32, type ColorBlendMaskOptions, type ColorBlendOptions, type FloodFillImageDataOptions, type FloodFillResult, type HistoryAction, HistoryManager, type HistoryMutator, type IPixelData, type ImageDataLike, type ImageDataLikeConstructor, IndexedImage, type InvertMask, type MaskOffset, type MaskOffsetWidth, MaskType, type MergeAlphaMasksOptions, OFFSCREEN_CANVAS_CTX_FAILED, PixelAccumulator, type PixelBlendMaskOptions, type PixelBlendOptions, PixelBuffer32, type PixelCanvas, PixelData, PixelEngineConfig, type PixelMutateOptions, type PixelPatchTiles, type PixelRect, PixelTile, PixelWriter, type PixelWriterOptions, type RGBA, type Rect, type RequiredBlendModes, type ReusableCanvas, type ReusableImageData, type SelectionRect, type SerializedImageData, UnsupportedFormatError, applyAlphaMaskToPixelData, applyBinaryMaskToAlphaMask, applyBinaryMaskToPixelData, applyCircleBrushToPixelData, applyPatchTiles, applyRectBrushToPixelData, base64DecodeArrayBuffer, base64EncodeArrayBuffer, blendColorPixelData, blendColorPixelDataAlphaMask, blendColorPixelDataBinaryMask, blendPixelData, blendPixelDataAlphaMask, blendPixelDataBinaryMask, 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, extractPixelData, extractPixelDataBuffer, fileInputChangeToImageData, fileToImageData, fillPixelData, floodFillSelection, forEachLinePoint, getCircleBrushOrPencilBounds, getCircleBrushOrPencilStrokeBounds, getImageDataFromClipboard, getIndexedImageColorCounts, getRectBrushOrPencilBounds, getRectBrushOrPencilStrokeBounds, 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, makeBlendModeRegistry, makeFastBlendModeRegistry, makeFullPixelMutator, makeImageDataLike, makePerfectBlendModeRegistry, makePixelCanvas, makeReusableCanvas, makeReusableImageData, mergeAlphaMasks, mergeBinaryMasks, multiplyFast, multiplyPerfect, mutatorApplyAlphaMask, mutatorApplyBinaryMask, mutatorApplyCircleBrush, mutatorApplyCircleBrushStroke, mutatorApplyCirclePencil, mutatorApplyCirclePencilStroke, mutatorApplyRectBrush, mutatorApplyRectBrushStroke, mutatorApplyRectPencil, mutatorApplyRectPencilStroke, mutatorBlendColor, mutatorBlendPixel, mutatorBlendPixelData, mutatorClear, mutatorFill, mutatorInvert, overlayFast, overlayPerfect, overwriteBase, overwriteFast, overwritePerfect, packColor, packRGBA, pinLightFast, pinLightPerfect, pixelDataToAlphaMask, reflectPixelDataHorizontal, reflectPixelDataVertical, resampleImageData, resampleIndexedImage, resamplePixelData, resizeImageData, rotatePixelData, screenFast, screenPerfect, serializeImageData, serializeNullableImageData, softLightFast, softLightPerfect, sourceOverFast, sourceOverPerfect, subtractFast, subtractPerfect, toBlendModeIndexAndName, trimRectBounds, uInt32ArrayToImageData, uInt32ArrayToImageDataLike, unpackAlpha, unpackBlue, unpackColor, unpackColorTo, unpackGreen, unpackRed, vividLightFast, vividLightPerfect, writeImageData, writeImageDataBuffer, writeImageDataToClipboard, writeImgBlobToClipboard, writePixelDataBuffer };
1436
+ export { type Alpha, type AlphaMask, type AnyMask, type ApplyMaskToPixelDataOptions, BASE_FAST_BLEND_MODE_FUNCTIONS, BASE_PERFECT_BLEND_MODE_FUNCTIONS, type Base64EncodedUInt8Array, BaseBlendMode, type BaseBlendModes, type BasePixelBlendOptions, type BinaryMask, type BinaryMaskRect, type BlendColor32, type BlendModeRegistry, CANVAS_CTX_FAILED, type Color32, type ColorBlendMaskOptions, type ColorBlendOptions, type FloodFillImageDataOptions, type FloodFillResult, type HistoryAction, HistoryManager, type HistoryMutator, type IPixelData, type ImageDataLike, type ImageDataLikeConstructor, IndexedImage, type InvertMask, type MaskOffset, type MaskOffsetWidth, MaskType, type MergeAlphaMasksOptions, OFFSCREEN_CANVAS_CTX_FAILED, PixelAccumulator, type PixelBlendMaskOptions, type PixelBlendOptions, PixelBuffer32, type PixelCanvas, PixelData, PixelEngineConfig, type PixelMutateOptions, type PixelPatchTiles, type PixelRect, PixelTile, PixelWriter, type PixelWriterOptions, type RGBA, type Rect, type RequiredBlendModes, type ReusableCanvas, type ReusableImageData, type SelectionRect, type SerializedImageData, UnsupportedFormatError, applyAlphaMaskToPixelData, applyBinaryMaskToAlphaMask, applyBinaryMaskToPixelData, applyCircleBrushToPixelData, applyPatchTiles, applyRectBrushToPixelData, base64DecodeArrayBuffer, base64EncodeArrayBuffer, blendColorPixelData, blendColorPixelDataAlphaMask, blendColorPixelDataBinaryMask, blendPixelData, blendPixelDataAlphaMask, blendPixelDataBinaryMask, 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, extractPixelData, extractPixelDataBuffer, fileInputChangeToImageData, fileToImageData, fillPixelData, floodFillSelection, forEachLinePoint, getCircleBrushOrPencilBounds, getCircleBrushOrPencilStrokeBounds, getImageDataFromClipboard, getIndexedImageColorCounts, getRectBrushOrPencilBounds, getRectBrushOrPencilStrokeBounds, 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, makeBlendModeRegistry, makeFastBlendModeRegistry, makeFullPixelMutator, makeImageDataLike, makePerfectBlendModeRegistry, makePixelCanvas, makeReusableCanvas, makeReusableImageData, mergeAlphaMasks, mergeBinaryMasks, multiplyFast, multiplyPerfect, mutatorApplyAlphaMask, mutatorApplyBinaryMask, mutatorApplyCircleBrush, mutatorApplyCircleBrushStroke, mutatorApplyCirclePencil, mutatorApplyCirclePencilStroke, mutatorApplyRectBrush, mutatorApplyRectBrushStroke, mutatorApplyRectPencil, mutatorApplyRectPencilStroke, mutatorBlendColor, mutatorBlendPixel, mutatorBlendPixelData, mutatorClear, mutatorFill, mutatorInvert, overlayFast, overlayPerfect, overwriteBase, overwriteFast, overwritePerfect, packColor, packRGBA, pinLightFast, pinLightPerfect, pixelDataToAlphaMask, reflectPixelDataHorizontal, reflectPixelDataVertical, resampleImageData, resampleIndexedImage, resamplePixelData, resizeImageData, rotatePixelData, screenFast, screenPerfect, serializeImageData, serializeNullableImageData, softLightFast, softLightPerfect, sourceOverFast, sourceOverPerfect, subtractFast, subtractPerfect, toBlendModeIndexAndName, trimRectBounds, uInt32ArrayToImageData, uInt32ArrayToImageDataLike, unpackAlpha, unpackBlue, unpackColor, unpackColorTo, unpackGreen, unpackRed, vividLightFast, vividLightPerfect, writeImageData, writeImageDataBuffer, writeImageDataToClipboard, writeImgBlobToClipboard, writePixelDataBuffer };
@@ -3056,21 +3056,24 @@ var mutatorBlendPixelData = ((writer, deps = defaults11) => {
3056
3056
 
3057
3057
  // src/PixelData/fillPixelData.ts
3058
3058
  var SCRATCH_RECT = makeClippedRect();
3059
- function fillPixelData(dst, color, _x, _y, _w, _h) {
3059
+ function fillPixelData(dst, color, _x, _y, _w, _h, _mask) {
3060
3060
  let x;
3061
3061
  let y;
3062
3062
  let w;
3063
3063
  let h;
3064
+ let mask;
3064
3065
  if (typeof _x === "object") {
3065
3066
  x = _x.x ?? 0;
3066
3067
  y = _x.y ?? 0;
3067
3068
  w = _x.w ?? dst.width;
3068
3069
  h = _x.h ?? dst.height;
3070
+ mask = _x.mask;
3069
3071
  } else if (typeof _x === "number") {
3070
3072
  x = _x;
3071
3073
  y = _y;
3072
3074
  w = _w;
3073
3075
  h = _h;
3076
+ mask = _mask;
3074
3077
  } else {
3075
3078
  x = 0;
3076
3079
  y = 0;
@@ -3091,10 +3094,28 @@ function fillPixelData(dst, color, _x, _y, _w, _h) {
3091
3094
  dst32.fill(color);
3092
3095
  return;
3093
3096
  }
3094
- for (let iy = 0; iy < actualH; iy++) {
3095
- const start = (finalY + iy) * dw + finalX;
3096
- const end = start + actualW;
3097
- dst32.fill(color, start, end);
3097
+ if (mask) {
3098
+ for (let iy = 0; iy < actualH; iy++) {
3099
+ const currentY = finalY + iy;
3100
+ const maskY = currentY - y;
3101
+ const maskOffset = maskY * w;
3102
+ for (let ix = 0; ix < actualW; ix++) {
3103
+ const currentX = finalX + ix;
3104
+ const maskX = currentX - x;
3105
+ const maskIndex = maskOffset + maskX;
3106
+ const isMasked = mask[maskIndex];
3107
+ if (isMasked) {
3108
+ const dstIndex = currentY * dw + currentX;
3109
+ dst32[dstIndex] = color;
3110
+ }
3111
+ }
3112
+ }
3113
+ } else {
3114
+ for (let iy = 0; iy < actualH; iy++) {
3115
+ const start = (finalY + iy) * dw + finalX;
3116
+ const end = start + actualW;
3117
+ dst32.fill(color, start, end);
3118
+ }
3098
3119
  }
3099
3120
  }
3100
3121