From de659b311b756b75cbe06cf2ed02c7ab779915bd Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Sun, 10 Jul 2011 18:36:46 -0600 Subject: Support flags-style syntax for --quality. --- dimension/dimension.in | 2 +- libdimension-python/dimension.pyx | 63 ++++++++++++++++++++++++++++++++++++--- 2 files changed, 60 insertions(+), 5 deletions(-) diff --git a/dimension/dimension.in b/dimension/dimension.in index 90abdb7..f8cb114 100644 --- a/dimension/dimension.in +++ b/dimension/dimension.in @@ -75,7 +75,7 @@ _parser.add_argument("-q", "--quiet", action = "store_true", _parser.add_argument("--threads", action = "store", type = int, help = "the number of threads to render with") -_parser.add_argument("--quality", action = "store", type = int, +_parser.add_argument("--quality", action = "store", type = str, help = "the scene quality") _parser.add_argument("-o", "--output", action = "store", type = str, diff --git a/libdimension-python/dimension.pyx b/libdimension-python/dimension.pyx index addba7e..ff97f73 100644 --- a/libdimension-python/dimension.pyx +++ b/libdimension-python/dimension.pyx @@ -884,7 +884,7 @@ cdef class Object: self.texture = texture if pigment is not None: if texture is not None: - raise TypeError('both texture and pigment specified.') + raise TypeError("both texture and pigment specified.") else: if self.texture is None: self.texture = Texture() @@ -892,7 +892,7 @@ cdef class Object: if finish is not None: if texture is not None: - raise TypeError('both texture and finish specified.') + raise TypeError("both texture and finish specified.") else: if self.texture is None: self.texture = Texture() @@ -1401,9 +1401,9 @@ cdef class Scene: property quality: """The render quality.""" def __get__(self): - return self._scene.quality + return _quality_to_string(self._scene.quality) def __set__(self, q): - self._scene.quality = q + self._scene.quality = _string_to_quality(q) property bounding_timer: """The Timer for building the bounding hierarchy.""" @@ -1432,3 +1432,58 @@ cdef class Scene: def __dealloc__(self): dmnsn_delete_scene(self._scene) + +def _quality_to_string(int quality): + cdef str s = "" + + if quality & DMNSN_RENDER_PIGMENT: + s += 'p' + if quality & DMNSN_RENDER_LIGHTS: + s += 'l' + if quality & DMNSN_RENDER_FINISH: + s += 'f' + if quality & DMNSN_RENDER_TRANSLUCENCY: + s += 't' + if quality & DMNSN_RENDER_REFLECTION: + s += 'r' + + if s == "": + return "0" + else: + return s + +def _string_to_quality(str quality not None): + cdef int q = DMNSN_RENDER_NONE + inverse = False + + if quality[0] == '^': + inverse = True + quality = quality[1:] + + if quality != "0": + while len(quality) > 0: + ch = quality[0] + quality = quality[1:] + + if ch == 'p': + flag = DMNSN_RENDER_PIGMENT + elif ch == 'l': + flag = DMNSN_RENDER_LIGHTS + elif ch == 'f': + flag = DMNSN_RENDER_FINISH + elif ch == 't': + flag = DMNSN_RENDER_TRANSLUCENCY + elif ch == 'r': + flag = DMNSN_RENDER_REFLECTION + else: + raise ValueError("unknown quality flag '%c'" % ch) + + if q & flag: + raise ValueError("flag '%c' specified twice" % ch) + else: + q |= flag + + if inverse: + q = ~q + + return q -- cgit v1.2.3