Zivid C++ API 2.11.1+de9b5dae-1
Color.h
Go to the documentation of this file.
1/*******************************************************************************
2 * This file is part of the Zivid API
3 *
4 * Copyright 2015-2024 (C) Zivid AS
5 * All rights reserved.
6 *
7 * Zivid Software License, v1.0
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
18 *
19 * 3. Neither the name of Zivid AS nor the names of its contributors may be used
20 * to endorse or promote products derived from this software without specific
21 * prior written permission.
22 *
23 * 4. This software, with or without modification, must not be used with any
24 * other 3D camera than from Zivid AS.
25 *
26 * 5. Any software provided in binary form under this license must not be
27 * reverse engineered, decompiled, modified and/or disassembled.
28 *
29 * THIS SOFTWARE IS PROVIDED BY ZIVID AS "AS IS" AND ANY EXPRESS OR IMPLIED
30 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
31 * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
32 * DISCLAIMED. IN NO EVENT SHALL ZIVID AS OR CONTRIBUTORS BE LIABLE FOR ANY
33 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
35 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
36 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 *
40 * Contact: Zivid Customer Success Team <customersuccess@zivid.com>
41 * Info: http://www.zivid.com
42 ******************************************************************************/
43
44#pragma once
45
48
49#include <cstdint>
50#include <iosfwd>
51#include <string>
52#include <type_traits>
53
54namespace Zivid
55{
56#ifndef NO_DOC
58 namespace Detail
59 {
60 ZIVID_CORE_EXPORT std::string rgbaIntsToString(int r, int g, int b, int a);
61 ZIVID_CORE_EXPORT std::string bgraIntsToString(int b, int g, int r, int a);
62
63 template<typename T>
64 std::string rgbaToString(T r, T g, T b, T a)
65 {
66 return rgbaIntsToString(static_cast<int>(r), static_cast<int>(g), static_cast<int>(b), static_cast<int>(a));
67 }
68
69 template<typename T>
70 std::string bgraToString(T b, T g, T r, T a)
71 {
72 return bgraIntsToString(static_cast<int>(b), static_cast<int>(g), static_cast<int>(r), static_cast<int>(a));
73 }
74 } // namespace Detail
75#endif
76
77 struct ColorBGRA;
78
79 template<typename T>
81 {
83 using ValueType = T;
84
86 ColorRGBABase() = default;
87
89 ColorRGBABase(T red, T green, T blue, T alpha)
90 : r{ red }
91 , g{ green }
92 , b{ blue }
93 , a{ alpha }
94 {}
95
97 T r;
98
100 T g;
101
103 T b;
104
106 T a;
107
110
113
115 std::string toString() const
116 {
117 return Detail::rgbaToString(r, g, b, a);
118 }
119 };
120
122 template<typename T>
123 std::ostream &operator<<(std::ostream &stream, const ColorRGBABase<T> &color)
124 {
125 return stream << color.toString();
126 }
127
139 struct ColorSRGB : public ColorRGBABase<uint8_t>
140 {
142 };
143
145
156 struct ColorRGBA : public ColorRGBABase<uint8_t>
157 {
159 };
160
162
163 template<typename T>
165 {
167 using ValueType = T;
168
170 ColorBGRABase() = default;
171
173 ColorBGRABase(T blue, T green, T red, T alpha)
174 : b{ blue }
175 , g{ green }
176 , r{ red }
177 , a{ alpha }
178 {}
179
181 T b;
182
184 T g;
185
187 T r;
188
190 T a;
191
194
197
199 std::string toString() const
200 {
201 return Detail::bgraToString(b, g, r, a);
202 }
203 };
204
206 template<typename T>
207 std::ostream &operator<<(std::ostream &stream, const ColorBGRABase<T> &color)
208 {
209 return stream << color.toString();
210 }
211
222 struct ColorBGRA : public ColorBGRABase<uint8_t>
223 {
225 };
226
228
229} // namespace Zivid
#define ZIVID_CORE_EXPORT
Definition CoreExport.h:56
#define ZIVID_STATIC_ASSERT_DATA_FORMAT_TYPE(Type, size)
Definition DataFormatUtils.h:48
The main Zivid namespace. All Zivid code is found here.
Definition Application.h:54
std::ostream & operator<<(std::ostream &stream, const Array2D< T > &array)
Serialize array information to a stream.
Definition Array2D.h:285
Definition Color.h:165
ColorBGRABase(T blue, T green, T red, T alpha)
Constructor.
Definition Color.h:173
T g
Green channel.
Definition Color.h:184
ColorBGRABase()=default
Constructor.
T a
Alpha channel.
Definition Color.h:190
T ValueType
The type of the channel values.
Definition Color.h:167
T r
Red channel.
Definition Color.h:187
ZIVID_CORE_EXPORT bool operator!=(const ColorBGRABase &rhs) const
Check for inequality.
ZIVID_CORE_EXPORT bool operator==(const ColorBGRABase &rhs) const
Check for equality.
T b
Blue channel.
Definition Color.h:181
std::string toString() const
Get string representation.
Definition Color.h:199
Color with 8-bit blue, green, red and alpha channels.
Definition Color.h:223
Definition Color.h:81
T ValueType
The type of the channel values.
Definition Color.h:83
std::string toString() const
Get string representation.
Definition Color.h:115
T g
Green channel.
Definition Color.h:100
ColorRGBABase()=default
Constructor.
T a
Alpha channel.
Definition Color.h:106
T r
Red channel.
Definition Color.h:97
ZIVID_CORE_EXPORT bool operator==(const ColorRGBABase &rhs) const
Check for equality.
ZIVID_CORE_EXPORT bool operator!=(const ColorRGBABase &rhs) const
Check for inequality.
T b
Blue channel.
Definition Color.h:103
ColorRGBABase(T red, T green, T blue, T alpha)
Constructor.
Definition Color.h:89
Color with 8-bit red, green, blue and alpha channels.
Definition Color.h:157
Color with 8-bit red, green, blue and alpha channels in the sRGB color space.
Definition Color.h:140