Add a --verbose option to output progress

This commit is contained in:
kris 2021-03-15 15:01:21 +00:00
parent e98116b276
commit f87ca90fd4
2 changed files with 7 additions and 2 deletions

View File

@ -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

View File

@ -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):