mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-27 10:26:19 +03:00
commit
436daee5e0
|
@ -134,9 +134,13 @@ class BmpImageFile(ImageFile.ImageFile):
|
||||||
24: [(0xff0000, 0xff00, 0xff)],
|
24: [(0xff0000, 0xff00, 0xff)],
|
||||||
16: [(0xf800, 0x7e0, 0x1f), (0x7c00, 0x3e0, 0x1f)]}
|
16: [(0xf800, 0x7e0, 0x1f), (0x7c00, 0x3e0, 0x1f)]}
|
||||||
MASK_MODES = {
|
MASK_MODES = {
|
||||||
(32, (0xff0000, 0xff00, 0xff, 0x0)): "BGRX", (32, (0xff0000, 0xff00, 0xff, 0xff000000)): "BGRA", (32, (0x0, 0x0, 0x0, 0x0)): "BGRA",
|
(32, (0xff0000, 0xff00, 0xff, 0x0)): "BGRX",
|
||||||
|
(32, (0xff0000, 0xff00, 0xff, 0xff000000)): "BGRA",
|
||||||
|
(32, (0x0, 0x0, 0x0, 0x0)): "BGRA",
|
||||||
(24, (0xff0000, 0xff00, 0xff)): "BGR",
|
(24, (0xff0000, 0xff00, 0xff)): "BGR",
|
||||||
(16, (0xf800, 0x7e0, 0x1f)): "BGR;16", (16, (0x7c00, 0x3e0, 0x1f)): "BGR;15"}
|
(16, (0xf800, 0x7e0, 0x1f)): "BGR;16",
|
||||||
|
(16, (0x7c00, 0x3e0, 0x1f)): "BGR;15"
|
||||||
|
}
|
||||||
if file_info['bits'] in SUPPORTED:
|
if file_info['bits'] in SUPPORTED:
|
||||||
if file_info['bits'] == 32 and file_info['rgba_mask'] in SUPPORTED[file_info['bits']]:
|
if file_info['bits'] == 32 and file_info['rgba_mask'] in SUPPORTED[file_info['bits']]:
|
||||||
raw_mode = MASK_MODES[(file_info['bits'], file_info['rgba_mask'])]
|
raw_mode = MASK_MODES[(file_info['bits'], file_info['rgba_mask'])]
|
||||||
|
|
|
@ -295,7 +295,7 @@ class EpsImageFile(ImageFile.ImageFile):
|
||||||
break
|
break
|
||||||
try:
|
try:
|
||||||
self.mode = self.mode_map[int(mo)]
|
self.mode = self.mode_map[int(mo)]
|
||||||
except:
|
except ValueError:
|
||||||
break
|
break
|
||||||
|
|
||||||
self.size = int(x), int(y)
|
self.size = int(x), int(y)
|
||||||
|
|
|
@ -397,10 +397,8 @@ def _save(im, fp, filename, save_all=False):
|
||||||
|
|
||||||
fp.write(b";") # end of file
|
fp.write(b";") # end of file
|
||||||
|
|
||||||
try:
|
if hasattr(fp, "flush"):
|
||||||
fp.flush()
|
fp.flush()
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def get_interlace(im):
|
def get_interlace(im):
|
||||||
|
|
|
@ -42,6 +42,7 @@ from PIL._util import isStringType
|
||||||
# Application code should use the <b>Draw</b> factory, instead of
|
# Application code should use the <b>Draw</b> factory, instead of
|
||||||
# directly.
|
# directly.
|
||||||
|
|
||||||
|
|
||||||
class ImageDraw(object):
|
class ImageDraw(object):
|
||||||
|
|
||||||
##
|
##
|
||||||
|
@ -297,7 +298,6 @@ class ImageDraw(object):
|
||||||
|
|
||||||
def multiline_textsize(self, text, font=None, spacing=0):
|
def multiline_textsize(self, text, font=None, spacing=0):
|
||||||
max_width = 0
|
max_width = 0
|
||||||
height = 0
|
|
||||||
lines = self._multiline_split(text)
|
lines = self._multiline_split(text)
|
||||||
line_spacing = self.textsize('A', font=font)[1] + spacing
|
line_spacing = self.textsize('A', font=font)[1] + spacing
|
||||||
for line in lines:
|
for line in lines:
|
||||||
|
|
|
@ -85,6 +85,7 @@ def fromqpixmap(im):
|
||||||
# bytes_io.seek(0)
|
# bytes_io.seek(0)
|
||||||
# return Image.open(bytes_io)
|
# return Image.open(bytes_io)
|
||||||
|
|
||||||
|
|
||||||
def align8to32(bytes, width, mode):
|
def align8to32(bytes, width, mode):
|
||||||
"""
|
"""
|
||||||
converts each scanline of data from 8 bit to 32 bit aligned
|
converts each scanline of data from 8 bit to 32 bit aligned
|
||||||
|
@ -113,6 +114,7 @@ def align8to32(bytes, width, mode):
|
||||||
|
|
||||||
return b''.join(new_data)
|
return b''.join(new_data)
|
||||||
|
|
||||||
|
|
||||||
def _toqclass_helper(im):
|
def _toqclass_helper(im):
|
||||||
data = None
|
data = None
|
||||||
colortable = None
|
colortable = None
|
||||||
|
|
|
@ -719,7 +719,6 @@ def jpeg_factory(fp=None, filename=None):
|
||||||
except SyntaxError:
|
except SyntaxError:
|
||||||
warnings.warn("Image appears to be a malformed MPO file, it will be "
|
warnings.warn("Image appears to be a malformed MPO file, it will be "
|
||||||
"interpreted as a base JPEG file")
|
"interpreted as a base JPEG file")
|
||||||
pass
|
|
||||||
return im
|
return im
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ from helper import unittest, PillowTestCase
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
try:
|
try:
|
||||||
import numpy as np
|
import numpy as np
|
||||||
except:
|
except ImportError:
|
||||||
raise unittest.SkipTest("numpy not installed")
|
raise unittest.SkipTest("numpy not installed")
|
||||||
|
|
||||||
YDIM = 32769
|
YDIM = 32769
|
||||||
|
|
|
@ -70,7 +70,6 @@ class TestFileTiffMetadata(PillowTestCase):
|
||||||
loaded_double = loaded.tag[tag_ids['YawAngle']][0]
|
loaded_double = loaded.tag[tag_ids['YawAngle']][0]
|
||||||
self.assertAlmostEqual(loaded_double, doubledata)
|
self.assertAlmostEqual(loaded_double, doubledata)
|
||||||
|
|
||||||
|
|
||||||
def test_read_metadata(self):
|
def test_read_metadata(self):
|
||||||
img = Image.open('Tests/images/hopper_g4.tif')
|
img = Image.open('Tests/images/hopper_g4.tif')
|
||||||
|
|
||||||
|
@ -167,7 +166,6 @@ class TestFileTiffMetadata(PillowTestCase):
|
||||||
self.assert_(im.info['icc_profile'])
|
self.assert_(im.info['icc_profile'])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
||||||
|
|
|
@ -24,13 +24,13 @@ class TestImageOpsUsm(PillowTestCase):
|
||||||
|
|
||||||
def test_filter_api(self):
|
def test_filter_api(self):
|
||||||
|
|
||||||
filter = ImageFilter.GaussianBlur(2.0)
|
test_filter = ImageFilter.GaussianBlur(2.0)
|
||||||
i = im.filter(filter)
|
i = im.filter(test_filter)
|
||||||
self.assertEqual(i.mode, "RGB")
|
self.assertEqual(i.mode, "RGB")
|
||||||
self.assertEqual(i.size, (128, 128))
|
self.assertEqual(i.size, (128, 128))
|
||||||
|
|
||||||
filter = ImageFilter.UnsharpMask(2.0, 125, 8)
|
test_filter = ImageFilter.UnsharpMask(2.0, 125, 8)
|
||||||
i = im.filter(filter)
|
i = im.filter(test_filter)
|
||||||
self.assertEqual(i.mode, "RGB")
|
self.assertEqual(i.mode, "RGB")
|
||||||
self.assertEqual(i.size, (128, 128))
|
self.assertEqual(i.size, (128, 128))
|
||||||
|
|
||||||
|
|
|
@ -60,7 +60,6 @@ if sys.platform.startswith('win32'):
|
||||||
CreateDIBSection.argtypes = [ctypes.wintypes.HDC, ctypes.c_void_p, ctypes.c_uint, ctypes.POINTER(ctypes.c_void_p), ctypes.wintypes.HANDLE, ctypes.wintypes.DWORD]
|
CreateDIBSection.argtypes = [ctypes.wintypes.HDC, ctypes.c_void_p, ctypes.c_uint, ctypes.POINTER(ctypes.c_void_p), ctypes.wintypes.HANDLE, ctypes.wintypes.DWORD]
|
||||||
CreateDIBSection.restype = ctypes.wintypes.HBITMAP
|
CreateDIBSection.restype = ctypes.wintypes.HBITMAP
|
||||||
|
|
||||||
|
|
||||||
def serialize_dib(bi, pixels):
|
def serialize_dib(bi, pixels):
|
||||||
bf = BITMAPFILEHEADER()
|
bf = BITMAPFILEHEADER()
|
||||||
bf.bfType = 0x4d42
|
bf.bfType = 0x4d42
|
||||||
|
@ -108,4 +107,3 @@ if sys.platform.startswith('win32'):
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
||||||
|
|
|
@ -22,9 +22,9 @@ class TestNumpy(PillowTestCase):
|
||||||
|
|
||||||
def test_numpy_to_image(self):
|
def test_numpy_to_image(self):
|
||||||
|
|
||||||
def to_image(dtype, bands=1, bool=0):
|
def to_image(dtype, bands=1, boolean=0):
|
||||||
if bands == 1:
|
if bands == 1:
|
||||||
if bool:
|
if boolean:
|
||||||
data = [0, 1] * 50
|
data = [0, 1] * 50
|
||||||
else:
|
else:
|
||||||
data = list(range(100))
|
data = list(range(100))
|
||||||
|
@ -43,8 +43,8 @@ class TestNumpy(PillowTestCase):
|
||||||
# print dtype, list(i.getdata())
|
# print dtype, list(i.getdata())
|
||||||
return i
|
return i
|
||||||
|
|
||||||
# self.assert_image(to_image(numpy.bool, bool=1), "1", (10, 10))
|
# self.assert_image(to_image(numpy.bool, boolean=1), "1", (10, 10))
|
||||||
# self.assert_image(to_image(numpy.bool8, bool=1), "1", (10, 10))
|
# self.assert_image(to_image(numpy.bool8, boolean=1), "1", (10, 10))
|
||||||
|
|
||||||
self.assertRaises(TypeError, lambda: to_image(numpy.uint))
|
self.assertRaises(TypeError, lambda: to_image(numpy.uint))
|
||||||
self.assert_image(to_image(numpy.uint8), "L", (10, 10))
|
self.assert_image(to_image(numpy.uint8), "L", (10, 10))
|
||||||
|
|
|
@ -52,10 +52,10 @@ class TestOleFileIo(PillowTestCase):
|
||||||
ole = OleFileIO.OleFileIO(ole_file)
|
ole = OleFileIO.OleFileIO(ole_file)
|
||||||
|
|
||||||
# Act
|
# Act
|
||||||
type = ole.get_type('worddocument')
|
entry_type = ole.get_type('worddocument')
|
||||||
|
|
||||||
# Assert
|
# Assert
|
||||||
self.assertEqual(type, OleFileIO.STGTY_STREAM)
|
self.assertEqual(entry_type, OleFileIO.STGTY_STREAM)
|
||||||
ole.close()
|
ole.close()
|
||||||
|
|
||||||
def test_get_size(self):
|
def test_get_size(self):
|
||||||
|
|
|
@ -22,8 +22,8 @@ class TestPickle(PillowTestCase):
|
||||||
self.assertEqual(im, loaded_im)
|
self.assertEqual(im, loaded_im)
|
||||||
|
|
||||||
def helper_pickle_string(self, pickle, protocol=0,
|
def helper_pickle_string(self, pickle, protocol=0,
|
||||||
file='Tests/images/hopper.jpg', mode=None):
|
test_file='Tests/images/hopper.jpg', mode=None):
|
||||||
im = Image.open(file)
|
im = Image.open(test_file)
|
||||||
if mode:
|
if mode:
|
||||||
im = im.convert(mode)
|
im = im.convert(mode)
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ class TestPickle(PillowTestCase):
|
||||||
"Tests/images/p_trns_single.png",
|
"Tests/images/p_trns_single.png",
|
||||||
"Tests/images/pil123p.png"
|
"Tests/images/pil123p.png"
|
||||||
]:
|
]:
|
||||||
self.helper_pickle_string(pickle, file=test_file)
|
self.helper_pickle_string(pickle, test_file=test_file)
|
||||||
|
|
||||||
def test_pickle_l_mode(self):
|
def test_pickle_l_mode(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
|
|
Loading…
Reference in New Issue
Block a user