From f5ba642b5e49253f7256e08aa5e53226aac1194e Mon Sep 17 00:00:00 2001 From: wiredfool Date: Mon, 7 Apr 2014 22:12:33 -0700 Subject: [PATCH] Read support for 16 bit pgm file --- PIL/PpmImagePlugin.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/PIL/PpmImagePlugin.py b/PIL/PpmImagePlugin.py index 9aa5b1135..d7af308c2 100644 --- a/PIL/PpmImagePlugin.py +++ b/PIL/PpmImagePlugin.py @@ -96,7 +96,18 @@ class PpmImageFile(ImageFile.ImageFile): ysize = s if mode == "1": break - + elif ix == 2: + # maxgrey + if s > 255: + if not mode == 'L': + raise ValueError("Too many colors for band: %s" %s) + if s <= 2**16 - 1: + self.mode = 'I' + rawmode = 'I;16B' + else: + self.mode = 'I'; + rawmode = 'I;32B' + self.size = xsize, ysize self.tile = [("raw", (0, 0, xsize, ysize),