fix: apply scale diff masks as alpha

This commit is contained in:
134 2026-07-03 22:44:18 +08:00
parent b4db755c45
commit b9e1671777

View File

@ -2804,7 +2804,7 @@ async function applyScaleAdjustPatchCompositeToImages(params: {
})
.png({ compressionLevel: 6 })
.toBuffer();
const patchMask =
const diffPatchMask =
composite.maskMode === "diff"
? await buildLocalEditDiffCompositeMask({
composite: {
@ -2823,15 +2823,22 @@ async function applyScaleAdjustPatchCompositeToImages(params: {
sourceBuffer: sourcePatchBuffer,
width: workspaceBox.width,
})
: staticPatchMask;
: null;
const patchMask = diffPatchMask || staticPatchMask;
if (!patchMask) {
throw new Error("比例调整局部结果合成失败:无法生成合成蒙版");
}
const patchOverlayBuffer = await sharp(resizedGeneratedBuffer, { failOn: "none" })
.ensureAlpha()
.composite([{ input: patchMask, blend: "dest-in" }])
.png({ compressionLevel: 6 })
.toBuffer();
const patchOverlayBuffer = diffPatchMask
? await sharp(resizedGeneratedBuffer, { failOn: "none" })
.removeAlpha()
.joinChannel(diffPatchMask)
.png({ compressionLevel: 6 })
.toBuffer()
: 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([