9 from pathlib import Path
12 HOST = "192.168.0.106"
15 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
16 s.connect((HOST, PORT))
20 quality=int(sys.argv[1])
21 print("quality ",quality)
26 im=Image.open("lena.jpg")
27 im.save("lena.bmp",quality=quality)
30 for i in range(nb_times):
32 im.save(buf, "BMP", quality=quality)
34 elapsed_time += time.time() - t
36 print("compute bmp",elapsed_time/nb_times," / size of file ",Path('lena.bmp').stat().st_size)
40 im=Image.open("lena.jpg")
44 for i in range(nb_times):
45 im.save("lena.bmp",quality=quality)
47 elapsed_time += time.time() - t
49 print("time bmp",elapsed_time/nb_times)
54 im=Image.open("lena.jpg")
56 im.save("lena2.jpg",quality=quality)
58 for i in range(nb_times):
60 im.save(buf, "JPEG", quality=quality)
62 elapsed_time += time.time() - t
64 print("compute noscale jpg",elapsed_time/nb_times, " / size of file ",Path('lena2.jpg').stat().st_size)
69 im2=im.resize((256, 256))
70 im2.save("lena3.jpg",quality=quality)
72 for i in range(nb_times):
73 im2=im.resize((256, 256))
75 im2.save(buf, "JPEG", quality=quality)
77 elapsed_time += time.time() - t
78 print("compute scale 4 jpg ",elapsed_time/nb_times, " / size of file ",Path('lena3.jpg').stat().st_size)
86 sbuf = buffer.Buffer(s)
92 for i in range(nb_times):
94 sbuf.put_utf8(file_name)
96 file_size = os.path.getsize(file_name)
97 sbuf.put_utf8(str(file_size))
99 with open(file_name, 'rb') as f:
100 sbuf.put_bytes(f.read())
102 elapsed_time += time.time() - t
103 print("send bmp ",elapsed_time/nb_times)
107 file_name="lena2.jpg"
108 for i in range(nb_times):
110 sbuf.put_utf8(file_name)
112 file_size = os.path.getsize(file_name)
113 sbuf.put_utf8(str(file_size))
115 with open(file_name, 'rb') as f:
116 sbuf.put_bytes(f.read())
118 elapsed_time += time.time() - t
119 print("send noscale jpg ",elapsed_time/nb_times)
123 file_name="lena3.jpg"
124 for i in range(nb_times):
126 sbuf.put_utf8(file_name)
128 file_size = os.path.getsize(file_name)
129 sbuf.put_utf8(str(file_size))
131 with open(file_name, 'rb') as f:
132 sbuf.put_bytes(f.read())
134 elapsed_time += time.time() - t
135 print("send scale 4 jpg ",elapsed_time/nb_times)