From f0a7333bc1fe14b25f592ee4164bcea852cca4ea Mon Sep 17 00:00:00 2001
From: Paul McCarthy <pauldmccarthy@gmail.com>
Date: Thu, 4 Jul 2019 22:11:25 +0100
Subject: [PATCH] BF: Support palette images

---
 fsl/data/bitmap.py | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/fsl/data/bitmap.py b/fsl/data/bitmap.py
index 299534f54..51b354f7d 100644
--- a/fsl/data/bitmap.py
+++ b/fsl/data/bitmap.py
@@ -61,12 +61,20 @@ class Bitmap(object):
             except ImportError:
                 raise RuntimeError('Install Pillow to use the Bitmap class')
 
-            source = bmp
-            data   = np.array(Image.open(source))
+            src = bmp
+            img = Image.open(src)
+
+            # If this is a palette/LUT
+            # image, convert it into a
+            # regular rgb(a) image.
+            if img.mode == 'P':
+                img = img.convert()
+
+            data = np.array(img)
 
         elif isinstance(bmp, np.ndarray):
-            source = 'array'
-            data   = np.copy(bmp)
+            src  = 'array'
+            data = np.copy(bmp)
 
         else:
             raise ValueError('unknown bitmap: {}'.format(bmp))
@@ -83,8 +91,8 @@ class Bitmap(object):
         w, h = data.shape[:2]
 
         self.__data       = data
-        self.__dataSource = source
-        self.__name       = op.basename(source)
+        self.__dataSource = src
+        self.__name       = op.basename(src)
 
 
     def __hash__(self):
-- 
GitLab