From 9f0cd870e756f0736d1b0dcdf084ca1f70db7b2e Mon Sep 17 00:00:00 2001 From: kris Date: Sat, 16 Jan 2021 18:11:21 +0000 Subject: [PATCH] In 140px resolution show the output image with and without NTSC fringing --- convert.py | 18 ++++++++++++++---- screen.py | 12 ++++++++++++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/convert.py b/convert.py index ff68ec3..9a66879 100644 --- a/convert.py +++ b/convert.py @@ -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)) diff --git a/screen.py b/screen.py index 0d64bee..02ecffb 100644 --- a/screen.py +++ b/screen.py @@ -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