| import math
|
| import torch
|
| import comfy.utils
|
|
|
| class WanNativeResize_Dolphin:
|
| @classmethod
|
| def INPUT_TYPES(cls):
|
| return {
|
| "required": {
|
| "image": ("IMAGE",),
|
| "target_model": (["480P (832x480)", "720P (1280x720)", "1080P (1920x1080)"], {"default": "720P (1280x720)"}),
|
| "upscale_method": (["nearest-exact", "bilinear", "area", "bicubic", "lanczos"], {"default": "lanczos"}),
|
| "alignment": ("INT", {"default": 16, "min": 8, "max": 64, "step": 8}),
|
| }
|
| }
|
|
|
| RETURN_TYPES = ("IMAGE", "INT", "INT")
|
| RETURN_NAMES = ("IMAGE", "width", "height")
|
| FUNCTION = "resize_for_wan"
|
| CATEGORY = "Dolphin Node/Wan Video"
|
|
|
| def resize_for_wan(self, image, target_model, upscale_method, alignment):
|
|
|
| b, h, w, c = image.shape
|
|
|
|
|
| if "480P" in target_model:
|
| target_area = 832 * 480
|
| elif "720P" in target_model:
|
| target_area = 1280 * 720
|
| else:
|
| target_area = 1920 * 1080
|
|
|
|
|
| aspect_ratio = w / h
|
| new_h = math.sqrt(target_area / aspect_ratio)
|
| new_w = new_h * aspect_ratio
|
|
|
|
|
| new_w = int(round(new_w / alignment) * alignment)
|
| new_h = int(round(new_h / alignment) * alignment)
|
|
|
|
|
| if w == new_w and h == new_h:
|
| return (image, new_w, new_h)
|
|
|
|
|
| image = image.movedim(-1, 1)
|
|
|
|
|
| resized_image = comfy.utils.common_upscale(image, new_w, new_h, upscale_method, "disabled")
|
|
|
|
|
| resized_image = resized_image.movedim(1, -1)
|
|
|
| return (resized_image, new_w, new_h) |