AI 漫剧流水线技能完整落地:文件驱动、可校验、单镜可重做。 七阶段:基线资产 → 策划叙事 → 分镜中枢 → 配音先行 → 出图/出视频 → 缝合 → 审片归档。 - scripts/: manju.py 编排、submit_t2i/submit_i2v 提交、cleanup_comfyui 清理 - assets/comfyui-manju-cleanup/: ComfyUI 清理扩展,归属校验 fail-closed - references/: models.md 模型节点图全表、workflow/director/storyboard/pitfalls - .gitignore: 排除 __pycache__ 与运行产物
132 lines
4.3 KiB
Python
132 lines
4.3 KiB
Python
#!/usr/bin/env python3
|
|
"""xv 程序化包装素材:0 积分、零第三方依赖,纯标准库写 PNG。
|
|
|
|
生成 HUD 横/竖细光分隔 与 落版(光环 / 光束 / 星点)底图。
|
|
文字不烧进图里(避免生成模型重绘文字),后期由 ASS 叠加。
|
|
|
|
用法: python3 tools/make_overlay.py
|
|
"""
|
|
import math
|
|
import os
|
|
import random
|
|
import struct
|
|
import zlib
|
|
|
|
def _find_root():
|
|
"""工作空间根:MANJU_ROOT > cwd 向上找 config/pipeline.json > 脚本上级。"""
|
|
env = os.environ.get("MANJU_ROOT")
|
|
if env:
|
|
return os.path.abspath(os.path.expanduser(env))
|
|
d = os.getcwd()
|
|
while True:
|
|
if os.path.isfile(os.path.join(d, "config", "pipeline.json")):
|
|
return d
|
|
nd = os.path.dirname(d)
|
|
if nd == d:
|
|
break
|
|
d = nd
|
|
return os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
|
|
ROOT = _find_root()
|
|
OUT = os.path.join(ROOT, "assets", "overlay")
|
|
W, H = 720, 1280
|
|
|
|
|
|
def write_png(path, w, h, rows):
|
|
raw = b"".join(b"\x00" + r for r in rows)
|
|
|
|
def chunk(t, d):
|
|
return struct.pack(">I", len(d)) + t + d + struct.pack(">I", zlib.crc32(t + d) & 0xFFFFFFFF)
|
|
|
|
data = b"\x89PNG\r\n\x1a\n"
|
|
data += chunk(b"IHDR", struct.pack(">IIBBBBB", w, h, 8, 2, 0, 0, 0))
|
|
data += chunk(b"IDAT", zlib.compress(raw, 9))
|
|
data += chunk(b"IEND", b"")
|
|
with open(path, "wb") as f:
|
|
f.write(data)
|
|
return len(data)
|
|
|
|
|
|
def clamp(v):
|
|
return max(0, min(255, int(v)))
|
|
|
|
|
|
def outro():
|
|
"""深蓝径向底 + 三层光环 + 中心光束 + 星点,供 zoompan 缓推。"""
|
|
random.seed(20102026)
|
|
cx, cy = W * 0.5, H * 0.46
|
|
rows = []
|
|
for y in range(H):
|
|
row = bytearray()
|
|
for x in range(W):
|
|
dx, dy = (x - cx) / W, (y - cy) / H
|
|
d = math.sqrt(dx * dx + dy * dy)
|
|
# 基底:越靠中心越亮的深蓝
|
|
base = math.exp(-d * 3.1)
|
|
r = 4 + 16 * base
|
|
g = 10 + 46 * base
|
|
b = 22 + 92 * base
|
|
# 三层同心光环(高斯窄带)
|
|
for radius, strength in ((0.155, 1.0), (0.225, 0.62), (0.30, 0.30)):
|
|
ring = math.exp(-((d - radius) / 0.010) ** 2) * strength
|
|
r += 26 * ring
|
|
g += 120 * ring
|
|
b += 190 * ring
|
|
# 中心光束:竖直柔和光柱
|
|
beam = math.exp(-((x - cx) / 46.0) ** 2) * math.exp(-abs(y - cy) / 520.0)
|
|
g += 20 * beam
|
|
b += 42 * beam
|
|
# 上下压暗
|
|
fade = 1.0 - 0.55 * (abs(y / H - 0.5) * 2) ** 3
|
|
row += bytes((clamp(r * fade), clamp(g * fade), clamp(b * fade)))
|
|
rows.append(bytes(row))
|
|
# 星点(在已生成的行上补点)
|
|
pix = [bytearray(r) for r in rows]
|
|
for _ in range(230):
|
|
x, y = random.randrange(W), random.randrange(H)
|
|
a = random.uniform(0.25, 0.9)
|
|
for dy in range(-1, 2):
|
|
for dx in range(-1, 2):
|
|
xx, yy = x + dx, y + dy
|
|
if 0 <= xx < W and 0 <= yy < H:
|
|
k = a if (dx, dy) == (0, 0) else a * 0.22
|
|
i = xx * 3
|
|
pix[yy][i] = clamp(pix[yy][i] + 40 * k)
|
|
pix[yy][i + 1] = clamp(pix[yy][i + 1] + 150 * k)
|
|
pix[yy][i + 2] = clamp(pix[yy][i + 2] + 220 * k)
|
|
return [bytes(r) for r in pix]
|
|
|
|
|
|
def hud(vertical):
|
|
"""细光分隔:横排为水平线,竖排为垂直线;带两端渐隐。"""
|
|
rows = []
|
|
for y in range(H):
|
|
row = bytearray()
|
|
for x in range(W):
|
|
if vertical:
|
|
t = abs(x - W * 0.5)
|
|
fade = max(0.0, 1.0 - abs(y / H - 0.5) * 1.7)
|
|
else:
|
|
t = abs(y - H * 0.5)
|
|
fade = max(0.0, 1.0 - abs(x / W - 0.5) * 1.7)
|
|
glow = math.exp(-(t / 2.2) ** 2) * fade
|
|
row += bytes((clamp(6 * glow), clamp(110 * glow), clamp(190 * glow)))
|
|
rows.append(bytes(row))
|
|
return rows
|
|
|
|
|
|
def main():
|
|
os.makedirs(OUT, exist_ok=True)
|
|
for name, rows in (("outro.png", outro()),
|
|
("hud_flow.png", hud(False)),
|
|
("hud_seed.png", hud(True))):
|
|
p = os.path.join(OUT, name)
|
|
n = write_png(p, W, H, rows)
|
|
print(" %s %dx%d %d KB" % (name, W, H, n // 1024))
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|