From 7402ccc0e5a71d3c3ea829dfb9e9bcd42844ec3e Mon Sep 17 00:00:00 2001 From: Meettya Date: Wed, 8 Jan 2025 01:49:24 +0300 Subject: [PATCH] chore(*): small code improvment Changes: - just improve code style - decrease position round to 0.001 --- modules/image_tool.py | 25 ++++++++++++++++++++----- modules/util.py | 14 +++++--------- pyproject.toml | 2 +- 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/modules/image_tool.py b/modules/image_tool.py index 332b62c..7e2ffbf 100644 --- a/modules/image_tool.py +++ b/modules/image_tool.py @@ -1,3 +1,6 @@ +from numpy import ndarray +from typing import Union + from .util import get_sizes @@ -17,7 +20,7 @@ class OFOImageFit: "min": 0.0, "max": 1.0, "step": 0.01, - "round": 0.01, + "round": 0.001, "display": "number", "lazy": True, }, @@ -29,7 +32,7 @@ class OFOImageFit: "min": 0.0, "max": 1.0, "step": 0.01, - "round": 0.01, + "round": 0.001, "display": "number", "lazy": True, }, @@ -57,13 +60,25 @@ class OFOImageFit: "INT", "INT", ) - RETURN_NAMES = ("IMAGE_WIDTH", "IMAGE_HEIGHT", "PAD_TOP", "PAD_RIGHT", "PAD_BOTTOM", "PAD_LEFT") + RETURN_NAMES = ( + "IMAGE_WIDTH", + "IMAGE_HEIGHT", + "PAD_TOP", + "PAD_RIGHT", + "PAD_BOTTOM", + "PAD_LEFT", + ) FUNCTION = "calculate" CATEGORY = "OneForOne" def calculate( - self, latent, image, width_position=0.5, height_position=0.5, scale=1.0 + self, + latent: Union[dict, ndarray], + image: ndarray, + width_position: float = 0.5, + height_position: float = 0.5, + scale: float = 1.0, ): """ Calculate new dimensions and paddings for image, based on latent and given parameters. @@ -77,7 +92,7 @@ class OFOImageFit: Returns: tuple: A tuple containing six integers representing the new width, height, top, right, bottom, and left padding values. - """ + """ # get sizes latent_height, latent_width = get_sizes(latent) image_height, image_width = get_sizes(image) diff --git a/modules/util.py b/modules/util.py index 759222b..62023e1 100644 --- a/modules/util.py +++ b/modules/util.py @@ -1,18 +1,14 @@ from numpy import ndarray from typing import Union, Tuple -scale = 8 +# latent to pixel scale factor +SCALE = 8 + def get_sizes(target: Union[dict, ndarray]) -> Tuple[int, int]: if isinstance(target, dict) and "samples" in target: # Latent height, width - return ( - target["samples"].shape[2] * scale, - target["samples"].shape[3] * scale - ) + return (target["samples"].shape[2] * SCALE, target["samples"].shape[3] * SCALE) else: # Image height, width - return ( - target.shape[1], - target.shape[2] - ) + return (target.shape[1], target.shape[2]) diff --git a/pyproject.toml b/pyproject.toml index 8d11b0a..b3edd70 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [project] name = "comfyui-oneforone" description = "Node:Image Fit Calculator" -version = "1.0.0" +version = "1.0.1" license = {file = "LICENSE"} dependencies = ["numpy"]