error when saving

This commit is contained in:
Klemek
2021-08-29 20:25:48 +02:00
parent 125f1555b4
commit 228a60f659
+11 -5
View File
@@ -36,16 +36,22 @@ class Image:
def get_pixel(self, x: int, y: int) -> bool: def get_pixel(self, x: int, y: int) -> bool:
position = self.__get_position(x, y) position = self.__get_position(x, y)
chunk_id = position // 8 chunk_id = position // 8
return self.data[chunk_id] & (1 << (7 - position % 8)) > 0 try:
return self.data[chunk_id] & (1 << (7 - position % 8)) > 0
except:
return False
def set_pixel(self, x: int, y: int, v: bool) -> None: def set_pixel(self, x: int, y: int, v: bool) -> None:
position = self.__get_position(x, y) position = self.__get_position(x, y)
chunk_id = position // 8 chunk_id = position // 8
if v != self.get_pixel(x, y): if v != self.get_pixel(x, y):
if v: try:
self.data[chunk_id] |= 1 << (7 - position % 8) if v:
else: self.data[chunk_id] |= 1 << (7 - position % 8)
self.data[chunk_id] &= ~(1 << (7 - position % 8)) else:
self.data[chunk_id] &= ~(1 << (7 - position % 8))
except:
pass
self.modified = True self.modified = True
def __get_color_bytes(self) -> bytes: def __get_color_bytes(self) -> bytes: