fix: avoid compositing dirty full-frame scale drafts
This commit is contained in:
parent
fa5212a33e
commit
deee79c5c2
@ -2931,18 +2931,42 @@ async function buildScaleAdjustStructureLockedComposite(params: {
|
|||||||
((sourceCenterY - placement.sourceFootprintBox.top) /
|
((sourceCenterY - placement.sourceFootprintBox.top) /
|
||||||
Math.max(1, placement.sourceFootprintBox.height)) *
|
Math.max(1, placement.sourceFootprintBox.height)) *
|
||||||
placement.targetBox.height;
|
placement.targetBox.height;
|
||||||
const structureOverlay = await sharp(subjectCrop, { failOn: "none" })
|
const useRectCropTargetGuide = preferPixelStructure && Boolean(protectedPersonSide);
|
||||||
.joinChannel(subjectAlpha)
|
const structureOverlay = useRectCropTargetGuide
|
||||||
.resize(placedWidth, placedHeight, {
|
? await sharp(sourceBuffer, { failOn: "none" })
|
||||||
fit: "fill",
|
.extract(placement.sourceBox)
|
||||||
kernel: sharp.kernel.lanczos3,
|
.resize(placement.placedWidth, placement.placedHeight, {
|
||||||
})
|
fit: "fill",
|
||||||
.png({ compressionLevel: 6 })
|
kernel: sharp.kernel.lanczos3,
|
||||||
.toBuffer();
|
})
|
||||||
|
.ensureAlpha()
|
||||||
|
.composite([
|
||||||
|
{
|
||||||
|
input: buildScaleAdjustPatchMaskSvg({
|
||||||
|
height: placement.placedHeight,
|
||||||
|
width: placement.placedWidth,
|
||||||
|
}),
|
||||||
|
blend: "dest-in",
|
||||||
|
},
|
||||||
|
])
|
||||||
|
.png({ compressionLevel: 6 })
|
||||||
|
.toBuffer()
|
||||||
|
: await sharp(subjectCrop, { failOn: "none" })
|
||||||
|
.joinChannel(subjectAlpha)
|
||||||
|
.resize(placedWidth, placedHeight, {
|
||||||
|
fit: "fill",
|
||||||
|
kernel: sharp.kernel.lanczos3,
|
||||||
|
})
|
||||||
|
.png({ compressionLevel: 6 })
|
||||||
|
.toBuffer();
|
||||||
const targetClipMaskPatch =
|
const targetClipMaskPatch =
|
||||||
await buildScaleAdjustOverlayClipMaskPatch(structureOverlay);
|
await buildScaleAdjustOverlayClipMaskPatch(structureOverlay);
|
||||||
const overlayLeft = Math.round(targetCenterX - placedWidth / 2);
|
const overlayLeft = useRectCropTargetGuide
|
||||||
const overlayTop = Math.round(targetCenterY - placedHeight / 2);
|
? placement.placedLeft
|
||||||
|
: Math.round(targetCenterX - placedWidth / 2);
|
||||||
|
const overlayTop = useRectCropTargetGuide
|
||||||
|
? placement.placedTop
|
||||||
|
: Math.round(targetCenterY - placedHeight / 2);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
compositeClip: {
|
compositeClip: {
|
||||||
@ -2950,7 +2974,7 @@ async function buildScaleAdjustStructureLockedComposite(params: {
|
|||||||
left: placement.sourceBox.left,
|
left: placement.sourceBox.left,
|
||||||
top: placement.sourceBox.top,
|
top: placement.sourceBox.top,
|
||||||
},
|
},
|
||||||
method: "pixel-mask",
|
method: useRectCropTargetGuide ? "rect-crop-guide" : "pixel-mask",
|
||||||
overlay: {
|
overlay: {
|
||||||
input: structureOverlay,
|
input: structureOverlay,
|
||||||
left: overlayLeft,
|
left: overlayLeft,
|
||||||
@ -5032,7 +5056,8 @@ export async function POST(request: NextRequest) {
|
|||||||
: "locked-plate-semantic-target-map-no-old-crop-v15"
|
: "locked-plate-semantic-target-map-no-old-crop-v15"
|
||||||
: undefined,
|
: undefined,
|
||||||
scaleAdjustPostCompositeApplied:
|
scaleAdjustPostCompositeApplied:
|
||||||
Boolean(scaleAdjustPatchReference),
|
Boolean(scaleAdjustPatchReference) &&
|
||||||
|
!useScaleAdjustFullFrameStructurePatch,
|
||||||
scaleAdjustUsesFullFrameOutput:
|
scaleAdjustUsesFullFrameOutput:
|
||||||
isScaleAdjustOperation &&
|
isScaleAdjustOperation &&
|
||||||
(!scaleAdjustPatchReference || useScaleAdjustFullFrameStructurePatch),
|
(!scaleAdjustPatchReference || useScaleAdjustFullFrameStructurePatch),
|
||||||
@ -5070,7 +5095,7 @@ export async function POST(request: NextRequest) {
|
|||||||
? { maskImageUrl: scaleAdjustEditMaskUpload.url }
|
? { maskImageUrl: scaleAdjustEditMaskUpload.url }
|
||||||
: undefined,
|
: undefined,
|
||||||
referenceImages,
|
referenceImages,
|
||||||
scaleAdjustPatchComposite: scaleAdjustPatchReference
|
scaleAdjustPatchComposite: scaleAdjustPatchReference && !useScaleAdjustFullFrameStructurePatch
|
||||||
? {
|
? {
|
||||||
diffAlphaCutoff:
|
diffAlphaCutoff:
|
||||||
scaleAdjustPatchReference.structureLockedDraft ? 24 : 8,
|
scaleAdjustPatchReference.structureLockedDraft ? 24 : 8,
|
||||||
@ -5086,9 +5111,6 @@ export async function POST(request: NextRequest) {
|
|||||||
scaleAdjustPatchReference.structureLockedDraft ? 36 : 42,
|
scaleAdjustPatchReference.structureLockedDraft ? 36 : 42,
|
||||||
featherMinPx: 10,
|
featherMinPx: 10,
|
||||||
featherRatio: 0.018,
|
featherRatio: 0.018,
|
||||||
generatedFrame: useScaleAdjustFullFrameStructurePatch
|
|
||||||
? "full"
|
|
||||||
: "workspace",
|
|
||||||
maskMode: "diff",
|
maskMode: "diff",
|
||||||
regions: scaleAdjustPatchCompositeRegions,
|
regions: scaleAdjustPatchCompositeRegions,
|
||||||
sourceImageUrl,
|
sourceImageUrl,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user