UFO 1.0.0
An Efficient Probabilistic 3D Mapping Framework That Embraces the Unknown
Loading...
Searching...
No Matches
rgb.hpp
1
45#ifndef UFO_VISION_COLOR_RGB_HPP
46#define UFO_VISION_COLOR_RGB_HPP
47
48// UFO
49#include <ufo/vision/color/flags.hpp>
50
51// STL
52#include <concepts>
53#include <cstdint>
54#include <format>
55#include <ostream>
56
57namespace ufo
58{
73template <class T = float, ColorFlags Flags = ColorFlags::None>
74 requires(std::integral<T> || std::floating_point<T>)
75struct Rgb;
76
85template <class T>
86 requires(std::integral<T> || std::floating_point<T>)
94 T red;
95
103
111
119 [[nodiscard]] friend constexpr bool operator==(Rgb const& a,
120 Rgb const& b) noexcept = default;
121};
122
130template <class T>
131 requires(std::integral<T> || std::floating_point<T>)
140
148
156
164
172 [[nodiscard]] friend constexpr bool operator==(Rgb const& a,
173 Rgb const& b) noexcept = default;
174};
175
184template <class T>
185 requires(std::integral<T> || std::floating_point<T>)
194
202
210
214 float weight;
215
223 [[nodiscard]] friend constexpr bool operator==(Rgb const& a,
224 Rgb const& b) noexcept = default;
225};
226
235template <class T>
236 requires(std::integral<T> || std::floating_point<T>)
245
253
261
269
273 float weight;
274
282 [[nodiscard]] friend constexpr bool operator==(Rgb const& a,
283 Rgb const& b) noexcept = default;
284};
285
292template <class T, ColorFlags Flags>
293[[nodiscard]] constexpr T red(Rgb<T, Flags> color) noexcept
294{
295 if constexpr (weightset(Flags) && std::floating_point<T>) {
296 return color.red / static_cast<T>(color.weight);
297 } else {
298 return color.red;
299 }
300}
301
308template <class T, ColorFlags Flags>
309[[nodiscard]] constexpr T green(Rgb<T, Flags> color) noexcept
310{
311 if constexpr (weightset(Flags) && std::floating_point<T>) {
312 return color.green / static_cast<T>(color.weight);
313 } else {
314 return color.green;
315 }
316}
317
324template <class T, ColorFlags Flags>
325[[nodiscard]] constexpr T blue(Rgb<T, Flags> color) noexcept
326{
327 if constexpr (weightset(Flags) && std::floating_point<T>) {
328 return color.blue / static_cast<T>(color.weight);
329 } else {
330 return color.blue;
331 }
332}
333
338
343
348
353
358
363
368
373
380template <class T, ColorFlags Flags>
381inline std::ostream& operator<<(std::ostream& out, Rgb<T, Flags> const& c)
382{
383 out << "Red: " << +c.red << " Green: " << +c.green << " Blue: " << +c.blue;
384 if constexpr (alphaset(Flags)) {
385 out << " Alpha: " << +c.alpha;
386 }
387 if constexpr (weightset(Flags)) {
388 out << " Weight: " << c.weight;
389 }
390 return out;
391}
392
396} // namespace ufo
397
401template <class T, ufo::ColorFlags Flags>
402struct std::formatter<ufo::Rgb<T, Flags>> {
403 constexpr auto parse(std::format_parse_context& ctx) { return ctx.begin(); }
404
405 auto format(ufo::Rgb<T, Flags> const& c, std::format_context& ctx) const
406 {
407 auto out = std::format_to(ctx.out(), "Red: {} Green: {} Blue: {}", +c.red, +c.green,
408 +c.blue);
409 if constexpr (ufo::alphaset(Flags)) {
410 out = std::format_to(out, " Alpha: {}", +c.alpha);
411 }
412 if constexpr (ufo::weightset(Flags)) {
413 out = std::format_to(out, " Weight: {}", c.weight);
414 }
415 return out;
416 }
417};
418
419#endif // UFO_VISION_COLOR_RGB_HPP
consteval bool alphaset(ColorFlags flags) noexcept
Returns true if the Alpha flag is set.
Definition flags.hpp:114
consteval bool weightset(ColorFlags flags) noexcept
Returns true if the Weight flag is set.
Definition flags.hpp:122
All vision-related classes and functions.
Definition cloud.hpp:49
constexpr T b(Lab< T, Flags > color) noexcept
Returns the un-weighted blue–yellow axis value.
Definition lab.hpp:326
constexpr T green(Lrgb< T, Flags > color) noexcept
Returns the un-weighted green channel value.
Definition lrgb.hpp:309
constexpr T a(Lab< T, Flags > color) noexcept
Returns the un-weighted green–red axis value.
Definition lab.hpp:310
constexpr T blue(Lrgb< T, Flags > color) noexcept
Returns the un-weighted blue channel value.
Definition lrgb.hpp:325
constexpr T red(Lrgb< T, Flags > color) noexcept
Returns the un-weighted red channel value.
Definition lrgb.hpp:293
friend constexpr bool operator==(Rgb const &a, Rgb const &b) noexcept=default
Returns true if a and b are equal.
float weight
Accumulation weight (positive).
Definition rgb.hpp:273
T green
Green channel (possibly pre-multiplied by weight).
Definition rgb.hpp:252
T alpha
Alpha channel (possibly pre-multiplied by weight).
Definition rgb.hpp:268
friend constexpr bool operator==(Rgb const &a, Rgb const &b) noexcept=default
Returns true if a and b are equal.
T blue
Blue channel (possibly pre-multiplied by weight).
Definition rgb.hpp:260
T red
Red channel (possibly pre-multiplied by weight).
Definition rgb.hpp:244
friend constexpr bool operator==(Rgb const &a, Rgb const &b) noexcept=default
Returns true if a and b are equal.
T blue
Blue channel (possibly pre-multiplied by weight).
Definition rgb.hpp:209
T green
Green channel (possibly pre-multiplied by weight).
Definition rgb.hpp:201
T red
Red channel (possibly pre-multiplied by weight).
Definition rgb.hpp:193
friend constexpr bool operator==(Rgb const &a, Rgb const &b) noexcept=default
Returns true if a and b are equal.
float weight
Accumulation weight (positive).
Definition rgb.hpp:214
Gamma-encoded sRGB color.
Definition rgb.hpp:75