commit feadc7a4f0106d756b633723f751e7b520a3fe98 Author: Totori <290Livermorium@gmail.com> Date: Wed Aug 28 00:40:26 2024 +0900 initial commit diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..560a9bf --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2023 Alex "mcmonkey" Goodwin + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.MD b/README.MD new file mode 100644 index 0000000..2a51c63 --- /dev/null +++ b/README.MD @@ -0,0 +1,5 @@ +# ComfyUI-LoadImage-Advanced + +LoadImageとVae Encode、Upscaleを統合しただけのノードです + +![sample](./images/sample.png) diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..054eff3 --- /dev/null +++ b/__init__.py @@ -0,0 +1,13 @@ +from .load_image_advanced import LoadImageUpscale, LoadImageUpscaleBy + +NODE_CLASS_MAPPINGS = { + "LoadImageUpscaleBy": LoadImageUpscaleBy, + "LoadImageUpscale": LoadImageUpscale, +} + +NODE_DISPLAY_NAME_MAPPINGS = { + "LoadImageUpscaleBy": "Load Image Upscale By", + "LoadImageUpscale": "Load Image Upscale", +} + +__all__ = ['NODE_CLASS_MAPPINGS', 'NODE_DISPLAY_NAME_MAPPINGS'] diff --git a/__pycache__/__init__.cpython-310.pyc b/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000..fd92ded Binary files /dev/null and b/__pycache__/__init__.cpython-310.pyc differ diff --git a/__pycache__/load_image_advanced.cpython-310.pyc b/__pycache__/load_image_advanced.cpython-310.pyc new file mode 100644 index 0000000..07a4087 Binary files /dev/null and b/__pycache__/load_image_advanced.cpython-310.pyc differ diff --git a/images/sample.png b/images/sample.png new file mode 100644 index 0000000..4d24885 Binary files /dev/null and b/images/sample.png differ diff --git a/load_image_advanced.py b/load_image_advanced.py new file mode 100644 index 0000000..cc4acdb --- /dev/null +++ b/load_image_advanced.py @@ -0,0 +1,75 @@ +import folder_paths +import os + +from nodes import MAX_RESOLUTION, ImageScale, ImageScaleBy, LatentUpscaleBy, LoadImage, VAEEncode + + +class LoadImageUpscaleBy: + latent_upscale_methods = ["nearest-exact", "bilinear", "area", "bicubic", "bislerp"] + image_upscale_methods = ["nearest-exact", "bilinear", "area", "bicubic", "lanczos"] + + def __init__(self) -> None: + pass + + @classmethod + def INPUT_TYPES(cls): + input_dir = folder_paths.get_input_directory() + files = [f for f in os.listdir(input_dir) if os.path.isfile(os.path.join(input_dir, f))] + + return { + "required": { + "vae": ("VAE", ), + "image": (sorted(files), {"image_upload": True}), + + "image_upscale_method": (cls.image_upscale_methods,), + "image_scale_by": ("FLOAT", {"default": 1.0, "min": 0.01, "max": 8.0, "step": 0.01}), + + "latent_upscale_method": (cls.latent_upscale_methods,), + "latent_scale_by": ("FLOAT", {"default": 1.0, "min": 0.01, "max": 8.0, "step": 0.01}), + } + } + + CATEGORY = "image" + RETURN_TYPES = ("LATENT", "MASK") + FUNCTION = "load_image" + def load_image(self, image, vae, image_upscale_method, image_scale_by, latent_upscale_method, latent_scale_by): + (output_image, output_mask) = LoadImage().load_image(image) + (upscaled_image,) = ImageScaleBy().upscale(output_image, image_upscale_method, image_scale_by) if image_scale_by != 1.0 else (output_image, ) + (latent,) = VAEEncode().encode(vae, upscaled_image) + (upscaled_latent,) = LatentUpscaleBy().upscale(latent, latent_upscale_method, latent_scale_by) if latent_scale_by != 1.0 else (latent, ) + return (upscaled_latent, output_mask) + +class LoadImageUpscale: + latent_upscale_methods = ["nearest-exact", "bilinear", "area", "bicubic", "bislerp"] + image_upscale_methods = ["nearest-exact", "bilinear", "area", "bicubic", "lanczos"] + crop_methods = ["disabled", "center"] + + def __init__(self) -> None: + pass + + @classmethod + def INPUT_TYPES(cls): + input_dir = folder_paths.get_input_directory() + files = [f for f in os.listdir(input_dir) if os.path.isfile(os.path.join(input_dir, f))] + + return { + "required": { + "vae": ("VAE", ), + "image": (sorted(files), {"image_upload": True}), + + "image_upscale_method": (cls.image_upscale_methods,), + "width": ("INT", {"default": 512, "min": 0, "max": MAX_RESOLUTION, "step": 1}), + "height": ("INT", {"default": 512, "min": 0, "max": MAX_RESOLUTION, "step": 1}), + "crop": (cls.crop_methods,), + } + } + + CATEGORY = "image" + RETURN_TYPES = ("LATENT", "MASK") + FUNCTION = "load_image" + def load_image(self, image, vae, image_upscale_method, width, height, crop): + (output_image, output_mask) = LoadImage().load_image(image) + (upscaled_image,) = ImageScale().upscale(output_image, image_upscale_method, width, height, crop) + + (latent,) = VAEEncode().encode(vae, upscaled_image) + return (latent, output_mask)