Adding a new node RS Ref 2 Latent
This commit is contained in:
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -0,0 +1,72 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# Copyright 2025-2026 Raykosan (RaykoStudio)
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import node_helpers
|
||||
import comfy.utils
|
||||
|
||||
class RSRef2Latent:
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {
|
||||
"required": {
|
||||
"vae": ("VAE",),
|
||||
"image": ("IMAGE",),
|
||||
"positive": ("CONDITIONING",),
|
||||
"negative": ("CONDITIONING",),
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("CONDITIONING", "CONDITIONING", "LATENT")
|
||||
RETURN_NAMES = ("positive", "negative", "latent")
|
||||
FUNCTION = "process"
|
||||
CATEGORY = "🦊 RaykoStudio"
|
||||
DESCRIPTION = "Converts reference image to latent and adds it as reference_latents in conditioning"
|
||||
|
||||
def process(self, vae, image, positive, negative):
|
||||
if vae is None:
|
||||
raise RuntimeError("VAE is required. Please connect a VAE loader.")
|
||||
|
||||
original_height, original_width = image.shape[1], image.shape[2]
|
||||
|
||||
downscale_factor = getattr(vae, 'downscale_factor', 8)
|
||||
valid_multiple = downscale_factor * 8
|
||||
|
||||
def round_to_valid(x):
|
||||
return ((x + valid_multiple - 1) // valid_multiple) * valid_multiple
|
||||
|
||||
target_width = round_to_valid(original_width)
|
||||
target_height = round_to_valid(original_height)
|
||||
|
||||
samples = image.movedim(-1, 1)
|
||||
vae_input = comfy.utils.common_upscale(samples, target_width, target_height, "lanczos", "center")
|
||||
vae_input = vae_input.movedim(1, -1)
|
||||
|
||||
ref_latent = vae.encode(vae_input[:, :target_height, :target_width, :])
|
||||
|
||||
positive_out = node_helpers.conditioning_set_values(positive, {"reference_latents": [ref_latent]}, append=True)
|
||||
negative_out = node_helpers.conditioning_set_values(negative, {"reference_latents": [ref_latent]}, append=True)
|
||||
|
||||
latent = {"samples": ref_latent}
|
||||
|
||||
return (positive_out, negative_out, latent)
|
||||
|
||||
|
||||
NODE_CLASS_MAPPINGS = {
|
||||
"RSRef2Latent": RSRef2Latent,
|
||||
}
|
||||
|
||||
NODE_DISPLAY_NAME_MAPPINGS = {
|
||||
"RSRef2Latent": "🦊 RS Ref 2 Latent",
|
||||
}
|
||||
+1
-1
@@ -29,7 +29,7 @@ IGNORED_MODULES: Set[str] = {'__init__.py'}
|
||||
REQUIRED_MODULES: Set[str] = set()
|
||||
|
||||
PACKAGE_DISPLAY_NAME = "ComfyUI_RaykoStudio"
|
||||
__version__ = "0.28.1"
|
||||
__version__ = "0.28.2"
|
||||
|
||||
def load_modules():
|
||||
print(f"🦊 {PACKAGE_DISPLAY_NAME}: Version: {__version__}")
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+2
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "ComfyUI_RaykoStudio",
|
||||
"version": "0.28.1",
|
||||
"version": "0.28.2",
|
||||
"description": "Set of custom nodes for ComfyUI providing additional image processing capabilities",
|
||||
"author": "Raykosan",
|
||||
"license": "Apache License 2.0",
|
||||
@@ -27,6 +27,7 @@
|
||||
"Rayko_MultiLatent.py"
|
||||
"Rayko_Outpaint.py"
|
||||
"Rayko_Prompts.py"
|
||||
"Rayko_Ref2Latent.py"
|
||||
"Rayko_RGB2RGBA.py"
|
||||
"Rayko_Saturation.py"
|
||||
"Rayko_Save_Image.py"
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
[project]
|
||||
name = "ComfyUI_RaykoStudio"
|
||||
description = "Set of custom nodes for ComfyUI providing additional image processing capabilities"
|
||||
version = "0.28.1"
|
||||
version = "0.28.2"
|
||||
license = { file = "LICENSE" }
|
||||
dependencies = ["torch", "numpy", "Pillow>=10.0.0", "freetype-py>=2.5.1", "pycairo>=1.29.0", "scipy>=1.10.0"]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user