From 02cb40b55cc18da52a0629a539a2a84ae0f0f927 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B0=D1=80=D0=BF=D0=B8=D1=87=20=D0=94=D0=BC=D0=B8?= =?UTF-8?q?=D1=82=D1=80=D0=B8=D0=B9=20=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B0?= =?UTF-8?q?=D0=BD=D0=B4=D1=80=D0=BE=D0=B2=D0=B8=D1=87?= Date: Sun, 26 Apr 2026 02:50:54 +0300 Subject: [PATCH] feat(*): add latent scale options --- modules/image_tool.py | 25 ++++++++++++++++++++----- modules/util.py | 20 +++++++++----------- 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/modules/image_tool.py b/modules/image_tool.py index 7e2ffbf..54487f9 100644 --- a/modules/image_tool.py +++ b/modules/image_tool.py @@ -1,7 +1,15 @@ from numpy import ndarray from typing import Union -from .util import get_sizes +from .util import get_latent_size, get_image_size + +SCALE_8X = "SD, Qwen (8x)" +SCALE_16X = "Flux2 (16x)" +SCALE_OPTIONS = [SCALE_8X, SCALE_16X] +SCALE_FACTOR_MAP = { + SCALE_8X: 8, + SCALE_16X: 16, +} class OFOImageFit: @@ -11,7 +19,11 @@ class OFOImageFit: @classmethod def INPUT_TYPES(s): return { - "required": {"latent": ("LATENT",), "image": ("IMAGE",)}, + "required": { + "latent": ("LATENT",), + "image": ("IMAGE",), + "latent_scale": (SCALE_OPTIONS,), + }, "optional": { "width_position": ( "FLOAT", @@ -76,6 +88,7 @@ class OFOImageFit: self, latent: Union[dict, ndarray], image: ndarray, + latent_scale: str, width_position: float = 0.5, height_position: float = 0.5, scale: float = 1.0, @@ -86,6 +99,7 @@ class OFOImageFit: Args: latent (np.ndarray or dict): Latent representation or dictionary containing latent samples. image (np.ndarray): Input image to be resized and padded. + latent_scale (str): Latent scale factor option. "SD, Qwen (8x)" or "Flux2 (16x)". width_position (float, optional): Horizontal position where the image will be placed within the latent space. Defaults to 0.5. height_position (float, optional): Vertical position where the image will be placed within the latent space. Defaults to 0.5. scale (float, optional): Scaling factor applied to the image before resizing. Defaults to 1.0. @@ -93,9 +107,10 @@ 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) + scale_factor = SCALE_FACTOR_MAP[latent_scale] + + latent_height, latent_width = get_latent_size(latent, scale_factor) + image_height, image_width = get_image_size(image) # get minimum scale scale_w = latent_width / image_width diff --git a/modules/util.py b/modules/util.py index 62023e1..4e70b0e 100644 --- a/modules/util.py +++ b/modules/util.py @@ -1,14 +1,12 @@ from numpy import ndarray -from typing import Union, Tuple - -# latent to pixel scale factor -SCALE = 8 +from typing import Tuple -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) - else: - # Image height, width - return (target.shape[1], target.shape[2]) +def get_latent_size(latent: dict, scale_factor: int = 8) -> Tuple[int, int]: + """Convert latent dimensions to pixel dimensions using scale factor.""" + return (latent["samples"].shape[2] * scale_factor, latent["samples"].shape[3] * scale_factor) + + +def get_image_size(image: ndarray) -> Tuple[int, int]: + """Get image height and width from numpy array.""" + return (image.shape[1], image.shape[2])