From 536dce6a985718a55237f475b2d31be6f0b93449 Mon Sep 17 00:00:00 2001 From: Jared Miller Date: Thu, 12 Feb 2026 21:10:39 -0500 Subject: [PATCH] Use set for O(1) palette color deduplication --- playscii/palette.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/playscii/palette.py b/playscii/palette.py index 812f2ef..d3a77af 100644 --- a/playscii/palette.py +++ b/playscii/palette.py @@ -72,6 +72,7 @@ class Palette: # scan image L->R T->B for unique colors, store em as tuples # color 0 is always fully transparent self.colors = [(0, 0, 0, 0)] + seen = {(0, 0, 0, 0)} # determine lightest and darkest colors in palette for defaults lightest = 0 darkest = 255 * 3 + 1 @@ -82,7 +83,8 @@ class Palette: if len(self.colors) >= MAX_COLORS: break color = src_img.getpixel((x, y)) - if color not in self.colors: + if color not in seen: + seen.add(color) self.colors.append(color) # is this lightest/darkest unique color so far? save index luminosity = color[0] * 0.21 + color[1] * 0.72 + color[2] * 0.07