pixel-data-js 0.25.0 → 0.25.2

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.
@@ -525,6 +525,25 @@ declare function toBlendModeIndexAndName(input: string | number): {
525
525
  declare const OFFSCREEN_CANVAS_CTX_FAILED = "Failed to create OffscreenCanvas context";
526
526
  declare const CANVAS_CTX_FAILED = "Failed to create Canvas context";
527
527
 
528
+ declare const CANVAS_COMPOSITE_MAP: {
529
+ readonly 0: "copy";
530
+ readonly 1: "source-over";
531
+ readonly 2: "darken";
532
+ readonly 3: "multiply";
533
+ readonly 4: "color-burn";
534
+ readonly 7: "lighten";
535
+ readonly 8: "screen";
536
+ readonly 9: "color-dodge";
537
+ readonly 10: "lighter";
538
+ readonly 12: "overlay";
539
+ readonly 13: "soft-light";
540
+ readonly 14: "hard-light";
541
+ readonly 19: "difference";
542
+ readonly 20: "exclusion";
543
+ };
544
+ type CanvasBlendModeIndex = keyof typeof CANVAS_COMPOSITE_MAP;
545
+ type CanvasCompositeOperation = typeof CANVAS_COMPOSITE_MAP[CanvasBlendModeIndex];
546
+
528
547
  type PixelCanvas = {
529
548
  readonly canvas: HTMLCanvasElement;
530
549
  readonly ctx: CanvasRenderingContext2D;
@@ -567,14 +586,14 @@ declare function makeReusableOffscreenCanvas(): {
567
586
  type DrawPixelLayer = (ctx: CanvasRenderingContext2D) => void;
568
587
  type DrawScreenLayer = (ctx: CanvasRenderingContext2D, scale: number) => void;
569
588
  type CanvasFrameRenderer = ReturnType<typeof makeCanvasFrameRenderer>;
570
- declare const defaults$b: {
589
+ declare const defaults$c: {
571
590
  makeReusableCanvas: typeof makeReusableCanvas;
572
591
  };
573
- type Deps$b = Partial<typeof defaults$b>;
592
+ type Deps$c = Partial<typeof defaults$c>;
574
593
  /**
575
594
  * @param deps - @hidden
576
595
  */
577
- declare function makeCanvasFrameRenderer(deps?: Deps$b): (pixelCanvas: PixelCanvas, scale: number, getImageData: () => ImageData | undefined | null, drawPixelLayer?: DrawPixelLayer, drawScreenLayer?: DrawScreenLayer) => void;
596
+ declare function makeCanvasFrameRenderer(deps?: Deps$c): (pixelCanvas: PixelCanvas, scale: number, getImageData: () => ImageData | undefined | null, drawPixelLayer?: DrawPixelLayer, drawScreenLayer?: DrawScreenLayer) => void;
578
597
 
579
598
  /**
580
599
  * Extracts {@link ImageData} from a clipboard event if an image is present.
@@ -854,14 +873,14 @@ declare function makeFullPixelMutator(writer: PixelWriter<any>): {
854
873
  */
855
874
  declare function applyAlphaMaskToPixelData(dst: IPixelData32, mask: AlphaMask, opts?: ApplyMaskToPixelDataOptions): boolean;
856
875
 
857
- declare const defaults$a: {
876
+ declare const defaults$b: {
858
877
  applyAlphaMaskToPixelData: typeof applyAlphaMaskToPixelData;
859
878
  };
860
- type Deps$a = Partial<typeof defaults$a>;
879
+ type Deps$b = Partial<typeof defaults$b>;
861
880
  /**
862
881
  * @param deps - @hidden
863
882
  */
864
- declare const mutatorApplyAlphaMask: (writer: PixelWriter<any>, deps?: Deps$a) => {
883
+ declare const mutatorApplyAlphaMask: (writer: PixelWriter<any>, deps?: Deps$b) => {
865
884
  applyAlphaMask(mask: AlphaMask, opts?: ApplyMaskToPixelDataOptions): boolean;
866
885
  };
867
886
 
@@ -872,14 +891,14 @@ declare const mutatorApplyAlphaMask: (writer: PixelWriter<any>, deps?: Deps$a) =
872
891
  */
873
892
  declare function applyBinaryMaskToPixelData(dst: IPixelData32, mask: BinaryMask, opts?: ApplyMaskToPixelDataOptions): boolean;
874
893
 
875
- declare const defaults$9: {
894
+ declare const defaults$a: {
876
895
  applyBinaryMaskToPixelData: typeof applyBinaryMaskToPixelData;
877
896
  };
878
- type Deps$9 = Partial<typeof defaults$9>;
897
+ type Deps$a = Partial<typeof defaults$a>;
879
898
  /**
880
899
  * @param deps - @hidden
881
900
  */
882
- declare const mutatorApplyBinaryMask: (writer: PixelWriter<any>, deps?: Deps$9) => {
901
+ declare const mutatorApplyBinaryMask: (writer: PixelWriter<any>, deps?: Deps$a) => {
883
902
  applyBinaryMask(mask: BinaryMask, opts?: ApplyMaskToPixelDataOptions): boolean;
884
903
  };
885
904
 
@@ -889,17 +908,59 @@ declare const mutatorApplyBinaryMask: (writer: PixelWriter<any>, deps?: Deps$9)
889
908
  */
890
909
  declare function blendColorPixelData(dst: IPixelData32, color: Color32, opts?: ColorBlendOptions): boolean;
891
910
 
892
- declare const defaults$8: {
911
+ declare const defaults$9: {
893
912
  blendColorPixelData: typeof blendColorPixelData;
894
913
  };
895
- type Deps$8 = Partial<typeof defaults$8>;
914
+ type Deps$9 = Partial<typeof defaults$9>;
896
915
  /**
897
916
  * @param deps - @hidden
898
917
  */
899
- declare const mutatorBlendColor: (writer: PixelWriter<any>, deps?: Deps$8) => {
918
+ declare const mutatorBlendColor: (writer: PixelWriter<any>, deps?: Deps$9) => {
900
919
  blendColor(color: Color32, opts?: ColorBlendOptions): boolean;
901
920
  };
902
921
 
922
+ /**
923
+ * Blends a solid color into a target pixel buffer using an alpha mask.
924
+ *
925
+ * @remarks
926
+ * If the width (`w`) or height (`h`) are omitted from the options, they will safely
927
+ * default to the dimensions of the provided mask to prevent out-of-bounds memory access.
928
+ *
929
+ * @param dst - The destination {@link IPixelData32} buffer to modify.
930
+ * @param color - The solid color to apply.
931
+ * @param mask - The mask defining the per-pixel opacity of the target area.
932
+ * @param opts - Configuration options including placement coordinates, bounds, global alpha, and mask offsets.
933
+ * @returns true if any pixels were actually modified.
934
+ */
935
+ declare function blendColorPixelDataAlphaMask(dst: IPixelData32, color: Color32, mask: AlphaMask, opts?: ColorBlendMaskOptions): boolean;
936
+
937
+ /**
938
+ * Blends a solid color into a target pixel buffer using a binary mask.
939
+ *
940
+ * @remarks
941
+ * If the width (`w`) or height (`h`) are omitted from the options, they will safely
942
+ * default to the dimensions of the provided mask to prevent out-of-bounds memory access.
943
+ *
944
+ * @param dst - The destination {@link IPixelData32} buffer to modify.
945
+ * @param color - The solid color to apply.
946
+ * @param mask - The mask defining the per-pixel opacity of the target area.
947
+ * @param opts - Configuration options including placement coordinates, bounds, global alpha, and mask offsets.
948
+ * @returns true if any pixels were actually modified.
949
+ */
950
+ declare function blendColorPixelDataBinaryMask(dst: IPixelData32, color: Color32, mask: BinaryMask, opts?: ColorBlendMaskOptions): boolean;
951
+
952
+ declare const defaults$8: {
953
+ blendColorPixelDataAlphaMask: typeof blendColorPixelDataAlphaMask;
954
+ blendColorPixelDataBinaryMask: typeof blendColorPixelDataBinaryMask;
955
+ };
956
+ type Deps$8 = Partial<typeof defaults$8>;
957
+ /**
958
+ * @param deps - @hidden
959
+ */
960
+ declare const mutatorBlendPaintMask: (writer: PixelWriter<any>, deps?: Partial<Deps$8>) => {
961
+ blendColorPaintMask(color: Color32, mask: PaintMask, x: number, y: number, alpha?: number, blendFn?: BlendColor32): boolean;
962
+ };
963
+
903
964
  declare function blendPixel(target: IPixelData32, x: number, y: number, color: Color32, alpha?: number, blendFn?: BlendColor32): boolean;
904
965
 
905
966
  declare const defaults$7: {
@@ -1485,36 +1546,6 @@ declare function mergeBinaryMaskRects(current: NullableBinaryMaskRect[], adding:
1485
1546
 
1486
1547
  declare function subtractBinaryMaskRects(current: NullableBinaryMaskRect[], subtracting: NullableBinaryMaskRect[]): NullableBinaryMaskRect[];
1487
1548
 
1488
- /**
1489
- * Blends a solid color into a target pixel buffer using an alpha mask.
1490
- *
1491
- * @remarks
1492
- * If the width (`w`) or height (`h`) are omitted from the options, they will safely
1493
- * default to the dimensions of the provided mask to prevent out-of-bounds memory access.
1494
- *
1495
- * @param dst - The destination {@link IPixelData32} buffer to modify.
1496
- * @param color - The solid color to apply.
1497
- * @param mask - The mask defining the per-pixel opacity of the target area.
1498
- * @param opts - Configuration options including placement coordinates, bounds, global alpha, and mask offsets.
1499
- * @returns true if any pixels were actually modified.
1500
- */
1501
- declare function blendColorPixelDataAlphaMask(dst: IPixelData32, color: Color32, mask: AlphaMask, opts?: ColorBlendMaskOptions): boolean;
1502
-
1503
- /**
1504
- * Blends a solid color into a target pixel buffer using a binary mask.
1505
- *
1506
- * @remarks
1507
- * If the width (`w`) or height (`h`) are omitted from the options, they will safely
1508
- * default to the dimensions of the provided mask to prevent out-of-bounds memory access.
1509
- *
1510
- * @param dst - The destination {@link IPixelData32} buffer to modify.
1511
- * @param color - The solid color to apply.
1512
- * @param mask - The mask defining the per-pixel opacity of the target area.
1513
- * @param opts - Configuration options including placement coordinates, bounds, global alpha, and mask offsets.
1514
- * @returns true if any pixels were actually modified.
1515
- */
1516
- declare function blendColorPixelDataBinaryMask(dst: IPixelData32, color: Color32, mask: BinaryMask, opts?: ColorBlendMaskOptions): boolean;
1517
-
1518
1549
  declare function blendPixelDataPaintBuffer(paintBuffer: PaintBuffer, target: IPixelData32, alpha?: number, blendFn?: BlendColor32, blendPixelDataFn?: typeof blendPixelData): void;
1519
1550
 
1520
1551
  /**
@@ -1621,4 +1652,4 @@ declare function makePaintBufferCanvasRenderer(paintBuffer: PaintBuffer, offscre
1621
1652
  prototype: OffscreenCanvas;
1622
1653
  }): (targetCtx: CanvasRenderingContext2D, alpha?: number, compOperation?: GlobalCompositeOperation) => void;
1623
1654
 
1624
- export { type AlphaMask, type AlphaMaskRect, 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 CanvasContext, type CanvasFrameRenderer, type Color32, type ColorBlendMaskOptions, type ColorBlendOptions, type DidChangeFn, type DrawPixelLayer, type DrawScreenLayer, type FloodFillImageDataOptions, type FloodFillResult, type HistoryAction, type HistoryActionFactory, HistoryManager, type HistoryMutator, type IPixelData, type IPixelData32, type ImageDataLike, type ImageDataLikeConstructor, IndexedImage, type InvertMask, type Mask, type MaskOffset, type MaskRect, MaskType, type MergeAlphaMasksOptions, type NullableBinaryMaskRect, type NullableMaskRect, OFFSCREEN_CANVAS_CTX_FAILED, type PaintAlphaMask, type PaintBinaryMask, PaintBuffer, type PaintBufferCanvasRenderer, type PaintMask, PixelAccumulator, type PixelBlendMaskOptions, type PixelBlendOptions, PixelBuffer32, type PixelCanvas, PixelData, PixelEngineConfig, type PixelMutateOptions, type PixelPatchTiles, type PixelRect, PixelTile, PixelTilePool, PixelWriter, type PixelWriterOptions, type RGBA, type Rect, type RequiredBlendModes, type ReusableCanvas, type ReusableImageData, type SerializedImageData, UnsupportedFormatError, applyAlphaMaskToPixelData, applyBinaryMaskToAlphaMask, applyBinaryMaskToPixelData, applyPatchTiles, base64DecodeArrayBuffer, base64EncodeArrayBuffer, blendColorPixelData, blendColorPixelDataAlphaMask, blendColorPixelDataBinaryMask, blendPixel, blendPixelData, blendPixelDataAlphaMask, blendPixelDataBinaryMask, blendPixelDataPaintBuffer, 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, extractMaskBuffer, extractPixelData, extractPixelDataBuffer, fileInputChangeToImageData, fileToImageData, fillPixelData, fillPixelDataBinaryMask, fillPixelDataFast, floodFillSelection, forEachLinePoint, getImageDataFromClipboard, getIndexedImageColorCounts, getRectsBounds, getSupportedPixelFormats, hardLightFast, hardLightPerfect, hardMixFast, hardMixPerfect, imageDataToAlphaMaskBuffer, imageDataToDataUrl, imageDataToImgBlob, imageDataToUInt32Array, imgBlobToImageData, indexedImageToAverageColor, indexedImageToImageData, invertAlphaMask, invertBinaryMask, invertImageData, invertPixelData, lerpColor32, lerpColor32Fast, lightenFast, lightenPerfect, lighterFast, lighterPerfect, linearBurnFast, linearBurnPerfect, linearDodgeFast, linearDodgePerfect, linearLightFast, linearLightPerfect, makeAlphaMask, makeBinaryMask, makeBlendModeRegistry, makeCanvasFrameRenderer, makeCirclePaintAlphaMask, makeCirclePaintBinaryMask, makeFastBlendModeRegistry, makeFullPixelMutator, makeHistoryAction, makeImageDataLike, makePaintAlphaMask, makePaintBinaryMask, makePaintBufferCanvasRenderer, makePerfectBlendModeRegistry, makePixelCanvas, makeRectFalloffPaintAlphaMask, makeReusableCanvas, makeReusableImageData, makeReusableOffscreenCanvas, merge2BinaryMaskRects, mergeAlphaMasks, mergeBinaryMaskRects, mergeBinaryMasks, multiplyFast, multiplyPerfect, mutatorApplyAlphaMask, mutatorApplyBinaryMask, mutatorBlendColor, mutatorBlendPixel, mutatorBlendPixelData, mutatorBlendPixelDataAlphaMask, mutatorBlendPixelDataBinaryMask, mutatorClear, mutatorFill, mutatorFillBinaryMask, mutatorFillRect, mutatorInvert, overlayFast, overlayPerfect, overwriteBase, overwriteFast, overwritePerfect, packColor, packRGBA, pinLightFast, pinLightPerfect, pixelDataToAlphaMask, reflectPixelDataHorizontal, reflectPixelDataVertical, resampleImageData, resampleIndexedImage, resamplePixelData, resizeImageData, rotatePixelData, screenFast, screenPerfect, serializeImageData, serializeNullableImageData, setMaskData, softLightFast, softLightPerfect, sourceOverFast, sourceOverPerfect, subtractBinaryMaskRects, subtractFast, subtractPerfect, toBlendModeIndexAndName, trimMaskRectBounds, trimRectBounds, uInt32ArrayToImageData, uInt32ArrayToImageDataLike, unpackAlpha, unpackBlue, unpackColor, unpackColorTo, unpackGreen, unpackRed, vividLightFast, vividLightPerfect, writeImageData, writeImageDataBuffer, writeImageDataToClipboard, writeImgBlobToClipboard, writePaintBufferToPixelData, writePixelDataBuffer };
1655
+ export { type AlphaMask, type AlphaMaskRect, 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_COMPOSITE_MAP, CANVAS_CTX_FAILED, type CanvasBlendModeIndex, type CanvasCompositeOperation, type CanvasContext, type CanvasFrameRenderer, type Color32, type ColorBlendMaskOptions, type ColorBlendOptions, type DidChangeFn, type DrawPixelLayer, type DrawScreenLayer, type FloodFillImageDataOptions, type FloodFillResult, type HistoryAction, type HistoryActionFactory, HistoryManager, type HistoryMutator, type IPixelData, type IPixelData32, type ImageDataLike, type ImageDataLikeConstructor, IndexedImage, type InvertMask, type Mask, type MaskOffset, type MaskRect, MaskType, type MergeAlphaMasksOptions, type NullableBinaryMaskRect, type NullableMaskRect, OFFSCREEN_CANVAS_CTX_FAILED, type PaintAlphaMask, type PaintBinaryMask, PaintBuffer, type PaintBufferCanvasRenderer, type PaintMask, PixelAccumulator, type PixelBlendMaskOptions, type PixelBlendOptions, PixelBuffer32, type PixelCanvas, PixelData, PixelEngineConfig, type PixelMutateOptions, type PixelPatchTiles, type PixelRect, PixelTile, PixelTilePool, PixelWriter, type PixelWriterOptions, type RGBA, type Rect, type RequiredBlendModes, type ReusableCanvas, type ReusableImageData, type SerializedImageData, UnsupportedFormatError, applyAlphaMaskToPixelData, applyBinaryMaskToAlphaMask, applyBinaryMaskToPixelData, applyPatchTiles, base64DecodeArrayBuffer, base64EncodeArrayBuffer, blendColorPixelData, blendColorPixelDataAlphaMask, blendColorPixelDataBinaryMask, blendPixel, blendPixelData, blendPixelDataAlphaMask, blendPixelDataBinaryMask, blendPixelDataPaintBuffer, 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, extractMaskBuffer, extractPixelData, extractPixelDataBuffer, fileInputChangeToImageData, fileToImageData, fillPixelData, fillPixelDataBinaryMask, fillPixelDataFast, floodFillSelection, forEachLinePoint, getImageDataFromClipboard, getIndexedImageColorCounts, getRectsBounds, getSupportedPixelFormats, hardLightFast, hardLightPerfect, hardMixFast, hardMixPerfect, imageDataToAlphaMaskBuffer, imageDataToDataUrl, imageDataToImgBlob, imageDataToUInt32Array, imgBlobToImageData, indexedImageToAverageColor, indexedImageToImageData, invertAlphaMask, invertBinaryMask, invertImageData, invertPixelData, lerpColor32, lerpColor32Fast, lightenFast, lightenPerfect, lighterFast, lighterPerfect, linearBurnFast, linearBurnPerfect, linearDodgeFast, linearDodgePerfect, linearLightFast, linearLightPerfect, makeAlphaMask, makeBinaryMask, makeBlendModeRegistry, makeCanvasFrameRenderer, makeCirclePaintAlphaMask, makeCirclePaintBinaryMask, makeFastBlendModeRegistry, makeFullPixelMutator, makeHistoryAction, makeImageDataLike, makePaintAlphaMask, makePaintBinaryMask, makePaintBufferCanvasRenderer, makePerfectBlendModeRegistry, makePixelCanvas, makeRectFalloffPaintAlphaMask, makeReusableCanvas, makeReusableImageData, makeReusableOffscreenCanvas, merge2BinaryMaskRects, mergeAlphaMasks, mergeBinaryMaskRects, mergeBinaryMasks, multiplyFast, multiplyPerfect, mutatorApplyAlphaMask, mutatorApplyBinaryMask, mutatorBlendColor, mutatorBlendPaintMask, mutatorBlendPixel, mutatorBlendPixelData, mutatorBlendPixelDataAlphaMask, mutatorBlendPixelDataBinaryMask, mutatorClear, mutatorFill, mutatorFillBinaryMask, mutatorFillRect, mutatorInvert, overlayFast, overlayPerfect, overwriteBase, overwriteFast, overwritePerfect, packColor, packRGBA, pinLightFast, pinLightPerfect, pixelDataToAlphaMask, reflectPixelDataHorizontal, reflectPixelDataVertical, resampleImageData, resampleIndexedImage, resamplePixelData, resizeImageData, rotatePixelData, screenFast, screenPerfect, serializeImageData, serializeNullableImageData, setMaskData, softLightFast, softLightPerfect, sourceOverFast, sourceOverPerfect, subtractBinaryMaskRects, subtractFast, subtractPerfect, toBlendModeIndexAndName, trimMaskRectBounds, trimRectBounds, uInt32ArrayToImageData, uInt32ArrayToImageDataLike, unpackAlpha, unpackBlue, unpackColor, unpackColorTo, unpackGreen, unpackRed, vividLightFast, vividLightPerfect, writeImageData, writeImageDataBuffer, writeImageDataToClipboard, writeImgBlobToClipboard, writePaintBufferToPixelData, writePixelDataBuffer };
@@ -1533,6 +1533,24 @@ var getKeyByValue = (obj, value) => {
1533
1533
  var OFFSCREEN_CANVAS_CTX_FAILED = "Failed to create OffscreenCanvas context";
1534
1534
  var CANVAS_CTX_FAILED = "Failed to create Canvas context";
1535
1535
 
1536
+ // src/Canvas/canvas-blend-modes.ts
1537
+ var CANVAS_COMPOSITE_MAP = {
1538
+ [BaseBlendMode.overwrite]: "copy",
1539
+ [BaseBlendMode.sourceOver]: "source-over",
1540
+ [BaseBlendMode.darken]: "darken",
1541
+ [BaseBlendMode.multiply]: "multiply",
1542
+ [BaseBlendMode.colorBurn]: "color-burn",
1543
+ [BaseBlendMode.lighten]: "lighten",
1544
+ [BaseBlendMode.screen]: "screen",
1545
+ [BaseBlendMode.colorDodge]: "color-dodge",
1546
+ [BaseBlendMode.linearDodge]: "lighter",
1547
+ [BaseBlendMode.overlay]: "overlay",
1548
+ [BaseBlendMode.softLight]: "soft-light",
1549
+ [BaseBlendMode.hardLight]: "hard-light",
1550
+ [BaseBlendMode.difference]: "difference",
1551
+ [BaseBlendMode.exclusion]: "exclusion"
1552
+ };
1553
+
1536
1554
  // src/Canvas/ReusableCanvas.ts
1537
1555
  function makeReusableCanvas() {
1538
1556
  return makeReusableCanvasMeta((w, h) => {
@@ -3420,6 +3438,196 @@ var mutatorApplyBinaryMask = ((writer, deps = defaults12) => {
3420
3438
  };
3421
3439
  });
3422
3440
 
3441
+ // src/PixelData/blendColorPixelDataAlphaMask.ts
3442
+ function blendColorPixelDataAlphaMask(dst, color, mask, opts = {}) {
3443
+ const targetX = opts.x ?? 0;
3444
+ const targetY = opts.y ?? 0;
3445
+ const w = opts.w ?? mask.w;
3446
+ const h = opts.h ?? mask.h;
3447
+ const globalAlpha = opts.alpha ?? 255;
3448
+ const blendFn = opts.blendFn ?? sourceOverPerfect;
3449
+ const mx = opts.mx ?? 0;
3450
+ const my = opts.my ?? 0;
3451
+ const invertMask = opts.invertMask ?? false;
3452
+ if (globalAlpha === 0) return false;
3453
+ const baseSrcAlpha = color >>> 24;
3454
+ const isOverwrite = blendFn.isOverwrite || false;
3455
+ if (baseSrcAlpha === 0 && !isOverwrite) return false;
3456
+ let x = targetX;
3457
+ let y = targetY;
3458
+ let actualW = w;
3459
+ let actualH = h;
3460
+ if (x < 0) {
3461
+ actualW += x;
3462
+ x = 0;
3463
+ }
3464
+ if (y < 0) {
3465
+ actualH += y;
3466
+ y = 0;
3467
+ }
3468
+ actualW = Math.min(actualW, dst.width - x);
3469
+ actualH = Math.min(actualH, dst.height - y);
3470
+ if (actualW <= 0 || actualH <= 0) return false;
3471
+ const dx = x - targetX | 0;
3472
+ const dy = y - targetY | 0;
3473
+ const dst32 = dst.data32;
3474
+ const dw = dst.width;
3475
+ const mPitch = mask.w;
3476
+ const maskData = mask.data;
3477
+ let dIdx = y * dw + x | 0;
3478
+ let mIdx = (my + dy) * mPitch + (mx + dx) | 0;
3479
+ const dStride = dw - actualW | 0;
3480
+ const mStride = mPitch - actualW | 0;
3481
+ const isOpaque = globalAlpha === 255;
3482
+ const colorRGB = color & 16777215;
3483
+ let didChange = false;
3484
+ for (let iy = 0; iy < actualH; iy++) {
3485
+ for (let ix = 0; ix < actualW; ix++) {
3486
+ const mVal = maskData[mIdx];
3487
+ const effM = invertMask ? 255 - mVal : mVal;
3488
+ if (effM === 0) {
3489
+ dIdx++;
3490
+ mIdx++;
3491
+ continue;
3492
+ }
3493
+ let weight = globalAlpha;
3494
+ if (isOpaque) {
3495
+ weight = effM;
3496
+ } else if (effM !== 255) {
3497
+ weight = effM * globalAlpha + 128 >> 8;
3498
+ }
3499
+ if (weight === 0) {
3500
+ dIdx++;
3501
+ mIdx++;
3502
+ continue;
3503
+ }
3504
+ let finalCol = color;
3505
+ if (weight < 255) {
3506
+ const a = baseSrcAlpha * weight + 128 >> 8;
3507
+ if (a === 0 && !isOverwrite) {
3508
+ dIdx++;
3509
+ mIdx++;
3510
+ continue;
3511
+ }
3512
+ finalCol = (colorRGB | a << 24) >>> 0;
3513
+ }
3514
+ const current = dst32[dIdx];
3515
+ const next = blendFn(finalCol, current);
3516
+ if (current !== next) {
3517
+ dst32[dIdx] = next;
3518
+ didChange = true;
3519
+ }
3520
+ dIdx++;
3521
+ mIdx++;
3522
+ }
3523
+ dIdx += dStride;
3524
+ mIdx += mStride;
3525
+ }
3526
+ return didChange;
3527
+ }
3528
+
3529
+ // src/PixelData/blendColorPixelDataBinaryMask.ts
3530
+ function blendColorPixelDataBinaryMask(dst, color, mask, opts = {}) {
3531
+ const targetX = opts.x ?? 0;
3532
+ const targetY = opts.y ?? 0;
3533
+ let w = opts.w ?? mask.w;
3534
+ let h = opts.h ?? mask.h;
3535
+ const globalAlpha = opts.alpha ?? 255;
3536
+ const blendFn = opts.blendFn ?? sourceOverPerfect;
3537
+ const mx = opts.mx ?? 0;
3538
+ const my = opts.my ?? 0;
3539
+ const invertMask = opts.invertMask ?? false;
3540
+ if (globalAlpha === 0) return false;
3541
+ const baseSrcAlpha = color >>> 24;
3542
+ const isOverwrite = blendFn.isOverwrite || false;
3543
+ if (baseSrcAlpha === 0 && !isOverwrite) return false;
3544
+ let x = targetX;
3545
+ let y = targetY;
3546
+ if (x < 0) {
3547
+ w += x;
3548
+ x = 0;
3549
+ }
3550
+ if (y < 0) {
3551
+ h += y;
3552
+ y = 0;
3553
+ }
3554
+ const actualW = Math.min(w, dst.width - x);
3555
+ const actualH = Math.min(h, dst.height - y);
3556
+ if (actualW <= 0 || actualH <= 0) return false;
3557
+ let baseColorWithGlobalAlpha = color;
3558
+ if (globalAlpha < 255) {
3559
+ const a = baseSrcAlpha * globalAlpha + 128 >> 8;
3560
+ if (a === 0 && !isOverwrite) return false;
3561
+ baseColorWithGlobalAlpha = (color & 16777215 | a << 24) >>> 0;
3562
+ }
3563
+ const dx = x - targetX | 0;
3564
+ const dy = y - targetY | 0;
3565
+ const dst32 = dst.data32;
3566
+ const dw = dst.width;
3567
+ const mPitch = mask.w;
3568
+ const maskData = mask.data;
3569
+ let dIdx = y * dw + x | 0;
3570
+ let mIdx = (my + dy) * mPitch + (mx + dx) | 0;
3571
+ const dStride = dw - actualW | 0;
3572
+ const mStride = mPitch - actualW | 0;
3573
+ const skipVal = invertMask ? 1 : 0;
3574
+ let didChange = false;
3575
+ for (let iy = 0; iy < actualH; iy++) {
3576
+ for (let ix = 0; ix < actualW; ix++) {
3577
+ if (maskData[mIdx] === skipVal) {
3578
+ dIdx++;
3579
+ mIdx++;
3580
+ continue;
3581
+ }
3582
+ const current = dst32[dIdx];
3583
+ const next = blendFn(baseColorWithGlobalAlpha, current);
3584
+ if (current !== next) {
3585
+ dst32[dIdx] = next;
3586
+ didChange = true;
3587
+ }
3588
+ dIdx++;
3589
+ mIdx++;
3590
+ }
3591
+ dIdx += dStride;
3592
+ mIdx += mStride;
3593
+ }
3594
+ return didChange;
3595
+ }
3596
+
3597
+ // src/History/PixelMutator/mutatorBlendPaintMask.ts
3598
+ var defaults13 = {
3599
+ blendColorPixelDataAlphaMask,
3600
+ blendColorPixelDataBinaryMask
3601
+ };
3602
+ var mutatorBlendPaintMask = ((writer, deps = defaults13) => {
3603
+ const {
3604
+ blendColorPixelDataBinaryMask: blendColorPixelDataBinaryMask2 = defaults13.blendColorPixelDataBinaryMask,
3605
+ blendColorPixelDataAlphaMask: blendColorPixelDataAlphaMask2 = defaults13.blendColorPixelDataAlphaMask
3606
+ } = deps;
3607
+ const OPTS = {
3608
+ x: 0,
3609
+ y: 0,
3610
+ blendFn: sourceOverPerfect,
3611
+ alpha: 255
3612
+ };
3613
+ return {
3614
+ blendColorPaintMask(color, mask, x, y, alpha = 255, blendFn = sourceOverPerfect) {
3615
+ const tx = x + mask.centerOffsetX;
3616
+ const ty = y + mask.centerOffsetY;
3617
+ const didChange = writer.accumulator.storeRegionBeforeState(tx, ty, mask.w, mask.h);
3618
+ OPTS.x = tx;
3619
+ OPTS.y = ty;
3620
+ OPTS.alpha = alpha;
3621
+ OPTS.blendFn = blendFn;
3622
+ if (mask.type === 1 /* BINARY */) {
3623
+ return didChange(blendColorPixelDataBinaryMask2(writer.config.target, color, mask, OPTS));
3624
+ } else {
3625
+ return didChange(blendColorPixelDataAlphaMask2(writer.config.target, color, mask, OPTS));
3626
+ }
3627
+ }
3628
+ };
3629
+ });
3630
+
3423
3631
  // src/ImageData/copyImageData.ts
3424
3632
  function copyImageData({
3425
3633
  data,
@@ -4409,162 +4617,6 @@ var PixelData = class {
4409
4617
  }
4410
4618
  };
4411
4619
 
4412
- // src/PixelData/blendColorPixelDataAlphaMask.ts
4413
- function blendColorPixelDataAlphaMask(dst, color, mask, opts = {}) {
4414
- const targetX = opts.x ?? 0;
4415
- const targetY = opts.y ?? 0;
4416
- const w = opts.w ?? mask.w;
4417
- const h = opts.h ?? mask.h;
4418
- const globalAlpha = opts.alpha ?? 255;
4419
- const blendFn = opts.blendFn ?? sourceOverPerfect;
4420
- const mx = opts.mx ?? 0;
4421
- const my = opts.my ?? 0;
4422
- const invertMask = opts.invertMask ?? false;
4423
- if (globalAlpha === 0) return false;
4424
- const baseSrcAlpha = color >>> 24;
4425
- const isOverwrite = blendFn.isOverwrite || false;
4426
- if (baseSrcAlpha === 0 && !isOverwrite) return false;
4427
- let x = targetX;
4428
- let y = targetY;
4429
- let actualW = w;
4430
- let actualH = h;
4431
- if (x < 0) {
4432
- actualW += x;
4433
- x = 0;
4434
- }
4435
- if (y < 0) {
4436
- actualH += y;
4437
- y = 0;
4438
- }
4439
- actualW = Math.min(actualW, dst.width - x);
4440
- actualH = Math.min(actualH, dst.height - y);
4441
- if (actualW <= 0 || actualH <= 0) return false;
4442
- const dx = x - targetX | 0;
4443
- const dy = y - targetY | 0;
4444
- const dst32 = dst.data32;
4445
- const dw = dst.width;
4446
- const mPitch = mask.w;
4447
- const maskData = mask.data;
4448
- let dIdx = y * dw + x | 0;
4449
- let mIdx = (my + dy) * mPitch + (mx + dx) | 0;
4450
- const dStride = dw - actualW | 0;
4451
- const mStride = mPitch - actualW | 0;
4452
- const isOpaque = globalAlpha === 255;
4453
- const colorRGB = color & 16777215;
4454
- let didChange = false;
4455
- for (let iy = 0; iy < actualH; iy++) {
4456
- for (let ix = 0; ix < actualW; ix++) {
4457
- const mVal = maskData[mIdx];
4458
- const effM = invertMask ? 255 - mVal : mVal;
4459
- if (effM === 0) {
4460
- dIdx++;
4461
- mIdx++;
4462
- continue;
4463
- }
4464
- let weight = globalAlpha;
4465
- if (isOpaque) {
4466
- weight = effM;
4467
- } else if (effM !== 255) {
4468
- weight = effM * globalAlpha + 128 >> 8;
4469
- }
4470
- if (weight === 0) {
4471
- dIdx++;
4472
- mIdx++;
4473
- continue;
4474
- }
4475
- let finalCol = color;
4476
- if (weight < 255) {
4477
- const a = baseSrcAlpha * weight + 128 >> 8;
4478
- if (a === 0 && !isOverwrite) {
4479
- dIdx++;
4480
- mIdx++;
4481
- continue;
4482
- }
4483
- finalCol = (colorRGB | a << 24) >>> 0;
4484
- }
4485
- const current = dst32[dIdx];
4486
- const next = blendFn(finalCol, current);
4487
- if (current !== next) {
4488
- dst32[dIdx] = next;
4489
- didChange = true;
4490
- }
4491
- dIdx++;
4492
- mIdx++;
4493
- }
4494
- dIdx += dStride;
4495
- mIdx += mStride;
4496
- }
4497
- return didChange;
4498
- }
4499
-
4500
- // src/PixelData/blendColorPixelDataBinaryMask.ts
4501
- function blendColorPixelDataBinaryMask(dst, color, mask, opts = {}) {
4502
- const targetX = opts.x ?? 0;
4503
- const targetY = opts.y ?? 0;
4504
- let w = opts.w ?? mask.w;
4505
- let h = opts.h ?? mask.h;
4506
- const globalAlpha = opts.alpha ?? 255;
4507
- const blendFn = opts.blendFn ?? sourceOverPerfect;
4508
- const mx = opts.mx ?? 0;
4509
- const my = opts.my ?? 0;
4510
- const invertMask = opts.invertMask ?? false;
4511
- if (globalAlpha === 0) return false;
4512
- const baseSrcAlpha = color >>> 24;
4513
- const isOverwrite = blendFn.isOverwrite || false;
4514
- if (baseSrcAlpha === 0 && !isOverwrite) return false;
4515
- let x = targetX;
4516
- let y = targetY;
4517
- if (x < 0) {
4518
- w += x;
4519
- x = 0;
4520
- }
4521
- if (y < 0) {
4522
- h += y;
4523
- y = 0;
4524
- }
4525
- const actualW = Math.min(w, dst.width - x);
4526
- const actualH = Math.min(h, dst.height - y);
4527
- if (actualW <= 0 || actualH <= 0) return false;
4528
- let baseColorWithGlobalAlpha = color;
4529
- if (globalAlpha < 255) {
4530
- const a = baseSrcAlpha * globalAlpha + 128 >> 8;
4531
- if (a === 0 && !isOverwrite) return false;
4532
- baseColorWithGlobalAlpha = (color & 16777215 | a << 24) >>> 0;
4533
- }
4534
- const dx = x - targetX | 0;
4535
- const dy = y - targetY | 0;
4536
- const dst32 = dst.data32;
4537
- const dw = dst.width;
4538
- const mPitch = mask.w;
4539
- const maskData = mask.data;
4540
- let dIdx = y * dw + x | 0;
4541
- let mIdx = (my + dy) * mPitch + (mx + dx) | 0;
4542
- const dStride = dw - actualW | 0;
4543
- const mStride = mPitch - actualW | 0;
4544
- const skipVal = invertMask ? 1 : 0;
4545
- let didChange = false;
4546
- for (let iy = 0; iy < actualH; iy++) {
4547
- for (let ix = 0; ix < actualW; ix++) {
4548
- if (maskData[mIdx] === skipVal) {
4549
- dIdx++;
4550
- mIdx++;
4551
- continue;
4552
- }
4553
- const current = dst32[dIdx];
4554
- const next = blendFn(baseColorWithGlobalAlpha, current);
4555
- if (current !== next) {
4556
- dst32[dIdx] = next;
4557
- didChange = true;
4558
- }
4559
- dIdx++;
4560
- mIdx++;
4561
- }
4562
- dIdx += dStride;
4563
- mIdx += mStride;
4564
- }
4565
- return didChange;
4566
- }
4567
-
4568
4620
  // src/PixelData/blendPixelDataPaintBuffer.ts
4569
4621
  var SCRATCH_OPTS = {
4570
4622
  x: 0,
@@ -4892,8 +4944,8 @@ function makePaintBinaryMask(mask) {
4892
4944
  data: mask.data,
4893
4945
  w: mask.w,
4894
4946
  h: mask.h,
4895
- centerOffsetX: -macro_halfAndFloor(mask.w),
4896
- centerOffsetY: -macro_halfAndFloor(mask.h)
4947
+ centerOffsetX: -(mask.w >> 1),
4948
+ centerOffsetY: -(mask.h >> 1)
4897
4949
  };
4898
4950
  }
4899
4951
  function makePaintAlphaMask(mask) {
@@ -4902,8 +4954,8 @@ function makePaintAlphaMask(mask) {
4902
4954
  data: mask.data,
4903
4955
  w: mask.w,
4904
4956
  h: mask.h,
4905
- centerOffsetX: -macro_halfAndFloor(mask.w),
4906
- centerOffsetY: -macro_halfAndFloor(mask.h)
4957
+ centerOffsetX: -(mask.w >> 1),
4958
+ centerOffsetY: -(mask.h >> 1)
4907
4959
  };
4908
4960
  }
4909
4961
 
@@ -4935,8 +4987,8 @@ function makeRectFalloffPaintAlphaMask(width, height, fallOff = (d) => d) {
4935
4987
  data,
4936
4988
  w: width,
4937
4989
  h: height,
4938
- centerOffsetX: -(width >> 1),
4939
- centerOffsetY: -(height >> 1)
4990
+ centerOffsetX: -macro_halfAndFloor(width),
4991
+ centerOffsetY: -macro_halfAndFloor(height)
4940
4992
  };
4941
4993
  }
4942
4994
 
@@ -4970,6 +5022,7 @@ export {
4970
5022
  BASE_FAST_BLEND_MODE_FUNCTIONS,
4971
5023
  BASE_PERFECT_BLEND_MODE_FUNCTIONS,
4972
5024
  BaseBlendMode,
5025
+ CANVAS_COMPOSITE_MAP,
4973
5026
  CANVAS_CTX_FAILED,
4974
5027
  HistoryManager,
4975
5028
  IndexedImage,
@@ -5093,6 +5146,7 @@ export {
5093
5146
  mutatorApplyAlphaMask,
5094
5147
  mutatorApplyBinaryMask,
5095
5148
  mutatorBlendColor,
5149
+ mutatorBlendPaintMask,
5096
5150
  mutatorBlendPixel,
5097
5151
  mutatorBlendPixelData,
5098
5152
  mutatorBlendPixelDataAlphaMask,