12 changed files with 202 additions and 46 deletions
@ -0,0 +1,20 @@ |
|||
import { describe, expect, it } from "vitest"; |
|||
|
|||
import { deriveOutpaintingOutputDimensions } from "../outpaintingNodes"; |
|||
|
|||
describe("deriveOutpaintingOutputDimensions", () => { |
|||
it("expands source dimensions from outpainting insets", () => { |
|||
expect( |
|||
deriveOutpaintingOutputDimensions( |
|||
{ width: 1000, height: 500 }, |
|||
{ left: 0.2, right: 0.3, top: 0.1, bottom: 0.1 } |
|||
) |
|||
).toEqual({ width: 1500, height: 600 }); |
|||
}); |
|||
|
|||
it("returns null when source dimensions are unavailable", () => { |
|||
expect( |
|||
deriveOutpaintingOutputDimensions(null, { left: 0.2, right: 0.3, top: 0.1, bottom: 0.1 }) |
|||
).toBeNull(); |
|||
}); |
|||
}); |
|||
@ -1 +1,24 @@ |
|||
export const OUTPAINTING_DEFAULT_PROMPT = "将画面自然延展,补充完整场景"; |
|||
|
|||
interface MediaDimensions { |
|||
width: number; |
|||
height: number; |
|||
} |
|||
|
|||
interface OutpaintingInsets { |
|||
top: number; |
|||
left: number; |
|||
right: number; |
|||
bottom: number; |
|||
} |
|||
|
|||
export function deriveOutpaintingOutputDimensions( |
|||
sourceDimensions: MediaDimensions | null | undefined, |
|||
params: OutpaintingInsets |
|||
): MediaDimensions | null { |
|||
if (!sourceDimensions) return null; |
|||
return { |
|||
width: Math.max(1, Math.round(sourceDimensions.width * (1 + params.left + params.right))), |
|||
height: Math.max(1, Math.round(sourceDimensions.height * (1 + params.top + params.bottom))), |
|||
}; |
|||
} |
|||
|
|||
Loading…
Reference in new issue