Files
chrmc40 9fd6498ba6 Publish snapshot: v1->v2 character port + accumulated fixes
- Tag-builder: port ~1,477 v1 characters into the v2 chip format so the
  character picker shows 1,486 characters (was 9); 1,390 carry rich per-chip
  descriptions restructured from each character's own bio. Adds
  scripts/port_v1_characters_to_v2.py.
- Ideogram: rewrite caption to the real Ideogram-4 schema + broaden refusal
  detection; sampler updates.
- Pose-studio, regional-detailer, attention-couple: assorted fixes.
- Add validate_templates / test_regions / test_crop_windows scripts.
2026-06-28 20:49:04 -07:00

30 lines
1.2 KiB
Python

"""Pure crop-window remap for regional / tiled re-sampling.
Extracted from regional_detailer so the most-revised, most-regressed geometry in
the codebase (the moved-content inpaint and per-tile cond + ControlNet-hint
remap) is importable and unit-testable WITHOUT the ComfyUI runtime. torch-only,
no comfy deps — see scripts/test_crop_windows.py.
"""
from __future__ import annotations
import torch
import torch.nn.functional as F
def crop_hint_to_window(t, win, img_h, img_w, sh, sw, mode="bilinear"):
"""Resize a (...,H,W) hint to canvas, crop the detail window, resize to the
sampled crop dims — the per-crop remap the tiled upscaler does. Depth/control
hints use bilinear; region masks pass mode='nearest-exact' so a hard region
edge doesn't soften into a bleed band against the neighbouring region.
win is (cx1, cy1, cx2, cy2) in canvas pixels. Output last two dims == (sh, sw).
"""
cx1, cy1, cx2, cy2 = win
t = t.float()
align = None if mode.startswith("nearest") else False
if t.shape[-2:] != (img_h, img_w):
t = F.interpolate(t, size=(img_h, img_w), mode=mode, align_corners=align)
t = t[..., cy1:cy2, cx1:cx2]
return F.interpolate(t, size=(sh, sw), mode=mode, align_corners=align)