import React, { ReactNode } from 'react' import { useRecoilState } from 'recoil' import { settingState } from '../../store/Atoms' import Selector from '../shared/Selector' import NumberInputSetting from './NumberInputSetting' import SettingBlock from './SettingBlock' export enum HDStrategy { ORIGINAL = 'Original', RESIZE = 'Resize', CROP = 'Crop', } function HDSettingBlock() { const [setting, setSettingState] = useRecoilState(settingState) const onStrategyChange = (value: HDStrategy) => { setSettingState(old => { return { ...old, hdStrategy: value } }) } const onResizeLimitChange = (value: string) => { const val = value.length === 0 ? 0 : parseInt(value, 10) setSettingState(old => { return { ...old, hdStrategyResizeLimit: val } }) } const onCropTriggerSizeChange = (value: string) => { const val = value.length === 0 ? 0 : parseInt(value, 10) setSettingState(old => { return { ...old, hdStrategyCropTrigerSize: val } }) } const onCropMarginChange = (value: string) => { const val = value.length === 0 ? 0 : parseInt(value, 10) setSettingState(old => { return { ...old, hdStrategyCropMargin: val } }) } const renderOriginalOptionDesc = () => { return (
Use the original resolution of the picture, suitable for picture size below 2K. Try{' '}
onStrategyChange(HDStrategy.RESIZE)} > Resize Strategy
{' '} if you do not get good results on high resolution images.
) } const renderResizeOptionDesc = () => { return (
Resize the longer side of the image to a specific size(keep ratio), then do inpainting on the resized image.
) } const renderCropOptionDesc = () => { return (
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.
) } const renderHDStrategyOptionDesc = (): ReactNode => { switch (setting.hdStrategy) { case HDStrategy.ORIGINAL: return renderOriginalOptionDesc() case HDStrategy.CROP: return renderCropOptionDesc() case HDStrategy.RESIZE: return renderResizeOptionDesc() default: return renderOriginalOptionDesc() } } return ( onStrategyChange(val as HDStrategy)} /> } optionDesc={renderHDStrategyOptionDesc()} /> ) } export default HDSettingBlock