fix: clean product lock masks before scale adjust overlay

This commit is contained in:
134 2026-07-06 03:22:59 +08:00
parent 6694846c58
commit 7640e6b5ca

View File

@ -1944,8 +1944,9 @@ function filterScaleAdjustStructureComponents(params: {
function solidifyScaleAdjustStructureMask(params: { function solidifyScaleAdjustStructureMask(params: {
box: { width: number; height: number }; box: { width: number; height: number };
mask: Uint8Array; mask: Uint8Array;
maxPanelSpanRatio?: number;
}) { }) {
const { box, mask } = params; const { box, mask, maxPanelSpanRatio = 0.86 } = params;
const width = box.width; const width = box.width;
const height = box.height; const height = box.height;
const bridgeGap = Math.max(2, Math.round(Math.min(width, height) * 0.006)); 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); const density = marked / Math.max(1, span * bandHeight);
if ( if (
span < width * 0.16 || span < width * 0.16 ||
span > width * 0.86 || span > width * maxPanelSpanRatio ||
density < 0.025 || density < 0.025 ||
density > 0.78 density > 0.78
) { ) {
@ -2535,6 +2536,14 @@ async function buildScaleAdjustRmbgStructureLockedComposite(params: {
}), }),
}) })
: null; : null;
const protectedPersonRemovalMask =
protectedPersonMask ||
(protectedPersonSide && sameSizeCutout
? buildScaleAdjustProtectedPersonGeometryMask({
box: { width: cutoutWidth, height: cutoutHeight },
side: protectedPersonSide,
})
: null);
const sideProtectedCleanedAlpha = const sideProtectedCleanedAlpha =
protectedPersonSide && sameSizeCutout && sourceCropRaw protectedPersonSide && sameSizeCutout && sourceCropRaw
? suppressScaleAdjustProtectedFurnitureDarkAlpha({ ? suppressScaleAdjustProtectedFurnitureDarkAlpha({
@ -2548,7 +2557,7 @@ async function buildScaleAdjustRmbgStructureLockedComposite(params: {
: cleanedAlpha; : cleanedAlpha;
const protectedCleanedAlpha = removeScaleAdjustMaskFromAlpha({ const protectedCleanedAlpha = removeScaleAdjustMaskFromAlpha({
alphaMask: sideProtectedCleanedAlpha, alphaMask: sideProtectedCleanedAlpha,
removeMask: protectedPersonMask, removeMask: protectedPersonRemovalMask,
}); });
for (let index = 0; index < protectedCleanedAlpha.length; index += 1) { for (let index = 0; index < protectedCleanedAlpha.length; index += 1) {
cleanedRaw[index * 4 + 3] = protectedCleanedAlpha[index] || 0; cleanedRaw[index * 4 + 3] = protectedCleanedAlpha[index] || 0;
@ -2644,6 +2653,7 @@ async function buildScaleAdjustRmbgStructureLockedComposite(params: {
? solidifyScaleAdjustStructureMask({ ? solidifyScaleAdjustStructureMask({
box: placement.sourceBox, box: placement.sourceBox,
mask: filteredSourceMask, mask: filteredSourceMask,
maxPanelSpanRatio: protectedPersonSide ? 0.96 : 0.9,
}) })
: highConfidenceSourceMask; : highConfidenceSourceMask;
const sourceWashMask = dilateScaleAdjustStructureMask({ const sourceWashMask = dilateScaleAdjustStructureMask({
@ -2745,7 +2755,7 @@ async function buildScaleAdjustRmbgStructureLockedComposite(params: {
const targetClipMaskPatch = const targetClipMaskPatch =
await buildScaleAdjustOverlayClipMaskPatch(structureOverlay); await buildScaleAdjustOverlayClipMaskPatch(structureOverlay);
const productLockProtectMask = const productLockProtectMask =
protectedPersonMask || protectedPersonRemovalMask ||
(protectedPersonSide (protectedPersonSide
? buildScaleAdjustProtectedPersonGeometryMask({ ? buildScaleAdjustProtectedPersonGeometryMask({
box: placement.sourceBox, box: placement.sourceBox,
@ -2781,7 +2791,7 @@ async function buildScaleAdjustRmbgStructureLockedComposite(params: {
placedWidth, placedWidth,
protectedPersonSide, protectedPersonSide,
protectedPersonGeometryMaskApplied: protectedPersonGeometryMaskApplied:
Boolean(productLockProtectMask) && !protectedPersonMask, Boolean(protectedPersonRemovalMask) && !protectedPersonMask,
protectedPersonMaskApplied: Boolean(protectedPersonMask), protectedPersonMaskApplied: Boolean(protectedPersonMask),
sameSizeCutout, sameSizeCutout,
alphaBandingStats, alphaBandingStats,