speed up color matching
This commit is contained in:
parent
bc114af113
commit
14ae1a679e
|
|
@ -42,6 +42,8 @@ class ASCII(callbacks.Plugin):
|
|||
self.__parent = super(ASCII, self)
|
||||
self.__parent.__init__(irc)
|
||||
self.colors = 83
|
||||
self.matches = {}
|
||||
self.matches16 = {}
|
||||
self.ircColors= {
|
||||
(11.5497, 31.8768, 18.1739):16,
|
||||
(17.5866, 15.7066, 25.9892):17,
|
||||
|
|
@ -202,18 +204,23 @@ class ASCII(callbacks.Plugin):
|
|||
"""
|
||||
Given PIL Image, return average RGB value
|
||||
"""
|
||||
pixel = tuple(pixel)
|
||||
if self.colors == 16:
|
||||
speed = speed
|
||||
colors = list(self.colors16.keys())
|
||||
closest_colors = sorted(colors, key=lambda color: self.distance(self.rgb2lab(color), self.rgb2lab(pixel), speed))
|
||||
closest_color = closest_colors[0]
|
||||
return self.colors16[closest_color]
|
||||
if pixel not in self.matches16:
|
||||
closest_colors = sorted(colors, key=lambda color: self.distance(self.rgb2lab(color), self.rgb2lab(pixel), speed))
|
||||
closest_color = closest_colors[0]
|
||||
self.matches16[pixel] = self.colors16[closest_color]
|
||||
return self.matches16[pixel]
|
||||
else:
|
||||
speed = speed
|
||||
colors = list(self.ircColors.keys())
|
||||
closest_colors = sorted(colors, key=lambda color: self.distance(color, self.rgb2lab(pixel), speed))
|
||||
closest_color = closest_colors[0]
|
||||
return self.ircColors[closest_color]
|
||||
if pixel not in self.matches:
|
||||
closest_colors = sorted(colors, key=lambda color: self.distance(color, self.rgb2lab(pixel), speed))
|
||||
closest_color = closest_colors[0]
|
||||
self.matches[pixel] = self.ircColors[closest_color]
|
||||
return self.matches[pixel]
|
||||
|
||||
def rgb2lab (self, inputColor) :
|
||||
num = 0
|
||||
|
|
|
|||
Loading…
Reference in New Issue