test: accept frozen BOM workflow and add window-only GIF tutorial
This commit is contained in:
1 parent
a16914bc72
commit
6b5f79b412
9 files changed
+805
-6
No files matched your search
@@ -0,0 +1,55 @@
|
||||
"""Assemble numbered PrintWindow operation frames; shorten only idle waits."""
|
||||
import argparse
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
from PIL import Image
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument('--root', type=Path, required=True)
|
||||
parser.add_argument('--output', type=Path, required=True)
|
||||
args = parser.parse_args()
|
||||
root = args.root.resolve(strict=True)
|
||||
events = json.loads((root / 'recording/frames.json').read_text(encoding='utf-8'))
|
||||
by_number = {}
|
||||
for entry in events:
|
||||
first = entry['caption'].split(maxsplit=1)[0]
|
||||
if not first.isdigit():
|
||||
continue
|
||||
number = int(first)
|
||||
# Early driver setup retries are not part of the instructional sequence.
|
||||
if number not in by_number or number in (1, 2):
|
||||
by_number[number] = entry
|
||||
assert set(by_number) == set(range(1, 21)), sorted(by_number)
|
||||
selected = [by_number[n] for n in range(1, 21)]
|
||||
images = [Image.open(root / f'recording/frame-{e["frame"]:03d}.png').convert('RGB') for e in selected]
|
||||
assert {image.size for image in images} == {(1280, 980)}
|
||||
# A shared palette samples every real state, including error and success colors.
|
||||
contact = Image.new('RGB', (1024, 980), '#f3f5f8')
|
||||
for n, image in enumerate(images):
|
||||
thumb = image.resize((256, 196), Image.Resampling.LANCZOS)
|
||||
contact.paste(thumb, ((n % 4) * 256, (n // 4) * 196))
|
||||
palette = contact.quantize(colors=192)
|
||||
frames = [image.quantize(palette=palette, dither=Image.Dither.NONE) for image in images]
|
||||
args.output.parent.mkdir(parents=True, exist_ok=True)
|
||||
durations = [max(e['duration_ms'], 2200) for e in selected]
|
||||
frames[0].save(args.output, save_all=True, append_images=frames[1:],
|
||||
duration=durations, loop=0, optimize=True, disposal=2)
|
||||
contact.save(root / 'tutorial-contact-sheet.png')
|
||||
with Image.open(args.output) as exported:
|
||||
assert exported.n_frames == 20 and exported.size == (1280, 980)
|
||||
for number in (0, 5, 14, 19):
|
||||
exported.seek(number)
|
||||
exported.convert('RGB').save(root / f'tutorial-gif-check-{number:02d}.png')
|
||||
report = dict(gif=str(args.output.resolve()), bytes=args.output.stat().st_size,
|
||||
frames=20, duration_seconds=sum(durations) / 1000,
|
||||
capture='PrintWindow surfaces of the candidate process only',
|
||||
waits_shortened=True, steps=selected)
|
||||
(root / 'tutorial-report.json').write_text(json.dumps(report, ensure_ascii=False, indent=2), encoding='utf-8')
|
||||
print(json.dumps({k: v for k, v in report.items() if k != 'steps'}, ensure_ascii=False, indent=2))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in new issue
Block a user