itom 2.2.1
K:/git-itom/sources/itom/common/helperColor.h
00001 /* ********************************************************************
00002     itom software
00003     URL: http://www.uni-stuttgart.de/ito
00004     Copyright (C) 2016, Institut fuer Technische Optik (ITO),
00005     Universitaet Stuttgart, Germany
00006 
00007     This file is part of itom and its software development toolkit (SDK).
00008 
00009     itom is free software; you can redistribute it and/or modify it
00010     under the terms of the GNU Library General Public Licence as published by
00011     the Free Software Foundation; either version 2 of the Licence, or (at
00012     your option) any later version.
00013    
00014     In addition, as a special exception, the Institut fuer Technische
00015     Optik (ITO) gives you certain additional rights.
00016     These rights are described in the ITO LGPL Exception version 1.0,
00017     which can be found in the file LGPL_EXCEPTION.txt in this package.
00018 
00019     itom is distributed in the hope that it will be useful, but
00020     WITHOUT ANY WARRANTY; without even the implied warranty of
00021     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library
00022     General Public Licence for more details.
00023 
00024     You should have received a copy of the GNU Library General Public License
00025     along with itom. If not, see <http://www.gnu.org/licenses/>.
00026 *********************************************************************** */
00027 
00028 #ifndef HELPERCOLOR_H
00029 #define HELPERCOLOR_H
00030 
00031 #include "typeDefs.h"
00032 
00033 
00034 namespace ito
00035 {
00036     namespace colorHelper
00037     {
00038         inline float32 grayAlpha(const Rgba32_t &in) 
00039         {
00040             return in.gray() * m_value[0];
00041         }
00042 
00043         inline void rgb2yuv(const Rgba32_t &in, float32 &Y, float32 &U, float32 &V)
00044         {
00045             Y = in.gray();
00046             U = static_cast<float32>(-0.14713 * in.red() - 0.28886 * in.green() + 0.436 * in.blue());
00047             V = static_cast<float32>(0.615 * in.red() - 0.51499 * in.green() - 0.10001 * in.blue());
00048             return;
00049         }
00050 
00051         inline void rgb2cmyk(const Rgba32_t &in, float32 &C, float32 &M, float32 &Y, float32 &K) 
00052         {
00053             K = (255 - (in.red() > in.blue() ? (in.red() > in.green() ? in.red() : in.green()) : (in.blue() > in.green() ? in.blue() : in.green()))) / 255.0;
00054             
00055             if( fabs(K - 1) < std::numeric_limits<float32>::epsilon())
00056             {
00057                 C = 0.0;
00058                 M = 0.0;
00059                 Y = 0.0;
00060             }
00061             else
00062             {
00063                 C = (1.0 - in.red()/ 255.0 - K) / (1.0 - K);
00064                 M = (1.0 - in.green()/ 255.0 - K) / (1.0 - K);
00065                 Y = (1.0 - in.green()/ 255.0 - K) / (1.0 - K);
00066             }
00067             return;
00068         }
00069 
00070 
00071         template<uint8 _CHANNEL> inline Rgba32_t max(const Rgba32_t &first, const Rgba32_t &second) const
00072         {
00073             if (((RGBChannel_t<_CHANNEL>)first) > ((RGBChannel_t<_CHANNEL>)second)
00074             {
00075                 return first;
00076             }
00077             else
00078             {
00079                 return second;
00080             }
00081         }
00082 
00083         inline Rgba32_t max(const Rgba32_t &first, const Rgba32_t &second, const uint8 &mode)
00084         {
00085             switch(mode)
00086             {
00087                 case Rgba32_t::RGBA_B:
00088                 case Rgba32_t::RGBA_G:
00089                 case Rgba32_t::RGBA_R:
00090                 case Rgba32_t::RGBA_A:
00091                     return max<mode>(first, second);
00092                 break;
00093                 case Rgba32_t::RGBA_Y:
00094                     if(first.gray() < second.gray()) return second;
00095                     else return first;
00096                 break;
00097                 default:
00098                 case Rgba32_t::RGBA_RGB:
00099                 {
00100                     uint8 max1 = (first.red() > first.blue() ? (first.red() > first.green() ? first.red() : first.green()) : (first.blue() > first.green() ? first.blue() : first.green()));
00101                     uint8 max2 = (second.red() > second.blue() ? (second.red() > second.green() ? second.red() : second.green()) : (second.blue() > second.green() ? second.blue() : second.green()));
00102                     if(max1 < max2) return second;
00103                     else return first;
00104                 }
00105                 break;
00106             }
00107         }
00108 
00109     }   // end namespace colorHelper
00110 };   // end namespace ito
00111 
00112 #endif
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Properties Friends