Files
FastD 9e7b1e3430 Serve planet and mascots from src/assets
- Move served planet (animated webp, posters, 300 frames) and team mascots into src/assets/
- Use relative paths (assets/...) that work in file://, on the dev server and with docroot=src
- Screenshot pipeline writes to src/assets/projects
- Halo audit: report and measurements, ticker ring fix, shadow rules in DESIGN.md and spec.md
2026-11-10 18:42:12 +03:00

156 lines
6.0 KiB
Python

"""alpha_probe.py — есть ли ореол, ВШИТЫЙ в арт планеты (webp с прозрачностью).
Метрики по каждому кадру:
• semi_share — доля полупрозрачных пикселей от всех непрозрачных (сглаживание кромки);
• band_p50/p95/max — толщина полупрозрачной каймы: расстояние от полупрозрачного
пикселя до ближайшего полностью непрозрачного (двухпроходный chamfer-трансформ).
Сглаживание кромки даёт 1–2 px; «вшитый» ореол — десятки пикселей;
• composite_* — как выглядит кайма поверх фона темы (светлая #F5EEE2 / тёмная #181109):
средняя/максимальная дельта яркости и доля пикселей светлее фона.
Ореол = кайма, которая СВЕТЛЕЕ фона и толще сглаживания.
Дополнительно пишет превью-композиты (арт поверх фона обеих тем) в out/.
Запуск: py design/halo-audit-2026-11-10/alpha_probe.py
"""
import json
import os
import sys
from PIL import Image
ROOT = "G:/Project/Haevey_Monster_Team_Page/"
OUT = ROOT + "design/halo-audit-2026-11-10/out/"
ART = [
("poster-desktop", "Work_files/Planet/planet_poster.webp"),
("poster-mobile", "Work_files/Planet/planet_poster_mobile.webp"),
("seq-frame-0001", "Work_files/Planet/seq/Planet_seq_0001.webp"),
("seq-frame-0150", "Work_files/Planet/seq/Planet_seq_0150.webp"),
("static-png", "Work_files/Planet/planet_static.png"),
]
BG_LIGHT = (245, 238, 226)
BG_DARK = (24, 17, 9)
INF = 1 << 20
def luma(c):
return 0.2126 * c[0] + 0.7152 * c[1] + 0.0722 * c[2]
def chamfer(opaque, w, h):
"""Расстояние (в px, ~евклидово) от каждого пикселя до ближайшего непрозрачного."""
d = [[0 if opaque[y][x] else INF for x in range(w)] for y in range(h)]
for y in range(h):
for x in range(w):
if not opaque[y][x]:
best = d[y][x]
if y > 0:
best = min(best, d[y - 1][x] + 1)
if x > 0:
best = min(best, d[y - 1][x - 1] + 1)
if x < w - 1:
best = min(best, d[y - 1][x + 1] + 1)
if x > 0:
best = min(best, d[y][x - 1] + 1)
d[y][x] = best
for y in range(h - 1, -1, -1):
for x in range(w - 1, -1, -1):
if not opaque[y][x]:
best = d[y][x]
if y < h - 1:
best = min(best, d[y + 1][x] + 1)
if x > 0:
best = min(best, d[y + 1][x - 1] + 1)
if x < w - 1:
best = min(best, d[y + 1][x + 1] + 1)
if x < w - 1:
best = min(best, d[y][x + 1] + 1)
d[y][x] = best
return d
def pct(vals, p):
if not vals:
return None
s = sorted(vals)
k = min(len(s) - 1, max(0, int(round((len(s) - 1) * p))))
return s[k]
def probe(name, rel):
path = ROOT + rel
try:
im = Image.open(path).convert("RGBA")
except Exception as e: # noqa: BLE001
return {"name": name, "path": rel, "error": str(e)}
w, h = im.size
px = im.load()
opaque_mask = [[px[x, y][3] >= 250 for x in range(w)] for y in range(h)]
dist = chamfer(opaque_mask, w, h)
semi = 0
opaque = 0
band = []
light = []
dark = []
for y in range(h):
for x in range(w):
r, g, b, a = px[x, y]
if a == 0:
continue
if a >= 250:
opaque += 1
continue
semi += 1
band.append(dist[y][x])
for bg, acc in ((BG_LIGHT, light), (BG_DARK, dark)):
k = a / 255.0
comp = tuple(int(round(r * k + bg[i] * (1 - k))) for i in range(3))
acc.append(luma(comp) - luma(bg))
def summarize(vals, bg):
if not vals:
return None
return {
"mean_dluma": round(sum(vals) / len(vals), 2),
"max_dluma": round(max(vals), 2),
"min_dluma": round(min(vals), 2),
"share_lighter_than_bg": round(sum(1 for v in vals if v > 0.5) / len(vals), 3),
"bg": "#%02X%02X%02X" % bg,
}
# превью-композиты обеих тем (арт на фоне, без масштабирования)
for tag, bg in (("light", BG_LIGHT), ("dark", BG_DARK)):
canvas = Image.new("RGBA", (w, h), bg + (255,))
canvas.alpha_composite(im)
canvas.convert("RGB").save(os.path.join(OUT, "art-%s-%s.png" % (name, tag)))
return {
"name": name, "path": rel, "size": [w, h],
"opaque_px": opaque, "semi_px": semi,
"semi_share_of_art": round(semi / max(1, opaque + semi), 4),
"band_px_p50": pct(band, 0.5), "band_px_p95": pct(band, 0.95),
"band_px_max": max(band) if band else None,
"on_light_bg": summarize(light, BG_LIGHT),
"on_dark_bg": summarize(dark, BG_DARK),
}
def main():
res = [probe(n, p) for n, p in ART]
with open(os.path.join(OUT, "alpha.json"), "w", encoding="utf-8") as f:
json.dump(res, f, ensure_ascii=False, indent=2)
for r in res:
if "error" in r:
print(r["name"], "ERROR", r["error"])
continue
print("%-16s semi=%5d (%.2f%%) band p50/p95/max=%s/%s/%s | light mean %s | dark mean %s" % (
r["name"], r["semi_px"], r["semi_share_of_art"] * 100,
r["band_px_p50"], r["band_px_p95"], r["band_px_max"],
(r["on_light_bg"] or {}).get("mean_dluma"), (r["on_dark_bg"] or {}).get("mean_dluma")))
return 0
if __name__ == "__main__":
sys.exit(main())