URL:
https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2008-02-17 Caroline Vigouroux <vigour_c(a)epita.fr>
New structures.
* my_hsl.hh: New.
* my_hsv.hh: New.
* my_xyz.hh: New.
* my_yiq.hh: New.
* rgb_to_hsi.hh: .
---
my_hsl.hh | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
my_hsv.hh | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
my_xyz.hh | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
my_yiq.hh | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
rgb_to_hsi.hh | 11 ++++++--
5 files changed, 288 insertions(+), 3 deletions(-)
Index: trunk/milena/sandbox/vigouroux/color/my_hsl.hh
===================================================================
--- trunk/milena/sandbox/vigouroux/color/my_hsl.hh (revision 0)
+++ trunk/milena/sandbox/vigouroux/color/my_hsl.hh (revision 1734)
@@ -0,0 +1,71 @@
+#include <mln/value/ops.hh>
+
+#include <mln/value/concept/vectorial.hh>
+#include <mln/value/int_u.hh>
+#include <mln/metal/vec.hh>
+
+#ifndef MLN_VALUE_HSL_HH
+# define MLN_VALUE_HSL_HH
+
+namespace mln
+{
+ namespace value
+ {
+ template <unsigned n>
+ struct hsl
+ {
+ public:
+ /// Constructor without argument.
+ hsl<n>();
+
+ /// Constructor from component values.
+ hsl<n>(int h, int s, int l);
+
+ /// Access to component values.
+ double h() const { return this->h_; }
+ double s() const { return this->s_; }
+ double l() const { return this->l_; }
+
+ /// Set component values.
+ void h(double h)
+ {
+ this->h_ = h;
+ }
+ void s(double s)
+ {
+ this->s_ = s;
+ }
+ void l(double l)
+ {
+ mln_precondition(l >= 0);
+ this->l_ = l;
+ }
+
+ private:
+ double h_;
+ double s_;
+ double l_;
+ };
+
+ template <unsigned n>
+ inline
+ hsl<n>::hsl()
+ :h_(0), s_(0), l_(0)
+ {
+ }
+
+ template <unsigned n>
+ inline
+ hsl<n>::hsl(int h, int s, int l)
+ {
+ mln_precondition(h >= 0);
+ mln_precondition(s >= 0);
+ mln_precondition(l >= 0);
+ this->h_ = h;
+ this->s_ = s;
+ this->l_ = l;
+ }
+ }
+}
+
+#endif // ! MLN_VALUE_HSL_HH
Index: trunk/milena/sandbox/vigouroux/color/my_xyz.hh
===================================================================
--- trunk/milena/sandbox/vigouroux/color/my_xyz.hh (revision 0)
+++ trunk/milena/sandbox/vigouroux/color/my_xyz.hh (revision 1734)
@@ -0,0 +1,69 @@
+// #include <mln/value/ops.hh>
+
+// #include <mln/value/concept/vectorial.hh>
+// #include <mln/value/int_u.hh>
+// #include <mln/metal/vec.hh>
+
+#ifndef MLN_VALUE_XYZ_HH
+# define MLN_VALUE_XYZ_HH
+
+namespace mln
+{
+ namespace value
+ {
+ template <unsigned n>
+ struct xyz
+ {
+ public:
+ /// Constructor without argument.
+ xyz<n>();
+
+ /// Constructor from component values.
+ xyz<n>(double x, double y, double z);
+
+ /// Access to component values.
+ double x() const { return this->x_; }
+ double y() const { return this->y_; }
+ double z() const { return this->z_; }
+
+ /// Set component values.
+ void x(double x)
+ {
+ this->x_ = x;
+ }
+ void y(double y)
+ {
+ this->y_ = y;
+ }
+ void z(double z)
+ {
+ mln_precondition(z >= 0);
+ this->z_ = z;
+ }
+
+ private:
+ double x_;
+ double y_;
+ double z_;
+ };
+
+ template <unsigned n>
+ inline
+ xyz<n>::xyz()
+ :x_(0), y_(0), z_(0)
+ {
+ }
+
+ template <unsigned n>
+ inline
+ xyz<n>::xyz(double x, double y, double z)
+ {
+ mln_precondition(z >= 0);
+ this->x_ = x;
+ this->y_ = y;
+ this->z_ = z;
+ }
+ }
+}
+
+#endif // ! MLN_VALUE_XYZ_HH
Index: trunk/milena/sandbox/vigouroux/color/my_hsv.hh
===================================================================
--- trunk/milena/sandbox/vigouroux/color/my_hsv.hh (revision 0)
+++ trunk/milena/sandbox/vigouroux/color/my_hsv.hh (revision 1734)
@@ -0,0 +1,71 @@
+#include <mln/value/ops.hh>
+
+#include <mln/value/concept/vectorial.hh>
+#include <mln/value/int_u.hh>
+#include <mln/metal/vec.hh>
+
+#ifndef MLN_VALUE_HSV_HH
+# define MLN_VALUE_HSV_HH
+
+namespace mln
+{
+ namespace value
+ {
+ template <unsigned n>
+ struct hsv
+ {
+ public:
+ /// Constructor without argument.
+ hsv<n>();
+
+ /// Constructor from component values.
+ hsv<n>(int h, int s, int v);
+
+ /// Access to component values.
+ double h() const { return this->h_; }
+ double s() const { return this->s_; }
+ double v() const { return this->v_; }
+
+ /// Set component values.
+ void h(double h)
+ {
+ this->h_ = h;
+ }
+ void s(double s)
+ {
+ this->s_ = s;
+ }
+ void v(double v)
+ {
+ mln_precondition(v >= 0);
+ this->v_ = v;
+ }
+
+ private:
+ double h_;
+ double s_;
+ double v_;
+ };
+
+ template <unsigned n>
+ inline
+ hsi<n>::hsv()
+ :h_(0), s_(0), v_(0)
+ {
+ }
+
+ template <unsigned n>
+ inline
+ hsv<n>::hsv(int h, int s, int v)
+ {
+ mln_precondition(h >= 0);
+ mln_precondition(s >= 0);
+ mln_precondition(v >= 0);
+ this->h_ = h;
+ this->s_ = s;
+ this->v_ = v;
+ }
+ }
+}
+
+#endif // ! MLN_VALUE_HSV_HH
Index: trunk/milena/sandbox/vigouroux/color/my_yiq.hh
===================================================================
--- trunk/milena/sandbox/vigouroux/color/my_yiq.hh (revision 0)
+++ trunk/milena/sandbox/vigouroux/color/my_yiq.hh (revision 1734)
@@ -0,0 +1,69 @@
+// #include <mln/value/ops.hh>
+
+// #include <mln/value/concept/vectorial.hh>
+// #include <mln/value/int_u.hh>
+// #include <mln/metal/vec.hh>
+
+#ifndef MLN_VALUE_YIQ_HH
+# define MLN_VALUE_YIQ_HH
+
+namespace mln
+{
+ namespace value
+ {
+ template <unsigned n>
+ struct yiq
+ {
+ public:
+ /// Constructor without argument.
+ yiq<n>();
+
+ /// Constructor from component values.
+ yiq<n>(double y, double i, double q);
+
+ /// Access to component values.
+ double y() const { return this->y_; }
+ double i() const { return this->i_; }
+ double q() const { return this->q_; }
+
+ /// Set component values.
+ void y(double y)
+ {
+ this->y_ = y;
+ }
+ void i(double i)
+ {
+ this->i_ = i;
+ }
+ void q(double q)
+ {
+ mln_precondition(q >= 0);
+ this->q_ = q;
+ }
+
+ private:
+ double y_;
+ double i_;
+ double q_;
+ };
+
+ template <unsigned n>
+ inline
+ yiq<n>::yiq()
+ :y_(0), i_(0), q_(0)
+ {
+ }
+
+ template <unsigned n>
+ inline
+ yiq<n>::yiq(double y, double i, double q)
+ {
+ mln_precondition(q >= 0);
+ this->y_ = y;
+ this->i_ = i;
+ this->q_ = q;
+ }
+ }
+}
+
+#endif // ! MLN_VALUE_YIQ_HH
Index: trunk/milena/sandbox/vigouroux/color/rgb_to_hsi.hh
===================================================================
--- trunk/milena/sandbox/vigouroux/color/rgb_to_hsi.hh (revision 1733)
+++ trunk/milena/sandbox/vigouroux/color/rgb_to_hsi.hh (revision 1734)
@@ -16,10 +16,15 @@
doit(const struct value::rgb<8> rgb) const
{
struct value::hsi<8> hsi;
+ double alpha;
+ double beta;
- hsi.h(0); // not yet implemented
- hsi.s(0); // not yet implemented
- hsi.i(0); // not yet implemented
+ alpha = rgb.red() - 1 / 2 * (rgb.green() + rgb.blue());
+ beta = sqrt(3) / 2 * (rgb.green() - rgb.blue());
+
+ hsi.h(atan2(beta / alpha));
+ hsi.s(sqrt(alpha * alpha + beta * beta));
+ hsi.i((rgb.red() + rgb.green() + rgb.blue()) / 3);
return (hsi);
}