quantize/no-quantize option for color reduction

This commit is contained in:
Gordon Shumway 2019-08-27 19:22:58 -04:00 committed by GitHub
parent bffd68f227
commit c64fe6ab25
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 3 deletions

View File

@ -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):
"""[<channel>] [--delay] <url>