TextArt: move color maps out of init

This commit is contained in:
oddluck 2020-03-04 23:38:37 +00:00
parent ede1181df5
commit b2f2fad10f

View File

@ -68,337 +68,6 @@ class TextArt(callbacks.Plugin):
self.old_color = None
self.source_colors = 0
self.agents = self.registryValue("userAgents")
self.rgbColors = [
(255,255,255),
(0,0,0),
(0,0,127),
(0,147,0),
(255,0,0),
(127,0,0),
(156,0,156),
(252,127,0),
(255,255,0),
(0,252,0),
(0,147,147),
(0,255,255),
(0,0,252),
(255,0,255),
(127,127,127),
(210,210,210),
(71,0,0),
(71,33,0),
(71,71,0),
(50,71,0),
(0,71,0),
(0,71,44),
(0,71,71),
(0,39,71),
(0,0,71),
(46,0,71),
(71,0,71),
(71,0,42),
(116,0,0),
(116,58,0),
(116,116,0),
(81,116,0),
(0,116,0),
(0,116,73),
(0,116,116),
(0,64,116),
(0,0,116),
(75,0,116),
(116,0,116),
(116,0,69),
(181,0,0),
(181,99,0),
(181,181,0),
(125,181,0),
(0,181,0),
(0,181,113),
(0,181,181),
(0,99,181),
(0,0,181),
(117,0,181),
(181,0,181),
(181,0,107),
(255,0,0),
(255,140,0),
(255,255,0),
(178,255,0),
(0,255,0),
(0,255,160),
(0,255,255),
(0,140,255),
(0,0,255),
(165,0,255),
(255,0,255),
(255,0,152),
(255,89,89),
(255,180,89),
(255,255,113),
(207,255,96),
(111,255,111),
(101,255,201),
(109,255,255),
(89,180,255),
(89,89,255),
(196,89,255),
(255,102,255),
(255,89,188),
(255,156,156),
(255,211,156),
(255,255,156),
(226,255,156),
(156,255,156),
(156,255,219),
(156,255,255),
(156,211,255),
(156,156,255),
(220,156,255),
(255,156,255),
(255,148,211),
(0,0,0),
(19,19,19),
(40,40,40),
(54,54,54),
(77,77,77),
(101,101,101),
(129,129,129),
(159,159,159),
(188,188,188),
(226,226,226),
(255,255,255)]
self.colors83= {
(11.5497, 31.8768, 18.1739):16,
(17.5866, 15.7066, 25.9892):17,
(29.0208, -8.5776, 37.5533):18,
(27.2543, -19.015, 35.3673):19,
(25.2798, -34.2963, 32.8426):20,
(25.8276, -27.5812, 10.7515):21,
(26.6245, -19.1316, -5.6261):22,
(14.986, 1.2467, -23.6473):23,
(4.1091, 27.6851, -41.3905):24,
(9.2862, 34.8709, -32.6869):25,
(14.3696, 39.0991, -24.2113):26,
(12.6512, 34.8073, -6.066):27,
(22.699, 44.779, 34.3145):28,
(31.2054, 21.9979, 41.7676):29,
(47.2407, -12.0488, 52.8125):30,
(44.5753, -27.9355, 49.6338):31,
(41.9858, -48.1745, 46.4957):32,
(42.7207, -39.1444, 16.0528):33,
(43.8747, -26.8746, -7.9028):34,
(26.5278, 3.8603, -34.8152):35,
(11.0, 44.2673, -60.2918):36,
(19.0423, 48.637, -46.7161):37,
(26.6606, 54.9202, -34.0091):38,
(24.1377, 48.6121, -6.8774):39,
(37.5243, 61.9327, 51.9413):40,
(50.3904, 27.7338, 58.553):41,
(71.4677, -16.6651, 73.0447):42,
(67.5818, -39.987, 68.408):43,
(64.1995, -66.6294, 64.3075):44,
(65.1526, -54.8772, 23.9922):45,
(66.8122, -37.1703, -10.9303):46,
(41.6262, 7.9137, -50.0682):47,
(21.343, 61.2273, -83.3898):48,
(32.0743, 66.9878, -65.2716):49,
(43.0033, 75.9603, -47.0378):50,
(39.3866, 66.9043, -7.4929):51,
(53.2329, 80.1093, 67.2201):52,
(69.4811, 36.8308, 75.4949):53,
(97.1382, -21.5559, 94.4825):54,
(92.125, -51.6335, 88.501):55,
(87.737, -86.1846, 83.1812):56,
(88.9499, -71.2147, 31.6061):57,
(91.1165, -48.0796, -14.1381):58,
(58.0145, 11.3842, -65.6058):59,
(32.3026, 79.1967, -107.8637):60,
(45.9331, 86.4699, -84.8483):61,
(60.3199, 98.2542, -60.843):62,
(55.6111, 86.4597, -9.1916):63,
(60.8927, 62.8729, 35.0702):64,
(78.8241, 18.6736, 56.0796):65,
(97.6208, -17.6977, 66.4162):66,
(94.1539, -37.4631, 68.7023):67,
(89.8813, -66.1541, 56.3842):68,
(91.0093, -53.1765, 13.8066):69,
(92.571, -38.7824, -11.8131):70,
(70.8615, -4.4808, -45.0866):71,
(47.6091, 49.3215, -82.3961):72,
(58.1323, 68.3853, -64.8302):73,
(68.0079, 76.2368, -48.6298):74,
(63.3723, 71.7112, -18.3923):75,
(74.4686, 36.8822, 15.7988):76,
(87.1187, 8.2035, 33.0227):77,
(98.1056, -13.9188, 47.2642):78,
(96.0337, -24.7493, 44.2003):79,
(92.1264, -48.2196, 38.3812):80,
(93.3211, -36.9827, 8.0947):81,
(94.2302, -28.9926, -9.1665):82,
(82.3123, -6.9657, -27.1167):83,
(68.0684, 23.3938, -49.2364):84,
(73.6833, 41.0464, -40.0349):85,
(77.4342, 51.3197, -33.9217):86,
(74.2811, 48.1595, -14.7725):87,
(0.0, 0.0, 0.0):88,
(5.8822, 0.0022, -0.0022):89,
(16.1144, 0.0022, -0.0033):90,
(22.6151, 0.0018, -0.004):91,
(32.7476, 0.0018, -0.0044):92,
(42.7837, 0.0032, -0.0055):93,
(53.9767, 0.0034, -0.0063):94,
(65.4912, 0.0036, -0.0074):95,
(76.2461, 0.0044, -0.0083):96,
(89.8837, 0.0048, -0.0094):97,
(100.0, 0.0053, -0.0104):98}
self.colors16 = {
(100.0, 0.0053, -0.0104):0,
(0.0, 0.0, 0.0):1,
(12.8119, 47.2407, -64.3396):2,
(52.8041, -57.1624, 55.1703):3,
(53.2329, 80.1093, 67.2201):4,
(25.2966, 47.7847, 37.7562):5,
(36.8705, 68.0659, -42.1489):6,
(66.4237, 42.1616, 73.4335):7,
(97.1382, -21.5559, 94.4825):8,
(86.8105, -85.4149, 82.4382):9,
(55.0455, -31.8888, -9.3772):10,
(91.1165, -48.0796, -14.1381):11,
(31.8712, 78.4892, -106.9003):12,
(60.3199, 98.2542, -60.843):13,
(53.1928, 0.0029, -0.0061):14,
(84.1985, 0.0045, -0.0089):15}
self.colors99= {
(100.0, 0.0053, -0.0104):0,
(0.0, 0.0, 0.0):1,
(12.8119, 47.2407, -64.3396):2,
(52.8041, -57.1624, 55.1703):3,
(53.2329, 80.1093, 67.2201):4,
(25.2966, 47.7847, 37.7562):5,
(36.8705, 68.0659, -42.1489):6,
(66.4237, 42.1616, 73.4335):7,
(97.1382, -21.5559, 94.4825):8,
(86.8105, -85.4149, 82.4382):9,
(55.0455, -31.8888, -9.3772):10,
(91.1165, -48.0796, -14.1381):11,
(31.8712, 78.4892, -106.9003):12,
(60.3199, 98.2542, -60.843):13,
(53.1928, 0.0029, -0.0061):14,
(84.1985, 0.0045, -0.0089):15,
(11.5497, 31.8768, 18.1739):16,
(17.5866, 15.7066, 25.9892):17,
(29.0208, -8.5776, 37.5533):18,
(27.2543, -19.015, 35.3673):19,
(25.2798, -34.2963, 32.8426):20,
(25.8276, -27.5812, 10.7515):21,
(26.6245, -19.1316, -5.6261):22,
(14.986, 1.2467, -23.6473):23,
(4.1091, 27.6851, -41.3905):24,
(9.2862, 34.8709, -32.6869):25,
(14.3696, 39.0991, -24.2113):26,
(12.6512, 34.8073, -6.066):27,
(22.699, 44.779, 34.3145):28,
(31.2054, 21.9979, 41.7676):29,
(47.2407, -12.0488, 52.8125):30,
(44.5753, -27.9355, 49.6338):31,
(41.9858, -48.1745, 46.4957):32,
(42.7207, -39.1444, 16.0528):33,
(43.8747, -26.8746, -7.9028):34,
(26.5278, 3.8603, -34.8152):35,
(11.0, 44.2673, -60.2918):36,
(19.0423, 48.637, -46.7161):37,
(26.6606, 54.9202, -34.0091):38,
(24.1377, 48.6121, -6.8774):39,
(37.5243, 61.9327, 51.9413):40,
(50.3904, 27.7338, 58.553):41,
(71.4677, -16.6651, 73.0447):42,
(67.5818, -39.987, 68.408):43,
(64.1995, -66.6294, 64.3075):44,
(65.1526, -54.8772, 23.9922):45,
(66.8122, -37.1703, -10.9303):46,
(41.6262, 7.9137, -50.0682):47,
(21.343, 61.2273, -83.3898):48,
(32.0743, 66.9878, -65.2716):49,
(43.0033, 75.9603, -47.0378):50,
(39.3866, 66.9043, -7.4929):51,
(69.4811, 36.8308, 75.4949):53,
(92.125, -51.6335, 88.501):55,
(87.737, -86.1846, 83.1812):56,
(88.9499, -71.2147, 31.6061):57,
(58.0145, 11.3842, -65.6058):59,
(32.3026, 79.1967, -107.8637):60,
(45.9331, 86.4699, -84.8483):61,
(55.6111, 86.4597, -9.1916):63,
(60.8927, 62.8729, 35.0702):64,
(78.8241, 18.6736, 56.0796):65,
(97.6208, -17.6977, 66.4162):66,
(94.1539, -37.4631, 68.7023):67,
(89.8813, -66.1541, 56.3842):68,
(91.0093, -53.1765, 13.8066):69,
(92.571, -38.7824, -11.8131):70,
(70.8615, -4.4808, -45.0866):71,
(47.6091, 49.3215, -82.3961):72,
(58.1323, 68.3853, -64.8302):73,
(68.0079, 76.2368, -48.6298):74,
(63.3723, 71.7112, -18.3923):75,
(74.4686, 36.8822, 15.7988):76,
(87.1187, 8.2035, 33.0227):77,
(98.1056, -13.9188, 47.2642):78,
(96.0337, -24.7493, 44.2003):79,
(92.1264, -48.2196, 38.3812):80,
(93.3211, -36.9827, 8.0947):81,
(94.2302, -28.9926, -9.1665):82,
(82.3123, -6.9657, -27.1167):83,
(68.0684, 23.3938, -49.2364):84,
(73.6833, 41.0464, -40.0349):85,
(77.4342, 51.3197, -33.9217):86,
(74.2811, 48.1595, -14.7725):87,
(5.8822, 0.0022, -0.0022):89,
(16.1144, 0.0022, -0.0033):90,
(22.6151, 0.0018, -0.004):91,
(32.7476, 0.0018, -0.0044):92,
(42.7837, 0.0032, -0.0055):93,
(53.9767, 0.0034, -0.0063):94,
(65.4912, 0.0036, -0.0074):95,
(76.2461, 0.0044, -0.0083):96,
(89.8837, 0.0048, -0.0094):97}
self.x256colors99 = ['01','05','32','30','02','38','34','96','94','04','56','08','60','13','11','00','01','36','02','48','48','60','32','34','47','47','47','72','03','33','10','59','59','59','44','45','45','46','71','71','09','68','45','69','46','83','56','68','57','57','69','11','28','38','37','49','49','60','30','93','47','72','72','72','31','33','10','59','59','59','43','45','45','46','71','71','09','68','57','69','70','83','56','68','68','57','69','70','05','39','38','49','49','61','41','93','50','50','72','72','30','30','94','84','84','84','43','43','45','46','71','71','43','68','80','81','82','83','55','68','68','80','81','70','40','51','06','50','50','61','41','64','63','50','73','73','30','41','76','87','85','84','42','42','95','96','84','84','55','67','79','81','82','83','55','67','80','80','81','82','40','51','51','50','50','73','41','64','63','75','13','73','53','07','76','87','85','85','42','65','77','76','87','85','42','66','78','78','15','97','55','67','79','79','81','82','04','64','63','63','13','13','07','64','63','75','75','74','53','64','76','87','87','86','65','65','65','76','87','86','08','77','77','77','97','86','08','66','66','78','78','00','01','89','89','90','91','91','92','92','92','93','93','14','94','94','95','95','95','96','96','96','15','97','97','97']
self.x256colors16 = ['01','05','03','03','02','06','10','15','14','04','09','08','12','13','11','00','01','02','02','02','12','12','03','10','12','12','12','12','03','10','10','10','14','14','03','03','10','10','10','10','09','09','09','11','11','11','09','09','09','09','11','11','05','06','02','12','12','12','03','14','14','12','12','12','03','03','10','14','14','14','03','03','10','10','10','15','09','09','09','11','11','11','09','09','09','09','11','11','05','06','06','06','06','12','14','14','06','06','06','13','03','14','14','14','14','13','03','03','03','11','11','11','09','09','09','11','11','11','09','09','09','09','11','11','05','06','06','06','06','06','07','04','06','13','13','13','07','07','14','14','13','13','08','08','15','15','15','15','08','09','09','15','15','15','09','09','09','09','11','11','04','06','06','06','13','13','07','04','13','13','13','13','07','07','04','13','13','13','08','07','07','15','15','13','08','08','08','15','15','15','08','08','08','09','00','00','04','04','13','13','13','13','07','04','13','13','13','13','07','07','04','13','13','13','07','07','07','15','15','13','08','08','08','15','15','15','08','08','08','08','00','00','01','01','01','01','01','01','01','14','14','14','14','14','14','14','14','14','15','15','15','15','15','15','15','00']
self.x256colors83 = ['88','28','32','30','36','38','34','96','94','52','56','54','60','62','58','98','88','36','36','48','48','60','32','34','47','47','47','72','32','33','34','59','59','59','44','45','45','46','71','71','44','68','45','69','46','83','56','68','57','57','69','58','28','38','37','49','49','60','30','93','47','72','72','72','31','33','34','59','59','59','43','45','45','46','71','71','56','68','57','69','70','83','56','68','68','57','69','70','28','39','38','49','49','61','41','93','50','50','72','72','30','30','94','84','84','84','43','43','45','46','71','71','43','68','80','81','82','83','55','68','68','80','81','70','40','51','51','50','50','61','41','64','63','50','73','73','30','41','76','87','85','84','42','42','95','96','84','84','55','67','79','81','82','83','55','67','80','80','81','82','40','51','51','50','50','73','41','64','63','75','62','73','53','53','76','87','85','85','42','65','77','76','87','85','42','66','78','78','97','97','55','67','79','79','81','82','52','64','63','63','62','62','52','64','63','75','75','74','53','64','76','87','87','86','65','65','65','76','87','86','54','77','77','77','97','86','54','66','66','78','78','98','88','89','89','90','91','91','92','92','92','93','93','94','94','94','95','95','95','96','96','96','97','97','97','97']
self.x16colors = {
'30':'01',
'31':'05',
'32':'03',
'33':'07',
'34':'02',
'35':'06',
'36':'10',
'37':'15',
'30;1':'14',
'31;1':'04',
'32;1':'09',
'33;1':'08',
'34;1':'12',
'35;1':'13',
'36;1':'11',
'37;1':'00',
'40':'01',
'41':'05',
'42':'03',
'43':'07',
'44':'02',
'45':'06',
'46':'10',
'47':'15',
'40;1':'14',
'41;1':'04',
'42;1':'09',
'43;1':'08',
'44;1':'12',
'45;1':'13',
'46;1':'11',
'47;1':'00'}
def doPrivmsg(self, irc, msg):
channel = msg.args[0]
@ -424,6 +93,7 @@ class TextArt(callbacks.Plugin):
text = text.decode('utf-8')
except:
pass
rgbColors = [(255,255,255), (0,0,0), (0,0,127), (0,147,0), (255,0,0), (127,0,0), (156,0,156), (252,127,0), (255,255,0), (0,252,0), (0,147,147), (0,255,255), (0,0,252), (255,0,255), (127,127,127), (210,210,210), (71,0,0), (71,33,0), (71,71,0), (50,71,0), (0,71,0), (0,71,44), (0,71,71), (0,39,71), (0,0,71), (46,0,71), (71,0,71), (71,0,42), (116,0,0), (116,58,0), (116,116,0), (81,116,0), (0,116,0), (0,116,73), (0,116,116), (0,64,116), (0,0,116), (75,0,116), (116,0,116), (116,0,69), (181,0,0), (181,99,0), (181,181,0), (125,181,0), (0,181,0), (0,181,113), (0,181,181), (0,99,181), (0,0,181), (117,0,181), (181,0,181), (181,0,107), (255,0,0), (255,140,0), (255,255,0), (178,255,0), (0,255,0), (0,255,160), (0,255,255), (0,140,255), (0,0,255), (165,0,255), (255,0,255), (255,0,152), (255,89,89), (255,180,89), (255,255,113), (207,255,96), (111,255,111), (101,255,201), (109,255,255), (89,180,255), (89,89,255), (196,89,255), (255,102,255), (255,89,188), (255,156,156), (255,211,156), (255,255,156), (226,255,156), (156,255,156), (156,255,219), (156,255,255), (156,211,255), (156,156,255), (220,156,255), (255,156,255), (255,148,211), (0,0,0), (19,19,19), (40,40,40), (54,54,54), (77,77,77), (101,101,101), (129,129,129), (159,159,159), (188,188,188), (226,226,226), (255,255,255)]
text = text.replace('\t', ' ')
self.strip_colors_regex = re.compile('(\x03([0-9]{1,2})(,[0-9]{1,2})?)|[\x0f\x02\x1f\x03\x16]').sub
path = os.path.dirname(os.path.abspath(__file__))
@ -438,7 +108,7 @@ class TextArt(callbacks.Plugin):
fontX = 10
fontY = 20
imageX, imageY = maxWidth * fontX, height * fontY
image = Image.new('RGB', (imageX, imageY), self.rgbColors[defaultBg])
image = Image.new('RGB', (imageX, imageY), rgbColors[defaultBg])
draw = ImageDraw.Draw(image)
dtext, drect, match, x, y, fg, bg = draw.text, draw.rectangle, _colorRegex.match, 0, 0, defaultFg, defaultBg
start = time.time()
@ -459,9 +129,9 @@ class TextArt(callbacks.Plugin):
fg, bg = defaultFg, defaultBg
elif chr not in IGNORE_CHRS:
if bg != defaultBg: # bg is not white, render it
drect((x, y, x+fontX, y+fontY), fill=self.rgbColors[bg])
drect((x, y, x+fontX, y+fontY), fill = rgbColors[bg])
if bg != fg: # text will show, render it. this saves a lot of time!
dtext((x, y), chr, font=font, fill=self.rgbColors[fg])
dtext((x, y), chr, font=font, fill = rgbColors[fg])
x += fontX
i += 1
y += fontY
@ -474,19 +144,22 @@ class TextArt(callbacks.Plugin):
return self.matches[pixel]
except KeyError:
if self.colors == 16:
colors = list(self.colors16.keys())
colors16 = {(100.0, 0.0053, -0.0104):0, (0.0, 0.0, 0.0):1, (12.8119, 47.2407, -64.3396):2, (52.8041, -57.1624, 55.1703):3, (53.2329, 80.1093, 67.2201):4, (25.2966, 47.7847, 37.7562):5, (36.8705, 68.0659, -42.1489):6, (66.4237, 42.1616, 73.4335):7, (97.1382, -21.5559, 94.4825):8, (86.8105, -85.4149, 82.4382):9, (55.0455, -31.8888, -9.3772):10, (91.1165, -48.0796, -14.1381):11, (31.8712, 78.4892, -106.9003):12, (60.3199, 98.2542, -60.843):13, (53.1928, 0.0029, -0.0061):14, (84.1985, 0.0045, -0.0089):15}
colors = list(colors16.keys())
elif self.colors == 99:
colors = list(self.colors99.keys())
colors99= {(100.0, 0.0053, -0.0104):0, (0.0, 0.0, 0.0):1, (12.8119, 47.2407, -64.3396):2, (52.8041, -57.1624, 55.1703):3, (53.2329, 80.1093, 67.2201):4, (25.2966, 47.7847, 37.7562):5, (36.8705, 68.0659, -42.1489):6, (66.4237, 42.1616, 73.4335):7, (97.1382, -21.5559, 94.4825):8, (86.8105, -85.4149, 82.4382):9, (55.0455, -31.8888, -9.3772):10, (91.1165, -48.0796, -14.1381):11, (31.8712, 78.4892, -106.9003):12, (60.3199, 98.2542, -60.843):13, (53.1928, 0.0029, -0.0061):14, (84.1985, 0.0045, -0.0089):15, (11.5497, 31.8768, 18.1739):16, (17.5866, 15.7066, 25.9892):17, (29.0208, -8.5776, 37.5533):18, (27.2543, -19.015, 35.3673):19, (25.2798, -34.2963, 32.8426):20, (25.8276, -27.5812, 10.7515):21, (26.6245, -19.1316, -5.6261):22, (14.986, 1.2467, -23.6473):23, (4.1091, 27.6851, -41.3905):24, (9.2862, 34.8709, -32.6869):25, (14.3696, 39.0991, -24.2113):26, (12.6512, 34.8073, -6.066):27, (22.699, 44.779, 34.3145):28, (31.2054, 21.9979, 41.7676):29, (47.2407, -12.0488, 52.8125):30, (44.5753, -27.9355, 49.6338):31, (41.9858, -48.1745, 46.4957):32, (42.7207, -39.1444, 16.0528):33, (43.8747, -26.8746, -7.9028):34, (26.5278, 3.8603, -34.8152):35, (11.0, 44.2673, -60.2918):36, (19.0423, 48.637, -46.7161):37, (26.6606, 54.9202, -34.0091):38, (24.1377, 48.6121, -6.8774):39, (37.5243, 61.9327, 51.9413):40, (50.3904, 27.7338, 58.553):41, (71.4677, -16.6651, 73.0447):42, (67.5818, -39.987, 68.408):43, (64.1995, -66.6294, 64.3075):44, (65.1526, -54.8772, 23.9922):45, (66.8122, -37.1703, -10.9303):46, (41.6262, 7.9137, -50.0682):47, (21.343, 61.2273, -83.3898):48, (32.0743, 66.9878, -65.2716):49, (43.0033, 75.9603, -47.0378):50, (39.3866, 66.9043, -7.4929):51, (69.4811, 36.8308, 75.4949):53, (92.125, -51.6335, 88.501):55, (87.737, -86.1846, 83.1812):56, (88.9499, -71.2147, 31.6061):57, (58.0145, 11.3842, -65.6058):59, (32.3026, 79.1967, -107.8637):60, (45.9331, 86.4699, -84.8483):61, (55.6111, 86.4597, -9.1916):63, (60.8927, 62.8729, 35.0702):64, (78.8241, 18.6736, 56.0796):65, (97.6208, -17.6977, 66.4162):66, (94.1539, -37.4631, 68.7023):67, (89.8813, -66.1541, 56.3842):68, (91.0093, -53.1765, 13.8066):69, (92.571, -38.7824, -11.8131):70, (70.8615, -4.4808, -45.0866):71, (47.6091, 49.3215, -82.3961):72, (58.1323, 68.3853, -64.8302):73, (68.0079, 76.2368, -48.6298):74, (63.3723, 71.7112, -18.3923):75, (74.4686, 36.8822, 15.7988):76, (87.1187, 8.2035, 33.0227):77, (98.1056, -13.9188, 47.2642):78, (96.0337, -24.7493, 44.2003):79, (92.1264, -48.2196, 38.3812):80, (93.3211, -36.9827, 8.0947):81, (94.2302, -28.9926, -9.1665):82, (82.3123, -6.9657, -27.1167):83, (68.0684, 23.3938, -49.2364):84, (73.6833, 41.0464, -40.0349):85, (77.4342, 51.3197, -33.9217):86, (74.2811, 48.1595, -14.7725):87, (5.8822, 0.0022, -0.0022):89, (16.1144, 0.0022, -0.0033):90, (22.6151, 0.0018, -0.004):91, (32.7476, 0.0018, -0.0044):92, (42.7837, 0.0032, -0.0055):93, (53.9767, 0.0034, -0.0063):94, (65.4912, 0.0036, -0.0074):95, (76.2461, 0.0044, -0.0083):96, (89.8837, 0.0048, -0.0094):97}
colors = list(colors99.keys())
else:
colors = list(self.colors83.keys())
colors83 = {(11.5497, 31.8768, 18.1739):16, (17.5866, 15.7066, 25.9892):17, (29.0208, -8.5776, 37.5533):18, (27.2543, -19.015, 35.3673):19, (25.2798, -34.2963, 32.8426):20, (25.8276, -27.5812, 10.7515):21, (26.6245, -19.1316, -5.6261):22, (14.986, 1.2467, -23.6473):23, (4.1091, 27.6851, -41.3905):24, (9.2862, 34.8709, -32.6869):25, (14.3696, 39.0991, -24.2113):26, (12.6512, 34.8073, -6.066):27, (22.699, 44.779, 34.3145):28, (31.2054, 21.9979, 41.7676):29, (47.2407, -12.0488, 52.8125):30, (44.5753, -27.9355, 49.6338):31, (41.9858, -48.1745, 46.4957):32, (42.7207, -39.1444, 16.0528):33, (43.8747, -26.8746, -7.9028):34, (26.5278, 3.8603, -34.8152):35, (11.0, 44.2673, -60.2918):36, (19.0423, 48.637, -46.7161):37, (26.6606, 54.9202, -34.0091):38, (24.1377, 48.6121, -6.8774):39, (37.5243, 61.9327, 51.9413):40, (50.3904, 27.7338, 58.553):41, (71.4677, -16.6651, 73.0447):42, (67.5818, -39.987, 68.408):43, (64.1995, -66.6294, 64.3075):44, (65.1526, -54.8772, 23.9922):45, (66.8122, -37.1703, -10.9303):46, (41.6262, 7.9137, -50.0682):47, (21.343, 61.2273, -83.3898):48, (32.0743, 66.9878, -65.2716):49, (43.0033, 75.9603, -47.0378):50, (39.3866, 66.9043, -7.4929):51, (53.2329, 80.1093, 67.2201):52, (69.4811, 36.8308, 75.4949):53, (97.1382, -21.5559, 94.4825):54, (92.125, -51.6335, 88.501):55, (87.737, -86.1846, 83.1812):56, (88.9499, -71.2147, 31.6061):57, (91.1165, -48.0796, -14.1381):58, (58.0145, 11.3842, -65.6058):59, (32.3026, 79.1967, -107.8637):60, (45.9331, 86.4699, -84.8483):61, (60.3199, 98.2542, -60.843):62, (55.6111, 86.4597, -9.1916):63, (60.8927, 62.8729, 35.0702):64, (78.8241, 18.6736, 56.0796):65, (97.6208, -17.6977, 66.4162):66, (94.1539, -37.4631, 68.7023):67, (89.8813, -66.1541, 56.3842):68, (91.0093, -53.1765, 13.8066):69, (92.571, -38.7824, -11.8131):70, (70.8615, -4.4808, -45.0866):71, (47.6091, 49.3215, -82.3961):72, (58.1323, 68.3853, -64.8302):73, (68.0079, 76.2368, -48.6298):74, (63.3723, 71.7112, -18.3923):75, (74.4686, 36.8822, 15.7988):76, (87.1187, 8.2035, 33.0227):77, (98.1056, -13.9188, 47.2642):78, (96.0337, -24.7493, 44.2003):79, (92.1264, -48.2196, 38.3812):80, (93.3211, -36.9827, 8.0947):81, (94.2302, -28.9926, -9.1665):82, (82.3123, -6.9657, -27.1167):83, (68.0684, 23.3938, -49.2364):84, (73.6833, 41.0464, -40.0349):85, (77.4342, 51.3197, -33.9217):86, (74.2811, 48.1595, -14.7725):87, (0.0, 0.0, 0.0):88, (5.8822, 0.0022, -0.0022):89, (16.1144, 0.0022, -0.0033):90, (22.6151, 0.0018, -0.004):91, (32.7476, 0.0018, -0.0044):92, (42.7837, 0.0032, -0.0055):93, (53.9767, 0.0034, -0.0063):94, (65.4912, 0.0036, -0.0074):95, (76.2461, 0.0044, -0.0083):96, (89.8837, 0.0048, -0.0094):97, (100.0, 0.0053, -0.0104):98}
colors = list(colors83.keys())
closest_colors = sorted(colors, key=lambda color: self.distance(color, self.rgb2lab(pixel), speed))
closest_color = closest_colors[0]
if self.colors == 16:
self.matches[pixel] = self.colors16[closest_color]
self.matches[pixel] = colors16[closest_color]
elif self.colors == 99:
self.matches[pixel] = self.colors99[closest_color]
self.matches[pixel] = colors99[closest_color]
else:
self.matches[pixel] = self.colors83[closest_color]
self.matches[pixel] = colors83[closest_color]
self.source_colors += 1
return self.matches[pixel]
@ -587,11 +260,12 @@ class TextArt(callbacks.Plugin):
def process_ansi(self, ansi):
if self.colors == 16:
colors = self.x256colors16
colors = ['01','05','03','03','02','06','10','15','14','04','09','08','12','13','11','00','01','02','02','02','12','12','03','10','12','12','12','12','03','10','10','10','14','14','03','03','10','10','10','10','09','09','09','11','11','11','09','09','09','09','11','11','05','06','02','12','12','12','03','14','14','12','12','12','03','03','10','14','14','14','03','03','10','10','10','15','09','09','09','11','11','11','09','09','09','09','11','11','05','06','06','06','06','12','14','14','06','06','06','13','03','14','14','14','14','13','03','03','03','11','11','11','09','09','09','11','11','11','09','09','09','09','11','11','05','06','06','06','06','06','07','04','06','13','13','13','07','07','14','14','13','13','08','08','15','15','15','15','08','09','09','15','15','15','09','09','09','09','11','11','04','06','06','06','13','13','07','04','13','13','13','13','07','07','04','13','13','13','08','07','07','15','15','13','08','08','08','15','15','15','08','08','08','09','00','00','04','04','13','13','13','13','07','04','13','13','13','13','07','07','04','13','13','13','07','07','07','15','15','13','08','08','08','15','15','15','08','08','08','08','00','00','01','01','01','01','01','01','01','14','14','14','14','14','14','14','14','14','15','15','15','15','15','15','15','00']
elif self.colors == 99:
colors = self.x256colors99
colors = ['01','05','32','30','02','38','34','96','94','04','56','08','60','13','11','00','01','36','02','48','48','60','32','34','47','47','47','72','03','33','10','59','59','59','44','45','45','46','71','71','09','68','45','69','46','83','56','68','57','57','69','11','28','38','37','49','49','60','30','93','47','72','72','72','31','33','10','59','59','59','43','45','45','46','71','71','09','68','57','69','70','83','56','68','68','57','69','70','05','39','38','49','49','61','41','93','50','50','72','72','30','30','94','84','84','84','43','43','45','46','71','71','43','68','80','81','82','83','55','68','68','80','81','70','40','51','06','50','50','61','41','64','63','50','73','73','30','41','76','87','85','84','42','42','95','96','84','84','55','67','79','81','82','83','55','67','80','80','81','82','40','51','51','50','50','73','41','64','63','75','13','73','53','07','76','87','85','85','42','65','77','76','87','85','42','66','78','78','15','97','55','67','79','79','81','82','04','64','63','63','13','13','07','64','63','75','75','74','53','64','76','87','87','86','65','65','65','76','87','86','08','77','77','77','97','86','08','66','66','78','78','00','01','89','89','90','91','91','92','92','92','93','93','14','94','94','95','95','95','96','96','96','15','97','97','97']
else:
colors = self.x256colors83
colors = ['88','28','32','30','36','38','34','96','94','52','56','54','60','62','58','98','88','36','36','48','48','60','32','34','47','47','47','72','32','33','34','59','59','59','44','45','45','46','71','71','44','68','45','69','46','83','56','68','57','57','69','58','28','38','37','49','49','60','30','93','47','72','72','72','31','33','34','59','59','59','43','45','45','46','71','71','56','68','57','69','70','83','56','68','68','57','69','70','28','39','38','49','49','61','41','93','50','50','72','72','30','30','94','84','84','84','43','43','45','46','71','71','43','68','80','81','82','83','55','68','68','80','81','70','40','51','51','50','50','61','41','64','63','50','73','73','30','41','76','87','85','84','42','42','95','96','84','84','55','67','79','81','82','83','55','67','80','80','81','82','40','51','51','50','50','73','41','64','63','75','62','73','53','53','76','87','85','85','42','65','77','76','87','85','42','66','78','78','97','97','55','67','79','79','81','82','52','64','63','63','62','62','52','64','63','75','75','74','53','64','76','87','87','86','65','65','65','76','87','86','54','77','77','77','97','86','54','66','66','78','78','98','88','89','89','90','91','91','92','92','92','93','93','94','94','94','95','95','95','96','96','96','97','97','97','97']
x16colors = {'30':'01', '31':'05', '32':'03', '33':'07', '34':'02', '35':'06', '36':'10', '37':'15', '30;1':'14', '31;1':'04', '32;1':'09', '33;1':'08', '34;1':'12', '35;1':'13', '36;1':'11', '37;1':'00', '40':'01', '41':'05', '42':'03', '43':'07', '44':'02', '45':'06', '46':'10', '47':'15', '40;1':'14', '41;1':'04', '42;1':'09', '43;1':'08', '44;1':'12', '45;1':'13', '46;1':'11', '47;1':'00'}
x16color1 = None
x16color2 = None
x256color1 = None
@ -621,22 +295,22 @@ class TextArt(callbacks.Plugin):
continue
elif int(ansi[i]) > 29 and int(ansi[i]) < 38:
if effect == 1 or ansi[-1] == '1':
x16color1 = self.x16colors['{0};1'.format(ansi[i])]
x16color1 = x16colors['{0};1'.format(ansi[i])]
effect = None
i += 1
continue
else:
x16color1 = self.x16colors[ansi[i]]
x16color1 = x16colors[ansi[i]]
i += 1
continue
elif int(ansi[i]) > 39 and int(ansi[i]) < 48:
if effect == 1 or ansi[-1] == '1':
x16color2 = self.x16colors['{0};1'.format(ansi[i])]
x16color2 = x16colors['{0};1'.format(ansi[i])]
effect = None
i += 1
continue
else:
x16color2 = self.x16colors[ansi[i]]
x16color2 = x16colors[ansi[i]]
i += 1
continue
elif ansi[i] == '38':
@ -676,9 +350,9 @@ class TextArt(callbacks.Plugin):
elif ansi[0] == '4':
color = '\x1F'
elif int(ansi[0]) > 29 and int(ansi[0]) < 38:
color = '\x03{0}'.format(self.x16colors[ansi[0]])
color = '\x03{0}'.format(x16colors[ansi[0]])
elif int(ansi[0]) > 39 and int(ansi[0]) < 48:
color = '\x0399,{0}'.format(self.x16colors[ansi[0]])
color = '\x0399,{0}'.format(x16colors[ansi[0]])
elif ansi[0][-1] == 'c':
color = ' ' * int(ansi[0][:-1])
else:
@ -915,7 +589,8 @@ class TextArt(callbacks.Plugin):
newbg = 1
else:
newbg = bg
image = Image.alpha_composite(Image.new("RGBA", image.size, self.rgbColors[newbg] + (255,)), image)
rgbColors = [(255,255,255), (0,0,0), (0,0,127), (0,147,0), (255,0,0), (127,0,0), (156,0,156), (252,127,0), (255,255,0), (0,252,0), (0,147,147), (0,255,255), (0,0,252), (255,0,255), (127,127,127), (210,210,210), (71,0,0), (71,33,0), (71,71,0), (50,71,0), (0,71,0), (0,71,44), (0,71,71), (0,39,71), (0,0,71), (46,0,71), (71,0,71), (71,0,42), (116,0,0), (116,58,0), (116,116,0), (81,116,0), (0,116,0), (0,116,73), (0,116,116), (0,64,116), (0,0,116), (75,0,116), (116,0,116), (116,0,69), (181,0,0), (181,99,0), (181,181,0), (125,181,0), (0,181,0), (0,181,113), (0,181,181), (0,99,181), (0,0,181), (117,0,181), (181,0,181), (181,0,107), (255,0,0), (255,140,0), (255,255,0), (178,255,0), (0,255,0), (0,255,160), (0,255,255), (0,140,255), (0,0,255), (165,0,255), (255,0,255), (255,0,152), (255,89,89), (255,180,89), (255,255,113), (207,255,96), (111,255,111), (101,255,201), (109,255,255), (89,180,255), (89,89,255), (196,89,255), (255,102,255), (255,89,188), (255,156,156), (255,211,156), (255,255,156), (226,255,156), (156,255,156), (156,255,219), (156,255,255), (156,211,255), (156,156,255), (220,156,255), (255,156,255), (255,148,211), (0,0,0), (19,19,19), (40,40,40), (54,54,54), (77,77,77), (101,101,101), (129,129,129), (159,159,159), (188,188,188), (226,226,226), (255,255,255)]
image = Image.alpha_composite(Image.new("RGBA", image.size, rgbColors[newbg] + (255,)), image)
if image.mode != 'RGB':
image = image.convert('RGB')
try:
@ -1702,4 +1377,4 @@ class TextArt(callbacks.Plugin):
irc.reply("\x031,8888\x031,8989\x031,9090\x031,9191\x031,9292\x031,9393\x031,9494\x031,9595\x031,9696\x031,9797\x031,9898\x031,9999", prefixNick=False)
codes = wrap(codes)
Class = TextArt
Class = TextArt