From c64fe6ab259d8abc4b96e37a8a046ce43eb6f24b Mon Sep 17 00:00:00 2001 From: Gordon Shumway <39967334+oddluck@users.noreply.github.com> Date: Tue, 27 Aug 2019 19:22:58 -0400 Subject: [PATCH] quantize/no-quantize option for color reduction --- ASCII/plugin.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/ASCII/plugin.py b/ASCII/plugin.py index 6739d9d..104fb20 100644 --- a/ASCII/plugin.py +++ b/ASCII/plugin.py @@ -827,6 +827,12 @@ class ASCII(callbacks.Plugin): speed = 'dithered' else: dither = False + if 'quantize' in optlist: + quantize = True + elif 'no-quantize' in optlist: + quantize = False + else: + quantize = self.registryValue('quantize', msg.args[0]) if 'bg' in optlist: bg = optlist.get('bg') else: @@ -923,8 +929,8 @@ class ASCII(callbacks.Plugin): if dither: image2 = hitherdither.diffusion.error_diffusion_dithering(image2, self.palette, method=dither) image2 = image2.convert('RGB') - elif 'no-dither' not in optlist: - image2 = image2.convert('P', palette=Image.ADAPTIVE) + elif quantize: + image2 = image2.quantize(method=1, dither=None) image2 = image2.convert('RGB') colormap = np.array(image2) self.matches = {} @@ -1244,7 +1250,7 @@ class ASCII(callbacks.Plugin): irc.reply(line, prefixNick=False, noLengthCheck=True, private=False, notice=False, to=channel) if self.registryValue('pasteEnable', msg.args[0]): irc.reply(self.doPaste(url, paste), private=False, notice=False, to=channel) - img = wrap(img,[optional('channel'), getopts({'w':'int', 'invert':'', 'fast':'', 'slow':'', '16':'', '99':'', '83':'', 'delay':'float', 'dither':'text', 'no-dither':'', 'chars':'text', 'bg':'int', 'fg':'int', 'ramp':'text', 'no-color':'', 'block':'', 'ascii':'', '1/4':'', '1/2':'', 's':'float', 'tops':''}), ('text')]) + img = wrap(img,[optional('channel'), getopts({'w':'int', 'invert':'', 'fast':'', 'slow':'', '16':'', '99':'', '83':'', 'delay':'float', 'dither':'text', 'quantize':'', 'no-quantize':'', 'chars':'text', 'bg':'int', 'fg':'int', 'ramp':'text', 'no-color':'', 'block':'', 'ascii':'', '1/4':'', '1/2':'', 's':'float', 'tops':''}), ('text')]) def scroll(self, irc, msg, args, channel, optlist, url): """[] [--delay]