Files

84 lines
5.0 KiB
Python

#!/usr/bin/env python3
"""Verify the hair-only rebuild against accepted v03 and make review sheets."""
from pathlib import Path
import hashlib
import json
import numpy as np
from PIL import Image, ImageDraw, ImageFilter, ImageFont
ROOT = Path(__file__).resolve().parents[1]
REPO = next(p for p in ROOT.parents if (p / 'docs/card-layer-pipeline.md').is_file())
PREVIOUS = REPO / 'artifacts/cards/BE-002-the-fall'
PRINTINGS = ['normal', 'boundless', 'borderless', 'textless']
def digest(path):
return hashlib.sha256(path.read_bytes()).hexdigest()
def main():
before = np.asarray(Image.open(ROOT / 'source/art-original-native.png').convert('RGB'))
after = np.asarray(Image.open(ROOT / 'source/art-native.png').convert('RGB'))
mask = Image.open(ROOT / 'source/hair-recolor-mask.png').convert('L')
selected = np.asarray(mask) > 0
assert np.array_equal(before[~selected], after[~selected])
assert digest(PREVIOUS / 'source/art-native.png') == '7477ac677cd0c2401d27bca5a8b603aecb22274ea17e6c6e36f6acf039ea7c43'
assert digest(PREVIOUS / 'source/art-master.png') == '06c0df0db8108e687330df716cc0569433404d132962d7aa0b5dbd5662bf4c8e'
old_report = json.loads((PREVIOUS / 'review/build-validation.json').read_text())
build = json.loads((ROOT / 'review/build-validation.json').read_text())
assert build['status'] == 'passed'
assert old_report['sharedLayers']['manifestSHA256'] == build['sharedLayers']['manifestSHA256']
for key in ['referenceBaseline', 'referenceLineBox', 'textLayerSHA256']:
assert old_report['typography'][key] == build['typography'][key], key
checks = []
for label, width in [('low', 500), ('med', 1000), ('high', 2000)]:
size = (width, width * 7 // 5)
# Account for the recorded Lanczos fits, including output resampling.
support = mask.filter(ImageFilter.MaxFilter(9)).resize(size, Image.Resampling.NEAREST)
allowed = np.asarray(support.filter(ImageFilter.MaxFilter(9))) > 0
for printing in PRINTINGS:
old = np.asarray(Image.open(PREVIOUS / label / printing / 'card.png').convert('RGBA'))
new = np.asarray(Image.open(ROOT / label / printing / 'card.png').convert('RGBA'))
changed = np.any(old != new, axis=2)
assert old.shape == new.shape == (size[1], size[0], 4)
assert not np.any(changed & ~allowed), f'Unrequested face changes: {label}/{printing}'
assert np.all(new[..., 3] == 255)
old_text = np.asarray(Image.open(PREVIOUS / label / printing / 'text-mask.png').convert('RGBA'))
new_text = np.asarray(Image.open(ROOT / label / printing / 'text-mask.png').convert('RGBA'))
assert np.array_equal(old_text, new_text), f'Changed glyph protection: {label}/{printing}'
checks.append({'resolution': label, 'printing': printing,
'changedFacePixels': int(changed.sum()),
'outsideHairResamplingSupportChangedPixels': int((changed & ~allowed).sum()),
'textMaskPixelIdenticalToAccepted': True})
font = ImageFont.truetype(str(REPO / 'fonts/P052-Bold.otf'), 23)
for filename, asset in [('finish-masks-comparison.png', 'finish-mask.png'),
('text-masks-comparison.png', 'text-mask.png')]:
board = Image.new('RGB', (1200, 470), '#11161c')
draw = ImageDraw.Draw(board)
for i, printing in enumerate(PRINTINGS):
draw.text((i * 300 + 10, 10), printing.title(), font=font, fill='#f4ead4')
im = Image.open(ROOT / 'med' / printing / asset).convert('RGB')
board.paste(im.resize((280, 392), Image.Resampling.LANCZOS), (i * 300 + 10, 55))
board.save(ROOT / 'review' / filename)
board = Image.new('RGB', (1000, 750), '#11161c')
draw = ImageDraw.Draw(board)
for i, (path, title) in enumerate([(PREVIOUS, 'Accepted v03'), (ROOT, 'Hair-continuity v05')]):
draw.text((500 * i + 14, 10), title, font=font, fill='#f4ead4')
board.paste(Image.open(path / 'low/normal/card.png').convert('RGB'), (500 * i, 50))
board.save(ROOT / 'review/normal-comparison-v03-v05.png')
report = {'status': 'passed', 'revision': 'v05', 'acceptedBaseline': 'v03',
'nativeOutsideHairMaskPixelIdentical': True,
'acceptedNativeAndMasterHashesUnchanged': True,
'sharedLayerManifestUnchanged': True,
'typographyRasterAndReferenceMetricsUnchanged': True,
'faceComparisonPolicy': 'No changes outside local hair mask plus conservative Lanczos resampling support',
'checks': checks, 'movingLight': 'not performed'}
(ROOT / 'review/assembly-difference-validation.json').write_text(json.dumps(report, indent=2) + '\n')
print(json.dumps({'status': report['status'], 'printingResolutionChecks': len(checks),
'outsideHairChanges': sum(c['outsideHairResamplingSupportChangedPixels'] for c in checks),
'typographyUnchanged': True}, indent=2))
if __name__ == '__main__':
main()