Skip to content

Commit 21deefd

Browse files
Mary Hipppsychedelicious
authored andcommitted
(ui): add image resolution badge to initial upscale image
1 parent 4d4f921 commit 21deefd

File tree

3 files changed

+80
-22
lines changed

3 files changed

+80
-22
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { createMemoizedSelector } from 'app/store/createMemoizedSelector';
2+
import { useAppSelector } from 'app/store/storeHooks';
3+
import { selectUpscalelice } from 'features/parameters/store/upscaleSlice';
4+
import { selectConfigSlice } from 'features/system/store/configSlice';
5+
import { useMemo } from 'react';
6+
import type { ImageDTO } from 'services/api/types';
7+
8+
9+
export const createIsTooLargeToUpscaleSelector = (imageDTO?: ImageDTO) =>
10+
createMemoizedSelector(selectUpscalelice, selectConfigSlice, (upscale, config) => {
11+
const { upscaleModel, scale } = upscale;
12+
const { maxUpscalePixels } = config;
13+
14+
if (!maxUpscalePixels || !upscaleModel || !imageDTO) {
15+
return false
16+
}
17+
18+
const upscaledPixels = imageDTO.width * scale * imageDTO.height * scale;
19+
console.log({ upscaledPixels })
20+
console.log({ maxUpscalePixels })
21+
return upscaledPixels > maxUpscalePixels
22+
23+
});
24+
25+
export const useIsTooLargeToUpscale = (imageDTO?: ImageDTO) => {
26+
const selectIsTooLargeToUpscale = useMemo(() => createIsTooLargeToUpscaleSelector(imageDTO), [imageDTO]);
27+
return useAppSelector(selectIsTooLargeToUpscale);
28+
};

invokeai/frontend/web/src/features/settingsAccordions/components/UpscaleSettingsAccordion/UpscaleInitialImage.tsx

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Flex } from '@invoke-ai/ui-library';
1+
import { Flex, Text } from '@invoke-ai/ui-library';
22
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
33
import IAIDndImage from 'common/components/IAIDndImage';
44
import IAIDndImageIcon from 'common/components/IAIDndImageIcon';
@@ -41,13 +41,30 @@ export const UpscaleInitialImage = () => {
4141
postUploadAction={postUploadAction}
4242
/>
4343
{imageDTO && (
44-
<Flex position="absolute" flexDir="column" top={1} insetInlineEnd={1} gap={1}>
45-
<IAIDndImageIcon
46-
onClick={onReset}
47-
icon={<PiArrowCounterClockwiseBold size={16} />}
48-
tooltip={t('controlnet.resetControlImage')}
49-
/>
50-
</Flex>
44+
<>
45+
<Flex position="absolute" flexDir="column" top={1} insetInlineEnd={1} gap={1}>
46+
<IAIDndImageIcon
47+
onClick={onReset}
48+
icon={<PiArrowCounterClockwiseBold size={16} />}
49+
tooltip={t('controlnet.resetControlImage')}
50+
/>
51+
</Flex>
52+
<Text
53+
position="absolute"
54+
background="base.900"
55+
color="base.50"
56+
fontSize="sm"
57+
fontWeight="semibold"
58+
bottom={0}
59+
left={0}
60+
opacity={0.7}
61+
px={2}
62+
lineHeight={1.25}
63+
borderTopEndRadius="base"
64+
borderBottomStartRadius="base"
65+
pointerEvents="none"
66+
>{`${imageDTO.width}x${imageDTO.height}`}</Text>
67+
</>
5168
)}
5269
</Flex>
5370
</Flex>

invokeai/frontend/web/src/features/settingsAccordions/components/UpscaleSettingsAccordion/UpscaleWarning.tsx

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,19 @@ import { setActiveTab } from 'features/ui/store/uiSlice';
66
import { useCallback, useEffect, useMemo } from 'react';
77
import { Trans, useTranslation } from 'react-i18next';
88
import { useControlNetModels } from 'services/api/hooks/modelsByType';
9+
import { useIsTooLargeToUpscale } from '../../../parameters/hooks/useIsTooLargeToUpscale';
910

1011
export const UpscaleWarning = () => {
1112
const { t } = useTranslation();
1213
const model = useAppSelector((s) => s.generation.model);
1314
const upscaleModel = useAppSelector((s) => s.upscale.upscaleModel);
1415
const tileControlnetModel = useAppSelector((s) => s.upscale.tileControlnetModel);
16+
const upscaleInitialImage = useAppSelector((s) => s.upscale.upscaleInitialImage);
1517
const dispatch = useAppDispatch();
1618
const [modelConfigs, { isLoading }] = useControlNetModels();
1719
const disabledTabs = useAppSelector((s) => s.config.disabledTabs);
1820
const shouldShowButton = useMemo(() => !disabledTabs.includes('models'), [disabledTabs]);
21+
const isTooLargeToUpscale = useIsTooLargeToUpscale(upscaleInitialImage || undefined);
1922

2023
useEffect(() => {
2124
const validModel = modelConfigs.find((cnetModel) => {
@@ -24,7 +27,7 @@ export const UpscaleWarning = () => {
2427
dispatch(tileControlnetModelChanged(validModel || null));
2528
}, [model?.base, modelConfigs, dispatch]);
2629

27-
const warnings = useMemo(() => {
30+
const modelWarnings = useMemo(() => {
2831
const _warnings: string[] = [];
2932
if (!model) {
3033
_warnings.push(t('upscaling.mainModelDesc'));
@@ -35,33 +38,43 @@ export const UpscaleWarning = () => {
3538
if (!upscaleModel) {
3639
_warnings.push(t('upscaling.upscaleModelDesc'));
3740
}
38-
3941
return _warnings;
4042
}, [model, tileControlnetModel, upscaleModel, t]);
4143

44+
const otherWarnings = useMemo(() => {
45+
console.log({ isTooLargeToUpscale });
46+
const _warnings: string[] = [];
47+
if (isTooLargeToUpscale) {
48+
_warnings.push(t('upscaling.outputTooLarge'));
49+
}
50+
return _warnings;
51+
}, [isTooLargeToUpscale]);
52+
4253
const handleGoToModelManager = useCallback(() => {
4354
dispatch(setActiveTab('models'));
4455
$installModelsTab.set(3);
4556
}, [dispatch]);
4657

47-
if (!warnings.length || isLoading || !shouldShowButton) {
58+
if ((!modelWarnings.length && !otherWarnings.length) || isLoading || !shouldShowButton) {
4859
return null;
4960
}
5061

5162
return (
5263
<Flex bg="error.500" borderRadius="base" padding={4} direction="column" fontSize="sm" gap={2}>
53-
<Text>
54-
<Trans
55-
i18nKey="upscaling.missingModelsWarning"
56-
components={{
57-
LinkComponent: (
58-
<Button size="sm" flexGrow={0} variant="link" color="base.50" onClick={handleGoToModelManager} />
59-
),
60-
}}
61-
/>
62-
</Text>
64+
{!!modelWarnings.length && (
65+
<Text>
66+
<Trans
67+
i18nKey="upscaling.missingModelsWarning"
68+
components={{
69+
LinkComponent: (
70+
<Button size="sm" flexGrow={0} variant="link" color="base.50" onClick={handleGoToModelManager} />
71+
),
72+
}}
73+
/>
74+
</Text>
75+
)}
6376
<UnorderedList>
64-
{warnings.map((warning) => (
77+
{[...modelWarnings, ...otherWarnings].map((warning) => (
6578
<ListItem key={warning}>{warning}</ListItem>
6679
))}
6780
</UnorderedList>

0 commit comments

Comments
 (0)