FotoSHOCK
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
ColorSpace.hpp
1 /*
2  * Copyright 2011-2013 Lukas Jirkovsky
3  *
4  * This file is part of FotoSHOCKcore.
5  *
6  * FotoSHOCKcore is free software: you can redistribute it and/or modify it
7  * under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, version 3 of the License.
9  *
10  * FotoSHOCKcore is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with FotoSHOCKcore. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef COLORSPACE_H
20 #define COLORSPACE_H
21 
22 #include <lcms2.h>
23 #include <string>
24 
25 namespace FotoSHOCKcore {
26 
28 
38 class ColorSpace {
39 public:
41  enum Enum {value_ANY, value_SAME,
42  value_gray, value_RGB, value_CMY, value_CMYK, value_XYZ, value_Lab, value_YUV, value_HLS, value_HSV};
43 
44  friend class ColorSpaceEnum;
45 
47 
51  : m_ID(value_RGB), m_requiredBands(3), m_cmsFormatter(COLORSPACE_SH(PT_RGB)) {};
53  ColorSpace(const ColorSpace& other) = default;
55  ColorSpace& operator=(const ColorSpace& other) = default;
56 
58  bool operator==(const ColorSpace& other) const {return m_ID == other.m_ID;};
60  bool operator!=(const ColorSpace& other) const {return !(*this == other);};
61 
63 
67  constexpr operator Enum() const {return m_ID;};
68 
70 
73  constexpr int requiredBands() const {return m_requiredBands;};
75 
78  constexpr cmsUInt32Number cmsFormatter() const {return m_cmsFormatter;};
79 protected:
81  constexpr ColorSpace(const Enum v, const unsigned int bands, const cmsUInt32Number formatter)
82  : m_ID(v), m_requiredBands(bands), m_cmsFormatter(formatter) {}
83 private:
84  Enum m_ID;
85  unsigned int m_requiredBands;
86  cmsUInt32Number m_cmsFormatter;
87 };
88 
90 
95 public:
97  static constexpr ColorSpace ANY = ColorSpace(ColorSpace::value_ANY, 0, 0);
99  static constexpr ColorSpace SAME = ColorSpace(ColorSpace::value_SAME, 0, 0);
100 
101  static constexpr ColorSpace gray = ColorSpace(ColorSpace::value_gray, 1, COLORSPACE_SH(PT_GRAY));
102  static constexpr ColorSpace RGB = ColorSpace(ColorSpace::value_RGB, 3, COLORSPACE_SH(PT_RGB));
103  static constexpr ColorSpace CMY = ColorSpace(ColorSpace::value_CMY, 3, COLORSPACE_SH(PT_CMY));
104  static constexpr ColorSpace CMYK = ColorSpace(ColorSpace::value_CMYK, 4, COLORSPACE_SH(PT_CMYK));
105  static constexpr ColorSpace XYZ = ColorSpace(ColorSpace::value_XYZ, 3, COLORSPACE_SH(PT_XYZ));
106  static constexpr ColorSpace Lab = ColorSpace(ColorSpace::value_Lab, 3, COLORSPACE_SH(PT_Lab));
107  static constexpr ColorSpace YUV = ColorSpace(ColorSpace::value_YUV, 3, COLORSPACE_SH(PT_YUV));
108  static constexpr ColorSpace HLS = ColorSpace(ColorSpace::value_HLS, 3, COLORSPACE_SH(PT_HLS));
109  static constexpr ColorSpace HSV = ColorSpace(ColorSpace::value_HSV, 3, COLORSPACE_SH(PT_HSV));
110 };
111 
112 }
113 
114 #endif