rgbxyz.hh

Go to the documentation of this file.
00001 // Copyright (C) 2001, 2002, 2003, 2004  EPITA Research and Development Laboratory
00002 //
00003 // This file is part of the Olena Library.  This library is free
00004 // software; you can redistribute it and/or modify it under the terms
00005 // of the GNU General Public License version 2 as published by the
00006 // Free Software Foundation.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU General Public License
00014 // along with this library; see the file COPYING.  If not, write to
00015 // the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
00016 // MA 02111-1307, USA.
00017 //
00018 // As a special exception, you may use this file as part of a free
00019 // software library without restriction.  Specifically, if other files
00020 // instantiate templates or use macros or inline functions from this
00021 // file, or you compile this file and link it with other files to
00022 // produce an executable, this file does not by itself cause the
00023 // resulting executable to be covered by the GNU General Public
00024 // License.  This exception does not however invalidate any other
00025 // reasons why the executable file might be covered by the GNU General
00026 // Public License.
00027 
00028 
00029 #ifndef OLENA_CONVERT_RGBXYZ_HH
00030 # define OLENA_CONVERT_RGBXYZ_HH
00031 
00032 # include <oln/convert/abstract/colorconv.hh>
00033 
00034 # include <ntg/color/rgb.hh>
00035 # include <ntg/color/xyz.hh>
00036 # include <ntg/basics.hh>
00037 
00038 # include <sstream>
00039 
00046 namespace oln {
00047 
00048   using namespace ntg;
00049 
00050   namespace convert {
00051 
00052     /* Functor for conversion from RGB to XYZ.
00053     **
00054     ** \see f_rgb_to_hsl
00055     */
00056     template <unsigned inbits, unsigned outbits>
00057     struct f_rgb_to_xyz
00058       : public abstract::color_conversion<3, inbits, rgb_traits,
00059                                           3, outbits, xyz_traits, f_rgb_to_xyz <inbits, outbits> >
00060     {
00061       color<3, outbits, xyz_traits>
00062       doit(const color<3, inbits, rgb_traits>& v) const
00063       {
00064         vec<3, float> in = v.to_float();
00065         vec<3, float> out;
00066         out[xyz_X] = 0.490 * in[rgb_R] + 0.310 * in[rgb_G] + 0.200 * in[rgb_B];
00067         out[xyz_Y] = 0.177 * in[rgb_R] + 0.812 * in[rgb_G] + 0.011 * in[rgb_B];
00068         out[xyz_Z] =                     0.010 * in[rgb_G] + 0.990 * in[rgb_B];
00069         return out;
00070       }
00071 
00072       static std::string
00073       name()
00074       {
00075         std::ostringstream s;
00076         s << "f_rgb_to_xyz<" << inbits << ", " << outbits << '>';
00077         s.str();
00078       }
00079     };
00080 
00081 
00082     /* Conversion from RGB to XYZ.
00083     **
00084     ** \see f_rgb_to_hsl
00085     */
00086     template <unsigned inbits, unsigned outbits>
00087     color<3, outbits, xyz_traits>
00088     rgb_to_xyz(const color<3, inbits, rgb_traits>& v)
00089     {
00090       f_rgb_to_xyz<inbits, outbits> f;
00091 
00092       return f(v);
00093     }
00094 
00095     /* Functor for conversion from XYZ to RGB
00096     **
00097     ** \see f_rgb_to_hsl
00098     */
00099     template <unsigned inbits, unsigned outbits>
00100     struct f_xyz_to_rgb
00101       : public abstract::color_conversion<3, inbits, xyz_traits,
00102                                           3, outbits, rgb_traits, f_xyz_to_rgb <inbits, outbits> >
00103     {
00104       color<3, outbits, rgb_traits>
00105       doit(const color<3, inbits, xyz_traits>& v) const
00106       {
00107         vec<3, float> in = v.to_float();
00108         vec<3, float> out;
00109         out[rgb_R] =
00110             2.365 * in[xyz_X] - 0.896 * in[xyz_Y] - 0.468 * in[xyz_Z];
00111         out[rgb_G] =
00112           - 0.515 * in[xyz_X] + 1.425 * in[xyz_Y] + 0.089 * in[xyz_Z];
00113         out[rgb_B] =
00114             0.005 * in[xyz_X] - 0.014 * in[xyz_Y] + 1.01 * in[xyz_Z];
00115         return out;
00116       }
00117 
00118       static std::string
00119       name()
00120       {
00121         std::ostringstream s;
00122         s << "f_xyz_to_rgb<" << inbits << ", " << outbits << '>';
00123         s.str();
00124       }
00125     };
00126 
00127     /* Functor for conversion from RGB to XYZ.
00128     **
00129     ** \see f_rgb_to_hsl
00130     */
00131     template <unsigned inbits, unsigned outbits>
00132     color<3, outbits, rgb_traits>
00133     xyz_to_rgb(const color<3, outbits, xyz_traits>& v)
00134     {
00135       f_xyz_to_rgb<inbits, outbits> f;
00136 
00137       return f(v);
00138     }
00139 
00140   } // convert
00141 } // oln
00142 
00143 #endif // OLENA_CONVERT_RGBXYZ_HH

Generated on Thu Apr 15 20:13:14 2004 for Olena by doxygen 1.3.6-20040222