In 140px resolution show the output image with and without NTSC fringing

This commit is contained in:
kris 2021-01-16 18:11:21 +00:00
parent f9f1398969
commit 9f0cd870e7
2 changed files with 26 additions and 4 deletions

View File

@ -14,7 +14,6 @@ import screen as screen_py
# TODO:
# - support alternate palettes properly
# - include fringing in 140px output
# - compare to bmp2dhr and a2bestpix
# - support LR/DLR
# - support HGR
@ -72,15 +71,26 @@ def main():
output_4bit, output_rgb = dither_pyx.dither_image(
screen, resized, dither, lookahead)
print(time.time() - start)
screen.pack(output_4bit)
if args.resolution == 140:
# Show un-fringed 140px output image
out_image = Image.fromarray(image_py.linear_to_srgb(output_rgb).astype(
np.uint8))
if args.show_output:
image_py.resize(out_image, 560, 384, srgb_output=True).show()
bitmap = screen.pack(output_4bit)
output_rgb = screen.bitmap_to_image_rgb(bitmap)
# Show output image
out_image = Image.fromarray(image_py.linear_to_srgb(output_rgb).astype(
np.uint8))
outfile = os.path.join(os.path.splitext(args.output)[0] + ".png")
out_image.save(outfile, "PNG")
if args.show_output:
image_py.resize(out_image, 560, 384, srgb_output=True).show()
outfile = os.path.join(os.path.splitext(args.output)[0] + ".png")
out_image.save(outfile, "PNG")
with open(args.output, "wb") as f:
f.write(bytes(screen.main))
f.write(bytes(screen.aux))

View File

@ -50,6 +50,18 @@ class Screen:
self.aux[addr:addr + 40] = aux_col[y, :]
self.main[addr:addr + 40] = main_col[y, :]
return bitmap
def bitmap_to_image_rgb(self, bitmap: np.ndarray) -> np.ndarray:
image_rgb = np.empty((192, 560, 3), dtype=np.uint8)
for y in range(self.Y_RES):
pixel = [False, False, False, False]
for x in range(560):
pixel[x % 4] = bitmap[y, x]
dots = self.palette.DOTS_TO_4BIT[tuple(pixel)]
image_rgb[y, x, :] = self.palette.RGB[dots]
return image_rgb
def pixel_palette_options(self, last_pixel_4bit, x: int):
raise NotImplementedError