|
23 | 23 | "Starlight (Astra) Fast": "slf-1", |
24 | 24 | "Starlight (Astra) Creative": "slc-1", |
25 | 25 | } |
26 | | -UPSCALER_VALUES_MAP = { |
27 | | - "FullHD (1080p)": 1920, |
28 | | - "4K (2160p)": 3840, |
29 | | -} |
30 | 26 |
|
31 | 27 |
|
32 | 28 | class TopazImageEnhance(IO.ComfyNode): |
@@ -214,7 +210,7 @@ def define_schema(cls): |
214 | 210 | IO.Video.Input("video"), |
215 | 211 | IO.Boolean.Input("upscaler_enabled", default=True), |
216 | 212 | IO.Combo.Input("upscaler_model", options=list(UPSCALER_MODELS_MAP.keys())), |
217 | | - IO.Combo.Input("upscaler_resolution", options=list(UPSCALER_VALUES_MAP.keys())), |
| 213 | + IO.Combo.Input("upscaler_resolution", options=["FullHD (1080p)", "4K (2160p)"]), |
218 | 214 | IO.Combo.Input( |
219 | 215 | "upscaler_creativity", |
220 | 216 | options=["low", "middle", "high"], |
@@ -306,8 +302,33 @@ async def execute( |
306 | 302 | target_frame_rate = src_frame_rate |
307 | 303 | filters = [] |
308 | 304 | if upscaler_enabled: |
309 | | - target_width = UPSCALER_VALUES_MAP[upscaler_resolution] |
310 | | - target_height = UPSCALER_VALUES_MAP[upscaler_resolution] |
| 305 | + if "1080p" in upscaler_resolution: |
| 306 | + target_pixel_p = 1080 |
| 307 | + max_long_side = 1920 |
| 308 | + else: |
| 309 | + target_pixel_p = 2160 |
| 310 | + max_long_side = 3840 |
| 311 | + ar = src_width / src_height |
| 312 | + if src_width >= src_height: |
| 313 | + # Landscape or Square; Attempt to set height to target (e.g., 2160), calculate width |
| 314 | + target_height = target_pixel_p |
| 315 | + target_width = int(target_height * ar) |
| 316 | + # Check if width exceeds standard bounds (for ultra-wide e.g., 21:9 ARs) |
| 317 | + if target_width > max_long_side: |
| 318 | + target_width = max_long_side |
| 319 | + target_height = int(target_width / ar) |
| 320 | + else: |
| 321 | + # Portrait; Attempt to set width to target (e.g., 2160), calculate height |
| 322 | + target_width = target_pixel_p |
| 323 | + target_height = int(target_width / ar) |
| 324 | + # Check if height exceeds standard bounds |
| 325 | + if target_height > max_long_side: |
| 326 | + target_height = max_long_side |
| 327 | + target_width = int(target_height * ar) |
| 328 | + if target_width % 2 != 0: |
| 329 | + target_width += 1 |
| 330 | + if target_height % 2 != 0: |
| 331 | + target_height += 1 |
311 | 332 | filters.append( |
312 | 333 | topaz_api.VideoEnhancementFilter( |
313 | 334 | model=UPSCALER_MODELS_MAP[upscaler_model], |
|
0 commit comments