11import math
22import struct
33
4+ import PIL .PyAccess
45from PIL import Image
56
67from system .bytestream import Reader
1011CHUNK_SIZE = 32
1112
1213
13- def load_image_from_buffer (img : Image ) -> None :
14+ def load_image_from_buffer (img : Image . Image ) -> None :
1415 width , height = img .size
15- img_loaded = img .load ()
16+ # noinspection PyTypeChecker
17+ img_loaded : PIL .PyAccess .PyAccess = img .load ()
1618
1719 with open ("pixel_buffer" , "rb" ) as pixel_buffer :
1820 channels_count = int .from_bytes (pixel_buffer .read (1 ), "little" )
@@ -22,12 +24,13 @@ def load_image_from_buffer(img: Image) -> None:
2224 img_loaded [x , y ] = tuple (pixel_buffer .read (channels_count ))
2325
2426
25- def join_image (img : Image ) -> None :
27+ def join_image (img : Image . Image ) -> None :
2628 with open ("pixel_buffer" , "rb" ) as pixel_buffer :
2729 channels_count = int .from_bytes (pixel_buffer .read (1 ), "little" )
2830
2931 width , height = img .size
30- loaded_img = img .load ()
32+ # noinspection PyTypeChecker
33+ loaded_img : PIL .PyAccess .PyAccess = img .load ()
3134
3235 x_chunks_count = width // CHUNK_SIZE
3336 y_chunks_count = height // CHUNK_SIZE
@@ -51,13 +54,15 @@ def join_image(img: Image) -> None:
5154 Console .progress_bar (locale .join_pic , y_chunk , y_chunks_count + 1 )
5255
5356
54- def split_image (img : Image ):
57+ def split_image (img : Image . Image ):
5558 def add_pixel (pixel : tuple ):
5659 loaded_image [pixel_index % width , int (pixel_index / width )] = pixel
5760
5861 width , height = img .size
59- loaded_image = img .load ()
60- loaded_clone = img .copy ().load ()
62+ # noinspection PyTypeChecker
63+ loaded_image : PIL .PyAccess .PyAccess = img .load ()
64+ # noinspection PyTypeChecker
65+ loaded_clone : PIL .PyAccess .PyAccess = img .copy ().load ()
6166
6267 x_chunks_count = width // CHUNK_SIZE
6368 y_chunks_count = height // CHUNK_SIZE
@@ -180,53 +185,54 @@ def read_pixel():
180185
181186
182187def save_texture (sc , img , _type ):
183- write_pixel = None
184188 if _type in (0 , 1 ):
185189
186190 def write_pixel (pixel ):
187191 return struct .pack ("4B" , * pixel )
188192
189- if _type == 2 :
193+ elif _type == 2 :
190194
191195 def write_pixel (pixel ):
192196 r , g , b , a = pixel
193197 return struct .pack ("<H" , a >> 4 | b >> 4 << 4 | g >> 4 << 8 | r >> 4 << 12 )
194198
195- if _type == 3 :
199+ elif _type == 3 :
196200
197201 def write_pixel (pixel ):
198202 r , g , b , a = pixel
199203 return struct .pack ("<H" , a >> 7 | b >> 3 << 1 | g >> 3 << 6 | r >> 3 << 11 )
200204
201- if _type == 4 :
205+ elif _type == 4 :
202206
203207 def write_pixel (pixel ):
204208 r , g , b = pixel
205209 return struct .pack ("<H" , b >> 3 | g >> 2 << 5 | r >> 3 << 11 )
206210
207- if _type == 6 :
211+ elif _type == 6 :
208212
209213 def write_pixel (pixel ):
210214 return struct .pack ("2B" , * pixel [::- 1 ])
211215
212- if _type == 10 :
216+ elif _type == 10 :
213217
214218 def write_pixel (pixel ):
215219 return struct .pack ("B" , pixel )
216220
217- if write_pixel is not None :
218- width , height = img . size
221+ else :
222+ return
219223
220- pix = img .getdata ()
221- point = - 1
222- for y in range (height ):
223- for x in range (width ):
224- sc .write (write_pixel (pix [y * width + x ]))
224+ width , height = img .size
225225
226- curr = Console .percent (y , height )
227- if curr > point :
228- Console .progress_bar (locale .writing_pic , y , height )
229- point = curr
226+ pix = img .getdata ()
227+ point = - 1
228+ for y in range (height ):
229+ for x in range (width ):
230+ sc .write (write_pixel (pix [y * width + x ]))
231+
232+ curr = Console .percent (y , height )
233+ if curr > point :
234+ Console .progress_bar (locale .writing_pic , y , height )
235+ point = curr
230236
231237
232238def transform_image (image , scale_x , scale_y , angle , x , y ):
0 commit comments