option to enforce square firstpass aspect ratio

This commit is contained in:
tim h 2023-01-05 17:42:50 -06:00
parent ee8166a387
commit bb815d62f9
4 changed files with 60 additions and 36 deletions

View file

@ -98,14 +98,16 @@
step="1" /> step="1" />
<br /> <br />
<input type="checkbox" id="cbxHRFix" onchange="changeHiResFix()" /> <input type="checkbox" id="cbxHRFix" onchange="changeHiResFix()" />
<label for="cbxHRFix">Apply txt2img HRfix</label> <label for="cbxHRFix">Apply Txt2Img HRfix</label>
<br /> <br />
<input <input
type="checkbox" type="checkbox"
id="cbxHRFSquare" id="cbxHRFSquare"
onchange="changeHiResSquare()" onchange="changeHiResSquare()"
class="hrfix" /> class="hrfix" />
<label for="cbxHRFSquare" class="hrfix">Square Aspect</label> <label for="cbxHRFSquare" class="hrfix">
Square Firstpass Aspect
</label>
<br class="hrfix" /> <br class="hrfix" />
<div id="hrFixScale" class="hrfix"></div> <div id="hrFixScale" class="hrfix"></div>
<div id="hrFixLockPx" class="hrfix"></div> <div id="hrFixLockPx" class="hrfix"></div>
@ -331,7 +333,7 @@
<script src="js/global.js?v=3a1cde6" type="text/javascript"></script> <script src="js/global.js?v=3a1cde6" type="text/javascript"></script>
<!-- Base Libs --> <!-- Base Libs -->
<script src="js/lib/util.js?v=7f6847c" type="text/javascript"></script> <script src="js/lib/util.js?v=5838390" type="text/javascript"></script>
<script src="js/lib/events.js?v=2ab7933" type="text/javascript"></script> <script src="js/lib/events.js?v=2ab7933" type="text/javascript"></script>
<script src="js/lib/input.js?v=09298ac" type="text/javascript"></script> <script src="js/lib/input.js?v=09298ac" type="text/javascript"></script>
<script src="js/lib/layers.js?v=a1f8aea" type="text/javascript"></script> <script src="js/lib/layers.js?v=a1f8aea" type="text/javascript"></script>
@ -349,7 +351,7 @@
<!-- Content --> <!-- Content -->
<script src="js/prompt.js?v=7a1c68c" type="text/javascript"></script> <script src="js/prompt.js?v=7a1c68c" type="text/javascript"></script>
<script src="js/index.js?v=2ac15cc" type="text/javascript"></script> <script src="js/index.js?v=c6539e5" type="text/javascript"></script>
<script <script
src="js/ui/floating/history.js?v=fc92d14" src="js/ui/floating/history.js?v=fc92d14"
@ -360,10 +362,10 @@
<!-- Load Tools --> <!-- Load Tools -->
<script <script
src="js/ui/tool/generic.js?v=2bcd36d" src="js/ui/tool/generic.js?v=f1a19a4"
type="text/javascript"></script> type="text/javascript"></script>
<script src="js/ui/tool/dream.js?v=5a652c4" type="text/javascript"></script> <script src="js/ui/tool/dream.js?v=ac1cedd" type="text/javascript"></script>
<script <script
src="js/ui/tool/maskbrush.js?v=1e8a893" src="js/ui/tool/maskbrush.js?v=1e8a893"
type="text/javascript"></script> type="text/javascript"></script>

View file

@ -165,6 +165,7 @@ function startup() {
changeSmoothRendering(); changeSmoothRendering();
changeSeed(); changeSeed();
changeHiResFix(); changeHiResFix();
changeHiResSquare();
changeRestoreFaces(); changeRestoreFaces();
changeSyncCursorSize(); changeSyncCursorSize();
} }
@ -690,7 +691,7 @@ const hrStepsSlider = makeSlider(
0, 0,
localStorage.getItem("openoutpaint/settings.max-steps") || 70, localStorage.getItem("openoutpaint/settings.max-steps") || 70,
5, 5,
30, 0,
1 1
); );

View file

