diff --git a/app/api/canvas/local-edit/route.ts b/app/api/canvas/local-edit/route.ts index 112151599..e75986ff7 100644 --- a/app/api/canvas/local-edit/route.ts +++ b/app/api/canvas/local-edit/route.ts @@ -5934,8 +5934,7 @@ export async function POST(request: NextRequest) { scaleAdjustPostCompositeApplied: Boolean(scaleAdjustPatchReference) && (!useScaleAdjustFullFrameStructurePatch || - (useScaleAdjustProductLockComposite && - !useScaleAdjustProductLockDirectMaskPlate)), + useScaleAdjustProductLockComposite), scaleAdjustUsesFullFrameOutput: isScaleAdjustOperation && (!scaleAdjustPatchReference || useScaleAdjustFullFrameStructurePatch), @@ -5986,18 +5985,18 @@ export async function POST(request: NextRequest) { : undefined, referenceImages, scaleAdjustPatchComposite: - useScaleAdjustProductLockComposite && !useScaleAdjustProductLockDirectMaskPlate + useScaleAdjustProductLockComposite ? { diffAlphaCutoff: 18, diffAlphaMultiplier: 2.6, diffCompareBlurPx: 1.1, diffHighThreshold: 64, diffLowThreshold: 20, - featherMaxPx: 34, - featherMinPx: 8, - featherRatio: 0.015, + featherMaxPx: useScaleAdjustProductLockDirectMaskPlate ? 72 : 34, + featherMinPx: useScaleAdjustProductLockDirectMaskPlate ? 18 : 8, + featherRatio: useScaleAdjustProductLockDirectMaskPlate ? 0.026 : 0.015, generatedFrame: "full", - maskMode: "diff", + maskMode: useScaleAdjustProductLockDirectMaskPlate ? "workspace" : "diff", regions: scaleAdjustPatchCompositeRegions, sourceImageUrl, clipMaskImageUrl: scaleAdjustProductLockRepairClipMaskUrl, diff --git a/lib/canvas/generate-image.ts b/lib/canvas/generate-image.ts index 79d9b70a0..583cb0426 100644 --- a/lib/canvas/generate-image.ts +++ b/lib/canvas/generate-image.ts @@ -3059,6 +3059,13 @@ async function applyScaleAdjustPatchCompositeToImages(params: { touchesTop, width: workspaceBox.width, }); + const staticPatchMaskRaw = staticPatchMask + ? await normalizeAlphaMaskToRaw({ + height: workspaceBox.height, + maskBuffer: staticPatchMask, + width: workspaceBox.width, + }) + : null; const regionClipPatchMask = maskRegionBoxes?.length ? buildScaleAdjustPatchCompositeMaskSvg({ featherPx, @@ -3177,11 +3184,21 @@ async function applyScaleAdjustPatchCompositeToImages(params: { imageBuffer: resizedGeneratedBuffer, width: workspaceBox.width, }) - : await sharp(resizedGeneratedBuffer, { failOn: "none" }) - .ensureAlpha() - .composite([{ input: patchMask, blend: "dest-in" }]) - .png({ compressionLevel: 6 }) - .toBuffer(); + : activeClipPatchMaskRaw || staticPatchMaskRaw + ? await applyRawAlphaToImage({ + alphaMaskRaw: + activeClipPatchMaskRaw && staticPatchMaskRaw + ? multiplyAlphaMasks(staticPatchMaskRaw, activeClipPatchMaskRaw) + : activeClipPatchMaskRaw || staticPatchMaskRaw!, + height: workspaceBox.height, + imageBuffer: resizedGeneratedBuffer, + width: workspaceBox.width, + }) + : await sharp(resizedGeneratedBuffer, { failOn: "none" }) + .ensureAlpha() + .composite([{ input: patchMask, blend: "dest-in" }]) + .png({ compressionLevel: 6 }) + .toBuffer(); const mergedBuffer = await sharp(sourceBuffer, { failOn: "none" }) .ensureAlpha() .composite([