8bitlenser/lenser/coco3/convert/gr16.py
2026-07-03 19:35:35 -07:00

24 lines
981 B
Python

"""CoCo 3 GIME 160x192, 16 colours from the 64-colour palette (flagship photo
mode -- wide pixels but the most colour)."""
from __future__ import annotations
from ...convert.base import Conversion, perceptual_error
from . import _common
WIDTH, HEIGHT = 160, 192
PIXEL_ASPECT = 2.0 # 160 wide on a 4:3 screen -> pixels twice as wide
NCOL = 16
CRES = 2
def convert(img_rgb, palette_name="gime", dither_mode="floyd",
intensive=False, base_color=None):
pen, inks, idx, img_lab, plab, prgb = _common.render(img_rgb, NCOL, dither_mode)
screen = _common.PACK[CRES](pen)
return Conversion(
mode="gr16", width=WIDTH, height=HEIGHT, pixel_aspect=PIXEL_ASPECT,
index_image=idx, data=screen, data_addr=0x4000, viewer="coco3",
preview_rgb=prgb[idx], error=perceptual_error(idx, img_lab, plab),
meta={"palette": "gime", "dither": dither_mode, "cres": CRES,
"inks": inks, "border": inks[0] if inks else 0},
)