From 19c16af5fae5515cfdb9580a51e3bdd36765c04e Mon Sep 17 00:00:00 2001 From: patriceac <48073125+patriceac@users.noreply.github.com> Date: Wed, 28 Dec 2022 16:43:35 -0800 Subject: [PATCH 1/6] Fix img2img task restoration Fix source image, mask, and color profile restoration for use settings, copy/paste, and d&d. --- ui/media/js/dnd.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/ui/media/js/dnd.js b/ui/media/js/dnd.js index 4d3f8af8..fa24ca00 100644 --- a/ui/media/js/dnd.js +++ b/ui/media/js/dnd.js @@ -137,7 +137,14 @@ const TASK_MAPPING = { readUI: () => (maskSetting.checked ? imageInpainter.getImg() : undefined), parse: (val) => val }, - + preserve_init_image_color_profile: { name: 'Preserve Color Profile', + setUI: (preserve_init_image_color_profile) => { + applyColorCorrectionField.checked = parseBoolean(preserve_init_image_color_profile) + }, + readUI: () => applyColorCorrectionField.checked, + parse: (val) => parseBoolean(val) + }, + use_face_correction: { name: 'Use Face Correction', setUI: (use_face_correction) => { useFaceCorrectionField.checked = parseBoolean(use_face_correction) @@ -297,7 +304,11 @@ function restoreTaskToUI(task, fieldsToSkip) { // restore the original tag promptField.value = task.reqBody.original_prompt || task.reqBody.prompt - // properly reset checkboxes + // properly reset missing fields + if (!('use_hypernetwork_model' in task.reqBody)) { + hypernetworkModelField.value = "" + hypernetworkModelField.dispatchEvent(new Event("change")) + } if (!('use_face_correction' in task.reqBody)) { useFaceCorrectionField.checked = false } @@ -306,6 +317,7 @@ function restoreTaskToUI(task, fieldsToSkip) { } if (!('mask' in task.reqBody)) { maskSetting.checked = false + maskSetting.dispatchEvent(new Event("click")) } upscaleModelField.disabled = !useUpscalingField.checked upscaleAmountField.disabled = !useUpscalingField.checked @@ -313,12 +325,17 @@ function restoreTaskToUI(task, fieldsToSkip) { // Show the source picture if present initImagePreview.src = (task.reqBody.init_image == undefined ? '' : task.reqBody.init_image) if (IMAGE_REGEX.test(initImagePreview.src)) { + initImagePreview.dispatchEvent(new Event("load")) if (Boolean(task.reqBody.mask)) { setTimeout(() => { // add a delay to insure this happens AFTER the main image loads (which reloads the inpainter) imageInpainter.setImg(task.reqBody.mask) }, 250) } } + else + { + img2imgUnload() + } } function readUI() { const reqBody = {} From 5fddae589b5c930244654029f7a7220b92cdfe31 Mon Sep 17 00:00:00 2001 From: patriceac <48073125+patriceac@users.noreply.github.com> Date: Wed, 28 Dec 2022 16:54:36 -0800 Subject: [PATCH 2/6] Reverting duplicate hypernetwork fix --- ui/media/js/dnd.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/ui/media/js/dnd.js b/ui/media/js/dnd.js index fa24ca00..c054bdf5 100644 --- a/ui/media/js/dnd.js +++ b/ui/media/js/dnd.js @@ -304,11 +304,7 @@ function restoreTaskToUI(task, fieldsToSkip) { // restore the original tag promptField.value = task.reqBody.original_prompt || task.reqBody.prompt - // properly reset missing fields - if (!('use_hypernetwork_model' in task.reqBody)) { - hypernetworkModelField.value = "" - hypernetworkModelField.dispatchEvent(new Event("change")) - } + // properly reset checkboxes if (!('use_face_correction' in task.reqBody)) { useFaceCorrectionField.checked = false } From 89170af72109c9351497e2c69a0b42d33c4e817c Mon Sep 17 00:00:00 2001 From: patriceac <48073125+patriceac@users.noreply.github.com> Date: Wed, 28 Dec 2022 17:00:38 -0800 Subject: [PATCH 3/6] Proper source image unloading --- ui/media/js/dnd.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/media/js/dnd.js b/ui/media/js/dnd.js index c054bdf5..d0be123e 100644 --- a/ui/media/js/dnd.js +++ b/ui/media/js/dnd.js @@ -330,7 +330,7 @@ function restoreTaskToUI(task, fieldsToSkip) { } else { - img2imgUnload() + initImageClearBtn.dispatchEvent(new Event("click")) } } function readUI() { From f7193966fbea27485c1b7e636647b63b0cb3c443 Mon Sep 17 00:00:00 2001 From: patriceac <48073125+patriceac@users.noreply.github.com> Date: Thu, 29 Dec 2022 01:16:44 -0800 Subject: [PATCH 4/6] Addressing Cmdr2's comments and more Only triggers events when there actually was a state change. Also opportunistically removed the hardcoded delay in favor of an even-driven flow, which makes the whole thing more robust and much more reactive. --- ui/media/js/dnd.js | 28 +++++++++++++++------------- ui/media/js/main.js | 1 + 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/ui/media/js/dnd.js b/ui/media/js/dnd.js index d0be123e..3732db19 100644 --- a/ui/media/js/dnd.js +++ b/ui/media/js/dnd.js @@ -282,6 +282,7 @@ const TASK_MAPPING = { parse: (val) => val } } + function restoreTaskToUI(task, fieldsToSkip) { fieldsToSkip = fieldsToSkip || [] @@ -311,27 +312,28 @@ function restoreTaskToUI(task, fieldsToSkip) { if (!('use_upscale' in task.reqBody)) { useUpscalingField.checked = false } - if (!('mask' in task.reqBody)) { + if (!('mask' in task.reqBody) && maskSetting.checked) { maskSetting.checked = false maskSetting.dispatchEvent(new Event("click")) } upscaleModelField.disabled = !useUpscalingField.checked upscaleAmountField.disabled = !useUpscalingField.checked - // Show the source picture if present - initImagePreview.src = (task.reqBody.init_image == undefined ? '' : task.reqBody.init_image) - if (IMAGE_REGEX.test(initImagePreview.src)) { - initImagePreview.dispatchEvent(new Event("load")) - if (Boolean(task.reqBody.mask)) { - setTimeout(() => { // add a delay to insure this happens AFTER the main image loads (which reloads the inpainter) - imageInpainter.setImg(task.reqBody.mask) - }, 250) - } - } - else - { + // hide/show source picture as needed + if (IMAGE_REGEX.test(initImagePreview.src) && task.reqBody.init_image == undefined) { + // hide source image initImageClearBtn.dispatchEvent(new Event("click")) } + else if (task.reqBody.init_image !== undefined) { + // listen for inpainter loading event, which happens AFTER the main image loads (which reloads the inpainter) + document.addEventListener('imagePainterLoad', function() { + if (Boolean(task.reqBody.mask)) { + imageInpainter.setImg(task.reqBody.mask) + } + }, { once: true }) + initImagePreview.src = task.reqBody.init_image + initImagePreview.dispatchEvent(new Event("load")) + } } function readUI() { const reqBody = {} diff --git a/ui/media/js/main.js b/ui/media/js/main.js index 07bd2e5f..b8483a92 100644 --- a/ui/media/js/main.js +++ b/ui/media/js/main.js @@ -1373,6 +1373,7 @@ function img2imgLoad() { initImageSizeBox.textContent = initImagePreview.naturalWidth + " x " + initImagePreview.naturalHeight imageEditor.setImage(this.src, initImagePreview.naturalWidth, initImagePreview.naturalHeight) imageInpainter.setImage(this.src, parseInt(widthField.value), parseInt(heightField.value)) + document.dispatchEvent(new Event("imagePainterLoad")) } function img2imgUnload() { From 21e3299b7af2f4afe12bb477bcf46f8c58d0c87d Mon Sep 17 00:00:00 2001 From: patriceac <48073125+patriceac@users.noreply.github.com> Date: Thu, 29 Dec 2022 09:26:32 -0800 Subject: [PATCH 5/6] Applying changes from latest CR - Replaced custom event with load event - Removed the custom event dispatch --- ui/media/js/dnd.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ui/media/js/dnd.js b/ui/media/js/dnd.js index 3732db19..16d17c29 100644 --- a/ui/media/js/dnd.js +++ b/ui/media/js/dnd.js @@ -326,13 +326,12 @@ function restoreTaskToUI(task, fieldsToSkip) { } else if (task.reqBody.init_image !== undefined) { // listen for inpainter loading event, which happens AFTER the main image loads (which reloads the inpainter) - document.addEventListener('imagePainterLoad', function() { + initImagePreview.addEventListener('load', function() { if (Boolean(task.reqBody.mask)) { imageInpainter.setImg(task.reqBody.mask) } }, { once: true }) initImagePreview.src = task.reqBody.init_image - initImagePreview.dispatchEvent(new Event("load")) } } function readUI() { From 813edec8087a1c91062fe634f985ca7ea4584fd8 Mon Sep 17 00:00:00 2001 From: patriceac <48073125+patriceac@users.noreply.github.com> Date: Thu, 29 Dec 2022 09:43:12 -0800 Subject: [PATCH 6/6] Removing one more unnecessary custom event --- ui/media/js/main.js | 1 - 1 file changed, 1 deletion(-) diff --git a/ui/media/js/main.js b/ui/media/js/main.js index b8483a92..07bd2e5f 100644 --- a/ui/media/js/main.js +++ b/ui/media/js/main.js @@ -1373,7 +1373,6 @@ function img2imgLoad() { initImageSizeBox.textContent = initImagePreview.naturalWidth + " x " + initImagePreview.naturalHeight imageEditor.setImage(this.src, initImagePreview.naturalWidth, initImagePreview.naturalHeight) imageInpainter.setImage(this.src, parseInt(widthField.value), parseInt(heightField.value)) - document.dispatchEvent(new Event("imagePainterLoad")) } function img2imgUnload() {