-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.py
150 lines (148 loc) · 6.7 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
from PIL.Image import EXTENSION
from python import conversions
import tkinter as tk
from tkinter import filedialog
import os
dir=os.getcwd()
def help():
print("\nFirst load the image by choosing an appropriate .bmp or .jpg file.")
print("Then select of following filters:\nGrayscale:It adds a gray shade to the image")
print("Sepia:It adds a red filter to the image\n Blur: It blurs the image.This further has 3 options")
print("Increase/Decrease Brightness: This will increase the brightness of the image\nCrop: It will crop the image(provide values in percentage)")
print("Main Menu: This will take you back to the main menu. You can load another image or quit.\n")
def load():
print("Choose an image File from the popup menu")
root = tk.Tk()
root.withdraw()
files = filedialog.askopenfilenames()
try:
width,height=conversions.imgtohex(files[0])
except:
print("Please Select valid file")
print("Image Loaded Successfully\n")
processMenu(width,height)
def processMenu(width,height):
while 1:
print("Select a filter")
print("1. Grayscale")
print("2. Sepia")
print("3. Blur")
print("4. Increase/Decrease Brightness ")
print("5. Crop ")
print("6. Main Menu")
choice = int(input())
if (choice==1):
try:
print("Processing Image!")
command="iverilog ./verilog/greyscale.v"
os.system(command)
print("Please wait! It may take longer time depending on the quality of the image")
command="vvp a.out"
os.system(command)
print("Processing complete! Please select a location to save from the popup menu")
root = tk.Tk()
root.withdraw()
file = filedialog.asksaveasfilename(defaultextension='.jpg', filetypes= [('JPG','.jpg'), ('BMP', '.bmp')])
conversions.hextoimg(width,height,file)
except:
print("Please select valid location and file name")
continue
elif choice==2:
try:
print("Processing Image!")
command="iverilog ./verilog/sepia.v"
os.system(command)
print("Please wait! It may take longer time depending on the quality of the image")
command="vvp a.out"
os.system(command)
print("Processing complete! Please select a location to save from the popup menu")
root = tk.Tk()
root.withdraw()
file = filedialog.asksaveasfilename(defaultextension='.jpg', filetypes= [('JPG','.jpg'), ('BMP', '.bmp')])
conversions.hextoimg(width,height,file)
except:
print("Please select valid location and file name")
continue
elif choice==3:
print("Select Blur Level:")
print("1. Low\n2. Medium\n3. High(Works Slow)")
order=int(input())
f=open("./data/size.hex","w")
f.write(hex(width)[2:]+"\n"+hex(height)[2:]+"\n"+hex(2*order+1)[2:])
f.close()
print("Processing Image!")
command="iverilog ./verilog/blur.v"
os.system(command)
print("Please wait! It may take longer time depending on the quality of the image")
command="vvp a.out"
os.system(command)
print("Processing complete! Please select a location to save from the popup menu")
root = tk.Tk()
root.withdraw()
file = filedialog.asksaveasfilename(defaultextension='.jpg', filetypes= [('JPG','.jpg'), ('BMP', '.bmp')])
conversions.hextoimg(width,height,file)
print("Please select valid location and file name")
continue
elif choice ==4:
try:
print("Enter a value between -255 to 255(-ve value will decrease brightness)")
brighness=int(input())
f=open("./data/size.hex","w")
sign=0
if brighness<0:
brighness*=-1
sign=1
f.write(hex(width)[2:]+"\n"+hex(height)[2:]+"\n"+hex(brighness)[2:]+"\n"+str(sign))
f.close()
print("Processing Image!")
command="iverilog ./verilog/brightness.v"
os.system(command)
print("Please wait! It may take longer time depending on the quality of the image")
command="vvp a.out"
os.system(command)
print("Processing complete! Please select a location to save from the popup menu")
root = tk.Tk()
root.withdraw()
file = filedialog.asksaveasfilename(defaultextension='.jpg', filetypes= [('JPG','.jpg'), ('BMP', '.bmp')])
conversions.hextoimg(width,height,file)
except:
print("Please select valid location and file name")
continue
elif choice ==5:
print("Enter 4 numbers seperated by space 'top bottom right left' ");
top,bottom,right,left = list(map(int,input().split()));
f=open("./data/size.hex","w")
top = int(top/100*height);
bottom = int(bottom/100*height);
left= int(left/100*width);
right = int(right/100*width);
f.write(hex(width)[2:]+"\n"+hex(height)[2:]+ "\n"+ hex(top)[2:]+"\n"+hex(bottom)[2:]+"\n"+hex(left)[2:]+"\n" + hex(right)[2:]+"\n");
f.close()
print("Processing Image!")
command="iverilog ./verilog/crop.v"
os.system(command)
print("Please wait! It may take longer time depending on the quality of the image")
command="vvp a.out"
os.system(command)
print("Processing complete! Please select a location to save from the popup menu")
root = tk.Tk()
root.withdraw()
file = filedialog.asksaveasfilename(defaultextension='.jpg', filetypes= [('JPG','.jpg'), ('BMP', '.bmp')])
conversions.hextoimg(width-(left+right),height-(top+bottom),file)
print("Please select valid location and file name")
continue
else :
break
print("Image Saved!")
while (1):
print("Main Menu")
print("1. Load Image")
print("2. Help")
print("3. Quit")
choice=int(input())
if choice==3:
break
if choice==1:
load()
if choice==2:
help()