From bb815d62f914659e07090c2920ab997ac64cd53f Mon Sep 17 00:00:00 2001 From: tim h Date: Thu, 5 Jan 2023 17:42:50 -0600 Subject: [PATCH] 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.