Skip to content

Commit

Permalink
palette support for saving 8-bit greyscale images
Browse files Browse the repository at this point in the history
  • Loading branch information
zpincus authored and stefanv committed Oct 22, 2010
1 parent 7784307 commit 325b59c
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion scikits/image/io/_plugins/freeimage_plugin.py
Expand Up @@ -389,6 +389,9 @@ def write_multipage(arrays, filename, flags=0):
finally:
_FI.FreeImage_CloseMultiBitmap(multibitmap, flags)

# 4-byte quads of 0,v,v,v from 0,0,0,0 to 0,255,255,255
_GREY_PALETTE = numpy.arange(0, 0x01000000, 0x00010101, dtype=numpy.uint32)

def _array_to_bitmap(array):
"""Allocate a FreeImage bitmap and copy a numpy array into it.
Expand Down Expand Up @@ -429,7 +432,11 @@ def n(arr): # normalise to freeimage's in-memory format
wrapped_array[3] = n(array[:,:,3])
else:
wrapped_array[:] = n(array)

if len(shape) == 2 and dtype.type == numpy.uint8:
palette = _FI.FreeImage_GetPalette(bitmap)
if not palette:
raise RuntimeError('Could not get image palette')
ctypes.memmove(palette, _GREY_PALETTE.ctypes.data, 1024)
return bitmap, fi_type
except:
_FI.FreeImage_Unload(bitmap)
Expand Down

0 comments on commit 325b59c

Please sign in to comment.