mirror of
https://github.com/KrisKennaway/ii-pix.git
synced 2024-06-12 16:29:28 +00:00
Tidy
This commit is contained in:
parent
e84dfb59f9
commit
9dbf413733
1
image.py
1
image.py
|
@ -1,6 +1,5 @@
|
||||||
"""Image transformation functions."""
|
"""Image transformation functions."""
|
||||||
|
|
||||||
import colour
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
|
|
24
palette.py
24
palette.py
|
@ -25,11 +25,31 @@ class Palette:
|
||||||
self.CAM16UCS[k] = colour.convert(
|
self.CAM16UCS[k] = colour.convert(
|
||||||
v / 255, "sRGB", "CAM16UCS").astype(np.float32)
|
v / 255, "sRGB", "CAM16UCS").astype(np.float32)
|
||||||
|
|
||||||
def pixels_to_idx(self, pixels: np.array) -> int:
|
def _pixel_phase_shifts(self, phase_0_rgb):
|
||||||
|
rgb_phases = {}
|
||||||
|
for pixels, rgb in phase_0_rgb.items():
|
||||||
|
rgb_phases[pixels, 0] = rgb
|
||||||
|
for phase in range(1, 4):
|
||||||
|
msb = pixels & (1 << (self.PALETTE_DEPTH - 1))
|
||||||
|
pixels <<= 1 | (msb >> (self.PALETTE_DEPTH - 1))
|
||||||
|
rgb_phases[pixels, phase] = rgb
|
||||||
|
return rgb_phases
|
||||||
|
|
||||||
|
def bitmap_to_idx(self, pixels: np.array) -> int:
|
||||||
|
"""Converts a bitmap of pixels into integer representation.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
pixels: 1-D array of booleans, representing a window of pixels from
|
||||||
|
L to R. Must be of size <= 8
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
8-bit integer representation of pixels, suitable for use as an
|
||||||
|
index into palette arrays
|
||||||
|
"""
|
||||||
return np.packbits(
|
return np.packbits(
|
||||||
# numpy uses big-endian representation which is the opposite
|
# numpy uses big-endian representation which is the opposite
|
||||||
# order to screen representation (i.e. LSB is the left-most
|
# order to screen representation (i.e. LSB is the left-most
|
||||||
# screen pixel)
|
# screen pixel), so we need to flip the order
|
||||||
np.flip(pixels, axis=0)
|
np.flip(pixels, axis=0)
|
||||||
)[0]
|
)[0]
|
||||||
|
|
||||||
|
|
|
@ -59,13 +59,13 @@ class DHGRScreen:
|
||||||
"""
|
"""
|
||||||
image_rgb = np.empty((self.Y_RES, self.X_RES, 3), dtype=np.uint8)
|
image_rgb = np.empty((self.Y_RES, self.X_RES, 3), dtype=np.uint8)
|
||||||
for y in range(self.Y_RES):
|
for y in range(self.Y_RES):
|
||||||
pixels = [False] * self.palette.PALETTE_DEPTH
|
bitmap_window = [False] * self.palette.PALETTE_DEPTH
|
||||||
for x in range(self.X_RES):
|
for x in range(self.X_RES):
|
||||||
# Maintain a sliding window of pixels of width PALETTE_DEPTH
|
# Maintain a sliding window of pixels of width PALETTE_DEPTH
|
||||||
pixels = pixels[1:] + [bitmap[y, x]]
|
bitmap_window = bitmap_window[1:] + [bitmap[y, x]]
|
||||||
image_rgb[y, x, :] = self.palette.RGB[
|
image_rgb[y, x, :] = self.palette.RGB[
|
||||||
self.palette.pixels_to_idx(
|
self.palette.bitmap_to_idx(
|
||||||
np.array(pixels, dtype=bool)), x % 4]
|
np.array(bitmap_window, dtype=bool)), x % 4]
|
||||||
return image_rgb
|
return image_rgb
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|
Loading…
Reference in New Issue
Block a user