Commit c8c22981 authored by Guillaume Lazzara's avatar Guillaume Lazzara
Browse files

Handle rgb and hsl conversions in from_to and remove to_rgb.

	* headers.mk: remove to_rgb.hh from distribution.

	* mln/convert/all.hh: remove to_rgb.hh.

	* mln/convert/from_to.hxx: add more predeclarations.

	* mln/convert/impl/from_value_to_value.hh: if no value concept is
	caught in the dispatch, try to call a from_to_ overload.

	* mln/fun/v2v/rgb_to_hsl.hh: add new global variables of function
	converting rgb16 to hsl.

	* mln/value/hsl.hh,
	* mln/value/rgb.hh: add new from_to_ overloads.

	* tests/convert/Makefile.am,
	* tests/convert/to_hsl.cc,
	* tests/convert/to_rgb.cc: new tests. Test conversions with rgb<n> and
	hsl<h,s,l> using from_to.

	* mln/convert/to_rgb.hh: remove. Useless since conversions are now done
	thanks to from_to.

	* tests/unit_test/Makefile.am,
	* tests/unit_test/mln_convert_to_rgb.cc: remove unit_test related to
	to_rgb.hh.

	* mln/fun/v2v/rgb_to_hsl.hh: do not include hsl.hh anymore.

git-svn-id: https://svn.lrde.epita.fr/svn/oln/trunk@3180 4aad255d-cdde-0310-9447-f3009e2ae8c0
parent 65fd6b89
2009-01-20 Guillaume Lazzara <z@lrde.epita.fr>
Handle rgb and hsl conversions in from_to and remove to_rgb.
* headers.mk: remove to_rgb.hh from distribution.
* mln/convert/all.hh: remove to_rgb.hh.
* mln/convert/from_to.hxx: add more predeclarations.
* mln/convert/impl/from_value_to_value.hh: if no value concept is
caught in the dispatch, try to call a from_to_ overload.
* mln/fun/v2v/rgb_to_hsl.hh: add new global variables of function
converting rgb16 to hsl.
* mln/value/hsl.hh,
* mln/value/rgb.hh: add new from_to_ overloads.
* tests/convert/Makefile.am,
* tests/convert/to_hsl.cc,
* tests/convert/to_rgb.cc: new tests. Test conversions with rgb<n> and
hsl<h,s,l> using from_to.
* mln/convert/to_rgb.hh: remove. Useless since conversions are now done
thanks to from_to.
* tests/unit_test/Makefile.am,
* tests/unit_test/mln_convert_to_rgb.cc: remove unit_test related to
to_rgb.hh.
* mln/fun/v2v/rgb_to_hsl.hh: do not include hsl.hh anymore.
2009-01-21 Nicolas Ballas <ballas@lrde.epita.fr>
 
