Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions 15 Tests/test_file_pcd.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
from __future__ import annotations

from io import BytesIO

import pytest

from PIL import Image


def test_load_raw() -> None:
with Image.open("Tests/images/hopper.pcd") as im:
assert im.size == (768, 512)
im.load() # should not segfault.

# Note that this image was created with a resized hopper
Expand All @@ -15,3 +20,13 @@ def test_load_raw() -> None:

# target = hopper().resize((768,512))
# assert_image_similar(im, target, 10)


@pytest.mark.parametrize("orientation", (1, 3))
def test_rotated(orientation: int) -> None:
with open("Tests/images/hopper.pcd", "rb") as fp:
data = bytearray(fp.read())
data[2048 + 1538] = orientation
f = BytesIO(data)
with Image.open(f) as im:
assert im.size == (512, 768)
5 changes: 2 additions & 3 deletions 5 src/PIL/PcdImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def _open(self) -> None:
assert self.fp is not None

self.fp.seek(2048)
s = self.fp.read(2048)
s = self.fp.read(1539)

if not s.startswith(b"PCD_"):
msg = "not a PCD file"
Expand All @@ -46,14 +46,13 @@ def _open(self) -> None:
self.tile_post_rotate = -90

self._mode = "RGB"
self._size = 768, 512 # FIXME: not correct for rotated images!
self._size = (512, 768) if orientation in (1, 3) else (768, 512)
self.tile = [ImageFile._Tile("pcd", (0, 0) + self.size, 96 * 2048)]

def load_end(self) -> None:
if self.tile_post_rotate:
# Handle rotated PCDs
self.im = self.im.rotate(self.tile_post_rotate)
self._size = self.im.size


#
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.