8bitlenser/lenser/cpc/convert/mode1.py
2026-07-03 19:35:35 -07:00

22 lines
845 B
Python

"""CPC Mode 1: 320x200, 4 colours from the 27-colour palette (more resolution,
fewer colours than mode 0)."""
from __future__ import annotations
from ...convert.base import Conversion, perceptual_error
from . import _common
WIDTH, HEIGHT = 320, 200
PIXEL_ASPECT = 1.0
NCOL = 4
def convert(img_rgb, palette_name="cpc", 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[1](pen)
return Conversion(
mode="mode1", width=WIDTH, height=HEIGHT, pixel_aspect=PIXEL_ASPECT,
index_image=idx, data=screen, data_addr=0xC000, viewer="cpc",
preview_rgb=prgb[idx], error=perceptual_error(idx, img_lab, plab),
meta={"palette": "cpc", "dither": dither_mode, "cpc_mode": 1, "inks": inks},
)