diff --git a/__init__.py b/__init__.py index c39b681..145d48b 100644 --- a/__init__.py +++ b/__init__.py @@ -1,10 +1,11 @@ -from .nodes import YARS, YARSAdv +from .nodes import YARS, YARSAdv, YARSAdvFrack -NODE_CLASS_MAPPINGS = {"YARS": YARS, "YARSAdv": YARSAdv} +NODE_CLASS_MAPPINGS = {"YARS": YARS, "YARSAdv": YARSAdv, "YARSAdvFrack": YARSAdvFrack} NODE_DISPLAY_NAME_MAPPINGS = { "YARS": "yaResolution Selector", "YARSAdv": "yaResolution Selector (Advanced)", + "YARSAdvFrack": "yaResolution Selector (Fractional)", } diff --git a/js/quickNodes.js b/js/quickNodes.js index 013faba..8f276a0 100644 --- a/js/quickNodes.js +++ b/js/quickNodes.js @@ -141,7 +141,11 @@ app.registerExtension({ name: "trop.YARS", async beforeRegisterNodeDef(nodeType, nodeData, app) { // add resolution printout - if (nodeData.name === "YARSAdv" || nodeData.name === "YARS") { + if ( + nodeData.name === "YARSAdvFrack" || + nodeData.name === "YARSAdv" || + nodeData.name === "YARS" + ) { const onExecuted = nodeType.prototype.onExecuted; nodeType.prototype.onExecuted = function (message) { const r = onExecuted?.apply?.(this, arguments); @@ -181,6 +185,7 @@ app.registerExtension({ const entries = [ { name: "yaResolution Selector", value: "YARS" }, { name: "Advanced yaResolution Selector", value: "YARSAdv" }, + { name: "Fractional yaResolution Selector", value: "YARSAdvFrack" }, ]; for (const entry of entries) { options.unshift({ diff --git a/node.tar.gz b/node.tar.gz new file mode 100644 index 0000000..962fe24 Binary files /dev/null and b/node.tar.gz differ diff --git a/nodes.py b/nodes.py index 5758e89..3c01fec 100644 --- a/nodes.py +++ b/nodes.py @@ -212,6 +212,84 @@ class YARSAdv: } +class YARSAdvFrack: + def __init__(self): + pass + + @classmethod + def INPUT_TYPES(self): + return { + "required": { + "base_resolution": ( + "INT", + { + "default": 512, + "min": 512, + "max": 8192, + "step": 128, + }, + ), + "width_ratio": ( + "FLOAT", + { + "default": 1, + "min": 0.1, + "max": 24, + "step": 0.01, + }, + ), + "height_ratio": ( + "FLOAT", + { + "default": 1, + "min": 0.1, + "max": 24, + "step": 0.01, + }, + ), + "overextend": ( + "BOOLEAN", + {"default": False, "label_on": "yes ", "label_off": "no "}, + ), + "constant_resolution": ( + "BOOLEAN", + {"default": False, "label_on": "yes ", "label_off": "no "}, + ), + }, + } + + RETURN_TYPES = ("INT", "INT") + RETURN_NAMES = ("width", "height") + FUNCTION = "calculate" + OUTPUT_NODE = False + CATEGORY = "utils" + + def calculate( + self, + base_resolution: int, + width_ratio: float, + height_ratio: float, + overextend: bool, + constant_resolution: bool, + ): + ratio: float = height_ratio / width_ratio + + if constant_resolution: + d = calculate_constant_constant_resolution(base_resolution, ratio) + else: + d = calculate_aspect_ratio(base_resolution, ratio, overextend) + + # return as dict with `ui` key to trigger onExecuted + return { + "ui": { + "width": [d.width], + "height": [d.height], + "ratio": [width_ratio / height_ratio], + }, + "result": (d.width, d.height), + } + + if __name__ == "__main__": import unittest diff --git a/pyproject.toml b/pyproject.toml index 47fa133..16f21da 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,8 +1,8 @@ [project] name = "comfyui-yaresolutionselector" description = "Freely adjust resolution and aspect ratio, maintain pixel count of StableDiffusion model, or hook it up to upscaling nodes to get that 5k 16:10 wallpaper in just few clicks." -version = "1.2.0" -license = "LICENSE" +version = "1.3.0" +license = {text = "GPL License"} [project.urls] Repository = "https://github.com/Tropfchen/ComfyUI-yaResolutionSelector"