kopia lustrzana https://github.com/inkstitch/inkstitch
pick the palette with the most exact matches
rodzic
0c60da4bb4
commit
0700817a3b
|
@ -30,6 +30,11 @@ class _ThreadCatalog(Sequence):
|
||||||
def __len__(self):
|
def __len__(self):
|
||||||
return len(self.palettes)
|
return len(self.palettes)
|
||||||
|
|
||||||
|
def _num_exact_color_matches(self, palette, threads):
|
||||||
|
"""Number of colors in stitch plan with an exact match in this palette."""
|
||||||
|
|
||||||
|
return sum(1 for thread in threads if thread in palette)
|
||||||
|
|
||||||
def match_and_apply_palette(self, stitch_plan):
|
def match_and_apply_palette(self, stitch_plan):
|
||||||
"""Figure out which color palette was used and set thread names.
|
"""Figure out which color palette was used and set thread names.
|
||||||
|
|
||||||
|
@ -41,16 +46,13 @@ class _ThreadCatalog(Sequence):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
threads = [color_block.color for color_block in stitch_plan]
|
threads = [color_block.color for color_block in stitch_plan]
|
||||||
|
palettes_and_matches = [(palette, self._num_exact_color_matches(palette, threads))
|
||||||
|
for palette in self]
|
||||||
|
palette, matches = max(palettes_and_matches, key=lambda item: item[1])
|
||||||
|
|
||||||
for palette in self:
|
if matches < 0.8 * len(stitch_plan):
|
||||||
num_matched = sum(1 for thread in threads if thread in palette)
|
# if less than 80% of the colors are an exact match,
|
||||||
if num_matched > (0.8 * len(threads)):
|
# don't use this palette
|
||||||
# Pick this one.
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
# This block will only get run if we ran off the end of the loop
|
|
||||||
# without breaking. No palette had enough colors that exactly
|
|
||||||
# matched, so just do nothing.
|
|
||||||
return
|
return
|
||||||
|
|
||||||
for thread in threads:
|
for thread in threads:
|
||||||
|
|
Ładowanie…
Reference in New Issue