Skip to content

Commit

Permalink
fix txt_fullfn
Browse files Browse the repository at this point in the history
  • Loading branch information
vladmandic committed May 8, 2023
1 parent 68b9b44 commit 4d9fab4
Show file tree
Hide file tree
Showing 26 changed files with 1,320 additions and 1,297 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ __pycache__
/webui-user.bat
/webui-user.sh
/javascript/themes.json
node_modules
pnpm-lock.yaml
package-lock.json
venv

# all models and temp files
Expand Down
2 changes: 1 addition & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Stuff to be added...
Stuff to be investigated...

- Torch Compile
- `Torch-DirectML`
- TXT2IMG: <https://github.com/vladmandic/automatic/discussions/814>
- `TensorRT`
- [Temporal Weighing](https://github.com/comfyanonymous/ComfyUI/discussions/473)

Expand Down
20 changes: 20 additions & 0 deletions javascript/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"globals": {},
"env": {
"browser": true,
"commonjs": false,
"node": false,
"jquery": false,
"es2020": true
},
"parserOptions": { "ecmaVersion": 2020 },
"plugins": [],
"extends": ["eslint:recommended", "airbnb-base"],
"rules": {
"max-len": [1, 220, 3],
"camelcase":"off",
"no-unused-vars":"off",
"no-plusplus":"off",
"no-param-reassign":"off"
}
}
183 changes: 87 additions & 96 deletions javascript/aspectRatioOverlay.js
Original file line number Diff line number Diff line change
@@ -1,116 +1,107 @@

let currentWidth = null;
let currentHeight = null;
let arFrameTimeout = setTimeout(function(){},0);

