30 lines
787 B
Python
30 lines
787 B
Python
"""Commodore Amiga (OCS/ECS) colour palette.
|
|
|
|
12-bit colour: 4 bits per channel (x17 -> 0..255), 4096 colours. A colour
|
|
register value is %0000 RRRR GGGG BBBB. We index the master palette by the
|
|
packed 12-bit key (R<<8)|(G<<4)|B, which is also the register word.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import numpy as np
|
|
|
|
from ..palette import srgb_to_lab
|
|
|
|
_r = (np.arange(4096) >> 8) & 0xF
|
|
_g = (np.arange(4096) >> 4) & 0xF
|
|
_b = np.arange(4096) & 0xF
|
|
PALETTE = (np.stack([_r, _g, _b], axis=1) * 17).astype(np.float64) # 4096 x 3
|
|
|
|
GREYS = [(v << 8) | (v << 4) | v for v in range(16)] # 16 grey keys
|
|
|
|
|
|
def color_word(key: int) -> int:
|
|
return key & 0x0FFF
|
|
|
|
|
|
def get_palette() -> np.ndarray:
|
|
return PALETTE
|
|
|
|
|
|
def palette_lab() -> np.ndarray:
|
|
return srgb_to_lab(PALETTE)
|