rgbnrgb.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_RGBNRGB_HH
00030 # define OLENA_CONVERT_RGBNRGB_HH
00031 
00032 # include <oln/convert/abstract/colorconv.hh>
00033 
00034 # include <ntg/color/rgb.hh>
00035 # include <ntg/color/nrgb.hh>
00036 # include <ntg/basics.hh>
00037 
00038 # include <sstream>
00039 
00046 namespace oln {
00047 
00048   using namespace ntg;
00049 
00050   namespace convert {
00051 
00056     template<unsigned inbits, unsigned outbits>
00057     struct f_rgb_to_nrgb
00058       : public abstract::color_conversion<3, inbits, rgb_traits,
00059                                           3, outbits, nrgb_traits, f_rgb_to_nrgb<inbits, outbits> >
00060     {
00061       color<3, outbits, nrgb_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[nrgb_R] =
00067           + 0.8417270*in[rgb_R] + 0.1560987*in[rgb_G] + 0.0906747*in[rgb_B];
00068         out[nrgb_G] =
00069           - 0.1290152*in[rgb_R] + 1.3189264*in[rgb_G] - 0.2031832*in[rgb_B];
00070         out[nrgb_B] =
00071           + 0.0074943*in[rgb_R] - 0.0688480*in[rgb_G] + 0.8972327*in[rgb_B];
00072         return out;
00073       }
00074 
00075       static std::string
00076       name()
00077       {
00078         std::ostringstream s;
00079         s << "f_rgb_to_nrgb<" << inbits << ", " << outbits << '>';
00080         s.str();
00081       }
00082     };
00083 
00088     template <unsigned inbits, unsigned outbits>
00089     color<3, outbits, nrgb_traits>
00090     rgb_to_nrgb(const color<3, inbits, rgb_traits>& v)
00091     {
00092       f_rgb_to_nrgb<inbits, outbits> f;
00093 
00094       return f(v);
00095     }
00096 
00101     template <unsigned inbits, unsigned outbits>
00102     struct f_nrgb_to_rgb
00103       : public abstract::color_conversion<3, inbits, nrgb_traits,
00104                                           3, outbits, rgb_traits, f_nrgb_to_rgb<inbits, outbits> >
00105     {
00106       color<3, outbits, rgb_traits>
00107       doit(const color<3, inbits, nrgb_traits>& v) const
00108       {
00109         vec<3, float> in = v.to_float();
00110         vec<3, float> out;
00111         out[rgb_R] =
00112           + 1.167 * in[nrgb_R] - 0.146 * in[nrgb_G] - 0.151 * in[nrgb_B];
00113         out[rgb_G] =
00114           + 0.114 * in[nrgb_R] + 0.753 * in[nrgb_G] + 0.159 * in[nrgb_B];
00115         out[rgb_B] =
00116           - 0.001 * in[nrgb_R] + 0.059 * in[nrgb_G] + 1.128 * in[nrgb_B];
00117         return out;
00118       }
00119 
00120       static std::string
00121       name()
00122       {
00123         std::ostringstream s;
00124         s << "f_nrgb_to_rgb<" << inbits << ", " << outbits << '>';
00125         s.str();
00126       }
00127     };
00128 
00133     template <unsigned inbits, unsigned outbits>
00134     color<3, outbits, rgb_traits>
00135     nrgb_to_rgb(const color<3, inbits, nrgb_traits>& v)
00136     {
00137       f_nrgb_to_rgb<inbits, outbits> f;
00138 
00139       return f(v);
00140     }
00141 
00142   } // convert
00143 } // oln
00144 
00145 #endif // OLENA_CONVERT_RGBNRGB_HH

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