itom 1.4.0
|
00001 /* ******************************************************************** 00002 itom software 00003 URL: http://www.uni-stuttgart.de/ito 00004 Copyright (C) 2013, Institut für Technische Optik (ITO), 00005 Universität 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 für 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 inline void rgb2yuv(const Rgba32_t &in, float32 &Y, float32 &U, float32 &V) 00043 { 00044 Y = in.gray(); 00045 U = static_cast<float32>(-0.14713 * in.red() - 0.28886 * in.green() + 0.436 * in.blue()); 00046 V = static_cast<float32>(0.615 * in.red() - 0.51499 * in.green() - 0.10001 * in.blue()); 00047 return; 00048 } 00049 00050 inline void rgb2cmyk(const Rgba32_t &in, float32 &C, float32 &M, float32 &Y, float32 &K) 00051 { 00052 K = (255 - (in.red() > in.blue() ? (in.red() > in.green() ? in.red() : in.green()) : (in.blue() > in.green() ? in.blue() : in.green()))) / 255.0; 00053 00054 if( fabs(K - 1) < std::numeric_limits<float32>::epsilon()) 00055 { 00056 C = 0.0; 00057 M = 0.0; 00058 Y = 0.0; 00059 } 00060 else 00061 { 00062 C = (1.0 - in.red()/ 255.0 - K) / (1.0 - K); 00063 M = (1.0 - in.green()/ 255.0 - K) / (1.0 - K); 00064 Y = (1.0 - in.green()/ 255.0 - K) / (1.0 - K); 00065 } 00066 return; 00067 } 00068 00069 00070 template<uint8 _CHANAL> inline Rgba32_t max(const Rgba32_t &first, const Rgba32_t &second) const 00071 { 00072 if(((RGBChannel_t<_CHANAL>)first) > ((RGBChannel_t<_CHANAL>)second) 00073 { 00074 return first; 00075 } 00076 else 00077 { 00078 return second; 00079 } 00080 } 00081 00082 inline Rgba32_t max(const Rgba32_t &first, const Rgba32_t &second, const uint8 &mode) 00083 { 00084 switch(mode) 00085 { 00086 case Rgba32_t::RGBA_B: 00087 case Rgba32_t::RGBA_G: 00088 case Rgba32_t::RGBA_R: 00089 case Rgba32_t::RGBA_A: 00090 return max<mode>(first, second); 00091 break; 00092 case Rgba32_t::RGBA_Y: 00093 if(first.gray() < second.gray()) return second; 00094 else return first; 00095 break; 00096 default: 00097 case Rgba32_t::RGBA_RGB: 00098 { 00099 uint8 max1 = (first.red() > first.blue() ? (first.red() > first.green() ? first.red() : first.green()) : (first.blue() > first.green() ? first.blue() : first.green())); 00100 uint8 max2 = (second.red() > second.blue() ? (second.red() > second.green() ? second.red() : second.green()) : (second.blue() > second.green() ? second.blue() : second.green())); 00101 if(max1 < max2) return second; 00102 else return first; 00103 } 00104 break; 00105 } 00106 } 00107 00108 } // end namespace colorHelper 00109 }; // end namespace ito 00110 00111 #endif