function dimensionChange(e, is_width, is_height){

if(is_width){
currentWidth = e.target.value*1.0
}
if(is_height){
currentHeight = e.target.value*1.0
}

var inImg2img = gradioApp().querySelector("#tab_img2img").style.display == "block";

if(!inImg2img){
return;
}

var targetElement = null;

var tabIndex = get_tab_index('mode_img2img')
if(tabIndex == 0){ // img2img
targetElement = gradioApp().querySelector('#img2img_image div[data-testid=image] img');
} else if(tabIndex == 1){ //Sketch
targetElement = gradioApp().querySelector('#img2img_sketch div[data-testid=image] img');
} else if(tabIndex == 2){ // Inpaint
targetElement = gradioApp().querySelector('#img2maskimg div[data-testid=image] img');
} else if(tabIndex == 3){ // Inpaint sketch
targetElement = gradioApp().querySelector('#inpaint_sketch div[data-testid=image] img');
}


if(targetElement){

var arPreviewRect = gradioApp().querySelector('#imageARPreview');
if(!arPreviewRect){
arPreviewRect = document.createElement('div')
arPreviewRect.id = "imageARPreview";
gradioApp().appendChild(arPreviewRect)
}


let arFrameTimeout = setTimeout(() => {}, 0);

function dimensionChange(e, is_width, is_height) {
if (is_width) {
currentWidth = e.target.value * 1.0;
}
if (is_height) {
currentHeight = e.target.value * 1.0;
}

const inImg2img = gradioApp().querySelector('#tab_img2img').style.display == 'block';

if (!inImg2img) {
return;
}

let targetElement = null;

const tabIndex = get_tab_index('mode_img2img');
if (tabIndex == 0) { // img2img
targetElement = gradioApp().querySelector('#img2img_image div[data-testid=image] img');
} else if (tabIndex == 1) { // Sketch
targetElement = gradioApp().querySelector('#img2img_sketch div[data-testid=image] img');
} else if (tabIndex == 2) { // Inpaint
targetElement = gradioApp().querySelector('#img2maskimg div[data-testid=image] img');
} else if (tabIndex == 3) { // Inpaint sketch
targetElement = gradioApp().querySelector('#inpaint_sketch div[data-testid=image] img');
}

if (targetElement) {
let arPreviewRect = gradioApp().querySelector('#imageARPreview');
if (!arPreviewRect) {
arPreviewRect = document.createElement('div');
arPreviewRect.id = 'imageARPreview';
gradioApp().appendChild(arPreviewRect);
}

var viewportOffset = targetElement.getBoundingClientRect();
const viewportOffset = targetElement.getBoundingClientRect();

viewportscale = Math.min( targetElement.clientWidth/targetElement.naturalWidth, targetElement.clientHeight/targetElement.naturalHeight )
viewportscale = Math.min(targetElement.clientWidth / targetElement.naturalWidth, targetElement.clientHeight / targetElement.naturalHeight);

scaledx = targetElement.naturalWidth*viewportscale
scaledy = targetElement.naturalHeight*viewportscale
scaledx = targetElement.naturalWidth * viewportscale;
scaledy = targetElement.naturalHeight * viewportscale;

cleintRectTop = (viewportOffset.top+window.scrollY)
cleintRectLeft = (viewportOffset.left+window.scrollX)
cleintRectCentreY = cleintRectTop + (targetElement.clientHeight/2)
cleintRectCentreX = cleintRectLeft + (targetElement.clientWidth/2)
cleintRectTop = (viewportOffset.top + window.scrollY);
cleintRectLeft = (viewportOffset.left + window.scrollX);
cleintRectCentreY = cleintRectTop + (targetElement.clientHeight / 2);
cleintRectCentreX = cleintRectLeft + (targetElement.clientWidth / 2);

viewRectTop = cleintRectCentreY-(scaledy/2)
viewRectLeft = cleintRectCentreX-(scaledx/2)
arRectWidth = scaledx
arRectHeight = scaledy
viewRectTop = cleintRectCentreY - (scaledy / 2);
viewRectLeft = cleintRectCentreX - (scaledx / 2);
arRectWidth = scaledx;
arRectHeight = scaledy;

arscale = Math.min( arRectWidth/currentWidth, arRectHeight/currentHeight )
arscaledx = currentWidth*arscale
arscaledy = currentHeight*arscale
arscale = Math.min(arRectWidth / currentWidth, arRectHeight / currentHeight);
arscaledx = currentWidth * arscale;
arscaledy = currentHeight * arscale;

arRectTop = cleintRectCentreY-(arscaledy/2)
arRectLeft = cleintRectCentreX-(arscaledx/2)
arRectWidth = arscaledx
arRectHeight = arscaledy
arRectTop = cleintRectCentreY - (arscaledy / 2);
arRectLeft = cleintRectCentreX - (arscaledx / 2);
arRectWidth = arscaledx;
arRectHeight = arscaledy;

arPreviewRect.style.top = arRectTop+'px';
arPreviewRect.style.left = arRectLeft+'px';
arPreviewRect.style.width = arRectWidth+'px';
arPreviewRect.style.height = arRectHeight+'px';
arPreviewRect.style.top = `${arRectTop}px`;
arPreviewRect.style.left = `${arRectLeft}px`;
arPreviewRect.style.width = `${arRectWidth}px`;
arPreviewRect.style.height = `${arRectHeight}px`;

clearTimeout(arFrameTimeout);
arFrameTimeout = setTimeout(function(){
arFrameTimeout = setTimeout(() => {
arPreviewRect.style.display = 'none';
},2000);
}, 2000);

arPreviewRect.style.display = 'block';

}

}
}


onUiUpdate(function(){
var arPreviewRect = gradioApp().querySelector('#imageARPreview');
if(arPreviewRect){
arPreviewRect.style.display = 'none';
}
var tabImg2img = gradioApp().querySelector("#tab_img2img");
if (tabImg2img) {
var inImg2img = tabImg2img.style.display == "block";
if(inImg2img){
let inputs = gradioApp().querySelectorAll('input');
inputs.forEach(function(e){
var is_width = e.parentElement.id == "img2img_width"
var is_height = e.parentElement.id == "img2img_height"

if((is_width || is_height) && !e.classList.contains('scrollwatch')){
e.addEventListener('input', function(e){dimensionChange(e, is_width, is_height)} )
e.classList.add('scrollwatch')
}
if(is_width){
currentWidth = e.value*1.0
}
if(is_height){
currentHeight = e.value*1.0
}
})
onUiUpdate(() => {
const arPreviewRect = gradioApp().querySelector('#imageARPreview');
if (arPreviewRect) {
arPreviewRect.style.display = 'none';
}
const tabImg2img = gradioApp().querySelector('#tab_img2img');
if (tabImg2img) {
const inImg2img = tabImg2img.style.display == 'block';
if (inImg2img) {
const inputs = gradioApp().querySelectorAll('input');
inputs.forEach((e) => {
const is_width = e.parentElement.id == 'img2img_width';
const is_height = e.parentElement.id == 'img2img_height';

if ((is_width || is_height) && !e.classList.contains('scrollwatch')) {
e.addEventListener('input', (e) => { dimensionChange(e, is_width, is_height); });
e.classList.add('scrollwatch');
}
if (is_width) {
currentWidth = e.value * 1.0;
}
if (is_height) {
currentHeight = e.value * 1.0;
}
});
}
}
});
Loading

0 comments on commit 4d9fab4

Please sign in to comment.