Externalize element and nelement method in fastest images.
......@@ -271,7 +271,6 @@ mln/convert/impl/from_int_to_value.hh \
mln/convert/to_dpoint.hh \
mln/convert/to_p_array.hh \
mln/convert/from_to.hxx \
mln/convert/to_rgb.hh \
mln/convert/essential.hh \
mln/value/shell.hh \
mln/value/float01_f.hh \
......
// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory
// (LRDE)
// Copyright (C) 2007, 2008, 2009 EPITA Research and Development
// Laboratory (LRDE)
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
......@@ -49,7 +49,6 @@ namespace mln
# include <mln/convert/to_dpoint.hh>
# include <mln/convert/to_fun.hh>
# include <mln/convert/to_image.hh>
# include <mln/convert/to_rgb.hh>
# include <mln/convert/to_p_array.hh>
# include <mln/convert/to_window.hh>
......
......@@ -82,6 +82,8 @@ namespace mln
namespace value {
template <unsigned n> struct rgb;
template <typename H, typename S, typename L> class hsl_;
template <unsigned n> struct int_u;
}
// end of Forward declarations.
......@@ -149,6 +151,29 @@ namespace mln
void
from_to_(bool from, value::rgb<m>& to);
// int_u -> rgb.
template <unsigned m>
void from_to_(const value::int_u<m>& from, value::rgb<m>& to);
// hsl -> rgb8.
template <typename H, typename S, typename L>
void from_to_(const value::hsl_<H,S,L>&, value::rgb<8>& to);
// hsl -> rgb16.
template <typename H, typename S, typename L>
void from_to_(const value::hsl_<H,S,L>&, value::rgb<16>& to);
// rgb to hsl
template <typename H, typename S, typename L>
void
from_to_(const value::rgb<16>& from, value::hsl_<H,S,L>& to);
// rgb to hsl
template <typename H, typename S, typename L>
void
from_to_(const value::rgb<8>& from, value::hsl_<H,S,L>& to);
// C-array -> Image.
template <typename V, unsigned S, typename I>
......
// Copyright (C) 2008 EPITA Research and Development Laboratory
// Copyright (C) 2008, 2009 EPITA Research and Development Laboratory
// (LRDE)
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
......@@ -28,12 +29,12 @@
#ifndef MLN_CONVERT_IMPL_FROM_VALUE_TO_VALUE_HH
# define MLN_CONVERT_IMPL_FROM_VALUE_TO_VALUE_HH
/*! \file mln/convert/from_to.hh
*
* \brief General conversion procedure from a value to a value.
*
* \todo Augment code + add checks.
*/
/// \file mln/convert/from_to.hh
///
/// General conversion procedure from a value to a value.
///
/// \todo Augment code + add checks.
# include <utility>
# include <mln/core/concept/image.hh>
......@@ -43,7 +44,7 @@
# include <mln/core/site_set/p_run.hh>
# include <mln/metal/converts_to.hh>
# include <mln/convert/from_to.hxx>
namespace mln
{
......@@ -88,6 +89,16 @@ namespace mln
exact(to) = exact(from).to_equiv();
}
template <typename V, typename W>
inline
void
from_value_to_value_(const Value<V>& from, Value<W>& to)
{
// No concept based conversion. Trying to find more specific
// conversion with other from_to overloads.
convert::over_load::from_to_(exact(from), exact(to));
}
// Facades.
......
......@@ -30,17 +30,21 @@
#include <cmath>
#include <mln/value/rgb8.hh>
#include <mln/math/round.hh>
#include <mln/math/max.hh>
#include <mln/math/min.hh>
#include <mln/value/hsl.hh>
namespace mln
{
// Forward declaration
namespace value
{
template <unsigned n> struct rgb;
template <typename H, typename S, typename L> class hsl_;
typedef hsl_<float, float, float> hsl_f;
}
namespace fun
{
......@@ -73,9 +77,11 @@ namespace mln
};
typedef f_hsl_to_rgb_<value::rgb8> f_hsl_to_rgb_3x8_t;
typedef f_hsl_to_rgb_< value::rgb<8> > f_hsl_to_rgb_3x8_t;
typedef f_hsl_to_rgb_< value::rgb<16> > f_hsl_to_rgb_3x16_t;
extern f_hsl_to_rgb_3x8_t f_hsl_to_rgb_3x8;
extern f_hsl_to_rgb_3x16_t f_hsl_to_rgb_3x16;
# ifndef MLN_INCLUDE_ONLY
......@@ -85,6 +91,7 @@ namespace mln
f_rgb_to_hsl_f_t f_rgb_to_hsl_f;
f_hsl_to_rgb_3x8_t f_hsl_to_rgb_3x8;
f_hsl_to_rgb_3x16_t f_hsl_to_rgb_3x16;
/// \}
......
......@@ -25,6 +25,15 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
/// \file mln/value/hsl.hh
///
/// Color class.
///
/// \todo write a better doc.
#ifndef MLN_VALUE_HSL_HH
# define MLN_VALUE_HSL_HH
#include <mln/value/ops.hh>
#include <mln/value/concept/vectorial.hh>
......@@ -33,13 +42,45 @@
#include <mln/value/float01_8.hh>
#ifndef MLN_VALUE_HSL_HH
# define MLN_VALUE_HSL_HH
// Used in from_to
#include <mln/fun/v2v/rgb_to_hsl.hh>
namespace mln
{
// Forward declarations.
namespace value
{
template <typename H, typename S, typename L>
class hsl_;
}
namespace convert
{
namespace over_load
{
// rgb to hsl
template <typename H, typename S, typename L>
void
from_to_(const value::rgb<16>& from, value::hsl_<H,S,L>& to);
// rgb to hsl
template <typename H, typename S, typename L>
void
from_to_(const value::rgb<8>& from, value::hsl_<H,S,L>& to);
} // end of namespace mln::convert::over_load
} // end of namespace mln::convert
namespace value
{
......@@ -71,32 +112,14 @@ namespace mln
}
/// Read-only access to the hue component.
const H& hue() const
{
return this->hue_;
}
const S& sat() const
{
return this->sat_;
}
const L& lum() const
{
return this->lum_;
}
const H& hue() const;
const S& sat() const;
const L& lum() const;
/// Read-write access to the hue component.
H& hue()
{
return this->hue_;
}
S& sat()
{
return this->sat_;
}
L& lum()
{
return this->lum_;
}
H& hue();
S& sat();
L& lum();
private:
H hue_;
......@@ -108,8 +131,128 @@ namespace mln
typedef hsl_<double, double, double> hsl_d;
/// Print an hsl \p c into the output stream \p ostr.
///
/// \param[in,out] ostr An output stream.
/// \param[in] c An rgb.
///
/// \return The modified output stream \p ostr.
template <typename H, typename S, typename L>
std::ostream& operator<<(std::ostream& ostr, const hsl_<H,S,L>& c);
} // end of namespace mln::value
// More forward declarations
namespace fun
{
namespace v2v
{
template <typename T_hsl>
struct f_rgb_to_hsl_;
typedef f_rgb_to_hsl_<value::hsl_f> f_rgb_to_hsl_f_t;
extern f_rgb_to_hsl_f_t f_rgb_to_hsl_f;
}
}
# ifndef MLN_INCLUDE_ONLY
namespace value
{
template <typename H, typename S, typename L>
const H&
hsl_<H,S,L>::hue() const
{
return this->hue_;
}
template <typename H, typename S, typename L>
const S&
hsl_<H,S,L>::sat() const
{
return this->sat_;
}
template <typename H, typename S, typename L>
const L&
hsl_<H,S,L>::lum() const
{
return this->lum_;
}
template <typename H, typename S, typename L>
H&
hsl_<H,S,L>::hue()
{
return this->hue_;
}
template <typename H, typename S, typename L>
S&
hsl_<H,S,L>::sat()
{
return this->sat_;
}
template <typename H, typename S, typename L>
L&
hsl_<H,S,L>::lum()
{
return this->lum_;
}
template <typename H, typename S, typename L>
inline
std::ostream& operator<<(std::ostream& ostr, const hsl_<H,S,L>& v)
{
return ostr << '(' << debug::format(v.hue())
<< ',' << debug::format(v.sat())
<< ',' << debug::format(v.lum())
<< ')';
}
} // end of namespace mln::value
namespace convert
{
namespace over_load
{
template <typename H, typename S, typename L>
void
from_to_(const value::rgb<16>& from, value::hsl_<H,S,L>& to)
{
to = fun::v2v::f_rgb_to_hsl_f(from);
}
template <typename H, typename S, typename L>
void
from_to_(const value::rgb<8>& from, value::hsl_<H,S,L>& to)
{
to = fun::v2v::f_rgb_to_hsl_f(from);
}
} // end of namespace mln::convert::over_load
} // end of namespace mln::convert
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
#endif // ! MLN_VALUE_HSL_HH
......@@ -25,9 +25,6 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
#ifndef MLN_VALUE_RGB_HH
# define MLN_VALUE_RGB_HH
/// \file mln/value/rgb.hh
///
/// Color class for red-green-blue where every component is
......@@ -38,16 +35,42 @@
/// \todo Introduce the concept of Color, then generalize from_to_ to
/// colors.
#ifndef MLN_VALUE_RGB_HH
# define MLN_VALUE_RGB_HH
# include <mln/value/ops.hh>
# include <mln/value/concept/vectorial.hh>
# include <mln/value/int_u.hh>
# include <mln/algebra/vec.hh>
// Needed by from_to_.
# include <mln/fun/v2v/rgb_to_hsl.hh>
namespace mln
{
namespace fun
{
namespace v2v
{
template <typename T_rgb>
struct f_hsl_to_rgb_;
typedef f_hsl_to_rgb_< value::rgb<8> > f_hsl_to_rgb_3x8_t;
typedef f_hsl_to_rgb_< value::rgb<16> > f_hsl_to_rgb_3x16_t;
extern f_hsl_to_rgb_3x8_t f_hsl_to_rgb_3x8;
extern f_hsl_to_rgb_3x16_t f_hsl_to_rgb_3x16;
}
}
namespace literal
{
/// \{ Forward declarations.
......@@ -77,8 +100,11 @@ namespace mln
// Forward declaration.
namespace value {
namespace value
{
template <unsigned n> struct rgb;
template <typename H, typename S, typename L> class hsl_;
template <unsigned n> struct int_u;
}
......@@ -96,6 +122,18 @@ namespace mln
template <unsigned m>
void from_to_(bool from, value::rgb<m>& to);
// int_u -> rgb.
template <unsigned m>
void from_to_(const value::int_u<m>& from, value::rgb<m>& to);
// hsl -> rgb8.
template <typename H, typename S, typename L>
void from_to_(const value::hsl_<H,S,L>&, value::rgb<8>& to);
// hsl -> rgb16.
template <typename H, typename S, typename L>
void from_to_(const value::hsl_<H,S,L>&, value::rgb<16>& to);
} // end of namespace mln::convert::over_load
} // end of namespace mln::convert
......@@ -711,6 +749,27 @@ namespace mln
to = *black_;
}
template <unsigned m>
void
from_to_(const value::int_u<m>& from, value::rgb<m>& to)
{
to = value::rgb<m>(from, from, from);
}
template <typename H, typename S, typename L>
void
from_to_(const value::hsl_<H,S,L>& from, value::rgb<8>& to)
{
to = fun::v2v::f_hsl_to_rgb_3x8(from);
}
template <typename H, typename S, typename L>
void
from_to_(const value::hsl_<H,S,L>& from, value::rgb<16>& to)
{
to = fun::v2v::f_hsl_to_rgb_3x16(from);
}
} // end of namespace mln::convert::over_load
} // end of namespace mln::convert
......
......@@ -4,14 +4,18 @@ include $(top_srcdir)/milena/tests/tests.mk
##FIXME: re-enable all tests
check_PROGRAMS = \
to_hsl \
to_image \
to_p_array \
to_p_set \
to_rgb \
to_window
to_hsl_SOURCES = to_hsl.cc
to_image_SOURCES = to_image.cc
to_p_array_SOURCES = to_p_array.cc
to_p_set_SOURCES = to_p_set.cc
to_rgb_SOURCES = to_rgb.cc
to_window_SOURCES = to_window.cc
TESTS = $(check_PROGRAMS)
// Copyright (C) 2007 EPITA Research and Development Laboratory
// Copyright (C) 2009 EPITA Research and Development Laboratory
// (LRDE)
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
......@@ -25,66 +26,26 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
#ifndef MLN_CONVERT_TO_RGB_HH
# define MLN_CONVERT_TO_RGB_HH
/// \file tests/convert/to_hsl.cc
///
/// Tests on mln::convert::from_to_ for hsl<H,S,L>.
/*! \file mln/convert/to_rgb.hh
*
* \brief Conversions to mln::value::rgb.
*
* \todo Re-write.
*/
#include <mln/core/image/image2d.hh>
#include <mln/value/hsl.hh>
#include <mln/value/rgb8.hh>
#include <mln/convert/to.hh>
# include <mln/value/rgb.hh>
namespace mln
int main()
{
using namespace mln;
namespace convert
{
value::rgb8 c1(3,3,3);
value::hsl_f c2 = convert::to<value::hsl_f>(c1);
// mln_assertion(c2 == hsl_f(0,0,3)); //FIXME: wrong result.
using namespace value;
value::hsl_f c3(3,3,3);
c1 = convert::to<value::rgb8>(c3);
// mln_assertion(c1 == rgb8(2,4,0)); //FIXME: wrong result.
/// Convert a int_u \p val into rgb value.
template <unsigned int n>
rgb<n> to_rgb(const int_u<n>& i);
template <unsigned int n>
rgb<n>& to_rgb(rgb<n>& i);
template <unsigned int n>
const rgb<n>& to_rgb(const rgb<n>& i);
# ifndef MLN_INCLUDE_ONLY
template <unsigned int n>
inline
rgb<n> to_rgb(const int_u<n>& i)
{
rgb<n> c(i, i, i);
return c;
}
template <unsigned int n>
inline
rgb<n>& to_rgb(rgb<n>& i)
{
return i;
}
template <unsigned int n>