Tidy a bit

This commit is contained in:
kris 2021-11-02 12:30:43 +00:00
parent 5675fac40d
commit d442baf1f1
2 changed files with 12 additions and 9 deletions

View File

@ -1,6 +1,5 @@
"""Precomputes all possible colours available via NTSC emulation.""" """Precomputes all possible colours available via NTSC emulation."""
import colour
import numpy as np import numpy as np
from PIL import Image from PIL import Image
import screen import screen
@ -14,6 +13,7 @@ def main():
print("import numpy as np") print("import numpy as np")
print() print()
print("# Indexed by (trailing 8-bit dot pattern, x % 4)")
print("SRGB = {") print("SRGB = {")
# For each sequence of 8 pixels, compute the RGB colour of the right-most # For each sequence of 8 pixels, compute the RGB colour of the right-most
# pixel, using NTSC emulation. # pixel, using NTSC emulation.
@ -21,28 +21,30 @@ def main():
# position with respect to NTSC phase. # position with respect to NTSC phase.
# TODO: should be 3? Do I have a compensating off-by-one in bitmap_to_ntsc? # TODO: should be 3? Do I have a compensating off-by-one in bitmap_to_ntsc?
ntsc_shift = 2 ntsc_shift = 2
for j in range(ntsc_shift, ntsc_shift+4): for j in range(ntsc_shift, ntsc_shift + 4):
bitmap = np.zeros((1, 11+ntsc_shift), dtype=np.bool) bitmap = np.zeros((1, 11 + ntsc_shift), dtype=np.bool)
for bits in range(256): for bits in range(256):
bits8 = np.empty((8,), dtype=np.bool) bits8 = np.empty((8,), dtype=np.bool)
for i in range(8): for i in range(8):
bits8[i] = bits & (1 << i) bits8[i] = bits & (1 << i)
bitmap[0, j:j+8] = bits8 bitmap[0, j:j + 8] = bits8
# bitmap_to_ntsc produces 3 output pixels for each DHGR input
ntsc = s.bitmap_to_ntsc(bitmap) ntsc = s.bitmap_to_ntsc(bitmap)
last_colour = ntsc[0, 3*(j+8)-1, :] last_colour = ntsc[0, 3 * (j + 8) - 1, :]
colours[(bits, j-ntsc_shift)] = last_colour colours[(bits, j - ntsc_shift)] = last_colour
unique.add(tuple(last_colour)) unique.add(tuple(last_colour))
print(" (%d, %d): np.array((%d, %d, %d))," % ( print(" (%d, %d): np.array((%d, %d, %d))," % (
bits, j-ntsc_shift, last_colour[0], last_colour[1], last_colour[2])) bits, j - ntsc_shift, last_colour[0], last_colour[1],
last_colour[2]))
print("}") print("}")
print("# %d unique colours" % len(unique)) print("# %d unique colours" % len(unique))
# Show spectrum of available colours sorted by HSV hue value # Show spectrum of available colours sorted by HSV hue value
im = np.zeros((128*4, 256 * 16, 3), dtype=np.uint8) im = np.zeros((128 * 4, 256 * 16, 3), dtype=np.uint8)
for x, j in colours: for x, j in colours:
im[128*j:128*(j+1), x * 16: (x + 1) * 16, :] = colours[x,j] im[128 * j:128 * (j + 1), x * 16: (x + 1) * 16, :] = colours[x, j]
Image.fromarray(im).show() Image.fromarray(im).show()

View File

@ -1,5 +1,6 @@
import numpy as np import numpy as np
# Indexed by (trailing 8-bit dot pattern, x % 4)
SRGB = { SRGB = {
(0, 0): np.array((0, 0, 0)), (0, 0): np.array((0, 0, 0)),
(1, 0): np.array((0, 37, 0)), (1, 0): np.array((0, 37, 0)),