@ -156,6 +156,7 @@ const _dream = async (endpoint, request) => {
generating(false); generating(false);
} }
var responseSubdata = JSON.parse(data.info); var responseSubdata = JSON.parse(data.info);
console.debug(responseSubdata);
var returnData = { var returnData = {
images: data.images, images: data.images,
seeds: responseSubdata.all_seeds, seeds: responseSubdata.all_seeds,
@ -815,44 +816,60 @@ const dream_generate_callback = async (bb, resolution, state) => {
// Use txt2img if canvas is blank // Use txt2img if canvas is blank
if (isCanvasBlank(0, 0, bb.w, bb.h, visibleCanvas)) { if (isCanvasBlank(0, 0, bb.w, bb.h, visibleCanvas)) {
if ( if (!global.isOldHRFix && request.enable_hr) {
!global.isOldHRFix &&
request.enable_hr &&
localStorage.getItem("openoutpaint/settings.hrfix-liar") == "true"
) {
/** /**
* try and make the new HRfix method useful for our purposes * 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 //laziness convenience
if (stableDiffusionData.hr_fix_lock_px > 0) { 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 appropriate scale factor for hrfix
var widthFactor = var widthFactor =
request.width / stableDiffusionData.hr_fix_lock_px <= 4 request.width / lockpx <= 4 ? request.width / lockpx : 4;
? request.width / stableDiffusionData.hr_fix_lock_px
: 4;
var heightFactor = var heightFactor =
request.height / stableDiffusionData.hr_fix_lock_px <= 4 request.height / lockpx <= 4 ? request.height / lockpx : 4;
? request.height / stableDiffusionData.hr_fix_lock_px
: 4;
var factor = heightFactor > widthFactor ? heightFactor : widthFactor; var factor = heightFactor > widthFactor ? heightFactor : widthFactor;
request.hr_scale = hrFixScaleSlider.value = factor < 1 ? 1 : factor; request.hr_scale = hrFixScaleSlider.value = factor < 1 ? 1 : factor;
} }
var newWidth = Math.floor(request.width / request.hr_scale); if (localStorage.getItem("openoutpaint/settings.hrfix-liar") == "true") {
var newHeight = Math.floor(request.height / request.hr_scale); /**
if (stableDiffusionData.hr_square_aspect) { * since it now returns an image that's been upscaled x the hr_scale parameter,
larger = newWidth > newHeight ? newWidth : newHeight; * we cheekily lie to SD and tell it that the original dimensions are _divided_
newWidth = larger; * by the scale factor so it returns something about the same size as we wanted initially
newHeight = larger; */
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 // ensure firstpass "resolution" complies with lockpx
request.width = newWidth; if (lockpx > 0) {
request.height = newHeight; //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 // For compatibility with the old HRFix API

View file

@ -84,11 +84,12 @@
step="0.1" step="0.1"
value="30.0" /> value="30.0" />
</label> </label>
<!-- <p>Refresh the page to apply aabove.</p> -->
<hr />
<label style="display: flex"> <label style="display: flex">
Lie to HRfix: Lie to HRfix:
<input id="hrfix-liar" class="canvas-size-input" type="checkbox" /> <input id="hrfix-liar" class="canvas-size-input" type="checkbox" />
</label> </label>
<p>Refresh the page to apply settings.</p>
<script> <script>
const canvasWidth = document.getElementById("canvas-width"); const canvasWidth = document.getElementById("canvas-width");
@ -127,8 +128,11 @@
localStorage.getItem("openoutpaint/settings.min-cfg") || -1; localStorage.getItem("openoutpaint/settings.min-cfg") || -1;
maxCfg.value = maxCfg.value =
localStorage.getItem("openoutpaint/settings.max-cfg") || 30; localStorage.getItem("openoutpaint/settings.max-cfg") || 30;
hrfixLiar.checked = let _enable_dishonesty =
localStorage.getItem("openoutpaint/settings.hrfix-liar") || true; localStorage.getItem("openoutpaint/settings.hrfix-liar") === null
? true
: localStorage.getItem("openoutpaint/settings.hrfix-liar") === "true";
hrfixLiar.checked = _enable_dishonesty;
writeToLocalStorage(); writeToLocalStorage();