Commits

Fredrik Lundh committed ac94108

Disabled mode 1 support for array interface.

  • Participants
  • Parent commits d060128
  • Branches numpy

Comments (0)

Files changed (3)

 
 _MODE_CONV = {
     # official modes
-    "1": ('|b1', None),
+    "1": ('|b1', None), # broken
     "L": ('|u1', None),
-    "I": ('%si4' % _ENDIAN, None), # FIXME: is this correct?
-    "F": ('%sf4' % _ENDIAN, None), # FIXME: is this correct?
+    "I": (_ENDIAN + 'i4', None),
+    "F": (_ENDIAN + 'f4', None),
     "P": ('|u1', None),
     "RGB": ('|u1', 3),
     "RGBX": ('|u1', 4),
 _fromarray_typemap = {
     # (shape, typestr) => mode, rawmode
     # first two members of shape are set to one
+    # ((1, 1), "|b1"): ("1", "1"), # broken
     ((1, 1), "|u1"): ("L", "L"),
     ((1, 1), "|i1"): ("I", "I;8"),
     ((1, 1), "<i2"): ("I", "I;16"),

Tests/test_image_array.py

     def test(mode):
         ai = im.convert(mode).__array_interface__
         return ai["shape"], ai["typestr"], len(ai["data"])
-    assert_equal(test("1"), ((100, 128), '|b1', 1600))
+    # assert_equal(test("1"), ((100, 128), '|b1', 1600))
     assert_equal(test("L"), ((100, 128), '|u1', 12800))
     assert_equal(test("I"), ((100, 128), '<i4', 51200)) # FIXME: wrong?
     assert_equal(test("F"), ((100, 128), '<f4', 51200)) # FIXME: wrong?
         i.__array_interface__ = a # patch in new version of attribute
         out = Image.fromarray(i)
         return out.mode, out.size, list(i.getdata()) == list(out.getdata())
-    assert_equal(test("1"), ("1", (128, 100), True))
+    # assert_equal(test("1"), ("1", (128, 100), True))
     assert_equal(test("L"), ("L", (128, 100), True))
     assert_equal(test("I"), ("I", (128, 100), True))
     assert_equal(test("F"), ("F", (128, 100), True))

Tests/test_numpy.py

 from tester import *
 
-import Image
+from PIL import Image
 try:
     import numpy
 except ImportError:
 
 def test_numpy_to_image():
 
-    def to_image(dtype, bands=1):
+    def to_image(dtype, bands=1, bool=0):
         if bands == 1:
-            data = range(100)
+            if bool:
+                data = [0, 1] * 50
+            else:
+                data = range(100)
             a = numpy.array(data, dtype=dtype)
             a.shape = 10, 10
             i = Image.fromarray(a)
         # print dtype, list(i.getdata())
         return i
 
+    assert_image(to_image(numpy.bool, bool=1), "L", (10, 10))
+    assert_image(to_image(numpy.bool8, bool=1), "L", (10, 10))
+
     assert_exception(TypeError, lambda: to_image(numpy.uint))
     assert_image(to_image(numpy.uint8), "L", (10, 10))
     assert_exception(TypeError, lambda: to_image(numpy.uint16))