Skip to content

πŸ’ƒ Free CC0 mannequin pose reference library for AI image tools (Nano Banana, ChatGPT, ComfyUI, Midjourney) β€” 250+ poses Γ— 5 angles in line art, names in ja/zh/en/ko

9.1 KB
Raw Blame
#!/usr/bin/env python3
"""Contact sheets for the QC reviews (docs/qc/README.md), drawn from full-size sources.

Usage: python3 tools/review_sheets.py OUT_DIR [--mode MODE] [--passed] std=SRC sexy=SRC upper=SRC duo=SRC
SRC is a source set (e.g. ~/Downloads/pose-gallery-std73); line art is read from SRC/img, photos from SRC/photo.
Only the series given are drawn, so one series can be reviewed on its own. Redrawn sets (catalog `source`) are drawn
only when their source is given too (digi=SRC), and only then; --only-source digi limits the run to them.
Single-view fills (catalog `fills`, tools/import_fills.py) work the same way per view: --only-source fill-r1 draws
just the views filled from that source, read from fill-r1=SRC.

Modes (each pairs with a prompt in docs/qc/):
  panels      up to 3 views per sheet, 600x800 each        review_prompt.md      <id>__<view>-<view>.jpg
  name        first 3 views of a set on one sheet           name_prompt.md        <id>.jpg
  proportion  every view of a set, 360x480 each             proportion_prompt.md  <id>.jpg
  rating      first 3 views of a set on one sheet           rating_prompt.md      <id>.jpg
  photo       up to 3 photo renders per sheet, 400x800      photo_prompt.md       <id>__<view>-<view>.jpg
  limbs       up to 2 views per sheet, 600x800 each        limbs_prompt.md       <id>__<view>-<view>.jpg
  maps        2 views per sheet, one row each: line, clay, line over clay, depth, normal (360x480)
                                                            maps_prompt.md        <id>__<view>-<view>.jpg
              Usage: review_sheets.py OUT --mode maps maps=~/Downloads/pose-gallery-clay
              Line art comes from images/line/w900 (the maps were made from it); only catalog views are drawn.
  mapclay     3 clay renders per sheet, 600x800 each      maps_nipple_prompt.md <id>__<view>-<view>-<view>.jpg
              The surface-detail pass: nipple bumps are too small to judge on the five-panel maps sheet.
Views are every generated file (catalog or qc.json), so a failed view can be re-reviewed; --passed keeps only the
views now in the catalog β€” use it for proportion and rating, which judge what ships.
A batch file for a reviewer is just a list of sheet paths: `ls OUT_DIR/*.jpg | split -l 35 - OUT_DIR/batch_`.
"""
import argparse, json, pathlib

from PIL import Image, ImageChops, ImageDraw

ROOT = pathlib.Path(__file__).resolve().parent.parent
VIEWS = ("front", "diag", "side", "above", "below")
EXPECT = {
    "std": "1 woman, full body",
    "sexy": "1 woman, full body",
    "upper": "1 woman, upper-body framing (head to hips); full body visible is acceptable",
    "duo": "2 figures in contact, full body",
}
BODIES = {"MF": "1 man (broad shoulders) + 1 woman", "FF": "2 women"}
# panel size, views per sheet (None = all), per-set sheet name
MODES = {"panels": ((600, 800), 3, False), "name": ((600, 800), 3, True), "proportion": ((360, 480), None, True),
         "rating": ((600, 800), 3, True), "photo": ((400, 800), 3, False), "limbs": ((600, 800), 2, False), "maps": ((360, 480), 2, False),
         "mapclay": ((600, 800), 3, False)}
MAP_KINDS = ("clay", "depth", "normal")


def sheet(path, title, panels, size):
    w, h = size
    sh = Image.new("RGB", (w * len(panels), h + 40), "white")
    dr = ImageDraw.Draw(sh)
    dr.text((8, 6), title, fill="black")
    for j, (label, f) in enumerate(panels):
        sh.paste(Image.open(f).convert("RGB").resize((w, h)), (j * w, 40))
        dr.text((j * w + 8, 24), label, fill="red")
    sh.save(path, quality=88)


def map_sheet(path, title, rows, size):
    """One row per view: line, clay, line art in red over the clay (alignment), depth, normal."""
    w, h = size
    sh = Image.new("RGB", (w * 5, (h + 22) * len(rows) + 30), "white")
    dr = ImageDraw.Draw(sh)
    dr.text((8, 6), title, fill="black")
    for r, (view, line, maps) in enumerate(rows):
        y = 30 + r * (h + 22)
        ln = Image.open(line).convert("L").resize((w, h))
        clay = Image.open(maps / "clay" / line.name).convert("RGB").resize((w, h))
        over = ImageChops.multiply(clay, Image.merge("RGB", (Image.new("L", (w, h), 255), ln, ln)))
        tiles = [ln.convert("RGB"), clay, over] + [Image.open(maps / k / line.name).convert("RGB").resize((w, h))
                                                     for k in MAP_KINDS[1:]]
        for j, (label, t) in enumerate(zip(("line", "clay", "line over clay", "depth", "normal"), tiles)):
            sh.paste(t, (j * w, y + 18))
            dr.text((j * w + 8, y + 4), f"{view} Β· {label}", fill="red")
    sh.save(path, quality=88)


