From 05a601031142ecf0ca21c521a6c312c66c4e48b6 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Fri, 29 Aug 2025 07:35:18 +1000 Subject: [PATCH 1/2] Fixed loading rotated PCD images --- Tests/test_file_pcd.py | 7 +++++++ src/PIL/PcdImagePlugin.py | 9 +++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Tests/test_file_pcd.py b/Tests/test_file_pcd.py index 9bf1a75f0..a2d07ff51 100644 --- a/Tests/test_file_pcd.py +++ b/Tests/test_file_pcd.py @@ -6,6 +6,8 @@ import pytest from PIL import Image +from .helper import assert_image_equal + def test_load_raw() -> None: with Image.open("Tests/images/hopper.pcd") as im: @@ -30,3 +32,8 @@ def test_rotated(orientation: int) -> None: f = BytesIO(data) with Image.open(f) as im: assert im.size == (512, 768) + + with Image.open("Tests/images/hopper.pcd") as expected: + assert_image_equal( + im, expected.rotate(90 if orientation == 1 else -90, expand=True) + ) diff --git a/src/PIL/PcdImagePlugin.py b/src/PIL/PcdImagePlugin.py index 7f9ab525c..00864a4bf 100644 --- a/src/PIL/PcdImagePlugin.py +++ b/src/PIL/PcdImagePlugin.py @@ -47,12 +47,17 @@ class PcdImageFile(ImageFile.ImageFile): self._mode = "RGB" self._size = (512, 768) if orientation in (1, 3) else (768, 512) - self.tile = [ImageFile._Tile("pcd", (0, 0) + self.size, 96 * 2048)] + self.tile = [ImageFile._Tile("pcd", (0, 0, 768, 512), 96 * 2048)] + + def load_prepare(self) -> None: + if self._im is None and self.tile_post_rotate: + self.im = Image.core.new(self.mode, (768, 512)) + ImageFile.ImageFile.load_prepare(self) def load_end(self) -> None: if self.tile_post_rotate: # Handle rotated PCDs - self.im = self.im.rotate(self.tile_post_rotate) + self.im = self.rotate(self.tile_post_rotate, expand=True).im # From c6915f717f3b9bb694421f4d711808ba2c464d40 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Fri, 29 Aug 2025 07:43:51 +1000 Subject: [PATCH 2/2] rotate() will use "angle % 360" --- Tests/test_file_pcd.py | 2 +- src/PIL/PcdImagePlugin.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/test_file_pcd.py b/Tests/test_file_pcd.py index a2d07ff51..15dd7f116 100644 --- a/Tests/test_file_pcd.py +++ b/Tests/test_file_pcd.py @@ -35,5 +35,5 @@ def test_rotated(orientation: int) -> None: with Image.open("Tests/images/hopper.pcd") as expected: assert_image_equal( - im, expected.rotate(90 if orientation == 1 else -90, expand=True) + im, expected.rotate(90 if orientation == 1 else 270, expand=True) ) diff --git a/src/PIL/PcdImagePlugin.py b/src/PIL/PcdImagePlugin.py index 00864a4bf..296f3775b 100644 --- a/src/PIL/PcdImagePlugin.py +++ b/src/PIL/PcdImagePlugin.py @@ -43,7 +43,7 @@ class PcdImageFile(ImageFile.ImageFile): if orientation == 1: self.tile_post_rotate = 90 elif orientation == 3: - self.tile_post_rotate = -90 + self.tile_post_rotate = 270 self._mode = "RGB" self._size = (512, 768) if orientation in (1, 3) else (768, 512)