/usr/lib/python2.7/dist-packages/pyqtgraph/util/pil_fix.py is in python-pyqtgraph 0.9.10-5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | # -*- coding: utf-8 -*-
"""
Importing this module installs support for 16-bit images in PIL.
This works by patching objects in the PIL namespace; no files are
modified.
"""
from PIL import Image
if Image.VERSION == '1.1.7':
Image._MODE_CONV["I;16"] = ('%su2' % Image._ENDIAN, None)
Image._fromarray_typemap[((1, 1), "<u2")] = ("I", "I;16")
if Image.VERSION == '1.1.6':
Image._MODE_CONV["I;16"] = ('%su2' % Image._ENDIAN, None)
## just a copy of fromarray() from Image.py with I;16 added in
def fromarray(obj, mode=None):
arr = obj.__array_interface__
shape = arr['shape']
ndim = len(shape)
try:
strides = arr['strides']
except KeyError:
strides = None
if mode is None:
typestr = arr['typestr']
if not (typestr[0] == '|' or typestr[0] == Image._ENDIAN or
typestr[1:] not in ['u1', 'b1', 'i4', 'f4']):
raise TypeError("cannot handle data-type")
if typestr[0] == Image._ENDIAN:
typestr = typestr[1:3]
else:
typestr = typestr[:2]
if typestr == 'i4':
mode = 'I'
if typestr == 'u2':
mode = 'I;16'
elif typestr == 'f4':
mode = 'F'
elif typestr == 'b1':
mode = '1'
elif ndim == 2:
mode = 'L'
elif ndim == 3:
mode = 'RGB'
elif ndim == 4:
mode = 'RGBA'
else:
raise TypeError("Do not understand data.")
ndmax = 4
bad_dims=0
if mode in ['1','L','I','P','F']:
ndmax = 2
elif mode == 'RGB':
ndmax = 3
if ndim > ndmax:
raise ValueError("Too many dimensions.")
size = shape[:2][::-1]
if strides is not None:
obj = obj.tostring()
return frombuffer(mode, size, obj, "raw", mode, 0, 1)
Image.fromarray=fromarray
|