diff --git a/src/wrappers/python/Imath.py b/src/wrappers/python/Imath.py index 3f551e3741..a3fccc2634 100644 --- a/src/wrappers/python/Imath.py +++ b/src/wrappers/python/Imath.py @@ -164,12 +164,18 @@ class Channel: >>> import Imath >>> print Imath.Channel(Imath.PixelType(Imath.PixelType.FLOAT), 4, 4) FLOAT (4, 4) + >>> print Imath.Channel(Imath.PixelType.FLOAT, 4, 4) + Traceback (most recent call last): + ... + TypeError: type needs to be a PixelType. """ def __init__(self, type = PixelType(PixelType.HALF), xSampling = 1, ySampling = 1): self.type = type self.xSampling = xSampling self.ySampling = ySampling + if not isinstance(self.type, PixelType): + raise TypeError("type needs to be a PixelType.") def __repr__(self): return repr(self.type) + " " + repr((self.xSampling, self.ySampling)) def __eq__(self, other): diff --git a/src/wrappers/python/README.md b/src/wrappers/python/README.md index d7c15c989a..7ab4f284f1 100644 --- a/src/wrappers/python/README.md +++ b/src/wrappers/python/README.md @@ -71,17 +71,18 @@ for more information. The "hello, world" image writer: - import OpenEXR + import OpenEXR, Imath + from array import array width = 10 height = 10 size = width * height h = OpenEXR.Header(width,height) - h['channels'] = {'R' : Imath.Channel(FLOAT), - 'G' : Imath.Channel(FLOAT), - 'B' : Imath.Channel(FLOAT), - 'A' : Imath.Channel(FLOAT)} + h['channels'] = {'R' : Imath.Channel(Imath.PixelType(Imath.PixelType.FLOAT)), + 'G' : Imath.Channel(Imath.PixelType(Imath.PixelType.FLOAT)), + 'B' : Imath.Channel(Imath.PixelType(Imath.PixelType.FLOAT)), + 'A' : Imath.Channel(Imath.PixelType(Imath.PixelType.FLOAT))} o = OpenEXR.OutputFile("hello.exr", h) r = array('f', [n for n in range(size*0,size*1)]).tobytes() g = array('f', [n for n in range(size*1,size*2)]).tobytes() diff --git a/src/wrappers/python/tests/test_unittest.py b/src/wrappers/python/tests/test_unittest.py index e08a44b0b9..96f06d3379 100644 --- a/src/wrappers/python/tests/test_unittest.py +++ b/src/wrappers/python/tests/test_unittest.py @@ -197,6 +197,13 @@ def test_invalid_pixeltype(): else: assert 0 + try: + Imath.Channel(FLOAT) + except: + pass + else: + assert 0 + print("invalid pixeltype ok") testList.append(("test_invalid_pixeltype", test_invalid_pixeltype))