got the inpainting mask sent to the server

This commit is contained in:
caranicas 2022-09-27 14:50:05 -04:00
parent 094687717d
commit 1961567ebd
4 changed files with 27 additions and 30 deletions

View File

@ -14,6 +14,7 @@ interface DrawImageProps {
brushShape: string; brushShape: string;
brushColor: string; brushColor: string;
isErasing: boolean; isErasing: boolean;
setData: (data: string) => void;
} }
export default function DrawImage({ export default function DrawImage({
@ -22,6 +23,7 @@ export default function DrawImage({
brushShape, brushShape,
brushColor, brushColor,
isErasing, isErasing,
setData,
}: DrawImageProps) { }: DrawImageProps) {
const drawingRef = useRef<HTMLCanvasElement>(null); const drawingRef = useRef<HTMLCanvasElement>(null);
const cursorRef = useRef<HTMLCanvasElement>(null); const cursorRef = useRef<HTMLCanvasElement>(null);
@ -74,7 +76,8 @@ export default function DrawImage({
const canvas = drawingRef.current; const canvas = drawingRef.current;
if (canvas != null) { if (canvas != null) {
const data = canvas.toDataURL(); const data = canvas.toDataURL();
// TODO: SEND THIS TO THE STATE debugger;
setData(data);
} }
}; };

View File

@ -50,6 +50,7 @@ export default function SeedImage(_props: any) {
const _handleClearImage = () => { const _handleClearImage = () => {
setRequestOption("init_image", undefined); setRequestOption("init_image", undefined);
setRequestOption("mask", undefined);
if (isInPaintingMode) { if (isInPaintingMode) {
toggleInpainting(); toggleInpainting();
} }
@ -82,7 +83,7 @@ export default function SeedImage(_props: any) {
X X
</button> </button>
</div> </div>
{/* <label> <label>
<input <input
type="checkbox" type="checkbox"
onChange={(e) => { onChange={(e) => {
@ -91,7 +92,7 @@ export default function SeedImage(_props: any) {
checked={isInPaintingMode} checked={isInPaintingMode}
></input> ></input>
{t("in-paint.txt")} {t("in-paint.txt")}
</label> */} </label>
</> </>
)} )}
</div> </div>

View File

@ -11,7 +11,7 @@ import {
export default function InpaintingPanel() { export default function InpaintingPanel() {
// no idea if this is the right typing // no idea if this is the right typing
const drawingRef = useRef(null); // const drawingRef = useRef(null);
const [brushSize, setBrushSize] = useState("20"); const [brushSize, setBrushSize] = useState("20");
const [brushShape, setBrushShape] = useState("round"); const [brushShape, setBrushShape] = useState("round");
@ -22,6 +22,13 @@ export default function InpaintingPanel() {
state.getValueForRequestKey("init_image") state.getValueForRequestKey("init_image")
); );
const setRequestOption = useImageCreate((state) => state.setRequestOptions);
const setMask = (data: string) => {
setRequestOption("mask", data);
}
const _handleBrushMask = () => { const _handleBrushMask = () => {
setIsErasing(false); setIsErasing(false);
}; };
@ -30,15 +37,6 @@ export default function InpaintingPanel() {
setIsErasing(true); setIsErasing(true);
}; };
const _handleFillMask = () => {
console.log("fill mask!!", drawingRef);
// drawingRef.current?.fillCanvas();
};
const _handleClearAll = () => {
console.log("clear all");
};
const _handleBrushSize = (event: ChangeEvent<HTMLInputElement>) => { const _handleBrushSize = (event: ChangeEvent<HTMLInputElement>) => {
setBrushSize(event.target.value); setBrushSize(event.target.value);
@ -53,17 +51,18 @@ export default function InpaintingPanel() {
brushShape={brushShape} brushShape={brushShape}
brushColor={brushColor} brushColor={brushColor}
isErasing={isErasing} isErasing={isErasing}
setData={setMask}
/> />
<div className={InpaintingControls}> <div className={InpaintingControls}>
<div className={InpaintingControlRow}> <div className={InpaintingControlRow}>
<button onClick={_handleBrushMask}>Mask</button> <button onClick={_handleBrushMask}>Mask</button>
<button onClick={_handleBrushErase}>Erase</button> <button onClick={_handleBrushErase}>Erase</button>
<button disabled onClick={_handleFillMask}> {/* <button disabled onClick={_handleFillMask}>
Fill Fill
</button> </button>
<button disabled onClick={_handleClearAll}> <button disabled onClick={_handleClearAll}>
Clear Clear
</button> </button> */}
<label> <label>
Brush Size Brush Size
@ -93,20 +92,20 @@ export default function InpaintingPanel() {
Square Brush Square Brush
</button> </button>
<button {/* <button
onClick={() => { onClick={() => {
setBrushColor("#000"); setBrushColor("#000");
}} }}
> >
Dark Brush Dark Brush
</button> </button> */}
<button {/* <button
onClick={() => { onClick={() => {
setBrushColor("#fff"); setBrushColor("#fff");
}} }}
> >
Light Brush Light Brush
</button> </button> */}
</div> </div>
</div> </div>
</div> </div>

View File

@ -71,9 +71,11 @@ export interface ImageRequest {
show_only_filtered_image: boolean; show_only_filtered_image: boolean;
init_image: undefined | string; init_image: undefined | string;
prompt_strength: undefined | number; prompt_strength: undefined | number;
mask: undefined | string;
sampler: typeof SAMPLER_OPTIONS[number]; sampler: typeof SAMPLER_OPTIONS[number];
stream_progress_updates: true; stream_progress_updates: true;
stream_image_progress: boolean; stream_image_progress: boolean;
} }
export interface ModifierPreview { export interface ModifierPreview {
@ -155,7 +157,8 @@ export const useImageCreate = create<ImageCreateState>(
init_image: undefined, init_image: undefined,
sampler: "plms", sampler: "plms",
stream_progress_updates: true, stream_progress_updates: true,
stream_image_progress: false stream_image_progress: false,
mask: undefined,
}, },
// selected tags // selected tags
@ -217,15 +220,6 @@ export const useImageCreate = create<ImageCreateState>(
state.tagMap[category] = [tag]; state.tagMap[category] = [tag];
} }
// const index = state.tags.indexOf(tag);
// if (index > -1) {
// state.tags.splice(index, 1);
// } else {
// state.tags.push(tag);
// }
}) })
); );
}, },
@ -307,7 +301,7 @@ export const useImageCreate = create<ImageCreateState>(
) { ) {
request.show_only_filtered_image = false; request.show_only_filtered_image = false;
} }
debugger;
return request; return request;
}, },