mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-07-04 03:43:13 +03:00
F mode support
This commit is contained in:
parent
b6ad79d9f9
commit
bfdc599c28
|
@ -209,6 +209,24 @@ class _PyAccessI16_B(PyAccess):
|
||||||
pixel.l = color >> 8
|
pixel.l = color >> 8
|
||||||
pixel.r = color & 0xFF
|
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,
|
mode_map = {'1': _PyAccess8,
|
||||||
'L': _PyAccess8,
|
'L': _PyAccess8,
|
||||||
'P': _PyAccess8,
|
'P': _PyAccess8,
|
||||||
|
@ -221,6 +239,7 @@ mode_map = {'1': _PyAccess8,
|
||||||
'RGBa': _PyAccess32_4,
|
'RGBa': _PyAccess32_4,
|
||||||
'RGBX': _PyAccess32_4,
|
'RGBX': _PyAccess32_4,
|
||||||
'CMYK': _PyAccess32_4,
|
'CMYK': _PyAccess32_4,
|
||||||
|
'F': _PyAccessF,
|
||||||
}
|
}
|
||||||
|
|
||||||
if sys.byteorder == 'little':
|
if sys.byteorder == 'little':
|
||||||
|
|
|
@ -41,6 +41,7 @@ def test_get_vs_c():
|
||||||
_test_get_access(lena('1'))
|
_test_get_access(lena('1'))
|
||||||
_test_get_access(lena('P'))
|
_test_get_access(lena('P'))
|
||||||
#_test_get_access(lena('PA')) # PA -- how do I make a PA image???
|
#_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)
|
im = Image.new('I;16', (10,10), 40000)
|
||||||
_test_get_access(im)
|
_test_get_access(im)
|
||||||
|
@ -49,6 +50,8 @@ def test_get_vs_c():
|
||||||
im = Image.new('I;16B', (10,10), 40000)
|
im = Image.new('I;16B', (10,10), 40000)
|
||||||
_test_get_access(im)
|
_test_get_access(im)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def _test_set_access(im, color):
|
def _test_set_access(im, color):
|
||||||
""" Are we writing the correct bits into the image? """
|
""" Are we writing the correct bits into the image? """
|
||||||
|
|
||||||
|
@ -70,6 +73,7 @@ def test_set_vs_c():
|
||||||
_test_set_access(lena('1'), 255)
|
_test_set_access(lena('1'), 255)
|
||||||
_test_set_access(lena('P') , 128)
|
_test_set_access(lena('P') , 128)
|
||||||
##_test_set_access(i, (128,128)) #PA -- undone how to make
|
##_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)
|
im = Image.new('I;16', (10,10), 40000)
|
||||||
_test_set_access(im, 45000)
|
_test_set_access(im, 45000)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user