diff --git a/.devtools/sethooks.ps1 b/.devtools/sethooks.ps1 new file mode 100644 index 0000000..930a120 --- /dev/null +++ b/.devtools/sethooks.ps1 @@ -0,0 +1,4 @@ +git config core.eol lf +git config core.autocrlf input + +git config core.hooksPath .githooks/windows \ No newline at end of file diff --git a/.devtools/sethooks.sh b/.devtools/sethooks.sh index 7df28b7..ddb6619 100755 --- a/.devtools/sethooks.sh +++ b/.devtools/sethooks.sh @@ -1,3 +1,3 @@ #!/usr/bin/sh -git config core.hooksPath .githooks \ No newline at end of file +git config core.hooksPath .githooks/linux \ No newline at end of file diff --git a/.devtools/updatehashes.ps1 b/.devtools/updatehashes.ps1 new file mode 100644 index 0000000..993cab6 --- /dev/null +++ b/.devtools/updatehashes.ps1 @@ -0,0 +1,27 @@ +# Updates html files with cache busting urls including file hashes. + +# Actual file processing +$htmlfiles = Get-ChildItem -Path . -Recurse -Filter "*.html" | Where {$_.FullName -notlike "*\node_modules\*"} | Resolve-path -relative +foreach ($htmlfile in $htmlfiles) { + Write-Host "[info] Processing '${htmlfile}' for cache busting..." -ForegroundColor Blue + + $resfiles = (@(Get-ChildItem -Path . -Recurse -Filter "*.css") + (Get-ChildItem -Path . -Recurse -Filter "*.js")) | Resolve-Path -relative + + if ($args[0] -eq "gitadd") { + $resfiles = (git status -s | Select-String -Pattern "[A-Z] .+") | ForEach-Object { -split $_.Line | Select-Object -Last 1 } + } + + foreach ($resfile in $resfiles) { + $resfile = $resfile -replace '\\', '/' -replace '\./', '' + # Check if resource is used in html file + if ($null -ne (Select-String -Path $htmlfile -Pattern $resfile)) { + $hash = (Get-FileHash $resfile -Algorithm SHA1).Hash + + # This is just for cache busting... + # If 7 first characters of SHA1 is okay for git, it should be more than enough for us + $hash = $hash.Substring(0, 7).ToLower() + + (Get-Content -Raw -Path $htmlfile).replace('\r\n', "\n") -replace "$resfile(\?v=[a-z0-9]+)?", "${resfile}?v=$hash" | Set-Content $htmlfile + } + } +} diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..07764a7 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text eol=lf \ No newline at end of file diff --git a/.githooks/pre-commit b/.githooks/linux/pre-commit similarity index 100% rename from .githooks/pre-commit rename to .githooks/linux/pre-commit diff --git a/.githooks/windows/pre-commit b/.githooks/windows/pre-commit new file mode 100755 index 0000000..6b35b79 --- /dev/null +++ b/.githooks/windows/pre-commit @@ -0,0 +1,9 @@ +#!/bin/sh +# +# Script to perform some basic operations to the code before committing. + +# Adds file hashes to html script imports for cache busting purposes +powershell .devtools/updatehashes.ps1 gitadd + +# Adds file to current commit +git add "**.html" \ No newline at end of file diff --git a/docs/02-sample.png b/docs/02-sample.png index 6bc24a7..d702989 100644 Binary files a/docs/02-sample.png and b/docs/02-sample.png differ diff --git a/docs/03-arbimg.png b/docs/03-arbimg.png index 3893d45..ed2e127 100644 Binary files a/docs/03-arbimg.png and b/docs/03-arbimg.png differ diff --git a/docs/04-catsonaspacestation.png b/docs/04-catsonaspacestation.png index 7cae7a9..09e6c73 100644 Binary files a/docs/04-catsonaspacestation.png and b/docs/04-catsonaspacestation.png differ diff --git a/docs/05-openOutpaintFish.png b/docs/05-openOutpaintFish.png index e03a6e8..73fa60e 100644 Binary files a/docs/05-openOutpaintFish.png and b/docs/05-openOutpaintFish.png differ diff --git a/docs/06-desert.png b/docs/06-desert.png index f44776d..27e528f 100644 Binary files a/docs/06-desert.png and b/docs/06-desert.png differ diff --git a/index.html b/index.html index 504d477..0eeeee8 100644 --- a/index.html +++ b/index.html @@ -98,9 +98,12 @@ step="1" />
- +
-
+
+ +
+
+ + +
+ +
+ + - - - -
- -
- - +
@@ -187,7 +190,7 @@
- Alpha release v0.0.12.3 + Alpha release v0.0.12.5
@@ -311,7 +314,7 @@
+ src="pages/configuration.html?v=3d710ce">
@@ -337,7 +340,7 @@ - + - + diff --git a/js/index.js b/js/index.js index 06b7285..f950f1f 100644 --- a/js/index.js +++ b/js/index.js @@ -106,8 +106,10 @@ var stableDiffusionData = { inpainting_fill: 2, enable_hr: false, restore_faces: false, - firstphase_width: 0, - firstphase_height: 0, + //firstphase_width: 0, + //firstphase_height: 0, //20230102 welp looks like the entire way HRfix is implemented has become bonkersly different + hr_scale: 2.0, + hr_upscaler: "None", styles: [], // here's some more fields that might be useful @@ -340,6 +342,12 @@ async function testHostConnection() { const response = await fetch( document.getElementById("host").value + "/sdapi/v1/options" ); + const optionsdata = await response.json(); + if (optionsdata["use_scale_latent_for_hires_fix"]) { + const message = `You are using an outdated version of A1111 webUI.\nThe HRfix options will not work until you update to at least commit ef27a18\n(https://github.com/AUTOMATIC1111/stable-diffusion-webui/commit/ef27a18b6b7cb1a8eebdc9b2e88d25baf2c2414d)\nor newer.`; + console.error(message); + alert(message); + } switch (response.status) { case 200: { setConnectionStatus("online"); @@ -551,6 +559,15 @@ const upscalerAutoComplete = createAutoComplete( document.getElementById("upscaler-ac-select") ); +const hrFixUpscalerAutoComplete = createAutoComplete( + "HRfix Upscaler", + document.getElementById("hrFixUpscaler") +); +hrFixUpscalerAutoComplete.onchange.on(({value}) => { + stableDiffusionData.hr_upscaler = value; + localStorage.setItem(`openoutpaint/hr_upscaler`, value); +}); + const resSlider = makeSlider( "Resolution", document.getElementById("resolution"), @@ -562,8 +579,6 @@ const resSlider = makeSlider( 2, (v) => { stableDiffusionData.width = stableDiffusionData.height = v; - stableDiffusionData.firstphase_width = - stableDiffusionData.firstphase_height = v / 2; toolbar.currentTool && toolbar.currentTool.redraw && @@ -620,15 +635,27 @@ makeSlider( 1 ); +// 20230102 grumble grumble makeSlider( - "HRfix Lock Px.", - document.getElementById("hrFixLock"), - "hr_fix_lock_px", + "HRfix Scale", + document.getElementById("hrFixScale"), + "hr_scale", + 1.0, + 4.0, + 0.1, + 2.0, + 0.1 +); + +makeSlider( + "HRfix Denoising", + document.getElementById("hrDenoising"), + "denoising_strength", 0.0, - 768.0, - 256.0, - 0.0, - 1.0 + 1.0, + 0.05, + 0.7, + 0.01 ); function changeMaskBlur() { @@ -648,6 +675,23 @@ function changeHiResFix() { 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"); + if (stableDiffusionData.enable_hr) { + hrfSlider.classList.remove("invisible"); + hrfOpotions.classList.remove("invisible"); + hrfLabel.classList.remove("invisible"); + hrfDenoiseSlider.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"); + //state.ctxmenu.keepUnmaskedBlurSliderLinebreak.classList.remove("invisible"); + } } function changeRestoreFaces() { @@ -742,17 +786,26 @@ async function getUpscalers() { "[index] purposefully_incorrect_data response, ignore above error" ); // result = purposefully_incorrect_data response: Invalid upscaler, needs to be on of these: None , Lanczos , Nearest , LDSR , BSRGAN , R-ESRGAN General 4xV3 , R-ESRGAN 4x+ Anime6B , ScuNET , ScuNET PSNR , SwinIR_4x - const upscalers = data.detail + const upscalersPlusNone = data.detail .split(": ")[1] .split(",") - .map((v) => v.trim()) - .filter((v) => v !== "None"); // converting the result to a list of upscalers + .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"); + upscalersPlusNone.push("Latent (nearest)"); // GRUMBLE GRUMBLE upscalerAutoComplete.options = upscalers.map((u) => { return {name: u, value: u}; }); + hrFixUpscalerAutoComplete.options = upscalersPlusNone.map((u) => { + return {name: u, value: u}; + }); upscalerAutoComplete.value = upscalers[0]; + hrFixUpscalerAutoComplete.value = + localStorage.getItem("openoutpaint/hr_upscaler") === null + ? "None" + : localStorage.getItem("openoutpaint/hr_upscaler"); } catch (e) { console.warn("[index] Failed to fetch upscalers:"); console.warn(e); @@ -1082,6 +1135,15 @@ function loadSettings() { ? true : localStorage.getItem("openoutpaint/sync_cursor_size") === "true"; + let _hrfix_scale = + localStorage.getItem("openoutpaint/hr_scale") === null + ? 2.0 + : localStorage.getItem("openoutpaint/hr_scale"); + + let _hrfix_denoising = + localStorage.getItem("openoutpaint/denoising_strength") === null + ? 0.7 + : localStorage.getItem("openoutpaint/denoising_strength"); // set the values into the UI document.getElementById("maskBlur").value = Number(_mask_blur); document.getElementById("seed").value = Number(_seed); @@ -1089,6 +1151,8 @@ function loadSettings() { document.getElementById("cbxRestoreFaces").checked = Boolean(_restore_faces); document.getElementById("cbxSyncCursorSize").checked = Boolean(_sync_cursor_size); + document.getElementById("hrFixScale").value = Number(_hrfix_scale); + document.getElementById("hrDenoising").value = Number(_hrfix_denoising); } imageCollection.element.addEventListener( diff --git a/js/ui/tool/dream.js b/js/ui/tool/dream.js index 49dd376..956464d 100644 --- a/js/ui/tool/dream.js +++ b/js/ui/tool/dream.js @@ -130,6 +130,22 @@ const _dream = async (endpoint, request) => { let data = null; try { generating = true; + if ( + endpoint == "txt2img" && + request.enable_hr && + localStorage.getItem("openoutpaint/settings.hrfix-liar") == "true" + ) { + /** + * 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 + */ + var newWidth = Math.floor(request.width / request.hr_scale); + var newHeight = Math.floor(request.height / request.hr_scale); + request.width = newWidth; + request.height = newHeight; + } const response = await fetch(apiURL, { method: "POST", headers: { @@ -1387,18 +1403,6 @@ const dreamTool = () => h: stableDiffusionData.height, }; - //hacky set non-square auto hrfix values - let hrLockPx = - localStorage.getItem("openoutpaint/hr_fix_lock_px") ?? 0; - stableDiffusionData.firstphase_height = - hrLockPx == 0 || resolution.h / 2 <= hrLockPx - ? resolution.h / 2 - : hrLockPx; - stableDiffusionData.firstphase_width = - hrLockPx == 0 || resolution.w / 2 <= hrLockPx - ? resolution.w / 2 - : hrLockPx; - if (global.connection === "online") { dream_generate_callback(bb, resolution, state); } else { @@ -1495,8 +1499,14 @@ const dreamTool = () => state.ctxmenu.keepUnmaskedBlurSlider.classList.remove( "invisible" ); + state.ctxmenu.keepUnmaskedBlurSliderLinebreak.classList.add( + "invisible" + ); } else { state.ctxmenu.keepUnmaskedBlurSlider.classList.add("invisible"); + state.ctxmenu.keepUnmaskedBlurSliderLinebreak.classList.remove( + "invisible" + ); } } ).checkbox; @@ -1514,6 +1524,12 @@ const dreamTool = () => } ).slider; + state.ctxmenu.keepUnmaskedBlurSliderLinebreak = + document.createElement("br"); + state.ctxmenu.keepUnmaskedBlurSliderLinebreak.classList.add( + "invisible" + ); + // Preserve Brushed Masks Checkbox state.ctxmenu.preserveMasksLabel = _toolbar_input.checkbox( state, @@ -1560,6 +1576,9 @@ const dreamTool = () => array.appendChild(state.ctxmenu.keepUnmaskedLabel); menu.appendChild(array); menu.appendChild(state.ctxmenu.keepUnmaskedBlurSlider); + menu.appendChild(state.ctxmenu.keepUnmaskedBlurSliderLinebreak); + menu.appendChild(state.ctxmenu.preserveMasksLabel); + menu.appendChild(document.createElement("br")); menu.appendChild(state.ctxmenu.overMaskPxLabel); menu.appendChild(state.ctxmenu.eagerGenerateCountLabel); }, diff --git a/pages/configuration.html b/pages/configuration.html index c2c8dcc..5e53994 100644 --- a/pages/configuration.html +++ b/pages/configuration.html @@ -84,6 +84,10 @@ step="0.1" value="30.0" /> +

Refresh the page to apply settings.

diff --git a/pages/embed.test.html b/pages/embed.test.html index 877e48f..1376eb6 100644 --- a/pages/embed.test.html +++ b/pages/embed.test.html @@ -8,6 +8,7 @@ diff --git a/res/fonts/OpenSans.ttf b/res/fonts/OpenSans.ttf index db43334..79a4385 100644 Binary files a/res/fonts/OpenSans.ttf and b/res/fonts/OpenSans.ttf differ