nrgbxyz.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_NRGBXYZ_HH
00030 # define OLENA_CONVERT_NRGBXYZ_HH
00031 
00032 # include <oln/convert/abstract/colorconv.hh>
00033 
00034 # include <ntg/color/nrgb.hh>
00035 # include <ntg/color/xyz.hh>
00036 # include <ntg/basics.hh>
00037 
00038 # include <sstream>
00039 
00046 namespace oln {
00047 
00048   // FIXME: should it be removed?
00049   using namespace ntg;
00050 
00051   namespace convert {
00052 
00082     template <unsigned inbits, unsigned outbits>
00083     struct f_nrgb_to_xyz
00084       : public abstract::color_conversion<3, inbits, nrgb_traits,
00085                                           3, outbits, xyz_traits, f_nrgb_to_xyz<inbits, outbits> >
00086     {
00087       color<3, outbits, xyz_traits>
00088       doit(const color<3, inbits, nrgb_traits>& v) const
00089       {
00090         vec<3, float> in = v.to_float();
00091         vec<3, float> out;
00092         out[xyz_X] =
00093           0.606734 * in[nrgb_R] + 0.173564 * in[nrgb_G] + 0.200112 * in[nrgb_B];
00094 
00095         out[xyz_Y] =
00096           0.298839 * in[nrgb_R] + 0.586811 * in[nrgb_G] + 0.114350 * in[nrgb_B];
00097 
00098         out[xyz_Z] =
00099                                   0.0661196 * in[nrgb_G] + 1.11491 * in[nrgb_B];
00100 
00101         return out;
00102       }
00103 
00104       static std::string
00105       name()
00106       {
00107         std::ostringstream s;
00108         s << "f_nrgb_to_xyz<" << inbits << ", " << outbits << '>';
00109         s.str();
00110       }
00111     };
00112 
00119     template <unsigned inbits, unsigned outbits>
00120     color<3, outbits, xyz_traits>
00121     nrgb_to_xyz(const color<3, inbits, nrgb_traits>& v)
00122     {
00123       f_nrgb_to_xyz<inbits, outbits> f;
00124 
00125       return f(v);
00126     }
00127 
00134     template<unsigned inbits, unsigned outbits>
00135     struct f_xyz_to_nrgb
00136       : public abstract::color_conversion<3, inbits, xyz_traits,
00137                                           3, outbits, nrgb_traits, f_xyz_to_nrgb<inbits, outbits> >
00138     {
00139       color<3, outbits, nrgb_traits>
00140       doit(const color<3, inbits, xyz_traits>& v) const
00141       {
00142         vec<3, float> in = v.to_float();
00143         vec<3, float> out;
00144         out[nrgb_R] =
00145             1.91049 * in[xyz_X] - 0.532592 * in[xyz_Y] - 0.288284 * in[xyz_Z];
00146         out[nrgb_G] =
00147           - 0.984310 * in[xyz_X] + 1.99845 * in[xyz_Y] - 0.0282980 * in[xyz_Z];
00148         out[nrgb_B] =
00149             0.0583744 * in[xyz_X] - 0.118518 * in[xyz_Y] + 0.898611 * in[xyz_Z];
00150         return out;
00151       }
00152 
00153       static std::string
00154       name()
00155       {
00156         std::ostringstream s;
00157         s << "f_xyz_to_nrgb<" << inbits << ", " << outbits << '>';
00158         s.str();
00159       }
00160     };
00161 
00162 
00169     template <unsigned inbits, unsigned outbits>
00170     color<3, outbits, nrgb_traits>
00171     xyz_to_nrgb(const color<3, inbits, xyz_traits>& v)
00172     {
00173       f_xyz_to_nrgb<inbits, outbits> f;
00174 
00175       return f(v);
00176     }
00177 
00178   } // convert
00179 } // oln
00180 
00181 #endif // OLENA_CONVERT_NRGBXYZ_HH

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