mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
feat: Scaled Bounding Box Dimensions now respect Aspect Ratio
This commit is contained in:
parent
dfbcb773da
commit
86185f2fe3
@ -235,10 +235,18 @@ export const canvasSlice = createSlice({
|
|||||||
state.boundingBoxDimensions.width,
|
state.boundingBoxDimensions.width,
|
||||||
state.boundingBoxDimensions.height,
|
state.boundingBoxDimensions.height,
|
||||||
];
|
];
|
||||||
|
const [currScaledWidth, currScaledHeight] = [
|
||||||
|
state.scaledBoundingBoxDimensions.width,
|
||||||
|
state.scaledBoundingBoxDimensions.height,
|
||||||
|
];
|
||||||
state.boundingBoxDimensions = {
|
state.boundingBoxDimensions = {
|
||||||
width: currHeight,
|
width: currHeight,
|
||||||
height: currWidth,
|
height: currWidth,
|
||||||
};
|
};
|
||||||
|
state.scaledBoundingBoxDimensions = {
|
||||||
|
width: currScaledHeight,
|
||||||
|
height: currScaledWidth,
|
||||||
|
};
|
||||||
},
|
},
|
||||||
setBoundingBoxCoordinates: (state, action: PayloadAction<Vector2d>) => {
|
setBoundingBoxCoordinates: (state, action: PayloadAction<Vector2d>) => {
|
||||||
state.boundingBoxCoordinates = floorCoordinates(action.payload);
|
state.boundingBoxCoordinates = floorCoordinates(action.payload);
|
||||||
@ -788,6 +796,10 @@ export const canvasSlice = createSlice({
|
|||||||
state.boundingBoxDimensions.width / ratio,
|
state.boundingBoxDimensions.width / ratio,
|
||||||
64
|
64
|
||||||
);
|
);
|
||||||
|
state.scaledBoundingBoxDimensions.height = roundToMultiple(
|
||||||
|
state.scaledBoundingBoxDimensions.width / ratio,
|
||||||
|
64
|
||||||
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -2,6 +2,7 @@ import { createSelector } from '@reduxjs/toolkit';
|
|||||||
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
|
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 { roundToMultiple } from 'common/util/roundDownToMultiple';
|
||||||
import { canvasSelector } from 'features/canvas/store/canvasSelectors';
|
import { canvasSelector } from 'features/canvas/store/canvasSelectors';
|
||||||
import { setScaledBoundingBoxDimensions } from 'features/canvas/store/canvasSlice';
|
import { setScaledBoundingBoxDimensions } from 'features/canvas/store/canvasSlice';
|
||||||
import { generationSelector } from 'features/parameters/store/generationSelectors';
|
import { generationSelector } from 'features/parameters/store/generationSelectors';
|
||||||
@ -12,12 +13,13 @@ const selector = createSelector(
|
|||||||
[generationSelector, canvasSelector],
|
[generationSelector, canvasSelector],
|
||||||
(generation, canvas) => {
|
(generation, canvas) => {
|
||||||
const { scaledBoundingBoxDimensions, boundingBoxScaleMethod } = canvas;
|
const { scaledBoundingBoxDimensions, boundingBoxScaleMethod } = canvas;
|
||||||
const { model } = generation;
|
const { model, aspectRatio } = generation;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
model,
|
model,
|
||||||
scaledBoundingBoxDimensions,
|
scaledBoundingBoxDimensions,
|
||||||
isManual: boundingBoxScaleMethod === 'manual',
|
isManual: boundingBoxScaleMethod === 'manual',
|
||||||
|
aspectRatio,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
defaultSelectorOptions
|
defaultSelectorOptions
|
||||||
@ -25,7 +27,7 @@ const selector = createSelector(
|
|||||||
|
|
||||||
const ParamScaledHeight = () => {
|
const ParamScaledHeight = () => {
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
const { model, isManual, scaledBoundingBoxDimensions } =
|
const { model, isManual, scaledBoundingBoxDimensions, aspectRatio } =
|
||||||
useAppSelector(selector);
|
useAppSelector(selector);
|
||||||
|
|
||||||
const initial = ['sdxl', 'sdxl-refiner'].includes(model?.base_model as string)
|
const initial = ['sdxl', 'sdxl-refiner'].includes(model?.base_model as string)
|
||||||
@ -35,19 +37,33 @@ const ParamScaledHeight = () => {
|
|||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
const handleChangeScaledHeight = (v: number) => {
|
const handleChangeScaledHeight = (v: number) => {
|
||||||
|
let newWidth = scaledBoundingBoxDimensions.width;
|
||||||
|
const newHeight = Math.floor(v);
|
||||||
|
|
||||||
|
if (aspectRatio) {
|
||||||
|
newWidth = roundToMultiple(newHeight * aspectRatio, 8);
|
||||||
|
}
|
||||||
|
|
||||||
dispatch(
|
dispatch(
|
||||||
setScaledBoundingBoxDimensions({
|
setScaledBoundingBoxDimensions({
|
||||||
...scaledBoundingBoxDimensions,
|
width: newWidth,
|
||||||
height: Math.floor(v),
|
height: newHeight,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleResetScaledHeight = () => {
|
const handleResetScaledHeight = () => {
|
||||||
|
let resetWidth = scaledBoundingBoxDimensions.width;
|
||||||
|
const resetHeight = Math.floor(initial);
|
||||||
|
|
||||||
|
if (aspectRatio) {
|
||||||
|
resetWidth = roundToMultiple(resetHeight * aspectRatio, 8);
|
||||||
|
}
|
||||||
|
|
||||||
dispatch(
|
dispatch(
|
||||||
setScaledBoundingBoxDimensions({
|
setScaledBoundingBoxDimensions({
|
||||||
...scaledBoundingBoxDimensions,
|
width: resetWidth,
|
||||||
height: Math.floor(initial),
|
height: resetHeight,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -2,6 +2,7 @@ import { createSelector } from '@reduxjs/toolkit';
|
|||||||
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
|
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 { roundToMultiple } from 'common/util/roundDownToMultiple';
|
||||||
import { canvasSelector } from 'features/canvas/store/canvasSelectors';
|
import { canvasSelector } from 'features/canvas/store/canvasSelectors';
|
||||||
import { setScaledBoundingBoxDimensions } from 'features/canvas/store/canvasSlice';
|
import { setScaledBoundingBoxDimensions } from 'features/canvas/store/canvasSlice';
|
||||||
import { generationSelector } from 'features/parameters/store/generationSelectors';
|
import { generationSelector } from 'features/parameters/store/generationSelectors';
|
||||||
@ -12,11 +13,12 @@ const selector = createSelector(
|
|||||||
[canvasSelector, generationSelector],
|
[canvasSelector, generationSelector],
|
||||||
(canvas, generation) => {
|
(canvas, generation) => {
|
||||||
const { boundingBoxScaleMethod, scaledBoundingBoxDimensions } = canvas;
|
const { boundingBoxScaleMethod, scaledBoundingBoxDimensions } = canvas;
|
||||||
const { model } = generation;
|
const { model, aspectRatio } = generation;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
model,
|
model,
|
||||||
scaledBoundingBoxDimensions,
|
scaledBoundingBoxDimensions,
|
||||||
|
aspectRatio,
|
||||||
isManual: boundingBoxScaleMethod === 'manual',
|
isManual: boundingBoxScaleMethod === 'manual',
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
@ -25,7 +27,7 @@ const selector = createSelector(
|
|||||||
|
|
||||||
const ParamScaledWidth = () => {
|
const ParamScaledWidth = () => {
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
const { model, isManual, scaledBoundingBoxDimensions } =
|
const { model, isManual, scaledBoundingBoxDimensions, aspectRatio } =
|
||||||
useAppSelector(selector);
|
useAppSelector(selector);
|
||||||
|
|
||||||
const initial = ['sdxl', 'sdxl-refiner'].includes(model?.base_model as string)
|
const initial = ['sdxl', 'sdxl-refiner'].includes(model?.base_model as string)
|
||||||
@ -35,19 +37,33 @@ const ParamScaledWidth = () => {
|
|||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
const handleChangeScaledWidth = (v: number) => {
|
const handleChangeScaledWidth = (v: number) => {
|
||||||
|
const newWidth = Math.floor(v);
|
||||||
|
let newHeight = scaledBoundingBoxDimensions.height;
|
||||||
|
|
||||||
|
if (aspectRatio) {
|
||||||
|
newHeight = roundToMultiple(newWidth / aspectRatio, 8);
|
||||||
|
}
|
||||||
|
|
||||||
dispatch(
|
dispatch(
|
||||||
setScaledBoundingBoxDimensions({
|
setScaledBoundingBoxDimensions({
|
||||||
...scaledBoundingBoxDimensions,
|
width: newWidth,
|
||||||
width: Math.floor(v),
|
height: newHeight,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleResetScaledWidth = () => {
|
const handleResetScaledWidth = () => {
|
||||||
|
const resetWidth = Math.floor(initial);
|
||||||
|
let resetHeight = scaledBoundingBoxDimensions.height;
|
||||||
|
|
||||||
|
if (aspectRatio) {
|
||||||
|
resetHeight = roundToMultiple(resetWidth / aspectRatio, 8);
|
||||||
|
}
|
||||||
|
|
||||||
dispatch(
|
dispatch(
|
||||||
setScaledBoundingBoxDimensions({
|
setScaledBoundingBoxDimensions({
|
||||||
...scaledBoundingBoxDimensions,
|
width: resetWidth,
|
||||||
width: Math.floor(initial),
|
height: resetHeight,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user