From 22d1b1ba8815d248a4979a77b2b5bd94ee77070f Mon Sep 17 00:00:00 2001 From: Katie McLaughlin Date: Sun, 25 Oct 2020 19:03:15 +1100 Subject: [PATCH] Improve feedback give color data, show processing for larger palettes only --- ih/chart.py | 4 +++- ih/palette.py | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/ih/chart.py b/ih/chart.py index f9b7cae..c86c3dc 100644 --- a/ih/chart.py +++ b/ih/chart.py @@ -28,7 +28,7 @@ GUIDECOL = (0, 0, 0, 0) -def debug_data(image_name, scale, palette_name, chartimage, fileformat="html"): +def debug_data(image_name, scale, colors, palette_name, chartimage, fileformat="html"): import pkg_resources ih_version = pkg_resources.require("ih")[0].version @@ -37,6 +37,7 @@ def debug_data(image_name, scale, palette_name, chartimage, fileformat="html"): f"Scale: {scale}x", f"Image size: {chartimage.height} x {chartimage.width}", f"Palette: {palette_name}", + f"Colors: {colors}", f"ih version: {ih_version}", ] if fileformat == "html": @@ -339,6 +340,7 @@ def chart( data = debug_data( image_name=image_name, scale=scale, + colors=colors, palette_name=palette_name, chartimage=chartimage, fileformat=fileformat, diff --git a/ih/palette.py b/ih/palette.py index d680881..547b3f6 100644 --- a/ih/palette.py +++ b/ih/palette.py @@ -87,12 +87,15 @@ def reduce_palette(palette, image): if len(palette) <= 256: return palette - print("Evaluating best colour selection...") palette_triplets = [x["rgb"] for x in palette] best_colours = set() # Get image palette in RGB triplets my_colours = [x[0:3] for x in image.getdata()] + + # Larger palettes may take some time, so let 'em know. + if len(my_colours) > 12: + print("Processing...") # Get nearest colour https://stackoverflow.com/a/22478139 tree = sp.KDTree(palette_triplets) for colour in my_colours: @@ -107,7 +110,6 @@ def reduce_palette(palette, image): first_colours += palette - print("...Done") return first_colours