more accurate palette conversion

This commit is contained in:
Irmen de Jong 2023-11-08 01:33:55 +01:00
parent 5698de6cf4
commit f70fa42eac
2 changed files with 6 additions and 2 deletions

View File

@ -1,7 +1,6 @@
TODO
====
- integrate MCIOUT into diskio.f_write()
- revisit the seek example to see if write-seeking now works?
- remove unused interned strings in the resulting code (for example from removed if/else blocks)
- [on branch: shortcircuit] investigate McCarthy evaluation again? this may also reduce code size perhaps for things like if a>4 or a<2 ....

View File

@ -2,10 +2,15 @@
from PIL import Image
def make_cx16_palette(palette: list[int]) -> bytes:
def to4bit(color: int) -> int:
return (color * 15 + 135) >> 8 # see https://threadlocalmutex.com/?p=48
cx16palette = bytearray()
for pi in range(0, len(palette), 3):
r, g, b = palette[pi] >> 4, palette[pi + 1] >> 4, palette[pi + 2] >> 4
r = to4bit(palette[pi])
g = to4bit(palette[pi+1])
b = to4bit(palette[pi+2])
cx16palette.append(g << 4 | b)
cx16palette.append(r)
return cx16palette