| 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 | #ifndef H_GEO_IMAGE_TYPES_COLORMAP_H | ||
| 41 | #define H_GEO_IMAGE_TYPES_COLORMAP_H | ||
| 42 | |||
| 43 | #include <geogram/basic/common.h> | ||
| 44 | #include <geogram/basic/counted.h> | ||
| 45 | #include <geogram/basic/smart_pointer.h> | ||
| 46 | #include <geogram/image/color.h> | ||
| 47 | |||
| 48 | /** | ||
| 49 | * \file geogram/image/colormap.h | ||
| 50 | * \brief Colormap type. | ||
| 51 | */ | ||
| 52 | namespace GEO { | ||
| 53 | |||
| 54 | /******************************************************************/ | ||
| 55 | |||
| 56 | /** | ||
| 57 | * \brief A Colormap. | ||
| 58 | * \details A Colormap is an array of colors, | ||
| 59 | * encoded with one byte per component. | ||
| 60 | */ | ||
| 61 | class GEOGRAM_API Colormap : public Counted { | ||
| 62 | public: | ||
| 63 | |||
| 64 | /** | ||
| 65 | * \brief Type of each cell of the Colormap. | ||
| 66 | */ | ||
| 67 | typedef GenColor<Numeric::uint8> ColorCell ; | ||
| 68 | |||
| 69 | /** | ||
| 70 | * \brief Colormap constructor. | ||
| 71 | * \param[in] size_in number of cells in the Colormap | ||
| 72 | */ | ||
| 73 | Colormap(index_t size_in = 256) ; | ||
| 74 | |||
| 75 | /** | ||
| 76 | * \brief Colormap destructor. | ||
| 77 | */ | ||
| 78 | ~Colormap() override; | ||
| 79 | |||
| 80 | /** | ||
| 81 | * \brief Gets a ColorCell by index. | ||
| 82 | * \param[in] index the index of the ColorCell | ||
| 83 | * \return a const reference to the ColorCell | ||
| 84 | * \pre index < size() | ||
| 85 | */ | ||
| 86 | const ColorCell& color_cell(index_t index) const { | ||
| 87 | geo_assert(index < size_) ; | ||
| 88 | return cells_[index] ; | ||
| 89 | } | ||
| 90 | |||
| 91 | /** | ||
| 92 | * \brief Gets a ColorCell by index. | ||
| 93 | * \param[in] index the index of the ColorCell | ||
| 94 | * \return a modifiable reference to the ColorCell | ||
| 95 | * \pre index < size() | ||
| 96 | */ | ||
| 97 | ✗ | ColorCell& color_cell(index_t index) { | |
| 98 | ✗ | geo_assert(index < size_) ; | |
| 99 | ✗ | return cells_[index] ; | |
| 100 | } | ||
| 101 | |||
| 102 | /** | ||
| 103 | * \brief Gets the size. | ||
| 104 | * \return the number of ColorCells in this Colormap | ||
| 105 | */ | ||
| 106 | index_t size() const { | ||
| 107 | return size_; | ||
| 108 | } | ||
| 109 | |||
| 110 | /** | ||
| 111 | * \brief Sets a color by index and components. | ||
| 112 | * \details The transparency a is left unchanged. | ||
| 113 | * \param[in] index the index | ||
| 114 | * \param[in] r , g , b the components, as single-precision | ||
| 115 | * floating points, between 0.0f, and 1.0f | ||
| 116 | */ | ||
| 117 | void set_color(index_t index, float r, float g, float b) ; | ||
| 118 | |||
| 119 | /** | ||
| 120 | * \brief Sets a color by index and components. | ||
| 121 | * \param[in] index the index | ||
| 122 | * \param[in] r , g , b , a the components, as single-precision | ||
| 123 | * floating points, between 0.0f, and 1.0f | ||
| 124 | */ | ||
| 125 | void set_color(index_t index, float r, float g, float b, float a) ; | ||
| 126 | |||
| 127 | /** | ||
| 128 | * \brief Make a color component linearly interpolate two values | ||
| 129 | * between two given indices. | ||
| 130 | * \param[in] component the index of the component, one of 0,1,2,3 | ||
| 131 | * \param[in] index1 the first index | ||
| 132 | * \param[in] val1 the first value of the component, associated | ||
| 133 | * with \p index1 | ||
| 134 | * \param[in] index2 the second index | ||
| 135 | * \param[in] val2 the second value of the component, associated | ||
| 136 | * with \p index2 | ||
| 137 | */ | ||
| 138 | void color_ramp_component( | ||
| 139 | index_t component, | ||
| 140 | index_t index1, Numeric::uint8 val1, | ||
| 141 | index_t index2, Numeric::uint8 val2 | ||
| 142 | ) ; | ||
| 143 | |||
| 144 | |||
| 145 | /** | ||
| 146 | * \brief Make a color linearly interpolate two values | ||
| 147 | * between two given indices. | ||
| 148 | * \details All components and transparency are updated. | ||
| 149 | * \param[in] index1 the first index | ||
| 150 | * \param[in] c1 the first color, associated with \p index1 | ||
| 151 | * \param[in] index2 the second index | ||
| 152 | * \param[in] c2 the first color, associated with \p index2 | ||
| 153 | */ | ||
| 154 | void color_ramp_rgba( | ||
| 155 | index_t index1, const Color& c1, | ||
| 156 | index_t index2, const Color& c2 | ||
| 157 | ) ; | ||
| 158 | |||
| 159 | /** | ||
| 160 | * \brief Make a color linearly interpolate two values | ||
| 161 | * between two given indices. | ||
| 162 | * \details Only r,g,b are updated. Transparency a is left | ||
| 163 | * unmodified in the concerned color cells. | ||
| 164 | * \param[in] index1 the first index | ||
| 165 | * \param[in] c1 the first color, associated with \p index1 | ||
| 166 | * \param[in] index2 the second index | ||
| 167 | * \param[in] c2 the first color, associated with \p index2 | ||
| 168 | */ | ||
| 169 | void color_ramp_rgb( | ||
| 170 | index_t index1, const Color& c1, | ||
| 171 | index_t index2, const Color& c2 | ||
| 172 | ) ; | ||
| 173 | |||
| 174 | private: | ||
| 175 | ColorCell* cells_ ; | ||
| 176 | index_t size_ ; | ||
| 177 | } ; | ||
| 178 | |||
| 179 | /** | ||
| 180 | * \brief An automatic reference-counted pointer to a Colormap. | ||
| 181 | */ | ||
| 182 | typedef SmartPointer<Colormap> Colormap_var ; | ||
| 183 | |||
| 184 | /************************************************************************/ | ||
| 185 | |||
| 186 | } | ||
| 187 | #endif | ||
| 188 |