summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2011-07-10 18:36:46 -0600
committerTavian Barnes <tavianator@gmail.com>2011-07-13 22:24:10 -0600
commitde659b311b756b75cbe06cf2ed02c7ab779915bd (patch)
treefa05783bfc185406f57b9afdcfaecbb63d6d3f63
parent3ec26ddd28cbcc279a4fa65de8d68c68b3950576 (diff)
downloaddimension-de659b311b756b75cbe06cf2ed02c7ab779915bd.tar.xz
Support flags-style syntax for --quality.
-rw-r--r--dimension/dimension.in2
-rw-r--r--libdimension-python/dimension.pyx63
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