URL:
https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2008-02-14 Caroline Vigouroux <vigour_c(a)epita.fr>
Corrections on color structures.
* color/my_cmy.hh: corrections.
* color/my_hsi.hh: corrections.
* color/rgb_to_cmy.hh: corrections.
* color/rgb_to_yuv.hh: corrections.
* color/tests.cc: corrections.
---
my_cmy.hh | 12 ++++++------
my_hsi.hh | 35 ++++++++++++++++++++++++++++++-----
rgb_to_cmy.hh | 16 ++++++++++------
rgb_to_yuv.hh | 13 +++++++++----
tests.cc | 2 +-
5 files changed, 56 insertions(+), 22 deletions(-)
Index: trunk/milena/sandbox/vigouroux/color/rgb_to_cmy.hh
===================================================================
--- trunk/milena/sandbox/vigouroux/color/rgb_to_cmy.hh (revision 1722)
+++ trunk/milena/sandbox/vigouroux/color/rgb_to_cmy.hh (revision 1723)
@@ -5,6 +5,7 @@
#include <mln/io/ppm/save.hh>
#include <mln/display/save_and_show.hh>
#include <mln/level/fill.hh>
+#include <mln/value/int_u.hh>
#include "my_cmy.hh"
@@ -12,7 +13,7 @@
namespace convert {
struct f_rgb_to_cmy
{
- struct value::cmy
+ struct value::cmy<8>
doit(const struct value::rgb<8> rgb) const
{
struct value::cmy cmy;
@@ -30,11 +31,14 @@
struct value::rgb<8>
doit(const struct value::cmy cmy) const
{
- struct value::rgb<8> rgb;
-
- rgb.red() = 1 - cmy.c();
- rgb.green() = 1 - cmy.m();
- rgb.blue() = 1 - cmy.y();
+ int red;
+ int green;
+ int blue;
+
+ red = int(1 - cmy.c());
+ green = int(1 - cmy.m());
+ blue = int(1 - cmy.y());
+ struct value::rgb<8> rgb(red, green, blue);
return (rgb);
}
Index: trunk/milena/sandbox/vigouroux/color/tests.cc
===================================================================
--- trunk/milena/sandbox/vigouroux/color/tests.cc (revision 1722)
+++ trunk/milena/sandbox/vigouroux/color/tests.cc (revision 1723)
@@ -13,7 +13,7 @@
{
using namespace mln;
- struct value::yuv yuv(4, 4, 4);
+ struct value::yuv<8> yuv(4, 4, 4);
std::cout << yuv.y() << std::endl;
std::cout << yuv.u() << std::endl;
std::cout << yuv.v() << std::endl;
Index: trunk/milena/sandbox/vigouroux/color/my_hsi.hh
===================================================================
--- trunk/milena/sandbox/vigouroux/color/my_hsi.hh (revision 1722)
+++ trunk/milena/sandbox/vigouroux/color/my_hsi.hh (revision 1723)
@@ -4,6 +4,9 @@
#include <mln/value/int_u.hh>
#include <mln/metal/vec.hh>
+#ifndef MLN_VALUE_HSI_HH
+# define MLN_VALUE_HSI_HH
+
namespace mln
{
namespace value
@@ -18,22 +21,42 @@
/// Constructor from component values.
hsi<n>(int h, int s, int i);
+ /// Access to component values.
+ double h() const { return this->h_; }
+ double s() const { return this->s_; }
+ double i() const { return this->i_; }
+
+ /// Set component values.
+ void h(double h)
+ {
+ this->h_ = h;
+ }
+ void s(double s)
+ {
+ this->s_ = s;
+ }
+ void i(double i)
+ {
+ mln_precondition(i >= 0);
+ this->i_ = i;
+ }
+
private:
- int h_;
- int s_;
- int i_;
+ double h_;
+ double s_;
+ double i_;
};
template <unsigned n>
inline
- hsi::hsi<n>()
+ hsi<n>::hsi()
:h_(0), s_(0), i_(0)
{
}
template <unsigned n>
inline
- hsi::hsi<n>(int h, int s, int i)
+ hsi<n>::hsi(int h, int s, int i)
{
mln_precondition(h >= 0);
mln_precondition(s >= 0);
@@ -44,3 +67,5 @@
}
}
}
+
+#endif // ! MLN_VALUE_HSI_HH
Index: trunk/milena/sandbox/vigouroux/color/my_cmy.hh
===================================================================
--- trunk/milena/sandbox/vigouroux/color/my_cmy.hh (revision 1722)
+++ trunk/milena/sandbox/vigouroux/color/my_cmy.hh (revision 1723)
@@ -1,11 +1,11 @@
-#ifndef MLN_VALUE_YUV_HH
-# define MLN_VALUE_YUV_HH
+#ifndef MLN_VALUE_CMY_HH
+# define MLN_VALUE_CMY_HH
namespace mln
{
namespace value
{
-// template <unsigned n>
+ template <unsigned n>
struct cmy
{
public:
@@ -43,14 +43,14 @@
double y_;
};
-// template <unsigned n>
+ template <unsigned n>
inline
yuv::cmy()
:c_(0), m_(0), y_(0)
{
}
-// template <unsigned n>
+ template <unsigned n>
inline
cmy::cmy(double c, double m, double y)
{
@@ -64,4 +64,4 @@
}
}
-#endif // ! MLN_VALUE_YUV_HH
+#endif // ! MLN_VALUE_CMY_HH
Index: trunk/milena/sandbox/vigouroux/color/rgb_to_yuv.hh
===================================================================
--- trunk/milena/sandbox/vigouroux/color/rgb_to_yuv.hh (revision 1722)
+++ trunk/milena/sandbox/vigouroux/color/rgb_to_yuv.hh (revision 1723)
@@ -5,6 +5,7 @@
#include <mln/io/ppm/save.hh>
#include <mln/display/save_and_show.hh>
#include <mln/level/fill.hh>
+#include <mln/value/int_u.hh>
#include "my_yuv.hh"
@@ -30,11 +31,15 @@
struct value::rgb<8>
doit(const struct value::yuv<8> yuv) const
{
- struct value::rgb<8> rgb;
+ int r;
+ int g;
+ int b;
+
+ r = int(yuv.y() + 1.13983 * yuv.v());
+ g = int(yuv.y() - 0.39465 * yuv.u() - 0.58060 * yuv.v());
+ b = int(yuv.y() + 2.03211 * yuv.u());
- rgb.red(yuv.y() + 1.13983 * yuv.v());
- rgb.green(yuv.y() - 0.39465 * yuv.u() - 0.58060 * yuv.v());
- rgb.blue(yuv.y() + 2.03211 * yuv.u());
+ struct value::rgb<8> rgb(r, g, b);
return (rgb);
}