fix: add focused crop reference for scale adjust

This commit is contained in:
134 2026-07-02 19:54:33 +08:00
parent 98e987e75b
commit 7152435a3d

View File

@ -739,11 +739,17 @@ async function createScaleAdjustCropReferences(params: {
const regionsForCrop = params.regions.slice(0, MAX_SCALE_ADJUST_CROP_REFERENCES);
for (const region of regionsForCrop) {
const cropBox = expandPixelRectForCrop({
height: params.sourceHeight,
pixelRect: region.pixelRect,
width: params.sourceWidth,
const focusBox = getScaleAdjustFocusedSourceBox({
region,
sourceBox: region.pixelRect,
});
const cropBox = getScaleAdjustFocusDirection(region)
? focusBox
: expandPixelRectForCrop({
height: params.sourceHeight,
pixelRect: region.pixelRect,
width: params.sourceWidth,
});
const cropBuffer = await sharp(params.sourceBuffer, { failOn: "none" })
.extract(cropBox)
.resize({
@ -1720,7 +1726,7 @@ function buildScaleAdjustCoordinatePrompt(
}
const coordinateGuideLine = options.visualLayoutGuide
? "输入图片2是一张完整画面的粗略目标布局草稿,不是输出底图。它把 OLD 源框旧主体占位洗淡,表示旧尺寸主体需要移除并自然修复背景;同时把源框中的目标主体粗略缩放/移动到 TARGET 最终占位附近,帮助你理解最终主体大小、位置和室内画面关系。请只读取 input 2 的最终几何意图,不要复制它的淡化痕迹、粗糙拼接、局部透明边、矩形补丁、亮度变化或参考图画质;最终必须以 input 1 的真实照片为唯一画面基底重新完成无缝图片编辑。"
? "输入图片2是一张完整画面的粗略目标布局草稿,不是输出底图。它把 OLD 源框旧主体占位洗淡,表示旧尺寸主体必须从原尺寸位置移除并自然修复背景;同时把目标主体粗略缩放/移动到 TARGET 最终占位附近,这个缩小后的位置和尺寸是最终结果必须匹配的几何目标。请把 input 2 当成最终构图/比例的强约束:如果 input 2 中目标主体比 input 1 小,最终输出也必须明显变小,不能保留 input 1 的原尺寸主体。不要复制 input 2 的淡化痕迹、粗糙拼接、局部透明边、矩形补丁、亮度变化或参考图画质;最终必须以 input 1 的真实照片为唯一画面基底重新完成无缝图片编辑。"
: 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.";
@ -1993,7 +1999,15 @@ export async function POST(request: NextRequest) {
annotatedFilename,
toArrayBuffer(annotatedBuffer)
);
const scaleAdjustCropReferences: ScaleAdjustCropReference[] = [];
const scaleAdjustCropReferences: ScaleAdjustCropReference[] =
isScaleAdjustOperation && useScaleAdjustVisualLayoutGuide
? await createScaleAdjustCropReferences({
regions,
sourceBuffer,
sourceHeight,
sourceWidth,
})
: [];
const prompt = isScaleAdjustOperation
? useScaleAdjustCoordinateGuide
? buildScaleAdjustCoordinatePrompt(
@ -2136,7 +2150,7 @@ export async function POST(request: NextRequest) {
? useFalScaleAdjustCoordinatePrompt
? "fal-safe-marked-photo-box-guide-no-old-crop-v44-one-shot"
: useScaleAdjustVisualLayoutGuide
? "same-name-visual-layout-guide-v50-one-shot"
? "same-name-focused-layout-crop-guide-v54-one-shot"
: "same-name-marked-photo-box-guide-no-old-crop-v45-one-shot"
: "locked-plate-semantic-target-map-no-old-crop-v15"
: undefined,