option to enforce square firstpass aspect ratio
This commit is contained in:
parent
ee8166a387
commit
bb815d62f9
4 changed files with 60 additions and 36 deletions
14
index.html
14
index.html
|
@ -98,14 +98,16 @@
|
|||
step="1" />
|
||||
<br />
|
||||
<input type="checkbox" id="cbxHRFix" onchange="changeHiResFix()" />
|
||||
<label for="cbxHRFix">Apply txt2img HRfix</label>
|
||||
<label for="cbxHRFix">Apply Txt2Img HRfix</label>
|
||||
<br />
|
||||
<input
|
||||
type="checkbox"
|
||||
id="cbxHRFSquare"
|
||||
onchange="changeHiResSquare()"
|
||||
class="hrfix" />
|
||||
<label for="cbxHRFSquare" class="hrfix">Square Aspect</label>
|
||||
<label for="cbxHRFSquare" class="hrfix">
|
||||
Square Firstpass Aspect
|
||||
</label>
|
||||
<br class="hrfix" />
|
||||
<div id="hrFixScale" class="hrfix"></div>
|
||||
<div id="hrFixLockPx" class="hrfix"></div>
|
||||
|
@ -331,7 +333,7 @@
|
|||
<script src="js/global.js?v=3a1cde6" type="text/javascript"></script>
|
||||
|
||||
<!-- 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/input.js?v=09298ac" type="text/javascript"></script>
|
||||
<script src="js/lib/layers.js?v=a1f8aea" type="text/javascript"></script>
|
||||
|
@ -349,7 +351,7 @@
|
|||
|
||||
<!-- Content -->
|
||||
<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
|
||||
src="js/ui/floating/history.js?v=fc92d14"
|
||||
|
@ -360,10 +362,10 @@
|
|||
|
||||
<!-- Load Tools -->
|
||||
<script
|
||||
src="js/ui/tool/generic.js?v=2bcd36d"
|
||||
src="js/ui/tool/generic.js?v=f1a19a4"
|
||||
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
|
||||
src="js/ui/tool/maskbrush.js?v=1e8a893"
|
||||
type="text/javascript"></script>
|
||||
|
|
|
@ -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
|
||||
);
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -84,11 +84,12 @@
|
|||
step="0.1"
|
||||
value="30.0" />
|
||||
</label>
|
||||
<!-- <p>Refresh the page to apply aabove.</p> -->
|
||||
<hr />
|
||||
<label style="display: flex">
|
||||
Lie to HRfix:
|
||||
<input id="hrfix-liar" class="canvas-size-input" type="checkbox" />
|
||||
</label>
|
||||
<p>Refresh the page to apply settings.</p>
|
||||
|
||||
<script>
|
||||
const canvasWidth = document.getElementById("canvas-width");
|
||||
|
@ -127,8 +128,11 @@
|
|||
localStorage.getItem("openoutpaint/settings.min-cfg") || -1;
|
||||
maxCfg.value =
|
||||
localStorage.getItem("openoutpaint/settings.max-cfg") || 30;
|
||||
hrfixLiar.checked =
|
||||
localStorage.getItem("openoutpaint/settings.hrfix-liar") || true;
|
||||
let _enable_dishonesty =
|
||||
localStorage.getItem("openoutpaint/settings.hrfix-liar") === null
|
||||
? true
|
||||
: localStorage.getItem("openoutpaint/settings.hrfix-liar") === "true";
|
||||
hrfixLiar.checked = _enable_dishonesty;
|
||||
|
||||
writeToLocalStorage();
|
||||
|
||||
|
|
Loading…
Reference in a new issue