From f87ca90fd48e53b85faf41fe4eb3052c5349ab11 Mon Sep 17 00:00:00 2001 From: kris Date: Mon, 15 Mar 2021 15:01:21 +0000 Subject: [PATCH] Add a --verbose option to output progress --- convert.py | 5 ++++- dither.pyx | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/convert.py b/convert.py index 867524d..318b751 100644 --- a/convert.py +++ b/convert.py @@ -61,6 +61,9 @@ def main(): '--show_palette', type=str, choices=list(palette_py.PALETTES.keys()), help="RGB colour palette to use when --show_output (default: " "value of --palette)") + parser.add_argument( + '--verbose', action=argparse.BooleanOptionalAction, + default=False, help="Show progress during conversion") args = parser.parse_args() palette = palette_py.PALETTES[args.palette]() @@ -88,7 +91,7 @@ def main(): dither = dither_pattern.PATTERNS[args.dither]() output_nbit, _ = dither_pyx.dither_image( - screen, resized, dither, lookahead) + screen, resized, dither, lookahead, args.verbose) bitmap = screen.pack(output_nbit) # Show output image by rendering in target palette diff --git a/dither.pyx b/dither.pyx index 5d3effa..1c28e20 100644 --- a/dither.pyx +++ b/dither.pyx @@ -201,7 +201,7 @@ cdef find_nearest_colour(screen, float[3] pixel_rgb, unsigned char[::1] options_ @cython.boundscheck(False) @cython.wraparound(False) -def dither_image(screen, float[:, :, ::1] image_rgb, dither, int lookahead): +def dither_image(screen, float[:, :, ::1] image_rgb, dither, int lookahead, unsigned char verbose): cdef (unsigned char)[:, ::1] image_nbit = np.empty( (image_rgb.shape[0], image_rgb.shape[1]), dtype=np.uint8) @@ -240,6 +240,8 @@ def dither_image(screen, float[:, :, ::1] image_rgb, dither, int lookahead): cdither.pattern[i * cdither.x_shape + j] = dither.PATTERN[i, j, 0] for y in range(yres): + if verbose: + print("%d/%d" % (y, yres)) output_pixel_nbit = 0 for x in range(xres): for i in range(3):