From f0bdb728f82190fd6919adc57e98ad68a05f08a7 Mon Sep 17 00:00:00 2001 From: TTPlanetPig <152850462+TTPlanetPig@users.noreply.github.com> Date: Sun, 15 Jun 2025 19:21:34 +0800 Subject: [PATCH] Add iterative upscale node --- README.md | 13 ++++++++++ TTP_toolsets.py | 68 ++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 69 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 99205ea..e244f78 100644 --- a/README.md +++ b/README.md @@ -107,6 +107,19 @@ This node merges all tiled conditions into one and prepares them for building th --- +### **7. Iterative Upscale Node** +This node crops and upscales an image multiple times. Use it together with **TTP_Expand_And_Mask** to create an infinite zoom effect. + +| Parameter | Description | +|-----------|-------------| +| **Iterations** | Number of upscale cycles. | +| **Scale Factor** | Factor used for each upscale step. | +| **Crop X/Y/Width/Height** | Optional region to crop before scaling. | + +**Example Chain**: `TTP_Expand_And_Mask → TTP_Iterative_Upscale` (repeat as needed) + +--- + ## **Examples** ### **Pixel Example (Recommended)** diff --git a/TTP_toolsets.py b/TTP_toolsets.py index aff6ec4..5191c73 100644 --- a/TTP_toolsets.py +++ b/TTP_toolsets.py @@ -1096,8 +1096,50 @@ def sample(self, noise, guider, sampler, sigmas, latent_image, speedup, enable_c return (out, out_denoised) - except Exception as e: - raise RuntimeError(f"Sampling failed: {str(e)}") + except Exception as e: + raise RuntimeError(f"Sampling failed: {str(e)}") + + +class TTP_Iterative_Upscale: + def __init__(self, *args, **kwargs): + pass + + @classmethod + def INPUT_TYPES(cls): + return { + "required": { + "image": ("IMAGE",), + "iterations": ("INT", {"default": 1, "min": 1, "max": 10, "step": 1}), + "scale_factor": ("FLOAT", {"default": 2.0, "min": 1.0, "max": 4.0, "step": 0.05}), + }, + "optional": { + "crop_x": ("INT", {"default": 0, "min": 0}), + "crop_y": ("INT", {"default": 0, "min": 0}), + "crop_width": ("INT", {"default": 0, "min": 0}), + "crop_height": ("INT", {"default": 0, "min": 0}), + } + } + + RETURN_TYPES = ("IMAGE",) + RETURN_NAMES = ("IMAGE",) + FUNCTION = "iter_upscale" + CATEGORY = "TTP/Image" + + def iter_upscale(self, image, iterations=1, scale_factor=2.0, crop_x=0, crop_y=0, crop_width=0, crop_height=0): + pil_img = tensor2pil(image) + + for _ in range(iterations): + if crop_width > 0 and crop_height > 0: + left = max(0, crop_x) + top = max(0, crop_y) + right = min(pil_img.width, crop_x + crop_width) + bottom = min(pil_img.height, crop_y + crop_height) + pil_img = pil_img.crop((left, top, right, bottom)) + + new_size = (int(pil_img.width * scale_factor), int(pil_img.height * scale_factor)) + pil_img = pil_img.resize(new_size, Image.LANCZOS) + + return (pil2tensor(pil_img),) NODE_CLASS_MAPPINGS = { "TTPlanet_Tile_Preprocessor_Simple": TTPlanet_Tile_Preprocessor_Simple, @@ -1107,11 +1149,12 @@ def sample(self, noise, guider, sampler, sigmas, latent_image, speedup, enable_c "TTP_condtobatch": TTP_condtobatch, "TTP_condsetarea_merge": TTP_condsetarea_merge, "TTP_Tile_image_size": Tile_imageSize, - "TTP_condsetarea_merge_test": TTP_condsetarea_merge_test, - "TTP_Expand_And_Mask": TTP_Expand_And_Mask, - "TTP_text_mix": TTP_text_mix, - "TeaCacheHunyuanVideoSampler": TeaCacheHunyuanVideoSampler -} + "TTP_condsetarea_merge_test": TTP_condsetarea_merge_test, + "TTP_Expand_And_Mask": TTP_Expand_And_Mask, + "TTP_Iterative_Upscale": TTP_Iterative_Upscale, + "TTP_text_mix": TTP_text_mix, + "TeaCacheHunyuanVideoSampler": TeaCacheHunyuanVideoSampler +} NODE_DISPLAY_NAME_MAPPINGS = { "TTPlanet_Tile_Preprocessor_Simple": "TTP Tile Preprocessor Simple", @@ -1121,8 +1164,9 @@ def sample(self, noise, guider, sampler, sigmas, latent_image, speedup, enable_c "TTP_condtobatch": "TTP_cond to batch", "TTP_condsetarea_merge": "TTP_condsetarea_merge", "TTP_Tile_image_size": "TTP_Tile_image_size", - "TTP_condsetarea_merge_test": "TTP_condsetarea_merge_test", - "TTP_Expand_And_Mask": "TTP_Expand_And_Mask", - "TTP_text_mix": "TTP_text_mix", - "TeaCacheHunyuanVideoSampler": "TTP_TeaCache HunyuanVideo Sampler" -} + "TTP_condsetarea_merge_test": "TTP_condsetarea_merge_test", + "TTP_Expand_And_Mask": "TTP_Expand_And_Mask", + "TTP_Iterative_Upscale": "TTP_Iterative_Upscale", + "TTP_text_mix": "TTP_text_mix", + "TeaCacheHunyuanVideoSampler": "TTP_TeaCache HunyuanVideo Sampler" +}