Skip to content

Commit e6838ce

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent ef4c08d commit e6838ce

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

Tests/test_file_qoi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
hopper,
1111
)
1212

13+
1314
def test_sanity() -> None:
1415
with Image.open("Tests/images/hopper.qoi") as im:
1516
assert im.mode == "RGB"
@@ -52,4 +53,3 @@ def test_save(tmp_path: Path) -> None:
5253
im = hopper("P")
5354
with pytest.raises(ValueError):
5455
im.save(f)
55-

src/PIL/QoiImagePlugin.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
import os
1111

1212
from . import Image, ImageFile
13-
from ._binary import i32be as i32, o32be as o32, o8
13+
from ._binary import i32be as i32
14+
from ._binary import o8
15+
from ._binary import o32be as o32
1416

1517

1618
def _accept(prefix: bytes) -> bool:
@@ -138,10 +140,10 @@ class QoiEncoder(ImageFile.PyEncoder):
138140
_previously_seen_pixels: dict[int, tuple[int]] = {}
139141

140142
def _write_run(self, run):
141-
return o8(0xc0 | (run - 1)) # QOI_OP_RUN
143+
return o8(0xC0 | (run - 1)) # QOI_OP_RUN
142144

143145
def _delta(self, left, right):
144-
result = (left - right) & 0xff
146+
result = (left - right) & 0xFF
145147
if result >= 0x80:
146148
result -= 0x100
147149
return result
@@ -176,7 +178,7 @@ def encode(self, bufsize: int) -> tuple[int, int, bytes]:
176178
r, g, b, a = pixel
177179
hash_value = (r * 3 + g * 5 + b * 7 + a * 11) % 64
178180
if self._previously_seen_pixels.get(hash_value) == pixel:
179-
data += o8(hash_value) # QOI_OP_INDEX
181+
data += o8(hash_value) # QOI_OP_INDEX
180182
else:
181183
self._previously_seen_pixels[hash_value] = pixel
182184

@@ -189,22 +191,24 @@ def encode(self, bufsize: int) -> tuple[int, int, bytes]:
189191
dgb = self._delta(db, dg)
190192

191193
if -2 <= dr < 2 and -2 <= dg < 2 and -2 <= db < 2:
192-
data += o8(0x40 | (dr + 2) << 4 | (dg + 2) << 2 | (db + 2)) # QOI_OP_DIFF
194+
data += o8(
195+
0x40 | (dr + 2) << 4 | (dg + 2) << 2 | (db + 2)
196+
) # QOI_OP_DIFF
193197
elif -8 <= dgr < 8 and -32 <= dg < 32 and -8 <= dgb < 8:
194-
data += o8(0x80 | (dg + 32)) # QOI_OP_LUMA
198+
data += o8(0x80 | (dg + 32)) # QOI_OP_LUMA
195199
data += o8((dgr + 8) << 4 | (dgb + 8))
196200
else:
197-
data += o8(0xfe) # QOI_OP_RGB
201+
data += o8(0xFE) # QOI_OP_RGB
198202
data += bytes(pixel[:3])
199203
else:
200-
data += o8(0xff) # QOI_OP_RGBA
204+
data += o8(0xFF) # QOI_OP_RGBA
201205
data += bytes(pixel)
202206

203207
self._previous_pixel = pixel
204208

205209
if run > 0:
206210
data += self._write_run(run)
207-
data += bytes((0,0,0,0,0,0,0,1)) # padding
211+
data += bytes((0, 0, 0, 0, 0, 0, 0, 1)) # padding
208212

209213
return len(data), 0, data
210214

0 commit comments

Comments
 (0)