/
main.py
executable file
·117 lines (99 loc) · 3.87 KB
/
main.py
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
from PIL import Image, ImageDraw
from progressbar import ProgressBar
import sys
import Pixel
def rgbget(pix):
pixel.getcolors(pix[0], pix[1], pix[2])
def processing(mode, pix, width, height, draw, image):
print(str(mode + 1) + ". Image")
pbar.start()
for i in range(width):
for j in range(height):
pixel = Pixel.Pixel(*pix[i, j])
draw.point((i, j), (pixel.modeget(mode)))
pbar.update(i * j)
del pixel
image.save("Image" + str(mode + 1) + ".jpg", "JPEG")
print('')
def negative(mode, pix, width, height, draw, image):
print(str(mode + 1) + ". Negative")
pbar.start()
for i in range(width):
for j in range(height):
pixel = Pixel.Pixel(*pix[i, j])
red, green, blue = pixel.modeget(mode)
draw.point((i, j), (255-red, 255-green, 255-blue))
pbar.update(i * j)
del pixel
image.save("Negative" + str(mode + 1) + ".jpg", "JPEG")
print('')
def main():
IMAGE_NAME = sys.argv[1]
pixel = Pixel.Pixel(0, 0, 0)
modsquantity = pixel.getmodsquantity()
selectedmods = []
print("Available modes:", modsquantity)
wrongoption = True
while(wrongoption):
print("-p, -P \t Positive mods;")
print("-n, -N \t Negative mods;")
print("-a, -A \t All mods;")
global administration
administration = list(input("Select mods: ").split(" "))
select = administration[:-1]
print(administration)
if len(select)==1:
select = select[0]
print(select)
if select.startswith("-"):
modenumber = select[1:]
if modenumber.isdigit():
selectedmods = list(range(int(modenumber) - 1))
wrongoption = False
else:
print('Wrong option 1')
elif select.endswith("-"):
modenumber = select[:-1]
if modenumber.isdigit():
selectedmods = list(range(int(modenumber) - 1, modsquantity))
wrongoption = False
else:
print('Wrong option 2')
elif select.find('-')!=-1:
try:
modenumber = list(map(int, select.split("-")))
selectedmods = list(range(modenumber[0] - 1, modenumber[1]))
wrongoption = False
except:
print('Wrong option 3')
else:
selectedmods.append(int(select) - 1)
wrongoption = False
else:
selectedmods = list(map(int, select))
#try:
for i in range(len(selectedmods)):
selectedmods[i]=selectedmods[i]-1
wrongoption = False
#except:
# print('Wrong option 4')
print('----------------------------------------------------------------')
del pixel
for mode in selectedmods:
image = Image.open(IMAGE_NAME)
draw = ImageDraw.Draw(image)
width = image.size[0]
height = image.size[1]
global pbar
pbar = ProgressBar(maxval=width * height)
pix = image.load()
if administration[-1]=='-p' or administration[-1]=='-P':
processing(mode = mode, pix=pix, width = width, height = height, draw = draw, image = image)
elif administration[-1]=='-n' or administration[-1]=='-N':
negative(mode = mode, pix=pix, width=width, height=height, draw=draw, image = image)
elif administration[-1]=='-a' or administration[-1]=='-A':
processing(mode = mode, pix=pix, width = width, height = height, draw = draw, image = image)
negative(mode = mode, pix=pix, width=width, height=height, draw=draw, image = image)
print('')
if __name__=='__main__':
main()