def maps_main(out, srcs, clay_only=False):
    maps, n = srcs["maps"], 0
    for p in json.loads((ROOT / "data/catalog.json").read_text()):
        rows = [(v, ROOT / "images/line/w900" / f) for v in VIEWS if (f := p["views"].get(v))
                and all((maps / k / f).exists() for k in MAP_KINDS)]
        expect = EXPECT[p["series"]] + (f" ({BODIES[p['bodies']]})" if p.get("bodies") else "")
        if clay_only:
            for i in range(0, len(rows), 3):
                chunk = rows[i:i + 3]
                sheet(out / f"{p['id']}__{'-'.join(v for v, _ in chunk)}.jpg", f"{p['id']} | {p['name_en']} | clay",
                      [(v, maps / "clay" / f.name) for v, f in chunk], MODES["mapclay"][0])
                n += 1
            continue
        for i in range(0, len(rows), 2):
            chunk = rows[i:i + 2]
            map_sheet(out / f"{p['id']}__{'-'.join(v for v, _ in chunk)}.jpg",
                      f"{p['id']} | {p['name_en']} | expected: {expect}", [(v, f, maps) for v, f in chunk],
                      MODES["maps"][0])
            n += 1
    print(f"maps: {n} sheets in {out}")


def main() -> None:
    ap = argparse.ArgumentParser()
    ap.add_argument("out")
    ap.add_argument("--mode", default="panels", choices=MODES)
    ap.add_argument("--passed", action="store_true")
    ap.add_argument("--only-source", default=None)
    ap.add_argument("srcs", nargs="+", metavar="series=SRC")
    a = ap.parse_args()
    srcs = {k: pathlib.Path(v).expanduser() for k, v in (s.split("=", 1) for s in a.srcs)}
    out = pathlib.Path(a.out)
    out.mkdir(parents=True, exist_ok=True)
    if a.mode in ("maps", "mapclay"):
        return maps_main(out, srcs, a.mode == "mapclay")
    size, per, per_set = MODES[a.mode]
    qc_path = ROOT / "data/qc.json"
    qc = json.loads(qc_path.read_text()) if qc_path.exists() else {}
    n = 0
    for p in json.loads((ROOT / "data/catalog.json").read_text()):
        line_src = p.get("source") or p["series"]
        if a.mode == "photo":
            view_src = {v: line_src for v in VIEWS if not a.only_source or p.get("source") == a.only_source}
        else:
            view_src = {v: p.get("fills", {}).get(v) or line_src for v in VIEWS}
        # A view is drawn only when its source was given (and is the one asked for with --only-source).
        view_src = {v: s for v, s in view_src.items() if s in srcs and (a.mode == "photo" or not a.only_source
                                                                       or s == a.only_source)}
        if p["series"] not in srcs or not view_src:
            continue
        src, pid = srcs[p["series"]], p["id"]
        expect = EXPECT[p["series"]] + (f" ({BODIES[p['bodies']]})" if p.get("bodies") else "")
        if a.mode == "photo":
            files = {v: r["file"] for v, r in qc.get("photos", {}).get(pid, {}).items()} | (p.get("photos") or {})
            if a.passed:
                files = p.get("photos") or {}
            panels = [(v, src / "photo" / files[v]) for v in VIEWS if v in files]
            title = f"{pid} | {p['name_en']} | {p['class_en']} | expected: 1 adult woman, photo render, full body"
        else:
            # qc.json file names of a set redrawn since the last merge belong to the old drawing.
            same = qc.get("sources", {}).get(pid) == p.get("source")
            files = {v: (p["views"].get(v) or (None if a.passed or not same else
                                               qc.get("views", {}).get(pid, {}).get(v, {}).get("file")))
                     for v in VIEWS}
            panels = [(v, srcs[view_src[v]] / "img" / files[v]) for v in VIEWS if files[v] and v in view_src]
            title = {"panels": f"{pid} | {p['name_en']} | expected: {expect}",
                     "limbs": f"{pid} | {p['name_en']} | expected: {expect}",
                     "name": f"{pid} | {p['class_en']} | {p['name_en']} | ja: {p['name_jp']}"
                             + (f" | bodies {p['bodies']}" if p.get("bodies") else ""),
                     "proportion": f"{pid} | {p['name_en']} | bodies {p.get('bodies') or 'F'}",
                     "rating": f"{pid} | {p['series']} | {p['class_en']} | {p['name_en']}"}[a.mode]
        if not panels:
            continue
        if per_set:
            sheet(out / f"{pid}.jpg", title, panels[:per], size)
            n += 1
            continue
        for i in range(0, len(panels), per):
            chunk = panels[i:i + per]
            sheet(out / f"{pid}__{'-'.join(v for v, _ in chunk)}.jpg", title, chunk, size)
            n += 1
    print(f"{a.mode}: {n} sheets in {out}")


if __name__ == "__main__":
    main()