From 40fa7b1e262068b4a0491b60b97df4dcfb102f8b Mon Sep 17 00:00:00 2001 From: 134 Date: Sat, 4 Jul 2026 16:46:04 +0800 Subject: [PATCH] fix: filter scale adjust haze in patch composites --- app/api/canvas/local-edit/route.ts | 16 ++++++++++++---- lib/canvas/generate-image.ts | 18 ++++++++++++++++-- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/app/api/canvas/local-edit/route.ts b/app/api/canvas/local-edit/route.ts index 8b7be22ad..357c49d8b 100644 --- a/app/api/canvas/local-edit/route.ts +++ b/app/api/canvas/local-edit/route.ts @@ -4408,10 +4408,18 @@ export async function POST(request: NextRequest) { referenceImages, scaleAdjustPatchComposite: scaleAdjustPatchReference ? { - diffCompareBlurPx: 0.8, - diffHighThreshold: 42, - diffLowThreshold: 14, - featherMaxPx: 42, + diffAlphaCutoff: + scaleAdjustPatchReference.structureLockedDraft ? 24 : 8, + diffAlphaMultiplier: + scaleAdjustPatchReference.structureLockedDraft ? 2.25 : 3, + diffCompareBlurPx: + scaleAdjustPatchReference.structureLockedDraft ? 1.2 : 0.8, + diffHighThreshold: + scaleAdjustPatchReference.structureLockedDraft ? 72 : 42, + diffLowThreshold: + scaleAdjustPatchReference.structureLockedDraft ? 26 : 14, + featherMaxPx: + scaleAdjustPatchReference.structureLockedDraft ? 36 : 42, featherMinPx: 10, featherRatio: 0.018, maskMode: "diff", diff --git a/lib/canvas/generate-image.ts b/lib/canvas/generate-image.ts index e29df494e..fd71b56aa 100644 --- a/lib/canvas/generate-image.ts +++ b/lib/canvas/generate-image.ts @@ -58,6 +58,8 @@ export interface CanvasScaleAdjustPatchCompositeConfig { workspaceRegion: CanvasLocalEditCompositeRegion; regions?: CanvasLocalEditCompositeRegion[]; maskMode?: "workspace" | "diff"; + diffAlphaCutoff?: number; + diffAlphaMultiplier?: number; diffLowThreshold?: number; diffHighThreshold?: number; diffCompareBlurPx?: number; @@ -405,6 +407,14 @@ function normalizeScaleAdjustPatchCompositeConfig( workspaceRegion, ...(regions.length > 0 ? { regions } : {}), maskMode: value.maskMode === "diff" ? "diff" : "workspace", + diffAlphaCutoff: normalizeOptionalNumber(value.diffAlphaCutoff, { + max: 96, + min: 0, + }), + diffAlphaMultiplier: normalizeOptionalNumber(value.diffAlphaMultiplier, { + max: 6, + min: 0.5, + }), diffHighThreshold: normalizeOptionalNumber(value.diffHighThreshold, { max: 120, min: 1, @@ -2961,8 +2971,12 @@ async function applyScaleAdjustPatchCompositeToImages(params: { regionClipPatchMaskRaw || Buffer.alloc(workspaceBox.width * workspaceBox.height, 255) ), - 8, - 3 + typeof composite.diffAlphaCutoff === "number" + ? composite.diffAlphaCutoff + : 8, + typeof composite.diffAlphaMultiplier === "number" + ? composite.diffAlphaMultiplier + : 3 ), height: workspaceBox.height, imageBuffer: resizedGeneratedBuffer,