mirror of
https://git.datalinker.icu/kijai/ComfyUI-KJNodes.git
synced 2026-03-16 11:57:04 +08:00
Further fix for input selection nodes
This commit is contained in:
parent
d399bc559d
commit
9903cf078e
@ -1793,7 +1793,8 @@ Inserts a latent at the specified index into the original latent batch.
|
|||||||
|
|
||||||
class ImageBatchFilter:
|
class ImageBatchFilter:
|
||||||
|
|
||||||
RETURN_TYPES = ("IMAGE",)
|
RETURN_TYPES = ("IMAGE", "STRING",)
|
||||||
|
RETURN_NAMES = ("images", "removed_indices",)
|
||||||
FUNCTION = "filter"
|
FUNCTION = "filter"
|
||||||
CATEGORY = "KJNodes/image"
|
CATEGORY = "KJNodes/image"
|
||||||
DESCRIPTION = "Removes empty images from a batch"
|
DESCRIPTION = "Removes empty images from a batch"
|
||||||
@ -1823,6 +1824,7 @@ class ImageBatchFilter:
|
|||||||
mean_diff = color_diff.mean(dim=(1, 2, 3))
|
mean_diff = color_diff.mean(dim=(1, 2, 3))
|
||||||
|
|
||||||
empty_indices = mean_diff <= empty_threshold
|
empty_indices = mean_diff <= empty_threshold
|
||||||
|
empty_indices_string = ', '.join([str(i) for i in range(B) if empty_indices[i]])
|
||||||
|
|
||||||
if replacement_image is not None:
|
if replacement_image is not None:
|
||||||
B_rep, H_rep, W_rep, C_rep = replacement_image.shape
|
B_rep, H_rep, W_rep, C_rep = replacement_image.shape
|
||||||
@ -1831,10 +1833,10 @@ class ImageBatchFilter:
|
|||||||
replacement = common_upscale(replacement.movedim(-1, 1), W, H, "lanczos", "center").movedim(1, -1)
|
replacement = common_upscale(replacement.movedim(-1, 1), W, H, "lanczos", "center").movedim(1, -1)
|
||||||
input_images[empty_indices] = replacement[0]
|
input_images[empty_indices] = replacement[0]
|
||||||
|
|
||||||
return (input_images,)
|
return (input_images, empty_indices_string,)
|
||||||
else:
|
else:
|
||||||
non_empty_images = input_images[~empty_indices]
|
non_empty_images = input_images[~empty_indices]
|
||||||
return (non_empty_images,)
|
return (non_empty_images, empty_indices_string,)
|
||||||
|
|
||||||
class GetImagesFromBatchIndexed:
|
class GetImagesFromBatchIndexed:
|
||||||
|
|
||||||
|
|||||||
@ -17,7 +17,7 @@ app.registerExtension({
|
|||||||
this.inputs = [];
|
this.inputs = [];
|
||||||
}
|
}
|
||||||
const target_number_of_inputs = this.widgets.find(w => w.name === "inputcount")["value"];
|
const target_number_of_inputs = this.widgets.find(w => w.name === "inputcount")["value"];
|
||||||
const num_inputs = this.inputs.filter(input => input.type !== "INT").length
|
const num_inputs = this.inputs.filter(input => input.type === this.cond_type).length
|
||||||
if(target_number_of_inputs===num_inputs)return; // already set, do nothing
|
if(target_number_of_inputs===num_inputs)return; // already set, do nothing
|
||||||
|
|
||||||
if(target_number_of_inputs < num_inputs){
|
if(target_number_of_inputs < num_inputs){
|
||||||
@ -38,46 +38,51 @@ app.registerExtension({
|
|||||||
case "TransitionImagesMulti":
|
case "TransitionImagesMulti":
|
||||||
nodeType.prototype.onNodeCreated = function () {
|
nodeType.prototype.onNodeCreated = function () {
|
||||||
this._type = "IMAGE"
|
this._type = "IMAGE"
|
||||||
this.inputs_offset = nodeData.name.includes("selective")?1:0
|
|
||||||
this.addWidget("button", "Update inputs", null, () => {
|
this.addWidget("button", "Update inputs", null, () => {
|
||||||
if (!this.inputs) {
|
if (!this.inputs) {
|
||||||
this.inputs = [];
|
this.inputs = [];
|
||||||
}
|
}
|
||||||
const target_number_of_inputs = this.widgets.find(w => w.name === "inputcount")["value"];
|
const target_number_of_inputs = this.widgets.find(w => w.name === "inputcount")["value"];
|
||||||
const num_inputs = this.inputs.filter(input => input.type !== "INT").length
|
console.log("target_number_of_inputs", target_number_of_inputs)
|
||||||
|
const num_inputs = this.inputs.filter(input => input.type === this._type).length
|
||||||
|
console.log("num_inputs", num_inputs)
|
||||||
if(target_number_of_inputs===num_inputs)return; // already set, do nothing
|
if(target_number_of_inputs===num_inputs)return; // already set, do nothing
|
||||||
|
|
||||||
if(target_number_of_inputs < num_inputs){
|
if(target_number_of_inputs < num_inputs){
|
||||||
for(let i = num_inputs; i>=this.inputs_offset+target_number_of_inputs; i--)
|
const inputs_to_remove = num_inputs - target_number_of_inputs;
|
||||||
this.removeInput(i)
|
for(let i = 0; i < inputs_to_remove; i++) {
|
||||||
|
this.removeInput(this.inputs.length - 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
for(let i = num_inputs+1-this.inputs_offset; i <= target_number_of_inputs; ++i)
|
for(let i = num_inputs+1; i <= target_number_of_inputs; ++i)
|
||||||
this.addInput(`image_${i}`, this._type)
|
this.addInput(`image_${i}`, this._type)
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "MaskBatchMulti":
|
case "MaskBatchMulti":
|
||||||
nodeType.prototype.onNodeCreated = function () {
|
nodeType.prototype.onNodeCreated = function () {
|
||||||
this._type = "MASK"
|
this._type = "MASK"
|
||||||
this.inputs_offset = nodeData.name.includes("selective")?1:0
|
|
||||||
this.addWidget("button", "Update inputs", null, () => {
|
this.addWidget("button", "Update inputs", null, () => {
|
||||||
if (!this.inputs) {
|
if (!this.inputs) {
|
||||||
this.inputs = [];
|
this.inputs = [];
|
||||||
}
|
}
|
||||||
const target_number_of_inputs = this.widgets.find(w => w.name === "inputcount")["value"];
|
const target_number_of_inputs = this.widgets.find(w => w.name === "inputcount")["value"];
|
||||||
const num_inputs = this.inputs.filter(input => input.type !== "INT").length
|
const num_inputs = this.inputs.filter(input => input.type === this._type).length
|
||||||
if(target_number_of_inputs===num_inputs)return; // already set, do nothing
|
if(target_number_of_inputs===num_inputs)return; // already set, do nothing
|
||||||
|
|
||||||
if(target_number_of_inputs < num_inputs){
|
if(target_number_of_inputs < num_inputs){
|
||||||
for(let i = num_inputs; i>=this.inputs_offset+target_number_of_inputs; i--)
|
const inputs_to_remove = num_inputs - target_number_of_inputs;
|
||||||
this.removeInput(i)
|
for(let i = 0; i < inputs_to_remove; i++) {
|
||||||
|
this.removeInput(this.inputs.length - 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
for(let i = num_inputs+1-this.inputs_offset; i <= target_number_of_inputs; ++i)
|
for(let i = num_inputs+1; i <= target_number_of_inputs; ++i)
|
||||||
this.addInput(`mask_${i}`, this._type)
|
this.addInput(`mask_${i}`, this._type)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -225,21 +230,23 @@ app.registerExtension({
|
|||||||
originalOnNodeCreated.apply(this, arguments);
|
originalOnNodeCreated.apply(this, arguments);
|
||||||
|
|
||||||
this._type = "STRING";
|
this._type = "STRING";
|
||||||
this.inputs_offset = nodeData.name.includes("selective") ? 1 : 0;
|
|
||||||
this.addWidget("button", "Update inputs", null, () => {
|
this.addWidget("button", "Update inputs", null, () => {
|
||||||
if (!this.inputs) {
|
if (!this.inputs) {
|
||||||
this.inputs = [];
|
this.inputs = [];
|
||||||
}
|
}
|
||||||
const target_number_of_inputs = this.widgets.find(w => w.name === "inputcount")["value"];
|
const target_number_of_inputs = this.widgets.find(w => w.name === "inputcount")["value"];
|
||||||
const num_inputs = this.inputs.filter(input => input.type !== "INT").length
|
const num_inputs = this.inputs.filter(input => input.name && input.name.toLowerCase().includes("string_")).length
|
||||||
if (target_number_of_inputs === num_inputs) return; // already set, do nothing
|
if (target_number_of_inputs === num_inputs) return; // already set, do nothing
|
||||||
|
|
||||||
if (target_number_of_inputs < num_inputs) {
|
if(target_number_of_inputs < num_inputs){
|
||||||
for (let i = num_inputs; i >= this.inputs_offset + target_number_of_inputs; i--)
|
const inputs_to_remove = num_inputs - target_number_of_inputs;
|
||||||
this.removeInput(i);
|
for(let i = 0; i < inputs_to_remove; i++) {
|
||||||
} else {
|
this.removeInput(this.inputs.length - 1);
|
||||||
for (let i = num_inputs + 1 - this.inputs_offset; i <= target_number_of_inputs; ++i)
|
}
|
||||||
this.addInput(`string_${i}`, this._type);
|
}
|
||||||
|
else{
|
||||||
|
for(let i = num_inputs+1; i <= target_number_of_inputs; ++i)
|
||||||
|
this.addInput(`string_${i}`, this._type)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user