supertux
colorspace_oklab.hpp
1 // Copyright (c) 2021
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a copy of
4 // this software and associated documentation files (the "Software"), to deal in
5 // the Software without restriction, including without limitation the rights to
6 // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7 // of the Software, and to permit persons to whom the Software is furnished to do
8 // so, subject to the following conditions:
9 //
10 // The above copyright notice and this permission notice shall be included in all
11 // copies or substantial portions of the Software.
12 //
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19 // SOFTWARE.
20 
21 
22 class Color;
23 
24 struct ColorOKLCh final {
25  ColorOKLCh(float pL, float pC, float ph) : L(pL), C(pC), h(ph) {}
26 
27  // Convert an non-linear sRGB colour to OKLab's LCh
28  ColorOKLCh(Color& c);
29 
30  // Convert to non-linear sRGB; clip_chroma is applied if required.
31  Color to_srgb() const;
32 
33  // Find the maximum chroma which is still representable in sRGB while the
34  // lightness and hue are preserved
35  float get_maximum_chroma() const;
36 
37  // Find the maximum chroma which is still representable in sRGB while the
38  // hue is preserved
39  float get_maximum_chroma_any_l() const;
40 
41  // Reduce the chroma so that the colour can be represented in sRGB.
42  // Also clamp the lightness if needed.
43  void clip_chroma();
44 
45  // Change the lightness so that the colour can be represented in sRGB.
46  void clip_lightness();
47 
48  // Changes both the lightness and chroma so that the colour can be represented
49  // in sRGB. The resulting colour should have less visual distance to the true
50  // colour than colour produced by clipping only chroma or lightness.
51  void clip_adaptive_L0_L_cusp(float alpha=0.05f);
52 
53  float L, C, h;
54 };
55 
56 /* EOF */
Definition: colorspace_oklab.hpp:24
Definition: color.hpp:26