The most powerful and modular diffusion model GUI, api and backend with a graph/nodes interface. The fastest local inference engine in the world.
Added support for lanczos scaling
MoonRide3032b6b17817331
diff --git a/comfy/utils.py b/comfy/utils.pyindex 3ed32e372..4e08bcb80 100644--- a/comfy/utils.py+++ b/comfy/utils.py@@ -1,8 +1,10 @@import torch+import torchvisionimport mathimport structimport comfy.checkpoint_pickleimport safetensors.torch+from PIL import Imagedef load_torch_file(ckpt, safe_load=False, device=None):if device is None:@@ -346,6 +348,13 @@ def bislerp(samples, width, height):result = result.reshape(n, h_new, w_new, c).movedim(-1, 1)return result+def lanczos(samples, width, height):+ images = [torchvision.transforms.functional.to_pil_image(image) for image in samples]+ images = [image.resize((width, height), resample=Image.Resampling.LANCZOS) for image in images]+ images = [torchvision.transforms.functional.to_tensor(image) for image in images]+ result = torch.stack(images)+ return result+def common_upscale(samples, width, height, upscale_method, crop):if crop == "center":old_width = samples.shape[3]@@ -364,6 +373,8 @@ def common_upscale(samples, width, height, upscale_method, crop):if upscale_method == "bislerp":return bislerp(s, width, height)+ elif upscale_method == "lanczos":+ return lanczos(s, width, height)else:return torch.nn.functional.interpolate(s, size=(height, width), mode=upscale_method)diff --git a/comfy_extras/nodes_post_processing.py b/comfy_extras/nodes_post_processing.pyindex 51bdb24fa..3f651e594 100644--- a/comfy_extras/nodes_post_processing.py+++ b/comfy_extras/nodes_post_processing.py@@ -211,7 +211,7 @@ class Sharpen:return (result,)class ImageScaleToTotalPixels:- upscale_methods = ["nearest-exact", "bilinear", "area", "bicubic"]+ upscale_methods = ["nearest-exact", "bilinear", "area", "bicubic", "lanczos"]crop_methods = ["disabled", "center"]@classmethoddiff --git a/nodes.py b/nodes.pyindex 9ccf179ce..59c50a161 100644--- a/nodes.py+++ b/nodes.py@@ -1423,7 +1423,7 @@ class LoadImageMask:return Trueclass ImageScale:- upscale_methods = ["nearest-exact", "bilinear", "area", "bicubic"]+ upscale_methods = ["nearest-exact", "bilinear", "area", "bicubic", "lanczos"]crop_methods = ["disabled", "center"]@classmethod@@ -1444,7 +1444,7 @@ class ImageScale:return (s,)class ImageScaleBy:- upscale_methods = ["nearest-exact", "bilinear", "area", "bicubic"]+ upscale_methods = ["nearest-exact", "bilinear", "area", "bicubic", "lanczos"]@classmethoddef INPUT_TYPES(s):