Lumitronix_Iflex_Pro_Workshop
Library to interact with the iFlexPro
RgbColorBase.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2 RgbColorBase provides a RGB color object common support
3 
4 Written by Michael C. Miller.
5 
6 I invest time and resources providing this open source code,
7 please support me by dontating (see https://github.com/Makuna)
8 
9 -------------------------------------------------------------------------
10 This file is part of the LUMITRONIX_iFlex_Workshop library.
11 
12 LumitronixIFlexBus is free software: you can redistribute it and/or modify
13 it under the terms of the GNU Lesser General Public License as
14 published by the Free Software Foundation, either version 3 of
15 the License, or (at your option) any later version.
16 
17 LumitronixIFlexBus is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU Lesser General Public License for more details.
21 
22 You should have received a copy of the GNU Lesser General Public
23 License along with LumitronixIFlex. If not, see
24 <http://www.gnu.org/licenses/>.
25 -------------------------------------------------------------------------*/
26 #pragma once
27 
28 struct HslColor;
29 struct HsbColor;
30 struct HtmlColor;
31 struct Rgb16Color;
32 
34 {
35 
36 protected:
37  static float _CalcColor(float p, float q, float t);
38 
39  static void _HslToRgb(const HslColor& color, float* r, float* g, float* b);
40 
41  static void _HsbToRgb(const HsbColor& color, float* r, float* g, float* b);
42 
43  template <typename T_COLOR, typename T_RESULT> static T_RESULT _Compare(
44  const T_COLOR& left,
45  const T_COLOR& right,
46  T_RESULT epsilon)
47  {
48  T_RESULT result = 0;
49  T_RESULT resultAbs = 0;
50 
51  for (size_t elem = 0; elem < T_COLOR::Count; elem++)
52  {
53  T_RESULT delta = static_cast<T_RESULT>(left[elem]) - right[elem];
54  T_RESULT deltaAbs = abs(delta);
55 
56  if (deltaAbs > resultAbs)
57  {
58  resultAbs = deltaAbs;
59  result = delta;
60  }
61  }
62 
63  if (resultAbs > epsilon)
64  {
65  return result;
66  }
67  return 0;
68  }
69 };
Definition: HsbColor.h:35
Definition: HslColor.h:34
Definition: HtmlColor.h:70
Definition: Rgb16Color.h:34
Definition: RgbColorBase.h:34
static float _CalcColor(float p, float q, float t)
Definition: RgbColorBase.cpp:36
static void _HslToRgb(const HslColor &color, float *r, float *g, float *b)
Definition: RgbColorBase.cpp:55
static T_RESULT _Compare(const T_COLOR &left, const T_COLOR &right, T_RESULT epsilon)
Definition: RgbColorBase.h:43
static void _HsbToRgb(const HsbColor &color, float *r, float *g, float *b)
Definition: RgbColorBase.cpp:76