qualpal::Qualpal
C++ · cpp · 4.1.0
Builder for qualitative color palette generation.
The Qualpal class allows step-by-step configuration of palette generation options. Users can set the input source (RGB, hex, palette name, or HSL colorspace), color vision deficiency simulation parameters, background color, color difference metric, and memory limit. The palette is generated by calling generate().
Methods
Qualpal
Source: include/qualpal/qualpal.h
= defaultDefault constructor. Initializes with no input source.
extend
Source: include/qualpal/qualpal.h
std::vector<colors::RGB> Extend an existing palette by adding n new colors.
Parameters
palette
Existing palette (RGB colors) to keep fixed.
n
Total size of the new palette to generate, including existing colors. In other words, the new palette will have n colors.
Returns
Vector of palette + n new RGB colors.
generate
Source: include/qualpal/qualpal.h
std::vector<colors::RGB> Generate a qualitative color palette with the configured options.
Parameters
n
Number of colors to generate.
Returns
Vector of n selected RGB colors, each channel in [0, 1].
Throws
std::runtime_error
if no input source is configured.
std::invalid_argument
for invalid configuration.
setBackground
Source: include/qualpal/qualpal.h
Qualpal & Set the background color for palette generation.
Parameters
bg_color
RGB background color.
Returns
Reference to this object for chaining.
setColorspaceSize
Source: include/qualpal/qualpal.h
Qualpal & Set the number of points in the colorspace grid for HSL and LCHab input.
Parameters
n_points
Number of points to sample in the colorspace grid.
Returns
Reference to this object for chaining.
Throws
std::invalid_argument
if n_points <= 0.
setCvd
Source: include/qualpal/qualpal.h
Qualpal & Set color vision deficiency simulation parameters.
Parameters
cvd_params
Map of CVD type to severity, e.g., {{"protan", 0.5}, {"deutan", 0.2}}. Valid keys: "protan", "deutan", "tritan". Severity must be in [0, 1].
Returns
Reference to this object for chaining.
Throws
std::invalid_argument
if an invalid key or out-of-range severity is provided.
setInputColorspace
Source: include/qualpal/qualpal.h
Qualpal & Set input colors by sampling a colorspace (HSL or LCHab).
Parameters
h_lim
Hue range in degrees [-360, 360].
s_or_c_lim
Saturation or Chroma (depending on ColorspaceType) range [0, 1] or >= 0.
l_lim
Lightness range [0, 1] or [0, 100].
space
Colorspace type
Returns
Reference to this object for chaining.
Throws
std::invalid_argument
for invalid ranges.
setInputColorspaceRegions
Source: include/qualpal/qualpal.h
Qualpal & Set input colors by sampling multiple regions in a colorspace.
Parameters
regions
Vector of colorspace regions to sample from. Regions may overlap, which will increase sampling density in overlapping areas.
space
Colorspace type (HSL or LCHab)
Returns
Reference to this object for chaining.
Throws
std::invalid_argument
if regions is empty or any region has invalid ranges.
// Sample from warm and cool colors only
qualpal::Qualpal qp;
qp.;
auto palette = qp.;setInputHex
Source: include/qualpal/qualpal.h
Qualpal & Set input colors from a vector of hex color strings.
Parameters
colors
Vector of hex color strings (e.g., "#ff0000").
Returns
Reference to this object for chaining.
Throws
std::invalid_argument
if any hex string is invalid.
setInputPalette
Source: include/qualpal/qualpal.h
Qualpal & Set input colors from a named palette.
Parameters
palette_name
Palette name in the format "Package:Palette".
Returns
Reference to this object for chaining.
Throws
std::invalid_argument
if the palette name is invalid.
setInputRGB
Source: include/qualpal/qualpal.h
Qualpal & Set input colors from a vector of RGB values.
Parameters
colors
Vector of RGB colors to use as input. Each channel should be in [0, 1].
Returns
Reference to this object for chaining.
setMemoryLimit
Source: include/qualpal/qualpal.h
Qualpal & Set the maximum memory limit (in GB) for color difference matrix.
Parameters
gb
Memory limit in gigabytes.
Returns
Reference to this object for chaining.
Throws
std::invalid_argument
if gb <= 0.
setMetric
Source: include/qualpal/qualpal.h
Qualpal & Set the color difference metric to use.
Parameters
metric
Metric type (e.g., DIN99d).
Returns
Reference to this object for chaining.
setRefinementStarts
Source: include/qualpal/qualpal.h
Qualpal & Configure the post-discrete continuous refinement step.
Experimental. When n_starts > 0, generate() runs continuous local refinement after the discrete farthest-points selection, shifting each non-fixed palette point in CIE L*a*b* to maximize its minimum CIEDE2000 distance to the others. With n_starts > 1, the refinement is run from additional random seeds (in-region, in-gamut) and the best palette is kept — this escapes basins where the discrete warm start was suboptimal.
Refinement only takes effect when the input source is a colorspace region (HSL or LCHab); for fixed input sets (RGB/hex/named palettes) the output must come from the input set, so refinement is skipped.
Parameters
n_starts
0 disables refinement; 1 single-start (warm start from the discrete selection); ≥2 multi-start (warm start + random extras). Default is 5.
Returns
Reference to this object for chaining.
Throws
std::invalid_argument
if n_starts is negative.
setWhitePoint
setWhitePoint
Source: include/qualpal/qualpal.h
Qualpal & Set the reference white point for color conversions.
Parameters
wp
White point enum value (D65, D50, D55, A, or E).
Returns
Reference to this object for chaining.
setWhitePoint
Source: include/qualpal/qualpal.h
Qualpal & Set the reference white point using custom XYZ values.
Parameters
white_point
Custom XYZ tristimulus values for the white point.
Returns
Reference to this object for chaining.
