F mode support

This commit is contained in:
wiredfool 2014-01-08 20:23:20 -08:00
parent b6ad79d9f9
commit bfdc599c28
2 changed files with 25 additions and 2 deletions

View File

@ -209,6 +209,24 @@ class _PyAccessI16_B(PyAccess):
pixel.l = color >> 8
pixel.r = color & 0xFF
class _PyAccessF(PyAccess):
""" 32 bit float access """
def _post_init(self, *args, **kwargs):
self.pixels = ffi.cast('float **', self.image32)
def get_pixel(self, x,y):
return self.pixels[y][x]
def set_pixel(self, x,y, color):
try:
# not a tuple
self.pixels[y][x] = color
except:
# tuple
self.pixels[y][x] = color[0]
mode_map = {'1': _PyAccess8,
'L': _PyAccess8,
'P': _PyAccess8,
@ -221,6 +239,7 @@ mode_map = {'1': _PyAccess8,
'RGBa': _PyAccess32_4,
'RGBX': _PyAccess32_4,
'CMYK': _PyAccess32_4,
'F': _PyAccessF,
}
if sys.byteorder == 'little':

View File

@ -41,13 +41,16 @@ def test_get_vs_c():
_test_get_access(lena('1'))
_test_get_access(lena('P'))
#_test_get_access(lena('PA')) # PA -- how do I make a PA image???
_test_get_access(lena('F'))
im = Image.new('I;16', (10,10), 40000)
_test_get_access(im)
im = Image.new('I;16L', (10,10), 40000)
_test_get_access(im)
im = Image.new('I;16B', (10,10), 40000)
_test_get_access(im)
def _test_set_access(im, color):
""" Are we writing the correct bits into the image? """
@ -70,7 +73,8 @@ def test_set_vs_c():
_test_set_access(lena('1'), 255)
_test_set_access(lena('P') , 128)
##_test_set_access(i, (128,128)) #PA -- undone how to make
_test_set_access(lena('F'), 1024.0)
im = Image.new('I;16', (10,10), 40000)
_test_set_access(im, 45000)
im = Image.new('I;16L', (10,10), 40000)