Enforce min_res guarantee after nearest-multiple rounding
Nearest-multiple rounding could drop a dimension below min_res in min-res mode (e.g. min_res=1100, multiple_of=256 -> 1024); bump such dimensions to the next multiple instead. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
df2f96303a
commit
499e5a0078
@@ -245,6 +245,15 @@ class ConstrainResolution(io.ComfyNode):
|
||||
final_width = ConstrainResolution.round_to_multiple(int(new_width), multiple_of)
|
||||
final_height = ConstrainResolution.round_to_multiple(int(new_height), multiple_of)
|
||||
|
||||
# Nearest-multiple rounding can drop a dimension back below min_res
|
||||
# (e.g. min_res=1100, multiple_of=256 -> 1024). In min-res mode, bump
|
||||
# such a dimension up to the next multiple so the guarantee holds.
|
||||
if constraint_mode == ConstraintMode.MIN_RES.value:
|
||||
if final_width < min_res:
|
||||
final_width = math.ceil(min_res / multiple_of) * multiple_of
|
||||
if final_height < min_res:
|
||||
final_height = math.ceil(min_res / multiple_of) * multiple_of
|
||||
|
||||
# 4. In strict mode, rounding can exceed max_res (e.g. round_to_multiple(2160, 32) = 2176).
|
||||
# Clamp to the largest valid multiple of multiple_of that is <= max_res.
|
||||
if constraint_mode == ConstraintMode.MAX_RES_STRICT.value:
|
||||
|
||||
@@ -84,6 +84,17 @@ class TestMinRes:
|
||||
# The short dimension should be at least min_res
|
||||
assert min(w, h) >= 704
|
||||
|
||||
def test_rounding_never_drops_below_min_res(self):
|
||||
"""Nearest-multiple rounding must not violate the min_res guarantee.
|
||||
|
||||
min_res=1100 with multiple_of=256: 1100 would round to 1024 (< min_res);
|
||||
it must be bumped up to 1280 instead.
|
||||
"""
|
||||
w, h = calc(1000, 1000, 1100, 4096, 256, MIN)
|
||||
assert min(w, h) >= 1100
|
||||
assert w % 256 == 0
|
||||
assert h % 256 == 0
|
||||
|
||||
def test_min_res_normal_case(self):
|
||||
"""In MIN_RES mode with no extreme ratio, both dims should stay within normal range."""
|
||||
w, h = calc(500, 333, 704, 2048, 32, MIN)
|
||||
|
||||
Reference in New Issue
Block a user