mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
feat(ui): allow multiple inpaint masks
This is easier than making it a nullable singleton
This commit is contained in:
parent
c612f18114
commit
5101873f49
@ -1677,6 +1677,7 @@
|
|||||||
"controlLayers_withCount": "Control Layers ({{count}})",
|
"controlLayers_withCount": "Control Layers ({{count}})",
|
||||||
"rasterLayers_withCount": "Raster Layers ({{count}})",
|
"rasterLayers_withCount": "Raster Layers ({{count}})",
|
||||||
"ipAdapters_withCount": "IP Adapters ({{count}})",
|
"ipAdapters_withCount": "IP Adapters ({{count}})",
|
||||||
|
"inpaintMasks_withCount": "Inpaint Masks ({{count}})",
|
||||||
"globalControlAdapter": "Global $t(controlnet.controlAdapter_one)",
|
"globalControlAdapter": "Global $t(controlnet.controlAdapter_one)",
|
||||||
"globalControlAdapterLayer": "Global $t(controlnet.controlAdapter_one) $t(unifiedCanvas.layer)",
|
"globalControlAdapterLayer": "Global $t(controlnet.controlAdapter_one) $t(unifiedCanvas.layer)",
|
||||||
"globalIPAdapter": "Global $t(common.ipAdapter)",
|
"globalIPAdapter": "Global $t(common.ipAdapter)",
|
||||||
|
@ -1,7 +1,13 @@
|
|||||||
import { IconButton, Menu, MenuButton, MenuItem, MenuList } from '@invoke-ai/ui-library';
|
import { IconButton, Menu, MenuButton, MenuItem, MenuList } from '@invoke-ai/ui-library';
|
||||||
import { useAppDispatch } from 'app/store/storeHooks';
|
import { useAppDispatch } from 'app/store/storeHooks';
|
||||||
import { useDefaultControlAdapter, useDefaultIPAdapter } from 'features/controlLayers/hooks/useLayerControlAdapter';
|
import { useDefaultControlAdapter, useDefaultIPAdapter } from 'features/controlLayers/hooks/useLayerControlAdapter';
|
||||||
import { controlLayerAdded, ipaAdded, rasterLayerAdded, rgAdded } from 'features/controlLayers/store/canvasV2Slice';
|
import {
|
||||||
|
controlLayerAdded,
|
||||||
|
inpaintMaskAdded,
|
||||||
|
ipaAdded,
|
||||||
|
rasterLayerAdded,
|
||||||
|
rgAdded,
|
||||||
|
} from 'features/controlLayers/store/canvasV2Slice';
|
||||||
import { memo, useCallback } from 'react';
|
import { memo, useCallback } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { PiPlusBold } from 'react-icons/pi';
|
import { PiPlusBold } from 'react-icons/pi';
|
||||||
@ -11,7 +17,10 @@ export const AddLayerButton = memo(() => {
|
|||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
const defaultControlAdapter = useDefaultControlAdapter();
|
const defaultControlAdapter = useDefaultControlAdapter();
|
||||||
const defaultIPAdapter = useDefaultIPAdapter();
|
const defaultIPAdapter = useDefaultIPAdapter();
|
||||||
const addRGLayer = useCallback(() => {
|
const addInpaintMask = useCallback(() => {
|
||||||
|
dispatch(inpaintMaskAdded());
|
||||||
|
}, [dispatch]);
|
||||||
|
const addRegionalGuidance = useCallback(() => {
|
||||||
dispatch(rgAdded());
|
dispatch(rgAdded());
|
||||||
}, [dispatch]);
|
}, [dispatch]);
|
||||||
const addRasterLayer = useCallback(() => {
|
const addRasterLayer = useCallback(() => {
|
||||||
@ -34,7 +43,8 @@ export const AddLayerButton = memo(() => {
|
|||||||
data-testid="control-layers-add-layer-menu-button"
|
data-testid="control-layers-add-layer-menu-button"
|
||||||
/>
|
/>
|
||||||
<MenuList>
|
<MenuList>
|
||||||
<MenuItem onClick={addRGLayer}>{t('controlLayers.regionalGuidanceLayer')}</MenuItem>
|
<MenuItem onClick={addInpaintMask}>{t('controlLayers.inpaintMask')}</MenuItem>
|
||||||
|
<MenuItem onClick={addRegionalGuidance}>{t('controlLayers.regionalGuidance')}</MenuItem>
|
||||||
<MenuItem onClick={addRasterLayer}>{t('controlLayers.rasterLayer')}</MenuItem>
|
<MenuItem onClick={addRasterLayer}>{t('controlLayers.rasterLayer')}</MenuItem>
|
||||||
<MenuItem onClick={addControlLayer}>{t('controlLayers.controlLayer')}</MenuItem>
|
<MenuItem onClick={addControlLayer}>{t('controlLayers.controlLayer')}</MenuItem>
|
||||||
<MenuItem onClick={addIPAdapter}>{t('controlLayers.globalIPAdapterLayer')}</MenuItem>
|
<MenuItem onClick={addIPAdapter}>{t('controlLayers.globalIPAdapterLayer')}</MenuItem>
|
||||||
|
@ -2,7 +2,7 @@ import { Flex } from '@invoke-ai/ui-library';
|
|||||||
import ScrollableContent from 'common/components/OverlayScrollbars/ScrollableContent';
|
import ScrollableContent from 'common/components/OverlayScrollbars/ScrollableContent';
|
||||||
import { CanvasEntityOpacity } from 'features/controlLayers/components/common/CanvasEntityOpacity';
|
import { CanvasEntityOpacity } from 'features/controlLayers/components/common/CanvasEntityOpacity';
|
||||||
import { ControlLayerEntityList } from 'features/controlLayers/components/ControlLayer/ControlLayerEntityList';
|
import { ControlLayerEntityList } from 'features/controlLayers/components/ControlLayer/ControlLayerEntityList';
|
||||||
import { InpaintMask } from 'features/controlLayers/components/InpaintMask/InpaintMask';
|
import { InpaintMaskList } from 'features/controlLayers/components/InpaintMask/InpaintMaskList';
|
||||||
import { IPAdapterList } from 'features/controlLayers/components/IPAdapter/IPAdapterList';
|
import { IPAdapterList } from 'features/controlLayers/components/IPAdapter/IPAdapterList';
|
||||||
import { RasterLayerEntityList } from 'features/controlLayers/components/RasterLayer/RasterLayerEntityList';
|
import { RasterLayerEntityList } from 'features/controlLayers/components/RasterLayer/RasterLayerEntityList';
|
||||||
import { RegionalGuidanceEntityList } from 'features/controlLayers/components/RegionalGuidance/RegionalGuidanceEntityList';
|
import { RegionalGuidanceEntityList } from 'features/controlLayers/components/RegionalGuidance/RegionalGuidanceEntityList';
|
||||||
@ -13,7 +13,7 @@ export const CanvasEntityList = memo(() => {
|
|||||||
<ScrollableContent>
|
<ScrollableContent>
|
||||||
<Flex flexDir="column" gap={4} pt={2} data-testid="control-layers-layer-list">
|
<Flex flexDir="column" gap={4} pt={2} data-testid="control-layers-layer-list">
|
||||||
<CanvasEntityOpacity />
|
<CanvasEntityOpacity />
|
||||||
<InpaintMask />
|
<InpaintMaskList />
|
||||||
<RegionalGuidanceEntityList />
|
<RegionalGuidanceEntityList />
|
||||||
<IPAdapterList />
|
<IPAdapterList />
|
||||||
<ControlLayerEntityList />
|
<ControlLayerEntityList />
|
||||||
|
@ -54,7 +54,7 @@ const ControlLayersSettingsPopover = () => {
|
|||||||
for (const adapter of canvasManager.regionalGuidanceAdapters.values()) {
|
for (const adapter of canvasManager.regionalGuidanceAdapters.values()) {
|
||||||
adapter.transformer.requestRectCalculation();
|
adapter.transformer.requestRectCalculation();
|
||||||
}
|
}
|
||||||
canvasManager.inpaintMaskAdapter.transformer.requestRectCalculation();
|
canvasManager.inpaintMaskAdapters.transformer.requestRectCalculation();
|
||||||
}, [canvasManager]);
|
}, [canvasManager]);
|
||||||
return (
|
return (
|
||||||
<Popover isLazy>
|
<Popover isLazy>
|
||||||
|
@ -1,36 +1,32 @@
|
|||||||
import { Flex, Spacer } from '@invoke-ai/ui-library';
|
import { Spacer } from '@invoke-ai/ui-library';
|
||||||
import { useAppSelector } from 'app/store/storeHooks';
|
|
||||||
import { CanvasEntityContainer } from 'features/controlLayers/components/common/CanvasEntityContainer';
|
import { CanvasEntityContainer } from 'features/controlLayers/components/common/CanvasEntityContainer';
|
||||||
import { CanvasEntityEnabledToggle } from 'features/controlLayers/components/common/CanvasEntityEnabledToggle';
|
import { CanvasEntityEnabledToggle } from 'features/controlLayers/components/common/CanvasEntityEnabledToggle';
|
||||||
import { CanvasEntityGroupList } from 'features/controlLayers/components/common/CanvasEntityGroupList';
|
|
||||||
import { CanvasEntityHeader } from 'features/controlLayers/components/common/CanvasEntityHeader';
|
import { CanvasEntityHeader } from 'features/controlLayers/components/common/CanvasEntityHeader';
|
||||||
import { CanvasEntityTitle } from 'features/controlLayers/components/common/CanvasEntityTitle';
|
import { CanvasEntityEditableTitle } from 'features/controlLayers/components/common/CanvasEntityTitleEdit';
|
||||||
import { EntityIdentifierContext } from 'features/controlLayers/contexts/EntityIdentifierContext';
|
import { EntityIdentifierContext } from 'features/controlLayers/contexts/EntityIdentifierContext';
|
||||||
import type { CanvasEntityIdentifier } from 'features/controlLayers/store/types';
|
import type { CanvasEntityIdentifier } from 'features/controlLayers/store/types';
|
||||||
import { memo, useMemo } from 'react';
|
import { memo, useMemo } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
|
||||||
|
|
||||||
import { InpaintMaskMaskFillColorPicker } from './InpaintMaskMaskFillColorPicker';
|
import { InpaintMaskMaskFillColorPicker } from './InpaintMaskMaskFillColorPicker';
|
||||||
|
|
||||||
export const InpaintMask = memo(() => {
|
type Props = {
|
||||||
const { t } = useTranslation();
|
id: string;
|
||||||
const entityIdentifier = useMemo<CanvasEntityIdentifier>(() => ({ id: 'inpaint_mask', type: 'inpaint_mask' }), []);
|
};
|
||||||
const isSelected = useAppSelector((s) => Boolean(s.canvasV2.selectedEntityIdentifier?.type === 'inpaint_mask'));
|
|
||||||
|
export const InpaintMask = memo(({ id }: Props) => {
|
||||||
|
const entityIdentifier = useMemo<CanvasEntityIdentifier>(() => ({ id, type: 'inpaint_mask' }), [id]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Flex flexDir="column" gap={2}>
|
|
||||||
<CanvasEntityGroupList title={t('controlLayers.inpaintMask')} isSelected={isSelected} type="inpaint_mask" />
|
|
||||||
<EntityIdentifierContext.Provider value={entityIdentifier}>
|
<EntityIdentifierContext.Provider value={entityIdentifier}>
|
||||||
<CanvasEntityContainer>
|
<CanvasEntityContainer>
|
||||||
<CanvasEntityHeader>
|
<CanvasEntityHeader>
|
||||||
<CanvasEntityEnabledToggle />
|
<CanvasEntityEnabledToggle />
|
||||||
<CanvasEntityTitle />
|
<CanvasEntityEditableTitle />
|
||||||
<Spacer />
|
<Spacer />
|
||||||
<InpaintMaskMaskFillColorPicker />
|
<InpaintMaskMaskFillColorPicker />
|
||||||
</CanvasEntityHeader>
|
</CanvasEntityHeader>
|
||||||
</CanvasEntityContainer>
|
</CanvasEntityContainer>
|
||||||
</EntityIdentifierContext.Provider>
|
</EntityIdentifierContext.Provider>
|
||||||
</Flex>
|
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -0,0 +1,38 @@
|
|||||||
|
import { createMemoizedSelector } from 'app/store/createMemoizedSelector';
|
||||||
|
import { useAppSelector } from 'app/store/storeHooks';
|
||||||
|
import { CanvasEntityGroupList } from 'features/controlLayers/components/common/CanvasEntityGroupList';
|
||||||
|
import { InpaintMask } from 'features/controlLayers/components/InpaintMask/InpaintMask';
|
||||||
|
import { mapId } from 'features/controlLayers/konva/util';
|
||||||
|
import { selectCanvasV2Slice } from 'features/controlLayers/store/canvasV2Slice';
|
||||||
|
import { memo } from 'react';
|
||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
|
const selectEntityIds = createMemoizedSelector(selectCanvasV2Slice, (canvasV2) => {
|
||||||
|
return canvasV2.inpaintMasks.entities.map(mapId).reverse();
|
||||||
|
});
|
||||||
|
|
||||||
|
export const InpaintMaskList = memo(() => {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const isSelected = useAppSelector((s) => Boolean(s.canvasV2.selectedEntityIdentifier?.type === 'inpaint_mask'));
|
||||||
|
const entityIds = useAppSelector(selectEntityIds);
|
||||||
|
|
||||||
|
if (entityIds.length === 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (entityIds.length > 0) {
|
||||||
|
return (
|
||||||
|
<CanvasEntityGroupList
|
||||||
|
type="inpaint_mask"
|
||||||
|
title={t('controlLayers.inpaintMasks_withCount', { count: entityIds.length })}
|
||||||
|
isSelected={isSelected}
|
||||||
|
>
|
||||||
|
{entityIds.map((id) => (
|
||||||
|
<InpaintMask key={id} id={id} />
|
||||||
|
))}
|
||||||
|
</CanvasEntityGroupList>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
InpaintMaskList.displayName = 'InpaintMaskList';
|
@ -1,29 +1,33 @@
|
|||||||
import { Flex, Popover, PopoverBody, PopoverContent, PopoverTrigger } from '@invoke-ai/ui-library';
|
import { Flex, Popover, PopoverBody, PopoverContent, PopoverTrigger } from '@invoke-ai/ui-library';
|
||||||
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
|
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
|
||||||
import IAIColorPicker from 'common/components/IAIColorPicker';
|
import RgbColorPicker from 'common/components/RgbColorPicker';
|
||||||
import { rgbColorToString } from 'common/util/colorCodeTransformers';
|
import { rgbColorToString } from 'common/util/colorCodeTransformers';
|
||||||
import { stopPropagation } from 'common/util/stopPropagation';
|
import { stopPropagation } from 'common/util/stopPropagation';
|
||||||
import { MaskFillStyle } from 'features/controlLayers/components/common/MaskFillStyle';
|
import { MaskFillStyle } from 'features/controlLayers/components/common/MaskFillStyle';
|
||||||
import { imFillColorChanged, imFillStyleChanged } from 'features/controlLayers/store/canvasV2Slice';
|
import { useEntityIdentifierContext } from 'features/controlLayers/contexts/EntityIdentifierContext';
|
||||||
import type { FillStyle, RgbaColor } from 'features/controlLayers/store/types';
|
import { inpaintMaskFillColorChanged, inpaintMaskFillStyleChanged } from 'features/controlLayers/store/canvasV2Slice';
|
||||||
|
import { selectInpaintMaskEntityOrThrow } from 'features/controlLayers/store/inpaintMaskReducers';
|
||||||
|
import type { FillStyle, RgbColor } from 'features/controlLayers/store/types';
|
||||||
import { memo, useCallback } from 'react';
|
import { memo, useCallback } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
export const InpaintMaskMaskFillColorPicker = memo(() => {
|
export const InpaintMaskMaskFillColorPicker = memo(() => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
const fill = useAppSelector((s) => s.canvasV2.inpaintMask.fill);
|
const entityIdentifier = useEntityIdentifierContext();
|
||||||
|
const fill = useAppSelector((s) => selectInpaintMaskEntityOrThrow(s.canvasV2, entityIdentifier.id).fill);
|
||||||
|
|
||||||
const onChangeFillColor = useCallback(
|
const onChangeFillColor = useCallback(
|
||||||
(color: RgbaColor) => {
|
(color: RgbColor) => {
|
||||||
dispatch(imFillColorChanged({ color }));
|
dispatch(inpaintMaskFillColorChanged({ entityIdentifier, color }));
|
||||||
},
|
},
|
||||||
[dispatch]
|
[dispatch, entityIdentifier]
|
||||||
);
|
);
|
||||||
const onChangeFillStyle = useCallback(
|
const onChangeFillStyle = useCallback(
|
||||||
(style: FillStyle) => {
|
(style: FillStyle) => {
|
||||||
dispatch(imFillStyleChanged({ style }));
|
dispatch(inpaintMaskFillStyleChanged({ entityIdentifier, style }));
|
||||||
},
|
},
|
||||||
[dispatch]
|
[dispatch, entityIdentifier]
|
||||||
);
|
);
|
||||||
return (
|
return (
|
||||||
<Popover isLazy>
|
<Popover isLazy>
|
||||||
@ -43,7 +47,7 @@ export const InpaintMaskMaskFillColorPicker = memo(() => {
|
|||||||
<PopoverContent>
|
<PopoverContent>
|
||||||
<PopoverBody minH={64}>
|
<PopoverBody minH={64}>
|
||||||
<Flex flexDir="column" gap={4}>
|
<Flex flexDir="column" gap={4}>
|
||||||
<IAIColorPicker color={fill.color} onChange={onChangeFillColor} withNumberInput />
|
<RgbColorPicker color={fill.color} onChange={onChangeFillColor} withNumberInput />
|
||||||
<MaskFillStyle style={fill.style} onChange={onChangeFillStyle} />
|
<MaskFillStyle style={fill.style} onChange={onChangeFillStyle} />
|
||||||
</Flex>
|
</Flex>
|
||||||
</PopoverBody>
|
</PopoverBody>
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
import { Flex, Popover, PopoverBody, PopoverContent, PopoverTrigger } from '@invoke-ai/ui-library';
|
import { Flex, Popover, PopoverBody, PopoverContent, PopoverTrigger } from '@invoke-ai/ui-library';
|
||||||
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
|
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
|
||||||
import IAIColorPicker from 'common/components/IAIColorPicker';
|
import RgbColorPicker from 'common/components/RgbColorPicker';
|
||||||
import { rgbColorToString } from 'common/util/colorCodeTransformers';
|
import { rgbColorToString } from 'common/util/colorCodeTransformers';
|
||||||
import { stopPropagation } from 'common/util/stopPropagation';
|
import { stopPropagation } from 'common/util/stopPropagation';
|
||||||
import { MaskFillStyle } from 'features/controlLayers/components/common/MaskFillStyle';
|
import { MaskFillStyle } from 'features/controlLayers/components/common/MaskFillStyle';
|
||||||
import { useEntityIdentifierContext } from 'features/controlLayers/contexts/EntityIdentifierContext';
|
import { useEntityIdentifierContext } from 'features/controlLayers/contexts/EntityIdentifierContext';
|
||||||
import { rgFillColorChanged, rgFillStyleChanged } from 'features/controlLayers/store/canvasV2Slice';
|
import { rgFillColorChanged, rgFillStyleChanged } from 'features/controlLayers/store/canvasV2Slice';
|
||||||
import { selectRegionalGuidanceEntityOrThrow } from 'features/controlLayers/store/regionsReducers';
|
import { selectRegionalGuidanceEntityOrThrow } from 'features/controlLayers/store/regionsReducers';
|
||||||
import type { FillStyle, RgbaColor } from 'features/controlLayers/store/types';
|
import type { FillStyle, RgbColor } from 'features/controlLayers/store/types';
|
||||||
import { memo, useCallback } from 'react';
|
import { memo, useCallback } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
@ -17,7 +17,7 @@ export const RegionalGuidanceMaskFillColorPicker = memo(() => {
|
|||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
const fill = useAppSelector((s) => selectRegionalGuidanceEntityOrThrow(s.canvasV2, entityIdentifier.id).fill);
|
const fill = useAppSelector((s) => selectRegionalGuidanceEntityOrThrow(s.canvasV2, entityIdentifier.id).fill);
|
||||||
const onChangeFillColor = useCallback(
|
const onChangeFillColor = useCallback(
|
||||||
(color: RgbaColor) => {
|
(color: RgbColor) => {
|
||||||
dispatch(rgFillColorChanged({ id: entityIdentifier.id, color }));
|
dispatch(rgFillColorChanged({ id: entityIdentifier.id, color }));
|
||||||
},
|
},
|
||||||
[dispatch, entityIdentifier.id]
|
[dispatch, entityIdentifier.id]
|
||||||
@ -46,7 +46,7 @@ export const RegionalGuidanceMaskFillColorPicker = memo(() => {
|
|||||||
<PopoverContent>
|
<PopoverContent>
|
||||||
<PopoverBody minH={64}>
|
<PopoverBody minH={64}>
|
||||||
<Flex flexDir="column" gap={4}>
|
<Flex flexDir="column" gap={4}>
|
||||||
<IAIColorPicker color={fill.color} onChange={onChangeFillColor} withNumberInput />
|
<RgbColorPicker color={fill.color} onChange={onChangeFillColor} withNumberInput />
|
||||||
<MaskFillStyle style={fill.style} onChange={onChangeFillStyle} />
|
<MaskFillStyle style={fill.style} onChange={onChangeFillStyle} />
|
||||||
</Flex>
|
</Flex>
|
||||||
</PopoverBody>
|
</PopoverBody>
|
||||||
|
@ -48,7 +48,7 @@ export class CanvasManager {
|
|||||||
rasterLayerAdapters: Map<string, CanvasLayerAdapter> = new Map();
|
rasterLayerAdapters: Map<string, CanvasLayerAdapter> = new Map();
|
||||||
controlLayerAdapters: Map<string, CanvasLayerAdapter> = new Map();
|
controlLayerAdapters: Map<string, CanvasLayerAdapter> = new Map();
|
||||||
regionalGuidanceAdapters: Map<string, CanvasMaskAdapter> = new Map();
|
regionalGuidanceAdapters: Map<string, CanvasMaskAdapter> = new Map();
|
||||||
inpaintMaskAdapter: CanvasMaskAdapter;
|
inpaintMaskAdapters: Map<string, CanvasMaskAdapter> = new Map();
|
||||||
stateApi: CanvasStateApi;
|
stateApi: CanvasStateApi;
|
||||||
preview: CanvasPreview;
|
preview: CanvasPreview;
|
||||||
background: CanvasBackground;
|
background: CanvasBackground;
|
||||||
@ -120,9 +120,6 @@ export class CanvasManager {
|
|||||||
this.stateApi.$selectedEntityIdentifier.set(this.stateApi.getState().selectedEntityIdentifier);
|
this.stateApi.$selectedEntityIdentifier.set(this.stateApi.getState().selectedEntityIdentifier);
|
||||||
this.stateApi.$currentFill.set(this.stateApi.getCurrentFill());
|
this.stateApi.$currentFill.set(this.stateApi.getCurrentFill());
|
||||||
this.stateApi.$selectedEntity.set(this.stateApi.getSelectedEntity());
|
this.stateApi.$selectedEntity.set(this.stateApi.getSelectedEntity());
|
||||||
|
|
||||||
this.inpaintMaskAdapter = new CanvasMaskAdapter(this.stateApi.getInpaintMaskState(), this);
|
|
||||||
this.stage.add(this.inpaintMaskAdapter.konva.layer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
enableDebugging() {
|
enableDebugging() {
|
||||||
@ -149,19 +146,21 @@ export class CanvasManager {
|
|||||||
|
|
||||||
this.background.konva.layer.zIndex(++zIndex);
|
this.background.konva.layer.zIndex(++zIndex);
|
||||||
|
|
||||||
for (const layer of this.stateApi.getRasterLayersState().entities) {
|
for (const { id } of this.stateApi.getRasterLayersState().entities) {
|
||||||
this.rasterLayerAdapters.get(layer.id)?.konva.layer.zIndex(++zIndex);
|
this.rasterLayerAdapters.get(id)?.konva.layer.zIndex(++zIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const layer of this.stateApi.getControlLayersState().entities) {
|
for (const { id } of this.stateApi.getControlLayersState().entities) {
|
||||||
this.controlLayerAdapters.get(layer.id)?.konva.layer.zIndex(++zIndex);
|
this.controlLayerAdapters.get(id)?.konva.layer.zIndex(++zIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const rg of this.stateApi.getRegionsState().entities) {
|
for (const { id } of this.stateApi.getRegionsState().entities) {
|
||||||
this.regionalGuidanceAdapters.get(rg.id)?.konva.layer.zIndex(++zIndex);
|
this.regionalGuidanceAdapters.get(id)?.konva.layer.zIndex(++zIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.inpaintMaskAdapter.konva.layer.zIndex(++zIndex);
|
for (const { id } of this.stateApi.getInpaintMasksState().entities) {
|
||||||
|
this.inpaintMaskAdapters.get(id)?.konva.layer.zIndex(++zIndex);
|
||||||
|
}
|
||||||
|
|
||||||
this.preview.getLayer().zIndex(++zIndex);
|
this.preview.getLayer().zIndex(++zIndex);
|
||||||
}
|
}
|
||||||
@ -181,8 +180,10 @@ export class CanvasManager {
|
|||||||
getVisibleRect = (): Rect => {
|
getVisibleRect = (): Rect => {
|
||||||
const rects = [];
|
const rects = [];
|
||||||
|
|
||||||
if (this.inpaintMaskAdapter.state.isEnabled) {
|
for (const adapter of this.inpaintMaskAdapters.values()) {
|
||||||
rects.push(this.inpaintMaskAdapter.transformer.getRelativeRect());
|
if (adapter.state.isEnabled) {
|
||||||
|
rects.push(adapter.transformer.getRelativeRect());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const adapter of this.rasterLayerAdapters.values()) {
|
for (const adapter of this.rasterLayerAdapters.values()) {
|
||||||
@ -241,7 +242,7 @@ export class CanvasManager {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
getTransformingLayer() {
|
getTransformingLayer = (): CanvasLayerAdapter | CanvasMaskAdapter | null => {
|
||||||
const transformingEntity = this.stateApi.$transformingEntity.get();
|
const transformingEntity = this.stateApi.$transformingEntity.get();
|
||||||
if (!transformingEntity) {
|
if (!transformingEntity) {
|
||||||
return null;
|
return null;
|
||||||
@ -254,13 +255,13 @@ export class CanvasManager {
|
|||||||
} else if (type === 'control_layer') {
|
} else if (type === 'control_layer') {
|
||||||
return this.controlLayerAdapters.get(id) ?? null;
|
return this.controlLayerAdapters.get(id) ?? null;
|
||||||
} else if (type === 'inpaint_mask') {
|
} else if (type === 'inpaint_mask') {
|
||||||
return this.inpaintMaskAdapter;
|
return this.inpaintMaskAdapters.get(id) ?? null;
|
||||||
} else if (type === 'regional_guidance') {
|
} else if (type === 'regional_guidance') {
|
||||||
return this.regionalGuidanceAdapters.get(id) ?? null;
|
return this.regionalGuidanceAdapters.get(id) ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
};
|
||||||
|
|
||||||
getIsTransforming() {
|
getIsTransforming() {
|
||||||
return Boolean(this.stateApi.$transformingEntity.get());
|
return Boolean(this.stateApi.$transformingEntity.get());
|
||||||
@ -397,17 +398,34 @@ export class CanvasManager {
|
|||||||
|
|
||||||
if (
|
if (
|
||||||
isFirstRender ||
|
isFirstRender ||
|
||||||
state.inpaintMask !== prevState.inpaintMask ||
|
state.inpaintMasks.entities !== prevState.inpaintMasks.entities ||
|
||||||
state.tool.selected !== prevState.tool.selected ||
|
state.tool.selected !== prevState.tool.selected ||
|
||||||
state.selectedEntityIdentifier?.id !== prevState.selectedEntityIdentifier?.id
|
state.selectedEntityIdentifier?.id !== prevState.selectedEntityIdentifier?.id
|
||||||
) {
|
) {
|
||||||
this.log.debug('Rendering inpaint mask');
|
this.log.debug('Rendering inpaint masks');
|
||||||
await this.inpaintMaskAdapter.update({
|
|
||||||
state: state.inpaintMask,
|
// Destroy the konva nodes for nonexistent entities
|
||||||
|
for (const adapter of this.inpaintMaskAdapters.values()) {
|
||||||
|
if (!state.inpaintMasks.entities.find((rg) => rg.id === adapter.id)) {
|
||||||
|
adapter.destroy();
|
||||||
|
this.inpaintMaskAdapters.delete(adapter.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const entityState of state.inpaintMasks.entities) {
|
||||||
|
let adapter = this.inpaintMaskAdapters.get(entityState.id);
|
||||||
|
if (!adapter) {
|
||||||
|
adapter = new CanvasMaskAdapter(entityState, this);
|
||||||
|
this.inpaintMaskAdapters.set(adapter.id, adapter);
|
||||||
|
this.stage.add(adapter.konva.layer);
|
||||||
|
}
|
||||||
|
await adapter.update({
|
||||||
|
state: entityState,
|
||||||
toolState: state.tool,
|
toolState: state.tool,
|
||||||
isSelected: state.selectedEntityIdentifier?.id === state.inpaintMask.id,
|
isSelected: state.selectedEntityIdentifier?.id === entityState.id,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.stateApi.$toolState.set(state.tool);
|
this.stateApi.$toolState.set(state.tool);
|
||||||
this.stateApi.$selectedEntityIdentifier.set(state.selectedEntityIdentifier);
|
this.stateApi.$selectedEntityIdentifier.set(state.selectedEntityIdentifier);
|
||||||
@ -427,8 +445,9 @@ export class CanvasManager {
|
|||||||
if (
|
if (
|
||||||
isFirstRender ||
|
isFirstRender ||
|
||||||
state.rasterLayers.entities !== prevState.rasterLayers.entities ||
|
state.rasterLayers.entities !== prevState.rasterLayers.entities ||
|
||||||
|
state.controlLayers.entities !== prevState.controlLayers.entities ||
|
||||||
state.regions.entities !== prevState.regions.entities ||
|
state.regions.entities !== prevState.regions.entities ||
|
||||||
state.inpaintMask !== prevState.inpaintMask ||
|
state.inpaintMasks.entities !== prevState.inpaintMasks.entities ||
|
||||||
state.selectedEntityIdentifier?.id !== prevState.selectedEntityIdentifier?.id
|
state.selectedEntityIdentifier?.id !== prevState.selectedEntityIdentifier?.id
|
||||||
) {
|
) {
|
||||||
this.log.debug('Arranging entities');
|
this.log.debug('Arranging entities');
|
||||||
@ -454,14 +473,13 @@ export class CanvasManager {
|
|||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
this.log.debug('Cleaning up konva renderer');
|
this.log.debug('Cleaning up konva renderer');
|
||||||
this.inpaintMaskAdapter.destroy();
|
const allAdapters = [
|
||||||
for (const adapter of this.regionalGuidanceAdapters.values()) {
|
...this.rasterLayerAdapters.values(),
|
||||||
adapter.destroy();
|
...this.controlLayerAdapters.values(),
|
||||||
}
|
...this.inpaintMaskAdapters.values(),
|
||||||
for (const adapter of this.rasterLayerAdapters.values()) {
|
...this.regionalGuidanceAdapters.values(),
|
||||||
adapter.destroy();
|
];
|
||||||
}
|
for (const adapter of allAdapters) {
|
||||||
for (const adapter of this.controlLayerAdapters.values()) {
|
|
||||||
adapter.destroy();
|
adapter.destroy();
|
||||||
}
|
}
|
||||||
this.background.destroy();
|
this.background.destroy();
|
||||||
@ -558,7 +576,7 @@ export class CanvasManager {
|
|||||||
return pixels / this.getStageScale();
|
return pixels / this.getStageScale();
|
||||||
}
|
}
|
||||||
|
|
||||||
getCompositeLayerStageClone = (): Konva.Stage => {
|
getCompositeRasterLayerStageClone = (): Konva.Stage => {
|
||||||
const layersState = this.stateApi.getRasterLayersState();
|
const layersState = this.stateApi.getRasterLayersState();
|
||||||
const stageClone = this.stage.clone();
|
const stageClone = this.stage.clone();
|
||||||
|
|
||||||
@ -580,58 +598,95 @@ export class CanvasManager {
|
|||||||
return stageClone;
|
return stageClone;
|
||||||
};
|
};
|
||||||
|
|
||||||
getCompositeLayerBlob = (rect?: Rect): Promise<Blob> => {
|
getCompositeInpaintMaskStageClone = (): Konva.Stage => {
|
||||||
return konvaNodeToBlob(this.getCompositeLayerStageClone(), rect);
|
const entities = this.stateApi.getInpaintMasksState().entities;
|
||||||
|
const validEntities = entities.filter((entity) => entity.isEnabled && entity.objects.length > 0);
|
||||||
|
|
||||||
|
const stageClone = this.stage.clone();
|
||||||
|
|
||||||
|
stageClone.scaleX(1);
|
||||||
|
stageClone.scaleY(1);
|
||||||
|
stageClone.x(0);
|
||||||
|
stageClone.y(0);
|
||||||
|
|
||||||
|
// getLayers() returns the internal `children` array of the stage directly - calling destroy on a layer will
|
||||||
|
// mutate that array. We need to clone the array to avoid mutating the original.
|
||||||
|
for (const konvaLayer of stageClone.getLayers().slice()) {
|
||||||
|
if (!validEntities.find((l) => l.id === konvaLayer.id())) {
|
||||||
|
konvaLayer.destroy();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return stageClone;
|
||||||
};
|
};
|
||||||
|
|
||||||
getCompositeLayerImageData = (rect?: Rect): ImageData => {
|
getCompositeInpaintMaskImageCache = (rect: Rect): ImageCache | null => {
|
||||||
return konvaNodeToImageData(this.getCompositeLayerStageClone(), rect);
|
const { compositeRasterizationCache } = this.stateApi.getInpaintMasksState();
|
||||||
};
|
const imageCache = compositeRasterizationCache.find((cache) => isEqual(cache.rect, rect));
|
||||||
|
|
||||||
getCompositeRasterizedImageCache = (rect: Rect): ImageCache | null => {
|
|
||||||
const layerState = this.stateApi.getRasterLayersState();
|
|
||||||
const imageCache = layerState.compositeRasterizationCache.find((cache) => isEqual(cache.rect, rect));
|
|
||||||
return imageCache ?? null;
|
return imageCache ?? null;
|
||||||
};
|
};
|
||||||
|
|
||||||
getCompositeLayerImageDTO = async (rect: Rect): Promise<ImageDTO> => {
|
getCompositeRasterLayerImageCache = (rect: Rect): ImageCache | null => {
|
||||||
|
const { compositeRasterizationCache } = this.stateApi.getRasterLayersState();
|
||||||
|
const imageCache = compositeRasterizationCache.find((cache) => isEqual(cache.rect, rect));
|
||||||
|
return imageCache ?? null;
|
||||||
|
};
|
||||||
|
|
||||||
|
getCompositeRasterLayerImageDTO = async (rect: Rect): Promise<ImageDTO> => {
|
||||||
let imageDTO: ImageDTO | null = null;
|
let imageDTO: ImageDTO | null = null;
|
||||||
const compositeRasterizedImageCache = this.getCompositeRasterizedImageCache(rect);
|
const compositeRasterizedImageCache = this.getCompositeRasterLayerImageCache(rect);
|
||||||
|
|
||||||
if (compositeRasterizedImageCache) {
|
if (compositeRasterizedImageCache) {
|
||||||
imageDTO = await getImageDTO(compositeRasterizedImageCache.imageName);
|
imageDTO = await getImageDTO(compositeRasterizedImageCache.imageName);
|
||||||
if (imageDTO) {
|
if (imageDTO) {
|
||||||
this.log.trace({ rect, compositeRasterizedImageCache, imageDTO }, 'Using cached composite rasterized image');
|
this.log.trace({ rect, compositeRasterizedImageCache, imageDTO }, 'Using cached composite raster layer image');
|
||||||
return imageDTO;
|
return imageDTO;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.log.trace({ rect }, 'Rasterizing composite layer');
|
this.log.trace({ rect }, 'Rasterizing composite raster layer');
|
||||||
|
|
||||||
const blob = await this.getCompositeLayerBlob(rect);
|
const blob = await konvaNodeToBlob(this.getCompositeRasterLayerStageClone(), rect);
|
||||||
|
|
||||||
if (this._isDebugging) {
|
if (this._isDebugging) {
|
||||||
previewBlob(blob, 'Rasterized entity');
|
previewBlob(blob, 'Composite raster layer');
|
||||||
}
|
}
|
||||||
|
|
||||||
imageDTO = await uploadImage(blob, 'composite-layer.png', 'general', true);
|
imageDTO = await uploadImage(blob, 'composite-raster-layer.png', 'general', true);
|
||||||
this.stateApi.compositeLayerRasterized({ imageName: imageDTO.image_name, rect });
|
this.stateApi.compositeRasterLayerRasterized({ imageName: imageDTO.image_name, rect });
|
||||||
return imageDTO;
|
return imageDTO;
|
||||||
};
|
};
|
||||||
|
|
||||||
getInpaintMaskBlob = (rect?: Rect): Promise<Blob> => {
|
getCompositeInpaintMaskImageDTO = async (rect: Rect): Promise<ImageDTO> => {
|
||||||
return this.inpaintMaskAdapter.renderer.getBlob(rect);
|
let imageDTO: ImageDTO | null = null;
|
||||||
};
|
const compositeRasterizedImageCache = this.getCompositeInpaintMaskImageCache(rect);
|
||||||
|
|
||||||
getInpaintMaskImageData = (rect?: Rect): ImageData => {
|
if (compositeRasterizedImageCache) {
|
||||||
return this.inpaintMaskAdapter.renderer.getImageData(rect);
|
imageDTO = await getImageDTO(compositeRasterizedImageCache.imageName);
|
||||||
|
if (imageDTO) {
|
||||||
|
this.log.trace({ rect, compositeRasterizedImageCache, imageDTO }, 'Using cached composite inpaint mask image');
|
||||||
|
return imageDTO;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.log.trace({ rect }, 'Rasterizing composite inpaint mask');
|
||||||
|
|
||||||
|
const blob = await konvaNodeToBlob(this.getCompositeInpaintMaskStageClone(), rect);
|
||||||
|
|
||||||
|
if (this._isDebugging) {
|
||||||
|
previewBlob(blob, 'Composite inpaint mask');
|
||||||
|
}
|
||||||
|
|
||||||
|
imageDTO = await uploadImage(blob, 'composite-inpaint-mask.png', 'general', true);
|
||||||
|
this.stateApi.compositeInpaintMaskRasterized({ imageName: imageDTO.image_name, rect });
|
||||||
|
return imageDTO;
|
||||||
};
|
};
|
||||||
|
|
||||||
getGenerationMode(): GenerationMode {
|
getGenerationMode(): GenerationMode {
|
||||||
const { rect } = this.stateApi.getBbox();
|
const { rect } = this.stateApi.getBbox();
|
||||||
const inpaintMaskImageData = this.getInpaintMaskImageData(rect);
|
const inpaintMaskImageData = konvaNodeToImageData(this.getCompositeInpaintMaskStageClone(), rect);
|
||||||
const inpaintMaskTransparency = getImageDataTransparency(inpaintMaskImageData);
|
const inpaintMaskTransparency = getImageDataTransparency(inpaintMaskImageData);
|
||||||
const compositeLayerImageData = this.getCompositeLayerImageData(rect);
|
const compositeLayerImageData = konvaNodeToImageData(this.getCompositeRasterLayerStageClone(), rect);
|
||||||
const compositeLayerTransparency = getImageDataTransparency(compositeLayerImageData);
|
const compositeLayerTransparency = getImageDataTransparency(compositeLayerImageData);
|
||||||
if (compositeLayerTransparency === 'FULLY_TRANSPARENT') {
|
if (compositeLayerTransparency === 'FULLY_TRANSPARENT') {
|
||||||
// When the initial image is fully transparent, we are always doing txt2img
|
// When the initial image is fully transparent, we are always doing txt2img
|
||||||
|
@ -27,6 +27,7 @@ import {
|
|||||||
entitySelected,
|
entitySelected,
|
||||||
eraserWidthChanged,
|
eraserWidthChanged,
|
||||||
fillChanged,
|
fillChanged,
|
||||||
|
inpaintMaskCompositeRasterized,
|
||||||
rasterLayerCompositeRasterized,
|
rasterLayerCompositeRasterized,
|
||||||
toolBufferChanged,
|
toolBufferChanged,
|
||||||
toolChanged,
|
toolChanged,
|
||||||
@ -110,9 +111,12 @@ export class CanvasStateApi {
|
|||||||
rasterizeEntity = (arg: EntityRasterizedPayload) => {
|
rasterizeEntity = (arg: EntityRasterizedPayload) => {
|
||||||
this._store.dispatch(entityRasterized(arg));
|
this._store.dispatch(entityRasterized(arg));
|
||||||
};
|
};
|
||||||
compositeLayerRasterized = (arg: { imageName: string; rect: Rect }) => {
|
compositeRasterLayerRasterized = (arg: { imageName: string; rect: Rect }) => {
|
||||||
this._store.dispatch(rasterLayerCompositeRasterized(arg));
|
this._store.dispatch(rasterLayerCompositeRasterized(arg));
|
||||||
};
|
};
|
||||||
|
compositeInpaintMaskRasterized = (arg: { imageName: string; rect: Rect }) => {
|
||||||
|
this._store.dispatch(inpaintMaskCompositeRasterized(arg));
|
||||||
|
};
|
||||||
setSelectedEntity = (arg: EntityIdentifierPayload) => {
|
setSelectedEntity = (arg: EntityIdentifierPayload) => {
|
||||||
this._store.dispatch(entitySelected(arg));
|
this._store.dispatch(entitySelected(arg));
|
||||||
};
|
};
|
||||||
@ -154,8 +158,8 @@ export class CanvasStateApi {
|
|||||||
getControlLayersState = () => {
|
getControlLayersState = () => {
|
||||||
return this.getState().controlLayers;
|
return this.getState().controlLayers;
|
||||||
};
|
};
|
||||||
getInpaintMaskState = () => {
|
getInpaintMasksState = () => {
|
||||||
return this.getState().inpaintMask;
|
return this.getState().inpaintMasks;
|
||||||
};
|
};
|
||||||
getSession = () => {
|
getSession = () => {
|
||||||
return this.getState().session;
|
return this.getState().session;
|
||||||
@ -183,8 +187,8 @@ export class CanvasStateApi {
|
|||||||
entityState = state.regions.entities.find((i) => i.id === identifier.id) ?? null;
|
entityState = state.regions.entities.find((i) => i.id === identifier.id) ?? null;
|
||||||
entityAdapter = this.manager.regionalGuidanceAdapters.get(identifier.id) ?? null;
|
entityAdapter = this.manager.regionalGuidanceAdapters.get(identifier.id) ?? null;
|
||||||
} else if (identifier.type === 'inpaint_mask') {
|
} else if (identifier.type === 'inpaint_mask') {
|
||||||
entityState = state.inpaintMask;
|
entityState = state.inpaintMasks.entities.find((i) => i.id === identifier.id) ?? null;
|
||||||
entityAdapter = this.manager.inpaintMaskAdapter;
|
entityAdapter = this.manager.inpaintMaskAdapters.get(identifier.id) ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (entityState && entityAdapter) {
|
if (entityState && entityAdapter) {
|
||||||
|
@ -41,32 +41,17 @@ import type {
|
|||||||
FilterConfig,
|
FilterConfig,
|
||||||
StageAttrs,
|
StageAttrs,
|
||||||
} from './types';
|
} from './types';
|
||||||
import { IMAGE_FILTERS, isDrawableEntity } from './types';
|
import { getEntityIdentifier, IMAGE_FILTERS, isDrawableEntity } from './types';
|
||||||
|
|
||||||
const initialState: CanvasV2State = {
|
const initialState: CanvasV2State = {
|
||||||
_version: 3,
|
_version: 3,
|
||||||
selectedEntityIdentifier: { id: 'inpaint_mask', type: 'inpaint_mask' },
|
selectedEntityIdentifier: null,
|
||||||
rasterLayers: { entities: [], compositeRasterizationCache: [] },
|
rasterLayers: { entities: [], compositeRasterizationCache: [] },
|
||||||
controlLayers: { entities: [] },
|
controlLayers: { entities: [] },
|
||||||
ipAdapters: { entities: [] },
|
ipAdapters: { entities: [] },
|
||||||
regions: { entities: [] },
|
regions: { entities: [] },
|
||||||
loras: [],
|
loras: [],
|
||||||
inpaintMask: {
|
inpaintMasks: { entities: [], compositeRasterizationCache: [] },
|
||||||
id: 'inpaint_mask',
|
|
||||||
type: 'inpaint_mask',
|
|
||||||
fill: {
|
|
||||||
style: 'diagonal',
|
|
||||||
color: { r: 255, g: 122, b: 0 }, // some orange color
|
|
||||||
},
|
|
||||||
rasterizationCache: [],
|
|
||||||
isEnabled: true,
|
|
||||||
objects: [],
|
|
||||||
opacity: 1,
|
|
||||||
position: {
|
|
||||||
x: 0,
|
|
||||||
y: 0,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
tool: {
|
tool: {
|
||||||
selected: 'view',
|
selected: 'view',
|
||||||
selectedBuffer: null,
|
selectedBuffer: null,
|
||||||
@ -148,15 +133,15 @@ const initialState: CanvasV2State = {
|
|||||||
export function selectEntity(state: CanvasV2State, { id, type }: CanvasEntityIdentifier) {
|
export function selectEntity(state: CanvasV2State, { id, type }: CanvasEntityIdentifier) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'raster_layer':
|
case 'raster_layer':
|
||||||
return state.rasterLayers.entities.find((layer) => layer.id === id);
|
return state.rasterLayers.entities.find((entity) => entity.id === id);
|
||||||
case 'control_layer':
|
case 'control_layer':
|
||||||
return state.controlLayers.entities.find((layer) => layer.id === id);
|
return state.controlLayers.entities.find((entity) => entity.id === id);
|
||||||
case 'inpaint_mask':
|
case 'inpaint_mask':
|
||||||
return state.inpaintMask;
|
return state.inpaintMasks.entities.find((entity) => entity.id === id);
|
||||||
case 'regional_guidance':
|
case 'regional_guidance':
|
||||||
return state.regions.entities.find((rg) => rg.id === id);
|
return state.regions.entities.find((entity) => entity.id === id);
|
||||||
case 'ip_adapter':
|
case 'ip_adapter':
|
||||||
return state.ipAdapters.entities.find((ipa) => ipa.id === id);
|
return state.ipAdapters.entities.find((entity) => entity.id === id);
|
||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -168,7 +153,7 @@ export function selectAllEntitiesOfType(state: CanvasV2State, type: CanvasEntity
|
|||||||
} else if (type === 'control_layer') {
|
} else if (type === 'control_layer') {
|
||||||
return state.controlLayers.entities;
|
return state.controlLayers.entities;
|
||||||
} else if (type === 'inpaint_mask') {
|
} else if (type === 'inpaint_mask') {
|
||||||
return [state.inpaintMask];
|
return state.inpaintMasks.entities;
|
||||||
} else if (type === 'regional_guidance') {
|
} else if (type === 'regional_guidance') {
|
||||||
return state.regions.entities;
|
return state.regions.entities;
|
||||||
} else if (type === 'ip_adapter') {
|
} else if (type === 'ip_adapter') {
|
||||||
@ -194,6 +179,8 @@ const invalidateRasterizationCaches = (
|
|||||||
// its cache.
|
// its cache.
|
||||||
if (entity.type === 'raster_layer') {
|
if (entity.type === 'raster_layer') {
|
||||||
state.rasterLayers.compositeRasterizationCache = [];
|
state.rasterLayers.compositeRasterizationCache = [];
|
||||||
|
} else if (entity.type === 'inpaint_mask') {
|
||||||
|
state.inpaintMasks.compositeRasterizationCache = [];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -223,10 +210,6 @@ export const canvasV2Slice = createSlice({
|
|||||||
if (!entity) {
|
if (!entity) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (entity.type === 'inpaint_mask') {
|
|
||||||
// Inpaint mask cannot be renamed
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
entity.name = name;
|
entity.name = name;
|
||||||
},
|
},
|
||||||
entityReset: (state, action: PayloadAction<EntityIdentifierPayload>) => {
|
entityReset: (state, action: PayloadAction<EntityIdentifierPayload>) => {
|
||||||
@ -331,7 +314,11 @@ export const canvasV2Slice = createSlice({
|
|||||||
entityDeleted: (state, action: PayloadAction<EntityIdentifierPayload>) => {
|
entityDeleted: (state, action: PayloadAction<EntityIdentifierPayload>) => {
|
||||||
const { entityIdentifier } = action.payload;
|
const { entityIdentifier } = action.payload;
|
||||||
|
|
||||||
let selectedEntityIdentifier: CanvasEntityIdentifier = { type: state.inpaintMask.type, id: state.inpaintMask.id };
|
const firstInpaintMaskEntity = state.inpaintMasks.entities[0];
|
||||||
|
|
||||||
|
let selectedEntityIdentifier: CanvasV2State['selectedEntityIdentifier'] = firstInpaintMaskEntity
|
||||||
|
? getEntityIdentifier(firstInpaintMaskEntity)
|
||||||
|
: null;
|
||||||
|
|
||||||
if (entityIdentifier.type === 'raster_layer') {
|
if (entityIdentifier.type === 'raster_layer') {
|
||||||
const index = state.rasterLayers.entities.findIndex((layer) => layer.id === entityIdentifier.id);
|
const index = state.rasterLayers.entities.findIndex((layer) => layer.id === entityIdentifier.id);
|
||||||
@ -363,6 +350,15 @@ export const canvasV2Slice = createSlice({
|
|||||||
if (entity) {
|
if (entity) {
|
||||||
selectedEntityIdentifier = { type: entity.type, id: entity.id };
|
selectedEntityIdentifier = { type: entity.type, id: entity.id };
|
||||||
}
|
}
|
||||||
|
} else if (entityIdentifier.type === 'inpaint_mask') {
|
||||||
|
const index = state.inpaintMasks.entities.findIndex((layer) => layer.id === entityIdentifier.id);
|
||||||
|
state.inpaintMasks.entities = state.inpaintMasks.entities.filter((rg) => rg.id !== entityIdentifier.id);
|
||||||
|
// When deleting a inpaint mask, we need to invalidate the composite rasterization cache.
|
||||||
|
state.inpaintMasks.compositeRasterizationCache = [];
|
||||||
|
const entity = state.inpaintMasks.entities[index];
|
||||||
|
if (entity) {
|
||||||
|
selectedEntityIdentifier = { type: entity.type, id: entity.id };
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
assert(false, 'Not implemented');
|
assert(false, 'Not implemented');
|
||||||
}
|
}
|
||||||
@ -383,6 +379,10 @@ export const canvasV2Slice = createSlice({
|
|||||||
moveOneToEnd(state.controlLayers.entities, entity);
|
moveOneToEnd(state.controlLayers.entities, entity);
|
||||||
} else if (entity.type === 'regional_guidance') {
|
} else if (entity.type === 'regional_guidance') {
|
||||||
moveOneToEnd(state.regions.entities, entity);
|
moveOneToEnd(state.regions.entities, entity);
|
||||||
|
} else if (entity.type === 'inpaint_mask') {
|
||||||
|
moveOneToEnd(state.inpaintMasks.entities, entity);
|
||||||
|
// When arranging a inpaint mask, we need to invalidate the composite rasterization cache.
|
||||||
|
state.inpaintMasks.compositeRasterizationCache = [];
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
entityArrangedToFront: (state, action: PayloadAction<EntityIdentifierPayload>) => {
|
entityArrangedToFront: (state, action: PayloadAction<EntityIdentifierPayload>) => {
|
||||||
@ -399,6 +399,10 @@ export const canvasV2Slice = createSlice({
|
|||||||
moveToEnd(state.controlLayers.entities, entity);
|
moveToEnd(state.controlLayers.entities, entity);
|
||||||
} else if (entity.type === 'regional_guidance') {
|
} else if (entity.type === 'regional_guidance') {
|
||||||
moveToEnd(state.regions.entities, entity);
|
moveToEnd(state.regions.entities, entity);
|
||||||
|
} else if (entity.type === 'inpaint_mask') {
|
||||||
|
moveToEnd(state.inpaintMasks.entities, entity);
|
||||||
|
// When arranging a inpaint mask, we need to invalidate the composite rasterization cache.
|
||||||
|
state.inpaintMasks.compositeRasterizationCache = [];
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
entityArrangedBackwardOne: (state, action: PayloadAction<EntityIdentifierPayload>) => {
|
entityArrangedBackwardOne: (state, action: PayloadAction<EntityIdentifierPayload>) => {
|
||||||
@ -415,6 +419,10 @@ export const canvasV2Slice = createSlice({
|
|||||||
moveOneToStart(state.controlLayers.entities, entity);
|
moveOneToStart(state.controlLayers.entities, entity);
|
||||||
} else if (entity.type === 'regional_guidance') {
|
} else if (entity.type === 'regional_guidance') {
|
||||||
moveOneToStart(state.regions.entities, entity);
|
moveOneToStart(state.regions.entities, entity);
|
||||||
|
} else if (entity.type === 'inpaint_mask') {
|
||||||
|
moveOneToStart(state.inpaintMasks.entities, entity);
|
||||||
|
// When arranging a inpaint mask, we need to invalidate the composite rasterization cache.
|
||||||
|
state.inpaintMasks.compositeRasterizationCache = [];
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
entityArrangedToBack: (state, action: PayloadAction<EntityIdentifierPayload>) => {
|
entityArrangedToBack: (state, action: PayloadAction<EntityIdentifierPayload>) => {
|
||||||
@ -424,13 +432,17 @@ export const canvasV2Slice = createSlice({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (entity.type === 'raster_layer') {
|
if (entity.type === 'raster_layer') {
|
||||||
// When arranging a raster layer, we need to invalidate the composite rasterization cache.
|
|
||||||
moveToStart(state.rasterLayers.entities, entity);
|
moveToStart(state.rasterLayers.entities, entity);
|
||||||
|
// When arranging a raster layer, we need to invalidate the composite rasterization cache.
|
||||||
state.rasterLayers.compositeRasterizationCache = [];
|
state.rasterLayers.compositeRasterizationCache = [];
|
||||||
} else if (entity.type === 'control_layer') {
|
} else if (entity.type === 'control_layer') {
|
||||||
moveToStart(state.controlLayers.entities, entity);
|
moveToStart(state.controlLayers.entities, entity);
|
||||||
} else if (entity.type === 'regional_guidance') {
|
} else if (entity.type === 'regional_guidance') {
|
||||||
moveToStart(state.regions.entities, entity);
|
moveToStart(state.regions.entities, entity);
|
||||||
|
} else if (entity.type === 'inpaint_mask') {
|
||||||
|
moveToStart(state.inpaintMasks.entities, entity);
|
||||||
|
// When arranging a inpaint mask, we need to invalidate the composite rasterization cache.
|
||||||
|
state.inpaintMasks.compositeRasterizationCache = [];
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
entityOpacityChanged: (state, action: PayloadAction<EntityIdentifierPayload<{ opacity: number }>>) => {
|
entityOpacityChanged: (state, action: PayloadAction<EntityIdentifierPayload<{ opacity: number }>>) => {
|
||||||
@ -462,7 +474,7 @@ export const canvasV2Slice = createSlice({
|
|||||||
entities = state.controlLayers.entities;
|
entities = state.controlLayers.entities;
|
||||||
break;
|
break;
|
||||||
case 'inpaint_mask':
|
case 'inpaint_mask':
|
||||||
entities = [state.inpaintMask];
|
entities = state.inpaintMasks.entities;
|
||||||
break;
|
break;
|
||||||
case 'regional_guidance':
|
case 'regional_guidance':
|
||||||
entities = state.regions.entities;
|
entities = state.regions.entities;
|
||||||
@ -479,28 +491,28 @@ export const canvasV2Slice = createSlice({
|
|||||||
allEntitiesDeleted: (state) => {
|
allEntitiesDeleted: (state) => {
|
||||||
state.ipAdapters = deepClone(initialState.ipAdapters);
|
state.ipAdapters = deepClone(initialState.ipAdapters);
|
||||||
state.rasterLayers = deepClone(initialState.rasterLayers);
|
state.rasterLayers = deepClone(initialState.rasterLayers);
|
||||||
state.rasterLayers.compositeRasterizationCache = [];
|
|
||||||
state.controlLayers = deepClone(initialState.controlLayers);
|
state.controlLayers = deepClone(initialState.controlLayers);
|
||||||
state.regions = deepClone(initialState.regions);
|
state.regions = deepClone(initialState.regions);
|
||||||
state.inpaintMask = deepClone(initialState.inpaintMask);
|
state.inpaintMasks = deepClone(initialState.inpaintMasks);
|
||||||
|
|
||||||
state.selectedEntityIdentifier = deepClone(initialState.selectedEntityIdentifier);
|
state.selectedEntityIdentifier = deepClone(initialState.selectedEntityIdentifier);
|
||||||
},
|
},
|
||||||
rasterizationCachesInvalidated: (state) => {
|
rasterizationCachesInvalidated: (state) => {
|
||||||
// Invalidate the rasterization caches for all entities.
|
// Invalidate the rasterization caches for all entities.
|
||||||
|
const allEntities = [
|
||||||
|
...state.rasterLayers.entities,
|
||||||
|
...state.controlLayers.entities,
|
||||||
|
...state.regions.entities,
|
||||||
|
...state.inpaintMasks.entities,
|
||||||
|
];
|
||||||
|
|
||||||
// Layers & composite layer
|
for (const entity of allEntities) {
|
||||||
|
entity.rasterizationCache = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Also invalidate the composite rasterization caches.
|
||||||
state.rasterLayers.compositeRasterizationCache = [];
|
state.rasterLayers.compositeRasterizationCache = [];
|
||||||
for (const layer of state.rasterLayers.entities) {
|
state.inpaintMasks.compositeRasterizationCache = [];
|
||||||
layer.rasterizationCache = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Regions
|
|
||||||
for (const region of state.regions.entities) {
|
|
||||||
region.rasterizationCache = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Inpaint mask
|
|
||||||
state.inpaintMask.rasterizationCache = [];
|
|
||||||
},
|
},
|
||||||
canvasReset: (state) => {
|
canvasReset: (state) => {
|
||||||
state.bbox = deepClone(initialState.bbox);
|
state.bbox = deepClone(initialState.bbox);
|
||||||
@ -509,16 +521,16 @@ export const canvasV2Slice = createSlice({
|
|||||||
state.bbox.rect.height = optimalDimension;
|
state.bbox.rect.height = optimalDimension;
|
||||||
const size = pick(state.bbox.rect, 'width', 'height');
|
const size = pick(state.bbox.rect, 'width', 'height');
|
||||||
state.bbox.scaledSize = getScaledBoundingBoxDimensions(size, optimalDimension);
|
state.bbox.scaledSize = getScaledBoundingBoxDimensions(size, optimalDimension);
|
||||||
|
state.session = deepClone(initialState.session);
|
||||||
|
state.tool = deepClone(initialState.tool);
|
||||||
|
|
||||||
state.ipAdapters = deepClone(initialState.ipAdapters);
|
state.ipAdapters = deepClone(initialState.ipAdapters);
|
||||||
state.rasterLayers = deepClone(initialState.rasterLayers);
|
state.rasterLayers = deepClone(initialState.rasterLayers);
|
||||||
state.rasterLayers.compositeRasterizationCache = [];
|
|
||||||
state.controlLayers = deepClone(initialState.controlLayers);
|
state.controlLayers = deepClone(initialState.controlLayers);
|
||||||
state.regions = deepClone(initialState.regions);
|
state.regions = deepClone(initialState.regions);
|
||||||
|
state.inpaintMasks = deepClone(initialState.inpaintMasks);
|
||||||
|
|
||||||
state.selectedEntityIdentifier = deepClone(initialState.selectedEntityIdentifier);
|
state.selectedEntityIdentifier = deepClone(initialState.selectedEntityIdentifier);
|
||||||
state.session = deepClone(initialState.session);
|
|
||||||
state.tool = deepClone(initialState.tool);
|
|
||||||
state.inpaintMask = deepClone(initialState.inpaintMask);
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@ -652,9 +664,11 @@ export const {
|
|||||||
loraIsEnabledChanged,
|
loraIsEnabledChanged,
|
||||||
loraAllDeleted,
|
loraAllDeleted,
|
||||||
// Inpaint mask
|
// Inpaint mask
|
||||||
imRecalled,
|
inpaintMaskAdded,
|
||||||
imFillColorChanged,
|
inpaintMaskRecalled,
|
||||||
imFillStyleChanged,
|
inpaintMaskFillColorChanged,
|
||||||
|
inpaintMaskFillStyleChanged,
|
||||||
|
inpaintMaskCompositeRasterized,
|
||||||
// Staging
|
// Staging
|
||||||
sessionStartedStaging,
|
sessionStartedStaging,
|
||||||
sessionImageStaged,
|
sessionImageStaged,
|
||||||
|
@ -1,18 +1,80 @@
|
|||||||
import type { PayloadAction, SliceCaseReducers } from '@reduxjs/toolkit';
|
import type { PayloadAction, SliceCaseReducers } from '@reduxjs/toolkit';
|
||||||
import type { CanvasInpaintMaskState, CanvasV2State, FillStyle, RgbaColor } from 'features/controlLayers/store/types';
|
import { getPrefixedId } from 'features/controlLayers/konva/util';
|
||||||
|
import type {
|
||||||
|
CanvasInpaintMaskState,
|
||||||
|
CanvasV2State,
|
||||||
|
EntityIdentifierPayload,
|
||||||
|
FillStyle,
|
||||||
|
Rect,
|
||||||
|
RgbColor,
|
||||||
|
} from 'features/controlLayers/store/types';
|
||||||
|
import { isEqual, merge } from 'lodash-es';
|
||||||
|
import { assert } from 'tsafe';
|
||||||
|
|
||||||
|
export const selectInpaintMaskEntity = (state: CanvasV2State, id: string) =>
|
||||||
|
state.inpaintMasks.entities.find((layer) => layer.id === id);
|
||||||
|
export const selectInpaintMaskEntityOrThrow = (state: CanvasV2State, id: string) => {
|
||||||
|
const entity = selectInpaintMaskEntity(state, id);
|
||||||
|
assert(entity, `Inpaint mask with id ${id} not found`);
|
||||||
|
return entity;
|
||||||
|
};
|
||||||
|
|
||||||
export const inpaintMaskReducers = {
|
export const inpaintMaskReducers = {
|
||||||
imRecalled: (state, action: PayloadAction<{ data: CanvasInpaintMaskState }>) => {
|
inpaintMaskAdded: {
|
||||||
|
reducer: (
|
||||||
|
state,
|
||||||
|
action: PayloadAction<{ id: string; overrides?: Partial<CanvasInpaintMaskState>; isSelected?: boolean }>
|
||||||
|
) => {
|
||||||
|
const { id, overrides, isSelected } = action.payload;
|
||||||
|
const entity: CanvasInpaintMaskState = {
|
||||||
|
id,
|
||||||
|
name: null,
|
||||||
|
type: 'inpaint_mask',
|
||||||
|
isEnabled: true,
|
||||||
|
objects: [],
|
||||||
|
opacity: 1,
|
||||||
|
position: { x: 0, y: 0 },
|
||||||
|
rasterizationCache: [],
|
||||||
|
fill: {
|
||||||
|
style: 'diagonal',
|
||||||
|
color: { r: 255, g: 122, b: 0 }, // some orange color
|
||||||
|
},
|
||||||
|
};
|
||||||
|
merge(entity, overrides);
|
||||||
|
state.inpaintMasks.entities.push(entity);
|
||||||
|
if (isSelected) {
|
||||||
|
state.selectedEntityIdentifier = { type: 'inpaint_mask', id };
|
||||||
|
}
|
||||||
|
},
|
||||||
|
prepare: (payload?: { overrides?: Partial<CanvasInpaintMaskState>; isSelected?: boolean }) => ({
|
||||||
|
payload: { ...payload, id: getPrefixedId('inpaint_mask') },
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
inpaintMaskRecalled: (state, action: PayloadAction<{ data: CanvasInpaintMaskState }>) => {
|
||||||
const { data } = action.payload;
|
const { data } = action.payload;
|
||||||
state.inpaintMask = data;
|
state.inpaintMasks.entities = [data];
|
||||||
state.selectedEntityIdentifier = { type: 'inpaint_mask', id: data.id };
|
state.selectedEntityIdentifier = { type: 'inpaint_mask', id: data.id };
|
||||||
},
|
},
|
||||||
imFillColorChanged: (state, action: PayloadAction<{ color: RgbaColor }>) => {
|
inpaintMaskFillColorChanged: (state, action: PayloadAction<EntityIdentifierPayload<{ color: RgbColor }>>) => {
|
||||||
const { color } = action.payload;
|
const { color, entityIdentifier } = action.payload;
|
||||||
state.inpaintMask.fill.color = color;
|
const entity = selectInpaintMaskEntity(state, entityIdentifier.id);
|
||||||
|
if (!entity) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
entity.fill.color = color;
|
||||||
},
|
},
|
||||||
imFillStyleChanged: (state, action: PayloadAction<{ style: FillStyle }>) => {
|
inpaintMaskFillStyleChanged: (state, action: PayloadAction<EntityIdentifierPayload<{ style: FillStyle }>>) => {
|
||||||
const { style } = action.payload;
|
const { style, entityIdentifier } = action.payload;
|
||||||
state.inpaintMask.fill.style = style;
|
const entity = selectInpaintMaskEntity(state, entityIdentifier.id);
|
||||||
|
if (!entity) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
entity.fill.style = style;
|
||||||
|
},
|
||||||
|
inpaintMaskCompositeRasterized: (state, action: PayloadAction<{ imageName: string; rect: Rect }>) => {
|
||||||
|
state.inpaintMasks.compositeRasterizationCache = state.inpaintMasks.compositeRasterizationCache.filter(
|
||||||
|
(cache) => !isEqual(cache.rect, action.payload.rect)
|
||||||
|
);
|
||||||
|
state.inpaintMasks.compositeRasterizationCache.push(action.payload);
|
||||||
},
|
},
|
||||||
} satisfies SliceCaseReducers<CanvasV2State>;
|
} satisfies SliceCaseReducers<CanvasV2State>;
|
||||||
|
@ -6,7 +6,7 @@ import type {
|
|||||||
FillStyle,
|
FillStyle,
|
||||||
IPMethodV2,
|
IPMethodV2,
|
||||||
RegionalGuidanceIPAdapterConfig,
|
RegionalGuidanceIPAdapterConfig,
|
||||||
RgbaColor,
|
RgbColor,
|
||||||
} from 'features/controlLayers/store/types';
|
} from 'features/controlLayers/store/types';
|
||||||
import { imageDTOToImageWithDims } from 'features/controlLayers/store/types';
|
import { imageDTOToImageWithDims } from 'features/controlLayers/store/types';
|
||||||
import { zModelIdentifierField } from 'features/nodes/types/common';
|
import { zModelIdentifierField } from 'features/nodes/types/common';
|
||||||
@ -33,17 +33,17 @@ export const selectRegionalGuidanceEntityOrThrow = (state: CanvasV2State, id: st
|
|||||||
return rg;
|
return rg;
|
||||||
};
|
};
|
||||||
|
|
||||||
const DEFAULT_MASK_COLORS: RgbaColor[] = [
|
const DEFAULT_MASK_COLORS: RgbColor[] = [
|
||||||
{ r: 121, g: 157, b: 219, a: 0.5 }, // rgb(121, 157, 219)
|
{ r: 121, g: 157, b: 219 }, // rgb(121, 157, 219)
|
||||||
{ r: 131, g: 214, b: 131, a: 0.5 }, // rgb(131, 214, 131)
|
{ r: 131, g: 214, b: 131 }, // rgb(131, 214, 131)
|
||||||
{ r: 250, g: 225, b: 80, a: 0.5 }, // rgb(250, 225, 80)
|
{ r: 250, g: 225, b: 80 }, // rgb(250, 225, 80)
|
||||||
{ r: 220, g: 144, b: 101, a: 0.5 }, // rgb(220, 144, 101)
|
{ r: 220, g: 144, b: 101 }, // rgb(220, 144, 101)
|
||||||
{ r: 224, g: 117, b: 117, a: 0.5 }, // rgb(224, 117, 117)
|
{ r: 224, g: 117, b: 117 }, // rgb(224, 117, 117)
|
||||||
{ r: 213, g: 139, b: 202, a: 0.5 }, // rgb(213, 139, 202)
|
{ r: 213, g: 139, b: 202 }, // rgb(213, 139, 202)
|
||||||
{ r: 161, g: 120, b: 214, a: 0.5 }, // rgb(161, 120, 214)
|
{ r: 161, g: 120, b: 214 }, // rgb(161, 120, 214)
|
||||||
];
|
];
|
||||||
|
|
||||||
const getRGMaskFill = (state: CanvasV2State): RgbaColor => {
|
const getRGMaskFill = (state: CanvasV2State): RgbColor => {
|
||||||
const lastFill = state.regions.entities.slice(-1)[0]?.fill.color;
|
const lastFill = state.regions.entities.slice(-1)[0]?.fill.color;
|
||||||
let i = DEFAULT_MASK_COLORS.findIndex((c) => isEqual(c, lastFill));
|
let i = DEFAULT_MASK_COLORS.findIndex((c) => isEqual(c, lastFill));
|
||||||
if (i === -1) {
|
if (i === -1) {
|
||||||
@ -69,6 +69,7 @@ export const regionsReducers = {
|
|||||||
style: 'solid',
|
style: 'solid',
|
||||||
color: getRGMaskFill(state),
|
color: getRGMaskFill(state),
|
||||||
},
|
},
|
||||||
|
opacity: 0.5,
|
||||||
position: { x: 0, y: 0 },
|
position: { x: 0, y: 0 },
|
||||||
autoNegative: 'invert',
|
autoNegative: 'invert',
|
||||||
positivePrompt: '',
|
positivePrompt: '',
|
||||||
@ -105,7 +106,7 @@ export const regionsReducers = {
|
|||||||
}
|
}
|
||||||
entity.negativePrompt = prompt;
|
entity.negativePrompt = prompt;
|
||||||
},
|
},
|
||||||
rgFillColorChanged: (state, action: PayloadAction<{ id: string; color: RgbaColor }>) => {
|
rgFillColorChanged: (state, action: PayloadAction<{ id: string; color: RgbColor }>) => {
|
||||||
const { id, color } = action.payload;
|
const { id, color } = action.payload;
|
||||||
const entity = selectRegionalGuidanceEntity(state, id);
|
const entity = selectRegionalGuidanceEntity(state, id);
|
||||||
if (!entity) {
|
if (!entity) {
|
||||||
|
@ -41,6 +41,7 @@ import type {
|
|||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
export const zId = z.string().min(1);
|
export const zId = z.string().min(1);
|
||||||
|
export const zName = z.string().min(1).nullable();
|
||||||
|
|
||||||
export const zImageWithDims = z.object({
|
export const zImageWithDims = z.object({
|
||||||
image_name: z.string(),
|
image_name: z.string(),
|
||||||
@ -592,7 +593,7 @@ export type IPAdapterConfig = z.infer<typeof zIPAdapterConfig>;
|
|||||||
|
|
||||||
export const zCanvasIPAdapterState = z.object({
|
export const zCanvasIPAdapterState = z.object({
|
||||||
id: zId,
|
id: zId,
|
||||||
name: z.string().nullable(),
|
name: zName,
|
||||||
type: z.literal('ip_adapter'),
|
type: z.literal('ip_adapter'),
|
||||||
isEnabled: z.boolean(),
|
isEnabled: z.boolean(),
|
||||||
ipAdapter: zIPAdapterConfig,
|
ipAdapter: zIPAdapterConfig,
|
||||||
@ -665,7 +666,7 @@ export type RegionalGuidanceIPAdapterConfig = z.infer<typeof zRegionalGuidanceIP
|
|||||||
|
|
||||||
export const zCanvasRegionalGuidanceState = z.object({
|
export const zCanvasRegionalGuidanceState = z.object({
|
||||||
id: zId,
|
id: zId,
|
||||||
name: z.string().nullable(),
|
name: zName,
|
||||||
type: z.literal('regional_guidance'),
|
type: z.literal('regional_guidance'),
|
||||||
isEnabled: z.boolean(),
|
isEnabled: z.boolean(),
|
||||||
position: zCoordinate,
|
position: zCoordinate,
|
||||||
@ -681,7 +682,8 @@ export const zCanvasRegionalGuidanceState = z.object({
|
|||||||
export type CanvasRegionalGuidanceState = z.infer<typeof zCanvasRegionalGuidanceState>;
|
export type CanvasRegionalGuidanceState = z.infer<typeof zCanvasRegionalGuidanceState>;
|
||||||
|
|
||||||
const zCanvasInpaintMaskState = z.object({
|
const zCanvasInpaintMaskState = z.object({
|
||||||
id: z.literal('inpaint_mask'),
|
id: zId,
|
||||||
|
name: zName,
|
||||||
type: z.literal('inpaint_mask'),
|
type: z.literal('inpaint_mask'),
|
||||||
isEnabled: z.boolean(),
|
isEnabled: z.boolean(),
|
||||||
position: zCoordinate,
|
position: zCoordinate,
|
||||||
@ -742,7 +744,7 @@ export type T2IAdapterConfig = z.infer<typeof zT2IAdapterConfig>;
|
|||||||
|
|
||||||
export const zCanvasRasterLayerState = z.object({
|
export const zCanvasRasterLayerState = z.object({
|
||||||
id: zId,
|
id: zId,
|
||||||
name: z.string().nullable(),
|
name: zName,
|
||||||
type: z.literal('raster_layer'),
|
type: z.literal('raster_layer'),
|
||||||
isEnabled: z.boolean(),
|
isEnabled: z.boolean(),
|
||||||
position: zCoordinate,
|
position: zCoordinate,
|
||||||
@ -848,7 +850,7 @@ export const isCanvasBackgroundStyle = (v: unknown): v is CanvasBackgroundStyle
|
|||||||
export type CanvasV2State = {
|
export type CanvasV2State = {
|
||||||
_version: 3;
|
_version: 3;
|
||||||
selectedEntityIdentifier: CanvasEntityIdentifier | null;
|
selectedEntityIdentifier: CanvasEntityIdentifier | null;
|
||||||
inpaintMask: CanvasInpaintMaskState;
|
inpaintMasks: { entities: CanvasInpaintMaskState[]; compositeRasterizationCache: ImageCache[] };
|
||||||
rasterLayers: { entities: CanvasRasterLayerState[]; compositeRasterizationCache: ImageCache[] };
|
rasterLayers: { entities: CanvasRasterLayerState[]; compositeRasterizationCache: ImageCache[] };
|
||||||
controlLayers: { entities: CanvasControlLayerState[] };
|
controlLayers: { entities: CanvasControlLayerState[] };
|
||||||
ipAdapters: { entities: CanvasIPAdapterState[] };
|
ipAdapters: { entities: CanvasIPAdapterState[] };
|
||||||
|
@ -17,7 +17,7 @@ export const addImageToImage = async (
|
|||||||
): Promise<Invocation<'img_resize' | 'l2i'>> => {
|
): Promise<Invocation<'img_resize' | 'l2i'>> => {
|
||||||
denoise.denoising_start = denoising_start;
|
denoise.denoising_start = denoising_start;
|
||||||
|
|
||||||
const { image_name } = await manager.getCompositeLayerImageDTO(bbox.rect);
|
const { image_name } = await manager.getCompositeRasterLayerImageDTO(bbox.rect);
|
||||||
|
|
||||||
if (!isEqual(scaledSize, originalSize)) {
|
if (!isEqual(scaledSize, originalSize)) {
|
||||||
// Resize the initial image to the scaled size, denoise, then resize back to the original size
|
// Resize the initial image to the scaled size, denoise, then resize back to the original size
|
||||||
|
@ -21,8 +21,8 @@ export const addInpaint = async (
|
|||||||
): Promise<Invocation<'canvas_v2_mask_and_crop'>> => {
|
): Promise<Invocation<'canvas_v2_mask_and_crop'>> => {
|
||||||
denoise.denoising_start = denoising_start;
|
denoise.denoising_start = denoising_start;
|
||||||
|
|
||||||
const initialImage = await manager.getCompositeLayerImageDTO(bbox.rect);
|
const initialImage = await manager.getCompositeRasterLayerImageDTO(bbox.rect);
|
||||||
const maskImage = await manager.inpaintMaskAdapter.renderer.rasterize(bbox.rect);
|
const maskImage = await manager.getCompositeInpaintMaskImageDTO(bbox.rect);
|
||||||
|
|
||||||
if (!isEqual(scaledSize, originalSize)) {
|
if (!isEqual(scaledSize, originalSize)) {
|
||||||
// Scale before processing requires some resizing
|
// Scale before processing requires some resizing
|
||||||
|
@ -22,8 +22,8 @@ export const addOutpaint = async (
|
|||||||
): Promise<Invocation<'canvas_v2_mask_and_crop'>> => {
|
): Promise<Invocation<'canvas_v2_mask_and_crop'>> => {
|
||||||
denoise.denoising_start = denoising_start;
|
denoise.denoising_start = denoising_start;
|
||||||
|
|
||||||
const initialImage = await manager.getCompositeLayerImageDTO(bbox.rect);
|
const initialImage = await manager.getCompositeRasterLayerImageDTO(bbox.rect);
|
||||||
const maskImage = await manager.inpaintMaskAdapter.renderer.rasterize(bbox.rect);
|
const maskImage = await manager.getCompositeInpaintMaskImageDTO(bbox.rect);
|
||||||
const infill = getInfill(g, compositing);
|
const infill = getInfill(g, compositing);
|
||||||
|
|
||||||
if (!isEqual(scaledSize, originalSize)) {
|
if (!isEqual(scaledSize, originalSize)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user