Visual Computing Library
Loading...
Searching...
No Matches
color.h
1/*****************************************************************************
2 * VCLib *
3 * Visual Computing Library *
4 * *
5 * Copyright(C) 2021-2025 *
6 * Visual Computing Lab *
7 * ISTI - Italian National Research Council *
8 * *
9 * All rights reserved. *
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the Mozilla Public License Version 2.0 as published *
13 * by the Mozilla Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 * This program is distributed in the hope that it will be useful, *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19 * Mozilla Public License Version 2.0 *
20 * (https://www.mozilla.org/en-US/MPL/2.0/) for more details. *
21 ****************************************************************************/
22
23#ifndef VCL_CONCEPTS_SPACE_COLOR_H
24#define VCL_CONCEPTS_SPACE_COLOR_H
25
26#include <vclib/concepts/const_correctness.h>
27
28#include <concepts>
29#include <cstdint>
30
31namespace vcl {
32
40template<typename T>
41concept ColorConcept = requires (
42 T&& obj,
43 typename RemoveRef<T>::ColorABGR cABGR,
44 uint32_t u32,
45 uint16_t u16,
46 uint8_t u8,
47 float f,
48 typename RemoveRef<T>::Format fr) {
49 typename RemoveRef<T>::Representation;
50 typename RemoveRef<T>::Format;
51 typename RemoveRef<T>::ColorABGR;
52 typename RemoveRef<T>::ColorMap;
53
54 RemoveRef<T>();
55 RemoveRef<T>(cABGR);
56 RemoveRef<T>(u32, fr);
57 RemoveRef<T>(u8, u8, u8);
58 RemoveRef<T>(u8, u8, u8, u8);
59 RemoveRef<T>(obj);
60
61 { obj.red() } -> std::convertible_to<uint8_t>;
62 { obj.green() } -> std::convertible_to<uint8_t>;
63 { obj.blue() } -> std::convertible_to<uint8_t>;
64 { obj.alpha() } -> std::convertible_to<uint8_t>;
65
66 { obj.redF() } -> std::same_as<float>;
67 { obj.greenF() } -> std::same_as<float>;
68 { obj.blueF() } -> std::same_as<float>;
69 { obj.alphaF() } -> std::same_as<float>;
70
71 { obj.hsvHue() } -> std::same_as<uint8_t>;
72 { obj.hsvSaturation() } -> std::same_as<uint8_t>;
73
74 { obj.hsvHueF() } -> std::same_as<float>;
75 { obj.hsvSaturationF() } -> std::same_as<float>;
76
77 { obj.rgba() } -> std::same_as<uint32_t>;
78 { obj.bgra() } -> std::same_as<uint32_t>;
79 { obj.bgr5() } -> std::same_as<unsigned short>;
80 { obj.rgb5() } -> std::same_as<unsigned short>;
81
82 { obj == obj } -> std::same_as<bool>;
83 { obj != obj } -> std::same_as<bool>;
84 { obj < obj } -> std::same_as<bool>;
85
86 // non const requirements
87 requires IsConst<T> || requires {
88 { obj.red() } -> std::same_as<uint8_t&>;
89 { obj.green() } -> std::same_as<uint8_t&>;
90 { obj.blue() } -> std::same_as<uint8_t&>;
91 { obj.alpha() } -> std::same_as<uint8_t&>;
92
93 { obj.setAlpha(u8) } -> std::same_as<void>;
94 { obj.setRed(u8) } -> std::same_as<void>;
95 { obj.setGreen(u8) } -> std::same_as<void>;
96 { obj.setBlue(u8) } -> std::same_as<void>;
97
98 { obj.setRgb(u8, u8, u8) } -> std::same_as<void>;
99 { obj.setRgb(u8, u8, u8, u8) } -> std::same_as<void>;
100 { obj.set(u32, fr) } -> std::same_as<void>;
101 { obj.setAbgr(u32) } -> std::same_as<void>;
102 { obj.setArgb(u32) } -> std::same_as<void>;
103 { obj.setRgba(u32) } -> std::same_as<void>;
104 { obj.setBgra(u32) } -> std::same_as<void>;
105 { obj.setBgr5(u16) } -> std::same_as<void>;
106 { obj.setRgb5(u16) } -> std::same_as<void>;
107 { obj.setHsv(u8, u8, u8) } -> std::same_as<void>;
108 { obj.setHsv(u8, u8, u8, u8) } -> std::same_as<void>;
109
110 { obj.setAlphaF(f) } -> std::same_as<void>;
111 { obj.setRedF(f) } -> std::same_as<void>;
112 { obj.setGreenF(f) } -> std::same_as<void>;
113 { obj.setBlueF(f) } -> std::same_as<void>;
114 { obj.setRgbF(f, f, f) } -> std::same_as<void>;
115 { obj.setRgbF(f, f, f, f) } -> std::same_as<void>;
116 { obj.setHsvF(f, f, f) } -> std::same_as<void>;
117 { obj.setHsvF(f, f, f, f) } -> std::same_as<void>;
118 };
119};
120
121} // namespace vcl
122
123#endif // VCL_CONCEPTS_SPACE_COLOR_H
ColorConcept is satisfied only if a class provides the member functions specified in this concept....
Definition color.h:41
The IsConst concept is satisfied if T satisfies one of the following conditions:
Definition const_correctness.h:43