Update card production workflow and workspaces
This commit is contained in:
@@ -7,11 +7,13 @@ import hashlib
|
||||
import json
|
||||
import math
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import numpy as np
|
||||
from PIL import Image, ImageFilter, __version__ as pillow_version
|
||||
|
||||
RECIPE_PATH = Path(__file__).resolve().parent / 'recipes/raw-ridges-v1.json'
|
||||
RECIPE_SHA256 = '23331ce56a717edb4e6f85956d11fdd98397009c4e6dd230d8c334c77571dd18'
|
||||
DEFAULT_RECIPE_ID = 'raw-ridges-v1'
|
||||
PRINTINGS = ('normal', 'textless', 'borderless', 'boundless')
|
||||
|
||||
def sha256(path: Path) -> str:
|
||||
@@ -104,20 +106,24 @@ def compile_finish(illustration: IllustrationCoverage, printing: str,
|
||||
if (text is not None) != requires_text:
|
||||
raise ValueError(f'{printing} requires rendered text' if requires_text else f'{printing} has no text')
|
||||
r = load_recipe()
|
||||
if illustration.recipe_id != r['id'] or illustration.size != tuple(r['canvas']):
|
||||
raise ValueError('Illustration coverage must use the approved recipe and master canvas')
|
||||
if illustration.recipe_id not in (r['id'], 'gated-contrast-v1') or illustration.size != tuple(r['canvas']):
|
||||
raise ValueError('Illustration coverage must use a supported recipe and master canvas')
|
||||
panes, ridges = illustration.pane_weights, illustration.raw_ridges
|
||||
if panes.shape != ridges.shape or ridges.dtype != np.uint8:
|
||||
raise ValueError('Invalid illustration coverage arrays')
|
||||
if not np.all(np.isfinite(panes)) or np.any((panes < 0) | (panes > 1)):
|
||||
raise ValueError('Pane coverage must be finite within [0, 1]')
|
||||
oa = 0. if overlay is None else _component_alpha(overlay, illustration.size, 'Overlay')
|
||||
if illustration.recipe_id == 'gated-contrast-v1' and isinstance(oa, np.ndarray):
|
||||
oa = oa.astype(np.float32)
|
||||
if printing in ('normal', 'textless'):
|
||||
height, width = ridges.shape
|
||||
corners = ((0, 0), (0, width-1), (height-1, 0), (height-1, width-1))
|
||||
if any(oa[y, x] != 1 for y, x in corners):
|
||||
raise ValueError('Framed printings require opaque overlay corners; geometry owns rounding')
|
||||
ta = 0. if text is None else _component_alpha(text, illustration.size, 'Text')
|
||||
if illustration.recipe_id == 'gated-contrast-v1' and isinstance(ta, np.ndarray):
|
||||
ta = ta.astype(np.float32)
|
||||
protection = 1 - (1-oa)*(1-ta)
|
||||
confidence = ridges.astype(np.float32) / 255.
|
||||
coverage = np.rint(panes*(1-confidence)*(1-protection)*255).astype(np.uint8)
|
||||
@@ -144,6 +150,8 @@ def export_finish(master: Image.Image, output: Path, name: str, printing: str) -
|
||||
|
||||
def main() -> None:
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument('--recipe', choices=('gated-contrast-v1', 'raw-ridges-v1'),
|
||||
default=DEFAULT_RECIPE_ID)
|
||||
parser.add_argument('--art', type=Path, required=True)
|
||||
parser.add_argument('--printing', choices=PRINTINGS, required=True)
|
||||
parser.add_argument('--overlay', type=Path)
|
||||
@@ -155,23 +163,31 @@ def main() -> None:
|
||||
art = Image.open(args.art)
|
||||
overlay = Image.open(args.overlay) if args.overlay else None
|
||||
text = Image.open(args.text) if args.text else None
|
||||
illustration = prepare_illustration(art)
|
||||
if args.recipe == 'gated-contrast-v1':
|
||||
from gated_contrast import prepare_gated_illustration, RECIPE_PATH as selected_path, RECIPE_SHA256 as selected_sha
|
||||
illustration = prepare_gated_illustration(art)
|
||||
else:
|
||||
selected_path, selected_sha = RECIPE_PATH, RECIPE_SHA256
|
||||
illustration = prepare_illustration(art)
|
||||
master = compile_finish(illustration, args.printing, overlay, text)
|
||||
exports = export_finish(master, args.output, args.name, args.printing)
|
||||
except (OSError, ValueError) as error:
|
||||
parser.error(str(error))
|
||||
# Diagnostics are authoring inputs; they are not required runtime samplers.
|
||||
Image.fromarray(illustration.raw_ridges).save(args.output / f'{args.name}-raw-ridges.png')
|
||||
ridge_name = 'gated-contrast-ridges' if args.recipe == 'gated-contrast-v1' else 'raw-ridges'
|
||||
Image.fromarray(illustration.raw_ridges).save(args.output / f'{args.name}-{ridge_name}.png')
|
||||
Image.fromarray(np.rint(illustration.pane_weights*255).astype(np.uint8)).save(
|
||||
args.output / f'{args.name}-pane-coverage.png')
|
||||
sources = {name: {'path': str(path.resolve()), 'sha256': sha256(path)}
|
||||
for name, path in [('art', args.art), ('overlay', args.overlay), ('text', args.text)] if path}
|
||||
report = {'status': 'passed', 'recipe': load_recipe()['id'], 'recipePath': str(RECIPE_PATH),
|
||||
'recipeSha256': RECIPE_SHA256, 'moduleSha256': sha256(Path(__file__)),
|
||||
report = {'status': 'passed', 'recipe': args.recipe, 'recipePath': str(selected_path),
|
||||
'recipeSha256': selected_sha, 'moduleSha256': sha256(Path(__file__)),
|
||||
'tools': {'numpy': np.__version__, 'pillow': pillow_version},
|
||||
'printing': args.printing, 'inputs': sources, 'exports': exports,
|
||||
'review': {'structural': 'Canvas and component contract checked',
|
||||
'static': 'Pending', 'movingLight': 'Pending', 'userApproval': 'Pending for this card'}}
|
||||
if args.recipe == 'gated-contrast-v1':
|
||||
report['tools']['imageMagick'] = subprocess.check_output(['convert', '-version'], text=True).splitlines()[0]
|
||||
(args.output / f'{args.name}-{args.printing}-finish-validation.json').write_text(json.dumps(report, indent=2)+'\n')
|
||||
print(json.dumps({'recipe': report['recipe'], 'printing': args.printing, 'exports': exports}, indent=2))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user