Inkscape
Vector Graphics Editor
|
#include <color.h>
Public Member Functions | |
Color (std::shared_ptr< Space::AnySpace > space, std::vector< double > colors) | |
Construct a color in the given color space. | |
Color (Space::Type space_type, std::vector< double > values) | |
Create a color, given the type of the space and the values to store. | |
Color (uint32_t color, bool alpha=true) | |
Compatability layer for making blind RGB colors. | |
bool | operator== (Color const &other) const |
Return true if the two colors are the same. | |
double | operator[] (unsigned int index) const |
std::shared_ptr< Space::AnySpace > const & | getSpace () const |
const std::vector< double > & | getValues () const |
void | setValues (std::vector< double > values) |
Set the channels directly without checking if the space is correct. | |
size_t | size () const |
double | get (unsigned int index) const |
Get a single channel from this color. | |
bool | set (unsigned int index, double value) |
Set a specific channel in the color. | |
bool | set (Color const &other, bool keep_space=true) |
Set this color to the values from another color. | |
bool | set (std::string const &parsable, bool keep_space=true) |
Set this color by parsing the given string. | |
bool | set (uint32_t rgba, bool opacity=true) |
Set this color from an RGBA unsigned int. | |
bool | hasOpacity () const |
Returns true if there is an opacity channel in this color. | |
void | enableOpacity (bool enabled) |
Enables or disables the opacity channel. | |
unsigned int | getOpacityChannel () const |
Get the opacity channel index. | |
double | getOpacity () const |
Get the opacity in this color, if it's stored. | |
double | stealOpacity () |
Get the opacity, and remove it from this color. | |
bool | setOpacity (double opacity) |
Set the opacity of this color object. | |
bool | addOpacity (double opacity=1.0) |
unsigned int | getPin (unsigned int channel) const |
Return the pin number (pow2) of the channel index to pin that channel in a mutation. | |
double | difference (Color const &other) const |
Get the mean square difference between this color and another. | |
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. | |
bool | convert (Color const &other) |
Convert to the same format as the other color. | |
bool | convert (std::shared_ptr< Space::AnySpace > space) |
Convert this color into a different color space. | |
bool | convert (Space::Type type) |
Convert this color into the first matched color space of the given type. | |
std::optional< Color > | converted (Color const &other) const |
Return a copy of this color converted to the same format as the other color. | |
std::optional< Color > | converted (std::shared_ptr< Space::AnySpace > to_space) const |
Convert a copy of this color into a different color space. | |
std::optional< Color > | converted (Space::Type type) const |
Convert a copy of this color into the first matching color space type. | |
std::string | toString (bool opacity=true) const |
Format the color as a css string and return it. | |
uint32_t | toRGBA (double opacity=1.0) const |
Return an sRGB conversion of the color in RGBA int32 format. | |
uint32_t | toARGB (double opacity=1.0) const |
Return the RGBA int32 as an ARGB format number. | |
uint32_t | toABGR (double opacity=1.0) const |
Return the RGBA int32 as an ABGR format color. | |
std::string | getName () const |
void | setName (std::string name) |
bool | isOutOfGamut (std::shared_ptr< Space::AnySpace > other) const |
Return true if this color would be out of gamut when converted to another space. | |
bool | isOverInked () const |
Return true if this color would be considered over-inked. | |
void | normalize () |
Make sure the values for this color are within acceptable ranges. | |
Color | normalized () const |
Return a normalized copy of this color so the values are within acceptable ranges. | |
void | compose (Color const &other) |
Put the other color on top of this color, mixing the two according to the alpha. | |
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) |
Color | averaged (Color const &other, double pos=0.5) const |
Return the average between this and another color. | |
void | invert (unsigned int pin) |
Invert the color for each channel. | |
void | invert () |
void | jitter (double force, unsigned int pin=0) |
Jitter the color for each channel. | |
Static Public Member Functions | |
static std::optional< Color > | parse (char const *value) |
Create an optional color if value is valid. | |
static std::optional< Color > | parse (std::string const &value) |
Create an optional color, if possible, from the given string. | |
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. | |
Static Public Attributes | |
static constexpr double | EPSILON = 1e-4 |
Private Member Functions | |
template<typename Func > | |
void | _color_mutate_inplace (Color const &other, unsigned int pin, Func avgFunc) |
bool | _isnear (std::vector< double > const &other, double epsilon=0.001) const |
Returns true if the values are near to the other values. | |
Private Attributes | |
std::string | _name |
std::vector< double > | _values |
std::shared_ptr< Space::AnySpace > | _space |
Inkscape::Colors::Color::Color | ( | std::shared_ptr< Space::AnySpace > | space, |
std::vector< double > | colors | ||
) |
Construct a color in the given color space.
Inkscape::Colors::Color::Color | ( | Space::Type | space_type, |
std::vector< double > | values | ||
) |
|
explicit |
|
private |
Definition at line 630 of file color.cpp.
References _color_mutate_inplace(), _space, _values, converted(), and hasOpacity().
Referenced by _color_mutate_inplace(), average(), and compose().
|
private |
Returns true if the values are near to the other values.
Definition at line 292 of file color.cpp.
References _values.
Referenced by operator==(), and set().
|
inline |
Definition at line 56 of file color.h.
References getOpacity(), and setOpacity().
Referenced by Inkscape::UI::Widget::create_color_plate(), Inkscape::UI::Widget::draw_circle(), InkFileExportCmd::get_bgcolor(), SPStop::getColor(), Inkscape::Extension::Internal::LaTeXTextRenderer::sp_text_render(), and Inkscape::ObjectSet::swapFillStroke().
void Inkscape::Colors::Color::average | ( | Color const & | other, |
double | pos = 0.5 , |
||
unsigned int | pin = 0 |
||
) |
Definition at line 544 of file color.cpp.
References _color_mutate_inplace().
Referenced by Inkscape::UI::Tools::tweak_color().
Return the average between this and another color.
Definition at line 556 of file color.cpp.
Referenced by Inkscape::UI::Tools::GradientTool::simplify(), sp_gradient_add_stop(), and sp_vector_add_stop().
void Inkscape::Colors::Color::compose | ( | Color const & | other | ) |
Put the other color on top of this color, mixing the two according to the alpha.
Definition at line 517 of file color.cpp.
References _color_mutate_inplace(), getOpacity(), getOpacityChannel(), getPin(), and setOpacity().
Return the composition of this color, plus the other color on top.
Definition at line 530 of file color.cpp.
Referenced by Inkscape::UI::Tools::DropperTool::root_handler().
bool Inkscape::Colors::Color::convert | ( | Color const & | other | ) |
Convert to the same format as the other color.
Definition at line 145 of file color.cpp.
References _space, convert(), enableOpacity(), and hasOpacity().
Referenced by convert(), convert(), set(), sp_gradient_to_hhssll(), and Inkscape::Extension::Internal::LaTeXTextRenderer::sp_text_render().
bool Inkscape::Colors::Color::convert | ( | Space::Type | type | ) |
Convert this color into the first matched color space of the given type.
Definition at line 178 of file color.cpp.
References convert(), and Inkscape::Colors::Manager::get().
bool Inkscape::Colors::Color::convert | ( | std::shared_ptr< Space::AnySpace > | to_space | ) |
Return a copy of this color converted to the same format as the other color.
Definition at line 189 of file color.cpp.
Referenced by _color_mutate_inplace(), Inkscape::UI::Widget::LayerSelector::_layerModified(), Inkscape::Extension::Internal::Bitmap::Colorize::applyEffect(), Inkscape::UI::Widget::RotateableSwatch::color_adjust(), difference(), Inkscape::Extension::Internal::PdfBuilder::Document::get_color(), Inkscape::Colors::get_perceptual_lightness(), isSimilar(), Inkscape::UI::Widget::lerp(), Inkscape::UI::Widget::luminance(), Inkscape::UI::Widget::ColorWheelHSLuv::on_drawing_area_draw(), Inkscape::UI::Widget::ColorWheelHSLuv::on_key_pressed(), Inkscape::Colors::out_of_gamut(), Inkscape::Extension::Internal::stop_svg(), Inkscape::Colors::to_gamut_css(), and Inkscape::UI::Tools::tweak_color().
std::optional< Color > Inkscape::Colors::Color::converted | ( | Space::Type | type | ) | const |
std::optional< Color > Inkscape::Colors::Color::converted | ( | std::shared_ptr< Space::AnySpace > | to_space | ) | const |
double Inkscape::Colors::Color::difference | ( | Color const & | other | ) | const |
Get the mean square difference between this color and another.
Definition at line 566 of file color.cpp.
References _values, and converted().
void Inkscape::Colors::Color::enableOpacity | ( | bool | enabled | ) |
Enables or disables the opacity channel.
Definition at line 385 of file color.cpp.
References _values, and hasOpacity().
Referenced by convert(), set(), sp_gradstop_to_pixbuf_ref(), and stealOpacity().
double Inkscape::Colors::Color::get | ( | unsigned int | index | ) | const |
Get a single channel from this color.
Definition at line 87 of file color.cpp.
References _values, getOpacityChannel(), and index.
Referenced by operator[]().
|
inline |
Definition at line 78 of file color.h.
References _name.
Referenced by Inkscape::UI::Dialog::ColorItem::ColorItem().
double Inkscape::Colors::Color::getOpacity | ( | ) | const |
Get the opacity in this color, if it's stored.
Returns 1.0 if no opacity exists in this color or 0.0 if this color is empty.
Definition at line 407 of file color.cpp.
References _values, and hasOpacity().
Referenced by Inkscape::UI::Widget::ColorWheelHSL::_set_from_xy(), addOpacity(), SPNamedView::change_color(), compose(), Inkscape::LivePathEffect::LPEMeasureSegments::createLine(), Inkscape::LivePathEffect::LPEMeasureSegments::createTextLabel(), Inkscape::Extension::Internal::PdfBuilder::Document::get_color(), Inkscape::load_svg_cursor(), Inkscape::UI::Widget::RegisteredColorPicker::on_changed(), SPGrid::set(), SPStop::setColorRepr(), SPGrid::setMajorColor(), SPGrid::setMinorColor(), Inkscape::Extension::Internal::LaTeXTextRenderer::sp_text_render(), stealOpacity(), Inkscape::Extension::Internal::stop_svg(), and Inkscape::PageManager::subset().
unsigned int Inkscape::Colors::Color::getOpacityChannel | ( | ) | const |
unsigned int Inkscape::Colors::Color::getPin | ( | unsigned int | channel | ) | const |
|
inline |
Definition at line 39 of file color.h.
References _space.
Referenced by Inkscape::UI::Widget::RotateableSwatch::color_adjust(), Inkscape::Extension::Internal::PdfBuilder::Document::get_color(), Inkscape::Colors::out_of_gamut(), Inkscape::UI::Widget::ColorPlate::set_base_color(), Inkscape::UI::Widget::ColorWheelHSLuv::setColor(), and Inkscape::UI::Tools::tweak_color().
|
inline |
Definition at line 40 of file color.h.
References _values.
Referenced by Inkscape::Extension::Internal::PdfBuilder::Document::get_color(), and Inkscape::Colors::out_of_gamut().
bool Inkscape::Colors::Color::hasOpacity | ( | ) | const |
Returns true if there is an opacity channel in this color.
Definition at line 398 of file color.cpp.
References _values, and getOpacityChannel().
Referenced by _color_mutate_inplace(), SPNamedView::change_color(), convert(), enableOpacity(), getOpacity(), normalize(), set(), and setOpacity().
|
static |
Construct a color from the space type and values, if the values are valid.
Definition at line 331 of file color.cpp.
References Inkscape::Colors::Manager::get().
Referenced by parse().
|
inline |
void Inkscape::Colors::Color::invert | ( | unsigned int | pin | ) |
Find out if a color is a close match to another color of the same type.
Definition at line 583 of file color.cpp.
References _space, and _values.
Referenced by SPGradient::isEquivalent(), and isSimilar().
bool Inkscape::Colors::Color::isOutOfGamut | ( | std::shared_ptr< Space::AnySpace > | other | ) | const |
bool Inkscape::Colors::Color::isOverInked | ( | ) | const |
Find out if a color is similar to another color, converting it first if it's a different type.
If one has opacity and the other does not it always returns false.
Definition at line 599 of file color.cpp.
References _space, converted(), and isClose().
Referenced by sp_get_same_fill_or_stroke_color().
void Inkscape::Colors::Color::jitter | ( | double | force, |
unsigned int | pin = 0 |
||
) |
Jitter the color for each channel.
@
Definition at line 499 of file color.cpp.
References _values, and normalize().
void Inkscape::Colors::Color::normalize | ( | ) |
Make sure the values for this color are within acceptable ranges.
Definition at line 460 of file color.cpp.
References _space, _values, and hasOpacity().
Referenced by Inkscape::UI::Widget::OKWheel::_setColor(), jitter(), and Inkscape::UI::Widget::ColorWheelHSL::on_key_pressed().
Color Inkscape::Colors::Color::normalized | ( | ) | const |
bool Inkscape::Colors::Color::operator== | ( | Color const & | other | ) | const |
|
inline |
|
static |
|
static |
Create an optional color, if possible, from the given string.
Definition at line 315 of file color.cpp.
References Inkscape::Colors::Parsers::get(), ifValid(), and parse().
bool Inkscape::Colors::Color::set | ( | Color const & | other, |
bool | keep_space = true |
||
) |
Set this color to the values from another color.
Definition at line 249 of file color.cpp.
References _isnear(), _name, _space, _values, convert(), enableOpacity(), hasOpacity(), and set.
bool Inkscape::Colors::Color::set | ( | std::string const & | parsable, |
bool | keep_space = true |
||
) |
Set this color by parsing the given string.
If there's a parser error it will not change the existing color.
Definition at line 281 of file color.cpp.
References set.
bool Inkscape::Colors::Color::set | ( | uint32_t | rgba, |
bool | opacity = true |
||
) |
Set this color from an RGBA unsigned int.
Definition at line 369 of file color.cpp.
References _name, _space, _values, Inkscape::Colors::Manager::get(), Inkscape::Colors::Space::RGB, Inkscape::Colors::rgba_to_values(), and toRGBA().
bool Inkscape::Colors::Color::set | ( | unsigned int | index, |
double | value | ||
) |
Set a specific channel in the color.
Definition at line 350 of file color.cpp.
References _values, getOpacityChannel(), and index.
Referenced by Inkscape::UI::Widget::ColorWheelHSLuv::_set_from_xy(), Inkscape::UI::Widget::OKWheel::_setColor(), Inkscape::UI::Widget::ColorWheelHSL::_update_ring_color(), Inkscape::UI::Tools::compare_pixels(), Inkscape::UI::Widget::create_color_wheel_helper(), Inkscape::UI::Tools::getPickerData(), Inkscape::Colors::make_contrasted_color(), Inkscape::UI::Widget::ColorWheelHSL::on_key_pressed(), Inkscape::UI::Widget::ColorWheelHSLuv::on_key_pressed(), Inkscape::UI::Widget::set_color_helper(), Inkscape::UI::Widget::ColorWheelHSL::setColor(), Inkscape::UI::Widget::ColorWheelHSLuv::setColor(), and Inkscape::UI::Widget::OKWheel::setColor().
|
inline |
bool Inkscape::Colors::Color::setOpacity | ( | double | opacity | ) |
Set the opacity of this color object.
Definition at line 444 of file color.cpp.
References _values, and hasOpacity().
Referenced by addOpacity(), compose(), Inkscape::load_svg_cursor(), SPGrid::set(), Inkscape::UI::Widget::ColorPlate::set_base_color(), and Inkscape::PageManager::subset().
void Inkscape::Colors::Color::setValues | ( | std::vector< double > | values | ) |
|
inline |
Definition at line 42 of file color.h.
References _values.
Referenced by Inkscape::Colors::fromMIMEData().
double Inkscape::Colors::Color::stealOpacity | ( | ) |
Get the opacity, and remove it from this color.
This is useful when setting a color into an svg css property that has it's own opacity property but you aren't ready to create a string (see toString(false) for that use)
Definition at line 417 of file color.cpp.
References enableOpacity(), and getOpacity().
Referenced by Inkscape::UI::Tools::CalligraphicTool::brush(), Inkscape::UI::Widget::checkerboard_darken(), and Inkscape::UI::Widget::draw_circle().
uint32_t Inkscape::Colors::Color::toABGR | ( | double | opacity = 1.0 | ) | const |
uint32_t Inkscape::Colors::Color::toARGB | ( | double | opacity = 1.0 | ) | const |
Return the RGBA int32 as an ARGB format number.
Definition at line 125 of file color.cpp.
References toRGBA().
Referenced by Inkscape::UI::Widget::create_color_wheel(), Inkscape::UI::Widget::draw_vertical_padding(), Inkscape::Util::get_checkerboard_colors(), and Inkscape::UI::Widget::ColorWheelHSL::update_triangle_source().
uint32_t Inkscape::Colors::Color::toRGBA | ( | double | opacity = 1.0 | ) | const |
Return an sRGB conversion of the color in RGBA int32 format.
@args opacity - optional opacity to be mixed into any existing opacity in this color.
Definition at line 117 of file color.cpp.
References _space, and _values.
Referenced by Inkscape::UI::Tools::PenTool::_bsplineSpiroColor(), Inkscape::UI::Tools::PencilTool::_fitAndSplit(), Inkscape::CanvasPage::add(), color_to_rgba(), InkFileExportCmd::get_bgcolor(), Inkscape::Colors::hash_value(), ink_cairo_pattern_add_color_stop(), ink_cairo_pattern_create(), ink_cairo_set_source_color(), ink_cairo_set_source_color(), Inkscape::load_svg_cursor(), Inkscape::UI::Dialog::BatchExport::onExport(), Inkscape::UI::Dialog::SingleExport::onExport(), Inkscape::UI::Dialog::BatchExport::refreshPreview(), Inkscape::UI::Dialog::SingleExport::refreshPreview(), Inkscape::UI::Dialog::LivePathEffectEditor::selection_info(), set(), Inkscape::UI::Widget::ColorPicker::setColor(), Inkscape::UI::MultiPathManipulator::setItems(), toABGR(), toARGB(), Inkscape::CanvasPage::update(), and SPGrid::update().
std::string Inkscape::Colors::Color::toString | ( | bool | opacity = true | ) | const |
Format the color as a css string and return it.
Note: Choose the color space for your color carefully before printing. If you are outputting to a CSS version that only supports RGB hex codes, then convert the color to that color space before printing.
Definition at line 106 of file color.cpp.
References _space, and _values.
Referenced by SPNamedView::change_color(), Inkscape::LivePathEffect::LPEMeasureSegments::createLine(), Inkscape::LivePathEffect::LPEMeasureSegments::createTextLabel(), Inkscape::Extension::Internal::PdfBuilder::Document::get_color(), Inkscape::load_svg_cursor(), GrDrag::makeStopSafeColor(), Inkscape::UI::Widget::RegisteredColorPicker::on_changed(), Inkscape::UI::Dialog::set_export_bg_color(), Inkscape::Preferences::setColor(), SPStop::setColorRepr(), SPGrid::setMajorColor(), SPGrid::setMinorColor(), and Inkscape::Extension::ParamColor::value_to_string().
|
private |
|
private |
Definition at line 100 of file color.h.
Referenced by _color_mutate_inplace(), Color(), convert(), convert(), getOpacityChannel(), getSpace(), isClose(), isOutOfGamut(), isOverInked(), isSimilar(), normalize(), operator==(), set(), set(), setValues(), toRGBA(), and toString().
|
private |
Definition at line 99 of file color.h.
Referenced by _color_mutate_inplace(), _isnear(), Color(), convert(), difference(), enableOpacity(), get(), getOpacity(), getValues(), hasOpacity(), invert(), isClose(), isOutOfGamut(), isOverInked(), jitter(), normalize(), operator==(), set(), set(), set(), setOpacity(), setValues(), size(), toRGBA(), and toString().
|
staticconstexpr |