|
import comfy.utils |
|
import custom_nodes.Derfuu_Nodes.types as type |
|
import custom_nodes.Derfuu_Nodes.fields as field |
|
|
|
import math |
|
|
|
from custom_nodes.Derfuu_Nodes.tree import TREE_FUNCTIONS |
|
|
|
|
|
class Int2Float: |
|
def __init__(self): |
|
pass |
|
|
|
@classmethod |
|
def INPUT_TYPES(cls): |
|
return { |
|
"required": { |
|
"INT": (type.INT,), |
|
} |
|
} |
|
|
|
RETURN_TYPES = (type.FLOAT,) |
|
FUNCTION = "get_value" |
|
CATEGORY = TREE_FUNCTIONS |
|
|
|
def get_value(self, INT): |
|
return (float(INT),) |
|
|
|
|
|
class CeilNode: |
|
def __init__(self) -> None: |
|
pass |
|
|
|
@classmethod |
|
def INPUT_TYPES(cls): |
|
return { |
|
"required": { |
|
"FLOAT": (type.FLOAT,), |
|
} |
|
} |
|
|
|
RETURN_TYPES = (type.INT,) |
|
FUNCTION = "get_value" |
|
CATEGORY = TREE_FUNCTIONS |
|
|
|
def get_value(self, FLOAT): |
|
total = int(math.ceil(FLOAT)) |
|
return (total,) |
|
|
|
|
|
class FloorNode: |
|
def __init__(self) -> None: |
|
pass |
|
|
|
@classmethod |
|
def INPUT_TYPES(cls): |
|
return { |
|
"required": { |
|
"FLOAT": (type.FLOAT,), |
|
} |
|
} |
|
|
|
RETURN_TYPES = (type.INT,) |
|
FUNCTION = "get_value" |
|
CATEGORY = TREE_FUNCTIONS |
|
|
|
def get_value(self, FLOAT): |
|
total = int(math.floor(FLOAT)) |
|
return (total,) |
|
|
|
|
|
class Float2Tuple: |
|
def __init__(self) -> None: |
|
pass |
|
|
|
@classmethod |
|
def INPUT_TYPES(cls): |
|
return { |
|
"required": { |
|
"FLOAT_A": (type.FLOAT,), |
|
"FLOAT_B": (type.FLOAT,), |
|
"Ceil2Int": ([False, True],), |
|
} |
|
} |
|
|
|
RETURN_TYPES = (type.TUPLE,) |
|
CATEGORY = TREE_FUNCTIONS |
|
|
|
FUNCTION = 'get_tuple' |
|
|
|
def get_tuple(self, FLOAT_A=0, FLOAT_B=0, Ceil2Int="false"): |
|
if Ceil2Int == "true": |
|
FLOAT_A = math.ceil(FLOAT_A) |
|
FLOAT_B = math.ceil(FLOAT_B) |
|
return ((FLOAT_A, FLOAT_B),) |
|
|
|
|
|
class Tuple2Float: |
|
def __init__(self) -> None: |
|
pass |
|
|
|
@classmethod |
|
def INPUT_TYPES(cls): |
|
return { |
|
"required": { |
|
"TUPLE": (type.TUPLE,), |
|
} |
|
} |
|
|
|
RETURN_TYPES = (type.FLOAT, type.FLOAT,) |
|
CATEGORY = TREE_FUNCTIONS |
|
|
|
FUNCTION = 'get_tuple' |
|
|
|
def get_tuple(self, TUPLE): |
|
return (TUPLE[0], TUPLE[1],) |
|
|
|
|
|
class GetLatentSize: |
|
def __init__(self) -> None: |
|
pass |
|
|
|
@classmethod |
|
def INPUT_TYPES(cls): |
|
return { |
|
"required": { |
|
"LATENT": (type.LATENT,), |
|
"ORIGINAL_VALUES": ([False, True],), |
|
} |
|
} |
|
|
|
RETURN_TYPES = (type.TUPLE,) |
|
CATEGORY = TREE_FUNCTIONS |
|
|
|
FUNCTION = 'get_size' |
|
|
|
def get_size(self, LATENT, ORIGINAL_VALUES=False): |
|
lc = LATENT.copy() |
|
size = lc["samples"].shape[3], lc["samples"].shape[2] |
|
if ORIGINAL_VALUES == False: |
|
size = size[0] * 8, size[1] * 8 |
|
return (size,) |
|
|
|
|
|
class GetImageSize: |
|
def __init__(self) -> None: |
|
pass |
|
|
|
@classmethod |
|
def INPUT_TYPES(cls): |
|
return { |
|
"required": { |
|
"IMAGE": (type.IMAGE,), |
|
} |
|
} |
|
|
|
RETURN_TYPES = (type.TUPLE,) |
|
CATEGORY = TREE_FUNCTIONS |
|
|
|
FUNCTION = 'get_size' |
|
|
|
def get_size(self, IMAGE): |
|
samples = IMAGE.movedim(-1, 1) |
|
size = samples.shape[3], samples.shape[2] |
|
|
|
return (size,) |
|
|