pixel-data-js 0.19.2 → 0.21.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
  */
@@ -682,7 +689,7 @@ declare class PixelWriter<M> {
682
689
  }
683
690
 
684
691
  declare function makeFullPixelMutator(writer: PixelWriter<any>): {
685
- clear(rect?: Partial<Rect>): void;
692
+ clear(rect?: Partial<BinaryMaskRect>): void;
686
693
  applyRectPencilStroke(color: Color32, x0: number, y0: number, x1: number, y1: number, brushWidth: number, brushHeight: number, alpha?: number, blendFn?: BlendColor32): void;
687
694
  applyRectPencil(color: Color32, centerX: number, centerY: number, brushWidth: number, brushHeight: number, alpha?: number, blendFn?: BlendColor32): void;
688
695
  applyRectBrushStroke(color: Color32, x0: number, y0: number, x1: number, y1: number, brushWidth: number, brushHeight: number, alpha: number | undefined, fallOff: (dist: number) => number, blendFn?: BlendColor32): void;
@@ -691,7 +698,7 @@ declare function makeFullPixelMutator(writer: PixelWriter<any>): {
691
698
  applyCircleBrushStroke(color: Color32, x0: number, y0: number, x1: number, y1: number, brushSize: number, alpha: number | undefined, fallOff: (dist: number) => number, blendFn?: BlendColor32): void;
692
699
  applyCircleBrush(color: Color32, centerX: number, centerY: number, brushSize: number, alpha: number | undefined, fallOff: (dist: number) => number, blendFn?: BlendColor32): void;
693
700
  invert(opts?: PixelMutateOptions): void;
694
- fill(color: Color32, rect?: Partial<Rect>): void;
701
+ fill(color: Color32, rect?: Partial<BinaryMaskRect>): void;
695
702
  blendPixel(x: number, y: number, color: Color32, alpha?: number, blendFn?: BlendColor32): void;
696
703
  blendColor(color: Color32, opts?: ColorBlendOptions): void;
697
704
  blendPixelData(src: IPixelData, opts: PixelBlendOptions): void;
@@ -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,15 +902,16 @@ 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;
904
911
  };
905
912
  type Deps$2 = Partial<typeof defaults$2>;
906
913
  declare const mutatorClear: (writer: PixelWriter<any>, deps?: Deps$2) => {
907
- clear(rect?: Partial<Rect>): void;
914
+ clear(rect?: Partial<BinaryMaskRect>): void;
908
915
  };
909
916
 
910
917
  declare const defaults$1: {
@@ -912,7 +919,7 @@ declare const defaults$1: {
912
919
  };
913
920
  type Deps$1 = Partial<typeof defaults$1>;
914
921
  declare const mutatorFill: (writer: PixelWriter<any>, deps?: Deps$1) => {
915
- fill(color: Color32, rect?: Partial<Rect>): void;
922
+ fill(color: Color32, rect?: Partial<BinaryMaskRect>): void;
916
923
  };
917
924
 
918
925
  declare function invertPixelData(pixelData: IPixelData, opts?: PixelMutateOptions): void;
@@ -1354,7 +1361,7 @@ declare function blendPixelDataBinaryMask(dst: IPixelData, src: IPixelData, bina
1354
1361
  * Clears a region of the PixelData to transparent (0x00000000).
1355
1362
  * Internally uses the optimized fillPixelData.
1356
1363
  */
1357
- declare function clearPixelData(dst: IPixelData, rect?: Partial<Rect>): void;
1364
+ declare function clearPixelData(dst: IPixelData, rect?: Partial<BinaryMaskRect>): void;
1358
1365
 
1359
1366
  /**
1360
1367
  * High-level extraction that returns a new PixelData instance.
@@ -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
 
@@ -3112,10 +3133,11 @@ var mutatorClear = ((writer, deps = defaults12) => {
3112
3133
  x = 0,
3113
3134
  y = 0,
3114
3135
  w = writer.target.width,
3115
- h = writer.target.height
3136
+ h = writer.target.height,
3137
+ mask = void 0
3116
3138
  } = rect;
3117
3139
  writer.accumulator.storeRegionBeforeState(x, y, w, h);
3118
- fillPixelData2(writer.target, 0, x, y, w, h);
3140
+ fillPixelData2(writer.target, 0, x, y, w, h, mask);
3119
3141
  }
3120
3142
  };
3121
3143
  });
@@ -3134,10 +3156,11 @@ var mutatorFill = ((writer, deps = defaults13) => {
3134
3156
  x = 0,
3135
3157
  y = 0,
3136
3158
  w = writer.target.width,
3137
- h = writer.target.height
3159
+ h = writer.target.height,
3160
+ mask = void 0
3138
3161
  } = rect;
3139
3162
  writer.accumulator.storeRegionBeforeState(x, y, w, h);
3140
- fillPixelData2(writer.target, color, x, y, w, h);
3163
+ fillPixelData2(writer.target, color, x, y, w, h, mask);
3141
3164
  }
3142
3165
  };
3143
3166
  });