someone-in-the-world's picture
Skip text_encoder CPU offload in fast mode; type mode as an enum
39867e3
Raw
History Blame Contribute Delete
571 Bytes
MAX_OUTPUT_DIM = 2048
MAX_OUTPUT_DIM_FAST = 768
def compute_output_dimensions(w, h, max_dim=MAX_OUTPUT_DIM):
# Pin the long side to max_dim and scale the short side proportionally.
# We snap to the nearest multiple of 8 (not floor) to minimise aspect ratio
# distortion: floor always undershoots, whereas rounding keeps the error
# within ±4px, which halves the worst-case ratio deviation.
if w > h:
nw = max_dim
nh = round(nw * h / w / 8) * 8
else:
nh = max_dim
nw = round(nh * w / h / 8) * 8
return nw, nh