1
0
Fork 0

feat(gui): add fill with white, toggle for outpainting

This commit is contained in:
Sean Sube 2023-01-14 18:30:27 -06:00
parent 09c9b2c028
commit 0d53fdfe53
6 changed files with 47 additions and 8 deletions

View File

@ -46,6 +46,8 @@ export interface InpaintParams extends BaseImgParams {
} }
export interface OutpaintPixels { export interface OutpaintPixels {
enabled: boolean;
left: number; left: number;
right: number; right: number;
top: number; top: number;

View File

@ -27,7 +27,7 @@ export function Inpaint(props: InpaintProps) {
async function uploadSource(): Promise<void> { async function uploadSource(): Promise<void> {
const outpaint = state.getState().outpaint; // TODO: seems shady const outpaint = state.getState().outpaint; // TODO: seems shady
if (outpaint.bottom > 0 || outpaint.left > 0 || outpaint.right > 0 || outpaint.top > 0) { if (outpaint.enabled) {
const output = await client.outpaint({ const output = await client.outpaint({
...params, ...params,
...outpaint, ...outpaint,

View File

@ -233,8 +233,8 @@ export function MaskCanvas(props: MaskCanvasProps) {
<Stack direction='row' spacing={4}> <Stack direction='row' spacing={4}>
<NumericField <NumericField
label='Brush Color' label='Brush Color'
min={0} min={COLORS.black}
max={255} max={COLORS.white}
step={1} step={1}
value={brush.color} value={brush.color}
onChange={(color) => { onChange={(color) => {
@ -243,7 +243,7 @@ export function MaskCanvas(props: MaskCanvasProps) {
/> />
<NumericField <NumericField
label='Brush Size' label='Brush Size'
min={4} min={1}
max={64} max={64}
step={1} step={1}
value={brush.size} value={brush.size}
@ -282,6 +282,16 @@ export function MaskCanvas(props: MaskCanvasProps) {
}}> }}>
Fill with black Fill with black
</Button> </Button>
<Button
variant='outlined'
startIcon={<FormatColorFill />}
onClick={() => {
floodCanvas(bufferRef, floodWhite);
drawBuffer();
save();
}}>
Fill with white
</Button>
<Button <Button
variant='outlined' variant='outlined'
startIcon={<Gradient />} startIcon={<Gradient />}
@ -333,7 +343,11 @@ export function floodAbove(n: number): number {
} }
export function floodBlack(): number { export function floodBlack(): number {
return 0; return COLORS.black;
}
export function floodWhite(): number {
return COLORS.white;
} }
export function grayToRGB(n: number, o = 1.0): string { export function grayToRGB(n: number, o = 1.0): string {
@ -355,7 +369,7 @@ function floodCanvas(ref: RefObject<HTMLCanvasElement>, flood: FloodFn) {
pixels[i + 1] = final; pixels[i + 1] = final;
pixels[i + 2] = final; pixels[i + 2] = final;
// eslint-disable-next-line @typescript-eslint/no-magic-numbers // eslint-disable-next-line @typescript-eslint/no-magic-numbers
pixels[i + 3] = 255; pixels[i + 3] = COLORS.white; // fully opaque
} }
} }

View File

@ -12,6 +12,7 @@ export function parseNumber(num: string, decimal = false): number {
export interface ImageControlProps { export interface ImageControlProps {
decimal?: boolean; decimal?: boolean;
disabled?: boolean;
label: string; label: string;
min: number; min: number;
max: number; max: number;
@ -22,10 +23,12 @@ export interface ImageControlProps {
} }
export function NumericField(props: ImageControlProps) { export function NumericField(props: ImageControlProps) {
const { decimal, label, min, max, step, value } = props; const { decimal = false, disabled = false, label, min, max, step, value } = props;
return <Stack spacing={2}> return <Stack spacing={2}>
<TextField <TextField
label={label} label={label}
disabled={disabled}
variant='outlined' variant='outlined'
type='number' type='number'
inputProps={{ min, max, step }} inputProps={{ min, max, step }}
@ -37,6 +40,7 @@ export function NumericField(props: ImageControlProps) {
}} }}
/> />
<Slider <Slider
disabled={disabled}
min={min} min={min}
max={max} max={max}
step={step} step={step}

View File

@ -1,5 +1,6 @@
import { mustExist } from '@apextoaster/js-utils'; import { mustExist } from '@apextoaster/js-utils';
import { Stack } from '@mui/material'; import { Check } from '@mui/icons-material';
import { Stack, ToggleButton } from '@mui/material';
import * as React from 'react'; import * as React from 'react';
import { useContext } from 'react'; import { useContext } from 'react';
import { useStore } from 'zustand'; import { useStore } from 'zustand';
@ -21,8 +22,22 @@ export function OutpaintControl(props: OutpaintControlProps) {
const setOutpaint = useStore(state, (s) => s.setOutpaint); const setOutpaint = useStore(state, (s) => s.setOutpaint);
return <Stack direction='row' spacing={4}> return <Stack direction='row' spacing={4}>
<ToggleButton
color='primary'
selected={params.enabled}
value='check'
onChange={(event) => {
setOutpaint({
enabled: params.enabled === false,
});
}}
>
<Check />
Outpainting
</ToggleButton>
<NumericField <NumericField
label='Left' label='Left'
disabled={params.enabled === false}
min={0} min={0}
max={config.width.max} max={config.width.max}
step={config.width.step} step={config.width.step}
@ -35,6 +50,7 @@ export function OutpaintControl(props: OutpaintControlProps) {
/> />
<NumericField <NumericField
label='Right' label='Right'
disabled={params.enabled === false}
min={0} min={0}
max={config.width.max} max={config.width.max}
step={config.width.step} step={config.width.step}
@ -47,6 +63,7 @@ export function OutpaintControl(props: OutpaintControlProps) {
/> />
<NumericField <NumericField
label='Top' label='Top'
disabled={params.enabled === false}
min={0} min={0}
max={config.height.max} max={config.height.max}
step={config.height.step} step={config.height.step}
@ -59,6 +76,7 @@ export function OutpaintControl(props: OutpaintControlProps) {
/> />
<NumericField <NumericField
label='Bottom' label='Bottom'
disabled={params.enabled === false}
min={0} min={0}
max={config.height.max} max={config.height.max}
step={config.height.step} step={config.height.step}

View File

@ -184,6 +184,7 @@ export function createStateSlices(base: ConfigParams) {
const createOutpaintSlice: StateCreator<OnnxState, [], [], OutpaintSlice> = (set) => ({ const createOutpaintSlice: StateCreator<OnnxState, [], [], OutpaintSlice> = (set) => ({
outpaint: { outpaint: {
enabled: false,
left: 0, left: 0,
right: 0, right: 0,
top: 0, top: 0,