First public commit.

This commit is contained in:
The Dust Council 2026-07-03 19:35:35 -07:00
parent 2a48f52979
commit 4bac9d83ed
288 changed files with 18417 additions and 1076 deletions

33
lenser/sms/palette.py Normal file
View file

@ -0,0 +1,33 @@
"""Sega Master System VDP (315-5124) palette.
The SMS palette is 64 colours: each CRAM byte is %00BBGGRR -- 2 bits per channel
(x85 -> 0,85,170,255). The colour index IS the byte written to CRAM, so PALETTE
is indexed by hardware value 0-63. Two 16-colour palettes (background + sprite)
are loaded; an image uses up to 32 colours on screen.
"""
from __future__ import annotations
import numpy as np
from ..palette import srgb_to_lab
def _rgb(c):
r = (c & 3) * 85
g = ((c >> 2) & 3) * 85
b = ((c >> 4) & 3) * 85
return (r, g, b)
PALETTE = np.array([_rgb(c) for c in range(64)], dtype=np.float64)
# greys: R==G==B -> byte where the three 2-bit fields are equal (0,21,42,63).
GREYS = [c for c in range(64) if PALETTE[c, 0] == PALETTE[c, 1] == PALETTE[c, 2]]
def get_palette() -> np.ndarray:
return PALETTE
def palette_lab() -> np.ndarray:
return srgb_to_lab(PALETTE)