led_scenes.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/usr/bin/env python3
  2. """Writes the LED test scenes into <out dir>/led_<name>: solid colored rectangles on a gray background, with ledsource set on
  3. different layers (a none, b red, c red and blue, d the background, e a composelayer over a part of the scene, f blue and red
  4. with blue first). Run them through we_led.sh and tools/check_leds.sh and compare the two 80 x 10 frames."""
  5. import json, os, shutil, sys
  6. SOURCE = os.path.expanduser('~/.local/share/we_live/tests/ptfx/w1/project.json')
  7. RECTS = [('red', 300, 540, 400, 1080, '1 0 0'), ('green', 960, 300, 500, 300, '0 1 0'),
  8. ('blue', 1500, 800, 500, 400, '0 0 1'), ('yellow', 960, 900, 200, 100, '1 1 0')]
  9. SWAPPED = [RECTS[2], RECTS[0], RECTS[1], RECTS[3]]
  10. def write(out, led, rects, extra=()):
  11. os.makedirs(out, exist_ok=True)
  12. shutil.copy(SOURCE, out + '/project.json')
  13. objects = [{'id': 1, 'name': 'bg', 'image': 'models/util/solidlayer.json', 'size': '1920 1080', 'origin': '960 540 0',
  14. 'color': '0.2 0.2 0.2', 'alpha': 1.0, 'visible': True, 'ledsource': 1 in led}]
  15. for i, (name, x, y, w, h, color) in enumerate(rects):
  16. objects.append({'id': 10 + i, 'name': name, 'image': 'models/util/solidlayer.json', 'size': '%d %d' % (w, h),
  17. 'origin': '%d %d 0' % (x, y), 'color': color, 'alpha': 1.0, 'visible': True,
  18. 'ledsource': (10 + i) in led})
  19. objects.extend(extra)
  20. scene = {'version': 3, 'camera': {'center': '0 0 -1', 'eye': '0 0 0', 'up': '0 1 0'},
  21. 'general': {'orthogonalprojection': {'width': 1920, 'height': 1080}, 'clearcolor': '0 0 0', 'bloom': False,
  22. 'cameraparallax': False, 'ambientcolor': '0.2 0.2 0.2', 'skylightcolor': '0.3 0.3 0.3'},
  23. 'objects': objects}
  24. json.dump(scene, open(out + '/scene.json', 'w'), indent=1)
  25. out = sys.argv[1]
  26. write(out + '/led_a', set(), RECTS)
  27. write(out + '/led_b', {10}, RECTS)
  28. write(out + '/led_c', {10, 12}, RECTS)
  29. write(out + '/led_d', {1}, RECTS)
  30. write(out + '/led_e', set(), RECTS, [{'id': 50, 'name': 'cmp', 'image': 'models/util/composelayer.json', 'size': '800 400',
  31. 'origin': '700 540 0', 'visible': True, 'copybackground': True, 'ledsource': True}])
  32. write(out + '/led_f', {10, 11}, SWAPPED)