mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-07-28 17:10:02 +03:00
Simplified code
This commit is contained in:
parent
23a7fefced
commit
a714db9057
|
@ -145,9 +145,9 @@ class QoiEncoder(ImageFile.PyEncoder):
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def _delta(self, left: int, right: int) -> int:
|
def _delta(self, left: int, right: int) -> int:
|
||||||
result = (left - right) & 0xFF
|
result = (left - right) & 255
|
||||||
if result >= 0x80:
|
if result >= 128:
|
||||||
result -= 0x100
|
result -= 256
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def encode(self, bufsize: int) -> tuple[int, int, bytes]:
|
def encode(self, bufsize: int) -> tuple[int, int, bytes]:
|
||||||
|
@ -158,7 +158,7 @@ class QoiEncoder(ImageFile.PyEncoder):
|
||||||
|
|
||||||
data = bytearray()
|
data = bytearray()
|
||||||
w, h = self.im.size
|
w, h = self.im.size
|
||||||
bands = Image.getmodebands(self.im.mode)
|
bands = Image.getmodebands(self.mode)
|
||||||
|
|
||||||
for y in range(h):
|
for y in range(h):
|
||||||
for x in range(w):
|
for x in range(w):
|
||||||
|
@ -171,7 +171,7 @@ class QoiEncoder(ImageFile.PyEncoder):
|
||||||
if self._run == 62:
|
if self._run == 62:
|
||||||
data += self._write_run()
|
data += self._write_run()
|
||||||
else:
|
else:
|
||||||
if self._run > 0:
|
if self._run:
|
||||||
data += self._write_run()
|
data += self._write_run()
|
||||||
|
|
||||||
r, g, b, a = pixel
|
r, g, b, a = pixel
|
||||||
|
@ -208,7 +208,7 @@ class QoiEncoder(ImageFile.PyEncoder):
|
||||||
|
|
||||||
self._previous_pixel = pixel
|
self._previous_pixel = pixel
|
||||||
|
|
||||||
if self._run > 0:
|
if self._run:
|
||||||
data += self._write_run()
|
data += self._write_run()
|
||||||
data += bytes((0, 0, 0, 0, 0, 0, 0, 1)) # padding
|
data += bytes((0, 0, 0, 0, 0, 0, 0, 1)) # padding
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user