mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-02-14 23:42:35 +08:00
Merge branch 'comfyanonymous:master' into feat/widgetFeedback
This commit is contained in:
commit
da3c937ecf
@ -158,7 +158,7 @@ class SplitImageWithAlpha:
|
|||||||
def split_image_with_alpha(self, image: torch.Tensor):
|
def split_image_with_alpha(self, image: torch.Tensor):
|
||||||
out_images = [i[:,:,:3] for i in image]
|
out_images = [i[:,:,:3] for i in image]
|
||||||
out_alphas = [i[:,:,3] if i.shape[2] > 3 else torch.ones_like(i[:,:,0]) for i in image]
|
out_alphas = [i[:,:,3] if i.shape[2] > 3 else torch.ones_like(i[:,:,0]) for i in image]
|
||||||
result = (torch.stack(out_images), torch.stack(out_alphas))
|
result = (torch.stack(out_images), 1.0 - torch.stack(out_alphas))
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
@ -180,7 +180,7 @@ class JoinImageWithAlpha:
|
|||||||
batch_size = min(len(image), len(alpha))
|
batch_size = min(len(image), len(alpha))
|
||||||
out_images = []
|
out_images = []
|
||||||
|
|
||||||
alpha = resize_mask(alpha, image.shape[1:])
|
alpha = 1.0 - resize_mask(alpha, image.shape[1:])
|
||||||
for i in range(batch_size):
|
for i in range(batch_size):
|
||||||
out_images.append(torch.cat((image[i][:,:,:3], alpha[i].unsqueeze(2)), dim=2))
|
out_images.append(torch.cat((image[i][:,:,:3], alpha[i].unsqueeze(2)), dim=2))
|
||||||
|
|
||||||
|
|||||||
@ -15,7 +15,7 @@ class BasicScheduler:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
RETURN_TYPES = ("SIGMAS",)
|
RETURN_TYPES = ("SIGMAS",)
|
||||||
CATEGORY = "_for_testing/custom_sampling"
|
CATEGORY = "sampling/custom_sampling"
|
||||||
|
|
||||||
FUNCTION = "get_sigmas"
|
FUNCTION = "get_sigmas"
|
||||||
|
|
||||||
@ -35,7 +35,7 @@ class KarrasScheduler:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
RETURN_TYPES = ("SIGMAS",)
|
RETURN_TYPES = ("SIGMAS",)
|
||||||
CATEGORY = "_for_testing/custom_sampling"
|
CATEGORY = "sampling/custom_sampling"
|
||||||
|
|
||||||
FUNCTION = "get_sigmas"
|
FUNCTION = "get_sigmas"
|
||||||
|
|
||||||
@ -53,7 +53,7 @@ class ExponentialScheduler:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
RETURN_TYPES = ("SIGMAS",)
|
RETURN_TYPES = ("SIGMAS",)
|
||||||
CATEGORY = "_for_testing/custom_sampling"
|
CATEGORY = "sampling/custom_sampling"
|
||||||
|
|
||||||
FUNCTION = "get_sigmas"
|
FUNCTION = "get_sigmas"
|
||||||
|
|
||||||
@ -72,7 +72,7 @@ class PolyexponentialScheduler:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
RETURN_TYPES = ("SIGMAS",)
|
RETURN_TYPES = ("SIGMAS",)
|
||||||
CATEGORY = "_for_testing/custom_sampling"
|
CATEGORY = "sampling/custom_sampling"
|
||||||
|
|
||||||
FUNCTION = "get_sigmas"
|
FUNCTION = "get_sigmas"
|
||||||
|
|
||||||
@ -91,7 +91,7 @@ class VPScheduler:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
RETURN_TYPES = ("SIGMAS",)
|
RETURN_TYPES = ("SIGMAS",)
|
||||||
CATEGORY = "_for_testing/custom_sampling"
|
CATEGORY = "sampling/custom_sampling"
|
||||||
|
|
||||||
FUNCTION = "get_sigmas"
|
FUNCTION = "get_sigmas"
|
||||||
|
|
||||||
@ -108,7 +108,7 @@ class SplitSigmas:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
RETURN_TYPES = ("SIGMAS","SIGMAS")
|
RETURN_TYPES = ("SIGMAS","SIGMAS")
|
||||||
CATEGORY = "_for_testing/custom_sampling"
|
CATEGORY = "sampling/custom_sampling"
|
||||||
|
|
||||||
FUNCTION = "get_sigmas"
|
FUNCTION = "get_sigmas"
|
||||||
|
|
||||||
@ -125,7 +125,7 @@ class KSamplerSelect:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
RETURN_TYPES = ("SAMPLER",)
|
RETURN_TYPES = ("SAMPLER",)
|
||||||
CATEGORY = "_for_testing/custom_sampling"
|
CATEGORY = "sampling/custom_sampling"
|
||||||
|
|
||||||
FUNCTION = "get_sampler"
|
FUNCTION = "get_sampler"
|
||||||
|
|
||||||
@ -144,7 +144,7 @@ class SamplerDPMPP_2M_SDE:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
RETURN_TYPES = ("SAMPLER",)
|
RETURN_TYPES = ("SAMPLER",)
|
||||||
CATEGORY = "_for_testing/custom_sampling"
|
CATEGORY = "sampling/custom_sampling"
|
||||||
|
|
||||||
FUNCTION = "get_sampler"
|
FUNCTION = "get_sampler"
|
||||||
|
|
||||||
@ -168,7 +168,7 @@ class SamplerDPMPP_SDE:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
RETURN_TYPES = ("SAMPLER",)
|
RETURN_TYPES = ("SAMPLER",)
|
||||||
CATEGORY = "_for_testing/custom_sampling"
|
CATEGORY = "sampling/custom_sampling"
|
||||||
|
|
||||||
FUNCTION = "get_sampler"
|
FUNCTION = "get_sampler"
|
||||||
|
|
||||||
@ -201,7 +201,7 @@ class SamplerCustom:
|
|||||||
|
|
||||||
FUNCTION = "sample"
|
FUNCTION = "sample"
|
||||||
|
|
||||||
CATEGORY = "_for_testing/custom_sampling"
|
CATEGORY = "sampling/custom_sampling"
|
||||||
|
|
||||||
def sample(self, model, add_noise, noise_seed, cfg, positive, negative, sampler, sigmas, latent_image):
|
def sample(self, model, add_noise, noise_seed, cfg, positive, negative, sampler, sigmas, latent_image):
|
||||||
latent = latent_image
|
latent = latent_image
|
||||||
|
|||||||
@ -200,6 +200,10 @@ app.registerExtension({
|
|||||||
for (const input of this.inputs) {
|
for (const input of this.inputs) {
|
||||||
if (input.widget && !input.widget[GET_CONFIG]) {
|
if (input.widget && !input.widget[GET_CONFIG]) {
|
||||||
input.widget[GET_CONFIG] = () => getConfig.call(this, input.widget.name);
|
input.widget[GET_CONFIG] = () => getConfig.call(this, input.widget.name);
|
||||||
|
const w = this.widgets.find((w) => w.name === input.widget.name);
|
||||||
|
if (w) {
|
||||||
|
hideWidget(this, w);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -450,6 +450,47 @@ export class ComfyApp {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function calculateGrid(w, h, n) {
|
||||||
|
let columns, rows, cellsize;
|
||||||
|
|
||||||
|
if (w > h) {
|
||||||
|
cellsize = h;
|
||||||
|
columns = Math.ceil(w / cellsize);
|
||||||
|
rows = Math.ceil(n / columns);
|
||||||
|
} else {
|
||||||
|
cellsize = w;
|
||||||
|
rows = Math.ceil(h / cellsize);
|
||||||
|
columns = Math.ceil(n / rows);
|
||||||
|
}
|
||||||
|
|
||||||
|
while (columns * rows < n) {
|
||||||
|
cellsize++;
|
||||||
|
if (w >= h) {
|
||||||
|
columns = Math.ceil(w / cellsize);
|
||||||
|
rows = Math.ceil(n / columns);
|
||||||
|
} else {
|
||||||
|
rows = Math.ceil(h / cellsize);
|
||||||
|
columns = Math.ceil(n / rows);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const cell_size = Math.min(w/columns, h/rows);
|
||||||
|
return {cell_size, columns, rows};
|
||||||
|
}
|
||||||
|
|
||||||
|
function is_all_same_aspect_ratio(imgs) {
|
||||||
|
// assume: imgs.length >= 2
|
||||||
|
let ratio = imgs[0].naturalWidth/imgs[0].naturalHeight;
|
||||||
|
|
||||||
|
for(let i=1; i<imgs.length; i++) {
|
||||||
|
let this_ratio = imgs[i].naturalWidth/imgs[i].naturalHeight;
|
||||||
|
if(ratio != this_ratio)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (this.imgs && this.imgs.length) {
|
if (this.imgs && this.imgs.length) {
|
||||||
const canvas = graph.list_of_graphcanvas[0];
|
const canvas = graph.list_of_graphcanvas[0];
|
||||||
const mouse = canvas.graph_mouse;
|
const mouse = canvas.graph_mouse;
|
||||||
@ -460,26 +501,41 @@ export class ComfyApp {
|
|||||||
this.pointerDown = null;
|
this.pointerDown = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
let w = this.imgs[0].naturalWidth;
|
|
||||||
let h = this.imgs[0].naturalHeight;
|
|
||||||
let imageIndex = this.imageIndex;
|
let imageIndex = this.imageIndex;
|
||||||
const numImages = this.imgs.length;
|
const numImages = this.imgs.length;
|
||||||
if (numImages === 1 && !imageIndex) {
|
if (numImages === 1 && !imageIndex) {
|
||||||
this.imageIndex = imageIndex = 0;
|
this.imageIndex = imageIndex = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const shiftY = getImageTop(this);
|
const top = getImageTop(this);
|
||||||
|
var shiftY = top;
|
||||||
|
|
||||||
let dw = this.size[0];
|
let dw = this.size[0];
|
||||||
let dh = this.size[1];
|
let dh = this.size[1];
|
||||||
dh -= shiftY;
|
dh -= shiftY;
|
||||||
|
|
||||||
if (imageIndex == null) {
|
if (imageIndex == null) {
|
||||||
|
var cellWidth, cellHeight, shiftX, cell_padding, cols;
|
||||||
|
|
||||||
|
const compact_mode = is_all_same_aspect_ratio(this.imgs);
|
||||||
|
if(!compact_mode) {
|
||||||
|
// use rectangle cell style and border line
|
||||||
|
cell_padding = 2;
|
||||||
|
const { cell_size, columns, rows } = calculateGrid(dw, dh, numImages);
|
||||||
|
cols = columns;
|
||||||
|
|
||||||
|
cellWidth = cell_size;
|
||||||
|
cellHeight = cell_size;
|
||||||
|
shiftX = (dw-cell_size*cols)/2;
|
||||||
|
shiftY = (dh-cell_size*rows)/2 + top;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
cell_padding = 0;
|
||||||
let best = 0;
|
let best = 0;
|
||||||
let cellWidth;
|
let w = this.imgs[0].naturalWidth;
|
||||||
let cellHeight;
|
let h = this.imgs[0].naturalHeight;
|
||||||
let cols = 0;
|
|
||||||
let shiftX = 0;
|
// compact style
|
||||||
for (let c = 1; c <= numImages; c++) {
|
for (let c = 1; c <= numImages; c++) {
|
||||||
const rows = Math.ceil(numImages / c);
|
const rows = Math.ceil(numImages / c);
|
||||||
const cW = dw / c;
|
const cW = dw / c;
|
||||||
@ -500,6 +556,7 @@ export class ComfyApp {
|
|||||||
shiftX = c * ((cW - imageW) / 2);
|
shiftX = c * ((cW - imageW) / 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let anyHovered = false;
|
let anyHovered = false;
|
||||||
this.imageRects = [];
|
this.imageRects = [];
|
||||||
@ -542,7 +599,14 @@ export class ComfyApp {
|
|||||||
let imgWidth = ratio * img.width;
|
let imgWidth = ratio * img.width;
|
||||||
let imgX = col * cellWidth + shiftX + (cellWidth - imgWidth)/2;
|
let imgX = col * cellWidth + shiftX + (cellWidth - imgWidth)/2;
|
||||||
|
|
||||||
ctx.drawImage(img, imgX, imgY, imgWidth, imgHeight);
|
ctx.drawImage(img, imgX+cell_padding, imgY+cell_padding, imgWidth-cell_padding*2, imgHeight-cell_padding*2);
|
||||||
|
if(!compact_mode) {
|
||||||
|
// rectangle cell and border line style
|
||||||
|
ctx.strokeStyle = "#8F8F8F";
|
||||||
|
ctx.lineWidth = 1;
|
||||||
|
ctx.strokeRect(x+cell_padding, y+cell_padding, cellWidth-cell_padding*2, cellHeight-cell_padding*2);
|
||||||
|
}
|
||||||
|
|
||||||
ctx.filter = "none";
|
ctx.filter = "none";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -552,6 +616,9 @@ export class ComfyApp {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Draw individual
|
// Draw individual
|
||||||
|
let w = this.imgs[imageIndex].naturalWidth;
|
||||||
|
let h = this.imgs[imageIndex].naturalHeight;
|
||||||
|
|
||||||
const scaleX = dw / w;
|
const scaleX = dw / w;
|
||||||
const scaleY = dh / h;
|
const scaleY = dh / h;
|
||||||
const scale = Math.min(scaleX, scaleY, 1);
|
const scale = Math.min(scaleX, scaleY, 1);
|
||||||
@ -594,14 +661,14 @@ export class ComfyApp {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (numImages > 1) {
|
if (numImages > 1) {
|
||||||
if (drawButton(x + w - 35, y + h - 35, 30, `${this.imageIndex + 1}/${numImages}`)) {
|
if (drawButton(dw - 40, dh + top - 40, 30, `${this.imageIndex + 1}/${numImages}`)) {
|
||||||
let i = this.imageIndex + 1 >= numImages ? 0 : this.imageIndex + 1;
|
let i = this.imageIndex + 1 >= numImages ? 0 : this.imageIndex + 1;
|
||||||
if (!this.pointerDown || !this.pointerDown.index === i) {
|
if (!this.pointerDown || !this.pointerDown.index === i) {
|
||||||
this.pointerDown = { index: i, pos: [...mouse] };
|
this.pointerDown = { index: i, pos: [...mouse] };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (drawButton(x + w - 35, y + 5, 30, `x`)) {
|
if (drawButton(dw - 40, top + 10, 30, `x`)) {
|
||||||
if (!this.pointerDown || !this.pointerDown.index === null) {
|
if (!this.pointerDown || !this.pointerDown.index === null) {
|
||||||
this.pointerDown = { index: null, pos: [...mouse] };
|
this.pointerDown = { index: null, pos: [...mouse] };
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user