feat: implement inpainting functionality with mask handling
- Added `createMaskedPixelReplacementSource` function to handle pixel replacement using inpainting. - Introduced `buildInpaintBundle` to prepare inpainting data including mask generation and validation. - Created utility functions for mask operations such as `applyMaskedContentModeToRgba`, `expandRectWithinBounds`, and others for mask manipulation. - Developed tests for inpainting preparation and mask raster utilities to ensure functionality and correctness. - Implemented mask raster operations including inversion, feathering, blurring, and more.
This commit is contained in:
@@ -8,6 +8,7 @@ import {
|
||||
documentAddImageLayerCommand,
|
||||
documentAddLayerMaskCommand,
|
||||
documentAddRasterLayerCommand,
|
||||
documentApplyLayerMaskOperationCommand,
|
||||
documentGroupLayersCommand,
|
||||
documentMoveLayerCommand,
|
||||
documentRemoveArtboardCommand,
|
||||
@@ -236,6 +237,30 @@ describe("document commands", () => {
|
||||
expect(unmasked.editor.maskEdit).toBeUndefined();
|
||||
});
|
||||
|
||||
test("applies operations only to attached layer mask assets", () => {
|
||||
const state = documentAddLayerMaskCommand.execute(
|
||||
{ state: documentWithLayers([raster("target", "Target"), raster("loose", "Loose", "loose-asset")]) },
|
||||
{ layerId: "target", asset: maskAsset(), maskLayer: raster("mask", "Target Mask", "mask-asset") },
|
||||
);
|
||||
const withLooseAsset = documentAddAssetCommand.execute(
|
||||
{ state },
|
||||
{ asset: { id: "loose-asset", name: "Loose", mimeType: "image/png", source: "loose-source", intrinsicSize: { w: 100, h: 100 } } },
|
||||
);
|
||||
|
||||
const updated = documentApplyLayerMaskOperationCommand.execute(
|
||||
{ state: withLooseAsset },
|
||||
{ maskLayerId: "mask", source: "updated-mask", mimeType: "image/png", operation: { type: "invert" } },
|
||||
);
|
||||
const ignored = documentApplyLayerMaskOperationCommand.execute(
|
||||
{ state: updated },
|
||||
{ maskLayerId: "loose", source: "wrong", operation: { type: "invert" } },
|
||||
);
|
||||
|
||||
expect(updated.document.assets.find((asset) => asset.id === "mask-asset")?.source).toBe("updated-mask");
|
||||
expect(updated.document.assets.find((asset) => asset.id === "mask-asset")?.mimeType).toBe("image/png");
|
||||
expect(ignored.document.assets.find((asset) => asset.id === "loose-asset")?.source).toBe("loose-source");
|
||||
});
|
||||
|
||||
test("cleans mask references when deleting targets or mask layers", () => {
|
||||
const state = documentAddLayerMaskCommand.execute(
|
||||
{ state: documentWithLayers([raster("target", "Target")]) },
|
||||
|
||||
Reference in New Issue
Block a user