feat: Add Patchmatch Downscale control to UI + refine the ui there

This commit is contained in:
blessedcoolant 2023-09-02 10:24:32 +12:00
parent b73216ef81
commit 497f66e682
8 changed files with 120 additions and 19 deletions

View File

@ -520,6 +520,7 @@
"scaledHeight": "Scaled H", "scaledHeight": "Scaled H",
"infillMethod": "Infill Method", "infillMethod": "Infill Method",
"tileSize": "Tile Size", "tileSize": "Tile Size",
"patchmatchDownScaleSize": "Downscale",
"boundingBoxHeader": "Bounding Box", "boundingBoxHeader": "Bounding Box",
"seamCorrectionHeader": "Seam Correction", "seamCorrectionHeader": "Seam Correction",
"infillScalingHeader": "Infill and Scaling", "infillScalingHeader": "Infill and Scaling",

View File

@ -73,7 +73,8 @@ export const buildCanvasOutpaintGraph = (
maskBlur, maskBlur,
canvasCoherenceSteps, canvasCoherenceSteps,
canvasCoherenceStrength, canvasCoherenceStrength,
tileSize, infillTileSize,
infillPatchmatchDownscaleSize,
infillMethod, infillMethod,
clipSkip, clipSkip,
seamlessXAxis, seamlessXAxis,
@ -495,6 +496,7 @@ export const buildCanvasOutpaintGraph = (
type: 'infill_patchmatch', type: 'infill_patchmatch',
id: INPAINT_INFILL, id: INPAINT_INFILL,
is_intermediate: true, is_intermediate: true,
downscale: infillPatchmatchDownscaleSize,
}; };
} }
@ -519,7 +521,7 @@ export const buildCanvasOutpaintGraph = (
type: 'infill_tile', type: 'infill_tile',
id: INPAINT_INFILL, id: INPAINT_INFILL,
is_intermediate: true, is_intermediate: true,
tile_size: tileSize, tile_size: infillTileSize,
}; };
} }

View File

@ -74,7 +74,7 @@ export const buildCanvasSDXLOutpaintGraph = (
maskBlur, maskBlur,
canvasCoherenceSteps, canvasCoherenceSteps,
canvasCoherenceStrength, canvasCoherenceStrength,
tileSize, infillTileSize,
infillMethod, infillMethod,
seamlessXAxis, seamlessXAxis,
seamlessYAxis, seamlessYAxis,
@ -510,6 +510,7 @@ export const buildCanvasSDXLOutpaintGraph = (
type: 'infill_patchmatch', type: 'infill_patchmatch',
id: INPAINT_INFILL, id: INPAINT_INFILL,
is_intermediate: true, is_intermediate: true,
downscale: infillPatchmatchDownscaleSize,
}; };
} }
@ -534,7 +535,7 @@ export const buildCanvasSDXLOutpaintGraph = (
type: 'infill_tile', type: 'infill_tile',
id: INPAINT_INFILL, id: INPAINT_INFILL,
is_intermediate: true, is_intermediate: true,
tile_size: tileSize, tile_size: infillTileSize,
}; };
} }

View File

