summaryrefslogtreecommitdiffstats
path: root/libdimensionxx
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2009-04-10 20:53:40 +0000
committerTavian Barnes <tavianator@gmail.com>2009-04-10 20:53:40 +0000
commitbef2ee297d3492c8a54e61fe498e6eda518da250 (patch)
treee6a140f10bec35df88ef39e8baba023ee94441c9 /libdimensionxx
parentc29bc5a684107737b60be1474e8bd6470ce4eae9 (diff)
downloaddimension-bef2ee297d3492c8a54e61fe498e6eda518da250.tar.xz
Write C++ color wrappers.
Diffstat (limited to 'libdimensionxx')
-rw-r--r--libdimensionxx/color.cpp5
-rw-r--r--libdimensionxx/dimensionxx/canvas.hpp2
-rw-r--r--libdimensionxx/dimensionxx/color.hpp173
-rw-r--r--libdimensionxx/dimensionxx/geometry.hpp80
4 files changed, 218 insertions, 42 deletions
diff --git a/libdimensionxx/color.cpp b/libdimensionxx/color.cpp
index 8b90fe9..c7f768a 100644
--- a/libdimensionxx/color.cpp
+++ b/libdimensionxx/color.cpp
@@ -19,3 +19,8 @@
*************************************************************************/
#include "dimensionxx.hpp"
+
+namespace Dimension
+{
+ const CIE_XYZ whitepoint(dmnsn_whitepoint);
+}
diff --git a/libdimensionxx/dimensionxx/canvas.hpp b/libdimensionxx/dimensionxx/canvas.hpp
index 9bb76eb..e2e493a 100644
--- a/libdimensionxx/dimensionxx/canvas.hpp
+++ b/libdimensionxx/dimensionxx/canvas.hpp
@@ -21,7 +21,7 @@
#ifndef DIMENSIONXX_CANVAS_HPP
#define DIMENSIONXX_CANVAS_HPP
-namespace dimension
+namespace Dimension
{
}
diff --git a/libdimensionxx/dimensionxx/color.hpp b/libdimensionxx/dimensionxx/color.hpp
index 114485f..5db041a 100644
--- a/libdimensionxx/dimensionxx/color.hpp
+++ b/libdimensionxx/dimensionxx/color.hpp
@@ -21,8 +21,179 @@
#ifndef DIMENSIONXX_COLOR_HPP
#define DIMENSIONXX_COLOR_HPP
-namespace dimension
+namespace Dimension
{
+ class CIE_XYZ;
+ class CIE_xyY;
+ class CIE_Lab;
+ class CIE_Luv;
+ class sRGB;
+
+ extern const CIE_XYZ whitepoint;
+
+ class Color
+ {
+ public:
+ Color() { }
+ inline Color(const CIE_XYZ& XYZ);
+ inline Color(const CIE_xyY& xyY);
+ inline Color(const CIE_Lab& Lab, const CIE_XYZ& white = whitepoint);
+ inline Color(const CIE_Luv& Luv, const CIE_XYZ& white = whitepoint);
+ inline Color(const sRGB& RGB);
+ explicit Color(dmnsn_color c) : m_color(c) { }
+ // Color(const Color& c);
+ // ~Color();
+
+ double filter() const { return m_color.filter; }
+ double trans() const { return m_color.trans; }
+
+ double filter(double f) { m_color.filter = f; }
+ double trans(double t) { m_color.trans = t; }
+
+ // Color& operator=(const Color& c);
+
+ dmnsn_color dmnsn() const { return m_color; }
+
+ private:
+ dmnsn_color m_color;
+ };
+
+ class CIE_XYZ
+ {
+ public:
+ CIE_XYZ(double X, double Y, double Z)
+ { m_XYZ.X = X; m_XYZ.Y = Y; m_XYZ.Z = Z; }
+ CIE_XYZ(const Color& c) : m_XYZ(dmnsn_XYZ_from_color(c.dmnsn())) { }
+ explicit CIE_XYZ(dmnsn_CIE_XYZ XYZ) : m_XYZ(XYZ) { }
+ // CIE_XYZ(const CIE_XYZ& XYZ);
+ // ~CIE_XYZ();
+
+ double X() const { return m_XYZ.X; }
+ double Y() const { return m_XYZ.Y; }
+ double Z() const { return m_XYZ.Z; }
+
+ // CIE_XYZ& operator=(const CIE_XYZ& XYZ);
+ CIE_XYZ& operator=(const Color& c)
+ { m_XYZ = dmnsn_XYZ_from_color(c.dmnsn()); }
+
+ dmnsn_CIE_XYZ dmnsn() const { return m_XYZ; }
+
+ private:
+ dmnsn_CIE_XYZ m_XYZ;
+ };
+
+ class CIE_xyY
+ {
+ public:
+ CIE_xyY(double x, double y, double Y)
+ { m_xyY.x = x; m_xyY.y = y; m_xyY.Y = Y; }
+ CIE_xyY(const Color& c) : m_xyY(dmnsn_xyY_from_color(c.dmnsn())) { }
+ explicit CIE_xyY(dmnsn_CIE_xyY xyY) : m_xyY(xyY) { }
+ // CIE_xyY(const CIE_xyY& xyY);
+ // ~CIE_xyY();
+
+ double x() const { return m_xyY.x; }
+ double y() const { return m_xyY.y; }
+ double Y() const { return m_xyY.Y; }
+
+ // CIE_xyY& operator=(const CIE_xyY& xyY);
+ CIE_xyY& operator=(const Color& c)
+ { m_xyY = dmnsn_xyY_from_color(c.dmnsn()); }
+
+ dmnsn_CIE_xyY dmnsn() const { return m_xyY; }
+
+ private:
+ dmnsn_CIE_xyY m_xyY;
+ };
+
+ class CIE_Lab
+ {
+ public:
+ CIE_Lab(double L, double a, double b)
+ { m_Lab.L = L; m_Lab.a = a; m_Lab.b = b; }
+ CIE_Lab(const Color& c, const CIE_XYZ& white = whitepoint)
+ : m_Lab(dmnsn_Lab_from_color(c.dmnsn(), white.dmnsn())) { }
+ explicit CIE_Lab(dmnsn_CIE_Lab Lab) : m_Lab(Lab) { }
+ // CIE_Lab(const CIE_Lab& Lab);
+ // ~CIE_Lab();
+
+ double L() const { return m_Lab.L; }
+ double a() const { return m_Lab.a; }
+ double b() const { return m_Lab.b; }
+
+ // CIE_Lab& operator=(const CIE_Lab& Lab);
+ CIE_Lab& operator=(const Color& c)
+ { m_Lab = dmnsn_Lab_from_color(c.dmnsn(), whitepoint.dmnsn()); }
+
+ dmnsn_CIE_Lab dmnsn() const { return m_Lab; }
+
+ private:
+ dmnsn_CIE_Lab m_Lab;
+ };
+
+ class CIE_Luv
+ {
+ public:
+ CIE_Luv(double L, double u, double v)
+ { m_Luv.L = L; m_Luv.u = u; m_Luv.v = v; }
+ CIE_Luv(const Color& c, const CIE_XYZ& white = whitepoint)
+ : m_Luv(dmnsn_Luv_from_color(c.dmnsn(), white.dmnsn())) { }
+ explicit CIE_Luv(dmnsn_CIE_Luv Luv) : m_Luv(Luv) { }
+ // CIE_Luv(const CIE_Luv& Luv);
+ // ~CIE_Luv();
+
+ double L() const { return m_Luv.L; }
+ double u() const { return m_Luv.u; }
+ double v() const { return m_Luv.v; }
+
+ // CIE_Luv& operator=(const CIE_Luv& Luv);
+ CIE_Luv& operator=(const Color& c)
+ { m_Luv = dmnsn_Luv_from_color(c.dmnsn(), whitepoint.dmnsn()); }
+
+ dmnsn_CIE_Luv dmnsn() const { return m_Luv; }
+
+ private:
+ dmnsn_CIE_Luv m_Luv;
+ };
+
+ class sRGB
+ {
+ public:
+ sRGB(double R, double G, double B)
+ { m_RGB.R = R; m_RGB.G = G; m_RGB.B = B; }
+ sRGB(const Color& c) : m_RGB(dmnsn_sRGB_from_color(c.dmnsn())) { }
+ explicit sRGB(dmnsn_sRGB RGB) : m_RGB(RGB) { }
+ // sRGB(const sRGB& RGB);
+ // ~sRGB();
+
+ double R() const { return m_RGB.R; }
+ double G() const { return m_RGB.G; }
+ double B() const { return m_RGB.B; }
+
+ // sRGB& operator=(const sRGB& RGB);
+ sRGB& operator=(const Color& c)
+ { m_RGB = dmnsn_sRGB_from_color(c.dmnsn()); }
+
+ dmnsn_sRGB dmnsn() const { return m_RGB; }
+
+ private:
+ dmnsn_sRGB m_RGB;
+ };
+
+ inline Color::Color(const CIE_XYZ& XYZ)
+ : m_color(dmnsn_color_from_XYZ(XYZ.dmnsn())) { }
+
+ inline Color::Color(const CIE_xyY& xyY)
+ : m_color(dmnsn_color_from_xyY(xyY.dmnsn())) { }
+
+ inline Color::Color(const CIE_Lab& Lab, const CIE_XYZ& white)
+ : m_color(dmnsn_color_from_Lab(Lab.dmnsn(), white.dmnsn())) { }
+
+ inline Color::Color(const CIE_Luv& Luv, const CIE_XYZ& white)
+ : m_color(dmnsn_color_from_Luv(Luv.dmnsn(), white.dmnsn())) { }
+
+ inline Color::Color(const sRGB& RGB)
+ : m_color(dmnsn_color_from_sRGB(RGB.dmnsn())) { }
}
#endif /* DIMENSIONXX_COLOR_HPP */
diff --git a/libdimensionxx/dimensionxx/geometry.hpp b/libdimensionxx/dimensionxx/geometry.hpp
index 647bf24..4295c05 100644
--- a/libdimensionxx/dimensionxx/geometry.hpp
+++ b/libdimensionxx/dimensionxx/geometry.hpp
@@ -23,32 +23,32 @@
#include <dimension.h>
-namespace dimension
+namespace Dimension
{
- typedef dmnsn_scalar scalar;
+ typedef dmnsn_scalar Scalar;
- class vector
+ class Vector
{
public:
- vector() { }
- vector(scalar x, scalar y, scalar z)
+ Vector() { }
+ Vector(Scalar x, Scalar y, Scalar z)
: m_vector(dmnsn_vector_construct(x, y, z)) { }
- explicit vector(dmnsn_vector v) : m_vector(v) { }
- // vector(const vector& v);
- // ~vector();
+ explicit Vector(dmnsn_vector v) : m_vector(v) { }
+ // Vector(const Vector& v);
+ // ~Vector();
- scalar x() const { return m_vector.x; }
- scalar y() const { return m_vector.y; }
- scalar z() const { return m_vector.z; }
+ Scalar x() const { return m_vector.x; }
+ Scalar y() const { return m_vector.y; }
+ Scalar z() const { return m_vector.z; }
- // vector& operator=(const vector& rhs);
- vector& operator+=(const vector& rhs)
+ // Vector& operator=(const Vector& rhs);
+ Vector& operator+=(const Vector& rhs)
{ m_vector = dmnsn_vector_add(m_vector, rhs.m_vector); return *this; }
- vector& operator-=(const vector& rhs)
+ Vector& operator-=(const Vector& rhs)
{ m_vector = dmnsn_vector_sub(m_vector, rhs.m_vector); return *this; }
- vector& operator*=(scalar rhs)
+ Vector& operator*=(Scalar rhs)
{ m_vector = dmnsn_vector_mul(rhs, m_vector); return *this; }
- vector& operator/=(scalar rhs)
+ Vector& operator/=(Scalar rhs)
{ m_vector = dmnsn_vector_div(m_vector, rhs); return *this; }
dmnsn_vector dmnsn() const { return m_vector; }
@@ -61,16 +61,16 @@ namespace dimension
{
public:
line() { }
- line(const vector& x0, const vector& n)
+ line(const Vector& x0, const Vector& n)
{ m_line.x0 = x0.dmnsn(); m_line.n = n.dmnsn(); }
// line(const line& l);
// ~line();
- vector x0() const { return vector(m_line.x0); }
- vector n() const { return vector(m_line.n); }
+ Vector x0() const { return Vector(m_line.x0); }
+ Vector n() const { return Vector(m_line.n); }
// line& operator=(const line& l);
- vector operator()(scalar t) { return vector(dmnsn_line_point(m_line, t)); }
+ Vector operator()(Scalar t) { return Vector(dmnsn_line_point(m_line, t)); }
dmnsn_line dmnsn() const { return m_line; }
@@ -80,56 +80,56 @@ namespace dimension
// Vector operators
- inline vector
- operator+(const vector& lhs, const vector& rhs)
+ inline Vector
+ operator+(const Vector& lhs, const Vector& rhs)
{
- vector r = lhs;
+ Vector r = lhs;
r += rhs;
return r;
}
- inline vector
- operator-(const vector& lhs, const vector& rhs)
+ inline Vector
+ operator-(const Vector& lhs, const Vector& rhs)
{
- vector r = lhs;
+ Vector r = lhs;
r -= rhs;
return r;
}
- inline vector
- operator*(const vector& lhs, scalar rhs)
+ inline Vector
+ operator*(const Vector& lhs, Scalar rhs)
{
- vector r = lhs;
+ Vector r = lhs;
r *= rhs;
return r;
}
- inline vector
- operator*(scalar lhs, const vector& rhs)
+ inline Vector
+ operator*(Scalar lhs, const Vector& rhs)
{
- vector r = rhs;
+ Vector r = rhs;
r *= lhs;
return r;
}
- inline vector
- operator/(const vector& lhs, scalar rhs)
+ inline Vector
+ operator/(const Vector& lhs, Scalar rhs)
{
- vector r = lhs;
+ Vector r = lhs;
r /= rhs;
return r;
}
- inline scalar
- dot(const vector& lhs, const vector& rhs)
+ inline Scalar
+ dot(const Vector& lhs, const Vector& rhs)
{
return dmnsn_vector_dot(lhs.dmnsn(), rhs.dmnsn());
}
- inline vector
- cross(const vector& lhs, const vector& rhs)
+ inline Vector
+ cross(const Vector& lhs, const Vector& rhs)
{
- return vector(dmnsn_vector_cross(lhs.dmnsn(), rhs.dmnsn()));
+ return Vector(dmnsn_vector_cross(lhs.dmnsn(), rhs.dmnsn()));
}
}