2019-02-03 18:34:53 +03:00
|
|
|
from .helper import PillowTestCase, hopper
|
2012-10-16 00:26:38 +04:00
|
|
|
|
|
|
|
from PIL import Image
|
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
|
|
|
|
class TestImageMode(PillowTestCase):
|
|
|
|
def test_sanity(self):
|
|
|
|
|
2014-09-05 14:03:56 +04:00
|
|
|
im = hopper()
|
2014-06-10 13:10:47 +04:00
|
|
|
im.mode
|
|
|
|
|
2014-07-20 01:51:26 +04:00
|
|
|
from PIL import ImageMode
|
|
|
|
|
|
|
|
ImageMode.getmode("1")
|
|
|
|
ImageMode.getmode("L")
|
|
|
|
ImageMode.getmode("P")
|
|
|
|
ImageMode.getmode("RGB")
|
|
|
|
ImageMode.getmode("I")
|
|
|
|
ImageMode.getmode("F")
|
|
|
|
|
|
|
|
m = ImageMode.getmode("1")
|
|
|
|
self.assertEqual(m.mode, "1")
|
2015-07-03 08:03:25 +03:00
|
|
|
self.assertEqual(str(m), "1")
|
2014-07-20 01:51:26 +04:00
|
|
|
self.assertEqual(m.bands, ("1",))
|
|
|
|
self.assertEqual(m.basemode, "L")
|
|
|
|
self.assertEqual(m.basetype, "L")
|
|
|
|
|
2019-06-19 09:30:10 +03:00
|
|
|
for mode in (
|
|
|
|
"I;16",
|
|
|
|
"I;16S",
|
|
|
|
"I;16L",
|
|
|
|
"I;16LS",
|
|
|
|
"I;16B",
|
|
|
|
"I;16BS",
|
|
|
|
"I;16N",
|
|
|
|
"I;16NS",
|
|
|
|
):
|
2019-06-12 13:33:00 +03:00
|
|
|
m = ImageMode.getmode(mode)
|
|
|
|
self.assertEqual(m.mode, mode)
|
|
|
|
self.assertEqual(str(m), mode)
|
|
|
|
self.assertEqual(m.bands, ("I",))
|
|
|
|
self.assertEqual(m.basemode, "L")
|
|
|
|
self.assertEqual(m.basetype, "L")
|
|
|
|
|
2014-07-20 01:51:26 +04:00
|
|
|
m = ImageMode.getmode("RGB")
|
|
|
|
self.assertEqual(m.mode, "RGB")
|
2015-07-03 08:03:25 +03:00
|
|
|
self.assertEqual(str(m), "RGB")
|
2014-07-20 01:51:26 +04:00
|
|
|
self.assertEqual(m.bands, ("R", "G", "B"))
|
|
|
|
self.assertEqual(m.basemode, "RGB")
|
|
|
|
self.assertEqual(m.basetype, "L")
|
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
def test_properties(self):
|
|
|
|
def check(mode, *result):
|
|
|
|
signature = (
|
2019-06-13 18:54:24 +03:00
|
|
|
Image.getmodebase(mode),
|
|
|
|
Image.getmodetype(mode),
|
|
|
|
Image.getmodebands(mode),
|
|
|
|
Image.getmodebandnames(mode),
|
|
|
|
)
|
2014-06-10 13:10:47 +04:00
|
|
|
self.assertEqual(signature, result)
|
2019-06-13 18:54:24 +03:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
check("1", "L", "L", 1, ("1",))
|
|
|
|
check("L", "L", "L", 1, ("L",))
|
2019-03-19 03:13:58 +03:00
|
|
|
check("P", "P", "L", 1, ("P",))
|
2014-06-10 13:10:47 +04:00
|
|
|
check("I", "L", "I", 1, ("I",))
|
|
|
|
check("F", "L", "F", 1, ("F",))
|
|
|
|
check("RGB", "RGB", "L", 3, ("R", "G", "B"))
|
|
|
|
check("RGBA", "RGB", "L", 4, ("R", "G", "B", "A"))
|
|
|
|
check("RGBX", "RGB", "L", 4, ("R", "G", "B", "X"))
|
|
|
|
check("RGBX", "RGB", "L", 4, ("R", "G", "B", "X"))
|
|
|
|
check("CMYK", "RGB", "L", 4, ("C", "M", "Y", "K"))
|
|
|
|
check("YCbCr", "RGB", "L", 3, ("Y", "Cb", "Cr"))
|