Merge pull request #7706 from radarhere/psd

This commit is contained in:
Hugo van Kemenade 2024-03-11 17:51:06 +02:00 committed by GitHub
commit 94f319cd35
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 23 additions and 8 deletions

Binary file not shown.

View File

@ -113,6 +113,11 @@ def test_rgba() -> None:
assert_image_equal_tofile(im, "Tests/images/imagedraw_square.png") assert_image_equal_tofile(im, "Tests/images/imagedraw_square.png")
def test_negative_top_left_layer() -> None:
with Image.open("Tests/images/negative_top_left_layer.psd") as im:
assert im.layers[0][2] == (-50, -50, 50, 50)
def test_layer_skip() -> None: def test_layer_skip() -> None:
with Image.open("Tests/images/five_channels.psd") as im: with Image.open("Tests/images/five_channels.psd") as im:
assert im.n_frames == 1 assert im.n_frames == 1

View File

@ -24,6 +24,7 @@ from ._binary import i8
from ._binary import i16be as i16 from ._binary import i16be as i16
from ._binary import i32be as i32 from ._binary import i32be as i32
from ._binary import si16be as si16 from ._binary import si16be as si16
from ._binary import si32be as si32
MODES = { MODES = {
# (photoshop mode, bits) -> (pil mode, required channels) # (photoshop mode, bits) -> (pil mode, required channels)
@ -177,22 +178,21 @@ def _layerinfo(fp, ct_bytes):
for _ in range(abs(ct)): for _ in range(abs(ct)):
# bounding box # bounding box
y0 = i32(read(4)) y0 = si32(read(4))
x0 = i32(read(4)) x0 = si32(read(4))
y1 = i32(read(4)) y1 = si32(read(4))
x1 = i32(read(4)) x1 = si32(read(4))
# image info # image info
mode = [] mode = []
ct_types = i16(read(2)) ct_types = i16(read(2))
types = list(range(ct_types)) if ct_types > 4:
if len(types) > 4: fp.seek(ct_types * 6 + 12, io.SEEK_CUR)
fp.seek(len(types) * 6 + 12, io.SEEK_CUR)
size = i32(read(4)) size = i32(read(4))
fp.seek(size, io.SEEK_CUR) fp.seek(size, io.SEEK_CUR)
continue continue
for _ in types: for _ in range(ct_types):
type = i16(read(2)) type = i16(read(2))
if type == 65535: if type == 65535:

View File

@ -77,6 +77,16 @@ def si32le(c: bytes, o: int = 0) -> int:
return unpack_from("<i", c, o)[0] return unpack_from("<i", c, o)[0]
def si32be(c: bytes, o: int = 0) -> int:
"""
Converts a 4-bytes (32 bits) string to a signed integer, big endian.
:param c: string containing bytes to convert
:param o: offset of bytes to convert in string
"""
return unpack_from(">i", c, o)[0]
def i16be(c: bytes, o: int = 0) -> int: def i16be(c: bytes, o: int = 0) -> int:
return unpack_from(">H", c, o)[0] return unpack_from(">H", c, o)[0]