Color

API reference

Description

Using rili/color you can convert/aproximate colors between most widely used color definition models and paletes.

Note:

Some of these conversions may be loosy. For example : rili::color::RGB(r, g, b).ansi16().rgb() != rili::color::RGB(r, g, b) because ANSI16 palete holds only 16 different colors while RGB may hold up to 2**24 colors.

Note:

Some of conversions may result in slightly different values even if intermediate model is able theoretically to hold more colors than source model. This is because of finite floating point numbers precision and simplicity of used conversion routines.

Note:

Conversion routines are not implemented in all to all way(this is a lot of work!). Sometimes there is used internally intermediate conversion which may add it own conversion precision bias. For example conversion from HSL to HWB use HCG as bridge:

HWB HSL::hwb() const { return hcg().hwb(); }

If you know how to convert colors directly or with better aproximation/speed than now, please contribute.

Usage example

#include <rili/Color.hpp>
#include <cstdio>
#include <string>

void doSomething(std::uint8_t r, std::uint8_t g, std::uint8_t b){
   const auto xyz = rili::color::RGB(r, g, b).xyz(); // convert RGB color to XYZ color
   ::printf("RGB(%d, %d, %d) -> XYZ(%d, %d, %d)\n", int(r), int(g), int(b), int(xyz.x), int(xyz.y), int(xyz.z));
}

std::string doSomethingElse(double c, double m, double y, double k){
    return rili::color::CMYK(c, m, y, k).css().string(); // aproximate CMYK color to `CSS safe color` and get it name as string
}