@ -5,7 +5,7 @@ import { useTranslation } from 'react-i18next';
import IAICollapse from 'common/components/IAICollapse'; import IAICollapse from 'common/components/IAICollapse';
import SubParametersWrapper from '../../SubParametersWrapper'; import SubParametersWrapper from '../../SubParametersWrapper';
import ParamInfillMethod from './ParamInfillMethod'; import ParamInfillMethod from './ParamInfillMethod';
import ParamInfillTilesize from './ParamInfillTilesize'; import ParamInfillOptions from './ParamInfillOptions';
import ParamScaleBeforeProcessing from './ParamScaleBeforeProcessing'; import ParamScaleBeforeProcessing from './ParamScaleBeforeProcessing';
import ParamScaledHeight from './ParamScaledHeight'; import ParamScaledHeight from './ParamScaledHeight';
import ParamScaledWidth from './ParamScaledWidth'; import ParamScaledWidth from './ParamScaledWidth';
@ -18,7 +18,7 @@ const ParamInfillCollapse = () => {
<Flex sx={{ gap: 2, flexDirection: 'column' }}> <Flex sx={{ gap: 2, flexDirection: 'column' }}>
<SubParametersWrapper> <SubParametersWrapper>
<ParamInfillMethod /> <ParamInfillMethod />
<ParamInfillTilesize /> <ParamInfillOptions />
</SubParametersWrapper> </SubParametersWrapper>
<Divider /> <Divider />
<SubParametersWrapper> <SubParametersWrapper>

View File

@ -0,0 +1,29 @@
import { Flex } from '@chakra-ui/react';
import { createSelector } from '@reduxjs/toolkit';
import { useAppSelector } from 'app/store/storeHooks';
import { defaultSelectorOptions } from 'app/store/util/defaultMemoizeOptions';
import { generationSelector } from 'features/parameters/store/generationSelectors';
import ParamInfillPatchmatchDownscaleSize from './ParamInfillPatchmatchDownscaleSize';
import ParamInfillTilesize from './ParamInfillTilesize';
const selector = createSelector(
[generationSelector],
(parameters) => {
const { infillMethod } = parameters;
return {
infillMethod,
};
},
defaultSelectorOptions
);
export default function ParamInfillOptions() {
const { infillMethod } = useAppSelector(selector);
return (
<Flex>
{infillMethod === 'tile' && <ParamInfillTilesize />}
{infillMethod === 'patchmatch' && <ParamInfillPatchmatchDownscaleSize />}
</Flex>
);
}

View File

@ -0,0 +1,59 @@
import { createSelector } from '@reduxjs/toolkit';
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
import { defaultSelectorOptions } from 'app/store/util/defaultMemoizeOptions';
import IAISlider from 'common/components/IAISlider';
import { generationSelector } from 'features/parameters/store/generationSelectors';
import { setInfillPatchmatchDownscaleSize } from 'features/parameters/store/generationSlice';
import { memo, useCallback } from 'react';
import { useTranslation } from 'react-i18next';
const selector = createSelector(
[generationSelector],
(parameters) => {
const { infillPatchmatchDownscaleSize, infillMethod } = parameters;
return {
infillPatchmatchDownscaleSize,
infillMethod,
};
},
defaultSelectorOptions
);
const ParamInfillPatchmatchDownscaleSize = () => {
const dispatch = useAppDispatch();
const { infillPatchmatchDownscaleSize, infillMethod } =
useAppSelector(selector);
const { t } = useTranslation();
const handleChange = useCallback(
(v: number) => {
dispatch(setInfillPatchmatchDownscaleSize(v));
},
[dispatch]
);
const handleReset = useCallback(() => {
dispatch(setInfillPatchmatchDownscaleSize(2));
}, [dispatch]);
return (
<IAISlider
isDisabled={infillMethod !== 'patchmatch'}
label={t('parameters.patchmatchDownScaleSize')}
min={1}
max={10}
sliderNumberInputProps={{ max: 10 }}
value={infillPatchmatchDownscaleSize}
onChange={handleChange}
withInput
withSliderMarks
withReset
handleReset={handleReset}
/>
);
};
export default memo(ParamInfillPatchmatchDownscaleSize);

View File

@ -3,7 +3,7 @@ import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
import { defaultSelectorOptions } from 'app/store/util/defaultMemoizeOptions'; import { defaultSelectorOptions } from 'app/store/util/defaultMemoizeOptions';
import IAISlider from 'common/components/IAISlider'; import IAISlider from 'common/components/IAISlider';
import { generationSelector } from 'features/parameters/store/generationSelectors'; import { generationSelector } from 'features/parameters/store/generationSelectors';
import { setTileSize } from 'features/parameters/store/generationSlice'; import { setInfillTileSize } from 'features/parameters/store/generationSlice';
import { memo, useCallback } from 'react'; import { memo, useCallback } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
@ -11,10 +11,10 @@ import { useTranslation } from 'react-i18next';
const selector = createSelector( const selector = createSelector(
[generationSelector], [generationSelector],
(parameters) => { (parameters) => {
const { tileSize, infillMethod } = parameters; const { infillTileSize, infillMethod } = parameters;
return { return {
tileSize, infillTileSize,
infillMethod, infillMethod,
}; };
}, },
@ -23,19 +23,19 @@ const selector = createSelector(
const ParamInfillTileSize = () => { const ParamInfillTileSize = () => {
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
const { tileSize, infillMethod } = useAppSelector(selector); const { infillTileSize, infillMethod } = useAppSelector(selector);
const { t } = useTranslation(); const { t } = useTranslation();
const handleChange = useCallback( const handleChange = useCallback(
(v: number) => { (v: number) => {
dispatch(setTileSize(v)); dispatch(setInfillTileSize(v));
}, },
[dispatch] [dispatch]
); );
const handleReset = useCallback(() => { const handleReset = useCallback(() => {
dispatch(setTileSize(32)); dispatch(setInfillTileSize(32));
}, [dispatch]); }, [dispatch]);
return ( return (
@ -45,7 +45,7 @@ const ParamInfillTileSize = () => {
min={16} min={16}
max={64} max={64}
sliderNumberInputProps={{ max: 256 }} sliderNumberInputProps={{ max: 256 }}
value={tileSize} value={infillTileSize}
onChange={handleChange} onChange={handleChange}
withInput withInput
withSliderMarks withSliderMarks

View File

@ -47,7 +47,8 @@ export interface GenerationState {
shouldUseNoiseSettings: boolean; shouldUseNoiseSettings: boolean;
steps: StepsParam; steps: StepsParam;
threshold: number; threshold: number;
tileSize: number; infillTileSize: number;
infillPatchmatchDownscaleSize: number;
variationAmount: number; variationAmount: number;
width: WidthParam; width: WidthParam;
shouldUseSymmetry: boolean; shouldUseSymmetry: boolean;
@ -87,7 +88,8 @@ export const initialGenerationState: GenerationState = {
shouldUseNoiseSettings: false, shouldUseNoiseSettings: false,
steps: 50, steps: 50,
threshold: 0, threshold: 0,
tileSize: 32, infillTileSize: 32,
infillPatchmatchDownscaleSize: 2,
variationAmount: 0.1, variationAmount: 0.1,
width: 512, width: 512,
shouldUseSymmetry: false, shouldUseSymmetry: false,
@ -212,12 +214,18 @@ export const generationSlice = createSlice({
setCanvasCoherenceStrength: (state, action: PayloadAction<number>) => { setCanvasCoherenceStrength: (state, action: PayloadAction<number>) => {
state.canvasCoherenceStrength = action.payload; state.canvasCoherenceStrength = action.payload;
}, },
setTileSize: (state, action: PayloadAction<number>) => {
state.tileSize = action.payload;
},
setInfillMethod: (state, action: PayloadAction<string>) => { setInfillMethod: (state, action: PayloadAction<string>) => {
state.infillMethod = action.payload; state.infillMethod = action.payload;
}, },
setInfillTileSize: (state, action: PayloadAction<number>) => {
state.infillTileSize = action.payload;
},
setInfillPatchmatchDownscaleSize: (
state,
action: PayloadAction<number>
) => {
state.infillPatchmatchDownscaleSize = action.payload;
},
setShouldUseSymmetry: (state, action: PayloadAction<boolean>) => { setShouldUseSymmetry: (state, action: PayloadAction<boolean>) => {
state.shouldUseSymmetry = action.payload; state.shouldUseSymmetry = action.payload;
}, },
@ -332,7 +340,8 @@ export const {
setShouldRandomizeSeed, setShouldRandomizeSeed,
setSteps, setSteps,
setThreshold, setThreshold,
setTileSize, setInfillTileSize,
setInfillPatchmatchDownscaleSize,
setVariationAmount, setVariationAmount,
setShouldUseSymmetry, setShouldUseSymmetry,
setHorizontalSymmetrySteps, setHorizontalSymmetrySteps,