From 4ebe7fc45964607b04a3c97526497dc282c733b4 Mon Sep 17 00:00:00 2001 From: tdesvenain Date: Sun, 29 Jul 2012 15:48:40 +0200 Subject: [PATCH 1/3] Fix opening psd files with RGBA layers when A mode is not of type 65535 but 3. Fixes issue https://github.com/python-imaging/Pillow/issues/3 --- PIL/PsdImagePlugin.py | 11 ++++++++--- docs/HISTORY.txt | 6 +++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/PIL/PsdImagePlugin.py b/PIL/PsdImagePlugin.py index 9d1b17a36..a3fa75368 100644 --- a/PIL/PsdImagePlugin.py +++ b/PIL/PsdImagePlugin.py @@ -165,7 +165,6 @@ def _layerinfo(file): # read layerinfo block layers = [] read = file.read - for i in range(abs(i16(read(2)))): # bounding box @@ -175,12 +174,18 @@ def _layerinfo(file): # image info info = [] mode = [] - for i in range(i16(read(2))): + types = range(i16(read(2))) + if len(types) > 4: + continue + + for i in types: type = i16(read(2)) + if type == 65535: m = "A" else: - m = "RGB"[type] + m = "RGBA"[type] + mode.append(m) size = i32(read(4)) info.append((m, size)) diff --git a/docs/HISTORY.txt b/docs/HISTORY.txt index 3d0e6a4b9..4e61263a7 100644 --- a/docs/HISTORY.txt +++ b/docs/HISTORY.txt @@ -5,6 +5,10 @@ Changelog 1.7.8 (Unreleased) ------------------ +- Fix opening psd files with RGBA layers when A mode is not of type 65535 but 3. + Fixes issue https://github.com/python-imaging/Pillow/issues/3 + [thomasdesvenain] + 1.7.7 (2012-04-04) ------------------ @@ -38,7 +42,7 @@ Changelog 1.7.3 (2011-07-20) ------------------ -- Fix : resize need int values, append int conversion in thumbnail method +- Fix : resize need int values, append int conversion in thumbnail method [harobed] 1.7.2 (2011-06-02) From bc9455d0594c508f60b940372f47a805cb0ced93 Mon Sep 17 00:00:00 2001 From: tdesvenain Date: Sun, 29 Jul 2012 16:02:26 +0200 Subject: [PATCH 2/3] Added a psd mode (mode 4, 16 bits). --- PIL/PsdImagePlugin.py | 1 + docs/HISTORY.txt | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/PIL/PsdImagePlugin.py b/PIL/PsdImagePlugin.py index a3fa75368..211393cdb 100644 --- a/PIL/PsdImagePlugin.py +++ b/PIL/PsdImagePlugin.py @@ -28,6 +28,7 @@ MODES = { (2, 8): ("P", 1), (3, 8): ("RGB", 3), (4, 8): ("CMYK", 4), + (4, 16): ("CMYK", 4), (7, 8): ("L", 1), # FIXME: multilayer (8, 8): ("L", 1), # duotone (9, 8): ("LAB", 3) diff --git a/docs/HISTORY.txt b/docs/HISTORY.txt index 4e61263a7..cd5148d68 100644 --- a/docs/HISTORY.txt +++ b/docs/HISTORY.txt @@ -5,9 +5,15 @@ Changelog 1.7.8 (Unreleased) ------------------ -- Fix opening psd files with RGBA layers when A mode is not of type 65535 but 3. - Fixes issue https://github.com/python-imaging/Pillow/issues/3 - [thomasdesvenain] +- Manage more psd files: + + - Added a psd mode (mode 4, 16 bits). + [thomasdesvenain] + + - Fix opening psd files with RGBA layers when A mode is not of type 65535 but 3. + Fixes issue https://github.com/python-imaging/Pillow/issues/3 + [thomasdesvenain] + 1.7.7 (2012-04-04) ------------------ From 3eda40cb4c3105c17ffab6fb5fcca6c5df145b7b Mon Sep 17 00:00:00 2001 From: tdesvenain Date: Sun, 29 Jul 2012 17:05:54 +0200 Subject: [PATCH 3/3] revert last commit, images rendered didn't match very well --- PIL/PsdImagePlugin.py | 3 +-- docs/HISTORY.txt | 11 +++-------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/PIL/PsdImagePlugin.py b/PIL/PsdImagePlugin.py index 211393cdb..4390f5f9c 100644 --- a/PIL/PsdImagePlugin.py +++ b/PIL/PsdImagePlugin.py @@ -28,7 +28,6 @@ MODES = { (2, 8): ("P", 1), (3, 8): ("RGB", 3), (4, 8): ("CMYK", 4), - (4, 16): ("CMYK", 4), (7, 8): ("L", 1), # FIXME: multilayer (8, 8): ("L", 1), # duotone (9, 8): ("LAB", 3) @@ -58,7 +57,7 @@ class PsdImageFile(ImageFile.ImageFile): format_description = "Adobe Photoshop" def _open(self): - + read = self.fp.read # diff --git a/docs/HISTORY.txt b/docs/HISTORY.txt index cd5148d68..25d98f318 100644 --- a/docs/HISTORY.txt +++ b/docs/HISTORY.txt @@ -5,14 +5,9 @@ Changelog 1.7.8 (Unreleased) ------------------ -- Manage more psd files: - - - Added a psd mode (mode 4, 16 bits). - [thomasdesvenain] - - - Fix opening psd files with RGBA layers when A mode is not of type 65535 but 3. - Fixes issue https://github.com/python-imaging/Pillow/issues/3 - [thomasdesvenain] +- Fix opening psd files with RGBA layers when A mode is not of type 65535 but 3. + Fixes issue https://github.com/python-imaging/Pillow/issues/3 + [thomasdesvenain] 1.7.7 (2012-04-04)