Browse Source

擦除 修改

feature/071
yun 5 days ago
parent
commit
2b495003fb
  1. 20
      src/components/media/MediaInpaintingOverlay.tsx
  2. 2
      src/components/media/image-edit/InpaintingEditSession.tsx

20
src/components/media/MediaInpaintingOverlay.tsx

@ -42,6 +42,10 @@ interface MediaInpaintingOverlayProps {
const MAX_HISTORY = 30;
function clamp(value: number, min: number, max: number) {
return Math.min(max, Math.max(min, value));
}
function validDimensions(width: unknown, height: unknown): { width: number; height: number } | null {
return typeof width === "number" && typeof height === "number" && width > 0 && height > 0
? { width, height }
@ -269,8 +273,8 @@ export function MediaInpaintingOverlay({
const canvas = canvasRef.current;
if (!rect || !canvas) return null;
return {
x: ((event.clientX - rect.left) / rect.width) * canvas.width,
y: ((event.clientY - rect.top) / rect.height) * canvas.height,
x: clamp(((event.clientX - rect.left) / rect.width) * canvas.width, 0, canvas.width),
y: clamp(((event.clientY - rect.top) / rect.height) * canvas.height, 0, canvas.height),
};
}, []);
@ -278,8 +282,16 @@ export function MediaInpaintingOverlay({
const rect = canvasRef.current?.getBoundingClientRect();
if (!rect || !bounds) return null;
return {
x: bounds.left + ((event.clientX - rect.left) / rect.width) * bounds.width,
y: bounds.top + ((event.clientY - rect.top) / rect.height) * bounds.height,
x: clamp(
bounds.left + ((event.clientX - rect.left) / rect.width) * bounds.width,
bounds.left,
bounds.left + bounds.width
),
y: clamp(
bounds.top + ((event.clientY - rect.top) / rect.height) * bounds.height,
bounds.top,
bounds.top + bounds.height
),
};
}, [bounds]);

2
src/components/media/image-edit/InpaintingEditSession.tsx

@ -23,7 +23,7 @@ export function InpaintingEditSession({
const [mask, setMask] = useState<MediaInpaintingMaskPayload | null>(null);
const [prompt, setPrompt] = useState("");
const [batchSize, setBatchSize] = useState<InpaintingBatchSize>(1);
const [brushSize, setBrushSize] = useState(40);
const [brushSize, setBrushSize] = useState(90);
const [drawTool, setDrawTool] = useState<MediaInpaintingDrawTool>("brush");
const [eraseMode, setEraseMode] = useState(false);
const [frameRect, setFrameRect] = useState<MediaInpaintingFrameRect | null>(null);

Loading…
Cancel
Save