| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * Copyright (c) 2000-2022 Inria | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * Redistribution and use in source and binary forms, with or without | ||
| 6 | * modification, are permitted provided that the following conditions are met: | ||
| 7 | * | ||
| 8 | * * Redistributions of source code must retain the above copyright notice, | ||
| 9 | * this list of conditions and the following disclaimer. | ||
| 10 | * * Redistributions in binary form must reproduce the above copyright notice, | ||
| 11 | * this list of conditions and the following disclaimer in the documentation | ||
| 12 | * and/or other materials provided with the distribution. | ||
| 13 | * * Neither the name of the ALICE Project-Team nor the names of its | ||
| 14 | * contributors may be used to endorse or promote products derived from this | ||
| 15 | * software without specific prior written permission. | ||
| 16 | * | ||
| 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
| 18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | ||
| 21 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
| 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
| 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
| 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
| 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
| 27 | * POSSIBILITY OF SUCH DAMAGE. | ||
| 28 | * | ||
| 29 | * Contact: Bruno Levy | ||
| 30 | * | ||
| 31 | * https://www.inria.fr/fr/bruno-levy | ||
| 32 | * | ||
| 33 | * Inria, | ||
| 34 | * Domaine de Voluceau, | ||
| 35 | * 78150 Le Chesnay - Rocquencourt | ||
| 36 | * FRANCE | ||
| 37 | * | ||
| 38 | */ | ||
| 39 | |||
| 40 | |||
| 41 | #ifndef H_OGF_IMAGE_TYPES_COLOR_H | ||
| 42 | #define H_OGF_IMAGE_TYPES_COLOR_H | ||
| 43 | |||
| 44 | #include <geogram/basic/common.h> | ||
| 45 | #include <geogram/basic/geometry.h> | ||
| 46 | |||
| 47 | /** | ||
| 48 | * \file geogram/image/color.h | ||
| 49 | * \brief Color types. | ||
| 50 | */ | ||
| 51 | namespace GEO { | ||
| 52 | |||
| 53 | /** | ||
| 54 | * \brief A generic color type. | ||
| 55 | * \tparam T type of the components | ||
| 56 | */ | ||
| 57 | template <class T> class GenColor : public vecng<4,T> { | ||
| 58 | public: | ||
| 59 | /** | ||
| 60 | * \brief The superclass type. | ||
| 61 | */ | ||
| 62 | typedef vecng<4,T> superclass; | ||
| 63 | |||
| 64 | /** | ||
| 65 | * \brief GenColor copy constructor | ||
| 66 | * \param[in] rhs the GenColor to be copied. | ||
| 67 | */ | ||
| 68 | ✗ | inline GenColor(const superclass& rhs) : superclass(rhs) { | |
| 69 | } | ||
| 70 | |||
| 71 | /** | ||
| 72 | * \brief GenColor constructor from T array. | ||
| 73 | * \param[in] rhs a pointer to an array of 4 Ts | ||
| 74 | */ | ||
| 75 | inline GenColor(const T* rhs) : superclass(rhs) { | ||
| 76 | } | ||
| 77 | |||
| 78 | /** | ||
| 79 | * \brief GenColor constructor from 4 parameters. | ||
| 80 | * \param[in] r , g , b , a the components of the color | ||
| 81 | */ | ||
| 82 | inline GenColor( | ||
| 83 | T r=0, T g=0, T b=0, T a=1 | ||
| 84 | ):superclass(r,g,b,a) { | ||
| 85 | ✗ | } | |
| 86 | |||
| 87 | /** | ||
| 88 | * \brief assignment operator. | ||
| 89 | * \param[in] rhs the GenColor to be copied | ||
| 90 | * \return the new value of this GenColor after assignment | ||
| 91 | */ | ||
| 92 | inline GenColor& operator=(const superclass& rhs) { | ||
| 93 | superclass::operator=(rhs); | ||
| 94 | return *this; | ||
| 95 | } | ||
| 96 | |||
| 97 | /** | ||
| 98 | * \brief Gets the red component. | ||
| 99 | * \return the value of the red component | ||
| 100 | */ | ||
| 101 | T r() const { | ||
| 102 | ✗ | return superclass::x; | |
| 103 | } | ||
| 104 | |||
| 105 | /** | ||
| 106 | * \brief Gets the green component. | ||
| 107 | * \return the value of the green component | ||
| 108 | */ | ||
| 109 | T g() const { | ||
| 110 | ✗ | return superclass::y; | |
| 111 | } | ||
| 112 | |||
| 113 | /** | ||
| 114 | * \brief Gets the blue component. | ||
| 115 | * \return the value of the blue component | ||
| 116 | */ | ||
| 117 | T b() const { | ||
| 118 | ✗ | return superclass::z; | |
| 119 | } | ||
| 120 | |||
| 121 | /** | ||
| 122 | * \brief Gets the alpha component (transparency). | ||
| 123 | * \return the value of the alpha component | ||
| 124 | */ | ||
| 125 | T a() const { | ||
| 126 | ✗ | return superclass::w; | |
| 127 | } | ||
| 128 | |||
| 129 | /** | ||
| 130 | * \brief Sets the red component. | ||
| 131 | * \param[in] r the value of the red component | ||
| 132 | */ | ||
| 133 | void set_r(T r) { | ||
| 134 | ✗ | superclass::x = r; | |
| 135 | } | ||
| 136 | |||
| 137 | /** | ||
| 138 | * \brief Sets the green component. | ||
| 139 | * \param[in] g the value of the green component | ||
| 140 | */ | ||
| 141 | void set_g(T g) { | ||
| 142 | ✗ | superclass::y = g; | |
| 143 | } | ||
| 144 | |||
| 145 | /** | ||
| 146 | * \brief Sets the blue component. | ||
| 147 | * \param[in] b the value of the blue component | ||
| 148 | */ | ||
| 149 | void set_b(T b) { | ||
| 150 | ✗ | superclass::z = b; | |
| 151 | } | ||
| 152 | |||
| 153 | /** | ||
| 154 | * \brief Sets the alpha component (transparency). | ||
| 155 | * \param[in] a the value of the alpha component | ||
| 156 | */ | ||
| 157 | void set_a(T a) { | ||
| 158 | ✗ | superclass::w = a; | |
| 159 | } | ||
| 160 | |||
| 161 | }; | ||
| 162 | |||
| 163 | /** | ||
| 164 | * \brief Default representation of colors. | ||
| 165 | * \details r,g,b,a components are double-precision | ||
| 166 | * number between 0.0 and 1.0. | ||
| 167 | */ | ||
| 168 | typedef GenColor<Numeric::float64> Color; | ||
| 169 | |||
| 170 | /** | ||
| 171 | * \brief Constructs a color from hue, saturation and lightness | ||
| 172 | * \param[in] h hue, in [0.0,1.0] | ||
| 173 | * \param[in] s saturation, in [0.0,1.0] | ||
| 174 | * \param[in] l lightness, in [0.0,1.0] | ||
| 175 | * \return a Color encoded in r,g,b with double-precision numbers. Alpha | ||
| 176 | * component is set to 1.0 | ||
| 177 | */ | ||
| 178 | Color GEOGRAM_API make_color_from_hsl(double h, double s, double l); | ||
| 179 | |||
| 180 | /** | ||
| 181 | * \brief Constructs a random color | ||
| 182 | * \param[in] min_h , max_h range for hue (use [0.0, 1.0] for whole spectrum) | ||
| 183 | * \param[in] min_s , max_s range for saturation, in [0.0, 1.0] | ||
| 184 | * \param[in] min_l , max_l range for lightness, in [0.0, 1.0] | ||
| 185 | */ | ||
| 186 | Color GEOGRAM_API make_random_color( | ||
| 187 | double min_h=0.0, double max_h=1.0, | ||
| 188 | double min_s=0.165, double max_s=0.4, | ||
| 189 | double min_l=0.4, double max_l=0.8 | ||
| 190 | ); | ||
| 191 | } | ||
| 192 | |||
| 193 | #endif | ||
| 194 |