Repository navigation
Expand file tree
/
Copy pathimageColor256.py
More file actions
87 lines (78 loc) · 5.56 KB
/
Copy pathimageColor256.py
File metadata and controls
87 lines (78 loc) · 5.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/python3.6
# -*- coding: utf-8 -*-
from PIL import Image, ImageDraw
from imageCls import ImageFile, ImageFolder
folderImgName = 'b/cgi'
imageOriginale = 'b/img test.bmp'
colors16 =[
(0, 0, 0), (0, 0, 128), (0, 0, 255), (0, 128, 0), (0, 128, 128), (0, 255, 0), (0, 255, 255), (128, 0, 0),
(128, 0, 128), (128, 128, 0), (128, 128, 128), (192, 192, 192), (255, 0, 0), (255, 0, 255), (255, 255, 0), (255, 255, 255)
]
colors256 =[
(0, 0, 64), (0, 0, 192), (0, 32, 64), (0, 32, 128), (0, 32, 192), (0, 64, 0), (0, 64, 64), (0, 64, 128), (0, 64, 192), (0, 96, 0), (0, 96, 64), (0, 96, 128), (0, 96, 192), (0, 128, 64), (0, 128, 192), (0, 160, 0), (0, 160, 64), (0, 160, 128), (0, 160, 192), (0, 192, 0), (0, 192, 64), (0, 192, 128), (0, 192, 192), (0, 224, 0), (0, 224, 64), (0, 224, 128), (32, 0, 64), (32, 0, 128), (32, 0, 192), (32, 32, 64), (32, 32, 128), (32, 32, 192), (32, 64, 0), (32, 64, 64), (32, 64, 128), (32, 64, 192), (32, 96, 0), (32, 96, 64), (32, 96, 128), (32, 96, 192), (32, 128, 0), (32, 128, 64), (32, 128, 128), (32, 128, 192), (32, 160, 0), (32, 160, 64), (32, 160, 128), (32, 160, 192), (32, 192, 0), (32, 192, 64), (32, 192, 128), (32, 192, 192), (32, 224, 0), (32, 224, 64), (32, 224, 128), (64, 0, 64), (64, 0, 128), (64, 0, 192), (64, 32, 0), (64, 32, 64), (64, 32, 128), (64, 32, 192), (64, 64, 0), (64, 64, 64), (64, 64, 128), (64, 64, 192), (64, 96, 0), (64, 96, 64), (64, 96, 128), (64, 96, 192), (64, 128, 0), (64, 128, 64), (64, 128, 128), (64, 128, 192), (64, 160, 0), (64, 160, 64), (64, 160, 128), (64, 160, 192), (64, 192, 0), (64, 192, 64), (64, 192, 128), (64, 192, 192), (64, 224, 0), (64, 224, 64), (64, 224, 128), (96, 0, 64), (96, 0, 128), (96, 0, 192), (96, 32, 0), (96, 32, 64), (96, 32, 128), (96, 32, 192), (96, 64, 0), (96, 64, 64), (96, 64, 128), (96, 64, 192), (96, 96, 0), (96, 96, 64), (96, 96, 128), (96, 96, 192), (96, 128, 0), (96, 128, 64), (96, 128, 128), (96, 128, 192), (96, 160, 0), (96, 160, 64), (96, 160, 128), (96, 160, 192), (96, 192, 0), (96, 192, 64), (96, 192, 128), (96, 192, 192), (96, 224, 0), (96, 224, 64), (96, 224, 128), (128, 0, 64), (128, 0, 192), (128, 32, 0), (128, 32, 64), (128, 32, 128), (128, 32, 192), (128, 64, 0), (128, 64, 64), (128, 64, 128), (128, 64, 192), (128, 96, 0), (128, 96, 64), (128, 96, 128), (128, 96, 192), (128, 128, 64), (128, 128, 192), (128, 160, 0), (128, 160, 64), (128, 160, 128), (128, 160, 192), (128, 192, 0), (128, 192, 64), (128, 192, 128), (128, 192, 192), (128, 224, 0), (128, 224, 64), (128, 224, 128), (160, 0, 64), (160, 0, 128), (160, 0, 192), (160, 32, 0), (160, 32, 64), (160, 32, 128), (160, 32, 192), (160, 64, 0), (160, 64, 64), (160, 64, 128), (160, 64, 192), (160, 96, 0), (160, 96, 64), (160, 96, 128), (160, 96, 192), (160, 128, 0), (160, 128, 64), (160, 128, 128), (160, 128, 192), (160, 160, 0), (160, 160, 64), (160, 160, 128), (160, 160, 164), (160, 160, 192), (160, 192, 0), (160, 192, 64), (160, 192, 128), (160, 192, 192), (160, 224, 0), (160, 224, 64), (160, 224, 128), (166, 202, 240), (192, 0, 64), (192, 0, 128), (192, 0, 192), (192, 32, 0), (192, 32, 64), (192, 32, 128), (192, 32, 192), (192, 64, 0), (192, 64, 64), (192, 64, 128), (192, 64, 192), (192, 96, 0), (192, 96, 64), (192, 96, 128), (192, 96, 192), (192, 128, 0), (192, 128, 64), (192, 128, 128), (192, 128, 192), (192, 160, 0), (192, 160, 64), (192, 160, 128), (192, 160, 192), (192, 192, 0), (192, 192, 64), (192, 192, 128), (192, 220, 192), (192, 224, 0), (192, 224, 64), (192, 224, 128), (224, 0, 64), (224, 0, 128), (224, 0, 192), (224, 32, 0), (224, 32, 64), (224, 32, 128), (224, 32, 192), (224, 64, 0), (224, 64, 64), (224, 64, 128), (224, 64, 192), (224, 96, 0), (224, 96, 64), (224, 96, 128), (224, 96, 192), (224, 128, 0), (224, 128, 64), (224, 128, 128), (224, 128, 192), (224, 160, 0), (224, 160, 64), (224, 160, 128), (224, 160, 192), (224, 192, 0), (224, 192, 64), (224, 192, 128), (224, 224, 0), (224, 224, 64), (224, 224, 128), (255, 251, 240)
]
colors256.extend (colors16)
def getColors (self):
# récupérer toutes les colors des images png
colorsNew =[]
self.open()
nbImg = len (self.list)
nbImgVues =0
i=0
while nbImgVues <1 and i< nbImg:
print ('img', i)
if self.list[i].width < 1500 and self.list[i].height < 1500:
i+=1
continue
colorImg = self.list[i].getColors()
if len (colorImg) < 5000:
i+=1
continue
print (nbImgVues, i)
nbImgVues +=1
i+=1
for color in colorImg:
if color not in colors256 and color not in colorsNew: colorsNew.append (color)
# dessiner l'image les regroupant
fileImg = ImageFile (imageOriginale)
fileImg.drawPixels (colorsNew)
def drawPixels (self, colors):
lenX = 1000
lenYfloat =1+ len (colors) / lenX
lenY = int (lenYfloat)
self.image = Image.new ('RGB', (lenX, lenY))
self.image.format = 'BMP'
drawing = ImageDraw.Draw (self.image)
x=0
y=0
colors.sort()
for color in colors:
drawing.rectangle (((x,y), (x+1, y+1)), fill=color)
x+=1
if x>= lenX:
x=0
y+=1
self.draw()
def showNewColors (self):
self.open()
colors = self.getColors()
colorsNew =[]
print (len (colors), "couleurs dans l'image")
for color in colors:
if color not in colors256: colorsNew.append (color)
print (len (colorsNew), 'nouvelles couleurs\n', colorsNew)
setattr (ImageFile, 'drawPixels', drawPixels)
setattr (ImageFile, 'showNewColors', showNewColors)
setattr (ImageFolder, 'getColors', getColors)
folderImg = ImageFolder (folderImgName)
folderImg.get ('png')
folderImg.getColors()
"""
folderImg = ImageFolder (folderImgName)
folderImg.get ('png')
folderImg.getColors()
colors256.sort()
print (len (colors256), colors256)
fileImg = ImageFile (imageOriginale)
fileImg.showNewColors()
"""