33 lines
1.9 KiB
Python
33 lines
1.9 KiB
Python
"""Recompute approved references without writing to any card/proof directory."""
|
|
import sys,json,tempfile
|
|
from pathlib import Path
|
|
import numpy as np
|
|
from PIL import Image
|
|
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
|
|
from finish_masks import prepare_illustration, compile_finish, export_finish, sha256, RECIPE_SHA256
|
|
REPO = Path(__file__).resolve().parents[3]
|
|
PRODUCTION = REPO/'tools/card-production'
|
|
PROOF = REPO/'spikes/finish-mask-line-continuity-proof'
|
|
approval = json.loads((PRODUCTION/'recipes/raw-ridges-v1-approval.json').read_text())
|
|
reports = {}
|
|
with tempfile.TemporaryDirectory() as temp:
|
|
for key, reference in approval['references'].items():
|
|
source = PROOF/key/'source'
|
|
art = Image.open(source/'art-master.png')
|
|
assert sha256(source/'art-master.png') == reference['artSha256']
|
|
illustration = prepare_illustration(art)
|
|
frozen = PROOF/'raw-ridges'/key/'source/raw-ridges.png'
|
|
assert sha256(frozen) == reference['rawRidgesSha256']
|
|
assert np.array_equal(illustration.raw_ridges, np.asarray(Image.open(frozen).convert('L')))
|
|
master = compile_finish(illustration, 'normal', Image.open(source/'normal-overlay.png'), Image.open(source/'text.png'))
|
|
files = export_finish(master, Path(temp)/key, key, 'normal')
|
|
for record in files:
|
|
width = str(record['size'][0])
|
|
assert record['sha256'] == reference['approvedNormalMasks'][width], (key, width)
|
|
reports[key] = {'regeneratedRawConfidencePixelIdentical': True, 'approvedNormalMaskHashesIdenticalAtAllWidths': True}
|
|
report = {'status': 'passed', 'recipe': 'raw-ridges-v1', 'recipeSha256': RECIPE_SHA256,
|
|
'checks': reports, 'migrationPerformed': False,
|
|
'otherPrintings': 'Component semantics covered by synthetic tests; existing cards not rebuilt'}
|
|
(PRODUCTION/'tests/approved-reference-check.json').write_text(json.dumps(report, indent=2)+'\n')
|
|
print(json.dumps(report, indent=2))
|