mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-11-04 01:47:47 +03:00 
			
		
		
		
	Merge ca35a9d65d into 6954e5c72c
				
					
				
			This commit is contained in:
		
						commit
						74dba4f809
					
				| 
						 | 
					@ -1,6 +1,7 @@
 | 
				
			||||||
from tester import *
 | 
					from tester import *
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from PIL import Image
 | 
					from PIL import Image
 | 
				
			||||||
 | 
					import struct
 | 
				
			||||||
 | 
					
 | 
				
			||||||
try:
 | 
					try:
 | 
				
			||||||
    import site
 | 
					    import site
 | 
				
			||||||
| 
						 | 
					@ -65,10 +66,43 @@ def test_3d_array():
 | 
				
			||||||
    assert_image(Image.fromarray(a[:, :, 1]), "L", (10, 10))
 | 
					    assert_image(Image.fromarray(a[:, :, 1]), "L", (10, 10))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def _test_img_equals_nparray(img, np):
 | 
				
			||||||
 | 
					    assert_equal(img.size, np.shape[0:2])
 | 
				
			||||||
 | 
					    px = img.load()
 | 
				
			||||||
 | 
					    for x in xrange(0, img.size[0], img.size[0]/10):
 | 
				
			||||||
 | 
					        for y in xrange(0, img.size[1],  img.size[1]/10):
 | 
				
			||||||
 | 
					            assert_deep_equal(px[x,y], np[y,x])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def test_16bit():
 | 
					def test_16bit():
 | 
				
			||||||
    img = Image.open('Tests/images/12bit.cropped.tif')
 | 
					    img = Image.open('Tests/images/12bit.cropped.tif')
 | 
				
			||||||
    px = img.load()
 | 
					 | 
				
			||||||
    np_img = numpy.array(img)
 | 
					    np_img = numpy.array(img)
 | 
				
			||||||
    assert_equal(np_img.shape, (64,64))
 | 
					    _test_img_equals_nparray(img, np_img)
 | 
				
			||||||
    assert_equal(px[1,1],np_img[1,1])
 | 
					    assert_equal(np_img.dtype, numpy.dtype('uint16'))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def test_to_array():
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def _to_array(mode, dtype):
 | 
				
			||||||
 | 
					        img = lena(mode)            
 | 
				
			||||||
 | 
					        np_img = numpy.array(img)
 | 
				
			||||||
 | 
					        _test_img_equals_nparray(img, np_img)
 | 
				
			||||||
 | 
					        assert_equal(np_img.dtype, numpy.dtype(dtype))
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					     
 | 
				
			||||||
 | 
					    modes = [("L", 'uint8'),
 | 
				
			||||||
 | 
					             ("I", 'int32'),
 | 
				
			||||||
 | 
					             ("F", 'float32'),
 | 
				
			||||||
 | 
					             ("RGB", 'uint8'),
 | 
				
			||||||
 | 
					             ("RGBA", 'uint8'),
 | 
				
			||||||
 | 
					             ("RGBX", 'uint8'),
 | 
				
			||||||
 | 
					             ("CMYK", 'uint8'),
 | 
				
			||||||
 | 
					             ("YCbCr", 'uint8'),
 | 
				
			||||||
 | 
					             ("I;16", 'uint16'),
 | 
				
			||||||
 | 
					             ("I;16B", '>u2'),
 | 
				
			||||||
 | 
					             ("I;16L", 'uint16'),
 | 
				
			||||||
 | 
					             ]
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    for mode in modes:
 | 
				
			||||||
 | 
					        assert_no_exception(lambda: _to_array(*mode))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -67,6 +67,19 @@ def assert_equal(a, b, msg=None):
 | 
				
			||||||
    else:
 | 
					    else:
 | 
				
			||||||
        failure(msg or "got %r, expected %r" % (a, b))
 | 
					        failure(msg or "got %r, expected %r" % (a, b))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def assert_deep_equal(a, b, msg=None):
 | 
				
			||||||
 | 
					    try:
 | 
				
			||||||
 | 
					        if len(a) == len(b):
 | 
				
			||||||
 | 
					            if all([x==y for x,y in zip(a,b)]):
 | 
				
			||||||
 | 
					                success()
 | 
				
			||||||
 | 
					            else:
 | 
				
			||||||
 | 
					                failure(msg or "got %s, expected %s" % (a,b))
 | 
				
			||||||
 | 
					        else:
 | 
				
			||||||
 | 
					            failure(msg or "got length %s, expected %s" % (len(a), len(b)))                 
 | 
				
			||||||
 | 
					    except:
 | 
				
			||||||
 | 
					        assert_equal(a,b,msg)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def assert_match(v, pattern, msg=None):
 | 
					def assert_match(v, pattern, msg=None):
 | 
				
			||||||
    import re
 | 
					    import re
 | 
				
			||||||
    if re.match(pattern, v):
 | 
					    if re.match(pattern, v):
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user