Skip to content

Commit

Permalink
Improve feedback
Browse files Browse the repository at this point in the history
give color data, show processing for larger palettes only
  • Loading branch information
glasnt committed Oct 25, 2020
1 parent d92a17b commit 22d1b1b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 3 additions & 1 deletion ih/chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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":
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 4 additions & 2 deletions ih/palette.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -107,7 +110,6 @@ def reduce_palette(palette, image):

first_colours += palette

print("...Done")
return first_colours


Expand Down

0 comments on commit 22d1b1b

Please sign in to comment.