itom
Loading...
Searching...
No Matches
helperColor.h
1/* ********************************************************************
2 itom software
3 URL: http://www.uni-stuttgart.de/ito
4 Copyright (C) 2020, Institut für Technische Optik (ITO),
5 Universität Stuttgart, Germany
6
7 This file is part of itom and its software development toolkit (SDK).
8
9 itom is free software; you can redistribute it and/or modify it
10 under the terms of the GNU Library General Public Licence as published by
11 the Free Software Foundation; either version 2 of the Licence, or (at
12 your option) any later version.
13
14 In addition, as a special exception, the Institut für Technische
15 Optik (ITO) gives you certain additional rights.
16 These rights are described in the ITO LGPL Exception version 1.0,
17 which can be found in the file LGPL_EXCEPTION.txt in this package.
18
19 itom is distributed in the hope that it will be useful, but
20 WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library
22 General Public Licence for more details.
23
24 You should have received a copy of the GNU Library General Public License
25 along with itom. If not, see <http://www.gnu.org/licenses/>.
26*********************************************************************** */
27
28#ifndef HELPERCOLOR_H
29#define HELPERCOLOR_H
30
31#include "typeDefs.h"
32
33
34namespace ito
35{
36 namespace colorHelper
37 {
38 inline float32 grayAlpha(const Rgba32_t &in)
39 {
40 return in.gray() * m_value[0];
41 }
42
43 inline void rgb2yuv(const Rgba32_t &in, float32 &Y, float32 &U, float32 &V)
44 {
45 Y = in.gray();
46 U = static_cast<float32>(-0.14713 * in.red() - 0.28886 * in.green() + 0.436 * in.blue());
47 V = static_cast<float32>(0.615 * in.red() - 0.51499 * in.green() - 0.10001 * in.blue());
48 return;
49 }
50
51 inline void rgb2cmyk(const Rgba32_t &in, float32 &C, float32 &M, float32 &Y, float32 &K)
52 {
53 K = (255 - (in.red() > in.blue() ? (in.red() > in.green() ? in.red() : in.green()) : (in.blue() > in.green() ? in.blue() : in.green()))) / 255.0;
54
55 if( fabs(K - 1) < std::numeric_limits<float32>::epsilon())
56 {
57 C = 0.0;
58 M = 0.0;
59 Y = 0.0;
60 }
61 else
62 {
63 C = (1.0 - in.red()/ 255.0 - K) / (1.0 - K);
64 M = (1.0 - in.green()/ 255.0 - K) / (1.0 - K);
65 Y = (1.0 - in.green()/ 255.0 - K) / (1.0 - K);
66 }
67 return;
68 }
69
70
71 template<uint8 _CHANNEL> inline Rgba32_t max(const Rgba32_t &first, const Rgba32_t &second) const
72 {
73 if (((RGBChannel_t<_CHANNEL>)first) > ((RGBChannel_t<_CHANNEL>)second)
74 {
75 return first;
76 }
77 else
78 {
79 return second;
80 }
81 }
82
83 inline Rgba32_t max(const Rgba32_t &first, const Rgba32_t &second, const uint8 &mode)
84 {
85 switch(mode)
86 {
87 case Rgba32_t::RGBA_B:
88 case Rgba32_t::RGBA_G:
89 case Rgba32_t::RGBA_R:
90 case Rgba32_t::RGBA_A:
91 return max<mode>(first, second);
92 break;
93 case Rgba32_t::RGBA_Y:
94 if(first.gray() < second.gray()) return second;
95 else return first;
96 break;
97 default:
98 case Rgba32_t::RGBA_RGB:
99 {
100 uint8 max1 = (first.red() > first.blue() ? (first.red() > first.green() ? first.red() : first.green()) : (first.blue() > first.green() ? first.blue() : first.green()));
101 uint8 max2 = (second.red() > second.blue() ? (second.red() > second.green() ? second.red() : second.green()) : (second.blue() > second.green() ? second.blue() : second.green()));
102 if(max1 < max2) return second;
103 else return first;
104 }
105 break;
106 }
107 }
108
109 } // end namespace colorHelper
110}; // end namespace ito
111
112#endif
Definition apiFunctionsGraph.cpp:40