10#ifndef SEEN_COLORS_COLOR_H
11#define SEEN_COLORS_COLOR_H
28 Color(std::shared_ptr<Space::AnySpace> space, std::vector<double> colors);
30 explicit Color(uint32_t color,
bool alpha =
true);
32 static std::optional<Color>
parse(
char const *value);
33 static std::optional<Color>
parse(std::string
const &value);
34 static std::optional<Color>
ifValid(
Space::Type space_type, std::vector<double> values);
41 void setValues(std::vector<double> values);
44 double get(
unsigned int index)
const;
45 bool set(
unsigned int index,
double value);
46 bool set(
Color const &other,
bool keep_space =
true);
47 bool set(std::string
const &parsable,
bool keep_space =
true);
48 bool set(uint32_t rgba,
bool opacity =
true);
58 unsigned int getPin(
unsigned int channel)
const;
67 bool convert(std::shared_ptr<Space::AnySpace> space);
70 std::optional<Color>
converted(std::shared_ptr<Space::AnySpace> to_space)
const;
73 std::string
toString(
bool opacity =
true)
const;
74 uint32_t
toRGBA(
double opacity = 1.0)
const;
75 uint32_t
toARGB(
double opacity = 1.0)
const;
76 uint32_t
toABGR(
double opacity = 1.0)
const;
81 bool isOutOfGamut(std::shared_ptr<Space::AnySpace> other)
const;
90 void average(
Color const &other,
double pos = 0.5,
unsigned int pin = 0);
93 void invert(
unsigned int pin);
95 void jitter(
double force,
unsigned int pin = 0);
102 template <
typename Func>
105 bool _isnear(std::vector<double>
const &other,
double epsilon = 0.001)
const;
114 char const *
what() const noexcept
override {
return _msg.c_str(); }
char const * what() const noexcept override
ColorError(std::string &&msg)
bool convert(Color const &other)
Convert to the same format as the other color.
bool isOutOfGamut(std::shared_ptr< Space::AnySpace > other) const
Return true if this color would be out of gamut when converted to another space.
static std::optional< Color > ifValid(Space::Type space_type, std::vector< double > values)
Construct a color from the space type and values, if the values are valid.
bool _isnear(std::vector< double > const &other, double epsilon=0.001) const
Returns true if the values are near to the other values.
uint32_t toARGB(double opacity=1.0) const
Return the RGBA int32 as an ARGB format number.
double stealOpacity()
Get the opacity, and remove it from this color.
std::string toString(bool opacity=true) const
Format the color as a css string and return it.
double difference(Color const &other) const
Get the mean square difference between this color and another.
unsigned int getOpacityChannel() const
Get the opacity channel index.
Color normalized() const
Return a normalized copy of this color so the values are within acceptable ranges.
bool operator==(Color const &other) const
Return true if the two colors are the same.
void _color_mutate_inplace(Color const &other, unsigned int pin, Func avgFunc)
void setValues(std::vector< double > values)
Set the channels directly without checking if the space is correct.
bool addOpacity(double opacity=1.0)
uint32_t toRGBA(double opacity=1.0) const
Return an sRGB conversion of the color in RGBA int32 format.
bool setOpacity(double opacity)
Set the opacity of this color object.
bool isClose(Color const &other, double epsilon=EPSILON) const
Find out if a color is a close match to another color of the same type.
bool isSimilar(Color const &other, double epsilon=EPSILON) const
Find out if a color is similar to another color, converting it first if it's a different type.
void enableOpacity(bool enabled)
Enables or disables the opacity channel.
Color averaged(Color const &other, double pos=0.5) const
Return the average between this and another color.
void compose(Color const &other)
Put the other color on top of this color, mixing the two according to the alpha.
std::optional< Color > converted(Color const &other) const
Return a copy of this color converted to the same format as the other color.
double operator[](unsigned int index) const
void normalize()
Make sure the values for this color are within acceptable ranges.
std::vector< double > _values
void jitter(double force, unsigned int pin=0)
Jitter the color for each channel.
void setName(std::string name)
static constexpr double EPSILON
unsigned int getPin(unsigned int channel) const
Return the pin number (pow2) of the channel index to pin that channel in a mutation.
std::shared_ptr< Space::AnySpace > _space
static std::optional< Color > parse(char const *value)
Create an optional color if value is valid.
bool hasOpacity() const
Returns true if there is an opacity channel in this color.
double getOpacity() const
Get the opacity in this color, if it's stored.
Color composed(Color const &other) const
Return the composition of this color, plus the other color on top.
void average(Color const &other, double pos=0.5, unsigned int pin=0)
std::shared_ptr< Space::AnySpace > const & getSpace() const
std::string getName() const
const std::vector< double > & getValues() const
bool isOverInked() const
Return true if this color would be considered over-inked.
uint32_t toABGR(double opacity=1.0) const
Return the RGBA int32 as an ABGR format color.
double get(unsigned int index) const
Get a single channel from this color.
A set of useful color modifying functions which do not fit as generic methods on the color class itse...