rgbyiq.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_RGBYIQ_HH
00030 # define OLENA_CONVERT_RGBYIQ_HH
00031 
00032 # include <oln/convert/abstract/colorconv.hh>
00033 
00034 # include <ntg/color/rgb.hh>
00035 # include <ntg/color/yiq.hh>
00036 # include <ntg/basics.hh>
00037 
00038 # include <sstream>
00039 
00045 namespace oln {
00046 
00047   using namespace ntg;
00048 
00049   namespace convert {
00050 
00051     /* Functor for conversion from RGB to YIQ.
00052     **
00053     ** \see f_rgb_to_hsl
00054     */
00055     template<unsigned inbits, unsigned outbits>
00056     struct f_rgb_to_yiq
00057       : public abstract::color_conversion<3, inbits, rgb_traits,
00058                                           3, outbits, yiq_traits, f_rgb_to_yiq<inbits, outbits> >
00059     {
00060       color<3, inbits, yiq_traits>
00061       doit(const color<3, outbits, rgb_traits>& v) const
00062       {
00063         vec<3, float> in = v.to_float();
00064         vec<3, float> out;
00065         out[yiq_Y] =
00066           0.1768 * in[rgb_R] + 0.8130 * in[rgb_G] + 0.0101 * in[rgb_B];
00067         out[yiq_I] =
00068           0.5346 * in[rgb_R] - 0.2461 * in[rgb_G] - 0.1791 * in[rgb_B];
00069         out[yiq_Q] =
00070           0.2474 * in[rgb_R] - 0.6783 * in[rgb_G] + 0.4053 * in[rgb_B];
00071         return out;
00072       }
00073 
00074       static std::string
00075       name()
00076       {
00077         std::ostringstream s;
00078         s << "f_rgb_to_yiq<" << inbits << ", " << outbits << '>';
00079         s.str();
00080       }
00081     };
00082 
00083     /* Conversion from RGB to YIQ.
00084     **
00085     ** \see f_rgb_to_hsl
00086     */
00087     template <unsigned inbits, unsigned outbits>
00088     color<3, outbits, yiq_traits>
00089     rgb_to_yiq(const color<3, inbits, rgb_traits>& v)
00090     {
00091       f_rgb_to_yiq<inbits, outbits> f;
00092 
00093       return f(v);
00094     }
00095 
00096     /* Functor for conversion from YIQ to RGB.
00097     **
00098     ** \see f_rgb_to_hsl
00099     */
00100     template<unsigned inbits, unsigned outbits>
00101     struct f_yiq_to_rgb
00102       : public abstract::color_conversion<3, inbits, yiq_traits,
00103                                           3, outbits, rgb_traits, f_yiq_to_rgb<inbits, outbits> >
00104     {
00105       color<3, inbits, rgb_traits>
00106       doit(const color<3, outbits, yiq_traits>& v) const
00107       {
00108         vec<3, float> in = v.to_float();
00109         vec<3, float> out;
00110         out[rgb_R] = 0.87   * in[yiq_Y] + 1.3223 * in[yiq_I] + 0.5628 * in[yiq_Q];
00111         out[rgb_G] = 1.026  * in[yiq_Y] - 0.2718 * in[yiq_I] - 0.1458 * in[yiq_Q];
00112         out[rgb_B] = 1.186  * in[yiq_Y] - 1.2620 * in[yiq_I] + 1.8795 * in[yiq_Q];
00113         return out;
00114       }
00115 
00116       static std::string
00117       name()
00118       {
00119         std::ostringstream s;
00120         s << "f_yiq_to_rgb<" << inbits << ", " << outbits << '>';
00121         s.str();
00122       }
00123     };
00124 
00125     /* Conversion from YIQ to RGB.
00126     **
00127     ** \see f_rgb_to_hsl
00128     */
00129     template <unsigned inbits, unsigned outbits>
00130     color<3, outbits, rgb_traits>
00131     yiq_to_rgb(const color<3, inbits, yiq_traits>& v)
00132     {
00133       f_yiq_to_rgb<inbits, outbits> f;
00134 
00135       return f(v);
00136     }
00137 
00138   } // convert
00139 } // oln
00140 
00141 #endif // OLENA_CONVERT_RGBYIQ_HH

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