OSSIA
Open Scenario System for Interactive Application
color.hpp
1 #pragma once
2 #include <ossia/network/dataspace/dataspace_base.hpp>
3 #include <ossia/network/domain/domain_base_impl.hpp>
4 // Algorithms taken from http://www.easyrgb.com
5 namespace ossia
6 {
7 
8 struct argb_u;
9 struct color_u;
10 template <typename Impl>
11 struct color_unit
12 {
13  using is_unit = std::true_type;
14  using is_multidimensional = std::true_type;
15  // number of dimensiosn -> decltype(value)::size_value
16  using neutral_unit = argb_u;
17  using concrete_type = Impl;
18  using dataspace_type = color_u;
19 };
20 
21 struct OSSIA_EXPORT argb_u : public color_unit<argb_u>
22 {
23  static constexpr auto text() { constexpr_return(ossia::make_string_array("argb")); }
24 
25  static constexpr auto array_parameters()
26  {
27  constexpr_return(ossia::make_string_view("argb"));
28  }
29 
30  static ossia::vecf_domain<4> domain()
31  {
32  return vecf_domain<4>{
33  ossia::make_vec(0.f, 0.f, 0.f, 0.f), ossia::make_vec(1.f, 1.f, 1.f, 1.f)};
34  }
35 
36  static constexpr auto bounding() { return ossia::bounding_mode::CLIP; }
37 
38  using value_type = vec4f;
39 
40  static constexpr strong_value<neutral_unit>
41  to_neutral(strong_value<concrete_type> self)
42  {
43  return self;
44  }
45 
46  static constexpr value_type from_neutral(strong_value<neutral_unit> self)
47  {
48  return self.dataspace_value;
49  }
50 };
51 
52 struct OSSIA_EXPORT rgba8_u : public color_unit<rgba8_u>
53 {
54  static constexpr auto text() { constexpr_return(ossia::make_string_array("rgba8")); }
55 
56  static constexpr auto array_parameters()
57  {
58  constexpr_return(ossia::make_string_view("rgba"));
59  }
60 
61  using value_type = vec4f;
62 
63  static strong_value<neutral_unit> to_neutral(strong_value<concrete_type> self)
64  {
65  return make_vec(
66  self.dataspace_value[3] / 255.f, self.dataspace_value[0] / 255.f,
67  self.dataspace_value[1] / 255.f, self.dataspace_value[2] / 255.f);
68  }
69 
70  static value_type from_neutral(strong_value<neutral_unit> self)
71  {
72  return make_vec(
73  self.dataspace_value[1] * 255.f, self.dataspace_value[2] * 255.f,
74  self.dataspace_value[3] * 255.f, self.dataspace_value[0] * 255.f);
75  }
76 
77  static ossia::vecf_domain<4> domain()
78  {
79  return vecf_domain<4>{
80  ossia::make_vec(0.f, 0.f, 0.f, 0.f),
81  ossia::make_vec(255.f, 255.f, 255.f, 255.f)};
82  }
83 
84  static constexpr auto bounding() { return ossia::bounding_mode::CLIP; }
85 };
86 
87 struct OSSIA_EXPORT rgba_u : public color_unit<rgba_u>
88 {
89  static constexpr auto text() { constexpr_return(ossia::make_string_array("rgba")); }
90 
91  static constexpr auto array_parameters()
92  {
93  constexpr_return(ossia::make_string_view("rgba"));
94  }
95 
96  using value_type = vec4f;
97 
98  static strong_value<neutral_unit> to_neutral(strong_value<concrete_type> self)
99  {
100  return {
101  self.dataspace_value[3], self.dataspace_value[0], self.dataspace_value[1],
102  self.dataspace_value[2]};
103  }
104 
105  static value_type from_neutral(strong_value<neutral_unit> self)
106  {
107  return {
108  self.dataspace_value[1], self.dataspace_value[2], self.dataspace_value[3],
109  self.dataspace_value[0]};
110  }
111 
112  static ossia::vecf_domain<4> domain()
113  {
114  return vecf_domain<4>{
115  ossia::make_vec(0.f, 0.f, 0.f, 0.f), ossia::make_vec(1.f, 1.f, 1.f, 1.f)};
116  }
117  static constexpr auto bounding() { return ossia::bounding_mode::CLIP; }
118 };
119 
120 struct OSSIA_EXPORT rgb_u : public color_unit<rgb_u>
121 {
122  static constexpr auto text() { constexpr_return(ossia::make_string_array("rgb")); }
123 
124  static constexpr auto array_parameters()
125  {
126  constexpr_return(ossia::make_string_view("rgb"));
127  }
128 
129  using value_type = vec3f;
130 
131  static strong_value<neutral_unit> to_neutral(strong_value<concrete_type> self)
132  {
133  return {
134  1., self.dataspace_value[0], self.dataspace_value[1], self.dataspace_value[2]};
135  }
136 
137  static value_type from_neutral(strong_value<neutral_unit> self)
138  {
139  return {self.dataspace_value[1], self.dataspace_value[2], self.dataspace_value[3]};
140  }
141 
142  static ossia::vecf_domain<3> domain()
143  {
144  return vecf_domain<3>{
145  ossia::make_vec(0.f, 0.f, 0.f), ossia::make_vec(1.f, 1.f, 1.f)};
146  }
147  static constexpr auto bounding() { return ossia::bounding_mode::CLIP; }
148 };
149 
150 struct OSSIA_EXPORT bgr_u : public color_unit<bgr_u>
151 {
152  static constexpr auto text() { constexpr_return(ossia::make_string_array("bgr")); }
153 
154  static constexpr auto array_parameters()
155  {
156  constexpr_return(ossia::make_string_view("bgr"));
157  }
158 
159  using value_type = vec3f;
160 
161  static strong_value<neutral_unit> to_neutral(strong_value<concrete_type> self)
162  {
163  return {
164  1., self.dataspace_value[2], self.dataspace_value[1], self.dataspace_value[0]};
165  }
166 
167  static value_type from_neutral(strong_value<neutral_unit> self)
168  {
169  return {self.dataspace_value[3], self.dataspace_value[2], self.dataspace_value[1]};
170  }
171 
172  static ossia::vecf_domain<3> domain()
173  {
174  return vecf_domain<3>{
175  ossia::make_vec(0.f, 0.f, 0.f), ossia::make_vec(1.f, 1.f, 1.f)};
176  }
177  static constexpr auto bounding() { return ossia::bounding_mode::CLIP; }
178 };
179 
180 struct OSSIA_EXPORT argb8_u : public color_unit<argb8_u>
181 {
182  static constexpr auto text() { constexpr_return(ossia::make_string_array("argb8")); }
183 
184  static constexpr auto array_parameters()
185  {
186  constexpr_return(ossia::make_string_view("argb"));
187  }
188 
189  using value_type = vec4f;
190 
191  static strong_value<neutral_unit> to_neutral(strong_value<concrete_type> self)
192  {
193  return make_vec(
194  self.dataspace_value[0] / 255.f, self.dataspace_value[1] / 255.f,
195  self.dataspace_value[2] / 255.f, self.dataspace_value[3] / 255.f);
196  }
197 
198  static value_type from_neutral(strong_value<neutral_unit> self)
199  {
200  return make_vec(
201  self.dataspace_value[0] * 255.f, self.dataspace_value[1] * 255.f,
202  self.dataspace_value[2] * 255.f, self.dataspace_value[3] * 255.f);
203  }
204 
205  static ossia::vecf_domain<4> domain()
206  {
207  return vecf_domain<4>{
208  ossia::make_vec(0.f, 0.f, 0.f, 0.f),
209  ossia::make_vec(255.f, 255.f, 255.f, 255.f)};
210  }
211  static constexpr auto bounding() { return ossia::bounding_mode::CLIP; }
212 };
213 
214 struct OSSIA_EXPORT hsv_u : public color_unit<hsv_u>
215 {
216  static constexpr auto text() { constexpr_return(ossia::make_string_array("hsv")); }
217 
218  static constexpr auto array_parameters()
219  {
220  constexpr_return(ossia::make_string_view("hsv"));
221  }
222 
223  using value_type = vec3f;
224  static strong_value<neutral_unit> to_neutral(strong_value<concrete_type> self);
225 
226  static value_type from_neutral(strong_value<neutral_unit> self);
227 
228  static ossia::vecf_domain<3> domain()
229  {
230  return vecf_domain<3>{
231  ossia::make_vec(0.f, 0.f, 0.f), ossia::make_vec(1.f, 1.f, 1.f)};
232  }
233  static constexpr auto bounding() { return ossia::bounding_mode::CLIP; }
234 };
235 
236 struct OSSIA_EXPORT hsl_u : public color_unit<hsl_u>
237 {
238  static constexpr auto text() { constexpr_return(ossia::make_string_array("hsl")); }
239 
240  static constexpr auto array_parameters()
241  {
242  constexpr_return(ossia::make_string_view("hsl"));
243  }
244 
245  using value_type = vec3f;
246 
247  static ossia::vecf_domain<3> domain()
248  {
249  return vecf_domain<3>{
250  ossia::make_vec(0.f, 0.f, 0.f), ossia::make_vec(1.f, 1.f, 1.f)};
251  }
252  static constexpr auto bounding() { return ossia::bounding_mode::CLIP; }
253 };
254 
255 struct OSSIA_EXPORT cmy8_u : public color_unit<cmy8_u>
256 {
257  static constexpr auto text() { constexpr_return(ossia::make_string_array("cmy8")); }
258 
259  static constexpr auto array_parameters()
260  {
261  constexpr_return(ossia::make_string_view("cmy"));
262  }
263 
264  using value_type = vec3f;
265 
266  static strong_value<neutral_unit> to_neutral(strong_value<concrete_type> self)
267  {
268  return make_vec(
269  1.f, (255.f - self.dataspace_value[0]) / 255.f,
270  (255.f - self.dataspace_value[1]) / 255.f,
271  (255.f - self.dataspace_value[2]) / 255.f);
272  }
273 
274  static value_type from_neutral(strong_value<neutral_unit> self)
275  {
276  return make_vec(
277  255.f * (1.f - self.dataspace_value[1]), 255.f * (1.f - self.dataspace_value[2]),
278  255.f * (1.f - self.dataspace_value[3]));
279  }
280 
281  static ossia::vecf_domain<3> domain()
282  {
283  return vecf_domain<3>{
284  ossia::make_vec(0.f, 0.f, 0.f), ossia::make_vec(255.f, 255.f, 255.f)};
285  }
286  static constexpr auto bounding() { return ossia::bounding_mode::CLIP; }
287 };
288 
289 struct OSSIA_EXPORT cmyk8_u : public color_unit<cmyk8_u>
290 {
291  static constexpr auto text() { constexpr_return(ossia::make_string_array("cmyk8")); }
292 
293  static constexpr auto array_parameters()
294  {
295  constexpr_return(ossia::make_string_view("cmyk"));
296  }
297 
298  using value_type = vec4f;
299 };
300 
301 struct OSSIA_EXPORT xyz_u : public color_unit<xyz_u>
302 {
303  static constexpr auto text() { constexpr_return(ossia::make_string_array("cie_xyz")); }
304 
305  static constexpr auto array_parameters()
306  {
307  constexpr_return(ossia::make_string_view("xyz"));
308  }
309 
310  using value_type = vec3f;
311 
312  static strong_value<neutral_unit> to_neutral(strong_value<concrete_type> self);
313 
314  static value_type from_neutral(strong_value<neutral_unit> self);
315 
316  static ossia::vecf_domain<3> domain()
317  {
318  return vecf_domain<3>{
319  ossia::make_vec(0.f, 0.f, 0.f), ossia::make_vec(1.f, 1.f, 1.f)};
320  }
321  static constexpr auto bounding() { return ossia::bounding_mode::CLIP; }
322 };
323 
324 struct OSSIA_EXPORT yxy_u : public color_unit<yxy_u>
325 {
326  static constexpr auto text() { constexpr_return(ossia::make_string_array("cie_Yxy")); }
327 
328  static constexpr auto array_parameters()
329  {
330  constexpr_return(ossia::make_string_view("Yxy"));
331  }
332 
333  using value_type = vec3f;
334 
335  static ossia::vecf_domain<3> domain()
336  {
337  return vecf_domain<3>{
338  ossia::make_vec(0.f, 0.f, 0.f), ossia::make_vec(1.f, 1.f, 1.f)};
339  }
340  static constexpr auto bounding() { return ossia::bounding_mode::CLIP; }
341 };
342 
343 struct OSSIA_EXPORT hunter_lab_u : public color_unit<hunter_lab_u>
344 {
345  static constexpr auto text()
346  {
347  constexpr_return(ossia::make_string_array("hunter_lab"));
348  }
349  static constexpr auto array_parameters()
350  {
351  constexpr_return(ossia::make_string_view("lab"));
352  }
353  using value_type = vec3f;
354 
355  static strong_value<neutral_unit> to_neutral(strong_value<concrete_type> self);
356  static value_type from_neutral(strong_value<neutral_unit> self);
357 
358  static ossia::vecf_domain<3> domain()
359  {
360  return vecf_domain<3>{
361  ossia::make_vec(0.f, 0.f, 0.f), ossia::make_vec(1.f, 1.f, 1.f)};
362  }
363  static constexpr auto bounding() { return ossia::bounding_mode::CLIP; }
364 };
365 
366 struct OSSIA_EXPORT cie_lab_u : public color_unit<cie_lab_u>
367 {
368  static constexpr auto text() { constexpr_return(ossia::make_string_array("cie_lab")); }
369  static constexpr auto array_parameters()
370  {
371  constexpr_return(ossia::make_string_view("lab"));
372  }
373  using value_type = vec3f;
374 
375  static ossia::vecf_domain<3> domain()
376  {
377  return vecf_domain<3>{
378  ossia::make_vec(0.f, 0.f, 0.f), ossia::make_vec(1.f, 1.f, 1.f)};
379  }
380  static constexpr auto bounding() { return ossia::bounding_mode::CLIP; }
381 };
382 
383 struct OSSIA_EXPORT cie_luv_u : public color_unit<cie_luv_u>
384 {
385  static constexpr auto text() { constexpr_return(ossia::make_string_array("cie_luv")); }
386  static constexpr auto array_parameters()
387  {
388  constexpr_return(ossia::make_string_view("luv"));
389  }
390  using value_type = vec3f;
391 
392  static ossia::vecf_domain<3> domain()
393  {
394  return vecf_domain<3>{
395  ossia::make_vec(0.f, 0.f, 0.f), ossia::make_vec(1.f, 1.f, 1.f)};
396  }
397  static constexpr auto bounding() { return ossia::bounding_mode::CLIP; }
398 };
399 }
Definition: git_info.h:7
@ CLIP
The bounds are ignored.