33 lines
902 B
Python
33 lines
902 B
Python
"""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)
|