fix: guide scale adjust with layout draft

This commit is contained in:
134 2026-07-02 18:59:01 +08:00
parent 1ae9b5a89b
commit 956f9e0fed
2 changed files with 40 additions and 16 deletions

View File

@ -1572,7 +1572,11 @@ function buildScaleAdjustCoordinatePrompt(
scalePercent: ScaleAdjustPercent | null | undefined, scalePercent: ScaleAdjustPercent | null | undefined,
sourceSize: { width: number; height: number }, sourceSize: { width: number; height: number },
cropReferences: ScaleAdjustCropReference[] = [], cropReferences: ScaleAdjustCropReference[] = [],
options: { falSafe?: boolean; markedPhotoGuide?: boolean } = {} options: {
falSafe?: boolean;
markedPhotoGuide?: boolean;
visualLayoutGuide?: boolean;
} = {}
) { ) {
const regionLines = regions const regionLines = regions
.map((region) => { .map((region) => {
@ -1657,9 +1661,11 @@ function buildScaleAdjustCoordinatePrompt(
].join("\n"); ].join("\n");
} }
const coordinateGuideLine = options.markedPhotoGuide const coordinateGuideLine = options.visualLayoutGuide
? "输入图片2是一张原图浅化后的完整画面位置参考图,不是输出底图。青色虚线框表示当前主体搜索框(对应下方 OLD),蓝色实线框表示目标最终占位(对应下方 TARGET)。请用输入图片2理解主体在真实室内画面中的位置关系,但最终图不能出现任何框线、色块、标注或参考图的浅化效果。" ? "输入图片2是一张完整画面的粗略目标布局草稿,不是输出底图。它把 OLD 源框旧主体占位洗淡,表示旧尺寸主体需要移除并自然修复背景;同时把源框中的目标主体粗略缩放/移动到 TARGET 最终占位附近,帮助你理解最终主体大小、位置和室内画面关系。请只读取 input 2 的最终几何意图,不要复制它的淡化痕迹、粗糙拼接、局部透明边、矩形补丁、亮度变化或参考图画质;最终必须以 input 1 的真实照片为唯一画面基底重新完成无缝图片编辑。"
: "Input image 2 is a zoomed neutral coordinate instruction map, not a photo and not output content. It enlarges the OLD and TARGET boxes so their relative scale is easy to read; use the numeric pixel coordinates below for the exact absolute position in input image 1. The OLD box/label locates the current furniture; the TARGET box/label gives the required final footprint, center, and scale factor. If the map says OLD OUTSIDE -> BG, rebuild the old full-size furniture area outside TARGET as natural background in the final photo. Read the boxes, labels, arrows, and scale text only as instructions; never output any map graphics."; : options.markedPhotoGuide
? "输入图片2是一张原图浅化后的完整画面位置参考图,不是输出底图。青色虚线框表示当前主体搜索框(对应下方 OLD),蓝色实线框表示目标最终占位(对应下方 TARGET)。请用输入图片2理解主体在真实室内画面中的位置关系,但最终图不能出现任何框线、色块、标注或参考图的浅化效果。"
: "Input image 2 is a zoomed neutral coordinate instruction map, not a photo and not output content. It enlarges the OLD and TARGET boxes so their relative scale is easy to read; use the numeric pixel coordinates below for the exact absolute position in input image 1. The OLD box/label locates the current furniture; the TARGET box/label gives the required final footprint, center, and scale factor. If the map says OLD OUTSIDE -> BG, rebuild the old full-size furniture area outside TARGET as natural background in the final photo. Read the boxes, labels, arrows, and scale text only as instructions; never output any map graphics.";
return [ return [
"Local furniture scale edit. Use input image 1 as the clean original photo and the locked camera frame.", "Local furniture scale edit. Use input image 1 as the clean original photo and the locked camera frame.",
@ -1869,18 +1875,29 @@ export async function POST(request: NextRequest) {
const useFalScaleAdjustCoordinatePrompt = const useFalScaleAdjustCoordinatePrompt =
useScaleAdjustCoordinateGuide && useScaleAdjustCoordinateGuide &&
resolvedScaleAdjustModelEntry?.provider?.type === "fal-image"; resolvedScaleAdjustModelEntry?.provider?.type === "fal-image";
const useScaleAdjustMarkedPhotoGuide = useScaleAdjustCoordinateGuide; const useScaleAdjustVisualLayoutGuide =
useScaleAdjustCoordinateGuide && !useFalScaleAdjustCoordinatePrompt;
const useScaleAdjustMarkedPhotoGuide =
useScaleAdjustCoordinateGuide && !useScaleAdjustVisualLayoutGuide;
const annotatedBuffer = isScaleAdjustOperation const annotatedBuffer = isScaleAdjustOperation
? useScaleAdjustCoordinateGuide ? useScaleAdjustCoordinateGuide
? useScaleAdjustMarkedPhotoGuide ? useScaleAdjustVisualLayoutGuide
? await buildScaleAdjustMarkedPhotoGuideBuffer({ ? await buildScaleAdjustVisualLayoutGuideBuffer({
height: sourceHeight,
regions, regions,
scalePercent, scalePercent,
sourceBuffer, sourceBuffer,
width: sourceWidth, sourceHeight,
sourceWidth,
}) })
: await sharp( : useScaleAdjustMarkedPhotoGuide
? await buildScaleAdjustMarkedPhotoGuideBuffer({
height: sourceHeight,
regions,
scalePercent,
sourceBuffer,
width: sourceWidth,
})
: await sharp(
buildScaleAdjustZoomedCoordinateSvg({ buildScaleAdjustZoomedCoordinateSvg({
height: sourceHeight, height: sourceHeight,
regions, regions,
@ -1932,6 +1949,7 @@ export async function POST(request: NextRequest) {
{ {
falSafe: useFalScaleAdjustCoordinatePrompt, falSafe: useFalScaleAdjustCoordinatePrompt,
markedPhotoGuide: useScaleAdjustMarkedPhotoGuide, markedPhotoGuide: useScaleAdjustMarkedPhotoGuide,
visualLayoutGuide: useScaleAdjustVisualLayoutGuide,
} }
) )
: buildScaleAdjustPrompt( : buildScaleAdjustPrompt(
@ -1999,7 +2017,9 @@ export async function POST(request: NextRequest) {
annotatedReferenceSentToModel: isScaleAdjustOperation, annotatedReferenceSentToModel: isScaleAdjustOperation,
annotatedReferenceType: isScaleAdjustOperation annotatedReferenceType: isScaleAdjustOperation
? useScaleAdjustCoordinateGuide ? useScaleAdjustCoordinateGuide
? useScaleAdjustMarkedPhotoGuide ? useScaleAdjustVisualLayoutGuide
? "scale-adjust-visual-layout-guide"
: useScaleAdjustMarkedPhotoGuide
? "scale-adjust-marked-photo-guide" ? "scale-adjust-marked-photo-guide"
: "scale-adjust-neutral-coordinate-map" : "scale-adjust-neutral-coordinate-map"
: "scale-adjust-full-frame-semantic-edit-map" : "scale-adjust-full-frame-semantic-edit-map"
@ -2020,11 +2040,13 @@ export async function POST(request: NextRequest) {
scaleAdjustNeutralCoordinateMapApplied: scaleAdjustNeutralCoordinateMapApplied:
isScaleAdjustOperation && isScaleAdjustOperation &&
useScaleAdjustCoordinateGuide && useScaleAdjustCoordinateGuide &&
!useScaleAdjustMarkedPhotoGuide, !useScaleAdjustMarkedPhotoGuide &&
!useScaleAdjustVisualLayoutGuide,
scaleAdjustMarkedPhotoGuideApplied: useScaleAdjustMarkedPhotoGuide, scaleAdjustMarkedPhotoGuideApplied: useScaleAdjustMarkedPhotoGuide,
scaleAdjustFalMarkedPhotoGuideApplied: useFalScaleAdjustCoordinatePrompt, scaleAdjustFalMarkedPhotoGuideApplied: useFalScaleAdjustCoordinatePrompt,
scaleAdjustVisualLayoutGuideApplied: scaleAdjustVisualLayoutGuideApplied:
isScaleAdjustOperation && !useScaleAdjustCoordinateGuide, isScaleAdjustOperation &&
(!useScaleAdjustCoordinateGuide || useScaleAdjustVisualLayoutGuide),
falScaleAdjustCoordinateGuideApplied: falScaleAdjustCoordinateGuideApplied:
useScaleAdjustCoordinateGuide && useScaleAdjustCoordinateGuide &&
resolvedScaleAdjustModelEntry?.provider?.type === "fal-image", resolvedScaleAdjustModelEntry?.provider?.type === "fal-image",
@ -2054,7 +2076,9 @@ export async function POST(request: NextRequest) {
? useScaleAdjustCoordinateGuide ? useScaleAdjustCoordinateGuide
? useFalScaleAdjustCoordinatePrompt ? useFalScaleAdjustCoordinatePrompt
? "fal-safe-marked-photo-box-guide-no-old-crop-v44-one-shot" ? "fal-safe-marked-photo-box-guide-no-old-crop-v44-one-shot"
: "same-name-marked-photo-box-guide-no-old-crop-v45-one-shot" : useScaleAdjustVisualLayoutGuide
? "same-name-visual-layout-guide-v50-one-shot"
: "same-name-marked-photo-box-guide-no-old-crop-v45-one-shot"
: "locked-plate-semantic-target-map-no-old-crop-v15" : "locked-plate-semantic-target-map-no-old-crop-v15"
: undefined, : undefined,
scaleAdjustPostCompositeApplied: false, scaleAdjustPostCompositeApplied: false,

View File

@ -1643,7 +1643,7 @@ async function buildScaleAdjustDeterministicFallbackImages(params: {
.toColorspace("srgb") .toColorspace("srgb")
.raw() .raw()
.toBuffer(); .toBuffer();
const overlays: Array<{ buffer: Buffer; left: number; top: number }> = []; const overlays: Array<{ input: Buffer; left: number; top: number }> = [];
for (const [index, region] of verification.regions.entries()) { for (const [index, region] of verification.regions.entries()) {
const targetRegion = const targetRegion =
@ -1695,7 +1695,7 @@ async function buildScaleAdjustDeterministicFallbackImages(params: {
width: sourceImage.sourceWidth, width: sourceImage.sourceWidth,
}); });
overlays.push({ overlays.push({
buffer: objectBuffer, input: objectBuffer,
left: targetBox.left, left: targetBox.left,
top: targetBox.top, top: targetBox.top,
}); });