mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-26 17:24:31 +03:00
commit
b9f688301a
|
@ -14,6 +14,7 @@ def bench(mode):
|
|||
get(xy)
|
||||
print(mode, timeit.default_timer() - t0, "us")
|
||||
|
||||
|
||||
bench("L")
|
||||
bench("I")
|
||||
bench("I;16")
|
||||
|
|
|
@ -40,5 +40,6 @@ class TestImagingLeaks(PillowTestCase):
|
|||
# Pass a new list at each iteration.
|
||||
lambda: im.point(range(256)))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -10,5 +10,6 @@ class TestJ2kEncodeOverflow(PillowTestCase):
|
|||
with self.assertRaises(IOError):
|
||||
im.save(target)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -60,5 +60,6 @@ class TestPngDos(PillowTestCase):
|
|||
self.assertLess(total_len, 64*1024*1024,
|
||||
"Total text chunks greater than 64M")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -17,7 +17,8 @@ HAS_UPLOADER = False
|
|||
|
||||
if os.environ.get('SHOW_ERRORS', None):
|
||||
# local img.show for errors.
|
||||
HAS_UPLOADER=True
|
||||
HAS_UPLOADER = True
|
||||
|
||||
class test_image_results:
|
||||
@classmethod
|
||||
def upload(self, a, b):
|
||||
|
@ -31,7 +32,6 @@ else:
|
|||
pass
|
||||
|
||||
|
||||
|
||||
def convert_to_comparable(a, b):
|
||||
new_a, new_b = a, b
|
||||
if a.mode == 'P':
|
||||
|
@ -246,7 +246,7 @@ class PillowLeakTestCase(PillowTestCase):
|
|||
if sys.platform == 'darwin':
|
||||
# man 2 getrusage:
|
||||
# ru_maxrss the maximum resident set size utilized (in bytes).
|
||||
return mem / 1024 # Kb
|
||||
return mem / 1024 # Kb
|
||||
else:
|
||||
# linux
|
||||
# man 2 getrusage
|
||||
|
|
|
@ -32,6 +32,7 @@ def check(size, i0):
|
|||
h[i] = m
|
||||
return h
|
||||
|
||||
|
||||
min_start = 0
|
||||
|
||||
# 1) find the smallest table size with no collisions
|
||||
|
|
|
@ -23,5 +23,6 @@ class TestBinary(PillowTestCase):
|
|||
self.assertEqual(_binary.o16be(65535), b'\xff\xff')
|
||||
self.assertEqual(_binary.o32be(65535), b'\x00\x00\xff\xff')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -30,7 +30,7 @@ class TestDecompressionBomb(PillowTestCase):
|
|||
|
||||
def test_warning(self):
|
||||
# Set limit to trigger warning on the test file
|
||||
Image.MAX_IMAGE_PIXELS = 128 * 128 -1
|
||||
Image.MAX_IMAGE_PIXELS = 128 * 128 - 1
|
||||
self.assertEqual(Image.MAX_IMAGE_PIXELS, 128 * 128 - 1)
|
||||
|
||||
self.assert_warning(Image.DecompressionBombWarning,
|
||||
|
@ -38,12 +38,13 @@ class TestDecompressionBomb(PillowTestCase):
|
|||
|
||||
def test_exception(self):
|
||||
# Set limit to trigger exception on the test file
|
||||
Image.MAX_IMAGE_PIXELS = 64 * 128 -1
|
||||
Image.MAX_IMAGE_PIXELS = 64 * 128 - 1
|
||||
self.assertEqual(Image.MAX_IMAGE_PIXELS, 64 * 128 - 1)
|
||||
|
||||
self.assertRaises(Image.DecompressionBombError,
|
||||
lambda: Image.open(TEST_FILE))
|
||||
|
||||
|
||||
class TestDecompressionCrop(PillowTestCase):
|
||||
|
||||
def setUp(self):
|
||||
|
|
|
@ -111,5 +111,6 @@ class TestFileDds(PillowTestCase):
|
|||
|
||||
self.assertRaises(IOError, short_file)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -15,5 +15,6 @@ class TestFileFtex(PillowTestCase):
|
|||
target = Image.open('Tests/images/ftex_dxt1.png')
|
||||
self.assert_image_similar(im, target.convert('RGBA'), 15)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -18,5 +18,6 @@ class TestFileGbr(PillowTestCase):
|
|||
|
||||
self.assert_image_equal(target, im)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -266,7 +266,7 @@ class TestFileGif(PillowTestCase):
|
|||
Image.new('L', (100, 100), '#111'),
|
||||
Image.new('L', (100, 100), '#222'),
|
||||
]
|
||||
for method in range(0,4):
|
||||
for method in range(0, 4):
|
||||
im_list[0].save(
|
||||
out,
|
||||
save_all=True,
|
||||
|
@ -278,7 +278,6 @@ class TestFileGif(PillowTestCase):
|
|||
img.seek(img.tell() + 1)
|
||||
self.assertEqual(img.disposal_method, method)
|
||||
|
||||
|
||||
# check per frame disposal
|
||||
im_list[0].save(
|
||||
out,
|
||||
|
@ -582,9 +581,10 @@ class TestFileGif(PillowTestCase):
|
|||
# see https://github.com/python-pillow/Pillow/issues/2811
|
||||
im = Image.open('Tests/images/issue_2811.gif')
|
||||
|
||||
self.assertEqual(im.tile[0][3][0], 11) # LZW bits
|
||||
self.assertEqual(im.tile[0][3][0], 11) # LZW bits
|
||||
# codec error prepatch
|
||||
im.load()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -141,7 +141,7 @@ class TestFileJpeg(PillowTestCase):
|
|||
f = self.tempfile("temp.jpg")
|
||||
icc_profile = im.info["icc_profile"]
|
||||
try:
|
||||
im.save(f, format='JPEG', progressive=True,quality=95,
|
||||
im.save(f, format='JPEG', progressive=True, quality=95,
|
||||
icc_profile=icc_profile, optimize=True)
|
||||
except IOError:
|
||||
self.fail("Failed saving image with icc larger than image size")
|
||||
|
|
|
@ -176,5 +176,6 @@ class TestFileJpeg2k(PillowTestCase):
|
|||
with self.assertRaises(IOError):
|
||||
Image.open('Tests/images/unbound_variable.jp2')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -22,6 +22,7 @@ def chunk(cid, *data):
|
|||
PngImagePlugin.putchunk(*(test_file, cid) + data)
|
||||
return test_file.getvalue()
|
||||
|
||||
|
||||
o32 = PngImagePlugin.o32
|
||||
|
||||
IHDR = chunk(b"IHDR", o32(1), o32(1), b'\x08\x02', b'\0\0\0')
|
||||
|
@ -542,7 +543,7 @@ class TestFilePng(PillowTestCase):
|
|||
@unittest.skipIf(sys.platform.startswith('win32'), "requires Unix or MacOS")
|
||||
class TestTruncatedPngPLeaks(PillowLeakTestCase):
|
||||
mem_limit = 2*1024 # max increase in K
|
||||
iterations = 100 # Leak is 56k/iteration, this will leak 5.6megs
|
||||
iterations = 100 # Leak is 56k/iteration, this will leak 5.6megs
|
||||
|
||||
def setUp(self):
|
||||
if "zip_encoder" not in codecs or "zip_decoder" not in codecs:
|
||||
|
|
|
@ -46,5 +46,6 @@ class TestFileSun(PillowTestCase):
|
|||
with Image.open(target_path) as target:
|
||||
self.assert_image_equal(im, target)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -178,8 +178,8 @@ class TestFileTiff(PillowTestCase):
|
|||
im = Image.open('Tests/images/16bit.s.tif')
|
||||
im.load()
|
||||
self.assertEqual(im.mode, 'I')
|
||||
self.assertEqual(im.getpixel((0,0)),32767)
|
||||
self.assertEqual(im.getpixel((0,1)),0)
|
||||
self.assertEqual(im.getpixel((0, 0)), 32767)
|
||||
self.assertEqual(im.getpixel((0, 1)), 0)
|
||||
|
||||
def test_12bit_rawmode(self):
|
||||
""" Are we generating the same interpretation
|
||||
|
@ -398,7 +398,6 @@ class TestFileTiff(PillowTestCase):
|
|||
self.assertEqual(im.tag_v2[X_RESOLUTION], 72)
|
||||
self.assertEqual(im.tag_v2[Y_RESOLUTION], 36)
|
||||
|
||||
|
||||
def test_roundtrip_tiff_uint16(self):
|
||||
# Test an image of all '0' values
|
||||
pixel_value = 0x1234
|
||||
|
@ -447,7 +446,6 @@ class TestFileTiff(PillowTestCase):
|
|||
reread = Image.open(mp)
|
||||
self.assertEqual(reread.n_frames, 3)
|
||||
|
||||
|
||||
def test_saving_icc_profile(self):
|
||||
# Tests saving TIFF with icc_profile set.
|
||||
# At the time of writing this will only work for non-compressed tiffs
|
||||
|
@ -489,6 +487,7 @@ class TestFileTiff(PillowTestCase):
|
|||
im.load()
|
||||
self.assertFalse(fp.closed)
|
||||
|
||||
|
||||
@unittest.skipUnless(sys.platform.startswith('win32'), "Windows only")
|
||||
class TestFileTiffW32(PillowTestCase):
|
||||
def test_fd_leak(self):
|
||||
|
|
|
@ -78,7 +78,6 @@ class TestFileTiffMetadata(PillowTestCase):
|
|||
self.assertEqual(loaded.tag[ImageJMetaDataByteCounts], (8, len(bindata) - 8))
|
||||
self.assertEqual(loaded.tag_v2[ImageJMetaDataByteCounts], (8, len(bindata) - 8))
|
||||
|
||||
|
||||
def test_read_metadata(self):
|
||||
img = Image.open('Tests/images/hopper_g4.tif')
|
||||
|
||||
|
@ -243,7 +242,7 @@ class TestFileTiffMetadata(PillowTestCase):
|
|||
ifd = TiffImagePlugin.ImageFileDirectory_v2()
|
||||
|
||||
# 277: ("SamplesPerPixel", SHORT, 1),
|
||||
ifd._tagdata[277] = struct.pack('hh', 4,4)
|
||||
ifd._tagdata[277] = struct.pack('hh', 4, 4)
|
||||
ifd.tagtype[277] = TiffTags.SHORT
|
||||
|
||||
try:
|
||||
|
|
|
@ -3,16 +3,17 @@ from helper import unittest, PillowLeakTestCase
|
|||
import sys
|
||||
from PIL import Image, features, ImageDraw, ImageFont
|
||||
|
||||
|
||||
@unittest.skipIf(sys.platform.startswith('win32'), "requires Unix or MacOS")
|
||||
class TestTTypeFontLeak(PillowLeakTestCase):
|
||||
# fails at iteration 3 in master
|
||||
iterations = 10
|
||||
mem_limit = 4096 #k
|
||||
mem_limit = 4096 # k
|
||||
|
||||
def _test_font(self, font):
|
||||
im = Image.new('RGB', (255,255), 'white')
|
||||
im = Image.new('RGB', (255, 255), 'white')
|
||||
draw = ImageDraw.ImageDraw(im)
|
||||
self._test_leak(lambda: draw.text((0, 0), "some text "*1024, #~10k
|
||||
self._test_leak(lambda: draw.text((0, 0), "some text "*1024, # ~10k
|
||||
font=font, fill="black"))
|
||||
|
||||
@unittest.skipIf(not features.check('freetype2'), "Test requires freetype2")
|
||||
|
@ -20,10 +21,11 @@ class TestTTypeFontLeak(PillowLeakTestCase):
|
|||
ttype = ImageFont.truetype('Tests/fonts/FreeMono.ttf', 20)
|
||||
self._test_font(ttype)
|
||||
|
||||
|
||||
class TestDefaultFontLeak(TestTTypeFontLeak):
|
||||
# fails at iteration 37 in master
|
||||
iterations = 100
|
||||
mem_limit = 1024 #k
|
||||
mem_limit = 1024 # k
|
||||
|
||||
def test_leak(self):
|
||||
default_font = ImageFont.load_default()
|
||||
|
|
|
@ -46,7 +46,7 @@ class TestFontPcf(PillowTestCase):
|
|||
def test_draw(self):
|
||||
tempname = self.save_font()
|
||||
font = ImageFont.load(tempname)
|
||||
im = Image.new("L", (130,30), "white")
|
||||
im = Image.new("L", (130, 30), "white")
|
||||
draw = ImageDraw.Draw(im)
|
||||
draw.text((0, 0), message, 'black', font=font)
|
||||
with Image.open('Tests/images/test_draw_pbm_target.png') as target:
|
||||
|
@ -56,23 +56,22 @@ class TestFontPcf(PillowTestCase):
|
|||
tempname = self.save_font()
|
||||
font = ImageFont.load(tempname)
|
||||
for i in range(255):
|
||||
(dx,dy) = font.getsize(chr(i))
|
||||
(dx, dy) = font.getsize(chr(i))
|
||||
self.assertEqual(dy, 20)
|
||||
self.assertIn(dx, (0,10))
|
||||
self.assertIn(dx, (0, 10))
|
||||
for l in range(len(message)):
|
||||
msg = message[:l+1]
|
||||
self.assertEqual(font.getsize(msg), (len(msg)*10,20))
|
||||
self.assertEqual(font.getsize(msg), (len(msg)*10, 20))
|
||||
|
||||
def _test_high_characters(self, message):
|
||||
tempname = self.save_font()
|
||||
font = ImageFont.load(tempname)
|
||||
im = Image.new("L", (750,30) , "white")
|
||||
im = Image.new("L", (750, 30) , "white")
|
||||
draw = ImageDraw.Draw(im)
|
||||
draw.text((0, 0), message, "black", font=font)
|
||||
with Image.open('Tests/images/high_ascii_chars.png') as target:
|
||||
self.assert_image_similar(im, target, 0)
|
||||
|
||||
|
||||
def test_high_characters(self):
|
||||
message = "".join(chr(i+1) for i in range(140, 232))
|
||||
self._test_high_characters(message)
|
||||
|
|
|
@ -10,6 +10,7 @@ from PIL import Image
|
|||
import sys
|
||||
import os
|
||||
|
||||
|
||||
class AccessTest(PillowTestCase):
|
||||
# initial value
|
||||
_init_cffi_access = Image.USE_CFFI_ACCESS
|
||||
|
@ -309,5 +310,6 @@ int main(int argc, char* argv[])
|
|||
process.communicate()
|
||||
self.assertEqual(process.returncode, 0)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -90,7 +90,6 @@ class TestImageConvert(PillowTestCase):
|
|||
# https://github.com/python-pillow/Pillow/issues/2702
|
||||
self.assertEqual(rgba.palette, None)
|
||||
|
||||
|
||||
def test_trns_l(self):
|
||||
im = hopper('L')
|
||||
im.info['transparency'] = 128
|
||||
|
|
|
@ -70,5 +70,6 @@ class TestImageDraft(PillowTestCase):
|
|||
im.draft(None, (64, 64))
|
||||
im.load()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -29,5 +29,6 @@ class TestImageLoad(PillowTestCase):
|
|||
|
||||
self.assertRaises(OSError, os.fstat, fn)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -84,5 +84,6 @@ class TestImagePutData(PillowTestCase):
|
|||
|
||||
self.assertEqual(len(im.getdata()), len(arr))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -7,5 +7,6 @@ class TestImageToBytes(PillowTestCase):
|
|||
data = hopper().tobytes()
|
||||
self.assertIsInstance(data, bytes)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -61,7 +61,7 @@ class TestImageTransform(PillowTestCase):
|
|||
Image.BILINEAR,
|
||||
fillcolor = 'red')
|
||||
|
||||
self.assertEqual(transformed.getpixel((w-1,h-1)), (255,0,0))
|
||||
self.assertEqual(transformed.getpixel((w-1, h-1)), (255, 0, 0))
|
||||
|
||||
def test_mesh(self):
|
||||
# this should be a checkerboard of halfsized hoppers in ul, lr
|
||||
|
@ -267,5 +267,6 @@ class TestImageTransformPerspective(TestImageTransformAffine):
|
|||
# Repeat all tests for AFFINE transformations with PERSPECTIVE
|
||||
transform = Image.PERSPECTIVE
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -437,5 +437,6 @@ class TestImageCms(PillowTestCase):
|
|||
|
||||
self.assert_image_equal(test_image.convert(dst_format[2]), reference_image)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -146,6 +146,7 @@ class MockPyDecoder(ImageFile.PyDecoder):
|
|||
# eof
|
||||
return (-1, 0)
|
||||
|
||||
|
||||
xoff, yoff, xsize, ysize = 10, 20, 100, 100
|
||||
|
||||
|
||||
|
@ -222,5 +223,6 @@ class TestPyDecoder(PillowTestCase):
|
|||
im.tile = [("MOCK", (xoff, yoff, xoff+xsize, yoff+ysize + 100), 32, None)]
|
||||
self.assertRaises(ValueError, im.load)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -420,7 +420,6 @@ class TestImageFont(PillowTestCase):
|
|||
with self.assertRaises(UnicodeEncodeError):
|
||||
font.getsize(u"’")
|
||||
|
||||
|
||||
def _test_fake_loading_font(self, path_to_fake, fontname):
|
||||
# Make a copy of FreeTypeFont so we can patch the original
|
||||
free_type_font = copy.deepcopy(ImageFont.FreeTypeFont)
|
||||
|
|
|
@ -34,5 +34,6 @@ class TestImageFontBitmap(PillowTestCase):
|
|||
text, fill=(0, 0, 0), font=font_outline)
|
||||
self.assert_image_similar(im_bitmap, im_outline, 20)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -6,6 +6,7 @@ from PIL import Image, ImageDraw, ImageFont, features
|
|||
FONT_SIZE = 20
|
||||
FONT_PATH = "Tests/fonts/DejaVuSans.ttf"
|
||||
|
||||
|
||||
@unittest.skipUnless(features.check('raqm'), "Raqm Library is not installed.")
|
||||
class TestImagecomplextext(PillowTestCase):
|
||||
|
||||
|
@ -16,7 +17,6 @@ class TestImagecomplextext(PillowTestCase):
|
|||
draw = ImageDraw.Draw(im)
|
||||
draw.text((0, 0), 'TEST', font=ttf, fill=500, direction='ltr')
|
||||
|
||||
|
||||
def test_complex_text(self):
|
||||
ttf = ImageFont.truetype(FONT_PATH, FONT_SIZE)
|
||||
|
||||
|
@ -101,7 +101,7 @@ class TestImagecomplextext(PillowTestCase):
|
|||
self.assert_image_similar(im, target_img, .5)
|
||||
|
||||
liga_size = ttf.getsize('fi', features=['-liga'])
|
||||
self.assertEqual(liga_size,(13,19))
|
||||
self.assertEqual(liga_size, (13, 19))
|
||||
|
||||
def test_kerning_features(self):
|
||||
ttf = ImageFont.truetype(FONT_PATH, FONT_SIZE)
|
||||
|
@ -120,13 +120,14 @@ class TestImagecomplextext(PillowTestCase):
|
|||
|
||||
im = Image.new(mode='RGB', size=(300, 100))
|
||||
draw = ImageDraw.Draw(im)
|
||||
draw.text((0, 0), 'اللغة العربية', font=ttf, fill=500, features=['-fina','-init','-medi'])
|
||||
draw.text((0, 0), 'اللغة العربية', font=ttf, fill=500, features=['-fina', '-init', '-medi'])
|
||||
|
||||
target = 'Tests/images/test_arabictext_features.png'
|
||||
target_img = Image.open(target)
|
||||
|
||||
self.assert_image_similar(im, target_img, .5)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ def pixel(im):
|
|||
return int(im) # hack to deal with booleans
|
||||
print(im)
|
||||
|
||||
|
||||
A = Image.new("L", (1, 1), 1)
|
||||
B = Image.new("L", (1, 1), 2)
|
||||
Z = Image.new("L", (1, 1), 0) # Z for zero
|
||||
|
|
|
@ -97,5 +97,6 @@ class TestImageOpsUsm(PillowTestCase):
|
|||
self.assertTrue(236 <= gp(8, 6)[2] <= 239)
|
||||
self.assertTrue(236 <= gp(8, 7)[1] <= 239)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -70,5 +70,6 @@ class TestImageSequence(PillowTestCase):
|
|||
color2 = im.getpalette()[0:3]
|
||||
self.assertEqual(color1, color2)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -24,26 +24,26 @@ class TestLibPack(PillowTestCase):
|
|||
self.assertEqual(data, im.tobytes("raw", rawmode))
|
||||
|
||||
def test_1(self):
|
||||
self.assert_pack("1", "1", b'\x01', 0,0,0,0,0,0,0,X)
|
||||
self.assert_pack("1", "1;I", b'\x01', X,X,X,X,X,X,X,0)
|
||||
self.assert_pack("1", "1;R", b'\x01', X,0,0,0,0,0,0,0)
|
||||
self.assert_pack("1", "1;IR", b'\x01', 0,X,X,X,X,X,X,X)
|
||||
self.assert_pack("1", "1", b'\x01', 0, 0, 0, 0, 0, 0, 0, X)
|
||||
self.assert_pack("1", "1;I", b'\x01', X, X, X, X, X, X, X, 0)
|
||||
self.assert_pack("1", "1;R", b'\x01', X, 0, 0, 0, 0, 0, 0, 0)
|
||||
self.assert_pack("1", "1;IR", b'\x01', 0, X, X, X, X, X, X, X)
|
||||
|
||||
self.assert_pack("1", "1", b'\xaa', X,0,X,0,X,0,X,0)
|
||||
self.assert_pack("1", "1;I", b'\xaa', 0,X,0,X,0,X,0,X)
|
||||
self.assert_pack("1", "1;R", b'\xaa', 0,X,0,X,0,X,0,X)
|
||||
self.assert_pack("1", "1;IR", b'\xaa', X,0,X,0,X,0,X,0)
|
||||
self.assert_pack("1", "1", b'\xaa', X, 0, X, 0, X, 0, X, 0)
|
||||
self.assert_pack("1", "1;I", b'\xaa', 0, X, 0, X, 0, X, 0, X)
|
||||
self.assert_pack("1", "1;R", b'\xaa', 0, X, 0, X, 0, X, 0, X)
|
||||
self.assert_pack("1", "1;IR", b'\xaa', X, 0, X, 0, X, 0, X, 0)
|
||||
|
||||
self.assert_pack("1", "L", b'\xff\x00\x00\xff\x00\x00', X,0,0,X,0,0)
|
||||
self.assert_pack("1", "L", b'\xff\x00\x00\xff\x00\x00', X, 0, 0, X, 0, 0)
|
||||
|
||||
def test_L(self):
|
||||
self.assert_pack("L", "L", 1, 1,2,3,4)
|
||||
self.assert_pack("L", "L", 1, 1, 2, 3, 4)
|
||||
self.assert_pack("L", "L;16", b'\x00\xc6\x00\xaf', 198, 175)
|
||||
self.assert_pack("L", "L;16B", b'\xc6\x00\xaf\x00', 198, 175)
|
||||
|
||||
def test_LA(self):
|
||||
self.assert_pack("LA", "LA", 2, (1,2), (3,4), (5,6))
|
||||
self.assert_pack("LA", "LA;L", 2, (1,4), (2,5), (3,6))
|
||||
self.assert_pack("LA", "LA", 2, (1, 2), (3, 4), (5, 6))
|
||||
self.assert_pack("LA", "LA;L", 2, (1, 4), (2, 5), (3, 6))
|
||||
|
||||
def test_P(self):
|
||||
self.assert_pack("P", "P;1", b'\xe4', 1, 1, 1, 0, 0, 255, 0, 0)
|
||||
|
@ -52,100 +52,100 @@ class TestLibPack(PillowTestCase):
|
|||
self.assert_pack("P", "P", 1, 1, 2, 3, 4)
|
||||
|
||||
def test_PA(self):
|
||||
self.assert_pack("PA", "PA", 2, (1,2), (3,4), (5,6))
|
||||
self.assert_pack("PA", "PA;L", 2, (1,4), (2,5), (3,6))
|
||||
self.assert_pack("PA", "PA", 2, (1, 2), (3, 4), (5, 6))
|
||||
self.assert_pack("PA", "PA;L", 2, (1, 4), (2, 5), (3, 6))
|
||||
|
||||
def test_RGB(self):
|
||||
self.assert_pack("RGB", "RGB", 3, (1,2,3), (4,5,6), (7,8,9))
|
||||
self.assert_pack("RGB", "RGB", 3, (1, 2, 3), (4, 5, 6), (7, 8, 9))
|
||||
self.assert_pack("RGB", "RGBX",
|
||||
b'\x01\x02\x03\xff\x05\x06\x07\xff', (1,2,3), (5,6,7))
|
||||
b'\x01\x02\x03\xff\x05\x06\x07\xff', (1, 2, 3), (5, 6, 7))
|
||||
self.assert_pack("RGB", "XRGB",
|
||||
b'\x00\x02\x03\x04\x00\x06\x07\x08', (2,3,4), (6,7,8))
|
||||
self.assert_pack("RGB", "BGR", 3, (3,2,1), (6,5,4), (9,8,7))
|
||||
b'\x00\x02\x03\x04\x00\x06\x07\x08', (2, 3, 4), (6, 7, 8))
|
||||
self.assert_pack("RGB", "BGR", 3, (3, 2, 1), (6, 5, 4), (9, 8, 7))
|
||||
self.assert_pack("RGB", "BGRX",
|
||||
b'\x01\x02\x03\x00\x05\x06\x07\x00', (3,2,1), (7,6,5))
|
||||
b'\x01\x02\x03\x00\x05\x06\x07\x00', (3, 2, 1), (7, 6, 5))
|
||||
self.assert_pack("RGB", "XBGR",
|
||||
b'\x00\x02\x03\x04\x00\x06\x07\x08', (4,3,2), (8,7,6))
|
||||
self.assert_pack("RGB", "RGB;L", 3, (1,4,7), (2,5,8), (3,6,9))
|
||||
self.assert_pack("RGB", "R", 1, (1,9,9), (2,9,9), (3,9,9))
|
||||
self.assert_pack("RGB", "G", 1, (9,1,9), (9,2,9), (9,3,9))
|
||||
self.assert_pack("RGB", "B", 1, (9,9,1), (9,9,2), (9,9,3))
|
||||
b'\x00\x02\x03\x04\x00\x06\x07\x08', (4, 3, 2), (8, 7, 6))
|
||||
self.assert_pack("RGB", "RGB;L", 3, (1, 4, 7), (2, 5, 8), (3, 6, 9))
|
||||
self.assert_pack("RGB", "R", 1, (1, 9, 9), (2, 9, 9), (3, 9, 9))
|
||||
self.assert_pack("RGB", "G", 1, (9, 1, 9), (9, 2, 9), (9, 3, 9))
|
||||
self.assert_pack("RGB", "B", 1, (9, 9, 1), (9, 9, 2), (9, 9, 3))
|
||||
|
||||
def test_RGBA(self):
|
||||
self.assert_pack("RGBA", "RGBA", 4,
|
||||
(1,2,3,4), (5,6,7,8), (9,10,11,12))
|
||||
(1, 2, 3, 4), (5, 6, 7, 8), (9, 10, 11, 12))
|
||||
self.assert_pack("RGBA", "RGBA;L", 4,
|
||||
(1,4,7,10), (2,5,8,11), (3,6,9,12))
|
||||
self.assert_pack("RGBA", "RGB", 3, (1,2,3,14), (4,5,6,15), (7,8,9,16))
|
||||
self.assert_pack("RGBA", "BGR", 3, (3,2,1,14), (6,5,4,15), (9,8,7,16))
|
||||
(1, 4, 7, 10), (2, 5, 8, 11), (3, 6, 9, 12))
|
||||
self.assert_pack("RGBA", "RGB", 3, (1, 2, 3, 14), (4, 5, 6, 15), (7, 8, 9, 16))
|
||||
self.assert_pack("RGBA", "BGR", 3, (3, 2, 1, 14), (6, 5, 4, 15), (9, 8, 7, 16))
|
||||
self.assert_pack("RGBA", "BGRA", 4,
|
||||
(3,2,1,4), (7,6,5,8), (11,10,9,12))
|
||||
(3, 2, 1, 4), (7, 6, 5, 8), (11, 10, 9, 12))
|
||||
self.assert_pack("RGBA", "ABGR", 4,
|
||||
(4,3,2,1), (8,7,6,5), (12,11,10,9))
|
||||
(4, 3, 2, 1), (8, 7, 6, 5), (12, 11, 10, 9))
|
||||
self.assert_pack("RGBA", "BGRa", 4,
|
||||
(191,127,63,4), (223,191,159,8), (233,212,191,12))
|
||||
self.assert_pack("RGBA", "R", 1, (1,0,8,9), (2,0,8,9), (3,0,8,0))
|
||||
self.assert_pack("RGBA", "G", 1, (6,1,8,9), (6,2,8,9), (6,3,8,9))
|
||||
self.assert_pack("RGBA", "B", 1, (6,7,1,9), (6,7,2,0), (6,7,3,9))
|
||||
self.assert_pack("RGBA", "A", 1, (6,7,0,1), (6,7,0,2), (0,7,0,3))
|
||||
(191, 127, 63, 4), (223, 191, 159, 8), (233, 212, 191, 12))
|
||||
self.assert_pack("RGBA", "R", 1, (1, 0, 8, 9), (2, 0, 8, 9), (3, 0, 8, 0))
|
||||
self.assert_pack("RGBA", "G", 1, (6, 1, 8, 9), (6, 2, 8, 9), (6, 3, 8, 9))
|
||||
self.assert_pack("RGBA", "B", 1, (6, 7, 1, 9), (6, 7, 2, 0), (6, 7, 3, 9))
|
||||
self.assert_pack("RGBA", "A", 1, (6, 7, 0, 1), (6, 7, 0, 2), (0, 7, 0, 3))
|
||||
|
||||
def test_RGBa(self):
|
||||
self.assert_pack("RGBa", "RGBa", 4,
|
||||
(1,2,3,4), (5,6,7,8), (9,10,11,12))
|
||||
(1, 2, 3, 4), (5, 6, 7, 8), (9, 10, 11, 12))
|
||||
self.assert_pack("RGBa", "BGRa", 4,
|
||||
(3,2,1,4), (7,6,5,8), (11,10,9,12))
|
||||
(3, 2, 1, 4), (7, 6, 5, 8), (11, 10, 9, 12))
|
||||
self.assert_pack("RGBa", "aBGR", 4,
|
||||
(4,3,2,1), (8,7,6,5), (12,11,10,9))
|
||||
(4, 3, 2, 1), (8, 7, 6, 5), (12, 11, 10, 9))
|
||||
|
||||
def test_RGBX(self):
|
||||
self.assert_pack("RGBX", "RGBX", 4, (1,2,3,4), (5,6,7,8), (9,10,11,12))
|
||||
self.assert_pack("RGBX", "RGBX;L", 4, (1,4,7,10), (2,5,8,11), (3,6,9,12))
|
||||
self.assert_pack("RGBX", "RGB", 3, (1,2,3,X), (4,5,6,X), (7,8,9,X))
|
||||
self.assert_pack("RGBX", "BGR", 3, (3,2,1,X), (6,5,4,X), (9,8,7,X))
|
||||
self.assert_pack("RGBX", "RGBX", 4, (1, 2, 3, 4), (5, 6, 7, 8), (9, 10, 11, 12))
|
||||
self.assert_pack("RGBX", "RGBX;L", 4, (1, 4, 7, 10), (2, 5, 8, 11), (3, 6, 9, 12))
|
||||
self.assert_pack("RGBX", "RGB", 3, (1, 2, 3, X), (4, 5, 6, X), (7, 8, 9, X))
|
||||
self.assert_pack("RGBX", "BGR", 3, (3, 2, 1, X), (6, 5, 4, X), (9, 8, 7, X))
|
||||
self.assert_pack("RGBX", "BGRX",
|
||||
b'\x01\x02\x03\x00\x05\x06\x07\x00\t\n\x0b\x00',
|
||||
(3,2,1,X), (7,6,5,X), (11,10,9,X))
|
||||
(3, 2, 1, X), (7, 6, 5, X), (11, 10, 9, X))
|
||||
self.assert_pack("RGBX", "XBGR",
|
||||
b'\x00\x02\x03\x04\x00\x06\x07\x08\x00\n\x0b\x0c',
|
||||
(4,3,2,X), (8,7,6,X), (12,11,10,X))
|
||||
self.assert_pack("RGBX", "R", 1, (1,0,8,9), (2,0,8,9), (3,0,8,0))
|
||||
self.assert_pack("RGBX", "G", 1, (6,1,8,9), (6,2,8,9), (6,3,8,9))
|
||||
self.assert_pack("RGBX", "B", 1, (6,7,1,9), (6,7,2,0), (6,7,3,9))
|
||||
self.assert_pack("RGBX", "X", 1, (6,7,0,1), (6,7,0,2), (0,7,0,3))
|
||||
(4, 3, 2, X), (8, 7, 6, X), (12, 11, 10, X))
|
||||
self.assert_pack("RGBX", "R", 1, (1, 0, 8, 9), (2, 0, 8, 9), (3, 0, 8, 0))
|
||||
self.assert_pack("RGBX", "G", 1, (6, 1, 8, 9), (6, 2, 8, 9), (6, 3, 8, 9))
|
||||
self.assert_pack("RGBX", "B", 1, (6, 7, 1, 9), (6, 7, 2, 0), (6, 7, 3, 9))
|
||||
self.assert_pack("RGBX", "X", 1, (6, 7, 0, 1), (6, 7, 0, 2), (0, 7, 0, 3))
|
||||
|
||||
def test_CMYK(self):
|
||||
self.assert_pack("CMYK", "CMYK", 4, (1,2,3,4), (5,6,7,8), (9,10,11,12))
|
||||
self.assert_pack("CMYK", "CMYK", 4, (1, 2, 3, 4), (5, 6, 7, 8), (9, 10, 11, 12))
|
||||
self.assert_pack("CMYK", "CMYK;I", 4,
|
||||
(254,253,252,251), (250,249,248,247), (246,245,244,243))
|
||||
(254, 253, 252, 251), (250, 249, 248, 247), (246, 245, 244, 243))
|
||||
self.assert_pack("CMYK", "CMYK;L", 4,
|
||||
(1,4,7,10), (2,5,8,11), (3,6,9,12))
|
||||
self.assert_pack("CMYK", "K", 1, (6,7,0,1), (6,7,0,2), (0,7,0,3))
|
||||
(1, 4, 7, 10), (2, 5, 8, 11), (3, 6, 9, 12))
|
||||
self.assert_pack("CMYK", "K", 1, (6, 7, 0, 1), (6, 7, 0, 2), (0, 7, 0, 3))
|
||||
|
||||
def test_YCbCr(self):
|
||||
self.assert_pack("YCbCr", "YCbCr", 3, (1,2,3), (4,5,6), (7,8,9))
|
||||
self.assert_pack("YCbCr", "YCbCr;L", 3, (1,4,7), (2,5,8), (3,6,9))
|
||||
self.assert_pack("YCbCr", "YCbCr", 3, (1, 2, 3), (4, 5, 6), (7, 8, 9))
|
||||
self.assert_pack("YCbCr", "YCbCr;L", 3, (1, 4, 7), (2, 5, 8), (3, 6, 9))
|
||||
self.assert_pack("YCbCr", "YCbCrX",
|
||||
b'\x01\x02\x03\xff\x05\x06\x07\xff\t\n\x0b\xff',
|
||||
(1,2,3), (5,6,7), (9,10,11))
|
||||
(1, 2, 3), (5, 6, 7), (9, 10, 11))
|
||||
self.assert_pack("YCbCr", "YCbCrK",
|
||||
b'\x01\x02\x03\xff\x05\x06\x07\xff\t\n\x0b\xff',
|
||||
(1,2,3), (5,6,7), (9,10,11))
|
||||
self.assert_pack("YCbCr", "Y", 1, (1,0,8,9), (2,0,8,9), (3,0,8,0))
|
||||
self.assert_pack("YCbCr", "Cb", 1, (6,1,8,9), (6,2,8,9), (6,3,8,9))
|
||||
self.assert_pack("YCbCr", "Cr", 1, (6,7,1,9), (6,7,2,0), (6,7,3,9))
|
||||
(1, 2, 3), (5, 6, 7), (9, 10, 11))
|
||||
self.assert_pack("YCbCr", "Y", 1, (1, 0, 8, 9), (2, 0, 8, 9), (3, 0, 8, 0))
|
||||
self.assert_pack("YCbCr", "Cb", 1, (6, 1, 8, 9), (6, 2, 8, 9), (6, 3, 8, 9))
|
||||
self.assert_pack("YCbCr", "Cr", 1, (6, 7, 1, 9), (6, 7, 2, 0), (6, 7, 3, 9))
|
||||
|
||||
def test_LAB(self):
|
||||
self.assert_pack("LAB", "LAB", 3,
|
||||
(1,130,131), (4,133,134), (7,136,137))
|
||||
self.assert_pack("LAB", "L", 1, (1,9,9), (2,9,9), (3,9,9))
|
||||
self.assert_pack("LAB", "A", 1, (9,1,9), (9,2,9), (9,3,9))
|
||||
self.assert_pack("LAB", "B", 1, (9,9,1), (9,9,2), (9,9,3))
|
||||
(1, 130, 131), (4, 133, 134), (7, 136, 137))
|
||||
self.assert_pack("LAB", "L", 1, (1, 9, 9), (2, 9, 9), (3, 9, 9))
|
||||
self.assert_pack("LAB", "A", 1, (9, 1, 9), (9, 2, 9), (9, 3, 9))
|
||||
self.assert_pack("LAB", "B", 1, (9, 9, 1), (9, 9, 2), (9, 9, 3))
|
||||
|
||||
def test_HSV(self):
|
||||
self.assert_pack("HSV", "HSV", 3, (1,2,3), (4,5,6), (7,8,9))
|
||||
self.assert_pack("HSV", "H", 1, (1,9,9), (2,9,9), (3,9,9))
|
||||
self.assert_pack("HSV", "S", 1, (9,1,9), (9,2,9), (9,3,9))
|
||||
self.assert_pack("HSV", "V", 1, (9,9,1), (9,9,2), (9,9,3))
|
||||
self.assert_pack("HSV", "HSV", 3, (1, 2, 3), (4, 5, 6), (7, 8, 9))
|
||||
self.assert_pack("HSV", "H", 1, (1, 9, 9), (2, 9, 9), (3, 9, 9))
|
||||
self.assert_pack("HSV", "S", 1, (9, 1, 9), (9, 2, 9), (9, 3, 9))
|
||||
self.assert_pack("HSV", "V", 1, (9, 9, 1), (9, 9, 2), (9, 9, 3))
|
||||
|
||||
def test_I(self):
|
||||
self.assert_pack("I", "I;16B", 2, 0x0102, 0x0304)
|
||||
|
@ -226,7 +226,6 @@ class TestLibUnpack(PillowTestCase):
|
|||
self.assert_unpack("L", "L;16", b'\x00\xc6\x00\xaf', 198, 175)
|
||||
self.assert_unpack("L", "L;16B", b'\xc6\x00\xaf\x00', 198, 175)
|
||||
|
||||
|
||||
def test_LA(self):
|
||||
self.assert_unpack("LA", "LA", 2, (1, 2), (3, 4), (5, 6))
|
||||
self.assert_unpack("LA", "LA;L", 2, (1, 4), (2, 5), (3, 6))
|
||||
|
@ -245,163 +244,163 @@ class TestLibUnpack(PillowTestCase):
|
|||
self.assert_unpack("PA", "PA;L", 2, (1, 4), (2, 5), (3, 6))
|
||||
|
||||
def test_RGB(self):
|
||||
self.assert_unpack("RGB", "RGB", 3, (1,2,3), (4,5,6), (7,8,9))
|
||||
self.assert_unpack("RGB", "RGB;L", 3, (1,4,7), (2,5,8), (3,6,9))
|
||||
self.assert_unpack("RGB", "RGB;R", 3, (128,64,192), (32,160,96))
|
||||
self.assert_unpack("RGB", "RGB;16L", 6, (2,4,6), (8,10,12))
|
||||
self.assert_unpack("RGB", "RGB;16B", 6, (1,3,5), (7,9,11))
|
||||
self.assert_unpack("RGB", "BGR", 3, (3,2,1), (6,5,4), (9,8,7))
|
||||
self.assert_unpack("RGB", "RGB;15", 2, (8,131,0), (24,0,8))
|
||||
self.assert_unpack("RGB", "BGR;15", 2, (0,131,8), (8,0,24))
|
||||
self.assert_unpack("RGB", "RGB;16", 2, (8,64,0), (24,129,0))
|
||||
self.assert_unpack("RGB", "BGR;16", 2, (0,64,8), (0,129,24))
|
||||
self.assert_unpack("RGB", "RGB;4B", 2, (17,0,34), (51,0,68))
|
||||
self.assert_unpack("RGB", "RGBX", 4, (1,2,3), (5,6,7), (9,10,11))
|
||||
self.assert_unpack("RGB", "RGBX;L", 4, (1,4,7), (2,5,8), (3,6,9))
|
||||
self.assert_unpack("RGB", "BGRX", 4, (3,2,1), (7,6,5), (11,10,9))
|
||||
self.assert_unpack("RGB", "XRGB", 4, (2,3,4), (6,7,8), (10,11,12))
|
||||
self.assert_unpack("RGB", "XBGR", 4, (4,3,2), (8,7,6), (12,11,10))
|
||||
self.assert_unpack("RGB", "RGB", 3, (1, 2, 3), (4, 5, 6), (7, 8, 9))
|
||||
self.assert_unpack("RGB", "RGB;L", 3, (1, 4, 7), (2, 5, 8), (3, 6, 9))
|
||||
self.assert_unpack("RGB", "RGB;R", 3, (128, 64, 192), (32, 160, 96))
|
||||
self.assert_unpack("RGB", "RGB;16L", 6, (2, 4, 6), (8, 10, 12))
|
||||
self.assert_unpack("RGB", "RGB;16B", 6, (1, 3, 5), (7, 9, 11))
|
||||
self.assert_unpack("RGB", "BGR", 3, (3, 2, 1), (6, 5, 4), (9, 8, 7))
|
||||
self.assert_unpack("RGB", "RGB;15", 2, (8, 131, 0), (24, 0, 8))
|
||||
self.assert_unpack("RGB", "BGR;15", 2, (0, 131, 8), (8, 0, 24))
|
||||
self.assert_unpack("RGB", "RGB;16", 2, (8, 64, 0), (24, 129, 0))
|
||||
self.assert_unpack("RGB", "BGR;16", 2, (0, 64, 8), (0, 129, 24))
|
||||
self.assert_unpack("RGB", "RGB;4B", 2, (17, 0, 34), (51, 0, 68))
|
||||
self.assert_unpack("RGB", "RGBX", 4, (1, 2, 3), (5, 6, 7), (9, 10, 11))
|
||||
self.assert_unpack("RGB", "RGBX;L", 4, (1, 4, 7), (2, 5, 8), (3, 6, 9))
|
||||
self.assert_unpack("RGB", "BGRX", 4, (3, 2, 1), (7, 6, 5), (11, 10, 9))
|
||||
self.assert_unpack("RGB", "XRGB", 4, (2, 3, 4), (6, 7, 8), (10, 11, 12))
|
||||
self.assert_unpack("RGB", "XBGR", 4, (4, 3, 2), (8, 7, 6), (12, 11, 10))
|
||||
self.assert_unpack("RGB", "YCC;P",
|
||||
b'D]\x9c\x82\x1a\x91\xfaOC\xe7J\x12', # random data
|
||||
(127,102,0), (192,227,0), (213,255,170), (98,255,133))
|
||||
self.assert_unpack("RGB", "R", 1, (1,0,0), (2,0,0), (3,0,0))
|
||||
self.assert_unpack("RGB", "G", 1, (0,1,0), (0,2,0), (0,3,0))
|
||||
self.assert_unpack("RGB", "B", 1, (0,0,1), (0,0,2), (0,0,3))
|
||||
(127, 102, 0), (192, 227, 0), (213, 255, 170), (98, 255, 133))
|
||||
self.assert_unpack("RGB", "R", 1, (1, 0, 0), (2, 0, 0), (3, 0, 0))
|
||||
self.assert_unpack("RGB", "G", 1, (0, 1, 0), (0, 2, 0), (0, 3, 0))
|
||||
self.assert_unpack("RGB", "B", 1, (0, 0, 1), (0, 0, 2), (0, 0, 3))
|
||||
|
||||
def test_RGBA(self):
|
||||
self.assert_unpack("RGBA", "LA", 2, (1,1,1,2), (3,3,3,4), (5,5,5,6))
|
||||
self.assert_unpack("RGBA", "LA", 2, (1, 1, 1, 2), (3, 3, 3, 4), (5, 5, 5, 6))
|
||||
self.assert_unpack("RGBA", "LA;16B", 4,
|
||||
(1,1,1,3), (5,5,5,7), (9,9,9,11))
|
||||
(1, 1, 1, 3), (5, 5, 5, 7), (9, 9, 9, 11))
|
||||
self.assert_unpack("RGBA", "RGBA", 4,
|
||||
(1,2,3,4), (5,6,7,8), (9,10,11,12))
|
||||
(1, 2, 3, 4), (5, 6, 7, 8), (9, 10, 11, 12))
|
||||
self.assert_unpack("RGBA", "RGBa", 4,
|
||||
(63,127,191,4), (159,191,223,8), (191,212,233,12))
|
||||
(63, 127, 191, 4), (159, 191, 223, 8), (191, 212, 233, 12))
|
||||
self.assert_unpack("RGBA", "RGBa",
|
||||
b'\x01\x02\x03\x00\x10\x20\x30\xff',
|
||||
(0,0,0,0), (16,32,48,255))
|
||||
(0, 0, 0, 0), (16, 32, 48, 255))
|
||||
self.assert_unpack("RGBA", "RGBa;16L", 8,
|
||||
(63,127,191,8), (159,191,223,16), (191,212,233,24))
|
||||
(63, 127, 191, 8), (159, 191, 223, 16), (191, 212, 233, 24))
|
||||
self.assert_unpack("RGBA", "RGBa;16L",
|
||||
b'\x88\x01\x88\x02\x88\x03\x88\x00'
|
||||
b'\x88\x10\x88\x20\x88\x30\x88\xff',
|
||||
(0,0,0,0), (16,32,48,255))
|
||||
(0, 0, 0, 0), (16, 32, 48, 255))
|
||||
self.assert_unpack("RGBA", "RGBa;16B", 8,
|
||||
(36,109,182,7), (153,187,221,15), (188,210,232,23))
|
||||
(36, 109, 182, 7), (153, 187, 221, 15), (188, 210, 232, 23))
|
||||
self.assert_unpack("RGBA", "RGBa;16B",
|
||||
b'\x01\x88\x02\x88\x03\x88\x00\x88'
|
||||
b'\x10\x88\x20\x88\x30\x88\xff\x88',
|
||||
(0,0,0,0), (16,32,48,255))
|
||||
(0, 0, 0, 0), (16, 32, 48, 255))
|
||||
self.assert_unpack("RGBA", "BGRa", 4,
|
||||
(191,127,63,4), (223,191,159,8), (233,212,191,12))
|
||||
(191, 127, 63, 4), (223, 191, 159, 8), (233, 212, 191, 12))
|
||||
self.assert_unpack("RGBA", "BGRa",
|
||||
b'\x01\x02\x03\x00\x10\x20\x30\xff',
|
||||
(0,0,0,0), (48,32,16,255))
|
||||
(0, 0, 0, 0), (48, 32, 16, 255))
|
||||
self.assert_unpack("RGBA", "RGBA;I", 4,
|
||||
(254,253,252,4), (250,249,248,8), (246,245,244,12))
|
||||
(254, 253, 252, 4), (250, 249, 248, 8), (246, 245, 244, 12))
|
||||
self.assert_unpack("RGBA", "RGBA;L", 4,
|
||||
(1,4,7,10), (2,5,8,11), (3,6,9,12))
|
||||
self.assert_unpack("RGBA", "RGBA;15", 2, (8,131,0,0), (24,0,8,0))
|
||||
self.assert_unpack("RGBA", "BGRA;15", 2, (0,131,8,0), (8,0,24,0))
|
||||
self.assert_unpack("RGBA", "RGBA;4B", 2, (17,0,34,0), (51,0,68,0))
|
||||
self.assert_unpack("RGBA", "RGBA;16L", 8, (2,4,6,8), (10,12,14,16))
|
||||
self.assert_unpack("RGBA", "RGBA;16B", 8, (1,3,5,7), (9,11,13,15))
|
||||
(1, 4, 7, 10), (2, 5, 8, 11), (3, 6, 9, 12))
|
||||
self.assert_unpack("RGBA", "RGBA;15", 2, (8, 131, 0, 0), (24, 0, 8, 0))
|
||||
self.assert_unpack("RGBA", "BGRA;15", 2, (0, 131, 8, 0), (8, 0, 24, 0))
|
||||
self.assert_unpack("RGBA", "RGBA;4B", 2, (17, 0, 34, 0), (51, 0, 68, 0))
|
||||
self.assert_unpack("RGBA", "RGBA;16L", 8, (2, 4, 6, 8), (10, 12, 14, 16))
|
||||
self.assert_unpack("RGBA", "RGBA;16B", 8, (1, 3, 5, 7), (9, 11, 13, 15))
|
||||
self.assert_unpack("RGBA", "BGRA", 4,
|
||||
(3,2,1,4), (7,6,5,8), (11,10,9,12))
|
||||
(3, 2, 1, 4), (7, 6, 5, 8), (11, 10, 9, 12))
|
||||
self.assert_unpack("RGBA", "ARGB", 4,
|
||||
(2,3,4,1), (6,7,8,5), (10,11,12,9))
|
||||
(2, 3, 4, 1), (6, 7, 8, 5), (10, 11, 12, 9))
|
||||
self.assert_unpack("RGBA", "ABGR", 4,
|
||||
(4,3,2,1), (8,7,6,5), (12,11,10,9))
|
||||
(4, 3, 2, 1), (8, 7, 6, 5), (12, 11, 10, 9))
|
||||
self.assert_unpack("RGBA", "YCCA;P",
|
||||
b']bE\x04\xdd\xbej\xed57T\xce\xac\xce:\x11', # random data
|
||||
(0,161,0,4), (255,255,255,237), (27,158,0,206), (0,118,0,17))
|
||||
self.assert_unpack("RGBA", "R", 1, (1,0,0,0), (2,0,0,0), (3,0,0,0))
|
||||
self.assert_unpack("RGBA", "G", 1, (0,1,0,0), (0,2,0,0), (0,3,0,0))
|
||||
self.assert_unpack("RGBA", "B", 1, (0,0,1,0), (0,0,2,0), (0,0,3,0))
|
||||
self.assert_unpack("RGBA", "A", 1, (0,0,0,1), (0,0,0,2), (0,0,0,3))
|
||||
(0, 161, 0, 4), (255, 255, 255, 237), (27, 158, 0, 206), (0, 118, 0, 17))
|
||||
self.assert_unpack("RGBA", "R", 1, (1, 0, 0, 0), (2, 0, 0, 0), (3, 0, 0, 0))
|
||||
self.assert_unpack("RGBA", "G", 1, (0, 1, 0, 0), (0, 2, 0, 0), (0, 3, 0, 0))
|
||||
self.assert_unpack("RGBA", "B", 1, (0, 0, 1, 0), (0, 0, 2, 0), (0, 0, 3, 0))
|
||||
self.assert_unpack("RGBA", "A", 1, (0, 0, 0, 1), (0, 0, 0, 2), (0, 0, 0, 3))
|
||||
|
||||
def test_RGBa(self):
|
||||
self.assert_unpack("RGBa", "RGBa", 4,
|
||||
(1,2,3,4), (5,6,7,8), (9,10,11,12))
|
||||
(1, 2, 3, 4), (5, 6, 7, 8), (9, 10, 11, 12))
|
||||
self.assert_unpack("RGBa", "BGRa", 4,
|
||||
(3,2,1,4), (7,6,5,8), (11,10,9,12))
|
||||
(3, 2, 1, 4), (7, 6, 5, 8), (11, 10, 9, 12))
|
||||
self.assert_unpack("RGBa", "aRGB", 4,
|
||||
(2,3,4,1), (6,7,8,5), (10,11,12,9))
|
||||
(2, 3, 4, 1), (6, 7, 8, 5), (10, 11, 12, 9))
|
||||
self.assert_unpack("RGBa", "aBGR", 4,
|
||||
(4,3,2,1), (8,7,6,5), (12,11,10,9))
|
||||
(4, 3, 2, 1), (8, 7, 6, 5), (12, 11, 10, 9))
|
||||
|
||||
def test_RGBX(self):
|
||||
self.assert_unpack("RGBX", "RGB", 3, (1,2,3,X), (4,5,6,X), (7,8,9,X))
|
||||
self.assert_unpack("RGBX", "RGB;L", 3, (1,4,7,X), (2,5,8,X), (3,6,9,X))
|
||||
self.assert_unpack("RGBX", "RGB;16B", 6, (1,3,5,X), (7,9,11,X))
|
||||
self.assert_unpack("RGBX", "BGR", 3, (3,2,1,X), (6,5,4,X), (9,8,7,X))
|
||||
self.assert_unpack("RGBX", "RGB;15", 2, (8,131,0,X), (24,0,8,X))
|
||||
self.assert_unpack("RGBX", "BGR;15", 2, (0,131,8,X), (8,0,24,X))
|
||||
self.assert_unpack("RGBX", "RGB;4B", 2, (17,0,34,X), (51,0,68,X))
|
||||
self.assert_unpack("RGBX", "RGB", 3, (1, 2, 3, X), (4, 5, 6, X), (7, 8, 9, X))
|
||||
self.assert_unpack("RGBX", "RGB;L", 3, (1, 4, 7, X), (2, 5, 8, X), (3, 6, 9, X))
|
||||
self.assert_unpack("RGBX", "RGB;16B", 6, (1, 3, 5, X), (7, 9, 11, X))
|
||||
self.assert_unpack("RGBX", "BGR", 3, (3, 2, 1, X), (6, 5, 4, X), (9, 8, 7, X))
|
||||
self.assert_unpack("RGBX", "RGB;15", 2, (8, 131, 0, X), (24, 0, 8, X))
|
||||
self.assert_unpack("RGBX", "BGR;15", 2, (0, 131, 8, X), (8, 0, 24, X))
|
||||
self.assert_unpack("RGBX", "RGB;4B", 2, (17, 0, 34, X), (51, 0, 68, X))
|
||||
self.assert_unpack("RGBX", "RGBX", 4,
|
||||
(1,2,3,4), (5,6,7,8), (9,10,11,12))
|
||||
(1, 2, 3, 4), (5, 6, 7, 8), (9, 10, 11, 12))
|
||||
self.assert_unpack("RGBX", "RGBXX", 5,
|
||||
(1,2,3,4), (6,7,8,9), (11,12,13,14))
|
||||
(1, 2, 3, 4), (6, 7, 8, 9), (11, 12, 13, 14))
|
||||
self.assert_unpack("RGBX", "RGBXXX", 6,
|
||||
(1,2,3,4), (7,8,9,10), (13,14,15,16))
|
||||
(1, 2, 3, 4), (7, 8, 9, 10), (13, 14, 15, 16))
|
||||
self.assert_unpack("RGBX", "RGBX;L", 4,
|
||||
(1,4,7,10), (2,5,8,11), (3,6,9,12))
|
||||
self.assert_unpack("RGBX", "RGBX;16L", 8, (2,4,6,8), (10,12,14,16))
|
||||
self.assert_unpack("RGBX", "RGBX;16B", 8, (1,3,5,7), (9,11,13,15))
|
||||
self.assert_unpack("RGBX", "BGRX", 4, (3,2,1,X), (7,6,5,X), (11,10,9,X))
|
||||
self.assert_unpack("RGBX", "XRGB", 4, (2,3,4,X), (6,7,8,X), (10,11,12,X))
|
||||
self.assert_unpack("RGBX", "XBGR", 4, (4,3,2,X), (8,7,6,X), (12,11,10,X))
|
||||
(1, 4, 7, 10), (2, 5, 8, 11), (3, 6, 9, 12))
|
||||
self.assert_unpack("RGBX", "RGBX;16L", 8, (2, 4, 6, 8), (10, 12, 14, 16))
|
||||
self.assert_unpack("RGBX", "RGBX;16B", 8, (1, 3, 5, 7), (9, 11, 13, 15))
|
||||
self.assert_unpack("RGBX", "BGRX", 4, (3, 2, 1, X), (7, 6, 5, X), (11, 10, 9, X))
|
||||
self.assert_unpack("RGBX", "XRGB", 4, (2, 3, 4, X), (6, 7, 8, X), (10, 11, 12, X))
|
||||
self.assert_unpack("RGBX", "XBGR", 4, (4, 3, 2, X), (8, 7, 6, X), (12, 11, 10, X))
|
||||
self.assert_unpack("RGBX", "YCC;P",
|
||||
b'D]\x9c\x82\x1a\x91\xfaOC\xe7J\x12', # random data
|
||||
(127,102,0,X), (192,227,0,X), (213,255,170,X), (98,255,133,X))
|
||||
self.assert_unpack("RGBX", "R", 1, (1,0,0,0), (2,0,0,0), (3,0,0,0))
|
||||
self.assert_unpack("RGBX", "G", 1, (0,1,0,0), (0,2,0,0), (0,3,0,0))
|
||||
self.assert_unpack("RGBX", "B", 1, (0,0,1,0), (0,0,2,0), (0,0,3,0))
|
||||
self.assert_unpack("RGBX", "X", 1, (0,0,0,1), (0,0,0,2), (0,0,0,3))
|
||||
(127, 102, 0, X), (192, 227, 0, X), (213, 255, 170, X), (98, 255, 133, X))
|
||||
self.assert_unpack("RGBX", "R", 1, (1, 0, 0, 0), (2, 0, 0, 0), (3, 0, 0, 0))
|
||||
self.assert_unpack("RGBX", "G", 1, (0, 1, 0, 0), (0, 2, 0, 0), (0, 3, 0, 0))
|
||||
self.assert_unpack("RGBX", "B", 1, (0, 0, 1, 0), (0, 0, 2, 0), (0, 0, 3, 0))
|
||||
self.assert_unpack("RGBX", "X", 1, (0, 0, 0, 1), (0, 0, 0, 2), (0, 0, 0, 3))
|
||||
|
||||
def test_CMYK(self):
|
||||
self.assert_unpack("CMYK", "CMYK", 4,
|
||||
(1,2,3,4), (5,6,7,8), (9,10,11,12))
|
||||
(1, 2, 3, 4), (5, 6, 7, 8), (9, 10, 11, 12))
|
||||
self.assert_unpack("CMYK", "CMYKX", 5,
|
||||
(1,2,3,4), (6,7,8,9), (11,12,13,14))
|
||||
(1, 2, 3, 4), (6, 7, 8, 9), (11, 12, 13, 14))
|
||||
self.assert_unpack("CMYK", "CMYKXX", 6,
|
||||
(1,2,3,4), (7,8,9,10), (13,14,15,16))
|
||||
(1, 2, 3, 4), (7, 8, 9, 10), (13, 14, 15, 16))
|
||||
self.assert_unpack("CMYK", "CMYK;I", 4,
|
||||
(254,253,252,251), (250,249,248,247), (246,245,244,243))
|
||||
(254, 253, 252, 251), (250, 249, 248, 247), (246, 245, 244, 243))
|
||||
self.assert_unpack("CMYK", "CMYK;L", 4,
|
||||
(1,4,7,10), (2,5,8,11), (3,6,9,12))
|
||||
self.assert_unpack("CMYK", "C", 1, (1,0,0,0), (2,0,0,0), (3,0,0,0))
|
||||
self.assert_unpack("CMYK", "M", 1, (0,1,0,0), (0,2,0,0), (0,3,0,0))
|
||||
self.assert_unpack("CMYK", "Y", 1, (0,0,1,0), (0,0,2,0), (0,0,3,0))
|
||||
self.assert_unpack("CMYK", "K", 1, (0,0,0,1), (0,0,0,2), (0,0,0,3))
|
||||
(1, 4, 7, 10), (2, 5, 8, 11), (3, 6, 9, 12))
|
||||
self.assert_unpack("CMYK", "C", 1, (1, 0, 0, 0), (2, 0, 0, 0), (3, 0, 0, 0))
|
||||
self.assert_unpack("CMYK", "M", 1, (0, 1, 0, 0), (0, 2, 0, 0), (0, 3, 0, 0))
|
||||
self.assert_unpack("CMYK", "Y", 1, (0, 0, 1, 0), (0, 0, 2, 0), (0, 0, 3, 0))
|
||||
self.assert_unpack("CMYK", "K", 1, (0, 0, 0, 1), (0, 0, 0, 2), (0, 0, 0, 3))
|
||||
self.assert_unpack("CMYK", "C;I", 1,
|
||||
(254,0,0,0), (253,0,0,0), (252,0,0,0))
|
||||
(254, 0, 0, 0), (253, 0, 0, 0), (252, 0, 0, 0))
|
||||
self.assert_unpack("CMYK", "M;I", 1,
|
||||
(0,254,0,0), (0,253,0,0), (0,252,0,0))
|
||||
(0, 254, 0, 0), (0, 253, 0, 0), (0, 252, 0, 0))
|
||||
self.assert_unpack("CMYK", "Y;I", 1,
|
||||
(0,0,254,0), (0,0,253,0), (0,0,252,0))
|
||||
(0, 0, 254, 0), (0, 0, 253, 0), (0, 0, 252, 0))
|
||||
self.assert_unpack("CMYK", "K;I", 1,
|
||||
(0,0,0,254), (0,0,0,253), (0,0,0,252))
|
||||
(0, 0, 0, 254), (0, 0, 0, 253), (0, 0, 0, 252))
|
||||
|
||||
def test_YCbCr(self):
|
||||
self.assert_unpack("YCbCr", "YCbCr", 3, (1,2,3), (4,5,6), (7,8,9))
|
||||
self.assert_unpack("YCbCr", "YCbCr;L", 3, (1,4,7), (2,5,8), (3,6,9))
|
||||
self.assert_unpack("YCbCr", "YCbCrK", 4, (1,2,3), (5,6,7), (9,10,11))
|
||||
self.assert_unpack("YCbCr", "YCbCrX", 4, (1,2,3), (5,6,7), (9,10,11))
|
||||
self.assert_unpack("YCbCr", "YCbCrXX", 5, (1,2,3), (6,7,8), (11,12,13))
|
||||
self.assert_unpack("YCbCr", "YCbCrXXX", 6, (1,2,3), (7,8,9), (13,14,15))
|
||||
self.assert_unpack("YCbCr", "YCbCr", 3, (1, 2, 3), (4, 5, 6), (7, 8, 9))
|
||||
self.assert_unpack("YCbCr", "YCbCr;L", 3, (1, 4, 7), (2, 5, 8), (3, 6, 9))
|
||||
self.assert_unpack("YCbCr", "YCbCrK", 4, (1, 2, 3), (5, 6, 7), (9, 10, 11))
|
||||
self.assert_unpack("YCbCr", "YCbCrX", 4, (1, 2, 3), (5, 6, 7), (9, 10, 11))
|
||||
self.assert_unpack("YCbCr", "YCbCrXX", 5, (1, 2, 3), (6, 7, 8), (11, 12, 13))
|
||||
self.assert_unpack("YCbCr", "YCbCrXXX", 6, (1, 2, 3), (7, 8, 9), (13, 14, 15))
|
||||
|
||||
def test_LAB(self):
|
||||
self.assert_unpack("LAB", "LAB", 3,
|
||||
(1,130,131), (4,133,134), (7,136,137))
|
||||
self.assert_unpack("LAB", "L", 1, (1,0,0), (2,0,0), (3,0,0))
|
||||
self.assert_unpack("LAB", "A", 1, (0,1,0), (0,2,0), (0,3,0))
|
||||
self.assert_unpack("LAB", "B", 1, (0,0,1), (0,0,2), (0,0,3))
|
||||
(1, 130, 131), (4, 133, 134), (7, 136, 137))
|
||||
self.assert_unpack("LAB", "L", 1, (1, 0, 0), (2, 0, 0), (3, 0, 0))
|
||||
self.assert_unpack("LAB", "A", 1, (0, 1, 0), (0, 2, 0), (0, 3, 0))
|
||||
self.assert_unpack("LAB", "B", 1, (0, 0, 1), (0, 0, 2), (0, 0, 3))
|
||||
|
||||
def test_HSV(self):
|
||||
self.assert_unpack("HSV", "HSV", 3, (1,2,3), (4,5,6), (7,8,9))
|
||||
self.assert_unpack("HSV", "H", 1, (1,0,0), (2,0,0), (3,0,0))
|
||||
self.assert_unpack("HSV", "S", 1, (0,1,0), (0,2,0), (0,3,0))
|
||||
self.assert_unpack("HSV", "V", 1, (0,0,1), (0,0,2), (0,0,3))
|
||||
self.assert_unpack("HSV", "HSV", 3, (1, 2, 3), (4, 5, 6), (7, 8, 9))
|
||||
self.assert_unpack("HSV", "H", 1, (1, 0, 0), (2, 0, 0), (3, 0, 0))
|
||||
self.assert_unpack("HSV", "S", 1, (0, 1, 0), (0, 2, 0), (0, 3, 0))
|
||||
self.assert_unpack("HSV", "V", 1, (0, 0, 1), (0, 0, 2), (0, 0, 3))
|
||||
|
||||
def test_I(self):
|
||||
self.assert_unpack("I", "I;8", 1, 0x01, 0x02, 0x03, 0x04)
|
||||
|
|
|
@ -214,7 +214,7 @@ class TestNumpy(PillowTestCase):
|
|||
|
||||
def test_bool(self):
|
||||
# https://github.com/python-pillow/Pillow/issues/2044
|
||||
a = numpy.zeros((10,2), dtype=numpy.bool)
|
||||
a = numpy.zeros((10, 2), dtype=numpy.bool)
|
||||
a[0][0] = True
|
||||
|
||||
im2 = Image.fromarray(a)
|
||||
|
|
|
@ -92,5 +92,6 @@ class TestPickle(PillowTestCase):
|
|||
self.helper_pickle_string(cPickle, protocol, mode="L")
|
||||
self.helper_pickle_file(cPickle, protocol, mode="L")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -59,5 +59,6 @@ class Test_IFDRational(PillowTestCase):
|
|||
self.assertEqual(float(IFDRational(301, 1)),
|
||||
float(reloaded.tag_v2[282]))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -12,5 +12,6 @@ class TestUploader(PillowTestCase):
|
|||
target = hopper('RGB')
|
||||
self.assert_image_similar(result, target, 0)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -75,5 +75,6 @@ class TestUtil(PillowTestCase):
|
|||
# Assert
|
||||
self.assertRaises(ValueError, lambda: thing.some_attr)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -4,10 +4,11 @@ from io import BytesIO
|
|||
|
||||
test_file = "Tests/images/hopper.webp"
|
||||
|
||||
|
||||
@unittest.skipUnless(features.check('webp'), "WebP is not installed")
|
||||
class TestWebPLeaks(PillowLeakTestCase):
|
||||
|
||||
mem_limit = 3 * 1024 # kb
|
||||
mem_limit = 3 * 1024 # kb
|
||||
iterations = 100
|
||||
|
||||
def test_leak_load(self):
|
||||
|
|
|
@ -34,6 +34,7 @@ class Worker(threading.Thread):
|
|||
sys.stdout.write(".")
|
||||
queue.task_done()
|
||||
|
||||
|
||||
t0 = time.time()
|
||||
|
||||
threads = 20
|
||||
|
|
|
@ -7,6 +7,7 @@ def version(module, version):
|
|||
if v:
|
||||
print(version, v)
|
||||
|
||||
|
||||
version(Image, "jpeglib")
|
||||
version(Image, "zlib")
|
||||
|
||||
|
|
|
@ -271,6 +271,7 @@ class DXT5Decoder(ImageFile.PyDecoder):
|
|||
raise IOError("Truncated DDS file")
|
||||
return 0, 0
|
||||
|
||||
|
||||
Image.register_decoder('DXT1', DXT1Decoder)
|
||||
Image.register_decoder('DXT5', DXT5Decoder)
|
||||
|
||||
|
|
2
setup.py
2
setup.py
|
@ -788,7 +788,7 @@ try:
|
|||
setup_requires=pytest_runner,
|
||||
tests_require=['pytest'],
|
||||
packages=["PIL"],
|
||||
package_dir={'':'src'},
|
||||
package_dir={'': 'src'},
|
||||
keywords=["Imaging", ],
|
||||
license='Standard PIL License',
|
||||
zip_safe=not (debug_build() or PLATFORM_MINGW), )
|
||||
|
|
|
@ -216,6 +216,7 @@ class DibImageFile(BmpImageFile):
|
|||
# --------------------------------------------------------------------
|
||||
# Write BMP file
|
||||
|
||||
|
||||
SAVE = {
|
||||
"1": ("1", 1, 2),
|
||||
"L": ("L", 8, 256),
|
||||
|
@ -279,6 +280,7 @@ def _save(im, fp, filename):
|
|||
# --------------------------------------------------------------------
|
||||
# Registry
|
||||
|
||||
|
||||
Image.register_open(BmpImageFile.format, BmpImageFile, _accept)
|
||||
Image.register_save(BmpImageFile.format, _save)
|
||||
|
||||
|
|
|
@ -418,6 +418,7 @@ def _save(im, fp, filename, eps=1):
|
|||
#
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
|
||||
Image.register_open(EpsImageFile.format, EpsImageFile, _accept)
|
||||
|
||||
Image.register_save(EpsImageFile.format, _save)
|
||||
|
|
|
@ -223,6 +223,7 @@ class FpxImageFile(ImageFile.ImageFile):
|
|||
#
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
|
||||
Image.register_open(FpxImageFile.format, FpxImageFile, _accept)
|
||||
|
||||
Image.register_extension(FpxImageFile.format, ".fpx")
|
||||
|
|
|
@ -89,5 +89,6 @@ class GbrImageFile(ImageFile.ImageFile):
|
|||
#
|
||||
# registry
|
||||
|
||||
|
||||
Image.register_open(GbrImageFile.format, GbrImageFile, _accept)
|
||||
Image.register_extension(GbrImageFile.format, ".gbr")
|
||||
|
|
|
@ -292,6 +292,7 @@ class GifImageFile(ImageFile.ImageFile):
|
|||
# --------------------------------------------------------------------
|
||||
# Write GIF files
|
||||
|
||||
|
||||
RAWMODE = {
|
||||
"1": "L",
|
||||
"L": "L",
|
||||
|
|
|
@ -55,6 +55,7 @@ def sphere_increasing(middle, pos):
|
|||
def sphere_decreasing(middle, pos):
|
||||
return 1.0 - sqrt(1.0 - linear(middle, pos) ** 2)
|
||||
|
||||
|
||||
SEGMENTS = [linear, curved, sine, sphere_increasing, sphere_decreasing]
|
||||
|
||||
|
||||
|
|
|
@ -342,6 +342,7 @@ def _save(im, fp, filename):
|
|||
if retcode:
|
||||
raise CalledProcessError(retcode, convert_cmd)
|
||||
|
||||
|
||||
Image.register_open(IcnsImageFile.format, IcnsImageFile,
|
||||
lambda x: x[:4] == b'icns')
|
||||
Image.register_extension(IcnsImageFile.format, '.icns')
|
||||
|
|
|
@ -294,6 +294,7 @@ class ImImageFile(ImageFile.ImageFile):
|
|||
# --------------------------------------------------------------------
|
||||
# Save IM files
|
||||
|
||||
|
||||
SAVE = {
|
||||
# mode: (im type, raw mode)
|
||||
"1": ("0 1", "1"),
|
||||
|
@ -339,6 +340,7 @@ def _save(im, fp, filename):
|
|||
# --------------------------------------------------------------------
|
||||
# Registry
|
||||
|
||||
|
||||
Image.register_open(ImImageFile.format, ImImageFile)
|
||||
Image.register_save(ImImageFile.format, _save)
|
||||
|
||||
|
|
|
@ -36,9 +36,11 @@ logger = logging.getLogger(__name__)
|
|||
class DecompressionBombWarning(RuntimeWarning):
|
||||
pass
|
||||
|
||||
|
||||
class DecompressionBombError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class _imaging_not_installed(object):
|
||||
# module placeholder
|
||||
def __getattr__(self, id):
|
||||
|
@ -1405,7 +1407,7 @@ class Image(object):
|
|||
else:
|
||||
self.im.paste(im, box)
|
||||
|
||||
def alpha_composite(self, im, dest=(0,0), source=(0,0)):
|
||||
def alpha_composite(self, im, dest=(0, 0), source=(0, 0)):
|
||||
""" 'In-place' analog of Image.alpha_composite. Composites an image
|
||||
onto this image.
|
||||
|
||||
|
@ -1436,7 +1438,7 @@ class Image(object):
|
|||
source = source + im.size
|
||||
|
||||
# over image, crop if it's not the whole thing.
|
||||
if source == (0,0) + im.size:
|
||||
if source == (0, 0) + im.size:
|
||||
overlay = im
|
||||
else:
|
||||
overlay = im.crop(source)
|
||||
|
@ -1445,7 +1447,7 @@ class Image(object):
|
|||
box = dest + (dest[0] + overlay.width, dest[1] + overlay.height)
|
||||
|
||||
# destination image. don't copy if we're using the whole image.
|
||||
if box == (0,0) + self.size:
|
||||
if box == (0, 0) + self.size:
|
||||
background = self
|
||||
else:
|
||||
background = self.crop(box)
|
||||
|
@ -2499,7 +2501,7 @@ def _decompression_bomb_check(size):
|
|||
raise DecompressionBombError(
|
||||
"Image size (%d pixels) exceeds limit of %d pixels, "
|
||||
"could be decompression bomb DOS attack." %
|
||||
(pixels, 2* MAX_IMAGE_PIXELS))
|
||||
(pixels, 2 * MAX_IMAGE_PIXELS))
|
||||
|
||||
if pixels > MAX_IMAGE_PIXELS:
|
||||
warnings.warn(
|
||||
|
@ -2745,6 +2747,7 @@ def register_extension(id, extension):
|
|||
"""
|
||||
EXTENSION[extension.lower()] = id.upper()
|
||||
|
||||
|
||||
def register_extensions(id, extensions):
|
||||
"""
|
||||
Registers image extensions. This function should not be
|
||||
|
@ -2756,6 +2759,7 @@ def register_extensions(id, extensions):
|
|||
for extension in extensions:
|
||||
register_extension(id, extension)
|
||||
|
||||
|
||||
def registered_extensions():
|
||||
"""
|
||||
Returns a dictionary containing all file extensions belonging
|
||||
|
@ -2886,5 +2890,6 @@ def _apply_env_variables(env=None):
|
|||
except ValueError as e:
|
||||
warnings.warn("{0}: {1}".format(var_name, e))
|
||||
|
||||
|
||||
_apply_env_variables()
|
||||
atexit.register(core.clear_cache)
|
||||
|
|
|
@ -554,6 +554,7 @@ def buildProofTransform(
|
|||
except (IOError, TypeError, ValueError) as v:
|
||||
raise PyCMSError(v)
|
||||
|
||||
|
||||
buildTransformFromOpenProfiles = buildTransform
|
||||
buildProofTransformFromOpenProfiles = buildProofTransform
|
||||
|
||||
|
|
|
@ -139,6 +139,7 @@ def getcolor(color, mode):
|
|||
return color + (alpha,)
|
||||
return color
|
||||
|
||||
|
||||
colormap = {
|
||||
# X11 colour table from https://drafts.csswg.org/css-color-4/, with
|
||||
# gray/grey spelling issues fixed. This is a superset of HTML 4.0
|
||||
|
|
|
@ -188,7 +188,7 @@ class ImageFile(Image.Image):
|
|||
self.map = None
|
||||
|
||||
self.load_prepare()
|
||||
err_code = -3 # initialize to unknown error
|
||||
err_code = -3 # initialize to unknown error
|
||||
if not self.map:
|
||||
# sort tiles in file order
|
||||
self.tile.sort(key=_tilesort)
|
||||
|
|
|
@ -33,6 +33,7 @@ import sys
|
|||
LAYOUT_BASIC = 0
|
||||
LAYOUT_RAQM = 1
|
||||
|
||||
|
||||
class _imagingft_not_installed(object):
|
||||
# module placeholder
|
||||
def __getattr__(self, id):
|
||||
|
|
|
@ -235,6 +235,7 @@ def imagemath_max(self, other):
|
|||
def imagemath_convert(self, mode):
|
||||
return _Operand(self.im.convert(mode))
|
||||
|
||||
|
||||
ops = {}
|
||||
for k, v in list(globals().items()):
|
||||
if k[:10] == "imagemath_":
|
||||
|
|
|
@ -162,6 +162,7 @@ def _toqclass_helper(im):
|
|||
'data': __data, 'im': im, 'format': format, 'colortable': colortable
|
||||
}
|
||||
|
||||
|
||||
if qt_is_installed:
|
||||
class ImageQt(QImage):
|
||||
|
||||
|
|
|
@ -144,4 +144,5 @@ class Stat(object):
|
|||
v.append(math.sqrt(self.var[i]))
|
||||
return v
|
||||
|
||||
|
||||
Global = Stat # compatibility
|
||||
|
|
|
@ -266,6 +266,7 @@ def _save(im, fp, filename):
|
|||
# ------------------------------------------------------------
|
||||
# Registry stuff
|
||||
|
||||
|
||||
Image.register_open(Jpeg2KImageFile.format, Jpeg2KImageFile, _accept)
|
||||
Image.register_save(Jpeg2KImageFile.format, _save)
|
||||
|
||||
|
|
|
@ -153,6 +153,7 @@ class PSDraw(object):
|
|||
# Copyright (c) Fredrik Lundh 1994.
|
||||
#
|
||||
|
||||
|
||||
EDROFF_PS = """\
|
||||
/S { show } bind def
|
||||
/P { moveto show } bind def
|
||||
|
|
|
@ -90,6 +90,7 @@ def build_prototype_image():
|
|||
image.putpalette(palettedata)
|
||||
return image
|
||||
|
||||
|
||||
Palm8BitColormapImage = build_prototype_image()
|
||||
|
||||
# OK, we now have in Palm8BitColormapImage,
|
||||
|
|
|
@ -110,6 +110,7 @@ class PcxImageFile(ImageFile.ImageFile):
|
|||
# --------------------------------------------------------------------
|
||||
# save PCX files
|
||||
|
||||
|
||||
SAVE = {
|
||||
# mode: (version, bits, planes, raw mode)
|
||||
"1": (2, 1, 1, "1"),
|
||||
|
@ -171,6 +172,7 @@ def _save(im, fp, filename):
|
|||
# --------------------------------------------------------------------
|
||||
# registry
|
||||
|
||||
|
||||
Image.register_open(PcxImageFile.format, PcxImageFile, _accept)
|
||||
Image.register_save(PcxImageFile.format, _save)
|
||||
|
||||
|
|
|
@ -263,6 +263,7 @@ def _save(im, fp, filename, save_all=False):
|
|||
#
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
|
||||
Image.register_save("PDF", _save)
|
||||
Image.register_save_all("PDF", _save_all)
|
||||
|
||||
|
|
|
@ -85,6 +85,7 @@ def _safe_zlib_decompress(s):
|
|||
raise ValueError("Decompressed Data Too Large")
|
||||
return plaintext
|
||||
|
||||
|
||||
def _crc32(data, seed=0):
|
||||
return zlib.crc32(data, seed) & 0xffffffff
|
||||
|
||||
|
|
|
@ -15,8 +15,6 @@
|
|||
#
|
||||
|
||||
|
||||
import string
|
||||
|
||||
from . import Image, ImageFile
|
||||
|
||||
__version__ = "0.2"
|
||||
|
@ -152,6 +150,7 @@ def _save(im, fp, filename):
|
|||
#
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
|
||||
Image.register_open(PpmImageFile.format, PpmImageFile, _accept)
|
||||
Image.register_save(PpmImageFile.format, _save)
|
||||
|
||||
|
|
|
@ -301,6 +301,7 @@ def _maketile(file, mode, bbox, channels):
|
|||
# --------------------------------------------------------------------
|
||||
# registry
|
||||
|
||||
|
||||
Image.register_open(PsdImageFile.format, PsdImageFile, _accept)
|
||||
|
||||
Image.register_extension(PsdImageFile.format, ".psd")
|
||||
|
|
|
@ -193,6 +193,7 @@ def _save(im, fp, filename):
|
|||
|
||||
fp.close()
|
||||
|
||||
|
||||
class SGI16Decoder(ImageFile.PyDecoder):
|
||||
_pulls_fd = True
|
||||
|
||||
|
|
|
@ -51,6 +51,7 @@ def isInt(f):
|
|||
except (ValueError, OverflowError):
|
||||
return 0
|
||||
|
||||
|
||||
iforms = [1, 3, -11, -12, -21, -22]
|
||||
|
||||
|
||||
|
@ -279,6 +280,7 @@ def _save_spider(im, fp, filename):
|
|||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
|
||||
Image.register_open(SpiderImageFile.format, SpiderImageFile)
|
||||
Image.register_save(SpiderImageFile.format, _save_spider)
|
||||
|
||||
|
|
|
@ -130,6 +130,7 @@ class SunImageFile(ImageFile.ImageFile):
|
|||
#
|
||||
# registry
|
||||
|
||||
|
||||
Image.register_open(SunImageFile.format, SunImageFile, _accept)
|
||||
|
||||
Image.register_extension(SunImageFile.format, ".ras")
|
||||
|
|
|
@ -130,6 +130,7 @@ class TgaImageFile(ImageFile.ImageFile):
|
|||
# --------------------------------------------------------------------
|
||||
# Write TGA file
|
||||
|
||||
|
||||
SAVE = {
|
||||
"1": ("1", 1, 0, 3),
|
||||
"L": ("L", 8, 0, 3),
|
||||
|
@ -186,6 +187,7 @@ def _save(im, fp, filename):
|
|||
# --------------------------------------------------------------------
|
||||
# Registry
|
||||
|
||||
|
||||
Image.register_open(TgaImageFile.format, TgaImageFile)
|
||||
Image.register_save(TgaImageFile.format, _save)
|
||||
|
||||
|
|
|
@ -572,7 +572,7 @@ class ImageFileDirectory_v2(collections.MutableMapping):
|
|||
if ((info.length == 1) or
|
||||
(info.length is None and len(values) == 1 and not legacy_api)):
|
||||
# Don't mess with the legacy api, since it's frozen.
|
||||
if legacy_api and self.tagtype[tag] in [5, 10]: # rationals
|
||||
if legacy_api and self.tagtype[tag] in [5, 10]: # rationals
|
||||
values = values,
|
||||
try:
|
||||
dest[tag], = values
|
||||
|
@ -1286,7 +1286,6 @@ class TiffImageFile(ImageFile.ImageFile):
|
|||
if ';16L' in rawmode:
|
||||
rawmode = rawmode.replace(';16L', ';16N')
|
||||
|
||||
|
||||
# Offset in the tile tuple is 0, we go from 0,0 to
|
||||
# w,h, and we only do this once -- eds
|
||||
a = (rawmode, self._compression, False)
|
||||
|
|
|
@ -193,8 +193,8 @@ TAGS_V2 = {
|
|||
|
||||
50741: ("MakerNoteSafety", SHORT, 1, {"Unsafe": 0, "Safe": 1}),
|
||||
50780: ("BestQualityScale", RATIONAL, 1),
|
||||
50838: ("ImageJMetaDataByteCounts", LONG, 0), # Can be more than one
|
||||
50839: ("ImageJMetaData", UNDEFINED, 1) # see Issue #2006
|
||||
50838: ("ImageJMetaDataByteCounts", LONG, 0), # Can be more than one
|
||||
50839: ("ImageJMetaData", UNDEFINED, 1) # see Issue #2006
|
||||
}
|
||||
|
||||
# Legacy Tags structure
|
||||
|
@ -355,6 +355,7 @@ def _populate():
|
|||
|
||||
TAGS_V2[k] = TagInfo(k, *v)
|
||||
|
||||
|
||||
_populate()
|
||||
##
|
||||
# Map type numbers to type names -- defined in ImageFileDirectory.
|
||||
|
|
|
@ -74,6 +74,7 @@ def open(filename):
|
|||
with builtins.open(filename, "rb") as fp:
|
||||
return imopen(fp)
|
||||
|
||||
|
||||
quake2palette = (
|
||||
# default palette taken from piffo 0.93 by Hans Häggström
|
||||
b"\x01\x01\x01\x0b\x0b\x0b\x12\x12\x12\x17\x17\x17\x1b\x1b\x1b\x1e"
|
||||
|
|
|
@ -42,6 +42,7 @@ def register_handler(handler):
|
|||
global _handler
|
||||
_handler = handler
|
||||
|
||||
|
||||
if hasattr(Image.core, "drawwmf"):
|
||||
# install default handler (windows only)
|
||||
|
||||
|
@ -161,6 +162,7 @@ def _save(im, fp, filename):
|
|||
# --------------------------------------------------------------------
|
||||
# Registry stuff
|
||||
|
||||
|
||||
Image.register_open(WmfStubImageFile.format, WmfStubImageFile, _accept)
|
||||
Image.register_save(WmfStubImageFile.format, _save)
|
||||
|
||||
|
|
|
@ -121,6 +121,7 @@ class XpmImageFile(ImageFile.ImageFile):
|
|||
#
|
||||
# Registry
|
||||
|
||||
|
||||
Image.register_open(XpmImageFile.format, XpmImageFile, _accept)
|
||||
|
||||
Image.register_extension(XpmImageFile.format, ".xpm")
|
||||
|
|
|
@ -8,6 +8,7 @@ modules = {
|
|||
"webp": "PIL._webp",
|
||||
}
|
||||
|
||||
|
||||
def check_module(feature):
|
||||
if not (feature in modules):
|
||||
raise ValueError("Unknown module %s" % feature)
|
||||
|
@ -15,14 +16,16 @@ def check_module(feature):
|
|||
module = modules[feature]
|
||||
|
||||
try:
|
||||
imported_module = __import__(module)
|
||||
__import__(module)
|
||||
return True
|
||||
except ImportError:
|
||||
return False
|
||||
|
||||
|
||||
def get_supported_modules():
|
||||
return [f for f in modules if check_module(f)]
|
||||
|
||||
|
||||
codecs = {
|
||||
"jpg": "jpeg",
|
||||
"jpg_2000": "jpeg2k",
|
||||
|
@ -30,6 +33,7 @@ codecs = {
|
|||
"libtiff": "libtiff"
|
||||
}
|
||||
|
||||
|
||||
def check_codec(feature):
|
||||
if feature not in codecs:
|
||||
raise ValueError("Unknown codec %s" % feature)
|
||||
|
@ -42,6 +46,7 @@ def check_codec(feature):
|
|||
def get_supported_codecs():
|
||||
return [f for f in codecs if check_codec(f)]
|
||||
|
||||
|
||||
features = {
|
||||
"webp_anim": ("PIL._webp", 'HAVE_WEBPANIM'),
|
||||
"webp_mux": ("PIL._webp", 'HAVE_WEBPMUX'),
|
||||
|
@ -49,6 +54,7 @@ features = {
|
|||
"raqm": ("PIL._imagingft", "HAVE_RAQM")
|
||||
}
|
||||
|
||||
|
||||
def check_feature(feature):
|
||||
if feature not in features:
|
||||
raise ValueError("Unknown feature %s" % feature)
|
||||
|
@ -71,9 +77,9 @@ def check(feature):
|
|||
feature in codecs and check_codec(feature) or \
|
||||
feature in features and check_feature(feature))
|
||||
|
||||
|
||||
def get_supported():
|
||||
ret = get_supported_modules()
|
||||
ret.extend(get_supported_features())
|
||||
ret.extend(get_supported_codecs())
|
||||
return ret
|
||||
|
||||
|
|
|
@ -14,5 +14,6 @@ def fetch(url):
|
|||
fd.write(content)
|
||||
return name
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
fetch(sys.argv[1])
|
||||
|
|
|
@ -6,5 +6,6 @@ def untar(src, dest):
|
|||
with tarfile.open(src, 'r:gz') as tgz:
|
||||
tgz.extractall(dest)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
untar(sys.argv[1], sys.argv[2])
|
||||
|
|
|
@ -6,5 +6,6 @@ def unzip(src, dest):
|
|||
with zipfile.ZipFile(src) as zf:
|
||||
zf.extractall(dest)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unzip(sys.argv[1], sys.argv[2])
|
||||
|
|
Loading…
Reference in New Issue
Block a user