From d88b59c5c419883efc7c6d6d5bc472a442fe6fa4 Mon Sep 17 00:00:00 2001 From: psychedelicious <4822129+psychedelicious@users.noreply.github.com> Date: Thu, 9 Jan 2025 15:21:12 +1100 Subject: [PATCH] Revert "feat(ui): rearrange canvas paste back nodes to save an image step" This reverts commit 7cdda00a5493aea09083006b627c1b8285bd40d8. --- .../nodes/util/graph/generation/addInpaint.ts | 30 +++++++++++------- .../util/graph/generation/addOutpaint.ts | 31 ++++++++++++------- 2 files changed, 37 insertions(+), 24 deletions(-) diff --git a/invokeai/frontend/web/src/features/nodes/util/graph/generation/addInpaint.ts b/invokeai/frontend/web/src/features/nodes/util/graph/generation/addInpaint.ts index 12969a62414..baf6974d226 100644 --- a/invokeai/frontend/web/src/features/nodes/util/graph/generation/addInpaint.ts +++ b/invokeai/frontend/web/src/features/nodes/util/graph/generation/addInpaint.ts @@ -86,6 +86,16 @@ export const addInpaint = async ({ type: 'img_resize', ...scaledSize, }); + const resizeImageToOriginalSize = g.addNode({ + id: getPrefixedId('resize_image_to_original_size'), + type: 'img_resize', + ...originalSize, + }); + const resizeMaskToOriginalSize = g.addNode({ + id: getPrefixedId('resize_mask_to_original_size'), + type: 'img_resize', + ...originalSize, + }); const createGradientMask = g.addNode({ id: getPrefixedId('create_gradient_mask'), type: 'create_gradient_mask', @@ -99,11 +109,6 @@ export const addInpaint = async ({ type: 'canvas_v2_mask_and_crop', mask_blur: params.maskBlur, }); - const resizeOutput = g.addNode({ - id: getPrefixedId('resize_output'), - type: 'img_resize', - ...originalSize, - }); // Resize initial image and mask to scaled size, feed into to gradient mask g.addEdge(alphaToMask, 'image', resizeMaskToScaledSize, 'image'); @@ -120,20 +125,21 @@ export const addInpaint = async ({ g.addEdge(createGradientMask, 'denoise_mask', denoise, 'denoise_mask'); - // Paste the generated masked image back onto the original image - g.addEdge(l2i, 'image', canvasPasteBack, 'generated_image'); - g.addEdge(createGradientMask, 'expanded_mask_area', canvasPasteBack, 'mask'); + // After denoising, resize the image and mask back to original size + g.addEdge(l2i, 'image', resizeImageToOriginalSize, 'image'); + g.addEdge(createGradientMask, 'expanded_mask_area', resizeMaskToOriginalSize, 'image'); - // Finally, resize the output back to the original size - g.addEdge(canvasPasteBack, 'image', resizeOutput, 'image'); + // Finally, paste the generated masked image back onto the original image + g.addEdge(resizeImageToOriginalSize, 'image', canvasPasteBack, 'generated_image'); + g.addEdge(resizeMaskToOriginalSize, 'image', canvasPasteBack, 'mask'); // Do the paste back if we are sending to gallery (in which case we want to see the full image), or if we are sending // to canvas but not outputting only masked regions if (!canvasSettings.sendToCanvas || !canvasSettings.outputOnlyMaskedRegions) { - g.addEdge(resizeImageToScaledSize, 'image', canvasPasteBack, 'source_image'); + canvasPasteBack.source_image = { image_name: initialImage.image_name }; } - return resizeOutput; + return canvasPasteBack; } else { // No scale before processing, much simpler const i2l = g.addNode({ diff --git a/invokeai/frontend/web/src/features/nodes/util/graph/generation/addOutpaint.ts b/invokeai/frontend/web/src/features/nodes/util/graph/generation/addOutpaint.ts index 72debe910c2..a1d6ddb738c 100644 --- a/invokeai/frontend/web/src/features/nodes/util/graph/generation/addOutpaint.ts +++ b/invokeai/frontend/web/src/features/nodes/util/graph/generation/addOutpaint.ts @@ -131,33 +131,40 @@ export const addOutpaint = async ({ g.addEdge(vaeSource, 'vae', i2l, 'vae'); g.addEdge(i2l, 'latents', denoise, 'latents'); + // Resize the output image back to the original size + const resizeOutputImageToOriginalSize = g.addNode({ + id: getPrefixedId('resize_image_to_original_size'), + type: 'img_resize', + ...originalSize, + }); + const resizeOutputMaskToOriginalSize = g.addNode({ + id: getPrefixedId('resize_mask_to_original_size'), + type: 'img_resize', + ...originalSize, + }); const canvasPasteBack = g.addNode({ id: getPrefixedId('canvas_v2_mask_and_crop'), type: 'canvas_v2_mask_and_crop', mask_blur: params.maskBlur, }); - const resizeOutput = g.addNode({ - id: getPrefixedId('resize_output'), - type: 'img_resize', - ...originalSize, - }); // Resize initial image and mask to scaled size, feed into to gradient mask - // Paste the generated masked image back onto the original image - g.addEdge(l2i, 'image', canvasPasteBack, 'generated_image'); - g.addEdge(createGradientMask, 'expanded_mask_area', canvasPasteBack, 'mask'); + // After denoising, resize the image and mask back to original size + g.addEdge(l2i, 'image', resizeOutputImageToOriginalSize, 'image'); + g.addEdge(createGradientMask, 'expanded_mask_area', resizeOutputMaskToOriginalSize, 'image'); - // Finally, resize the output back to the original size - g.addEdge(canvasPasteBack, 'image', resizeOutput, 'image'); + // Finally, paste the generated masked image back onto the original image + g.addEdge(resizeOutputImageToOriginalSize, 'image', canvasPasteBack, 'generated_image'); + g.addEdge(resizeOutputMaskToOriginalSize, 'image', canvasPasteBack, 'mask'); // Do the paste back if we are sending to gallery (in which case we want to see the full image), or if we are sending // to canvas but not outputting only masked regions if (!canvasSettings.sendToCanvas || !canvasSettings.outputOnlyMaskedRegions) { - g.addEdge(resizeInputImageToScaledSize, 'image', canvasPasteBack, 'source_image'); + canvasPasteBack.source_image = { image_name: initialImage.image_name }; } - return resizeOutput; + return canvasPasteBack; } else { infill.image = { image_name: initialImage.image_name }; // No scale before processing, much simpler