summaryrefslogtreecommitdiffstats
path: root/libdimension-python
diff options
context:
space:
mode:
Diffstat (limited to 'libdimension-python')
-rwxr-xr-xlibdimension-python/tests/color.py1
-rw-r--r--libdimension-python/wrapper.pxd4
-rw-r--r--libdimension-python/wrapper.pyx23
3 files changed, 16 insertions, 12 deletions
diff --git a/libdimension-python/tests/color.py b/libdimension-python/tests/color.py
index 47ac975..1299a88 100755
--- a/libdimension-python/tests/color.py
+++ b/libdimension-python/tests/color.py
@@ -50,3 +50,4 @@ assert Cyan == Color(0, 1, 1), Cyan
assert Red + Blue == Magenta, Red + Blue
assert 0.5*White == Color(0.5, 0.5, 0.5), 0.5*White
+assert White/2 == Color(0.5, 0.5, 0.5), White/2
diff --git a/libdimension-python/wrapper.pxd b/libdimension-python/wrapper.pxd
index 920f6f2..94966f3 100644
--- a/libdimension-python/wrapper.pxd
+++ b/libdimension-python/wrapper.pxd
@@ -155,8 +155,10 @@ cdef extern from "../libdimension/dimension.h":
dmnsn_color dmnsn_new_color5(double R, double G, double B,
double trans, double filter)
- dmnsn_color dmnsn_color_from_sRGB(dmnsn_color color)
+ double dmnsn_sRGB_gamma(double Clinear)
dmnsn_color dmnsn_color_to_sRGB(dmnsn_color color)
+ double dmnsn_sRGB_inverse_gamma(double CsRGB)
+ dmnsn_color dmnsn_color_from_sRGB(dmnsn_color color)
double dmnsn_color_intensity(dmnsn_color color)
dmnsn_color dmnsn_color_add(dmnsn_color color1, dmnsn_color color2)
diff --git a/libdimension-python/wrapper.pyx b/libdimension-python/wrapper.pyx
index 5431e75..2ed85e0 100644
--- a/libdimension-python/wrapper.pyx
+++ b/libdimension-python/wrapper.pyx
@@ -465,6 +465,8 @@ cdef class Color:
return _sRGBColor(dmnsn_color_mul(rhs, (<Color>lhs)._sRGB))
else:
return _sRGBColor(dmnsn_color_mul(lhs, (<Color?>rhs)._sRGB))
+ def __truediv__(Color lhs not None, double rhs):
+ return _sRGBColor(dmnsn_color_mul(1/rhs, lhs._sRGB))
def __richcmp__(lhs, rhs, int op):
cdef clhs = Color(lhs)
@@ -831,9 +833,9 @@ cdef class Diffuse(Finish):
Keyword arguments:
diffuse -- the intensity of the diffuse reflection
"""
- cdef dmnsn_color gray = dmnsn_color_mul(diffuse, dmnsn_white)
- diffuse = dmnsn_color_intensity(dmnsn_color_from_sRGB(gray))
- self._finish.diffuse = dmnsn_new_lambertian(diffuse)
+ self._finish.diffuse = dmnsn_new_lambertian(
+ dmnsn_sRGB_inverse_gamma(diffuse)
+ )
cdef class Phong(Finish):
"""Phong specular highlight."""
@@ -841,7 +843,10 @@ cdef class Phong(Finish):
"""
Create a Phong highlight.
"""
- self._finish.specular = dmnsn_new_phong(strength, size)
+ self._finish.specular = dmnsn_new_phong(
+ dmnsn_sRGB_inverse_gamma(strength),
+ size
+ )
cdef class Reflection(Finish):
"""Reflective finish."""
@@ -857,10 +862,8 @@ cdef class Reflection(Finish):
if max is None:
max = min
- # Use sRGB value because Reflection(0.5) should really mean "reflect half
- # the light"
- self._finish.reflection = dmnsn_new_basic_reflection(Color(min)._sRGB,
- Color(max)._sRGB,
+ self._finish.reflection = dmnsn_new_basic_reflection(Color(min)._c,
+ Color(max)._c,
falloff)
############
@@ -1317,9 +1320,7 @@ cdef class PointLight(Light):
location -- the origin of the light rays
color -- the color and intensity of the light
"""
- # Take the sRGB component because "color = 0.5*White" should really mean
- # a half-intensity white light
- self._light = dmnsn_new_point_light(Vector(location)._v, Color(color)._sRGB)
+ self._light = dmnsn_new_point_light(Vector(location)._v, Color(color)._c)
Light.__init__(self)
###########