outpaint orbit
This commit is contained in:
@@ -335,36 +335,14 @@ def _target_size(w: int, h: int, max_area: int) -> tuple[int, int]:
|
||||
def _prep_image(pil: Image.Image, max_area: int) -> tuple[Image.Image, int, int]:
|
||||
"""
|
||||
Prepare image for ComfyUI:
|
||||
1. If area > max_area, crop from bottom if height remains >= 256.
|
||||
2. Otherwise scale (up or down) to fit area while preserving aspect.
|
||||
3. Ensure dimensions are rounded to 16.
|
||||
1. Scale (up or down) to fit area while preserving aspect.
|
||||
2. Ensure dimensions are rounded to 16.
|
||||
"""
|
||||
w, h = pil.width, pil.height
|
||||
if w * h > max_area:
|
||||
# Try to keep width and crop height from bottom
|
||||
rw = _round16(w)
|
||||
th = max_area // rw
|
||||
if th >= 256:
|
||||
rh = (th // 16) * 16
|
||||
if rh < 16: rh = 16
|
||||
|
||||
# To avoid black bars from .crop((0,0,rw,rh)) when rw > w,
|
||||
# we crop to original w first, then resize to rw.
|
||||
pil = pil.crop((0, 0, w, min(h, (rh * w) // rw)))
|
||||
pil = pil.resize((rw, rh), resample=Image.LANCZOS)
|
||||
return pil, rw, rh
|
||||
else:
|
||||
# Too wide to keep width and have decent height, scale both down
|
||||
rw, rh = _target_size(w, h, max_area)
|
||||
pil = pil.resize((rw, rh), resample=Image.LANCZOS)
|
||||
return pil, rw, rh
|
||||
else:
|
||||
# Fits or is too small: scale UP to match the max_area budget
|
||||
# (Legacy behavior that gives better model performance)
|
||||
rw, rh = _target_size(w, h, max_area)
|
||||
if rw != w or rh != h:
|
||||
pil = pil.resize((rw, rh), resample=Image.LANCZOS)
|
||||
return pil, rw, rh
|
||||
rw, rh = _target_size(w, h, max_area)
|
||||
if rw != w or rh != h:
|
||||
pil = pil.resize((rw, rh), resample=Image.LANCZOS)
|
||||
return pil, rw, rh
|
||||
|
||||
|
||||
def _comfy_upload(img_bytes: bytes, filename: str) -> str:
|
||||
@@ -1342,8 +1320,8 @@ def _invalidate_static() -> None:
|
||||
def _batch_worker(job_id: str, filenames: list, prompts: list[str], poses: list,
|
||||
seed: int, max_area: int, group_id: str | None = None,
|
||||
wireframe_ref: str | None = None, wireframe_time: float = 0.5,
|
||||
pad_top: int = 0, pad_right: int = 0,
|
||||
pad_bottom: int = 0, pad_left: int = 0, pad_fill: str = "black",
|
||||
pad_top: Any = 0, pad_right: Any = 0,
|
||||
pad_bottom: Any = 0, pad_left: Any = 0, pad_fill: str = "black",
|
||||
pad_outpaint: bool = False):
|
||||
output_dir = _load_output_dir()
|
||||
for fname in filenames:
|
||||
@@ -1384,6 +1362,8 @@ def _batch_worker(job_id: str, filenames: list, prompts: list[str], poses: list,
|
||||
cap.release()
|
||||
if ret:
|
||||
pose_guide_pil = Image.fromarray(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB))
|
||||
if any([pad_top, pad_right, pad_bottom, pad_left]):
|
||||
pose_guide_pil = _apply_manual_pad(pose_guide_pil, pad_top, pad_right, pad_bottom, pad_left, pad_fill)
|
||||
print(f"[batch] using wireframe {wireframe_ref} frame {target_frame}/{total_frames}")
|
||||
except Exception as wf_err:
|
||||
print(f"[batch] wireframe extract error: {wf_err}")
|
||||
@@ -1451,8 +1431,8 @@ def _batch_worker(job_id: str, filenames: list, prompts: list[str], poses: list,
|
||||
|
||||
def _multi_ref_worker(job_id: str, filenames: list[str], prompts: list[str], poses: list,
|
||||
seed: int, max_area: int,
|
||||
pad_top: int = 0, pad_right: int = 0,
|
||||
pad_bottom: int = 0, pad_left: int = 0,
|
||||
pad_top: Any = 0, pad_right: Any = 0,
|
||||
pad_bottom: Any = 0, pad_left: Any = 0,
|
||||
pad_fill: str = "black", pad_outpaint: bool = False):
|
||||
"""Generate one output image per prompt using filenames[0] as primary and the rest as extra refs."""
|
||||
output_dir = _load_output_dir()
|
||||
@@ -1467,9 +1447,9 @@ def _multi_ref_worker(job_id: str, filenames: list[str], prompts: list[str], pos
|
||||
jobs[job_id]["status"] = "done"
|
||||
return
|
||||
|
||||
# Apply padding to the primary image if requested
|
||||
# Apply padding to images if requested
|
||||
if any([pad_top, pad_right, pad_bottom, pad_left]):
|
||||
pils[0] = (pils[0][0], _apply_manual_pad(pils[0][1], pad_top, pad_right, pad_bottom, pad_left, pad_fill))
|
||||
pils = [(name, _apply_manual_pad(pil, pad_top, pad_right, pad_bottom, pad_left, pad_fill)) for name, pil in pils]
|
||||
|
||||
# Output group: reuse shared group if all sources belong to the same one, else new group
|
||||
source_groups = set()
|
||||
|
||||
Reference in New Issue
Block a user