
Mea culpa, erreur de ma part.... Index: integre/ChangeLog from Giovanni Palma <giovanni@lrde.epita.fr> * ntg/color/yuv.hh: Change the working interval. * ntg/color/yiq.hh: Change the working interval. * ntg/color/xyz.hh: Change the Z upperbound value. * ntg/color/nrgb.hh: Change the working interval. * ntg/color/hsi.hh: Change the Saturation upper bound value. Index: olena/ChangeLog from Giovanni Palma <giovanni@lrde.epita.fr> * oln/convert/nrgbhsi.hh: Remove file. * oln/convert/nrgbhsl.hh: Remove file. * oln/convert/nrgbhsv.h: Remove file. * oln/convert/nrgbyiq.hh: Remove file. * oln/convert/nrgbyuv.hh: Remove file. * oln/convert/rgbyiq.hh: Add file. Add RGB to YIQ conversion code. * oln/convert/rgbyuv.hh: Add file. Add RGB to YUV conversion code. * oln/convert/rgbhsi.hh: Add file. Add RGB to HSI conversion code. * oln/convert/rgbhsl.hh: Add file. Add RGB to HSL conversion code. * oln/convert/rgbhsv.hh: Add file. Add RGB to HSV conversion code. * Makefile.am: Make new file Referenced. * tests/convert/Makefile.am: Remove tests on obsolete functions. Add test on new functions. * oln/convert/rgbxyz.hh: Correct the RGB to XYZ conversion. * oln/convert/nrgbxyz.hh: Make it obsolete. Index: olena/oln/convert/nrgbxyz.hh --- olena/oln/convert/nrgbxyz.hh Thu, 07 Aug 2003 02:08:21 +0200 david (oln/16_nrgbxyz.hh 1.11 640) +++ olena/oln/convert/nrgbxyz.hh Thu, 22 Jan 2004 15:54:07 +0100 palma_g (oln/16_nrgbxyz.hh 1.12 640) @@ -48,6 +48,9 @@ namespace convert { + /*! + ** obsolete a composition should be performed with nrgb->rgb and rgb->xyz + */ template <unsigned inbits, unsigned outbits> struct f_nrgb_to_xyz : public abstract::color_conversion<3, inbits, nrgb_traits, @@ -88,6 +91,9 @@ return f(v); } + /*! + ** obsolete a composition should be performed with xyz->rgb and rgb->nrgb + */ template<unsigned inbits, unsigned outbits> struct f_xyz_to_nrgb : public abstract::color_conversion<3, inbits, xyz_traits, Index: olena/oln/convert/rgbxyz.hh --- olena/oln/convert/rgbxyz.hh Thu, 07 Aug 2003 02:08:21 +0200 david (oln/19_rgbxyz.hh 1.11 640) +++ olena/oln/convert/rgbxyz.hh Thu, 22 Jan 2004 15:48:00 +0100 palma_g (oln/19_rgbxyz.hh 1.12 640) @@ -59,7 +59,7 @@ 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.813 * in[rgb_G] + 0.011 * 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; } @@ -95,9 +95,9 @@ 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.088 * in[xyz_Z]; + - 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.009 * in[xyz_Z]; + 0.005 * in[xyz_X] - 0.014 * in[xyz_Y] + 1.01 * in[xyz_Z]; return out; } Index: integre/ntg/color/hsi.hh --- integre/ntg/color/hsi.hh Mon, 28 Jul 2003 18:24:48 +0200 burrus_n (oln/i/20_hsi.hh 1.3.1.6 640) +++ integre/ntg/color/hsi.hh Thu, 22 Jan 2004 17:26:30 +0100 palma_g (oln/i/20_hsi.hh 1.3.1.7 640) @@ -45,7 +45,7 @@ template<> struct hsi_traits<hsi_S> { static float lower_bound() { return 0.; } - static float upper_bound() { return 1.0801234; } //sqrt(7. / 6) + static float upper_bound() { return 0.816497; } //2 / sqrt(6) }; template<> struct hsi_traits<hsi_I> Index: integre/ntg/color/nrgb.hh --- integre/ntg/color/nrgb.hh Wed, 30 Jul 2003 18:49:16 +0200 burrus_n (oln/i/19_nrgb.hh 1.5.1.5 640) +++ integre/ntg/color/nrgb.hh Thu, 22 Jan 2004 17:50:09 +0100 palma_g (oln/i/19_nrgb.hh 1.5.1.6 640) @@ -45,9 +45,29 @@ }; template<unsigned icomp> struct nrgb_traits; - template<> struct nrgb_traits<nrgb_R> : public interval<0,1> {}; - template<> struct nrgb_traits<nrgb_G> : public interval<0,1> {}; - template<> struct nrgb_traits<nrgb_B> : public interval<0,1> {}; + 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; Index: integre/ntg/color/xyz.hh --- integre/ntg/color/xyz.hh Mon, 28 Jul 2003 18:24:48 +0200 burrus_n (oln/i/24_xyz.hh 1.3.1.6 640) +++ integre/ntg/color/xyz.hh Thu, 22 Jan 2004 15:49:51 +0100 palma_g (oln/i/24_xyz.hh 1.3.1.7 640) @@ -43,12 +43,7 @@ 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> - { - static float lower_bound() { return 0.; } - static float upper_bound() { return 1.2; } - }; + 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; Index: integre/ntg/color/yiq.hh --- integre/ntg/color/yiq.hh Mon, 28 Jul 2003 18:24:48 +0200 burrus_n (oln/i/23_yiq.hh 1.3.1.6 640) +++ integre/ntg/color/yiq.hh Thu, 22 Jan 2004 18:59:48 +0100 palma_g (oln/i/23_yiq.hh 1.3.1.7 640) @@ -45,14 +45,14 @@ template<> struct yiq_traits<yiq_I> { - static float lower_bound() { return -.6; } - static float upper_bound() { return .6; } + static float lower_bound() { return -.4192; } + static float upper_bound() { return .5346; } }; template<> struct yiq_traits<yiq_Q> { - static float lower_bound() { return -.6; } - static float upper_bound() { return .6; } + static float lower_bound() { return -.6783; } + static float upper_bound() { return .6527; } }; typedef color<3,8,yiq_traits> yiq_8; Index: integre/ntg/color/yuv.hh --- integre/ntg/color/yuv.hh Mon, 28 Jul 2003 18:24:48 +0200 burrus_n (oln/i/25_yuv.hh 1.3.1.6 640) +++ integre/ntg/color/yuv.hh Thu, 22 Jan 2004 16:23:56 +0100 palma_g (oln/i/25_yuv.hh 1.3.1.7 640) @@ -44,14 +44,14 @@ template<> struct yuv_traits<yuv_Y> : public interval<0,1> {}; template<> struct yuv_traits<yuv_U> { - static float lower_bound() { return -0.45; } - static float upper_bound() { return 0.45; } + 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.62; } - static float upper_bound() { return 0.62; } + static float lower_bound() { return -0.576; } + static float upper_bound() { return 0.654; } }; typedef color<3,8,yuv_traits> yuv_8; Index: olena/tests/convert/Makefile.am --- olena/tests/convert/Makefile.am Fri, 01 Aug 2003 02:45:53 +0200 burrus_n (oln/f/0_Makefile.a 1.13 640) +++ olena/tests/convert/Makefile.am Thu, 22 Jan 2004 19:22:42 +0100 palma_g (oln/f/0_Makefile.a 1.14 640) @@ -4,74 +4,74 @@ include ../check/Makefile.check check_PROGRAMS = \ - 8-nrgb-hsi \ - 8-nrgb-hsl \ - 8-nrgb-hsv \ - 8-nrgb-xyz \ - 8-nrgb-yiq \ - 8-nrgb-yuv \ + 8-rgb-hsi \ + 8-rgb-hsl \ + 8-rgb-hsv \ + 8-rgb-xyz \ + 8-rgb-yiq \ + 8-rgb-yuv \ 8-rgb-nrgb \ 8-rgb-xyz \ - f-8-nrgb-hsi \ - f-8-nrgb-hsl \ - f-8-nrgb-hsv \ - f-8-nrgb-xyz \ - f-8-nrgb-yiq \ - f-8-nrgb-yuv \ + f-8-rgb-hsi \ + f-8-rgb-hsl \ + f-8-rgb-hsv \ + f-8-rgb-xyz \ + f-8-rgb-yiq \ + f-8-rgb-yuv \ f-8-rgb-nrgb \ f-8-rgb-xyz -XFAIL_TESTS = 8-rgb-nrgb$(EXEEXT) +# XFAIL_TESTS = 8-rgb-nrgb$(EXEEXT) ## FIXME: Ideally, each _SOURCES should be defined as $(CONVSOURCES), with ## CONVSOURCES = convcomp.cc convcomp.hh ## but this triggers a bug in Automake 1.6. -8_nrgb_hsi_SOURCES = conv.cc conv.hh -8_nrgb_hsi_CPPFLAGS = $(AM_CPPFLAGS) -DSRC=nrgb -DDEST=hsi -DEM=5 +8_rgb_hsi_SOURCES = conv.cc conv.hh +8_rgb_hsi_CPPFLAGS = $(AM_CPPFLAGS) -DSRC=rgb -DDEST=hsi -DEM=5 -8_nrgb_hsl_SOURCES = conv.cc conv.hh -8_nrgb_hsl_CPPFLAGS = $(AM_CPPFLAGS) -DSRC=nrgb -DDEST=hsl -DEM=5 +8_rgb_hsl_SOURCES = conv.cc conv.hh +8_rgb_hsl_CPPFLAGS = $(AM_CPPFLAGS) -DSRC=rgb -DDEST=hsl -DEM=5 -8_nrgb_hsv_SOURCES = conv.cc conv.hh -8_nrgb_hsv_CPPFLAGS = $(AM_CPPFLAGS) -DSRC=nrgb -DDEST=hsv -DEM=3 +8_rgb_hsv_SOURCES = conv.cc conv.hh +8_rgb_hsv_CPPFLAGS = $(AM_CPPFLAGS) -DSRC=rgb -DDEST=hsv -DEM=3 -8_nrgb_xyz_SOURCES = conv.cc conv.hh -8_nrgb_xyz_CPPFLAGS = $(AM_CPPFLAGS) -DSRC=nrgb -DDEST=xyz -DEM=5 +8_rgb_xyz_SOURCES = conv.cc conv.hh +8_rgb_xyz_CPPFLAGS = $(AM_CPPFLAGS) -DSRC=rgb -DDEST=xyz -DEM=5 -8_nrgb_yiq_SOURCES = conv.cc conv.hh -8_nrgb_yiq_CPPFLAGS = $(AM_CPPFLAGS) -DSRC=nrgb -DDEST=yiq -DEM=5 +8_rgb_yiq_SOURCES = conv.cc conv.hh +8_rgb_yiq_CPPFLAGS = $(AM_CPPFLAGS) -DSRC=rgb -DDEST=yiq -DEM=6 -8_nrgb_yuv_SOURCES = conv.cc conv.hh -8_nrgb_yuv_CPPFLAGS = $(AM_CPPFLAGS) -DSRC=nrgb -DDEST=yuv -DEM=6 +8_rgb_yuv_SOURCES = conv.cc conv.hh +8_rgb_yuv_CPPFLAGS = $(AM_CPPFLAGS) -DSRC=rgb -DDEST=yuv -DEM=6 8_rgb_nrgb_SOURCES = conv.cc conv.hh 8_rgb_nrgb_CPPFLAGS = $(AM_CPPFLAGS) -DSRC=rgb -DDEST=nrgb -DEM=6 -8_rgb_xyz_SOURCES = conv.cc conv.hh -8_rgb_xyz_CPPFLAGS = $(AM_CPPFLAGS) -DSRC=rgb -DDEST=xyz -DEM=4 +# 8_rgb_xyz_SOURCES = conv.cc conv.hh +# 8_rgb_xyz_CPPFLAGS = $(AM_CPPFLAGS) -DSRC=rgb -DDEST=xyz -DEM=4 -f_8_nrgb_hsi_SOURCES = convcomp.cc convcomp.hh -f_8_nrgb_hsi_CPPFLAGS = $(AM_CPPFLAGS) -DSRC=nrgb -DDEST=hsi -DEM=17.8723 -DEV=1099.78 +f_8_rgb_hsi_SOURCES = convcomp.cc convcomp.hh +f_8_rgb_hsi_CPPFLAGS = $(AM_CPPFLAGS) -DSRC=rgb -DDEST=hsi -DEM=17.8723 -DEV=1099.78 -f_8_nrgb_hsl_SOURCES = convcomp.cc convcomp.hh -f_8_nrgb_hsl_CPPFLAGS = $(AM_CPPFLAGS) -DSRC=nrgb -DDEST=hsl -DEM=5.90563 -DEV=152.583 +f_8_rgb_hsl_SOURCES = convcomp.cc convcomp.hh +f_8_rgb_hsl_CPPFLAGS = $(AM_CPPFLAGS) -DSRC=rgb -DDEST=hsl -DEM=5.90563 -DEV=152.583 -f_8_nrgb_hsv_SOURCES = convcomp.cc convcomp.hh -f_8_nrgb_hsv_CPPFLAGS = $(AM_CPPFLAGS) -DSRC=nrgb -DDEST=hsv -DEM=1.10193 -DEV=74.3924 +f_8_rgb_hsv_SOURCES = convcomp.cc convcomp.hh +f_8_rgb_hsv_CPPFLAGS = $(AM_CPPFLAGS) -DSRC=rgb -DDEST=hsv -DEM=1.10193 -DEV=74.3924 -f_8_nrgb_xyz_SOURCES = convcomp.cc convcomp.hh -f_8_nrgb_xyz_CPPFLAGS = $(AM_CPPFLAGS) -DSRC=nrgb -DDEST=xyz -DEM=0.952448 -DEV=4.04194 +# f_8_nrgb_xyz_SOURCES = convcomp.cc convcomp.hh +# f_8_nrgb_xyz_CPPFLAGS = $(AM_CPPFLAGS) -DSRC=nrgb -DDEST=xyz -DEM=0.952448 -DEV=4.04194 -f_8_nrgb_yiq_SOURCES = convcomp.cc convcomp.hh -f_8_nrgb_yiq_CPPFLAGS = $(AM_CPPFLAGS) -DSRC=nrgb -DDEST=yiq -DEM=2.11554 -DEV=18.7004 +f_8_rgb_yiq_SOURCES = convcomp.cc convcomp.hh +f_8_rgb_yiq_CPPFLAGS = $(AM_CPPFLAGS) -DSRC=rgb -DDEST=yiq -DEM=2.11554 -DEV=18.7004 -f_8_nrgb_yuv_SOURCES = convcomp.cc convcomp.hh -f_8_nrgb_yuv_CPPFLAGS = $(AM_CPPFLAGS) -DSRC=nrgb -DDEST=yuv -DEM=5.20401 -DEV=1.36447 +f_8_rgb_yuv_SOURCES = convcomp.cc convcomp.hh +f_8_rgb_yuv_CPPFLAGS = $(AM_CPPFLAGS) -DSRC=rgb -DDEST=yuv -DEM=5.20401 -DEV=1.36447 f_8_rgb_nrgb_SOURCES = convcomp.cc convcomp.hh -f_8_rgb_nrgb_CPPFLAGS = $(AM_CPPFLAGS) -DSRC=rgb -DDEST=nrgb -DEM=0.426287 -DEV=1.97667 +f_8_rgb_nrgb_CPPFLAGS = $(AM_CPPFLAGS) -DSRC=rgb -DDEST=nrgb -DEM=0.692094 -DEV=0.329154 f_8_rgb_xyz_SOURCES = convcomp.cc convcomp.hh f_8_rgb_xyz_CPPFLAGS = $(AM_CPPFLAGS) -DSRC=rgb -DDEST=xyz -DEM=0.865949 -DEV=0.356157 Index: olena/oln/Makefile.am --- olena/oln/Makefile.am Thu, 27 Nov 2003 10:33:30 +0100 burrus_n (oln/q/47_Makefile.a 1.3.1.1.1.6.1.6 640) +++ olena/oln/Makefile.am Thu, 22 Jan 2004 17:47:32 +0100 palma_g (oln/q/47_Makefile.a 1.3.1.1.1.6.1.7 640) @@ -25,11 +25,11 @@ convert/conversion_ng_se.hh \ convert/force.hh \ convert/nrgbxyz.hh \ - convert/nrgbyiq.hh \ - convert/nrgbyuv.hh \ - convert/nrgbhsi.hh \ - convert/nrgbhsl.hh \ - convert/nrgbhsv.hh \ + convert/rgbyiq.hh \ + convert/rgbyuv.hh \ + convert/rgbhsi.hh \ + convert/rgbhsl.hh \ + convert/rgbhsv.hh \ convert/rgbnrgb.hh \ convert/rgbxyz.hh \ convert/stretch.hh \ Index: olena/oln/convert/rgbhsv.hh --- olena/oln/convert/rgbhsv.hh Fri, 23 Jan 2004 16:01:31 +0100 palma_g () +++ olena/oln/convert/rgbhsv.hh Thu, 22 Jan 2004 17:35:48 +0100 palma_g (oln/j/35_rgbhsv.hh 1.1 644) @@ -0,0 +1,188 @@ +// 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 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> + +/*-----------------------------------------------------------------. +| The formulas used here come from ``Color Conversion Algorithms'' | +`-----------------------------------------------------------------*/ + +namespace oln { + + using namespace ntg; + + namespace convert { + + 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(); + } + }; + + 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); + } + + 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(); + } + }; + + 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: olena/oln/convert/rgbhsl.hh --- olena/oln/convert/rgbhsl.hh Fri, 23 Jan 2004 16:01:31 +0100 palma_g () +++ olena/oln/convert/rgbhsl.hh Thu, 22 Jan 2004 18:37:35 +0100 palma_g (oln/j/36_rgbhsl.hh 1.1 644) @@ -0,0 +1,185 @@ +// 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 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> + +/*------------------------------------------------------------------. +| The formulas used here come from ``Color space conversion''; Paul | +| Bourke. | +`------------------------------------------------------------------*/ +namespace oln { + + using namespace ntg; + + namespace convert { + 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(); + } + }; + + 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; + } + } + + 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(); + } + }; + + 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: olena/oln/convert/rgbhsi.hh --- olena/oln/convert/rgbhsi.hh Fri, 23 Jan 2004 16:01:31 +0100 palma_g () +++ olena/oln/convert/rgbhsi.hh Thu, 22 Jan 2004 16:39:38 +0100 palma_g (oln/j/37_rgbhsi.hh 1.1 644) @@ -0,0 +1,136 @@ +// 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 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> + +/*--------------------------------------------------------------. +| 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); + + 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(); + } + }; + + 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); + } + + 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(); + } + }; + + 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: olena/oln/convert/rgbyuv.hh --- olena/oln/convert/rgbyuv.hh Fri, 23 Jan 2004 16:01:31 +0100 palma_g () +++ olena/oln/convert/rgbyuv.hh Thu, 22 Jan 2004 16:28:30 +0100 palma_g (oln/j/38_rgbyuv.hh 1.1 644) @@ -0,0 +1,126 @@ +// 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 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> + +/*---------------------------------------------------------------. +| The formulas used here come from ``Colour Space Conversions'', | +| IAdrian Ford and Alan Roberts; August 11,1998. | +`---------------------------------------------------------------*/ + +namespace oln { + + using namespace ntg; + + namespace convert { + + 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(); + } + }; + + 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); + } + + 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(); + } + }; + + 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: olena/oln/convert/rgbyiq.hh --- olena/oln/convert/rgbyiq.hh Fri, 23 Jan 2004 16:01:31 +0100 palma_g () +++ olena/oln/convert/rgbyiq.hh Thu, 22 Jan 2004 16:35:28 +0100 palma_g (oln/j/39_rgbyiq.hh 1.1 644) @@ -0,0 +1,125 @@ +// 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 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> + +/*--------------------------------------------------------------. +| The formulas used here come from ``Digital Image Processing | +| Algorithms and Applications'', I. Pitas; Wiley-Interscience. | +`--------------------------------------------------------------*/ + +namespace oln { + + using namespace ntg; + + namespace convert { + + 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(); + } + }; + + 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); + } + + 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(); + } + }; + + 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: olena/oln/convert/nrgbhsi.hh --- olena/oln/convert/nrgbhsi.hh Thu, 07 Aug 2003 02:08:21 +0200 david (oln/15_nrgbhsi.hh 1.12 640) +++ olena/oln/convert/nrgbhsi.hh Fri, 23 Jan 2004 16:01:31 +0100 palma_g () @@ -1,136 +0,0 @@ -// 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 OLENA_CONVERT_NRGBHSI_HH -# define OLENA_CONVERT_NRGBHSI_HH - -# include <oln/convert/abstract/colorconv.hh> - -# include <ntg/basics.hh> -# include <ntg/color/nrgb.hh> -# include <ntg/color/hsi.hh> - -# include <sstream> - -/*--------------------------------------------------------------. -| 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); - - template<unsigned inbits, unsigned outbits> - struct f_nrgb_to_hsi - : public abstract::color_conversion<3, inbits, nrgb_traits, - 3, outbits, hsi_traits, f_nrgb_to_hsi<inbits, outbits> > - { - color<3, inbits, hsi_traits> - doit(const color<3, outbits, nrgb_traits>& v) const - { - vec<3, float> in = v.to_float(); - vec<3, float> out; - out[hsi_I] = - sqrt3_3 * in[nrgb_R] + sqrt3_3 * in[nrgb_G] + sqrt3_3 * in[nrgb_B]; - const float v1 = inv_sqrt2 * in[nrgb_G] - inv_sqrt2 * in[nrgb_B]; - const float v2 = 2 * inv_sqrt6 * in[nrgb_R] - inv_sqrt6 * in[nrgb_G] - - inv_sqrt6 * in[nrgb_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_nrgb_to_hsi<" << inbits << ", " << outbits << '>'; - s.str(); - } - }; - - template <unsigned inbits, unsigned outbits> - color<3, outbits, hsi_traits> - nrgb_to_hsi(const color<3, inbits, nrgb_traits>& v) - { - f_nrgb_to_hsi<inbits, outbits> f; - - return f(v); - } - - template<unsigned inbits, unsigned outbits> - struct f_hsi_to_nrgb - : public abstract::color_conversion<3, inbits, hsi_traits, - 3, outbits, nrgb_traits, f_hsi_to_nrgb<inbits, outbits> > - { - color<3, outbits, nrgb_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[nrgb_R] = sqrt3_3 * in[hsi_I] + 2 * inv_sqrt6 * v2; - out[nrgb_G] = sqrt3_3 * in[hsi_I] + inv_sqrt2 * v1 - inv_sqrt6 * v2; - out[nrgb_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_nrgb<" << inbits << ", " << outbits << '>'; - s.str(); - } - }; - - template <unsigned inbits, unsigned outbits> - color<3, outbits, nrgb_traits> - hsi_to_nrgb (const color<3, inbits, hsi_traits>& v) - { - f_hsi_to_nrgb<inbits, outbits> f; - - return f(v); - } - - } // convert -} // oln - -#endif // OLENA_CONVERT_NRGBHSI_HH Index: olena/oln/convert/nrgbhsl.hh --- olena/oln/convert/nrgbhsl.hh Wed, 08 Oct 2003 23:36:51 +0200 burrus_n (oln/12_nrgbhsl.hh 1.17 640) +++ olena/oln/convert/nrgbhsl.hh Fri, 23 Jan 2004 16:01:31 +0100 palma_g () @@ -1,187 +0,0 @@ -// 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 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> - -/*------------------------------------------------------------------. -| The formulas used here come from ``Color space conversion''; Paul | -| Bourke. | -`------------------------------------------------------------------*/ - -namespace oln { - - using namespace ntg; - - namespace convert { - - template<unsigned inbits, unsigned outbits> - struct f_nrgb_to_hsl - : public abstract::color_conversion<3, inbits, nrgb_traits, - 3, outbits, hsl_traits, f_nrgb_to_hsl<inbits, outbits> > - { - color<3, outbits, hsl_traits> - doit(const color<3, inbits, nrgb_traits>& v) const - { - vec<3, float> in = v.to_float(); - vec<3, float> out; - - float max_in = ntg::max(in[nrgb_R], std::max(in[nrgb_B], in[nrgb_G])); - float min_in = ntg::min(in[nrgb_R], std::min(in[nrgb_B], in[nrgb_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[nrgb_R]) / diff; - float g_dist = (max_in - in[nrgb_G]) / diff; - float b_dist = (max_in - in[nrgb_B]) / diff; - - if (in[nrgb_R] == max_in) - out[hsl_H] = b_dist - g_dist; - else if(in[nrgb_G] == max_in) - out[hsl_H] = 2 + r_dist - b_dist; - else if(in[nrgb_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_nrgb_to_hsl<" << inbits << ", " << outbits << '>'; - s.str(); - } - }; - - template <unsigned inbits, unsigned outbits> - color<3, inbits, hsl_traits> - nrgb_to_hsl(const color<3, outbits, nrgb_traits>& v) - { - f_nrgb_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; - } - } - - template<unsigned inbits, unsigned outbits> - struct f_hsl_to_nrgb - : public abstract::color_conversion<3, inbits, hsl_traits, - 3, outbits, nrgb_traits, f_hsl_to_nrgb<inbits, outbits> > - { - color<3, outbits, nrgb_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[nrgb_R] = out[nrgb_G] = out[nrgb_B] = in[hsl_L]; - else - { - out[nrgb_R] = internal::RGB(p1, p2, in[hsl_H] + 120); - out[nrgb_G] = internal::RGB(p1, p2, in[hsl_H]); - out[nrgb_B] = internal::RGB(p1, p2, in[hsl_H] - 120); - } - - return out; - } - - static std::string - name() - { - std::ostringstream s; - s << "f_hsl_to_nrgb<" << inbits << ", " << outbits << '>'; - s.str(); - } - }; - - template<unsigned inbits, unsigned outbits> - color<3, outbits, nrgb_traits> - hsl_to_nrgb(const color<3, inbits, hsl_traits>& v) - { - f_hsl_to_nrgb<inbits, outbits> f; - return f(v); - } - - } // convert -} // oln - -#endif // OLENA_CONVERT_NRGBHSL_HH Index: olena/oln/convert/nrgbhsv.hh --- olena/oln/convert/nrgbhsv.hh Thu, 07 Aug 2003 02:08:21 +0200 david (oln/11_nrgbhsv.hh 1.14 640) +++ olena/oln/convert/nrgbhsv.hh Fri, 23 Jan 2004 16:01:31 +0100 palma_g () @@ -1,188 +0,0 @@ -// 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 OLENA_CONVERT_NRGBHSV_HH -# define OLENA_CONVERT_NRGBHSV_HH - -# include <oln/basics.hh> -# include <oln/convert/abstract/colorconv.hh> - -# include <ntg/basics.hh> -# include <ntg/color/nrgb.hh> -# include <ntg/color/hsv.hh> - -# include <mlc/contract.hh> - -# include <sstream> - -/*-----------------------------------------------------------------. -| The formulas used here come from ``Color Conversion Algorithms'' | -`-----------------------------------------------------------------*/ - -namespace oln { - - using namespace ntg; - - namespace convert { - - template<unsigned inbits, unsigned outbits> - struct f_nrgb_to_hsv - : public abstract::color_conversion<3, inbits, nrgb_traits, - 3, outbits, hsv_traits, f_nrgb_to_hsv<inbits, outbits> > - { - color<3, outbits, hsv_traits> - doit(const color<3, inbits, nrgb_traits>& v) const - { - vec<3, float> in = v.to_float(); - vec<3, float> out; - float max_in = std::max(in[nrgb_R], std::max(in[nrgb_B], in[nrgb_G])); - float min_in = std::min(in[nrgb_R], std::min(in[nrgb_B], in[nrgb_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[nrgb_R] == max_in) - out[hsv_H] = (in[nrgb_G] - in[nrgb_B]) / delta; - else if (in[nrgb_G] == max_in) - out[hsv_H] = 2 + (in[nrgb_B] - in[nrgb_R]) / delta; - else - out[hsv_H] = 4 + (in[nrgb_R] - in[nrgb_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_nrgb_to_hsv<" << inbits << ", " << outbits << '>'; - s.str(); - } - }; - - template <unsigned inbits, unsigned outbits> - color<3, outbits, hsv_traits> - nrgb_to_hsv(const color<3, inbits, nrgb_traits>& v) - { - f_nrgb_to_hsv<inbits, outbits> f; - return f(v); - } - - template<unsigned inbits, unsigned outbits> - struct f_hsv_to_nrgb - : public abstract::color_conversion<3, inbits, hsv_traits, - 3, outbits, nrgb_traits, f_hsv_to_nrgb<inbits, outbits> > - { - color<3, outbits, nrgb_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[nrgb_G] = out[nrgb_B] = out[nrgb_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[nrgb_R] = in[hsv_V]; - out[nrgb_G] = t; - out[nrgb_B] = p; - break; - case 1: - out[nrgb_R] = q; - out[nrgb_G] = in[hsv_V]; - out[nrgb_B] = p; - break; - case 2: - out[nrgb_R] = p; - out[nrgb_G] = in[hsv_V]; - out[nrgb_B] = t; - break; - case 3: - out[nrgb_R] = p; - out[nrgb_G] = q; - out[nrgb_B] = in[hsv_V]; - break; - case 4: - out[nrgb_R] = t; - out[nrgb_G] = p; - out[nrgb_B] = in[hsv_V]; - break; - default: - out[nrgb_R] = in[hsv_V]; - out[nrgb_G] = p; - out[nrgb_B] = q; - break; - } - } - return out; - } - - static std::string - name() - { - std::ostringstream s; - s << "f_hsv_to_nrgb<" << inbits << ", " << outbits << '>'; - s.str(); - } - }; - - template <unsigned inbits, unsigned outbits> - color<3, outbits, nrgb_traits> - hsv_to_nrgb(const color<3, inbits, hsv_traits>& v) - { - f_hsv_to_nrgb<inbits, outbits> f; - return f(v); - } - - } // convert -} // oln - -#endif // OLENA_CONVERT_NRGBHSV_HH Index: olena/oln/convert/nrgbyiq.hh --- olena/oln/convert/nrgbyiq.hh Thu, 07 Aug 2003 02:08:21 +0200 david (oln/14_nrgbyiq.hh 1.11 640) +++ olena/oln/convert/nrgbyiq.hh Fri, 23 Jan 2004 16:01:31 +0100 palma_g () @@ -1,125 +0,0 @@ -// 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 OLENA_CONVERT_NRGBYIQ_HH -# define OLENA_CONVERT_NRGBYIQ_HH - -# include <oln/convert/abstract/colorconv.hh> - -# include <ntg/color/nrgb.hh> -# include <ntg/color/yiq.hh> -# include <ntg/basics.hh> - -# include <sstream> - -/*--------------------------------------------------------------. -| The formulas used here come from ``Digital Image Processing | -| Algorithms and Applications'', I. Pitas; Wiley-Interscience. | -`--------------------------------------------------------------*/ - -namespace oln { - - using namespace ntg; - - namespace convert { - - template<unsigned inbits, unsigned outbits> - struct f_nrgb_to_yiq - : public abstract::color_conversion<3, inbits, nrgb_traits, - 3, outbits, yiq_traits, f_nrgb_to_yiq<inbits, outbits> > - { - color<3, inbits, yiq_traits> - doit(const color<3, outbits, nrgb_traits>& v) const - { - vec<3, float> in = v.to_float(); - vec<3, float> out; - out[yiq_Y] = - 0.299 * in[nrgb_R] + 0.587 * in[nrgb_G] + 0.114 * in[nrgb_B]; - out[yiq_I] = - 0.596 * in[nrgb_R] - 0.274 * in[nrgb_G] - 0.322 * in[nrgb_B]; - out[yiq_Q] = - 0.211 * in[nrgb_R] - 0.523 * in[nrgb_G] + 0.312 * in[nrgb_B]; - return out; - } - - static std::string - name() - { - std::ostringstream s; - s << "f_nrgb_to_yiq<" << inbits << ", " << outbits << '>'; - s.str(); - } - }; - - template <unsigned inbits, unsigned outbits> - color<3, outbits, yiq_traits> - nrgb_to_yiq(const color<3, inbits, nrgb_traits>& v) - { - f_nrgb_to_yiq<inbits, outbits> f; - - return f(v); - } - - template<unsigned inbits, unsigned outbits> - struct f_yiq_to_nrgb - : public abstract::color_conversion<3, inbits, yiq_traits, - 3, outbits, nrgb_traits, f_yiq_to_nrgb<inbits, outbits> > - { - color<3, inbits, nrgb_traits> - doit(const color<3, outbits, yiq_traits>& v) const - { - vec<3, float> in = v.to_float(); - vec<3, float> out; - out[nrgb_R] = in[yiq_Y] + 0.95617 * in[yiq_I] + 0.62143 * in[yiq_Q]; - out[nrgb_G] = in[yiq_Y] - 0.27269 * in[yiq_I] - 0.64681 * in[yiq_Q]; - out[nrgb_B] = in[yiq_Y] - 1.10374 * in[yiq_I] + 1.70062 * in[yiq_Q]; - return out; - } - - static std::string - name() - { - std::ostringstream s; - s << "f_yiq_to_nrgb<" << inbits << ", " << outbits << '>'; - s.str(); - } - }; - - template <unsigned inbits, unsigned outbits> - color<3, outbits, nrgb_traits> - yiq_to_nrgb(const color<3, inbits, yiq_traits>& v) - { - f_yiq_to_nrgb<inbits, outbits> f; - - return f(v); - } - - } // convert -} // oln - -#endif // OLENA_CONVERT_NRGBYIQ_HH Index: olena/oln/convert/nrgbyuv.hh --- olena/oln/convert/nrgbyuv.hh Thu, 07 Aug 2003 02:08:21 +0200 david (oln/13_nrgbyuv.hh 1.12 640) +++ olena/oln/convert/nrgbyuv.hh Fri, 23 Jan 2004 16:01:31 +0100 palma_g () @@ -1,126 +0,0 @@ -// 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 OLENA_CONVERT_NRGBYUV_HH -# define OLENA_CONVERT_NRGBYUV_HH - -# include <oln/convert/abstract/colorconv.hh> - -# include <ntg/color/nrgb.hh> -# include <ntg/color/yuv.hh> -# include <ntg/basics.hh> - -# include <sstream> - -/*---------------------------------------------------------------. -| The formulas used here come from ``Colour Space Conversions'', | -| IAdrian Ford and Alan Roberts; August 11,1998. | -`---------------------------------------------------------------*/ - -namespace oln { - - using namespace ntg; - - namespace convert { - - template <unsigned inbits, unsigned outbits> - struct f_nrgb_to_yuv - : public abstract::color_conversion<3, inbits, nrgb_traits, - 3, outbits, yuv_traits, f_nrgb_to_yuv<inbits, outbits> > - { - color<3, outbits, yuv_traits> - doit(const color<3, inbits, nrgb_traits>& v) const - { - vec<3, float> in = v.to_float(); - vec<3, float> out; - out[yuv_Y] = - + 0.299 * in[nrgb_R] + 0.587 * in[nrgb_G] + 0.114 * in[nrgb_B]; - out[yuv_U] = - - 0.147 * in[nrgb_R] - 0.289 * in[nrgb_G] + 0.436 * in[nrgb_B]; - out[yuv_V] = - + 0.615 * in[nrgb_R] - 0.515 * in[nrgb_G] - 0.100 * in[nrgb_B]; - return out; - } - - static std::string - name() - { - std::ostringstream s; - s << "f_nrgb_to_yuv<" << inbits << ", " << outbits << '>'; - s.str(); - } - }; - - template <unsigned inbits, unsigned outbits> - color<3, outbits, yuv_traits> - nrgb_to_yuv(const color<3, inbits, nrgb_traits>& v) - { - f_nrgb_to_yuv<inbits, outbits> f; - - return f(v); - } - - template<unsigned inbits, unsigned outbits> - struct f_yuv_to_nrgb - : public abstract::color_conversion<3, inbits, yuv_traits, - 3, outbits, nrgb_traits, f_yuv_to_nrgb<inbits, outbits> > - { - color<3, outbits, nrgb_traits> - doit(const color<3, inbits, yuv_traits>& v) const - { - vec<3, float> in = v.to_float(); - vec<3, float> out; - out[nrgb_R] = in[yuv_Y] + 1.140 * in[yuv_V]; - out[nrgb_G] = in[yuv_Y] - 0.394 * in[yuv_U] - 0.581 * in[yuv_V]; - out[nrgb_B] = in[yuv_Y] + 2.028 * in[yuv_U]; - - return out; - } - - static std::string - name() - { - std::ostringstream s; - s << "f_yuv_to_nrgb<" << inbits << ", " << outbits << '>'; - s.str(); - } - }; - - template <unsigned inbits, unsigned outbits> - color<3, outbits, nrgb_traits> - yuv_to_nrgb(const color<3, inbits, yuv_traits>& v) - { - f_yuv_to_nrgb<inbits, outbits> f; - - return f(v); - } - - } // convert -} // oln - -#endif // OLENA_CONVERT_NRGBYUV_HH -- Giovanni Palma EPITA - promo 2005 - membre d'EpX - LRDE Mob. : +33 (0)6 60 97 31 74