diff options
| author | ItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com> | 2026-11-22 23:15:53 -0500 |
|---|---|---|
| committer | ItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com> | 2026-11-22 23:15:53 -0500 |
| commit | d7efebf7d43492e1fefd9bf9e5f2e8e762fb20eb (patch) | |
| tree | 4492c90b368bdcbe7091d4d785c5ddec8103b8c4 /tools/first_light.py | |
| parent | e23327ccc14fe6589419f5f679be99bdf6f01547 (diff) | |
| parent | bda6858c16271c0103367b6ec325678de9102465 (diff) | |
Merge pull request #4555 from Vonsek
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'tools/first_light.py')
| -rw-r--r-- | tools/first_light.py | 48 |
1 files changed, 31 insertions, 17 deletions
diff --git a/tools/first_light.py b/tools/first_light.py index 74540eb5e..d825c7c11 100644 --- a/tools/first_light.py +++ b/tools/first_light.py | |||
| @@ -676,6 +676,17 @@ def check_image(data: bytes, manifest: dict) -> dict: | |||
| 676 | tests/test_first_light.py imports this function, so the test and ``--check`` agree. | 676 | tests/test_first_light.py imports this function, so the test and ``--check`` agree. |
| 677 | """ | 677 | """ |
| 678 | width, height = manifest["width"], manifest["height"] | 678 | width, height = manifest["width"], manifest["height"] |
| 679 | |||
| 680 | def pixel_offset(point, field: str) -> int: | ||
| 681 | if ( | ||
| 682 | not isinstance(point, (list, tuple)) or len(point) != 2 | ||
| 683 | or any(type(coord) is not int for coord in point) | ||
| 684 | or not (0 <= point[0] < width and 0 <= point[1] < height) | ||
| 685 | ): | ||
| 686 | raise AssertionError(f"invalid {field} coordinates {point!r} for {width}x{height} image") | ||
| 687 | x, y = point | ||
| 688 | return (y * width + x) * 4 | ||
| 689 | |||
| 679 | if len(data) != width * height * 16: | 690 | if len(data) != width * height * 16: |
| 680 | raise AssertionError( | 691 | raise AssertionError( |
| 681 | f"raw is {len(data)} bytes, expected {width * height * 16}" | 692 | f"raw is {len(data)} bytes, expected {width * height * 16}" |
| @@ -708,7 +719,7 @@ def check_image(data: bytes, manifest: dict) -> dict: | |||
| 708 | f"[{manifest.get('min_coverage', 0.0)}, {manifest.get('max_coverage', 1.0)}]" | 719 | f"[{manifest.get('min_coverage', 0.0)}, {manifest.get('max_coverage', 1.0)}]" |
| 709 | ) | 720 | ) |
| 710 | if (clear := manifest.get("clear_pixel")) is not None: | 721 | if (clear := manifest.get("clear_pixel")) is not None: |
| 711 | i = (clear[1] * width + clear[0]) * 4 | 722 | i = pixel_offset(clear, "clear_pixel") |
| 712 | if any(not _close(pixels[i + c], clear_val, 1e-5) for c in range(4)): | 723 | if any(not _close(pixels[i + c], clear_val, 1e-5) for c in range(4)): |
| 713 | raise AssertionError( | 724 | raise AssertionError( |
| 714 | f"clear pixel {clear} is {pixels[i : i + 4]}, expected {clear_val}" | 725 | f"clear pixel {clear} is {pixels[i : i + 4]}, expected {clear_val}" |
| @@ -728,9 +739,11 @@ def check_image(data: bytes, manifest: dict) -> dict: | |||
| 728 | raise AssertionError( | 739 | raise AssertionError( |
| 729 | f"textured manifest has no expected colour distinguishable from fallback {FALLBACK_RGBA} (tol {tol})" | 740 | f"textured manifest has no expected colour distinguishable from fallback {FALLBACK_RGBA} (tol {tol})" |
| 730 | ) | 741 | ) |
| 742 | centre = manifest.get("centre_pixel") | ||
| 743 | if centre is None or centre == []: | ||
| 744 | centre = [width // 2, height // 2] | ||
| 731 | if (rgba := manifest.get("centre_rgba")) is not None: | 745 | if (rgba := manifest.get("centre_rgba")) is not None: |
| 732 | centre = manifest.get("centre_pixel") or [width // 2, height // 2] | 746 | i = pixel_offset(centre, "centre_pixel") |
| 733 | i = (centre[1] * width + centre[0]) * 4 | ||
| 734 | tol = manifest.get("rgba_tolerance", 0.02) | 747 | tol = manifest.get("rgba_tolerance", 0.02) |
| 735 | for c, want in enumerate(rgba): | 748 | for c, want in enumerate(rgba): |
| 736 | if not _close(pixels[i + c], want, tol): | 749 | if not _close(pixels[i + c], want, tol): |
| @@ -738,8 +751,7 @@ def check_image(data: bytes, manifest: dict) -> dict: | |||
| 738 | f"centre {centre} is {pixels[i : i + 4]}, expected {rgba} (tol {tol})" | 751 | f"centre {centre} is {pixels[i : i + 4]}, expected {rgba} (tol {tol})" |
| 739 | ) | 752 | ) |
| 740 | elif (uv := manifest.get("centre_uv")) is not None: | 753 | elif (uv := manifest.get("centre_uv")) is not None: |
| 741 | centre = manifest.get("centre_pixel") or [width // 2, height // 2] | 754 | i = pixel_offset(centre, "centre_pixel") |
| 742 | i = (centre[1] * width + centre[0]) * 4 | ||
| 743 | for c, want in enumerate((uv[0], uv[1], 0.0, 1.0)): | 755 | for c, want in enumerate((uv[0], uv[1], 0.0, 1.0)): |
| 744 | if not _close(pixels[i + c], want, 2e-3): | 756 | if not _close(pixels[i + c], want, 2e-3): |
| 745 | raise AssertionError( | 757 | raise AssertionError( |
| @@ -748,24 +760,26 @@ def check_image(data: bytes, manifest: dict) -> dict: | |||
| 748 | if (rgba_probes := manifest.get("rgba_probes")) is not None: | 760 | if (rgba_probes := manifest.get("rgba_probes")) is not None: |
| 749 | tol = manifest.get("rgba_tolerance", 0.02) | 761 | tol = manifest.get("rgba_tolerance", 0.02) |
| 750 | for probe in rgba_probes: | 762 | for probe in rgba_probes: |
| 751 | px, py = probe["pixel"] | 763 | i = pixel_offset(probe.get("pixel"), "rgba_probes pixel") |
| 752 | i = (py * width + px) * 4 | ||
| 753 | want_rgba = probe["rgba"] | 764 | want_rgba = probe["rgba"] |
| 754 | for c, want in enumerate(want_rgba): | 765 | for c, want in enumerate(want_rgba): |
| 755 | if not _close(pixels[i + c], want, tol): | 766 | if not _close(pixels[i + c], want, tol): |
| 756 | raise AssertionError( | 767 | raise AssertionError( |
| 757 | f"RGBA probe {probe['pixel']} is {pixels[i : i + 4]}, expected {want_rgba} (tol {tol})" | 768 | f"RGBA probe {probe['pixel']} is {pixels[i : i + 4]}, expected {want_rgba} (tol {tol})" |
| 758 | ) | 769 | ) |
| 759 | else: | 770 | uv_probes = manifest.get("uv_probes") |
| 760 | for probe in manifest.get("uv_probes", []): | 771 | if uv_probes is None: |
| 761 | px, py = probe["pixel"] | 772 | uv_probes = [] |
| 762 | i = (py * width + px) * 4 | 773 | for probe in uv_probes: |
| 763 | u, v = probe["uv"] | 774 | i = pixel_offset(probe.get("pixel"), "uv_probes pixel") |
| 764 | for c, want in enumerate((u, v, 0.0, 1.0)): | 775 | if rgba_probes is not None: |
| 765 | if not _close(pixels[i + c], want, 2e-3): | 776 | continue |
| 766 | raise AssertionError( | 777 | u, v = probe["uv"] |
| 767 | f"UV probe {probe['pixel']} is {pixels[i : i + 4]}, expected {want} at {c}" | 778 | for c, want in enumerate((u, v, 0.0, 1.0)): |
| 768 | ) | 779 | if not _close(pixels[i + c], want, 2e-3): |
| 780 | raise AssertionError( | ||
| 781 | f"UV probe {probe['pixel']} is {pixels[i : i + 4]}, expected {want} at {c}" | ||
| 782 | ) | ||
| 769 | return {"covered": covered, "ratio": ratio, "pixels": pixels} | 783 | return {"covered": covered, "ratio": ratio, "pixels": pixels} |
| 770 | 784 | ||
| 771 | 785 | ||