fix: simplify FAL scale adjust inputs

This commit is contained in:
134 2026-06-29 18:09:22 +08:00
parent 8a9fba7eab
commit 0a792c7e26

View File

@ -916,7 +916,6 @@ function buildScaleAdjustPrompt(
function buildFalScaleAdjustCoordinatePrompt(
regions: NormalizedLocalEditRegion[],
scalePercent: ScaleAdjustPercent | null | undefined,
cropReferences: ScaleAdjustCropReference[] = [],
sourceSize: { width: number; height: number }
) {
const regionLines = regions
@ -929,44 +928,32 @@ function buildFalScaleAdjustCoordinatePrompt(
region.rect.width > 0 ? targetRect.width / region.rect.width : 1;
const heightFactor =
region.rect.height > 0 ? targetRect.height / region.rect.height : 1;
const cropIndex = cropReferences.findIndex(
(reference) => reference.regionIndex === region.index
);
const cropNote =
cropIndex >= 0
? ` Input image ${cropIndex + 3} is this region's clean crop reference for subject identity and proportions only.`
: "";
const scaleDirection =
widthFactor < 0.92 || heightFactor < 0.92
? "make the furniture clearly smaller"
: widthFactor > 1.08 || heightFactor > 1.08
? "make the furniture clearly larger"
: "move/fit the furniture to the target box";
return `Region ${region.index}: old subject search box in input image 1 is x=${region.pixelRect.left}, y=${region.pixelRect.top}, w=${region.pixelRect.width}, h=${region.pixelRect.height}; final target visual box is x=${targetPixelRect.left}, y=${targetPixelRect.top}, w=${targetPixelRect.width}, h=${targetPixelRect.height}; target footprint is about ${widthFactor.toFixed(2)}x width and ${heightFactor.toFixed(2)}x height of the old search box.${cropNote}`;
return `Region ${region.index}: OLD search box in input 1 x=${region.pixelRect.left}, y=${region.pixelRect.top}, w=${region.pixelRect.width}, h=${region.pixelRect.height}; TARGET final visual box x=${targetPixelRect.left}, y=${targetPixelRect.top}, w=${targetPixelRect.width}, h=${targetPixelRect.height}; target scale is ${widthFactor.toFixed(2)}x width and ${heightFactor.toFixed(2)}x height. Main action: ${scaleDirection}.`;
})
.join("\n");
const cropLines = cropReferences
.map(
(reference, index) =>
`Input image ${index + 3}: clean crop reference for region ${reference.regionIndex}. Use it only to identify the selected furniture, its visible structure, proportions, material, and top objects. Never paste this crop into the output.`
)
.join("\n");
return [
"This is a local furniture scale-adjustment edit. It is not full-image resizing, not a collage, and not a patch-copy task.",
`Return one seamless realistic final photo with exactly the same camera frame and pixel size as input image 1: ${sourceSize.width} x ${sourceSize.height} px.`,
"Input image 1 is the clean original photo and must be treated as the locked background plate.",
"Input image 2 is a neutral coordinate instruction map with the same pixel size as input image 1. It is not a photo, not a texture source, not a layer, and not output content.",
"In input image 2, the lighter old/source outline only marks where to find the selected subject in input image 1. The darker target outline marks the desired final visual size and center.",
cropLines,
"Local furniture scale edit. Use input image 1 as the clean original photo and the locked camera frame.",
`Return one seamless realistic photo with the same frame and pixel size as input image 1: ${sourceSize.width} x ${sourceSize.height} px.`,
"Input image 2 is only a coordinate map. It is not output content. The OLD outline locates the current furniture in input image 1; the TARGET outline gives the final size and center.",
"",
"Task:",
"Identify the main independently adjustable furniture subject inside the old/source box in input image 1. Resize and, if needed, move only that furniture subject so its final visible footprint matches the target box size and center.",
"If the target box is smaller than the old/source box, the furniture must become clearly smaller. Remove the old larger footprint and naturally reconstruct the newly exposed rug, floor, wall base, shadows, cushion edges, and background continuity.",
"Preserve the selected furniture identity and structure from the original/crop reference: same tabletop, same objects on top, same material, same rectangular leg-frame design. Do not invent duplicate furniture, extra legs, side panels, shelves, cabinets, or a second copy.",
"Find the main movable furniture subject inside each OLD box in input image 1. Resize and, if needed, move that subject only so its final visible footprint matches the TARGET box.",
"Keep the furniture identity, material, perspective, objects on top, and natural aspect ratio from input image 1. Do not create a second copy or extra parts.",
"If the target is smaller, the furniture must visibly become smaller and the newly exposed floor, rug, wall, shadows, and background must be naturally healed. If the target is larger, enlarge the same furniture naturally without stretching it.",
"",
"Region requirements:",
regionLines,
"",
"Hard restrictions:",
"Do not copy, scale, move, or paste any rectangular area from input image 1, input image 2, or any crop reference.",
"Do not output guide marks, outlines, labels, haze, rectangular patch boundaries, seams, different-resolution blocks, color mismatch, or pasted edges.",
"Do not zoom, crop, pan, resize, reframe, or redesign the full canvas. Non-target background, camera perspective, lighting, color temperature, window blinds, wall, floor, rug, and cushion positions must remain coherent.",
"Success check: the selected furniture size must clearly change from the original, while the rest of the photo stays stable.",
"Do not paste rectangular image areas. Do not output coordinate lines, labels, boxes, seams, hard patch edges, haze, color mismatch, full-canvas zoom, crop, pan, or redesign.",
"Return only the clean edited photo.",
].join("\n");
}
@ -1169,7 +1156,8 @@ export async function POST(request: NextRequest) {
annotatedFilename,
toArrayBuffer(annotatedBuffer)
);
const scaleAdjustCropReferences = isScaleAdjustOperation
const scaleAdjustCropReferences =
isScaleAdjustOperation && !useFalScaleAdjustCoordinateGuide
? await createScaleAdjustCropReferences({
regions,
sourceBuffer,
@ -1182,7 +1170,6 @@ export async function POST(request: NextRequest) {
? buildFalScaleAdjustCoordinatePrompt(
regions,
scalePercent,
scaleAdjustCropReferences,
{
width: sourceWidth,
height: sourceHeight,
@ -1204,12 +1191,14 @@ export async function POST(request: NextRequest) {
(reference) => reference.url
);
const referenceImages = isScaleAdjustOperation
? [
sourceImageUrl,
annotatedUpload.url,
...scaleAdjustCropReferenceImageUrls,
...manualRegionReferenceImageUrls,
]
? useFalScaleAdjustCoordinateGuide
? [sourceImageUrl, annotatedUpload.url]
: [
sourceImageUrl,
annotatedUpload.url,
...scaleAdjustCropReferenceImageUrls,
...manualRegionReferenceImageUrls,
]
: [sourceImageUrl, ...manualRegionReferenceImageUrls];
const scaleAdjustCompositeRegions = isScaleAdjustOperation
? buildScaleAdjustCompositeRegions(regions, scalePercent)
@ -1251,7 +1240,7 @@ export async function POST(request: NextRequest) {
annotatedReferenceSentToModel: isScaleAdjustOperation,
annotatedReferenceType: isScaleAdjustOperation
? useFalScaleAdjustCoordinateGuide
? "scale-adjust-fal-coordinate-guide-plus-crop"
? "scale-adjust-fal-coordinate-guide-only"
: "scale-adjust-neutral-coordinate-guide-map"
: "source-overlay",
cleanSourceReferenceIndex: 1,
@ -1279,7 +1268,7 @@ export async function POST(request: NextRequest) {
.length,
scaleAdjustPromptStrategy: isScaleAdjustOperation
? useFalScaleAdjustCoordinateGuide
? "fal-locked-source-coordinate-crop-single-v23"
? "fal-locked-source-coordinate-single-v24"
: "locked-plate-neutral-coordinate-guide-map-pixel-anchors-v8"
: undefined,
scaleAdjustPostCompositeApplied: false,