Debian Codegraph @

cextern/healpix/src/cxx/cxxsupport/colour.h

raw
1 /*
2 * This file is part of libcxxsupport.
3 *
4 * libcxxsupport is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * libcxxsupport is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with libcxxsupport; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 /*
20 * libcxxsupport is being developed at the Max-Planck-Institut fuer Astrophysik
21 * and financially supported by the Deutsches Zentrum fuer Luft- und Raumfahrt
22 * (DLR).
23 */
24
25 /*! \file colour.h
26 * Simple class for representing colours. Adapted from RAY++ source code.
27 *
28 * Copyright (C) 2015 Max-Planck-Society
29 * \author Martin Reinecke
30 */
31
32 #ifndef PLANCK_COLOUR_H
33 #define PLANCK_COLOUR_H
34
35 #include <iostream>
36
37 template<typename T> class RGB_tuple
38 {
39 public:
40 T r, g, b;
41
42 RGB_tuple () {}
43 RGB_tuple (T rv, T gv, T bv)
44 : r (rv), g (gv), b (bv) {}
45 template<typename T2> explicit RGB_tuple (const RGB_tuple<T2> &orig)
46 : r(orig.r), g(orig.g), b(orig.b) {}
47
48 const RGB_tuple &operator= (const RGB_tuple &Col2)
49 { r=Col2.r; g=Col2.g; b=Col2.b; return *this; }
50 const RGB_tuple &operator+= (const RGB_tuple &Col2)
51 { r+=Col2.r; g+=Col2.g; b+=Col2.b; return *this; }
52 const RGB_tuple &operator*= (T fac)
53 { r*=fac; g*=fac; b*=fac; return *this; }
54 RGB_tuple operator+ (const RGB_tuple &Col2) const
55 { return RGB_tuple (r+Col2.r, g+Col2.g, b+Col2.b); }
56 RGB_tuple operator- (const RGB_tuple &Col2) const
57 { return RGB_tuple (r-Col2.r, g-Col2.g, b-Col2.b); }
58 template<typename T2> RGB_tuple operator* (T2 factor) const
59 { return RGB_tuple (r*factor, g*factor, b*factor); }
60 template<typename T2> friend inline RGB_tuple operator* (T2 factor,
61 const RGB_tuple &Col)
62 { return RGB_tuple (Col.r*factor, Col.g*factor, Col.b*factor); }
63
64 void Set (T r2, T g2, T b2)
65 { r=r2; g=g2; b=b2; }
66
67 friend std::ostream &operator<< (std::ostream &os, const RGB_tuple &c)
68 {
69 os << "(" << c.r << ", " << c.g << ", " << c.b << ")";
70 return os;
71 }
72 };
73
74 typedef RGB_tuple<float> Colour;
75
76 #endif