
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena ChangeLog: 2008-02-05 Caroline Vigouroux <vigour_c@epita.fr> Added personal folder and color files in sandbox. * sandbox/vigouroux/color.hh: New. * sandbox/vigouroux/color/color.hh: New. * sandbox/vigouroux/color/hsi.hh: New. * sandbox/vigouroux/color/hsl.hh: New. * sandbox/vigouroux/color/hsv.hh: New. * sandbox/vigouroux/color/nrgb.hh: New. * sandbox/vigouroux/color/rgb.hh: New. * sandbox/vigouroux/color/xyz.hh: New. * sandbox/vigouroux/color/yiq.hh: New. * sandbox/vigouroux/color/yuv.hh: New. * sandbox/vigouroux/color: New. * sandbox/vigouroux/convert/abstract/colorconv.hh: New. * sandbox/vigouroux/convert/abstract/conversion.hh: New. * sandbox/vigouroux/convert/abstract: New. * sandbox/vigouroux/convert/basics.hh: New. * sandbox/vigouroux/convert/bound.hh: New. * sandbox/vigouroux/convert/cast.hh: New. * sandbox/vigouroux/convert/conversion.hh: New. * sandbox/vigouroux/convert/conversion_ng_se.hh: New. * sandbox/vigouroux/convert/force.hh: New. * sandbox/vigouroux/convert/nrgbxyz.hh: New. * sandbox/vigouroux/convert/rgbhsi.hh: New. * sandbox/vigouroux/convert/rgbhsl.hh: New. * sandbox/vigouroux/convert/rgbhsv.hh: New. * sandbox/vigouroux/convert/rgbnrgb.hh: New. * sandbox/vigouroux/convert/rgbxyz.hh: New. * sandbox/vigouroux/convert/rgbyiq.hh: New. * sandbox/vigouroux/convert/rgbyuv.hh: New. * sandbox/vigouroux/convert/stretch.hh: New. * sandbox/vigouroux/convert/value_to_point.hh: New. * sandbox/vigouroux/convert: New folder. * sandbox/vigouroux: New folder. --- color.hh | 44 +++++ color/color.hh | 308 +++++++++++++++++++++++++++++++++++++++++ color/hsi.hh | 63 ++++++++ color/hsl.hh | 54 +++++++ color/hsv.hh | 55 +++++++ color/nrgb.hh | 130 +++++++++++++++++ color/rgb.hh | 58 +++++++ color/xyz.hh | 54 +++++++ color/yiq.hh | 64 ++++++++ color/yuv.hh | 63 ++++++++ convert/abstract/colorconv.hh | 68 +++++++++ convert/abstract/conversion.hh | 177 +++++++++++++++++++++++ convert/basics.hh | 38 +++++ convert/bound.hh | 66 ++++++++ convert/cast.hh | 63 ++++++++ convert/conversion.hh | 159 +++++++++++++++++++++ convert/conversion_ng_se.hh | 82 ++++++++++ convert/force.hh | 62 ++++++++ convert/nrgbxyz.hh | 181 ++++++++++++++++++++++++ convert/rgbhsi.hh | 153 ++++++++++++++++++++ convert/rgbhsl.hh | 226 ++++++++++++++++++++++++++++++ convert/rgbhsv.hh | 204 +++++++++++++++++++++++++++ convert/rgbnrgb.hh | 145 +++++++++++++++++++ convert/rgbxyz.hh | 143 +++++++++++++++++++ convert/rgbyiq.hh | 141 ++++++++++++++++++ convert/rgbyuv.hh | 139 ++++++++++++++++++ convert/stretch.hh | 217 ++++++++++++++++++++++++++++ convert/value_to_point.hh | 131 +++++++++++++++++ 28 files changed, 3288 insertions(+) Index: trunk/milena/sandbox/vigouroux/convert/rgbhsl.hh =================================================================== --- trunk/milena/sandbox/vigouroux/convert/rgbhsl.hh (revision 0) +++ trunk/milena/sandbox/vigouroux/convert/rgbhsl.hh (revision 1707) @@ -0,0 +1,226 @@ +// Copyright (C) 2001, 2002, 2003, 2004 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 59 Temple Place - Suite 330, Boston, +// MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + + +#ifndef OLENA_CONVERT_NRGBHSL_HH +# define OLENA_CONVERT_NRGBHSL_HH + +# include <oln/basics.hh> +# include <oln/convert/abstract/colorconv.hh> + +# include <ntg/basics.hh> +# include <ntg/color/nrgb.hh> +# include <ntg/color/hsl.hh> + +# include <mlc/contract.hh> + +# include <cstdlib> +# include <sstream> + +/*! \file olena/oln/convert/rgbhsl.hh +** +** REF: The formulas used here come from ``Color space conversion''; Paul +** Bourke. +*/ +namespace oln { + + using namespace ntg; + + namespace convert { + /*! Functor for conversion from RGB to HSL color space. + ** + ** \note Every conversion should go though the RGB color space. + ** + ** \code + ** #include <oln/basics2d.hh> + ** #include <oln/convert/rgbhsl.hh> + ** #include <ntg/all.hh> + ** + ** int main() + ** { + ** oln::image2d<ntg::rgb_8> lena_rgb = oln::load(IMG_IN "lena.ppm"); + ** + ** oln::image2d<ntg::hsl_8> lena_hsl = apply(oln::convert::f_rgb_to_hsl<8, 8>(), lena_rgb); + ** oln::image2d<ntg::hsl_8>::iter_type it(lena_hsl); + ** for_all(it) + ** lena_hsl[it][ntg::hsl_L] = 127; + ** + ** oln::io::save(apply(oln::convert::f_hsl_to_rgb<8, 8>(), lena_hsl), + ** IMG_OUT "oln_convert_f_rgb_to_hsl.pgm"); + ** } + ** \endcode + ** \image html lena_ppm.png + ** \image latex lena_ppm.png + ** => + ** \image html oln_convert_f_rgb_to_hsl.png + ** \image latex oln_convert_f_rgb_to_hsl.png + */ + template<unsigned inbits, unsigned outbits> + struct f_rgb_to_hsl + : public abstract::color_conversion<3, inbits, rgb_traits, + 3, outbits, hsl_traits, f_rgb_to_hsl<inbits, outbits> > + { + color<3, outbits, hsl_traits> + doit(const color<3, inbits, rgb_traits>& v) const + { + vec<3, float> in = v.to_float(); + vec<3, float> out; + + float max_in = ntg::max(in[rgb_R], std::max(in[rgb_B], in[rgb_G])); + float min_in = ntg::min(in[rgb_R], std::min(in[rgb_B], in[rgb_G])); + float diff = max_in-min_in; + + out[hsl_L] = (max_in + min_in) / 2; + if (std::abs(diff) <= FLT_EPSILON){ + out[hsl_S] = 0; + out[hsl_H] = 0; // undefined + } + else { + if (out[hsl_L] <= 0.5) + out[hsl_S] = diff / (max_in + min_in); + else + out[hsl_S] = diff / (2 - max_in - min_in); + + + float r_dist = (max_in - in[rgb_R]) / diff; + float g_dist = (max_in - in[rgb_G]) / diff; + float b_dist = (max_in - in[rgb_B]) / diff; + + if (in[rgb_R] == max_in) + out[hsl_H] = b_dist - g_dist; + else if(in[rgb_G] == max_in) + out[hsl_H] = 2 + r_dist - b_dist; + else if(in[rgb_B] == max_in) + out[hsl_H] = 4 + g_dist - r_dist; + + out[hsl_H] *= 60; + if(out[hsl_H] < 0) + out[hsl_H] += 360; + } + return out; + } + + static std::string + name() + { + std::ostringstream s; + s << "f_rgb_to_hsl<" << inbits << ", " << outbits << '>'; + s.str(); + } + }; + + /*! Conversion from RGB to HSL color space. + ** + ** \see f_rgb_to_hsl + */ + template <unsigned inbits, unsigned outbits> + color<3, inbits, hsl_traits> + rgb_to_hsl(const color<3, outbits, rgb_traits>& v) + { + f_rgb_to_hsl<inbits, outbits> f; + return f(v); + } + + namespace internal { + float + RGB(float q1, float q2, float hue) + { + if (hue >= 360) + hue -= 360; + if (hue < 0) + hue += 360; + if (hue < 60) + return q1 + (q2 - q1) * hue / 60; + else if (hue < 180) + return q2; + else if (hue < 240) + return q1 + (q2 - q1) * (240 - hue) / 60; + else + return q1; + } + } + + /*! Functor for conversion from HSL to RGB color space. + ** + ** \see f_rgb_to_hsl + */ + template<unsigned inbits, unsigned outbits> + struct f_hsl_to_rgb + : public abstract::color_conversion<3, inbits, hsl_traits, + 3, outbits, rgb_traits, f_hsl_to_rgb<inbits, outbits> > + { + color<3, outbits, rgb_traits> + doit(const color<3, inbits, hsl_traits>& v) const + { + vec<3, float> in = v.to_float(); + vec<3, float> out; + float p2; + + if(in[hsl_L] < 0.5) + p2 = in[hsl_L] * (1+in[hsl_S]); + else + p2 = in[hsl_L] + in[hsl_S] - (in[hsl_L] * in[hsl_S]); + + float p1 = 2 * in[hsl_L] - p2; + + if(in[hsl_S] == 0) + out[rgb_R] = out[rgb_G] = out[rgb_B] = in[hsl_L]; + else + { + out[rgb_R] = internal::RGB(p1, p2, in[hsl_H] + 120); + out[rgb_G] = internal::RGB(p1, p2, in[hsl_H]); + out[rgb_B] = internal::RGB(p1, p2, in[hsl_H] - 120); + } + + return out; + } + + static std::string + name() + { + std::ostringstream s; + s << "f_hsl_to_rgb<" << inbits << ", " << outbits << '>'; + s.str(); + } + }; + + /*! Conversion from HSL to RGB color space. + ** + ** \see f_rgb_to_hsl + */ + template<unsigned inbits, unsigned outbits> + color<3, outbits, rgb_traits> + hsl_to_rgb(const color<3, inbits, hsl_traits>& v) + { + f_hsl_to_rgb<inbits, outbits> f; + return f(v); + } + + } // convert +} // oln + +#endif // OLENA_CONVERT_RGBHSL_HH Index: trunk/milena/sandbox/vigouroux/convert/rgbnrgb.hh =================================================================== --- trunk/milena/sandbox/vigouroux/convert/rgbnrgb.hh (revision 0) +++ trunk/milena/sandbox/vigouroux/convert/rgbnrgb.hh (revision 1707) @@ -0,0 +1,145 @@ +// Copyright (C) 2001, 2002, 2003, 2004 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 59 Temple Place - Suite 330, Boston, +// MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + + +#ifndef OLENA_CONVERT_RGBNRGB_HH +# define OLENA_CONVERT_RGBNRGB_HH + +# include <oln/convert/abstract/colorconv.hh> + +# include <ntg/color/rgb.hh> +# include <ntg/color/nrgb.hh> +# include <ntg/basics.hh> + +# include <sstream> + +/*! \file olena/oln/convert/rgbnrgb.hh +** +** REF: The formulas used here come from ``Digital Image Processing +** Algorithms and Applications'', I. Pitas; Wiley-Interscience. +*/ + +namespace oln { + + using namespace ntg; + + namespace convert { + + /*! Functor for conversion from RGB to N-RGB. + ** + ** \see f_rgb_to_hsl + */ + template<unsigned inbits, unsigned outbits> + struct f_rgb_to_nrgb + : public abstract::color_conversion<3, inbits, rgb_traits, + 3, outbits, nrgb_traits, f_rgb_to_nrgb<inbits, outbits> > + { + color<3, outbits, nrgb_traits> + doit(const color<3, inbits, rgb_traits>& v) const + { + vec<3, float> in = v.to_float(); + vec<3, float> out; + out[nrgb_R] = + + 0.8417270*in[rgb_R] + 0.1560987*in[rgb_G] + 0.0906747*in[rgb_B]; + out[nrgb_G] = + - 0.1290152*in[rgb_R] + 1.3189264*in[rgb_G] - 0.2031832*in[rgb_B]; + out[nrgb_B] = + + 0.0074943*in[rgb_R] - 0.0688480*in[rgb_G] + 0.8972327*in[rgb_B]; + return out; + } + + static std::string + name() + { + std::ostringstream s; + s << "f_rgb_to_nrgb<" << inbits << ", " << outbits << '>'; + s.str(); + } + }; + + /*! Conversion from RGB to N-RGB. + ** + ** \see f_rgb_to_hsl + */ + template <unsigned inbits, unsigned outbits> + color<3, outbits, nrgb_traits> + rgb_to_nrgb(const color<3, inbits, rgb_traits>& v) + { + f_rgb_to_nrgb<inbits, outbits> f; + + return f(v); + } + + /*! Functor for conversion from N-RGB to RGB. + ** + ** \see f_rgb_to_hsl + */ + template <unsigned inbits, unsigned outbits> + struct f_nrgb_to_rgb + : public abstract::color_conversion<3, inbits, nrgb_traits, + 3, outbits, rgb_traits, f_nrgb_to_rgb<inbits, outbits> > + { + color<3, outbits, rgb_traits> + doit(const color<3, inbits, nrgb_traits>& v) const + { + vec<3, float> in = v.to_float(); + vec<3, float> out; + out[rgb_R] = + + 1.167 * in[nrgb_R] - 0.146 * in[nrgb_G] - 0.151 * in[nrgb_B]; + out[rgb_G] = + + 0.114 * in[nrgb_R] + 0.753 * in[nrgb_G] + 0.159 * in[nrgb_B]; + out[rgb_B] = + - 0.001 * in[nrgb_R] + 0.059 * in[nrgb_G] + 1.128 * in[nrgb_B]; + return out; + } + + static std::string + name() + { + std::ostringstream s; + s << "f_nrgb_to_rgb<" << inbits << ", " << outbits << '>'; + s.str(); + } + }; + + /*! Conversion from N-RGB to RGB. + ** + ** \see f_rgb_to_hsl + */ + template <unsigned inbits, unsigned outbits> + color<3, outbits, rgb_traits> + nrgb_to_rgb(const color<3, inbits, nrgb_traits>& v) + { + f_nrgb_to_rgb<inbits, outbits> f; + + return f(v); + } + + } // convert +} // oln + +#endif // OLENA_CONVERT_RGBNRGB_HH Index: trunk/milena/sandbox/vigouroux/convert/conversion.hh =================================================================== --- trunk/milena/sandbox/vigouroux/convert/conversion.hh (revision 0) +++ trunk/milena/sandbox/vigouroux/convert/conversion.hh (revision 1707) @@ -0,0 +1,159 @@ +// Copyright (C) 2001, 2002, 2003, 2004 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 59 Temple Place - Suite 330, Boston, +// MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef OLENA_CONVERT_CONVERSION_HH +# define OLENA_CONVERT_CONVERSION_HH + +# include <mlc/type.hh> +# include <oln/core/image.hh> +# include <oln/core/compose.hh> +# include <ntg/utils/debug.hh> +# include <oln/convert/abstract/conversion.hh> +# include <functional> + +namespace oln { + /*! + ** \brief Conversion implementation (for example cast, color, or + ** neighborhood to window). + */ + namespace convert { + + /*! Trait that returns the output of a conversion. + ** + ** convoutput queries the output type of conversion ConvType for + ** an input of type InputType. This comes handy when computing + ** the return type of a function which takes a conversion function + ** in argument. + ** + ** \note convoutput is exported in the namespace oln for convenience. + */ + template<class ConvType, class Base, class InputType> + struct convoutput + { + typedef typename abstract::conversion<ConvType, Base>::template output<InputType>::ret ret; + }; + + /// \brief Internal purpose only. + namespace internal { + /*! Compose a conversion C and an adaptable unary function UF, + ** producing an adaptable unary function. + */ + template <class C, class UF> + struct compconv1_ : + public std::unary_function <typename UF::argument_type, + typename C::template output<typename UF::argument_type>::ret> + { + typedef compconv1_ self_type; + + typename self_type::result_type + operator()(typename self_type::argument_type arg) const + { + return conv_(func_(arg)); + } + + compconv1_(const C& conv, const UF& func) + : conv_(conv), func_(func) + {} + private: + const C conv_; + const UF func_; + }; + + /*! Compose a conversion C and an adaptable binary function BF, + ** producing an adaptable binary function. + */ + template <class C, class BF> + struct compconv2_ : + public std::binary_function <typename BF::first_argument_type, + typename BF::second_argument_type, + typename C::template output<typename BF::result_type>::ret> + { + typedef compconv2_ self_type; + + typename self_type::result_type + operator()(typename self_type::first_argument_type arg1, + typename self_type::second_argument_type arg2) const + { + return conv_(func_(arg1, arg2)); + } + + compconv2_(const C &conv, const BF &func) + : conv_(conv), func_(func) + {} + private: + const C conv_; + const BF func_; + }; + + } // end of internal + + /*! Friendly procedure that build an internal::compconv1_ with + ** type deduction. + */ + template <class C, class B, class UF> + internal::compconv1_<C, UF> + compconv1(const abstract::conversion<C, B>& conv, const UF &func) + { + return internal::compconv1_<C, UF>(conv.exact(), func); + } + + /*! Likewise for compconv2_. */ + template <class C, class B, class BF> + internal::compconv2_<C, BF> + compconv2(const abstract::conversion<C, B>& conv, const BF &func) + { + return internal::compconv2_<C, BF>(conv.exact(), func); + } + + + /*! Apply function that retrive the result type within the conversion class. + ** + ** The core oln::apply function, cannot apply all conversion function, + ** because they do not all define result_type. So we define another + ** apply function here, to apply conversions. + */ + template<class C, class B, class I> inline + typename mute<I, typename convoutput<C, B, oln_value_type(I)>::ret>::ret + apply(const abstract::conversion<C, B>& conv, const oln::abstract::image<I>& input) + { + /* CONV can now be wrapped as an Adaptable Unary Function + because we know the input type. Composing CONV with the + identity for the input type will cause such wrapping to + happen. */ + return apply(compconv1(conv, f_identity<oln_value_type(I)>()), input); + } + + } // convert + + /* Export conversion and convouput into oln:: to simplify the + writing of processings. */ + using convert::convoutput; + +} // oln + + +#endif // OLENA_CONVERT_CONVERSION_HH Index: trunk/milena/sandbox/vigouroux/convert/rgbxyz.hh =================================================================== --- trunk/milena/sandbox/vigouroux/convert/rgbxyz.hh (revision 0) +++ trunk/milena/sandbox/vigouroux/convert/rgbxyz.hh (revision 1707) @@ -0,0 +1,143 @@ +// Copyright (C) 2001, 2002, 2003, 2004 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 59 Temple Place - Suite 330, Boston, +// MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + + +#ifndef OLENA_CONVERT_RGBXYZ_HH +# define OLENA_CONVERT_RGBXYZ_HH + +# include <oln/convert/abstract/colorconv.hh> + +# include <ntg/color/rgb.hh> +# include <ntg/color/xyz.hh> +# include <ntg/basics.hh> + +# include <sstream> + +/*! \file olena/oln/convert/rgbxyz.hh +** +** REF: The formulas used here come from ``Digital Image Processing +** Algorithms and Applications'', I. Pitas; Wiley-Interscience. +*/ + +namespace oln { + + using namespace ntg; + + namespace convert { + + /* Functor for conversion from RGB to XYZ. + ** + ** \see f_rgb_to_hsl + */ + template <unsigned inbits, unsigned outbits> + struct f_rgb_to_xyz + : public abstract::color_conversion<3, inbits, rgb_traits, + 3, outbits, xyz_traits, f_rgb_to_xyz <inbits, outbits> > + { + color<3, outbits, xyz_traits> + doit(const color<3, inbits, rgb_traits>& v) const + { + vec<3, float> in = v.to_float(); + vec<3, float> out; + out[xyz_X] = 0.490 * in[rgb_R] + 0.310 * in[rgb_G] + 0.200 * in[rgb_B]; + out[xyz_Y] = 0.177 * in[rgb_R] + 0.812 * in[rgb_G] + 0.011 * in[rgb_B]; + out[xyz_Z] = 0.010 * in[rgb_G] + 0.990 * in[rgb_B]; + return out; + } + + static std::string + name() + { + std::ostringstream s; + s << "f_rgb_to_xyz<" << inbits << ", " << outbits << '>'; + s.str(); + } + }; + + + /* Conversion from RGB to XYZ. + ** + ** \see f_rgb_to_hsl + */ + template <unsigned inbits, unsigned outbits> + color<3, outbits, xyz_traits> + rgb_to_xyz(const color<3, inbits, rgb_traits>& v) + { + f_rgb_to_xyz<inbits, outbits> f; + + return f(v); + } + + /* Functor for conversion from XYZ to RGB + ** + ** \see f_rgb_to_hsl + */ + template <unsigned inbits, unsigned outbits> + struct f_xyz_to_rgb + : public abstract::color_conversion<3, inbits, xyz_traits, + 3, outbits, rgb_traits, f_xyz_to_rgb <inbits, outbits> > + { + color<3, outbits, rgb_traits> + doit(const color<3, inbits, xyz_traits>& v) const + { + vec<3, float> in = v.to_float(); + vec<3, float> out; + out[rgb_R] = + 2.365 * in[xyz_X] - 0.896 * in[xyz_Y] - 0.468 * in[xyz_Z]; + out[rgb_G] = + - 0.515 * in[xyz_X] + 1.425 * in[xyz_Y] + 0.089 * in[xyz_Z]; + out[rgb_B] = + 0.005 * in[xyz_X] - 0.014 * in[xyz_Y] + 1.01 * in[xyz_Z]; + return out; + } + + static std::string + name() + { + std::ostringstream s; + s << "f_xyz_to_rgb<" << inbits << ", " << outbits << '>'; + s.str(); + } + }; + + /* Functor for conversion from RGB to XYZ. + ** + ** \see f_rgb_to_hsl + */ + template <unsigned inbits, unsigned outbits> + color<3, outbits, rgb_traits> + xyz_to_rgb(const color<3, outbits, xyz_traits>& v) + { + f_xyz_to_rgb<inbits, outbits> f; + + return f(v); + } + + } // convert +} // oln + +#endif // OLENA_CONVERT_RGBXYZ_HH Index: trunk/milena/sandbox/vigouroux/convert/value_to_point.hh =================================================================== --- trunk/milena/sandbox/vigouroux/convert/value_to_point.hh (revision 0) +++ trunk/milena/sandbox/vigouroux/convert/value_to_point.hh (revision 1707) @@ -0,0 +1,131 @@ +// Copyright (C) 2004 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 59 Temple Place - Suite 330, Boston, +// MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef OLENA_VALUE_TO_POINT +# define OLENA_VALUE_TO_POINT +# include <oln/core/point1d.hh> +# include <oln/core/point3d.hh> +# include <ntg/int.hh> +# include <ntg/color/color.hh> +# include <oln/convert/conversion.hh> +namespace oln { + + namespace convert { + /*! Convert a value of pixel to a point. + ** + ** For example, transform an RGB color to a 3D point + ** (ntg::rgb_8 => oln::point3d). + ** This function is useful to build the histogram. \n + ** Example: + ** \verbatim + ** f(oln::convert::value_to_point<ntg::rgb_8>()(ntg::rgb_8(1,6,64))); + ** // is equivalent to: + ** f(oln::point3d(1, 6, 64)); + ** \endverbatim + */ + template <typename Argument_type, + class Exact = mlc::final> + struct value_to_point: + public abstract::conversion_from_type_to_type + <Argument_type, + point1d, + typename mlc::exact_vt<value_to_point<Argument_type, + Exact>, + Exact>::ret> + { + private: + /// By default a scalar is expected. If the type is a vector, a + /// specialization should be written. + typedef typename ntg_is_a(Argument_type, ntg::non_vectorial)::ensure_type ensure_type; + public: + /// By default return a point1d. + typedef point1d result_type; + typedef Argument_type argument_type; + + /// Convert a binary to a point. + template <typename O, typename I> + struct doit_binary + { + static + O + doit(const I &input) + { + return input ? O(1) : O(0); + } + }; + /// Convert a non vectorial to a point. + template <typename O, typename I> + struct doit_not_binary + { + static + O + doit(const I &input) + { + return O(input - ntg_min_val(I)); + } + }; + + result_type + doit(const argument_type &input) const + { + typedef typename mlc::if_<ntg_is_a(argument_type, ntg::binary)::ret, + doit_binary<result_type, argument_type>, + doit_not_binary<result_type, argument_type> >::ret doit_type; + return doit_type::doit(input); + } + }; + + /*! Specialization for color of three dimension. + ** + ** \todo Could be generalized to n dimensions if there were a trait that + ** give a pointkd for a given dimension k. + */ + template <unsigned Qbits, template <unsigned> class S, class Exact> + struct value_to_point<ntg::color<3, Qbits, S>, Exact>: + public abstract::conversion_from_type_to_type + <typename ntg::color<3, Qbits, S>, + point3d, + typename mlc::exact_vt<value_to_point<typename ntg::color<3, Qbits, S>, + Exact>, + Exact>::ret> + { + public: + typedef point3d result_type; + typedef typename ntg::color<3, Qbits, S> argument_type; + + result_type + doit(const argument_type &input) const + { + result_type r; + for (unsigned i = 0; i < 3; ++i) + r.nth(i) = oln::coord(input[i]); + return r; + } + }; + } +} +#endif Index: trunk/milena/sandbox/vigouroux/convert/cast.hh =================================================================== --- trunk/milena/sandbox/vigouroux/convert/cast.hh (revision 0) +++ trunk/milena/sandbox/vigouroux/convert/cast.hh (revision 1707) @@ -0,0 +1,63 @@ +// Copyright (C) 2001, 2002, 2003, 2004 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 59 Temple Place - Suite 330, Boston, +// MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef OLENA_CONVERT_CAST_HH +# define OLENA_CONVERT_CAST_HH + +# include <oln/convert/abstract/conversion.hh> +# include <ntg/utils/cast.hh> + +namespace oln { + namespace convert { + + /*! Cast to an output. + */ + template<class Output, class Exact = mlc::final> + struct cast : public abstract::conversion_to_type< Output, typename mlc::exact_vt<cast<Output, Exact>, Exact>::ret > + { + template< class Input > + Output + doit(const Input& v) const + { + return v; + } + + static std::string + name() + { + // FIXME: ntg_name(Exact) will not work for mlc::final ! + return std::string("cast<") + + ntg_name(Output) + ", " + + "FIXME: ntg_name(Exact)" + ">"; + } + + }; + + } // convert +} // oln + +#endif // OLENA_CONVERT_CAST_HH Index: trunk/milena/sandbox/vigouroux/convert/rgbhsv.hh =================================================================== --- trunk/milena/sandbox/vigouroux/convert/rgbhsv.hh (revision 0) +++ trunk/milena/sandbox/vigouroux/convert/rgbhsv.hh (revision 1707) @@ -0,0 +1,204 @@ +// Copyright (C) 2001, 2002, 2003, 2004 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 59 Temple Place - Suite 330, Boston, +// MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + + +#ifndef OLENA_CONVERT_RGBHSV_HH +# define OLENA_CONVERT_RGBHSV_HH + +# include <oln/basics.hh> +# include <oln/convert/abstract/colorconv.hh> + +# include <ntg/basics.hh> +# include <ntg/color/rgb.hh> +# include <ntg/color/hsv.hh> + +# include <mlc/contract.hh> + +# include <sstream> + +/*! \file olena/oln/convert/rgbhsv.hh +** REF: The formulas used here come from ``Color Conversion Algorithms'' +*/ + +namespace oln { + + using namespace ntg; + + namespace convert { + + /*! Functor for conversion from RGB to HSV. + ** + ** \see f_rgb_to_hsl + */ + template<unsigned inbits, unsigned outbits> + struct f_rgb_to_hsv + : public abstract::color_conversion<3, inbits, rgb_traits, + 3, outbits, hsv_traits, f_rgb_to_hsv<inbits, outbits> > + { + color<3, outbits, hsv_traits> + doit(const color<3, inbits, rgb_traits>& v) const + { + vec<3, float> in = v.to_float(); + vec<3, float> out; + float max_in = std::max(in[rgb_R], std::max(in[rgb_B], in[rgb_G])); + float min_in = std::min(in[rgb_R], std::min(in[rgb_B], in[rgb_G])); + float delta = max_in - min_in; + + + out[hsv_V] = max_in; + + if (max_in != 0) + out[hsv_S] = delta / max_in; + else + out[hsv_S] = 0; + + if (out[hsv_S] == 0) + out[hsv_H] = -1; // undefined + else { + if (in[rgb_R] == max_in) + out[hsv_H] = (in[rgb_G] - in[rgb_B]) / delta; + else if (in[rgb_G] == max_in) + out[hsv_H] = 2 + (in[rgb_B] - in[rgb_R]) / delta; + else + out[hsv_H] = 4 + (in[rgb_R] - in[rgb_G]) / delta; + out[hsv_H] *= 60; + if (out[hsv_H] < 0) + out[hsv_H] += 360; + } + + return out; + } + + static std::string + name() + { + std::ostringstream s; + s << "f_rgb_to_hsv<" << inbits << ", " << outbits << '>'; + s.str(); + } + }; + + /*! Conversion from RGB to HSV. + ** + ** \see f_rgb_to_hsl + */ + template <unsigned inbits, unsigned outbits> + color<3, outbits, hsv_traits> + rgb_to_hsv(const color<3, inbits, rgb_traits>& v) + { + f_rgb_to_hsv<inbits, outbits> f; + return f(v); + } + + /*! Functor conversion from HSV to RGB. + ** + ** \see f_rgb_to_hsl + */ + template<unsigned inbits, unsigned outbits> + struct f_hsv_to_rgb + : public abstract::color_conversion<3, inbits, hsv_traits, + 3, outbits, rgb_traits, f_hsv_to_rgb<inbits, outbits> > + { + color<3, outbits, rgb_traits> + doit(const color<3, inbits, hsv_traits>& v) const + { + vec<3, float> in = v.to_float(); + vec<3, float> out; + + if(in[hsv_S] == 0) + out[rgb_G] = out[rgb_B] = out[rgb_R] = in[hsv_V]; + else + { + in[hsv_H] /= 60; + int i = (int)floor (in[hsv_H]); + float f = in[hsv_H] - i; + float p = in[hsv_V] * (1 - in[hsv_S]); + float q = in[hsv_V] * (1 - in[hsv_S] * f); + float t = in[hsv_V] * (1 - in[hsv_S] * (1 - f)); + + switch (i){ + case 0: + case 6: + out[rgb_R] = in[hsv_V]; + out[rgb_G] = t; + out[rgb_B] = p; + break; + case 1: + out[rgb_R] = q; + out[rgb_G] = in[hsv_V]; + out[rgb_B] = p; + break; + case 2: + out[rgb_R] = p; + out[rgb_G] = in[hsv_V]; + out[rgb_B] = t; + break; + case 3: + out[rgb_R] = p; + out[rgb_G] = q; + out[rgb_B] = in[hsv_V]; + break; + case 4: + out[rgb_R] = t; + out[rgb_G] = p; + out[rgb_B] = in[hsv_V]; + break; + default: + out[rgb_R] = in[hsv_V]; + out[rgb_G] = p; + out[rgb_B] = q; + break; + } + } + return out; + } + + static std::string + name() + { + std::ostringstream s; + s << "f_hsv_to_rgb<" << inbits << ", " << outbits << '>'; + s.str(); + } + }; + + /*! Conversion from HSV to RGB. + ** + ** \see f_rgb_to_hsl + */ + template <unsigned inbits, unsigned outbits> + color<3, outbits, rgb_traits> + hsv_to_rgb(const color<3, inbits, hsv_traits>& v) + { + f_hsv_to_rgb<inbits, outbits> f; + return f(v); + } + + } // convert +} // oln + +#endif // OLENA_CONVERT_RGBHSV_HH Index: trunk/milena/sandbox/vigouroux/convert/rgbyiq.hh =================================================================== --- trunk/milena/sandbox/vigouroux/convert/rgbyiq.hh (revision 0) +++ trunk/milena/sandbox/vigouroux/convert/rgbyiq.hh (revision 1707) @@ -0,0 +1,141 @@ +// Copyright (C) 2001, 2002, 2003, 2004 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 59 Temple Place - Suite 330, Boston, +// MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + + +#ifndef OLENA_CONVERT_RGBYIQ_HH +# define OLENA_CONVERT_RGBYIQ_HH + +# include <oln/convert/abstract/colorconv.hh> + +# include <ntg/color/rgb.hh> +# include <ntg/color/yiq.hh> +# include <ntg/basics.hh> + +# include <sstream> + +/*! \file olena/oln/convert/rgbyiq.hh +** +** REF: The formulas used here come from ``Digital Image Processing +** Algorithms and Applications'', I. Pitas; Wiley-Interscience. +*/ +namespace oln { + + using namespace ntg; + + namespace convert { + + /* Functor for conversion from RGB to YIQ. + ** + ** \see f_rgb_to_hsl + */ + template<unsigned inbits, unsigned outbits> + struct f_rgb_to_yiq + : public abstract::color_conversion<3, inbits, rgb_traits, + 3, outbits, yiq_traits, f_rgb_to_yiq<inbits, outbits> > + { + color<3, inbits, yiq_traits> + doit(const color<3, outbits, rgb_traits>& v) const + { + vec<3, float> in = v.to_float(); + vec<3, float> out; + out[yiq_Y] = + 0.1768 * in[rgb_R] + 0.8130 * in[rgb_G] + 0.0101 * in[rgb_B]; + out[yiq_I] = + 0.5346 * in[rgb_R] - 0.2461 * in[rgb_G] - 0.1791 * in[rgb_B]; + out[yiq_Q] = + 0.2474 * in[rgb_R] - 0.6783 * in[rgb_G] + 0.4053 * in[rgb_B]; + return out; + } + + static std::string + name() + { + std::ostringstream s; + s << "f_rgb_to_yiq<" << inbits << ", " << outbits << '>'; + s.str(); + } + }; + + /* Conversion from RGB to YIQ. + ** + ** \see f_rgb_to_hsl + */ + template <unsigned inbits, unsigned outbits> + color<3, outbits, yiq_traits> + rgb_to_yiq(const color<3, inbits, rgb_traits>& v) + { + f_rgb_to_yiq<inbits, outbits> f; + + return f(v); + } + + /* Functor for conversion from YIQ to RGB. + ** + ** \see f_rgb_to_hsl + */ + template<unsigned inbits, unsigned outbits> + struct f_yiq_to_rgb + : public abstract::color_conversion<3, inbits, yiq_traits, + 3, outbits, rgb_traits, f_yiq_to_rgb<inbits, outbits> > + { + color<3, inbits, rgb_traits> + doit(const color<3, outbits, yiq_traits>& v) const + { + vec<3, float> in = v.to_float(); + vec<3, float> out; + out[rgb_R] = 0.87 * in[yiq_Y] + 1.3223 * in[yiq_I] + 0.5628 * in[yiq_Q]; + out[rgb_G] = 1.026 * in[yiq_Y] - 0.2718 * in[yiq_I] - 0.1458 * in[yiq_Q]; + out[rgb_B] = 1.186 * in[yiq_Y] - 1.2620 * in[yiq_I] + 1.8795 * in[yiq_Q]; + return out; + } + + static std::string + name() + { + std::ostringstream s; + s << "f_yiq_to_rgb<" << inbits << ", " << outbits << '>'; + s.str(); + } + }; + + /* Conversion from YIQ to RGB. + ** + ** \see f_rgb_to_hsl + */ + template <unsigned inbits, unsigned outbits> + color<3, outbits, rgb_traits> + yiq_to_rgb(const color<3, inbits, yiq_traits>& v) + { + f_yiq_to_rgb<inbits, outbits> f; + + return f(v); + } + + } // convert +} // oln + +#endif // OLENA_CONVERT_RGBYIQ_HH Index: trunk/milena/sandbox/vigouroux/convert/force.hh =================================================================== --- trunk/milena/sandbox/vigouroux/convert/force.hh (revision 0) +++ trunk/milena/sandbox/vigouroux/convert/force.hh (revision 1707) @@ -0,0 +1,62 @@ +// Copyright (C) 2001, 2002, 2003, 2004 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 59 Temple Place - Suite 330, Boston, +// MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + + +#ifndef OLENA_CONVERT_FORCE_HH +# define OLENA_CONVERT_FORCE_HH + +# include <oln/convert/abstract/conversion.hh> +# include <ntg/utils/cast.hh> + +namespace oln { + namespace convert { + + /*! Like cast::force, but as a conversion functor. */ + template<class Output, class Exact = mlc::final> + struct force : public abstract::conversion_to_type< Output, typename mlc::exact_vt<force<Output, Exact>, Exact>::ret > + { + template< class Input > + Output + doit(const Input& v) const + { + return ntg::cast::force<Output>(v); + } + + static std::string + name() + { + // FIXME: Exact is not an integre type ! + return std::string("force<") + + ntg_name(Output) + ", " + + Exact::name() + ">"; + } + }; + + } // convert +} // oln + +#endif // OLENA_CONVERT_FORCE_HH Index: trunk/milena/sandbox/vigouroux/convert/conversion_ng_se.hh =================================================================== --- trunk/milena/sandbox/vigouroux/convert/conversion_ng_se.hh (revision 0) +++ trunk/milena/sandbox/vigouroux/convert/conversion_ng_se.hh (revision 1707) @@ -0,0 +1,82 @@ +// Copyright (C) 2002, 2004 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 59 Temple Place - Suite 330, Boston, +// MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef OLENA_CONVERT_CONVERSION_NG_SE_HH +# define OLENA_CONVERT_CONVERSION_NG_SE_HH + +# include <oln/basics.hh> + +// because of the internal function in this file +# include <oln/basics1d.hh> +# include <oln/basics2d.hh> +# include <oln/basics3d.hh> +# include <oln/core/neighborhood1d.hh> +# include <oln/core/neighborhood2d.hh> +# include <oln/core/neighborhood3d.hh> + +namespace oln { + namespace convert { + /*! Convert a neighborhood to a window. + ** + ** \see ng_to_cse + */ + template<class N> + typename oln::abstract::neighborhood<N>::win_type + ng_to_se(const oln::abstract::neighborhood<N>& Ng) + { + typename oln::abstract::neighborhood<N>::win_type output; + oln_iter_type(N) p(Ng); + for_all(p) + output.add(p); + return output; + } + + /*! Convert a neighborhood to a window and add the center. + ** + ** \see ng_to_cs + */ + template<class N> + typename oln::abstract::neighborhood<N>::win_type + ng_to_cse(const oln::abstract::neighborhood<N>& Ng) + { + typename oln::abstract::neighborhood<N>::win_type output; + oln_iter_type(N) p(Ng); + for_all(p) + output.add(p); + oln_dpoint_type(N) zero; + for (unsigned size = 0; size < N::dim; ++size) + zero.nth(size) = 0; + output.add(zero); + return output; + } + + + } // convert +} // oln + + +#endif // OLENA_CONVERT_CONVERSION_NG_SE_HH Index: trunk/milena/sandbox/vigouroux/convert/nrgbxyz.hh =================================================================== --- trunk/milena/sandbox/vigouroux/convert/nrgbxyz.hh (revision 0) +++ trunk/milena/sandbox/vigouroux/convert/nrgbxyz.hh (revision 1707) @@ -0,0 +1,181 @@ +// Copyright (C) 2001, 2002, 2003, 2004 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 59 Temple Place - Suite 330, Boston, +// MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + + +#ifndef OLENA_CONVERT_NRGBXYZ_HH +# define OLENA_CONVERT_NRGBXYZ_HH + +# include <oln/convert/abstract/colorconv.hh> + +# include <ntg/color/nrgb.hh> +# include <ntg/color/xyz.hh> +# include <ntg/basics.hh> + +# include <sstream> + +/*! \file olena/oln/convert/nrgbxyz.hh +** +** REF: The formulas used here come from ``Digital Image Processing +** Algorithms and Applications'', I. Pitas; Wiley-Interscience. +*/ + +namespace oln { + + // FIXME: should it be removed? + using namespace ntg; + + namespace convert { + + /*! Functor for conversion from N-RGB to XYZ color space. + ** + ** \deprecated A composition should be performed with nrgb->rgb and rgb->xyz. It has + ** not been replaced within the function because a double conversion 'reduces' + ** the color space. See the following example: + ** \code + ** // Obsolete: + ** // + ** // #include <oln/convert/nrgbxyz.hh> + ** // #include <ntg/all.hh> + ** // int main(int argc, char **argv) + ** // { + ** // ntg::nrgb_8 in(100, 60, 64); + ** // ntg::xyz_8 out = oln::convert::f_nrgb_to_xyz<8, 8>()(in); + ** // } + ** // + ** // Should be replaced by: + ** // + ** #include <oln/convert/rgbxyz.hh> + ** #include <oln/convert/rgbnrgb.hh> + ** #include <ntg/all.hh> + ** int main() + ** { + ** ntg::nrgb_8 in(100, 60, 64); + ** ntg::xyz_8 out = oln::convert::f_rgb_to_xyz<8, 8>() + ** (oln::convert::f_nrgb_to_rgb<8, 8>()(in)); + ** } + ** \endcode + */ + template <unsigned inbits, unsigned outbits> + struct f_nrgb_to_xyz + : public abstract::color_conversion<3, inbits, nrgb_traits, + 3, outbits, xyz_traits, f_nrgb_to_xyz<inbits, outbits> > + { + color<3, outbits, xyz_traits> + doit(const color<3, inbits, nrgb_traits>& v) const + { + vec<3, float> in = v.to_float(); + vec<3, float> out; + out[xyz_X] = + 0.606734 * in[nrgb_R] + 0.173564 * in[nrgb_G] + 0.200112 * in[nrgb_B]; + + out[xyz_Y] = + 0.298839 * in[nrgb_R] + 0.586811 * in[nrgb_G] + 0.114350 * in[nrgb_B]; + + out[xyz_Z] = + 0.0661196 * in[nrgb_G] + 1.11491 * in[nrgb_B]; + + return out; + } + + static std::string + name() + { + std::ostringstream s; + s << "f_nrgb_to_xyz<" << inbits << ", " << outbits << '>'; + s.str(); + } + }; + + /*! Conversion from N-RGB to XYZ color space. + ** + ** \deprecated A composition should be performed with nrgb->rgb and rgb->xyz. + ** + ** \see f_nrgb_to_xyz for more information. + */ + template <unsigned inbits, unsigned outbits> + color<3, outbits, xyz_traits> + nrgb_to_xyz(const color<3, inbits, nrgb_traits>& v) + { + f_nrgb_to_xyz<inbits, outbits> f; + + return f(v); + } + + /*! Functor for conversion from XYZ to N-RGB color space. + ** + ** \deprecated A composition should be performed with xyz->rgb and rgb->nrgb. + ** + ** \see f_nrgb_to_xyz for more information. + */ + template<unsigned inbits, unsigned outbits> + struct f_xyz_to_nrgb + : public abstract::color_conversion<3, inbits, xyz_traits, + 3, outbits, nrgb_traits, f_xyz_to_nrgb<inbits, outbits> > + { + color<3, outbits, nrgb_traits> + doit(const color<3, inbits, xyz_traits>& v) const + { + vec<3, float> in = v.to_float(); + vec<3, float> out; + out[nrgb_R] = + 1.91049 * in[xyz_X] - 0.532592 * in[xyz_Y] - 0.288284 * in[xyz_Z]; + out[nrgb_G] = + - 0.984310 * in[xyz_X] + 1.99845 * in[xyz_Y] - 0.0282980 * in[xyz_Z]; + out[nrgb_B] = + 0.0583744 * in[xyz_X] - 0.118518 * in[xyz_Y] + 0.898611 * in[xyz_Z]; + return out; + } + + static std::string + name() + { + std::ostringstream s; + s << "f_xyz_to_nrgb<" << inbits << ", " << outbits << '>'; + s.str(); + } + }; + + + /*! Conversion from XYZ to N-RGB color space. + ** + ** \deprecated a composition should be performed with xyz->rgb and rgb->nrgb. + ** + ** \see f_nrgb_to_xyz for more information. + */ + template <unsigned inbits, unsigned outbits> + color<3, outbits, nrgb_traits> + xyz_to_nrgb(const color<3, inbits, xyz_traits>& v) + { + f_xyz_to_nrgb<inbits, outbits> f; + + return f(v); + } + + } // convert +} // oln + +#endif // OLENA_CONVERT_NRGBXYZ_HH Index: trunk/milena/sandbox/vigouroux/convert/basics.hh =================================================================== --- trunk/milena/sandbox/vigouroux/convert/basics.hh (revision 0) +++ trunk/milena/sandbox/vigouroux/convert/basics.hh (revision 1707) @@ -0,0 +1,38 @@ +// Copyright (C) 2001, 2002, 2003, 2004 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 59 Temple Place - Suite 330, Boston, +// MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef OLENA_CONVERT_BASICS_HH +# define OLENA_CONVERT_BASICS_HH + +# include <oln/convert/abstract/conversion.hh> +# include <oln/convert/conversion.hh> +# include <oln/convert/cast.hh> +# include <oln/convert/force.hh> +# include <oln/convert/bound.hh> +# include <oln/convert/stretch.hh> + +#endif // OLENA_CONVERT_BASICS_HH Index: trunk/milena/sandbox/vigouroux/convert/abstract/colorconv.hh =================================================================== --- trunk/milena/sandbox/vigouroux/convert/abstract/colorconv.hh (revision 0) +++ trunk/milena/sandbox/vigouroux/convert/abstract/colorconv.hh (revision 1707) @@ -0,0 +1,68 @@ +// Copyright (C) 2001, 2002, 2003, 2004 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 59 Temple Place - Suite 330, Boston, +// MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef OLENA_CONVERT_ABSTRACT_COLORCONV_HH +# define OLENA_CONVERT_ABSTRACT_COLORCONV_HH + +# include <ntg/color/color.hh> +# include <oln/convert/abstract/conversion.hh> + +namespace oln { + + namespace convert { + + namespace abstract { + + /*! Base class for color conversion. + ** + ** \param icomps Number of components in the input. + ** \param iqbits Number of bits per components in the input. + ** \param icolor Input color. + ** \param ocomps Number of components in the output. + ** \param oqbits Number of bits per components in the output. + ** \param ocolor Output color. + ** \param Exact Exact class. + */ + template< unsigned icomps, + unsigned iqbits, + template<unsigned> class icolor, + unsigned ocomps, + unsigned oqbits, + template<unsigned> class ocolor, + class Exact = mlc::final > + struct color_conversion : + public abstract::conversion_from_type_to_type< ntg::color<icomps, iqbits, icolor>, + ntg::color<ocomps, oqbits, ocolor>, + typename mlc::exact_vt<color_conversion<icomps, iqbits, icolor, ocomps, oqbits, ocolor, Exact>, Exact>::ret > + { + }; + } + } // convert +} // oln + + +#endif // OLENA_CONVERT_ABSTRACT_COLORCONV_HH Index: trunk/milena/sandbox/vigouroux/convert/abstract/conversion.hh =================================================================== --- trunk/milena/sandbox/vigouroux/convert/abstract/conversion.hh (revision 0) +++ trunk/milena/sandbox/vigouroux/convert/abstract/conversion.hh (revision 1707) @@ -0,0 +1,177 @@ +// Copyright (C) 2001, 2002, 2003, 2004 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 59 Temple Place - Suite 330, Boston, +// MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef OLENA_CONVERT_ABSTRACT_CONVERSION_HH +# define OLENA_CONVERT_ABSTRACT_CONVERSION_HH + +# include <mlc/type.hh> +# include <ntg/utils/debug.hh> +# include <functional> + +namespace oln { + namespace convert { + /*! + ** \brief Base classes for conversion. + */ + namespace abstract { + + // fwd_decl + template <class Exact, class Base> + class conversion; + + template<class Result_Type, + class Exact, class Base> + struct conversion_to_type; + + template<class Argument_Type, class Result_Type, + class Exact, class Base> + struct conversion_from_type_to_type; + + template<class Conv> + struct conversion_traits; + + /*! \brief Internal purpose only. + */ + namespace internal { + /// Retrieve the result type of a conversion. + template <class Base, class T> + struct output {}; + + template <class Argument_Type, class Result_Type, + class Exact, class Base> + struct output<conversion_from_type_to_type<Argument_Type, Result_Type, Exact, Base >, Argument_Type> + { + typedef Result_Type ret; + }; + + template <class Result_Type, + class Exact, class Base, class T> + struct output<conversion_to_type<Result_Type, Exact, Base >, T> + { + typedef Result_Type ret; + }; + } + + } // end of namespace abstract + + namespace abstract { + /*! Base class for conversion. + ** + ** \note If you write an class derived from this one, you + ** must write the specialization of the output trait. + */ + template<class Exact, class Base> + struct conversion : public mlc_hierarchy::any< Exact > + { + static std::string + name() + { + return std::string("conversion<") + Exact::name() + ">"; + } + + public: + template<class T> + struct output + { + typedef typename internal::output<Base, T>::ret ret; + }; + + /// Call the conversion written in the exact class. + template <class T> + typename output<T>::ret + operator()(const T& in) const + { + return this->exact().doit(in); + } + + protected: + conversion() {} + }; + + /// Base class for the conversion to a specific type. + template<class Result_Type, class Exact = mlc::final, class Base = mlc::final> + struct conversion_to_type : + public conversion< typename mlc::exact_vt<conversion_to_type< Result_Type, Exact >, Exact>::ret, + typename mlc::exact_vt<conversion_to_type< Result_Type, Exact >, Base>::ret > + { + /* Additionally define result_type. This is not required + in a conversion class (generally not possible to define). + But it's useful when it's available (like here) + because it make the conversion appear almost as Adaptable + Unary Function (it will just lack the argument_type, but + this typedef is not used very much.) */ + + typedef Result_Type result_type; + + static std::string + name() + { + // FIXME: Exact is not an integre type ! + return std::string("conversion_to_type<") + + ntg_name(Result_Type) + ", " + + Exact::name() + ">"; + } + + protected: + conversion_to_type() {} + }; + + /// Base class if both input and output types of the conversion are fixed. + template<class Argument_Type, class Result_Type, + class Exact = mlc::final, class Base = mlc::final> + struct conversion_from_type_to_type: + public conversion_to_type< Result_Type, + typename mlc::exact_vt<conversion_from_type_to_type< Argument_Type, Result_Type, Base, Exact>, Exact>::ret, + typename mlc::exact_vt<conversion_from_type_to_type< Argument_Type, Result_Type, Base, Exact>, Base>::ret > + { + + /* By defining argument_type, and inheriting from result_type, + we comply to the STL concept of Adaptable Unary Function. */ + + typedef Argument_Type argument_type; + + static std::string + name() + { + // FIXME: Exact is not an integre type ! + return std::string("conversion_from_type_to_type<") + + ntg_name(Argument_Type) + ", " + + ntg_name(Result_Type) + ", " + + "FIXME: ntg_name(Exact)" + ">"; + } + + protected : + conversion_from_type_to_type() {} + }; + } + + } // convert + +} // oln + + +#endif // OLENA_CONVERT_ABSTRACT_CONVERSION_HH Index: trunk/milena/sandbox/vigouroux/convert/bound.hh =================================================================== --- trunk/milena/sandbox/vigouroux/convert/bound.hh (revision 0) +++ trunk/milena/sandbox/vigouroux/convert/bound.hh (revision 1707) @@ -0,0 +1,66 @@ +// Copyright (C) 2001, 2002, 2003, 2004 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 59 Temple Place - Suite 330, Boston, +// MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + + +#ifndef OLENA_CONVERT_BOUND_HH +# define OLENA_CONVERT_BOUND_HH + +# include <oln/convert/abstract/conversion.hh> +# include <ntg/utils/cast.hh> + +namespace oln { + namespace convert { + + /*! Like convert::force, but with saturation. + ** + ** \todo FIXME: is this really useful with new types ? + */ + template<class Output, class Exact = mlc::final> + struct bound : public abstract::conversion_to_type< Output, typename mlc::exact_vt<bound<Output, Exact>, Exact>::ret > + { + + template< class Input > + Output + doit(const Input& v) const + { + return ntg::cast::bound<Output>(v); + } + + static std::string + name() + { + // FIXME: ntg_name(Exact) will not work for mlc::final ! + return std::string("bound<") + + ntg_name(Output) + ", " + + "FIXME: ntg_name(Exact)" + ">"; + } + }; + + } // convert +} // oln + +#endif // OLENA_CONVERT_BOUND_HH Index: trunk/milena/sandbox/vigouroux/convert/stretch.hh =================================================================== --- trunk/milena/sandbox/vigouroux/convert/stretch.hh (revision 0) +++ trunk/milena/sandbox/vigouroux/convert/stretch.hh (revision 1707) @@ -0,0 +1,217 @@ +// Copyright (C) 2001, 2002, 2003, 2004 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 59 Temple Place - Suite 330, Boston, +// MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef OLENA_CONVERT_STRETCH_HH +# define OLENA_CONVERT_STRETCH_HH + +# include <mlc/type.hh> + +# include <oln/basics.hh> + +# include <ntg/basics.hh> + +# include <oln/convert/abstract/conversion.hh> + +# include <set> + +# include <vector> + +namespace oln { + + namespace convert { + + /*! Functor to stretch a value from a range Input to a range Output. + ** + ** \see stretch_balance + ** \code + ** #include <oln/basics2d.hh> + ** #include <oln/convert/stretch.hh> + ** #include <ntg/all.hh> + ** #include <iostream> + ** + ** int main() + ** { + ** oln::image2d<ntg::int_u8> lena = oln::load(IMG_IN "lena256.pgm"); + ** + ** oln::io::save(apply(oln::convert::stretch<ntg::int_u<3> >(), lena), + ** IMG_OUT "oln_convert_stretch.pgm"); + ** } + ** \endcode + ** \image html lena256_pgm.png + ** \image latex lena256_pgm.png + ** => + ** \image html oln_convert_stretch.png + ** \image latex oln_convert_stretch.png + */ + template<class Output, class Exact = mlc::final> + struct stretch + : public abstract::conversion_to_type<Output, typename mlc::exact_vt<stretch<Output, Exact>, Exact>::ret > + { + template< class Input > + Output doit(const Input& v) const { + return Output(ntg::cast::rbound<Output, float> + ( + double(v - ntg_min_val(Input)) + / double(ntg_max_val(Input) - ntg_min_val(Input)) + * (ntg_max_val(Output) - ntg_min_val(Output)) + + ntg_min_val(Output)) + ); + } + + static std::string + name() + { + // FIXME: Exact is not an integre type ! + return std::string("stretch<") + ntg_name(Output) + ", " + + Exact::name() + ">"; + } + }; + + /*! Stretch the value of an image. + ** + ** This function stretches values between \a min_in and \a max_in + ** of an image \a in, to a range that goes from \a min_out to \a max_out. + ** \arg in Input image, must be have scalar values + ** \arg min_in Lower bound of the range in the input. All values smaller + ** than min_in are converted to \a min_out. + ** \arg max_in Upper bound of the range in the input. All values + ** greater than max_in + ** are converted to \a max_out. + ** \arg min_out Low bound of the range in the output. + ** \arg max_out Upper bound of the range in the output. + ** + ** Difference between "apply(stretch<T>(), im)" and "stretch_balance<T>(im)": + ** the first one stretches all the range of oln_value_type(T), the second + ** stretches only values that appear is the image: + ** \code + ** #include <oln/basics1d.hh> + ** #include <oln/convert/stretch.hh> + ** #include <ntg/all.hh> + ** #include <iostream> + ** + ** int main() + ** { + ** + ** oln::image1d<ntg::int_u<17> > im(4); + ** im(0) = 0; im(1) = 2; im(2) = 5000; im(3) = 4000; + ** + ** // print "0 170 511 340" + ** //(values of the *image* are dispatched on the range [0..2^9-1]) + ** std::cout << oln::convert::stretch_balance<ntg::int_u<9> >(im) << std::endl; + ** + ** //print " 0 0 19 16" (19 is the result of 5000 * 2^9 / 2^17) + ** //(values of *int_u<17>* are dispatched on the range [0..2^9-1]) + ** std::cout << apply(oln::convert::stretch<ntg::int_u<9> >(), im) << std::endl; + ** } + ** \endcode + ** + ** This function is useful to stretch images of label: + ** \code + ** #include <oln/basics2d.hh> + ** #include <oln/convert/stretch.hh> + ** #include <oln/level/cc.hh> + ** #include <ntg/all.hh> + ** #include <iostream> + ** + ** int main() + ** { + ** oln::image2d<ntg::bin> light = oln::load(IMG_IN "face_se.pbm"); + ** + ** //Extraction of the connected components: + ** unsigned card; + ** oln::image2d<ntg::int_u8> cc + ** = oln::level::frontp_connected_component<ntg::int_u8>(light, + ** oln::neighb_c8(), + ** card); + ** oln::io::save(cc, IMG_OUT "oln_convert_stretch_dark.pgm"); + ** oln::io::save(oln::convert::stretch_balance<ntg::int_u8>(cc), + ** IMG_OUT "oln_convert_stretch_balance.pgm"); + ** } + ** \endcode + ** \image html face_se_pbm.png + ** \image latex face_se_pbm.png + ** => Without stretch_balance: + ** \image html oln_convert_stretch_dark.png + ** \image latex oln_convert_stretch_dark.png + ** => With stretch_balance: + ** \image html oln_convert_stretch_balance.png + ** \image latex oln_convert_stretch_balance.png + */ + template<class DestValue, class I> + typename mute<I, DestValue>::ret + stretch_balance(const oln::abstract::non_vectorial_image<I> &in, + const oln_value_type(I) & min_in + = ntg_min_val(oln_value_type(I)), + const oln_value_type(I) & max_in + = ntg_max_val(oln_value_type(I)), + const DestValue & min_out = ntg_min_val(DestValue), + const DestValue & max_out = ntg_max_val(DestValue)) + { + typedef typename + ntg_is_a(DestValue, ntg::non_vectorial)::ensure_type ensure_type; + + typename mute<I, DestValue>::ret out(in.size()); + + //FIXME: I would like to remove the static_cast. + std::vector<ntg_cumul_type(DestValue)> + tab(static_cast<int>(max_in - min_in + 1)); + typedef typename std::set<oln_value_type(I)> set_type; + set_type s; + oln_iter_type(I) it(in); + + for_all(it) + if (in[it] <= max_in && in[it] >= min_in) + s.insert(in[it]); + if (s.size() == 1) + { + for_all(it) + out[it] = ntg_zero_val(DestValue); + return out; + } + { + unsigned cpt = 0; + for (typename set_type::const_iterator it(s.begin()); + it != s.end(); ++it, ++cpt) + tab[*it - min_in] = cpt * (max_out - min_out) / (s.size() - 1); + } + for_all(it) + if (min_in <= in[it]) + { + if (in[it] <= max_in) + out[it] = tab[in[it] - min_in] + min_out; + else + out[it] = max_out; + } + else + out[it] = min_out; + return out; + } + } // end of convert. + +} // end of oln. + +#endif // OLENA_CONVERT_STRETCH_HH Index: trunk/milena/sandbox/vigouroux/convert/rgbyuv.hh =================================================================== --- trunk/milena/sandbox/vigouroux/convert/rgbyuv.hh (revision 0) +++ trunk/milena/sandbox/vigouroux/convert/rgbyuv.hh (revision 1707) @@ -0,0 +1,139 @@ +// Copyright (C) 2001, 2002, 2003, 2004 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 59 Temple Place - Suite 330, Boston, +// MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + + +#ifndef OLENA_CONVERT_NRGBYUV_HH +# define OLENA_CONVERT_NRGBYUV_HH + +# include <oln/convert/abstract/colorconv.hh> + +# include <ntg/color/rgb.hh> +# include <ntg/color/yuv.hh> +# include <ntg/basics.hh> + +# include <sstream> + +/*!\file olena/oln/convert/rgbyuv.hh +** +** REF: The formulas used here come from ``Colour Space Conversions'', +** IAdrian Ford and Alan Roberts; August 11,1998. +*/ +namespace oln { + + using namespace ntg; + + namespace convert { + /* Functor for conversion from RGB to YUV. + ** + ** \see f_rgb_to_hsl + */ + template <unsigned inbits, unsigned outbits> + struct f_rgb_to_yuv + : public abstract::color_conversion<3, inbits, rgb_traits, + 3, outbits, yuv_traits, f_rgb_to_yuv<inbits, outbits> > + { + color<3, outbits, yuv_traits> + doit(const color<3, inbits, rgb_traits>& v) const + { + vec<3, float> in = v.to_float(); + vec<3, float> out; + out[yuv_Y] = + + 0.177 * in[rgb_R] + 0.813 * in[rgb_G] + 0.01 * in[rgb_B]; + out[yuv_U] = + - 0.083 * in[rgb_R] - 0.434 * in[rgb_G] + 0.437 * in[rgb_B]; + out[yuv_V] = + + 0.583 * in[rgb_R] - 0.576 * in[rgb_G] + 0.071 * in[rgb_B]; + return out; + } + + static std::string + name() + { + std::ostringstream s; + s << "f_rgb_to_yuv<" << inbits << ", " << outbits << '>'; + s.str(); + } + }; + /* Conversion from RGB to YUV. + ** + ** \see f_rgb_to_hsl + */ + template <unsigned inbits, unsigned outbits> + color<3, outbits, yuv_traits> + rgb_to_yuv(const color<3, inbits, rgb_traits>& v) + { + f_rgb_to_yuv<inbits, outbits> f; + + return f(v); + } + /* Functor for conversion from YUV to RGB. + ** + ** \see f_rgb_to_hsl + */ + template<unsigned inbits, unsigned outbits> + struct f_yuv_to_rgb + : public abstract::color_conversion<3, inbits, yuv_traits, + 3, outbits, rgb_traits, f_yuv_to_rgb<inbits, outbits> > + { + color<3, outbits, rgb_traits> + doit(const color<3, inbits, yuv_traits>& v) const + { + vec<3, float> in = v.to_float(); + vec<3, float> out; + out[rgb_R] = 0.8702 * in[yuv_Y] - 0.2487 * in[yuv_U] + 1.4250 * in[yuv_V]; + out[rgb_G] = 1.0259 * in[yuv_Y] + 0.0259 * in[yuv_U] - 0.3072 * in[yuv_V]; + out[rgb_B] = 1.1837 * in[yuv_Y] + 2.2642 * in[yuv_U] - 0.0359 * in[yuv_V]; + + return out; + } + + static std::string + name() + { + std::ostringstream s; + s << "f_yuv_to_rgb<" << inbits << ", " << outbits << '>'; + s.str(); + } + }; + + /* Conversion from YUV to RGB. + ** + ** \see f_rgb_to_hsl + */ + template <unsigned inbits, unsigned outbits> + color<3, outbits, rgb_traits> + yuv_to_rgb(const color<3, inbits, yuv_traits>& v) + { + f_yuv_to_rgb<inbits, outbits> f; + + return f(v); + } + + } // convert +} // oln + +#endif // OLENA_CONVERT_RGBYUV_HH Index: trunk/milena/sandbox/vigouroux/convert/rgbhsi.hh =================================================================== --- trunk/milena/sandbox/vigouroux/convert/rgbhsi.hh (revision 0) +++ trunk/milena/sandbox/vigouroux/convert/rgbhsi.hh (revision 1707) @@ -0,0 +1,153 @@ +// Copyright (C) 2001, 2002, 2003, 2004 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 59 Temple Place - Suite 330, Boston, +// MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + + +#ifndef OLENA_CONVERT_RGBHSI_HH +# define OLENA_CONVERT_RGBHSI_HH + +# include <oln/convert/abstract/colorconv.hh> + +# include <ntg/basics.hh> +# include <ntg/color/rgb.hh> +# include <ntg/color/hsi.hh> + +# include <sstream> + +/*! \file olena/oln/convert/rgbhsi.hh +** +** REF: The formulas used here come from ``Digital Image Processing +** Algorithms and Applications'', I. Pitas; Wiley-Interscience. +*/ + +namespace oln { + + using namespace ntg; + + namespace convert { + + static const float sqrt3_3 = sqrt(3) / 3; + static const float inv_sqrt6 = 1 / sqrt(6); + static const float inv_sqrt2 = 1 / sqrt(2); + + /*! Functor for conversion from RGB to HSI color space. + ** + ** \see f_rgb_to_hsl + */ + template<unsigned inbits, unsigned outbits> + struct f_rgb_to_hsi + : public abstract::color_conversion<3, inbits, rgb_traits, + 3, outbits, hsi_traits, f_rgb_to_hsi<inbits, outbits> > + { + color<3, inbits, hsi_traits> + doit(const color<3, outbits, rgb_traits>& v) const + { + vec<3, float> in = v.to_float(); + vec<3, float> out; + out[hsi_I] = + sqrt3_3 * in[rgb_R] + sqrt3_3 * in[rgb_G] + sqrt3_3 * in[rgb_B]; + const float v1 = inv_sqrt2 * in[rgb_G] - inv_sqrt2 * in[rgb_B]; + const float v2 = 2 * inv_sqrt6 * in[rgb_R] - inv_sqrt6 * in[rgb_G] + - inv_sqrt6 * in[rgb_B]; + out[hsi_H] = atan2(v2, v1) / M_PI * 180.0; + if (out[hsi_H] < 0) + out[hsi_H] += 360.0; + assert(out[hsi_H] >= 0); + out[hsi_S] = sqrt(v1 * v1 + v2 * v2); + return out; + } + + static std::string + name() + { + std::ostringstream s; + s << "f_rgb_to_hsi<" << inbits << ", " << outbits << '>'; + s.str(); + } + }; + + /*! Conversion from RGB to HSI color space. + ** + ** \see f_rgb_to_hsl + */ + template <unsigned inbits, unsigned outbits> + color<3, outbits, hsi_traits> + rgb_to_hsi(const color<3, inbits, rgb_traits>& v) + { + f_rgb_to_hsi<inbits, outbits> f; + + return f(v); + } + + /*! Functor conversion from HSI to RGB color space. + ** + ** \see f_rgb_to_hsl + */ + template<unsigned inbits, unsigned outbits> + struct f_hsi_to_rgb + : public abstract::color_conversion<3, inbits, hsi_traits, + 3, outbits, rgb_traits, f_hsi_to_rgb<inbits, outbits> > + { + color<3, outbits, rgb_traits> + doit(const color<3, inbits, hsi_traits>& v) const + { + vec<3, float> in = v.to_float(); + vec<3, float> out; + const float h = in[hsi_H] / 180.0 * M_PI; + const float v1 = in[hsi_S] * cos(h); + const float v2 = in[hsi_S] * sin(h); + out[rgb_R] = sqrt3_3 * in[hsi_I] + 2 * inv_sqrt6 * v2; + out[rgb_G] = sqrt3_3 * in[hsi_I] + inv_sqrt2 * v1 - inv_sqrt6 * v2; + out[rgb_B] = sqrt3_3 * in[hsi_I] - inv_sqrt2 * v1 - inv_sqrt6 * v2; + return out; + } + + static std::string + name() + { + std::ostringstream s; + s << "f_hsi_to_rgb<" << inbits << ", " << outbits << '>'; + s.str(); + } + }; + + /*! Conversion from HSI to RGB color space. + ** + ** \see f_rgb_to_hsl + */ + template <unsigned inbits, unsigned outbits> + color<3, outbits, rgb_traits> + hsi_to_rgb (const color<3, inbits, hsi_traits>& v) + { + f_hsi_to_rgb<inbits, outbits> f; + + return f(v); + } + + } // convert +} // oln + +#endif // OLENA_CONVERT_RGBHSI_HH Index: trunk/milena/sandbox/vigouroux/color.hh =================================================================== --- trunk/milena/sandbox/vigouroux/color.hh (revision 0) +++ trunk/milena/sandbox/vigouroux/color.hh (revision 1707) @@ -0,0 +1,44 @@ +// Copyright (C) 2001, 2002, 2003 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 59 Temple Place - Suite 330, Boston, +// MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef NTG_COLOR_HH +# define NTG_COLOR_HH + +/* + Proxy header for color types. +*/ + +# include <ntg/color/rgb.hh> +# include <ntg/color/nrgb.hh> +# include <ntg/color/hsi.hh> +# include <ntg/color/hsl.hh> +# include <ntg/color/hsv.hh> +# include <ntg/color/xyz.hh> +# include <ntg/color/yiq.hh> +# include <ntg/color/yuv.hh> + +#endif // !NTG_COLOR_HH Index: trunk/milena/sandbox/vigouroux/color/yiq.hh =================================================================== --- trunk/milena/sandbox/vigouroux/color/yiq.hh (revision 0) +++ trunk/milena/sandbox/vigouroux/color/yiq.hh (revision 1707) @@ -0,0 +1,64 @@ +// Copyright (C) 2001, 2002, 2003 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 59 Temple Place - Suite 330, Boston, +// MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef NTG_COLOR_YIQ_HH +# define NTG_COLOR_YIQ_HH + +# include <ntg/color/color.hh> + +namespace ntg +{ + + enum yiq_comp + { + yiq_Y = 0, + yiq_I = 1, + yiq_Q = 2 + }; + + template<unsigned icomp> struct yiq_traits; + template<> struct yiq_traits<yiq_Y> : public interval<0,1> {}; + + template<> struct yiq_traits<yiq_I> + { + static float lower_bound() { return -.4192; } + static float upper_bound() { return .5346; } + }; + + template<> struct yiq_traits<yiq_Q> + { + static float lower_bound() { return -.6783; } + static float upper_bound() { return .6527; } + }; + + typedef color<3,8,yiq_traits> yiq_8; + typedef color<3,16,yiq_traits> yiq_16; + typedef color<3,32,yiq_traits> yiq_32; + +} // end of ntg. + +#endif // !NTG_COLOR_YIQ_HH Index: trunk/milena/sandbox/vigouroux/color/yuv.hh =================================================================== --- trunk/milena/sandbox/vigouroux/color/yuv.hh (revision 0) +++ trunk/milena/sandbox/vigouroux/color/yuv.hh (revision 1707) @@ -0,0 +1,63 @@ +// Copyright (C) 2001, 2002, 2003 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 59 Temple Place - Suite 330, Boston, +// MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef NTG_COLOR_YUV_HH +# define NTG_COLOR_YUV_HH + +# include <ntg/color/color.hh> + +namespace ntg +{ + + enum yuv_comp + { + yuv_Y = 0, + yuv_U = 1, + yuv_V = 2 + }; + + template<unsigned icomp> struct yuv_traits; + template<> struct yuv_traits<yuv_Y> : public interval<0,1> {}; + template<> struct yuv_traits<yuv_U> + { + static float lower_bound() { return -0.517; } + static float upper_bound() { return 0.437; } + }; + + template<> struct yuv_traits<yuv_V> + { + static float lower_bound() { return -0.576; } + static float upper_bound() { return 0.654; } + }; + + typedef color<3,8,yuv_traits> yuv_8; + typedef color<3,16,yuv_traits> yuv_16; + typedef color<3,32,yuv_traits> yuv_32; + +} // end of ntg. + +#endif // !NTG_COLOR_YUV_HH Index: trunk/milena/sandbox/vigouroux/color/hsi.hh =================================================================== --- trunk/milena/sandbox/vigouroux/color/hsi.hh (revision 0) +++ trunk/milena/sandbox/vigouroux/color/hsi.hh (revision 1707) @@ -0,0 +1,63 @@ +// Copyright (C) 2001, 2002, 2003 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 59 Temple Place - Suite 330, Boston, +// MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef NTG_COLOR_HSI_HH +# define NTG_COLOR_HSI_HH + +# include <ntg/color/color.hh> + +namespace ntg +{ + + enum hsi_comp + { + hsi_H = 0, + hsi_S = 1, + hsi_I = 2 + }; + + template<unsigned icomp> struct hsi_traits; + template<> struct hsi_traits<hsi_H> : public interval<0,360> {}; + template<> struct hsi_traits<hsi_S> + { + static float lower_bound() { return 0.; } + static float upper_bound() { return 0.816497; } //2 / sqrt(6) + }; + + template<> struct hsi_traits<hsi_I> + { + static float lower_bound() { return 0.; } + static float upper_bound() { return 1.7320508; } //sqrt(3) + }; + + typedef color<3,8,hsi_traits> hsi_8; + typedef color<3,16,hsi_traits> hsi_16; + typedef color<3,32,hsi_traits> hsi_32; + +} // end of ntg. + +#endif // !NTG_COLOR_HSI_HH Index: trunk/milena/sandbox/vigouroux/color/hsl.hh =================================================================== --- trunk/milena/sandbox/vigouroux/color/hsl.hh (revision 0) +++ trunk/milena/sandbox/vigouroux/color/hsl.hh (revision 1707) @@ -0,0 +1,54 @@ +// Copyright (C) 2001, 2002, 2003 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 59 Temple Place - Suite 330, Boston, +// MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef NTG_COLOR_HSL_HH +# define NTG_COLOR_HSL_HH + +# include <ntg/color/color.hh> + +namespace ntg +{ + + enum hsl_comp + { + hsl_H = 0, + hsl_S = 1, + hsl_L = 2 + }; + + template<unsigned icomp> struct hsl_traits; + template<> struct hsl_traits<hsl_H> : public interval<0,360> {}; + template<> struct hsl_traits<hsl_S> : public interval<0,1> {}; + template<> struct hsl_traits<hsl_L> : public interval<0,1> {}; + + typedef color<3,8,hsl_traits> hsl_8; + typedef color<3,16,hsl_traits> hsl_16; + typedef color<3,32,hsl_traits> hsl_32; + +} // end of ntg + +#endif // !NTG_COLOR_HSL_HH Index: trunk/milena/sandbox/vigouroux/color/nrgb.hh =================================================================== --- trunk/milena/sandbox/vigouroux/color/nrgb.hh (revision 0) +++ trunk/milena/sandbox/vigouroux/color/nrgb.hh (revision 1707) @@ -0,0 +1,130 @@ +// Copyright (C) 2001, 2002, 2003 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 59 Temple Place - Suite 330, Boston, +// MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef NTG_NRGB_HH +# define NTG_NRGB_HH + +# include <ntg/color/color.hh> + +namespace ntg +{ + + /*! + NTSC RGB format. + */ + + enum nrgb_comp + { + nrgb_R = 0, + nrgb_G = 1, + nrgb_B = 2 + }; + + template<unsigned icomp> struct nrgb_traits; + template<> + struct nrgb_traits<nrgb_R> + { + static float lower_bound() { return 0;} + static float upper_bound() { return 1.0885004;} + }; + + + template<> + struct nrgb_traits<nrgb_G> + { + static float lower_bound() { return -0.3321984;} + static float upper_bound() { return 1.3189264;} + }; + + + template<> + struct nrgb_traits<nrgb_B> + { + static float lower_bound() { return -0.0688480;} + static float upper_bound() { return 0.904727;} + }; + + + typedef color<3,8,nrgb_traits> nrgb_8; + typedef color<3,16,nrgb_traits> nrgb_16; + typedef color<3,32,nrgb_traits> nrgb_32; + + // FIXME: not thread safe ! +# define DEFINE_COLOR(Type, Name, V1, V2, V3) \ + inline const Type& Name() { \ + static const Type tmp(V1, V2, V3); \ + return tmp; \ + } + + namespace nrgb_8_color + { + + DEFINE_COLOR(nrgb_8, white, 255, 255, 255) + DEFINE_COLOR(nrgb_8, gray, 128, 128, 128) + DEFINE_COLOR(nrgb_8, black, 0, 0, 0) + DEFINE_COLOR(nrgb_8, red, 255, 0, 0) + DEFINE_COLOR(nrgb_8, green, 0, 255, 0) + DEFINE_COLOR(nrgb_8, blue, 0, 0, 255) + DEFINE_COLOR(nrgb_8, yellow,255, 255, 0) + DEFINE_COLOR(nrgb_8, cyan, 0, 255, 255) + DEFINE_COLOR(nrgb_8, pink, 255, 0, 255) + + } // end of nrgb_8_color + + namespace nrgb_16_color + { + + DEFINE_COLOR(nrgb_16, white, 255, 255, 255) + DEFINE_COLOR(nrgb_16, gray, 128, 128, 128) + DEFINE_COLOR(nrgb_16, black, 0, 0, 0) + DEFINE_COLOR(nrgb_16, red, 255, 0, 0) + DEFINE_COLOR(nrgb_16, green, 0, 255, 0) + DEFINE_COLOR(nrgb_16, blue, 0, 0, 255) + DEFINE_COLOR(nrgb_16, yellow,255, 255, 0) + DEFINE_COLOR(nrgb_16, cyan, 0, 255, 255) + DEFINE_COLOR(nrgb_16, pink, 255, 0, 255) + + } // end of nrgb_16_color + + namespace nrgb_32_color + { + + DEFINE_COLOR(nrgb_32, white, 255, 255, 255) + DEFINE_COLOR(nrgb_32, gray, 128, 128, 128) + DEFINE_COLOR(nrgb_32, black, 0, 0, 0) + DEFINE_COLOR(nrgb_32, red, 255, 0, 0) + DEFINE_COLOR(nrgb_32, green, 0, 255, 0) + DEFINE_COLOR(nrgb_32, blue, 0, 0, 255) + DEFINE_COLOR(nrgb_32, yellow,255, 255, 0) + DEFINE_COLOR(nrgb_32, cyan, 0, 255, 255) + DEFINE_COLOR(nrgb_32, pink, 255, 0, 255) + + } // end of nrgb_32_color. + +} // end of ntg. + +#endif // !NTG_COLOR_NRGB_HH Index: trunk/milena/sandbox/vigouroux/color/xyz.hh =================================================================== --- trunk/milena/sandbox/vigouroux/color/xyz.hh (revision 0) +++ trunk/milena/sandbox/vigouroux/color/xyz.hh (revision 1707) @@ -0,0 +1,54 @@ +// Copyright (C) 2001, 2002, 2003 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 59 Temple Place - Suite 330, Boston, +// MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef NTG_COLOR_XYZ_HH +# define NTG_COLOR_XYZ_HH + +# include <ntg/color/color.hh> + +namespace ntg +{ + + enum xyz_comp + { + xyz_X = 0, + xyz_Y = 1, + xyz_Z = 2 + }; + + template<unsigned icomp> struct xyz_traits; + template<> struct xyz_traits<xyz_X> : public interval<0,1> {}; + template<> struct xyz_traits<xyz_Y> : public interval<0,1> {}; + template<> struct xyz_traits<xyz_Z> : public interval<0,1> {}; + + typedef color<3,8,xyz_traits> xyz_8; + typedef color<3,16,xyz_traits> xyz_16; + typedef color<3,32,xyz_traits> xyz_32; + +} // end of ntg. + +#endif // !NTG_COLOR_XYZ_HH Index: trunk/milena/sandbox/vigouroux/color/rgb.hh =================================================================== --- trunk/milena/sandbox/vigouroux/color/rgb.hh (revision 0) +++ trunk/milena/sandbox/vigouroux/color/rgb.hh (revision 1707) @@ -0,0 +1,58 @@ +// Copyright (C) 2001, 2002, 2003 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 59 Temple Place - Suite 330, Boston, +// MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef NTG_COLOR_RGB_HH +# define NTG_COLOR_RGB_HH + +# include <ntg/color/color.hh> + +namespace ntg +{ + + /*! + CIE RGB format. + */ + + enum rgb_comp + { + rgb_R = 0, + rgb_G = 1, + rgb_B = 2 + }; + + template<unsigned icomp> struct rgb_traits; + template<> struct rgb_traits<rgb_R> : public interval<0,1> {}; + template<> struct rgb_traits<rgb_G> : public interval<0,1> {}; + template<> struct rgb_traits<rgb_B> : public interval<0,1> {}; + + typedef color<3,8,rgb_traits> rgb_8; + typedef color<3,16,rgb_traits> rgb_16; + typedef color<3,32,rgb_traits> rgb_32; + +} // end of ntg. + +#endif // !NTG_COLOR_RGB_HH Index: trunk/milena/sandbox/vigouroux/color/color.hh =================================================================== --- trunk/milena/sandbox/vigouroux/color/color.hh (revision 0) +++ trunk/milena/sandbox/vigouroux/color/color.hh (revision 1707) @@ -0,0 +1,308 @@ +// Copyright (C) 2001, 2002, 2003, 2004 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 59 Temple Place - Suite 330, Boston, +// MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef NTG_COLOR_COLOR_HH +# define NTG_COLOR_COLOR_HH + +/* + Header for generic color type, from which real color types are defined. +*/ + +# include <ntg/basics.hh> +# include <ntg/int.hh> +# include <ntg/vect/vec.hh> +# include <ntg/core/pred_succ.hh> + +# include <mlc/cmp.hh> + +# include <iostream> +# include <sstream> +# include <string> + +namespace ntg { + + namespace internal { + + /*------------------. + | typetraits<color> | + `------------------*/ + + template <unsigned ncomps, + unsigned qbits, + template <unsigned> class color_system> + struct typetraits<color<ncomps, qbits, color_system> > + { + enum { nb_comp = ncomps }; + + typedef color<ncomps, qbits, color_system> self; + typedef self ntg_type; + typedef vectorial abstract_type; + typedef int_u<qbits> comp_type; + typedef self base_type; + typedef vec<ncomps, int_u<qbits> > storage_type; + }; + + /*-------------------------. + | Helper structs for float | + `-------------------------*/ + + /*! + Helper struct to convert vec<N,T> to vec<N,float>, + taking color_system into account. + */ + template <unsigned n, + unsigned ncomps, + unsigned qbits, + template <unsigned> class color_system> + struct _to_float + { + typedef int_u<qbits> T; + typedef vec<ncomps, T> in_type; + typedef vec<ncomps, float> out_type; + + static void + doit (const in_type& in, out_type& out) + { + float in_range = float(ntg_max_val(T)) - float(ntg_min_val(T)); + float out_range = float(color_system<n>::upper_bound()) + - float(color_system<n>::lower_bound()); + out[n] = ((float(in[n]) - float(ntg_min_val(T))) + * out_range / in_range + + float(color_system<n>::lower_bound())); + + // process next componant recursively: + _to_float<n + 1, ncomps, qbits, color_system>::doit(in, out); + } + }; + + // Stop recursion when n == ncomps. + template <unsigned ncomps, + unsigned qbits, + template <unsigned> class color_system> + struct _to_float<ncomps, ncomps, qbits, color_system> + { + typedef vec<ncomps, int_u<qbits> > in_type; + typedef vec<ncomps, float> out_type; + + static void + doit (const in_type&, out_type&) + {} + }; + + /*! + Helper struct to convert vec<N,float> to vec<N,T>, + taking color_system into account. + */ + template <unsigned n, + unsigned ncomps, + unsigned qbits, + template <unsigned> class color_system> + struct _from_float + { + typedef int_u<qbits> T; + typedef vec<ncomps, float> in_type; + typedef vec<ncomps, T> out_type; + + static void + doit (const in_type& in, out_type& out) + { + float out_range = float(optraits<T>::max()) + - float(optraits<T>::min()); + float in_range = float(color_system<n>::upper_bound()) + - float(color_system<n>::lower_bound()); + + out[n] = cast::rbound<int_u<qbits> > + ((in[n] - float(color_system<n>::lower_bound())) + * out_range / in_range + + float(color_system<n>::lower_bound())); + + // process next componant recursively: + _from_float<n + 1, ncomps, qbits, color_system>::doit(in, out); + } + }; + + // stop recursion when n == ncomps. + template <unsigned ncomps, + unsigned qbits, + template <unsigned> class color_system> + struct _from_float<ncomps, ncomps, qbits, color_system> + { + typedef vec<ncomps, float> in_type; + typedef vec<ncomps, int_u<qbits> > out_type; + + static void + doit (const in_type&, out_type&) + {} + }; + + } // end of internal. + + /*-----------------------------------. + | color<ncomps, qbits, color_system> | + `-----------------------------------*/ + + //! Generic type for color. + /*! + Specific color types (such as rgb, xyz, etc.) are defined by + specifying ncomps, qbits and a color_system trait. + + ncomps: number of components. + qbits: number of bits of each unsigned integer component. + color_system: traits defining the intervals of each component. + + Colors are implemented and seen as a vector of components. + */ + template <unsigned ncomps, + unsigned qbits, + template <unsigned> class color_system> + struct color : public vect_value<color<ncomps, qbits, color_system> > + { + typedef int_u<qbits> comp_type; + typedef vec<ncomps, comp_type> vec_type; + typedef vec<ncomps, float> float_vec_type; + + color() {}; + color(const vec_type& vec) { this->val_ = vec; }; + color(const float_vec_type& vec) + { + internal::_from_float<0,ncomps,qbits,color_system>::doit(vec,this->val_); + } + + color(const comp_type& c1, const comp_type& c2, const comp_type& c3) + { + mlc::is_true<ncomps == 3>::ensure(); + this->val_[0] = c1; + this->val_[1] = c2; + this->val_[2] = c3; + } + + vec_type& as_vec() { return this->val_; } + const vec_type& as_vec() const { return this->val_; } + + float_vec_type + to_float() const + { + float_vec_type tmp; + internal::_to_float<0,ncomps,qbits,color_system>::doit(this->val_, tmp); + return tmp; + } + + bool + operator==(const color& r) const + { return this->val_ == r.val_; } + }; + + /*! + Helper function to complete color_system (by inheritance). + */ + template<int lval, int uval> + struct interval + { + static int lower_bound() { return lval; } + static int upper_bound() { return uval; } + }; + + template <unsigned ncomps, + unsigned qbits, + template <unsigned> class color_system> + inline std::ostream& + operator<<(std::ostream& o, + const color<ncomps, qbits, color_system>& r) + { + o << r.as_vec(); + return o; + } + + namespace internal + { + + /*----------------. + | optraits<color> | + `----------------*/ + + template <unsigned ncomps, + unsigned qbits, + template <unsigned> class color_system> + struct optraits<color<ncomps, qbits, color_system> > + { + private: + typedef color<ncomps, qbits, color_system> self; + typedef typename typetraits<self>::storage_type storage_type; + + public: + static unsigned max_print_width () + { + return ntg_max_print_width(storage_type); + } + + static std::string + name() + { + std::ostringstream out; + // FIXME: Output color_system somehow. + out << "color<" << ncomps << "," << qbits << ",...>" << std::ends; + return out.str(); + } + }; + + + template <typename T> struct default_less; + + /*! The specialized version of default_less for colors. + ** + ** \warning This class is only provided to build classes + ** that need a less class, it does not correspond to + ** the reality. \n + ** Example of a std::set of RGB colors: + ** \verbatim + ** std::set<ntg:rgb_8, + ** ntg::internal::default_less<ntg::rgb8> > s; + ** s.insert(ntg::rgb_8(10, 16, 64)); + ** \endverbatim + */ + template <unsigned ncomps, + unsigned qbits, + template <unsigned> class color_system> + struct default_less< ntg::color<ncomps, qbits, color_system> > + { + typedef ntg::color<ncomps, qbits, color_system> arg_type; + bool operator()(const arg_type& l, + const arg_type& r) const + { + for (unsigned i = 0; i < ntg_nb_comp(arg_type); ++i) + if (l[i] < r[i]) + return true; + else if (l[i] > r[i]) + return false; + return false; + } + }; + } // end of internal. + +} // end of ntg. + +#endif // !NTG_COLOR_COLOR_HH Index: trunk/milena/sandbox/vigouroux/color/hsv.hh =================================================================== --- trunk/milena/sandbox/vigouroux/color/hsv.hh (revision 0) +++ trunk/milena/sandbox/vigouroux/color/hsv.hh (revision 1707) @@ -0,0 +1,55 @@ +// Copyright (C) 2001, 2002, 2003 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 59 Temple Place - Suite 330, Boston, +// MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef NTG_COLOR_HSV_HH +# define NTG_COLOR_HSV_HH + +# include <ntg/color/color.hh> + +namespace ntg +{ + + enum hsv_comp + { + hsv_H = 0, + hsv_S = 1, + hsv_V = 2 + }; + + template<unsigned icomp> struct hsv_traits; + template<> struct hsv_traits<hsv_H> : public interval<0,360> {}; + template<> struct hsv_traits<hsv_S> : public interval<0,1> {}; + template<> struct hsv_traits<hsv_V> : public interval<0,1> {}; + + + typedef color<3,8,hsv_traits> hsv_8; + typedef color<3,16,hsv_traits> hsv_16; + typedef color<3,32,hsv_traits> hsv_32; + +} // end of ntg. + +#endif // !NTG_COLOR_HSV_HH