Add addMask method to MaskTool for overlaying masks

Introduces the addMask method to MaskTool in both JS and TS implementations, allowing new masks to be overlaid without clearing existing ones. Updates CanvasView to use addMask instead of setMask when applying SAM detector results.
This commit is contained in:
Dariusz L
2025-07-22 23:39:56 +02:00
parent 1d520eca01
commit 472f8768a5
4 changed files with 33 additions and 6 deletions

View File

@@ -336,4 +336,19 @@ export class MaskTool {
this.canvasInstance.render();
log.info(`MaskTool updated with a new mask image at correct canvas position (${destX}, ${destY}).`);
}
addMask(image: HTMLImageElement): void {
const destX = -this.x;
const destY = -this.y;
// Don't clear existing mask - just add to it
this.maskCtx.globalCompositeOperation = 'source-over';
this.maskCtx.drawImage(image, destX, destY);
if (this.onStateChange) {
this.onStateChange();
}
this.canvasInstance.render();
log.info(`MaskTool added mask overlay at correct canvas position (${destX}, ${destY}) without clearing existing mask.`);
}
}