projects
/
rainbowstream.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
image by flag
[rainbowstream.git]
/
rainbowstream
/
pure_image.py
diff --git
a/rainbowstream/pure_image.py
b/rainbowstream/pure_image.py
index 464f93f79fe630894809ea65b336bff4e1c909ba..f4cb751cdd70a6ca70d51bf229d09be2d47475fc 100644
(file)
--- a/
rainbowstream/pure_image.py
+++ b/
rainbowstream/pure_image.py
@@
-1,116
+1,117
@@
from PIL import Image
from functools import partial
from PIL import Image
from functools import partial
-import sys,os
+import sys
+import os
CLUT = [ # color look-up table
CLUT = [ # color look-up table
-# 8-bit, RGB hex
+
# 8-bit, RGB hex
# Primary 3-bit (8 colors). Unique representation!
# Primary 3-bit (8 colors). Unique representation!
- ('00',
'000000'),
- ('01',
'800000'),
- ('02',
'008000'),
- ('03',
'808000'),
- ('04',
'000080'),
- ('05',
'800080'),
- ('06',
'008080'),
- ('07',
'c0c0c0'),
+ ('00', '000000'),
+ ('01', '800000'),
+ ('02', '008000'),
+ ('03', '808000'),
+ ('04', '000080'),
+ ('05', '800080'),
+ ('06', '008080'),
+ ('07', 'c0c0c0'),
# Equivalent "bright" versions of original 8 colors.
# Equivalent "bright" versions of original 8 colors.
- ('08',
'808080'),
- ('09',
'ff0000'),
- ('10',
'00ff00'),
- ('11',
'ffff00'),
- ('12',
'0000ff'),
- ('13',
'ff00ff'),
- ('14',
'00ffff'),
- ('15',
'ffffff'),
+ ('08', '808080'),
+ ('09', 'ff0000'),
+ ('10', '00ff00'),
+ ('11', 'ffff00'),
+ ('12', '0000ff'),
+ ('13', 'ff00ff'),
+ ('14', '00ffff'),
+ ('15', 'ffffff'),
# Strictly ascending.
# Strictly ascending.
- ('16',
'000000'),
- ('17',
'00005f'),
- ('18',
'000087'),
- ('19',
'0000af'),
- ('20',
'0000d7'),
- ('21',
'0000ff'),
- ('22',
'005f00'),
- ('23',
'005f5f'),
- ('24',
'005f87'),
- ('25',
'005faf'),
- ('26',
'005fd7'),
- ('27',
'005fff'),
- ('28',
'008700'),
- ('29',
'00875f'),
- ('30',
'008787'),
- ('31',
'0087af'),
- ('32',
'0087d7'),
- ('33',
'0087ff'),
- ('34',
'00af00'),
- ('35',
'00af5f'),
- ('36',
'00af87'),
- ('37',
'00afaf'),
- ('38',
'00afd7'),
- ('39',
'00afff'),
- ('40',
'00d700'),
- ('41',
'00d75f'),
- ('42',
'00d787'),
- ('43',
'00d7af'),
- ('44',
'00d7d7'),
- ('45',
'00d7ff'),
- ('46',
'00ff00'),
- ('47',
'00ff5f'),
- ('48',
'00ff87'),
- ('49',
'00ffaf'),
- ('50',
'00ffd7'),
- ('51',
'00ffff'),
- ('52',
'5f0000'),
- ('53',
'5f005f'),
- ('54',
'5f0087'),
- ('55',
'5f00af'),
- ('56',
'5f00d7'),
- ('57',
'5f00ff'),
- ('58',
'5f5f00'),
- ('59',
'5f5f5f'),
- ('60',
'5f5f87'),
- ('61',
'5f5faf'),
- ('62',
'5f5fd7'),
- ('63',
'5f5fff'),
- ('64',
'5f8700'),
- ('65',
'5f875f'),
- ('66',
'5f8787'),
- ('67',
'5f87af'),
- ('68',
'5f87d7'),
- ('69',
'5f87ff'),
- ('70',
'5faf00'),
- ('71',
'5faf5f'),
- ('72',
'5faf87'),
- ('73',
'5fafaf'),
- ('74',
'5fafd7'),
- ('75',
'5fafff'),
- ('76',
'5fd700'),
- ('77',
'5fd75f'),
- ('78',
'5fd787'),
- ('79',
'5fd7af'),
- ('80',
'5fd7d7'),
- ('81',
'5fd7ff'),
- ('82',
'5fff00'),
- ('83',
'5fff5f'),
- ('84',
'5fff87'),
- ('85',
'5fffaf'),
- ('86',
'5fffd7'),
- ('87',
'5fffff'),
- ('88',
'870000'),
- ('89',
'87005f'),
- ('90',
'870087'),
- ('91',
'8700af'),
- ('92',
'8700d7'),
- ('93',
'8700ff'),
- ('94',
'875f00'),
- ('95',
'875f5f'),
- ('96',
'875f87'),
- ('97',
'875faf'),
- ('98',
'875fd7'),
- ('99',
'875fff'),
+ ('16', '000000'),
+ ('17', '00005f'),
+ ('18', '000087'),
+ ('19', '0000af'),
+ ('20', '0000d7'),
+ ('21', '0000ff'),
+ ('22', '005f00'),
+ ('23', '005f5f'),
+ ('24', '005f87'),
+ ('25', '005faf'),
+ ('26', '005fd7'),
+ ('27', '005fff'),
+ ('28', '008700'),
+ ('29', '00875f'),
+ ('30', '008787'),
+ ('31', '0087af'),
+ ('32', '0087d7'),
+ ('33', '0087ff'),
+ ('34', '00af00'),
+ ('35', '00af5f'),
+ ('36', '00af87'),
+ ('37', '00afaf'),
+ ('38', '00afd7'),
+ ('39', '00afff'),
+ ('40', '00d700'),
+ ('41', '00d75f'),
+ ('42', '00d787'),
+ ('43', '00d7af'),
+ ('44', '00d7d7'),
+ ('45', '00d7ff'),
+ ('46', '00ff00'),
+ ('47', '00ff5f'),
+ ('48', '00ff87'),
+ ('49', '00ffaf'),
+ ('50', '00ffd7'),
+ ('51', '00ffff'),
+ ('52', '5f0000'),
+ ('53', '5f005f'),
+ ('54', '5f0087'),
+ ('55', '5f00af'),
+ ('56', '5f00d7'),
+ ('57', '5f00ff'),
+ ('58', '5f5f00'),
+ ('59', '5f5f5f'),
+ ('60', '5f5f87'),
+ ('61', '5f5faf'),
+ ('62', '5f5fd7'),
+ ('63', '5f5fff'),
+ ('64', '5f8700'),
+ ('65', '5f875f'),
+ ('66', '5f8787'),
+ ('67', '5f87af'),
+ ('68', '5f87d7'),
+ ('69', '5f87ff'),
+ ('70', '5faf00'),
+ ('71', '5faf5f'),
+ ('72', '5faf87'),
+ ('73', '5fafaf'),
+ ('74', '5fafd7'),
+ ('75', '5fafff'),
+ ('76', '5fd700'),
+ ('77', '5fd75f'),
+ ('78', '5fd787'),
+ ('79', '5fd7af'),
+ ('80', '5fd7d7'),
+ ('81', '5fd7ff'),
+ ('82', '5fff00'),
+ ('83', '5fff5f'),
+ ('84', '5fff87'),
+ ('85', '5fffaf'),
+ ('86', '5fffd7'),
+ ('87', '5fffff'),
+ ('88', '870000'),
+ ('89', '87005f'),
+ ('90', '870087'),
+ ('91', '8700af'),
+ ('92', '8700d7'),
+ ('93', '8700ff'),
+ ('94', '875f00'),
+ ('95', '875f5f'),
+ ('96', '875f87'),
+ ('97', '875faf'),
+ ('98', '875fd7'),
+ ('99', '875fff'),
('100', '878700'),
('101', '87875f'),
('102', '878787'),
('100', '878700'),
('101', '87875f'),
('102', '878787'),
@@
-271,6
+272,7
@@
CLUT = [ # color look-up table
('255', 'eeeeee'),
]
('255', 'eeeeee'),
]
+
def _create_dicts():
short2rgb_dict = dict(CLUT)
rgb2short_dict = {}
def _create_dicts():
short2rgb_dict = dict(CLUT)
rgb2short_dict = {}
@@
-292,7
+294,7
@@
def pixel_print(ansicolor):
def hex_to_rgb(value):
value = value.lstrip('#')
lv = len(value)
def hex_to_rgb(value):
value = value.lstrip('#')
lv = len(value)
- return tuple(int(value[i:i
+lv/3], 16) for i in range(0, lv, lv/
3))
+ return tuple(int(value[i:i
+ lv / 3], 16) for i in range(0, lv, lv /
3))
def rgb_to_hex(rgb):
def rgb_to_hex(rgb):
@@
-300,31
+302,32
@@
def rgb_to_hex(rgb):
def rgb2short(r, g, b):
def rgb2short(r, g, b):
- dist = lambda s,d: (s[0]-d[0])**2+(s[1]-d[1])**2+(s[2]-d[2])**2
+ dist = lambda s, d: (s[0] - d[0]) ** 2 + \
+ (s[1] - d[1]) ** 2 + (s[2] - d[2]) ** 2
ary = [hex_to_rgb(hex) for hex in RGB2SHORT_DICT]
ary = [hex_to_rgb(hex) for hex in RGB2SHORT_DICT]
- m = min(ary, key=partial(dist, (r,
g,
b)))
+ m = min(ary, key=partial(dist, (r,
g,
b)))
return RGB2SHORT_DICT[rgb_to_hex(m)]
return RGB2SHORT_DICT[rgb_to_hex(m)]
+
def image_to_display(path):
def image_to_display(path):
- i = Image.open(path)
+ i = Image.open(path)
i = i.convert('RGBA')
i = i.convert('RGBA')
- w,h = i.size
+ w,
h = i.size
i.load()
rows, columns = os.popen('stty size', 'r').read().split()
i.load()
rows, columns = os.popen('stty size', 'r').read().split()
- width = min(w, int(columns)
-2*
6)
+ width = min(w, int(columns)
- 2 *
6)
height = int(float(h) * (float(width) / float(w)))
height //= 2
i = i.resize((width, height), Image.BICUBIC)
height = int(float(h) * (float(width) / float(w)))
height //= 2
i = i.resize((width, height), Image.BICUBIC)
- height = min(height,30)
+ height = min(height,
30)
for y in xrange(height):
for y in xrange(height):
- print ' '
*6
,
+ print ' '
* 6
,
for x in xrange(width):
for x in xrange(width):
- p = i.getpixel((x,y))
+ p = i.getpixel((x,
y))
r, g, b = p[:3]
r, g, b = p[:3]
- pixel_print(rgb2short(r,
g,
b))
+ pixel_print(rgb2short(r,
g,
b))
print ''
if __name__ == '__main__':
image_to_display(sys.argv[1])
print ''
if __name__ == '__main__':
image_to_display(sys.argv[1])
-