From f953b982859c43add1e035ab6346c59b2a43cc5b Mon Sep 17 00:00:00 2001 From: artscoop Date: Wed, 4 Mar 2015 22:40:04 +0100 Subject: [PATCH] Try to fix tests Choked on roundtrip, where a P;1 image was returned instead of a 1 image. --- PIL/BmpImagePlugin.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/PIL/BmpImagePlugin.py b/PIL/BmpImagePlugin.py index d6457f1e2..755cfb0fc 100644 --- a/PIL/BmpImagePlugin.py +++ b/PIL/BmpImagePlugin.py @@ -171,8 +171,13 @@ class BmpImageFile(ImageFile.ImageFile): else: padding = file_info['palette_padding'] palette = read(padding * file_info['colors']) + greyscale = True + indices = (0, 255) if file_info['colors'] == 2 else list(range(file_info['colors'])) #------------------- Check if greyscale and ignore palette if so - greyscale = all([palette[ind] == palette[ind+1] == palette[ind+2] == ind / padding for ind in range(0, len(palette), padding)]) + for ind in indices: + rgb = palette[ind*padding:ind*padding + 3] + if rgb != o8(ind) * 3: + greyscale = False #--------- If all colors are grey, white or black, ditch palette if greyscale: self.mode = "1" if file_info['colors'] == 2 else "L"