From 911bd0f7b2384015ee546a67bc91eb3b47faca46 Mon Sep 17 00:00:00 2001 From: Pierrick Koch Date: Wed, 27 Apr 2016 16:00:48 +0200 Subject: [PATCH 1/5] [Test] add Image.fromarray LA mode test inspired from Tests/test_image_frombytes.py --- Tests/test_image_fromarray_la.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Tests/test_image_fromarray_la.py diff --git a/Tests/test_image_fromarray_la.py b/Tests/test_image_fromarray_la.py new file mode 100644 index 000000000..15931b16d --- /dev/null +++ b/Tests/test_image_fromarray_la.py @@ -0,0 +1,22 @@ +from helper import unittest, PillowTestCase + +from PIL import Image + +import numpy as np + +class TestImageFromArrayLA(PillowTestCase): + + def test_sanity(self): + ar1 = (np.random.random((40,40,2))*255).astype('uint8') + im1 = Image.fromarray(ar1) + arr = np.array(im1.getdata(), 'uint8') + ar2 = arr.reshape(im1.size[1], im1.size[0], arr.shape[1]) + im2 = Image.fromarray(ar2) + + self.assert_image_equal(im1, im2) + + +if __name__ == '__main__': + unittest.main() + +# End of file From fbb6cae7853cd48e0f70d7e289645510c41e247f Mon Sep 17 00:00:00 2001 From: Pierrick Koch Date: Wed, 27 Apr 2016 16:23:22 +0200 Subject: [PATCH 2/5] [Test] fix Image.fromarray LA mode test AppVeyor: ERROR: Failure: ImportError (No module named numpy) inspired from: Tests/test_numpy.py --- Tests/test_image_fromarray_la.py | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/Tests/test_image_fromarray_la.py b/Tests/test_image_fromarray_la.py index 15931b16d..fa1e81e7c 100644 --- a/Tests/test_image_fromarray_la.py +++ b/Tests/test_image_fromarray_la.py @@ -2,18 +2,28 @@ from helper import unittest, PillowTestCase from PIL import Image -import numpy as np +try: + import site + import numpy +except ImportError: + # Skip via setUp() + pass class TestImageFromArrayLA(PillowTestCase): - def test_sanity(self): - ar1 = (np.random.random((40,40,2))*255).astype('uint8') - im1 = Image.fromarray(ar1) - arr = np.array(im1.getdata(), 'uint8') - ar2 = arr.reshape(im1.size[1], im1.size[0], arr.shape[1]) - im2 = Image.fromarray(ar2) + def setUp(self): + try: + import site + import numpy + except ImportError: + self.skipTest("ImportError") - self.assert_image_equal(im1, im2) + def test_sanity(self): + ar1 = (numpy.random.random((40,40,2))*255).astype('uint8') + im1 = Image.fromarray(ar1) + arr = numpy.array(im1.getdata(), 'uint8') + ar2 = arr.reshape(im1.size[1], im1.size[0], arr.shape[1]) + self.assertTrue(numpy.array_equal(ar1, ar2)) if __name__ == '__main__': From 7c7100679606149ae92f1edeec4eb4d3f41b8a5e Mon Sep 17 00:00:00 2001 From: Pierrick Koch Date: Thu, 28 Apr 2016 16:29:12 +0200 Subject: [PATCH 3/5] [Test] rm Image.fromarray LA mode test --- Tests/test_image_fromarray_la.py | 32 -------------------------------- 1 file changed, 32 deletions(-) delete mode 100644 Tests/test_image_fromarray_la.py diff --git a/Tests/test_image_fromarray_la.py b/Tests/test_image_fromarray_la.py deleted file mode 100644 index fa1e81e7c..000000000 --- a/Tests/test_image_fromarray_la.py +++ /dev/null @@ -1,32 +0,0 @@ -from helper import unittest, PillowTestCase - -from PIL import Image - -try: - import site - import numpy -except ImportError: - # Skip via setUp() - pass - -class TestImageFromArrayLA(PillowTestCase): - - def setUp(self): - try: - import site - import numpy - except ImportError: - self.skipTest("ImportError") - - def test_sanity(self): - ar1 = (numpy.random.random((40,40,2))*255).astype('uint8') - im1 = Image.fromarray(ar1) - arr = numpy.array(im1.getdata(), 'uint8') - ar2 = arr.reshape(im1.size[1], im1.size[0], arr.shape[1]) - self.assertTrue(numpy.array_equal(ar1, ar2)) - - -if __name__ == '__main__': - unittest.main() - -# End of file From 3c889a5b7201b438e437cee3ead1ba319e75fb95 Mon Sep 17 00:00:00 2001 From: Pierrick Koch Date: Thu, 28 Apr 2016 16:29:56 +0200 Subject: [PATCH 4/5] [PIL] Image add support _MODE_CONV LA mode --- PIL/Image.py | 1 + 1 file changed, 1 insertion(+) diff --git a/PIL/Image.py b/PIL/Image.py index 136f5134c..87868f8dc 100644 --- a/PIL/Image.py +++ b/PIL/Image.py @@ -245,6 +245,7 @@ _MODE_CONV = { # official modes "1": ('|b1', None), # broken "L": ('|u1', None), + "LA": ('|u1', 2), "I": (_ENDIAN + 'i4', None), "F": (_ENDIAN + 'f4', None), "P": ('|u1', None), From def667eefb85f85e18917ccb2ff9d174816ecdad Mon Sep 17 00:00:00 2001 From: Pierrick Koch Date: Thu, 28 Apr 2016 16:30:43 +0200 Subject: [PATCH 5/5] [Test] image array add LA mode test --- Tests/test_image_array.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Tests/test_image_array.py b/Tests/test_image_array.py index ce8cbe78c..5aad8d3b3 100644 --- a/Tests/test_image_array.py +++ b/Tests/test_image_array.py @@ -19,6 +19,7 @@ class TestImageArray(PillowTestCase): # FIXME: wrong? self.assertEqual(test("F"), (3, (100, 128), Image._ENDIAN + 'f4', 51200)) + self.assertEqual(test("LA"), (3, (100, 128, 2), '|u1', 25600)) self.assertEqual(test("RGB"), (3, (100, 128, 3), '|u1', 38400)) self.assertEqual(test("RGBA"), (3, (100, 128, 4), '|u1', 51200)) self.assertEqual(test("RGBX"), (3, (100, 128, 4), '|u1', 51200)) @@ -35,6 +36,7 @@ class TestImageArray(PillowTestCase): self.assertEqual(test("L"), ("L", (128, 100), True)) self.assertEqual(test("I"), ("I", (128, 100), True)) self.assertEqual(test("F"), ("F", (128, 100), True)) + self.assertEqual(test("LA"), ("LA", (128, 100), True)) self.assertEqual(test("RGB"), ("RGB", (128, 100), True)) self.assertEqual(test("RGBA"), ("RGBA", (128, 100), True)) self.assertEqual(test("RGBX"), ("RGBA", (128, 100), True))