Omnidome
Fulldome Mapping Software Toolkit
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PixelConverter.h
Go to the documentation of this file.
1 /* Copyright (c) 2014-2015 "Omnidome" by cr8tr
2  * Dome Mapping Projection Software (http://omnido.me).
3  * Omnidome was created by Michael Winkelmann aka Wilston Oreo (@WilstonOreo)
4  *
5  * This file is part of Omnidome.
6  *
7  * Omnidome is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU Affero General Public License for more details.
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 #ifndef OMNI_PIXELCONVERTER_H_
20 #define OMNI_PIXELCONVERTER_H_
21 
22 #include <QColor>
23 
24 namespace omni {
25  /// RGBA float pixel type
26  struct RGBAFloat
27  {
28  RGBAFloat() {}
29 
30  RGBAFloat(float r, float g, float b, float a = 1.0) :
31  r(r), g(g), b(b), a(a) {}
32 
33  float r, g, b, a;
34  };
35 
36  /// Template for converting IN pixel type to OUT pixel type
37  template<typename IN, typename OUT>
38  struct PixelConverter {
39  void operator()(IN const& _in, OUT& _out) {}
40  };
41 
42  /// Convert to QColor
43  template<typename IN>
44  struct PixelConverter<IN, QColor>{
45  template<typename T>
46  void operator()(T const& _in, QColor& _out) {
47  int _v = qBound(0, int(255.0 * _in), 255);
48 
49  _out = QColor(_v, _v, _v);
50  }
51  };
52 
53  /// Convert byte value to grayscale QColor
54  template<>
55  struct PixelConverter<uint8_t, QColor>{
56  template<typename T>
57  void operator()(T const& _in, QColor& _out) {
58  _out = QColor(_in, _in, _in);
59  }
60  };
61 
62 
63  /// Convert RGBA to QColor
64  template<>
65  struct PixelConverter<RGBAFloat, QColor>{
66  template<typename T>
67  void operator()(T const& _in, QColor& _out) {
68  _out = QColor(
69  qBound(0.0,_in.r*255.0,255.0),
70  qBound(0.0,_in.g*255.0,255.0),
71  qBound(0.0,_in.b*255.0,255.0),
72  qBound(0.0,_in.a*255.0,255.0));
73  }
74  };
75 
76  /// Convert int value to grayscale QColor
77  template<>
78  struct PixelConverter<int, QColor>: PixelConverter<uint8_t, QColor>{};
79 
80  /// Convert int value to grayscale QColor
81  template<>
82  struct PixelConverter<unsigned int, QColor>: PixelConverter<uint8_t, QColor>{};
83 
84 
85  /// Convert IN to OUT pixel
86  template<typename IN, typename OUT>
87  void convertPixel(const IN& _in, OUT& _out) {
88  PixelConverter<IN, OUT>()(_in, _out);
89  }
90 
91  /// Convert pixel IN to OUT pixel and return OUT
92  template<typename OUT, typename IN>
93  OUT convertPixel(const IN& _in) {
94  OUT _out;
95 
96  convertPixel(_in, _out);
97  return _out;
98  }
99 }
100 
101 #endif /* OMNI_PIXELCONVERTER_H_ */
void operator()(T const &_in, QColor &_out)
Definition: PixelConverter.h:46
float b
Definition: PixelConverter.h:33
RGBAFloat()
Definition: PixelConverter.h:28
void operator()(IN const &_in, OUT &_out)
Definition: PixelConverter.h:39
float r
Definition: PixelConverter.h:33
void operator()(T const &_in, QColor &_out)
Definition: PixelConverter.h:57
void operator()(T const &_in, QColor &_out)
Definition: PixelConverter.h:67
void convertPixel(const IN &_in, OUT &_out)
Convert IN to OUT pixel.
Definition: PixelConverter.h:87
float a
Definition: PixelConverter.h:33
RGBA float pixel type.
Definition: PixelConverter.h:26
float g
Definition: PixelConverter.h:33
RGBAFloat(float r, float g, float b, float a=1.0)
Definition: PixelConverter.h:30
Template for converting IN pixel type to OUT pixel type.
Definition: PixelConverter.h:38