From 20693db8b9f254d31d3094a38a1f82f7f30c40c2 Mon Sep 17 00:00:00 2001 From: 134 Date: Sun, 5 Jul 2026 12:52:44 +0800 Subject: [PATCH] fix: aggressively clear protected draft dark residue --- app/api/canvas/local-edit/route.ts | 38 ++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/app/api/canvas/local-edit/route.ts b/app/api/canvas/local-edit/route.ts index 3a8e43a9b..2bb7fff2c 100644 --- a/app/api/canvas/local-edit/route.ts +++ b/app/api/canvas/local-edit/route.ts @@ -2657,31 +2657,49 @@ function suppressScaleAdjustProtectedFurnitureDarkAlpha(params: { return sourceY >= sourceBox.height * 0.3; }; + let clearedPixels = 0; + let markedPixels = 0; for (let localY = 0; localY < bbox.height; localY += 1) { for (let localX = 0; localX < bbox.width; localX += 1) { const alphaIndex = localY * bbox.width + localX; const alpha = output[alphaIndex] || 0; if (alpha === 0) continue; + markedPixels += 1; const colorIndex = alphaIndex * 3; const r = rawRgb[colorIndex] || 0; const g = rawRgb[colorIndex + 1] || 0; const b = rawRgb[colorIndex + 2] || 0; const { luma, saturation } = getScaleAdjustPixelStats(r, g, b); - const veryDark = luma < 72; - const flatDark = luma < 110 && saturation < 0.28; - if (!veryDark && !flatDark) continue; - const sourceX = bbox.left + localX; const sourceY = bbox.top + localY; - if (isProtectedSideArea(sourceX, sourceY)) { - output[alphaIndex] = 0; - } else { - output[alphaIndex] = 0; - } + const inProtectedSideArea = isProtectedSideArea(sourceX, sourceY); + const neutralDark = + luma < 150 && + (saturation < 0.55 || (r < 110 && g < 110 && b < 110)); + const lowContrastDark = luma < 132 && saturation < 0.32; + const shouldClear = inProtectedSideArea + ? neutralDark || lowContrastDark + : luma < 100 || (luma < 132 && saturation < 0.22); + if (!shouldClear) continue; + + output[alphaIndex] = 0; + clearedPixels += 1; } } + if (markedPixels > 0) { + console.info( + "[Canvas Local Edit] Scale adjust protected furniture dark alpha cleared:", + { + clearedRatio: Number((clearedPixels / markedPixels).toFixed(3)), + clearedPixels, + protectedPersonSide, + totalMarkedPixels: markedPixels, + } + ); + } + return output; } @@ -4934,7 +4952,7 @@ export async function POST(request: NextRequest) { scaleAdjustPromptStrategy: isScaleAdjustOperation ? scaleAdjustPatchReference ? useScaleAdjustFullFrameStructurePatch - ? "full-frame-structure-locked-draft-v5-protected-side-dark-cleared-one-shot" + ? "full-frame-structure-locked-draft-v6-protected-side-dark-cleared-one-shot" : scaleAdjustPatchReference.structureLockedDraft ? "ai-patch-workspace-structure-locked-draft-v87-subject-alpha-clipped-one-shot" : "ai-patch-workspace-draft-v75-soft-wipe-erase-ghost-one-shot"