qualpal 2.3.0
Loading...
Searching...
No Matches
qualpal.h
Go to the documentation of this file.
1
23#pragma once
24
25#include <map>
26#include <optional>
27#include <qualpal/colors.h>
28#include <qualpal/metrics.h>
29#include <vector>
30
35namespace qualpal {
36
46{
47 HSL,
48 LCHab
49};
50
62{
63public:
67 Qualpal() = default;
68
74 Qualpal& setInputRGB(const std::vector<colors::RGB>& colors);
75
82 Qualpal& setInputHex(const std::vector<std::string>& colors);
83
90 Qualpal& setInputPalette(const std::string& palette_name);
91
101 Qualpal& setInputColorspace(const std::array<double, 2>& h_lim,
102 const std::array<double, 2>& s_lim,
103 const std::array<double, 2>& l_lim,
104 ColorspaceType space = ColorspaceType::HSL);
105
112 Qualpal& setCvd(const std::map<std::string, double>& cvd_params);
113
120
127
135
142 Qualpal& setColorspaceSize(std::size_t n_points);
143
151 std::vector<colors::RGB> generate(std::size_t n);
152
160 std::vector<colors::RGB> extend(const std::vector<colors::RGB>& palette,
161 std::size_t n);
162
163private:
164 std::vector<colors::RGB> selectColors(
165 std::size_t n,
166 const std::vector<colors::RGB>& fixed_palette = {});
167
168 std::vector<colors::RGB> rgb_colors_in;
169
170 std::vector<std::string> hex_colors;
171
172 std::string palette;
173
174 std::array<double, 2> h_lim = { 0, 360 };
175 std::array<double, 2> s_or_c_lim = { 0, 1 };
176 std::array<double, 2> l_lim = { 0, 1 };
177 std::size_t n_points = 100;
178
182 enum class Mode
183 {
184 NONE,
185 RGB,
186 HEX,
187 PALETTE,
188 COLORSPACE
189 } mode = Mode::NONE;
190
191 std::map<std::string, double> cvd;
192 std::optional<colors::RGB> bg;
194 double max_memory = 1;
195 ColorspaceType colorspace_input = ColorspaceType::HSL;
196};
197
198} // namespace qualpal
Builder for qualitative color palette generation.
Definition qualpal.h:62
Qualpal & setInputRGB(const std::vector< colors::RGB > &colors)
Set input colors from a vector of RGB values.
Qualpal & setInputColorspace(const std::array< double, 2 > &h_lim, const std::array< double, 2 > &s_lim, const std::array< double, 2 > &l_lim, ColorspaceType space=ColorspaceType::HSL)
Set input colors by sampling HSL colorspace.
Qualpal & setColorspaceSize(std::size_t n_points)
Set the number of points in the colorspace grid for HSL input.
Qualpal & setMetric(metrics::MetricType metric)
Set the color difference metric to use.
Qualpal & setInputPalette(const std::string &palette_name)
Set input colors from a named palette.
std::vector< colors::RGB > generate(std::size_t n)
Generate a qualitative color palette with the configured options.
Qualpal & setMemoryLimit(double gb)
Set the maximum memory limit (in GB) for color difference matrix.
std::vector< colors::RGB > extend(const std::vector< colors::RGB > &palette, std::size_t n)
Extend an existing palette by adding n new colors.
Qualpal & setBackground(const colors::RGB &bg_color)
Set the background color for palette generation.
Qualpal()=default
Default constructor. Initializes with no input source.
Qualpal & setInputHex(const std::vector< std::string > &colors)
Set input colors from a vector of hex color strings.
Qualpal & setCvd(const std::map< std::string, double > &cvd_params)
Set color vision deficiency simulation parameters.
RGB color representation with values in [0,1] range.
Definition colors.h:84
Color representation classes.
Color difference metrics for qualpal.
MetricType
Supported color difference metrics for palette generation.
Definition metrics.h:83
@ DIN99d
DIN99d color difference.
Qualitative color palette generation library.
Definition analyze.h:19
ColorspaceType
Supported cylindrical color spaces for input colors.
Definition qualpal.h:46