SMIL  0.9.1
DColor.h
1 /*
2  * Copyright (c) 2011-2016, Matthieu FAESSEL and ARMINES
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of Matthieu FAESSEL, or ARMINES nor the
14  * names of its contributors may be used to endorse or promote products
15  * derived from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY
18  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE LIABLE FOR ANY
21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 
30 #ifndef _D_COLOR_H
31 #define _D_COLOR_H
32 
33 
34 #include "Core/include/private/DMultichannelTypes.hpp"
35 
36 #ifdef RGB
37 #undef RGB
38 #endif
39 
40 namespace smil
41 {
42 
43  typedef MultichannelType<UINT8,3> COLOR_UINT8_3;
44  typedef MultichannelArray<UINT8,3> COLOR_UINT8_3_Array;
45 
46  template <>
47  struct ImDtTypes< COLOR_UINT8_3 >
48  {
49  typedef COLOR_UINT8_3 pixelType;
50  typedef COLOR_UINT8_3_Array lineType;
51  typedef COLOR_UINT8_3_Array restrictLineType;
52  typedef lineType* sliceType;
53  typedef sliceType* volType;
54 
56 
57  static inline pixelType min() { return COLOR_UINT8_3(0); }
58  static inline pixelType max() { return COLOR_UINT8_3(255); }
59  static inline size_t cardinal() { return 256*256*256; }
60  static inline lineType createLine(size_t lineLen)
61  {
62  lineType arr;
63  arr.createArrays(lineLen);
64  return arr;
65  }
66  static inline void deleteLine(lineType arr)
67  {
68  arr.deleteArrays();
69  }
70  static inline unsigned long ptrOffset(lineType p, unsigned long n=SIMD_VEC_SIZE) { return (size_t(p.arrays[0])) & (n-1); }
71  static inline std::string toString(const COLOR_UINT8_3 &val)
72  {
73  stringstream str;
74  str << "(";
75  for (UINT i=0;i<2;i++)
76  str << double(val[i]) << ",";
77  str << double(val[2]) << ")";
78  return str.str();
79  }
80  };
81 
82  typedef COLOR_UINT8_3_Array RGBArray;
83 
84  struct RGB
85 #ifndef SWIG
86  : public COLOR_UINT8_3
87 #endif // SWIG
88  {
89 #ifndef SWIG
90  UINT8 &r;
91  UINT8 &g;
92  UINT8 &b;
93 #else
94  UINT8 r;
95  UINT8 g;
96  UINT8 b;
97 #endif // SWIG
98  RGB()
100  r(c[0]), g(c[1]), b(c[2])
101 
102  {
103  }
104  RGB(const UINT &val)
106  r(c[0]), g(c[1]), b(c[2])
107  {
108  }
109  RGB(int _r, int _g, int _b)
110  : MultichannelType<UINT8, 3>(_r,_g,_b),
111  r(c[0]), g(c[1]), b(c[2])
112  {
113  }
114  RGB(const COLOR_UINT8_3 &rhs)
116  r(c[0]), g(c[1]), b(c[2])
117  {
118  }
119  RGB(const RGB &rhs)
121  r(c[0]), g(c[1]), b(c[2])
122  {
123  }
124  virtual ~RGB() {}
125  RGB& operator =(const RGB &rhs)
126  {
127  for (UINT i=0;i<3;i++)
128  c[i] = rhs.value(i);
129  return *this;
130  }
131  void printSelf(ostream &os = std::cout, string ="") const
132  {
133  os << "(" << double(c[0]) << "," << double(c[1]) << "," << double(c[2]) << ")";
134  }
135  };
136 
137 
138 
139 
140  template <>
141  struct ImDtTypes< RGB > : public ImDtTypes< COLOR_UINT8_3>
142  {
143  typedef RGB pixelType;
144  typedef RGBArray lineType;
145  static inline pixelType min() { return RGB(0); }
146  static inline pixelType max() { return RGB(255); }
147  static inline size_t cardinal() { return 256*256*256; }
148  };
149 
150  template <>
151  inline const char *getDataTypeAsString(RGB *) { return "RGB"; }
152 
153 
154 
157 
158  template <>
159  struct ImDtTypes< COLOR_32 >
160  {
161  typedef COLOR_32 pixelType;
162  typedef COLOR_32_Array lineType;
163  typedef lineType* sliceType;
164  typedef sliceType* volType;
165 
166  static inline pixelType min() { return COLOR_32(0); }
167  static inline pixelType max() { return COLOR_32(255); }
168  static inline lineType createLine(size_t lineLen)
169  {
170  lineType arr;
171  arr.createArrays(lineLen);
172  return arr;
173  }
174  static inline void deleteLine(lineType arr)
175  {
176  arr.deleteArrays();
177  }
178  static inline unsigned long ptrOffset(lineType p, unsigned long n=SIMD_VEC_SIZE) { return (size_t(p.arrays[0])) & (n-1); }
179  static inline std::string toString(const COLOR_32 &val)
180  {
181  stringstream str;
182  for (UINT i=0;i<3;i++)
183  str << double(val[i]) << ", ";
184  str << double(val[3]);
185  return str.str();
186  }
187  };
188 
189 } // namespace smil
190 
191 #endif // _D_COLOR_H
192 
Definition: DMultichannelTypes.hpp:42
Definition: DColorConvert.h:38
Definition: DMultichannelTypes.hpp:50
Definition: DTypes.hpp:78
Definition: DColor.h:84