Skip to content

Commit 94f319c

Browse files
authored
Merge pull request #7706 from radarhere/psd
2 parents fc30eba + 2888f76 commit 94f319c

File tree

4 files changed

+23
-8
lines changed

4 files changed

+23
-8
lines changed
8.03 KB
Binary file not shown.

Tests/test_file_psd.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ def test_rgba() -> None:
113113
assert_image_equal_tofile(im, "Tests/images/imagedraw_square.png")
114114

115115

116+
def test_negative_top_left_layer() -> None:
117+
with Image.open("Tests/images/negative_top_left_layer.psd") as im:
118+
assert im.layers[0][2] == (-50, -50, 50, 50)
119+
120+
116121
def test_layer_skip() -> None:
117122
with Image.open("Tests/images/five_channels.psd") as im:
118123
assert im.n_frames == 1

src/PIL/PsdImagePlugin.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from ._binary import i16be as i16
2525
from ._binary import i32be as i32
2626
from ._binary import si16be as si16
27+
from ._binary import si32be as si32
2728

2829
MODES = {
2930
# (photoshop mode, bits) -> (pil mode, required channels)
@@ -177,22 +178,21 @@ def read(size):
177178

178179
for _ in range(abs(ct)):
179180
# bounding box
180-
y0 = i32(read(4))
181-
x0 = i32(read(4))
182-
y1 = i32(read(4))
183-
x1 = i32(read(4))
181+
y0 = si32(read(4))
182+
x0 = si32(read(4))
183+
y1 = si32(read(4))
184+
x1 = si32(read(4))
184185

185186
# image info
186187
mode = []
187188
ct_types = i16(read(2))
188-
types = list(range(ct_types))
189-
if len(types) > 4:
190-
fp.seek(len(types) * 6 + 12, io.SEEK_CUR)
189+
if ct_types > 4:
190+
fp.seek(ct_types * 6 + 12, io.SEEK_CUR)
191191
size = i32(read(4))
192192
fp.seek(size, io.SEEK_CUR)
193193
continue
194194

195-
for _ in types:
195+
for _ in range(ct_types):
196196
type = i16(read(2))
197197

198198
if type == 65535:

src/PIL/_binary.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,16 @@ def si32le(c: bytes, o: int = 0) -> int:
7777
return unpack_from("<i", c, o)[0]
7878

7979

80+
def si32be(c: bytes, o: int = 0) -> int:
81+
"""
82+
Converts a 4-bytes (32 bits) string to a signed integer, big endian.
83+
84+
:param c: string containing bytes to convert
85+
:param o: offset of bytes to convert in string
86+
"""
87+
return unpack_from(">i", c, o)[0]
88+
89+
8090
def i16be(c: bytes, o: int = 0) -> int:
8191
return unpack_from(">H", c, o)[0]
8292

0 commit comments

Comments
 (0)