mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
fix(ui): fix canvas bbox autoscale
This commit is contained in:
parent
c22c6ca135
commit
1a3fd05b81
@ -9,7 +9,8 @@ import { IRect } from 'konva/lib/types';
|
|||||||
*/
|
*/
|
||||||
const createMaskStage = async (
|
const createMaskStage = async (
|
||||||
lines: CanvasMaskLine[],
|
lines: CanvasMaskLine[],
|
||||||
boundingBox: IRect
|
boundingBox: IRect,
|
||||||
|
shouldInvertMask: boolean
|
||||||
): Promise<Konva.Stage> => {
|
): Promise<Konva.Stage> => {
|
||||||
// create an offscreen canvas and add the mask to it
|
// create an offscreen canvas and add the mask to it
|
||||||
const { width, height } = boundingBox;
|
const { width, height } = boundingBox;
|
||||||
@ -29,7 +30,7 @@ const createMaskStage = async (
|
|||||||
baseLayer.add(
|
baseLayer.add(
|
||||||
new Konva.Rect({
|
new Konva.Rect({
|
||||||
...boundingBox,
|
...boundingBox,
|
||||||
fill: 'white',
|
fill: shouldInvertMask ? 'black' : 'white',
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -37,7 +38,7 @@ const createMaskStage = async (
|
|||||||
maskLayer.add(
|
maskLayer.add(
|
||||||
new Konva.Line({
|
new Konva.Line({
|
||||||
points: line.points,
|
points: line.points,
|
||||||
stroke: 'black',
|
stroke: shouldInvertMask ? 'white' : 'black',
|
||||||
strokeWidth: line.strokeWidth * 2,
|
strokeWidth: line.strokeWidth * 2,
|
||||||
tension: 0,
|
tension: 0,
|
||||||
lineCap: 'round',
|
lineCap: 'round',
|
||||||
|
@ -25,6 +25,7 @@ export const getCanvasData = async (state: RootState) => {
|
|||||||
boundingBoxCoordinates,
|
boundingBoxCoordinates,
|
||||||
boundingBoxDimensions,
|
boundingBoxDimensions,
|
||||||
isMaskEnabled,
|
isMaskEnabled,
|
||||||
|
shouldPreserveMaskedArea,
|
||||||
} = state.canvas;
|
} = state.canvas;
|
||||||
|
|
||||||
const boundingBox = {
|
const boundingBox = {
|
||||||
@ -58,7 +59,8 @@ export const getCanvasData = async (state: RootState) => {
|
|||||||
// For the mask layer, use the normal boundingBox
|
// For the mask layer, use the normal boundingBox
|
||||||
const maskStage = await createMaskStage(
|
const maskStage = await createMaskStage(
|
||||||
isMaskEnabled ? objects.filter(isCanvasMaskLine) : [], // only include mask lines, and only if mask is enabled
|
isMaskEnabled ? objects.filter(isCanvasMaskLine) : [], // only include mask lines, and only if mask is enabled
|
||||||
boundingBox
|
boundingBox,
|
||||||
|
shouldPreserveMaskedArea
|
||||||
);
|
);
|
||||||
const maskBlob = await konvaNodeToBlob(maskStage, boundingBox);
|
const maskBlob = await konvaNodeToBlob(maskStage, boundingBox);
|
||||||
const maskImageData = await konvaNodeToImageData(maskStage, boundingBox);
|
const maskImageData = await konvaNodeToImageData(maskStage, boundingBox);
|
||||||
|
@ -16,7 +16,7 @@ import { buildEdges } from '../edgeBuilders/buildEdges';
|
|||||||
import { log } from 'app/logging/useLogger';
|
import { log } from 'app/logging/useLogger';
|
||||||
import { buildInpaintNode } from '../nodeBuilders/buildInpaintNode';
|
import { buildInpaintNode } from '../nodeBuilders/buildInpaintNode';
|
||||||
|
|
||||||
const moduleLog = log.child({ namespace: 'buildCanvasGraph' });
|
const moduleLog = log.child({ namespace: 'nodes' });
|
||||||
|
|
||||||
const buildBaseNode = (
|
const buildBaseNode = (
|
||||||
nodeType: 'txt2img' | 'img2img' | 'inpaint' | 'outpaint',
|
nodeType: 'txt2img' | 'img2img' | 'inpaint' | 'outpaint',
|
||||||
@ -80,18 +80,23 @@ export const buildCanvasGraphComponents = async (
|
|||||||
infillMethod,
|
infillMethod,
|
||||||
} = state.generation;
|
} = state.generation;
|
||||||
|
|
||||||
// generationParameters.invert_mask = shouldPreserveMaskedArea;
|
const { scaledBoundingBoxDimensions, boundingBoxScaleMethod } =
|
||||||
// if (boundingBoxScale !== 'none') {
|
state.canvas;
|
||||||
// generationParameters.inpaint_width = scaledBoundingBoxDimensions.width;
|
|
||||||
// generationParameters.inpaint_height = scaledBoundingBoxDimensions.height;
|
if (boundingBoxScaleMethod !== 'none') {
|
||||||
// }
|
baseNode.inpaint_width = scaledBoundingBoxDimensions.width;
|
||||||
|
baseNode.inpaint_height = scaledBoundingBoxDimensions.height;
|
||||||
|
}
|
||||||
|
|
||||||
baseNode.seam_size = seamSize;
|
baseNode.seam_size = seamSize;
|
||||||
baseNode.seam_blur = seamBlur;
|
baseNode.seam_blur = seamBlur;
|
||||||
baseNode.seam_strength = seamStrength;
|
baseNode.seam_strength = seamStrength;
|
||||||
baseNode.seam_steps = seamSteps;
|
baseNode.seam_steps = seamSteps;
|
||||||
baseNode.tile_size = tileSize;
|
|
||||||
baseNode.infill_method = infillMethod as InpaintInvocation['infill_method'];
|
baseNode.infill_method = infillMethod as InpaintInvocation['infill_method'];
|
||||||
// baseNode.force_outpaint = false;
|
|
||||||
|
if (infillMethod === 'tile') {
|
||||||
|
baseNode.tile_size = tileSize;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// We always range and iterate nodes, no matter the iteration count
|
// We always range and iterate nodes, no matter the iteration count
|
||||||
|
@ -2,15 +2,12 @@ import { v4 as uuidv4 } from 'uuid';
|
|||||||
import { RootState } from 'app/store/store';
|
import { RootState } from 'app/store/store';
|
||||||
import { InpaintInvocation } from 'services/api';
|
import { InpaintInvocation } from 'services/api';
|
||||||
import { O } from 'ts-toolbelt';
|
import { O } from 'ts-toolbelt';
|
||||||
import { activeTabNameSelector } from 'features/ui/store/uiSelectors';
|
|
||||||
|
|
||||||
export const buildInpaintNode = (
|
export const buildInpaintNode = (
|
||||||
state: RootState,
|
state: RootState,
|
||||||
overrides: O.Partial<InpaintInvocation, 'deep'> = {}
|
overrides: O.Partial<InpaintInvocation, 'deep'> = {}
|
||||||
): InpaintInvocation => {
|
): InpaintInvocation => {
|
||||||
const nodeId = uuidv4();
|
const nodeId = uuidv4();
|
||||||
const { generation } = state;
|
|
||||||
const activeTabName = activeTabNameSelector(state);
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
positivePrompt: prompt,
|
positivePrompt: prompt,
|
||||||
@ -25,8 +22,7 @@ export const buildInpaintNode = (
|
|||||||
img2imgStrength: strength,
|
img2imgStrength: strength,
|
||||||
shouldFitToWidthHeight: fit,
|
shouldFitToWidthHeight: fit,
|
||||||
shouldRandomizeSeed,
|
shouldRandomizeSeed,
|
||||||
initialImage,
|
} = state.generation;
|
||||||
} = generation;
|
|
||||||
|
|
||||||
const inpaintNode: InpaintInvocation = {
|
const inpaintNode: InpaintInvocation = {
|
||||||
id: nodeId,
|
id: nodeId,
|
||||||
@ -42,19 +38,6 @@ export const buildInpaintNode = (
|
|||||||
fit,
|
fit,
|
||||||
};
|
};
|
||||||
|
|
||||||
// on Canvas tab, we do not manually specific init image
|
|
||||||
if (activeTabName !== 'unifiedCanvas') {
|
|
||||||
if (!initialImage) {
|
|
||||||
// TODO: handle this more better
|
|
||||||
throw 'no initial image';
|
|
||||||
}
|
|
||||||
|
|
||||||
inpaintNode.image = {
|
|
||||||
image_name: initialImage.name,
|
|
||||||
image_origin: initialImage.type,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!shouldRandomizeSeed) {
|
if (!shouldRandomizeSeed) {
|
||||||
inpaintNode.seed = seed;
|
inpaintNode.seed = seed;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user