8bitlenser/lenser/nes/convert/bg.py
2026-07-03 19:35:35 -07:00

21 lines
865 B
Python

"""NES background image: 256x240, 4 sub-palettes (universal bg + 3 each), tiles."""
from __future__ import annotations
from ...convert.base import Conversion
from . import _common
WIDTH, HEIGHT = 256, 240
PIXEL_ASPECT = 1.0 # NES pixels are ~square (8:7 really; close enough)
def convert(img_rgb, palette_name="nes", dither_mode="floyd",
intensive=False, base_color=None):
subs = _common.pick_subpalettes(img_rgb, mono=False)
pal32, nt, chr_rom, idx, err, plab, prgb = _common.encode(
img_rgb, dither_mode, subs)
return Conversion(
mode="bg", width=WIDTH, height=HEIGHT, pixel_aspect=PIXEL_ASPECT,
index_image=idx, data={"palette": pal32, "nametable": nt, "chr": chr_rom},
data_addr=0, viewer="nes", preview_rgb=prgb[idx], error=err,
meta={"palette": "nes", "dither": dither_mode},
)