IOPaint/lama_cleaner/app/src/components/Settings/HDSettingBlock.tsx

139 lines
3.6 KiB
TypeScript
Raw Normal View History

2022-04-12 14:58:57 +02:00
import React, { ReactNode } from 'react'
import { useRecoilState } from 'recoil'
import { settingState } from '../../store/Atoms'
import Selector from '../shared/Selector'
2022-04-15 18:11:51 +02:00
import NumberInputSetting from './NumberInputSetting'
2022-04-12 14:58:57 +02:00
import SettingBlock from './SettingBlock'
export enum HDStrategy {
ORIGINAL = 'Original',
2022-04-15 18:11:51 +02:00
RESIZE = 'Resize',
2022-04-12 14:58:57 +02:00
CROP = 'Crop',
}
2022-06-12 07:14:17 +02:00
export enum LDMSampler {
ddim = 'ddim',
plms = 'plms',
}
2022-04-12 14:58:57 +02:00
function HDSettingBlock() {
const [setting, setSettingState] = useRecoilState(settingState)
const onStrategyChange = (value: HDStrategy) => {
setSettingState(old => {
return { ...old, hdStrategy: value }
})
}
const onResizeLimitChange = (value: string) => {
2022-04-14 14:43:07 +02:00
const val = value.length === 0 ? 0 : parseInt(value, 10)
2022-04-12 14:58:57 +02:00
setSettingState(old => {
2022-04-14 14:43:07 +02:00
return { ...old, hdStrategyResizeLimit: val }
2022-04-12 14:58:57 +02:00
})
}
const onCropTriggerSizeChange = (value: string) => {
2022-04-14 14:43:07 +02:00
const val = value.length === 0 ? 0 : parseInt(value, 10)
2022-04-12 14:58:57 +02:00
setSettingState(old => {
2022-04-14 14:43:07 +02:00
return { ...old, hdStrategyCropTrigerSize: val }
})
}
const onCropMarginChange = (value: string) => {
const val = value.length === 0 ? 0 : parseInt(value, 10)
setSettingState(old => {
return { ...old, hdStrategyCropMargin: val }
2022-04-12 14:58:57 +02:00
})
}
const renderOriginalOptionDesc = () => {
return (
<div>
Use the original resolution of the picture, suitable for picture size
2022-04-14 14:43:07 +02:00
below 2K. Try{' '}
<div
tabIndex={0}
role="button"
className="inline-tip"
2022-04-15 18:11:51 +02:00
onClick={() => onStrategyChange(HDStrategy.RESIZE)}
2022-04-14 14:43:07 +02:00
>
Resize Strategy
</div>{' '}
if you do not get good results on high resolution images.
2022-04-12 14:58:57 +02:00
</div>
)
}
const renderResizeOptionDesc = () => {
return (
<div>
<div>
Resize the longer side of the image to a specific size(keep ratio),
2022-04-14 14:43:07 +02:00
then do inpainting on the resized image.
2022-04-12 14:58:57 +02:00
</div>
2022-04-15 18:11:51 +02:00
<NumberInputSetting
2022-04-12 14:58:57 +02:00
title="Size limit"
value={`${setting.hdStrategyResizeLimit}`}
2022-04-15 18:11:51 +02:00
suffix="pixel"
2022-04-12 14:58:57 +02:00
onValue={onResizeLimitChange}
/>
</div>
)
}
const renderCropOptionDesc = () => {
return (
<div>
<div>
Crop masking area from the original image to do inpainting, and paste
the result back. Mainly for performance and memory reasons on high
resolution image.
</div>
2022-04-15 18:11:51 +02:00
<NumberInputSetting
2022-04-12 14:58:57 +02:00
title="Trigger size"
value={`${setting.hdStrategyCropTrigerSize}`}
2022-04-15 18:11:51 +02:00
suffix="pixel"
2022-04-12 14:58:57 +02:00
onValue={onCropTriggerSizeChange}
/>
2022-04-15 18:11:51 +02:00
<NumberInputSetting
2022-04-14 14:43:07 +02:00
title="Crop margin"
value={`${setting.hdStrategyCropMargin}`}
2022-04-15 18:11:51 +02:00
suffix="pixel"
2022-04-14 14:43:07 +02:00
onValue={onCropMarginChange}
/>
2022-04-12 14:58:57 +02:00
</div>
)
}
const renderHDStrategyOptionDesc = (): ReactNode => {
switch (setting.hdStrategy) {
case HDStrategy.ORIGINAL:
return renderOriginalOptionDesc()
case HDStrategy.CROP:
return renderCropOptionDesc()
2022-04-15 18:11:51 +02:00
case HDStrategy.RESIZE:
2022-04-12 14:58:57 +02:00
return renderResizeOptionDesc()
default:
return renderOriginalOptionDesc()
}
}
return (
<SettingBlock
2022-04-14 14:43:07 +02:00
className="hd-setting-block"
2022-04-12 14:58:57 +02:00
title="High Resolution Strategy"
input={
<Selector
2022-05-21 09:13:09 +02:00
width={80}
2022-04-14 14:43:07 +02:00
value={setting.hdStrategy as string}
2022-04-12 14:58:57 +02:00
options={Object.values(HDStrategy)}
onChange={val => onStrategyChange(val as HDStrategy)}
/>
}
optionDesc={renderHDStrategyOptionDesc()}
/>
)
}
export default HDSettingBlock