From 7640e6b5ca249392cd9a4a1ed4c76bd03abb4a13 Mon Sep 17 00:00:00 2001 From: 134 Date: Mon, 6 Jul 2026 03:22:59 +0800 Subject: [PATCH] fix: clean product lock masks before scale adjust overlay --- app/api/canvas/local-edit/route.ts | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/app/api/canvas/local-edit/route.ts b/app/api/canvas/local-edit/route.ts index cc187948a..78ec735f9 100644 --- a/app/api/canvas/local-edit/route.ts +++ b/app/api/canvas/local-edit/route.ts @@ -1944,8 +1944,9 @@ function filterScaleAdjustStructureComponents(params: { function solidifyScaleAdjustStructureMask(params: { box: { width: number; height: number }; mask: Uint8Array; + maxPanelSpanRatio?: number; }) { - const { box, mask } = params; + const { box, mask, maxPanelSpanRatio = 0.86 } = params; const width = box.width; const height = box.height; const bridgeGap = Math.max(2, Math.round(Math.min(width, height) * 0.006)); @@ -2033,7 +2034,7 @@ function solidifyScaleAdjustStructureMask(params: { const density = marked / Math.max(1, span * bandHeight); if ( span < width * 0.16 || - span > width * 0.86 || + span > width * maxPanelSpanRatio || density < 0.025 || density > 0.78 ) { @@ -2535,6 +2536,14 @@ async function buildScaleAdjustRmbgStructureLockedComposite(params: { }), }) : null; + const protectedPersonRemovalMask = + protectedPersonMask || + (protectedPersonSide && sameSizeCutout + ? buildScaleAdjustProtectedPersonGeometryMask({ + box: { width: cutoutWidth, height: cutoutHeight }, + side: protectedPersonSide, + }) + : null); const sideProtectedCleanedAlpha = protectedPersonSide && sameSizeCutout && sourceCropRaw ? suppressScaleAdjustProtectedFurnitureDarkAlpha({ @@ -2548,7 +2557,7 @@ async function buildScaleAdjustRmbgStructureLockedComposite(params: { : cleanedAlpha; const protectedCleanedAlpha = removeScaleAdjustMaskFromAlpha({ alphaMask: sideProtectedCleanedAlpha, - removeMask: protectedPersonMask, + removeMask: protectedPersonRemovalMask, }); for (let index = 0; index < protectedCleanedAlpha.length; index += 1) { cleanedRaw[index * 4 + 3] = protectedCleanedAlpha[index] || 0; @@ -2644,6 +2653,7 @@ async function buildScaleAdjustRmbgStructureLockedComposite(params: { ? solidifyScaleAdjustStructureMask({ box: placement.sourceBox, mask: filteredSourceMask, + maxPanelSpanRatio: protectedPersonSide ? 0.96 : 0.9, }) : highConfidenceSourceMask; const sourceWashMask = dilateScaleAdjustStructureMask({ @@ -2745,7 +2755,7 @@ async function buildScaleAdjustRmbgStructureLockedComposite(params: { const targetClipMaskPatch = await buildScaleAdjustOverlayClipMaskPatch(structureOverlay); const productLockProtectMask = - protectedPersonMask || + protectedPersonRemovalMask || (protectedPersonSide ? buildScaleAdjustProtectedPersonGeometryMask({ box: placement.sourceBox, @@ -2781,7 +2791,7 @@ async function buildScaleAdjustRmbgStructureLockedComposite(params: { placedWidth, protectedPersonSide, protectedPersonGeometryMaskApplied: - Boolean(productLockProtectMask) && !protectedPersonMask, + Boolean(protectedPersonRemovalMask) && !protectedPersonMask, protectedPersonMaskApplied: Boolean(protectedPersonMask), sameSizeCutout, alphaBandingStats,