From 3c596e6a4c1d85dcb1ad809c3d650600b4036ccf Mon Sep 17 00:00:00 2001 From: tim h Date: Wed, 4 Jan 2023 20:00:51 -0600 Subject: [PATCH 1/8] experimental? newer hrfix stuff --- css/index.css | 6 ++++ index.html | 33 ++++++++++++++++++---- js/index.js | 60 ++++++++++++++++++++++++++++++---------- js/ui/tool/dream.js | 12 ++++++-- pages/configuration.html | 2 +- 5 files changed, 90 insertions(+), 23 deletions(-) diff --git a/css/index.css b/css/index.css index 80fa23d..0585f43 100644 --- a/css/index.css +++ b/css/index.css @@ -644,3 +644,9 @@ select > .style-select-option:active { .button.tool.active { background-color: rgb(60, 60, 130); } + +/* Miscellaneous garbage */ + +.thirdwidth { + max-width: 33%; +} diff --git a/index.html b/index.html index ce50bf7..1315cc4 100644 --- a/index.html +++ b/index.html @@ -7,7 +7,7 @@ - + @@ -100,8 +100,31 @@
+ +
+ + + +
+
@@ -323,7 +346,7 @@ - + @@ -341,7 +364,7 @@ - + - + diff --git a/js/index.js b/js/index.js index 1424164..8b2ea19 100644 --- a/js/index.js +++ b/js/index.js @@ -111,6 +111,9 @@ var stableDiffusionData = { //firstphase_height: 0, //20230102 welp looks like the entire way HRfix is implemented has become bonkersly different hr_scale: 2.0, hr_upscaler: "None", + hr_second_pass_steps: 0, + hr_resize_x: 0, + hr_resize_y: 0, styles: [], // here's some more fields that might be useful @@ -679,6 +682,17 @@ const lockPxSlider = makeSlider( 1 ); +const hrStepsSlider = makeSlider( + "HRfix Steps", + document.getElementById("hrFixSteps"), + "hr_second_pass_steps", + 0, + localStorage.getItem("openoutpaint/settings.max-steps") || 70, + 5, + 30, + 1 +); + function changeMaskBlur() { stableDiffusionData.mask_blur = parseInt( document.getElementById("maskBlur").value @@ -691,29 +705,45 @@ function changeSeed() { localStorage.setItem("openoutpaint/seed", stableDiffusionData.seed); } +function changeHRFX() { + stableDiffusionData.hr_resize_x = + document.getElementById("hr_resize_x").value; +} + +function changeHRFY() { + stableDiffusionData.hr_resize_y = + document.getElementById("hr_resize_y").value; +} + function changeHiResFix() { stableDiffusionData.enable_hr = Boolean( document.getElementById("cbxHRFix").checked ); localStorage.setItem("openoutpaint/enable_hr", stableDiffusionData.enable_hr); - var hrfSlider = document.getElementById("hrFixScale"); - var hrfOpotions = document.getElementById("hrFixUpscaler"); - var hrfLabel = document.getElementById("hrFixLabel"); - var hrfDenoiseSlider = document.getElementById("hrDenoising"); - var hrfLockPxSlider = document.getElementById("hrFixLockPx"); + // var hrfSlider = document.getElementById("hrFixScale"); + // var hrfOpotions = document.getElementById("hrFixUpscaler"); + // var hrfLabel = document.getElementById("hrFixLabel"); + // var hrfDenoiseSlider = document.getElementById("hrDenoising"); + // var hrfLockPxSlider = document.getElementById("hrFixLockPx"); if (stableDiffusionData.enable_hr) { - hrfSlider.classList.remove("invisible"); - hrfOpotions.classList.remove("invisible"); - hrfLabel.classList.remove("invisible"); - hrfDenoiseSlider.classList.remove("invisible"); - hrfLockPxSlider.classList.remove("invisible"); + document + .querySelectorAll(".hrfix") + .forEach((el) => el.classList.remove("invisible")); + // hrfSlider.classList.remove("invisible"); + // hrfOpotions.classList.remove("invisible"); + // hrfLabel.classList.remove("invisible"); + // hrfDenoiseSlider.classList.remove("invisible"); + // hrfLockPxSlider.classList.remove("invisible"); //state.ctxmenu.keepUnmaskedBlurSliderLinebreak.classList.add("invisible"); } else { - hrfSlider.classList.add("invisible"); - hrfOpotions.classList.add("invisible"); - hrfLabel.classList.add("invisible"); - hrfDenoiseSlider.classList.add("invisible"); - hrfLockPxSlider.classList.add("invisible"); + document + .querySelectorAll(".hrfix") + .forEach((el) => el.classList.add("invisible")); + // hrfSlider.classList.add("invisible"); + // hrfOpotions.classList.add("invisible"); + // hrfLabel.classList.add("invisible"); + // hrfDenoiseSlider.classList.add("invisible"); + // hrfLockPxSlider.classList.add("invisible"); //state.ctxmenu.keepUnmaskedBlurSliderLinebreak.classList.remove("invisible"); } } diff --git a/js/ui/tool/dream.js b/js/ui/tool/dream.js index 77207c5..2d5cc58 100644 --- a/js/ui/tool/dream.js +++ b/js/ui/tool/dream.js @@ -844,8 +844,16 @@ const dream_generate_callback = async (bb, resolution, state) => { var newWidth = Math.floor(request.width / request.hr_scale); var newHeight = Math.floor(request.height / request.hr_scale); - request.width = newWidth; - request.height = newHeight; + request.hr_resize_x = stableDiffusionData.hr_resize_x; + request.hr_resize_y = stableDiffusionData.hr_resize_y; + request.width = + stableDiffusionData.hr_resize_x || stableDiffusionData.hr_resize_y > 0 + ? request.width + : newWidth; + request.height = + stableDiffusionData.hr_resize_x || stableDiffusionData.hr_resize_y > 0 + ? request.height + : newHeight; //in webUI if _either_ x or y is > 0 then their values are used over scale as per https://github.com/AUTOMATIC1111/stable-diffusion-webui/commit/81490780949fffed77493b4bd741e96ec737fe27#diff-ddc07d50fa3b043925b1e831b1373976798d62c9f5c11fcb16c6c830bd3857cdR104 } // For compatibility with the old HRFix API diff --git a/pages/configuration.html b/pages/configuration.html index 5e53994..d8f0935 100644 --- a/pages/configuration.html +++ b/pages/configuration.html @@ -7,7 +7,7 @@ - + From 898cd35f621b1e740881a84bcaf3655a76bd17a7 Mon Sep 17 00:00:00 2001 From: zero01101 Date: Thu, 5 Jan 2023 02:09:53 +0000 Subject: [PATCH 2/8] Fixed resource hashes --- index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index 1315cc4..da484f3 100644 --- a/index.html +++ b/index.html @@ -346,7 +346,7 @@ - + @@ -375,7 +375,7 @@ From b45ce1aeba12e229361ac85d41cd0848d811c608 Mon Sep 17 00:00:00 2001 From: tim h Date: Wed, 4 Jan 2023 23:27:02 -0600 Subject: [PATCH 3/8] WIP - parity with square vs non- in/output HRfix res --- index.html | 27 ++++++--------------------- js/index.js | 29 +++++++++++++++++------------ js/ui/tool/dream.js | 20 ++++++++++---------- 3 files changed, 33 insertions(+), 43 deletions(-) diff --git a/index.html b/index.html index da484f3..ec2c965 100644 --- a/index.html +++ b/index.html @@ -100,28 +100,13 @@
- + +
- - - -
diff --git a/js/index.js b/js/index.js index 8b2ea19..5942bd3 100644 --- a/js/index.js +++ b/js/index.js @@ -114,6 +114,7 @@ var stableDiffusionData = { hr_second_pass_steps: 0, hr_resize_x: 0, hr_resize_y: 0, + hr_square_aspect: false, styles: [], // here's some more fields that might be useful @@ -729,25 +730,19 @@ function changeHiResFix() { document .querySelectorAll(".hrfix") .forEach((el) => el.classList.remove("invisible")); - // hrfSlider.classList.remove("invisible"); - // hrfOpotions.classList.remove("invisible"); - // hrfLabel.classList.remove("invisible"); - // hrfDenoiseSlider.classList.remove("invisible"); - // hrfLockPxSlider.classList.remove("invisible"); - //state.ctxmenu.keepUnmaskedBlurSliderLinebreak.classList.add("invisible"); } else { document .querySelectorAll(".hrfix") .forEach((el) => el.classList.add("invisible")); - // hrfSlider.classList.add("invisible"); - // hrfOpotions.classList.add("invisible"); - // hrfLabel.classList.add("invisible"); - // hrfDenoiseSlider.classList.add("invisible"); - // hrfLockPxSlider.classList.add("invisible"); - //state.ctxmenu.keepUnmaskedBlurSliderLinebreak.classList.remove("invisible"); } } +function changeHiResSquare() { + stableDiffusionData.hr_square_aspect = Boolean( + document.getElementById("cbxHRFSquare").checked + ); +} + function changeRestoreFaces() { stableDiffusionData.restore_faces = Boolean( document.getElementById("cbxRestoreFaces").checked @@ -845,7 +840,17 @@ async function getUpscalers() { .split(",") .map((v) => v.trim()); // need "None" for stupid hrfix changes razza frazza const upscalers = upscalersPlusNone.filter((v) => v !== "None"); // converting the result to a list of upscalers + // upscalersPlusNone.push([ + // "Latent", + // "Latent (antialiased)", + // "Latent (bicubic)", + // "Latent (bicubic, antialiased)", + // "Latent (nearest)", + // ]); upscalersPlusNone.push("Latent"); + upscalersPlusNone.push("Latent (antialiased)"); + upscalersPlusNone.push("Latent (bicubic)"); + upscalersPlusNone.push("Latent (bicubic, antialiased)"); upscalersPlusNone.push("Latent (nearest)"); // GRUMBLE GRUMBLE upscalerAutoComplete.options = upscalers.map((u) => { diff --git a/js/ui/tool/dream.js b/js/ui/tool/dream.js index 2d5cc58..9ef6706 100644 --- a/js/ui/tool/dream.js +++ b/js/ui/tool/dream.js @@ -844,20 +844,20 @@ const dream_generate_callback = async (bb, resolution, state) => { var newWidth = Math.floor(request.width / request.hr_scale); var newHeight = Math.floor(request.height / request.hr_scale); - request.hr_resize_x = stableDiffusionData.hr_resize_x; - request.hr_resize_y = stableDiffusionData.hr_resize_y; - request.width = - stableDiffusionData.hr_resize_x || stableDiffusionData.hr_resize_y > 0 - ? request.width - : newWidth; - request.height = - stableDiffusionData.hr_resize_x || stableDiffusionData.hr_resize_y > 0 - ? request.height - : newHeight; //in webUI if _either_ x or y is > 0 then their values are used over scale as per https://github.com/AUTOMATIC1111/stable-diffusion-webui/commit/81490780949fffed77493b4bd741e96ec737fe27#diff-ddc07d50fa3b043925b1e831b1373976798d62c9f5c11fcb16c6c830bd3857cdR104 + if (stableDiffusionData.hr_square_aspect) { + larger = newWidth > newHeight ? newWidth : newHeight; + newWidth = larger; + newHeight = larger; + } + request.hr_resize_x = request.width; + request.hr_resize_y = request.height; // screw the scale, damn the man, setting specified output dimensions overrides it anyway, who needs the thing, i need to revisit like all the hrfix code now though because i don't know if NOT lying to it is even worthwhile anymore + request.width = newWidth; + request.height = newHeight; } // For compatibility with the old HRFix API if (global.isOldHRFix && request.enable_hr) { + // For compatibility with the old HRFix API request.firstphase_width = request.width / 2; request.firstphase_height = request.height / 2; } From ee8166a387a1b2b0fb51ed5e9dd046b773938940 Mon Sep 17 00:00:00 2001 From: zero01101 Date: Thu, 5 Jan 2023 05:27:30 +0000 Subject: [PATCH 4/8] Fixed resource hashes --- index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index ec2c965..64c2c7c 100644 --- a/index.html +++ b/index.html @@ -349,7 +349,7 @@ - + - + From bb815d62f914659e07090c2920ab997ac64cd53f Mon Sep 17 00:00:00 2001 From: tim h Date: Thu, 5 Jan 2023 17:42:50 -0600 Subject: [PATCH 5/8] option to enforce square firstpass aspect ratio --- index.html | 14 ++++---- js/index.js | 3 +- js/ui/tool/dream.js | 69 +++++++++++++++++++++++++--------------- pages/configuration.html | 10 ++++-- 4 files changed, 60 insertions(+), 36 deletions(-) diff --git a/index.html b/index.html index 64c2c7c..16629da 100644 --- a/index.html +++ b/index.html @@ -98,14 +98,16 @@ step="1" />
- +
- +
@@ -331,7 +333,7 @@ - + @@ -349,7 +351,7 @@ - + - + diff --git a/js/index.js b/js/index.js index 5942bd3..7f341d4 100644 --- a/js/index.js +++ b/js/index.js @@ -165,6 +165,7 @@ function startup() { changeSmoothRendering(); changeSeed(); changeHiResFix(); + changeHiResSquare(); changeRestoreFaces(); changeSyncCursorSize(); } @@ -690,7 +691,7 @@ const hrStepsSlider = makeSlider( 0, localStorage.getItem("openoutpaint/settings.max-steps") || 70, 5, - 30, + 0, 1 ); diff --git a/js/ui/tool/dream.js b/js/ui/tool/dream.js index 9ef6706..af9caed 100644 --- a/js/ui/tool/dream.js +++ b/js/ui/tool/dream.js @@ -156,6 +156,7 @@ const _dream = async (endpoint, request) => { generating(false); } var responseSubdata = JSON.parse(data.info); + console.debug(responseSubdata); var returnData = { images: data.images, seeds: responseSubdata.all_seeds, @@ -815,44 +816,60 @@ const dream_generate_callback = async (bb, resolution, state) => { // Use txt2img if canvas is blank if (isCanvasBlank(0, 0, bb.w, bb.h, visibleCanvas)) { - if ( - !global.isOldHRFix && - request.enable_hr && - localStorage.getItem("openoutpaint/settings.hrfix-liar") == "true" - ) { + if (!global.isOldHRFix && request.enable_hr) { /** * try and make the new HRfix method useful for our purposes - * since it now returns an image that's been upscaled x the hr_scale parameter, - * we cheekily lie to SD and tell it that the original dimensions are _divided_ - * by the scale factor so it returns something about the same size as we wanted initially */ - // ok so instead, only do that if stableDiffusionData.hr_fix_lock_px > 0 - if (stableDiffusionData.hr_fix_lock_px > 0) { + //laziness convenience + let lockpx = stableDiffusionData.hr_fix_lock_px; + var divW = Math.floor(request.width / request.hr_scale); + var divH = Math.floor(request.height / request.hr_scale); + if (lockpx > 0) { // find the appropriate scale factor for hrfix var widthFactor = - request.width / stableDiffusionData.hr_fix_lock_px <= 4 - ? request.width / stableDiffusionData.hr_fix_lock_px - : 4; + request.width / lockpx <= 4 ? request.width / lockpx : 4; var heightFactor = - request.height / stableDiffusionData.hr_fix_lock_px <= 4 - ? request.height / stableDiffusionData.hr_fix_lock_px - : 4; + request.height / lockpx <= 4 ? request.height / lockpx : 4; var factor = heightFactor > widthFactor ? heightFactor : widthFactor; request.hr_scale = hrFixScaleSlider.value = factor < 1 ? 1 : factor; } - var newWidth = Math.floor(request.width / request.hr_scale); - var newHeight = Math.floor(request.height / request.hr_scale); - if (stableDiffusionData.hr_square_aspect) { - larger = newWidth > newHeight ? newWidth : newHeight; - newWidth = larger; - newHeight = larger; + if (localStorage.getItem("openoutpaint/settings.hrfix-liar") == "true") { + /** + * since it now returns an image that's been upscaled x the hr_scale parameter, + * we cheekily lie to SD and tell it that the original dimensions are _divided_ + * by the scale factor so it returns something about the same size as we wanted initially + */ + var firstpassWidth = divW; + var firstpassHeight = divH; // liar's firstpass output resolution + var desiredWidth = request.width; + var desiredHeight = request.height; // truthful desired output resolution + } else { + // use scale normally, dump supersampled image into undersized reticle + var desiredWidth = request.width * request.hr_scale; + var desiredHeight = request.height * request.hr_scale; //desired 2nd-pass output resolution + var firstpassWidth = request.width; + var firstpassHeight = request.height; } - request.hr_resize_x = request.width; - request.hr_resize_y = request.height; // screw the scale, damn the man, setting specified output dimensions overrides it anyway, who needs the thing, i need to revisit like all the hrfix code now though because i don't know if NOT lying to it is even worthwhile anymore - request.width = newWidth; - request.height = newHeight; + + // ensure firstpass "resolution" complies with lockpx + if (lockpx > 0) { + //sigh repeated code + // scale down by hr_scale? + firstpassWidth = divW < lockpx ? divW : lockpx; + firstpassHeight = divH < lockpx ? divH : lockpx; + } + + if (stableDiffusionData.hr_square_aspect) { + larger = + firstpassWidth > firstpassHeight ? firstpassWidth : firstpassHeight; + firstpassWidth = firstpassHeight = larger; + } + request.width = firstpassWidth; + request.height = firstpassHeight; + request.hr_resize_x = desiredWidth; + request.hr_resize_y = desiredHeight; } // For compatibility with the old HRFix API diff --git a/pages/configuration.html b/pages/configuration.html index d8f0935..ac40172 100644 --- a/pages/configuration.html +++ b/pages/configuration.html @@ -84,11 +84,12 @@ step="0.1" value="30.0" /> + +
-

Refresh the page to apply settings.

- + @@ -362,7 +362,7 @@ From 16ad7a550da66a6544262eeb7dc2f45415af701e Mon Sep 17 00:00:00 2001 From: tim h Date: Fri, 6 Jan 2023 12:49:15 -0600 Subject: [PATCH 7/8] think this was out-of-order and causing math problems with resolutions but i could be an idiot --- js/ui/tool/dream.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/js/ui/tool/dream.js b/js/ui/tool/dream.js index af9caed..7760de4 100644 --- a/js/ui/tool/dream.js +++ b/js/ui/tool/dream.js @@ -820,13 +820,10 @@ const dream_generate_callback = async (bb, resolution, state) => { /** * try and make the new HRfix method useful for our purposes */ - - //laziness convenience + // laziness convenience let lockpx = stableDiffusionData.hr_fix_lock_px; - var divW = Math.floor(request.width / request.hr_scale); - var divH = Math.floor(request.height / request.hr_scale); if (lockpx > 0) { - // find the appropriate scale factor for hrfix + // find the most appropriate scale factor for hrfix var widthFactor = request.width / lockpx <= 4 ? request.width / lockpx : 4; var heightFactor = @@ -834,6 +831,9 @@ const dream_generate_callback = async (bb, resolution, state) => { var factor = heightFactor > widthFactor ? heightFactor : widthFactor; request.hr_scale = hrFixScaleSlider.value = factor < 1 ? 1 : factor; } + // moar laziness convenience + var divW = Math.floor(request.width / request.hr_scale); + var divH = Math.floor(request.height / request.hr_scale); if (localStorage.getItem("openoutpaint/settings.hrfix-liar") == "true") { /** @@ -855,8 +855,7 @@ const dream_generate_callback = async (bb, resolution, state) => { // ensure firstpass "resolution" complies with lockpx if (lockpx > 0) { - //sigh repeated code - // scale down by hr_scale? + //sigh repeated loop firstpassWidth = divW < lockpx ? divW : lockpx; firstpassHeight = divH < lockpx ? divH : lockpx; } From 53c358809abd790c8dd9e35d203e59218f764400 Mon Sep 17 00:00:00 2001 From: zero01101 Date: Fri, 6 Jan 2023 18:49:43 +0000 Subject: [PATCH 8/8] Fixed resource hashes --- index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.html b/index.html index 44e72e3..7d6ae00 100644 --- a/index.html +++ b/index.html @@ -365,7 +365,7 @@ src="js/ui/tool/generic.js?v=2bcd36d" type="text/javascript"> - +