diff --git a/PIL/PyAccess.py b/PIL/PyAccess.py index f75fb312d..cd862d4f0 100644 --- a/PIL/PyAccess.py +++ b/PIL/PyAccess.py @@ -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': diff --git a/Tests/test_cffi.py b/Tests/test_cffi.py index 87214475b..1cf991701 100644 --- a/Tests/test_cffi.py +++ b/Tests/test_cffi.py @@ -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)