Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
Inkscape::Colors Namespace Reference

A set of useful color modifying functions which do not fit as generic methods on the color class itself but which are used in various places. More...

Namespaces

namespace  CMS
 
namespace  Space
 

Classes

class  Color
 
class  ColorError
 
class  ColorSet
 
class  CssColorPrinter
 
class  CssFuncPrinter
 
class  CssLegacyPrinter
 
class  CssParser
 
class  CssPrinter
 
class  DocumentCMS
 
class  HexParser
 
class  HueParser
 
class  IccColorPrinter
 
class  LegacyParser
 
class  Manager
 
struct  NoColor
 
class  Parser
 
class  Parsers
 

Typedefs

using IdColors = std::vector< std::pair< std::string, Color > >
 
using Paint = std::variant< NoColor, Color >
 

Enumerations

enum class  RenderingIntent {
  UNKNOWN = 0 , AUTO = 1 , PERCEPTUAL = 2 , RELATIVE_COLORIMETRIC = 3 ,
  SATURATION = 4 , ABSOLUTE_COLORIMETRIC = 5 , RELATIVE_COLORIMETRIC_NOBPC = 6
}
 

Functions

std::vector< char > getMIMEData (Paint const &paint, char const *mime_type)
 Convert a paint into a draggable object.
 
Paint fromMIMEData (std::span< char const > data, char const *mime_type)
 Convert a dropped object into a color, if possible.
 
Color to_gamut_css (const Color &origin, const std::shared_ptr< Space::AnySpace > &space)
 Given a color origin, returns a new color that is in gamut using the CSS Gamut Mapping Algorithm.
 
bool out_of_gamut (const Color &color, const std::shared_ptr< Space::AnySpace > &space, double eps)
 
uint32_t hex_to_rgba (std::string const &value)
 Parse a color directly without any CSS or CMS support.
 
std::vector< double > rgba_to_values (uint32_t rgba, bool opacity)
 Convert a 32bit unsigned int into a set of 3 or 4 double values for rgba.
 
std::string rgba_to_hex (uint32_t value, bool alpha)
 Output the RGBA value as a #RRGGBB hex color, if alpha is true then the output will be #RRGGBBAA instead.
 
std::string color_to_id (std::optional< Color > const &color)
 Create a somewhat unique id for the given color used for palette identification.
 
std::string desc_to_id (std::string const &desc)
 Transform a color name or description into an id used for palette identification.
 
Color make_contrasted_color (Color const &orig, double amount)
 Make a darker or lighter version of the color, useful for making checkerboards.
 
Color make_theme_color (Color const &orig, bool dark)
 Make a themed dark or light color based on a previous shade, returns RGB color.
 
double perceptual_lightness (double l)
 
double get_perceptual_lightness (Color const &color)
 Return a value for how the light the color appears to be using HSLUV.
 
std::pair< double, double > get_contrasting_color (double l)
 
double lightness (Color color)
 
std::string paint_to_xml_string (Paint const &paint)
 Turn a color into a color xml document, used for drag and drop.
 
Paint xml_string_to_paint (std::string const &xmls, SPDocument *doc)
 Parse an xml document into a color.
 
XML::Documentpaint_to_xml (Paint const &paint)
 
Paint xml_to_paint (XML::Document const *xml, SPDocument *doc)
 
std::size_t hash_value (Color const &b)
 

Variables

constexpr auto mimeOSWB_COLOR = "application/x-oswb-color"
 
constexpr auto mimeX_COLOR = "application/x-color"
 
constexpr auto mimeTEXT = "text/plain"
 
static std::map< RenderingIntent, std::string > intentIds
 
const auto oklab_space = Manager::get().find(Space::Type::OKLAB)
 
const auto oklch_space = Manager::get().find(Space::Type::OKLCH)
 
const Color COLORS_WHITE = Color(0xffffffff, false)
 
const Color COLORS_BLACK = Color(0x000000ff, false)
 

Detailed Description

A set of useful color modifying functions which do not fit as generic methods on the color class itself but which are used in various places.

Typedef Documentation

◆ IdColors

using Inkscape::Colors::IdColors = typedef std::vector<std::pair<std::string, Color> >

Definition at line 27 of file color-set.h.

◆ Paint

using Inkscape::Colors::Paint = typedef std::variant<NoColor, Color>

Definition at line 32 of file xml-color.h.

Enumeration Type Documentation

◆ RenderingIntent

Enumerator
UNKNOWN 
AUTO 
PERCEPTUAL 
RELATIVE_COLORIMETRIC 
SATURATION 
ABSOLUTE_COLORIMETRIC 
RELATIVE_COLORIMETRIC_NOBPC 

Definition at line 18 of file enum.h.

Function Documentation

◆ color_to_id()

std::string Inkscape::Colors::color_to_id ( std::optional< Color > const &  color)

Create a somewhat unique id for the given color used for palette identification.

Definition at line 81 of file utils.cpp.

References desc_to_id(), and name.

Referenced by Inkscape::UI::Dialog::ColorItem::ColorItem().

◆ desc_to_id()

std::string Inkscape::Colors::desc_to_id ( std::string const &  desc)

Transform a color name or description into an id used for palette identification.

Definition at line 115 of file utils.cpp.

References name.

Referenced by color_to_id().

◆ fromMIMEData()

Paint Inkscape::Colors::fromMIMEData ( std::span< char const >  data,
char const *  mime_type 
)

Convert a dropped object into a color, if possible.

Definition at line 59 of file dragndrop.cpp.

References data, mimeOSWB_COLOR, mimeTEXT, mimeX_COLOR, Inkscape::Colors::Color::size(), SP_RGBA32_U_COMPOSE(), and xml_string_to_paint().

◆ get_contrasting_color()

std::pair< double, double > Inkscape::Colors::get_contrasting_color ( double  l)

◆ get_perceptual_lightness()

double Inkscape::Colors::get_perceptual_lightness ( Color const &  color)

◆ getMIMEData()

std::vector< char > Inkscape::Colors::getMIMEData ( Paint const &  paint,
char const *  mime_type 
)

Convert a paint into a draggable object.

Definition at line 24 of file dragndrop.cpp.

References mimeOSWB_COLOR, mimeTEXT, mimeX_COLOR, paint_to_xml_string(), rgb, SP_RGBA32_A_U(), SP_RGBA32_B_U(), SP_RGBA32_G_U(), and SP_RGBA32_R_U().

◆ hash_value()

std::size_t Inkscape::Colors::hash_value ( Color const &  b)

Definition at line 41 of file swatches.cpp.

References Inkscape::Colors::Color::toRGBA().

◆ hex_to_rgba()

uint32_t Inkscape::Colors::hex_to_rgba ( std::string const &  value)

Parse a color directly without any CSS or CMS support.

This function is ONLY intended to parse values stored in inkscape specific screen-attributes and preferences.

DO NOT use this as a common color parser, it does not support any other format other than RRGGBBAA and anything else will cause an error.

  • value - Must be in format #RRGGBBAA only or an empty string.

Definition at line 32 of file utils.cpp.

Referenced by css_color_to_gdk().

◆ lightness()

◆ make_contrasted_color()

Color Inkscape::Colors::make_contrasted_color ( Color const &  orig,
double  amount 
)

Make a darker or lighter version of the color, useful for making checkerboards.

Definition at line 134 of file utils.cpp.

References Inkscape::Colors::Space::HSL, lightness(), orig, and Inkscape::Colors::Color::set().

Referenced by Inkscape::UI::Widget::checkerboard_darken(), and ink_cairo_pattern_create_checkerboard().

◆ make_theme_color()

Color Inkscape::Colors::make_theme_color ( Color const &  orig,
bool  dark 
)

Make a themed dark or light color based on a previous shade, returns RGB color.

Definition at line 148 of file utils.cpp.

References Inkscape::Colors::Space::HSLUV, orig, and Inkscape::Colors::Space::RGB.

◆ out_of_gamut()

bool Inkscape::Colors::out_of_gamut ( const Color color,
const std::shared_ptr< Space::AnySpace > &  space,
double  eps 
)

◆ paint_to_xml()

◆ paint_to_xml_string()

std::string Inkscape::Colors::paint_to_xml_string ( Paint const &  paint)

Turn a color into a color xml document, used for drag and drop.

  • paint - The color or none to convert into xml

Definition at line 34 of file xml-color.cpp.

References paint_to_xml(), Inkscape::GC::release(), and sp_repr_save_buf().

Referenced by getMIMEData().

◆ perceptual_lightness()

double Inkscape::Colors::perceptual_lightness ( double  l)

◆ rgba_to_hex()

std::string Inkscape::Colors::rgba_to_hex ( uint32_t  value,
bool  alpha 
)

◆ rgba_to_values()

std::vector< double > Inkscape::Colors::rgba_to_values ( uint32_t  rgba,
bool  opacity 
)

Convert a 32bit unsigned int into a set of 3 or 4 double values for rgba.

  • rgba - The integer in the format 0xRRGGBBAA
  • opacity - Include the opacity channel, if false throws opacity away.
Returns
the values of the rgba channels between 0.0 and 1.0

Definition at line 54 of file utils.cpp.

References SP_RGBA32_A_F(), SP_RGBA32_B_F(), SP_RGBA32_G_F(), and SP_RGBA32_R_F().

Referenced by Inkscape::Colors::Color::set().

◆ to_gamut_css()

Color Inkscape::Colors::to_gamut_css ( const Color origin,
const std::shared_ptr< Space::AnySpace > &  space 
)

Given a color origin, returns a new color that is in gamut using the CSS Gamut Mapping Algorithm.

If space is specified, it will be in gamut in space, and returned in space. Otherwise, it will be in gamut and returned in the color space of origin.

Parameters
{ColorTypes}origin
{{space?: string | ColorSpace | undefined }} param1
Returns
{PlainColorObject}

Definition at line 66 of file gamut.cpp.

References clip(), COLORS_BLACK, COLORS_WHITE, Inkscape::Colors::Color::converted(), current, oklch_space, origin, and out_of_gamut().

Referenced by Inkscape::Colors::Space::AnySpace::toGamut().

◆ xml_string_to_paint()

Paint Inkscape::Colors::xml_string_to_paint ( std::string const &  xmls,
SPDocument doc 
)

Parse an xml document into a color.

Usually from a drag and drop.

  • xmls - A string of a color xml document
  • doc - An optional document to match icc profiles

Definition at line 48 of file xml-color.cpp.

References Inkscape::GC::release(), sp_repr_read_buf(), and xml_to_paint().

Referenced by fromMIMEData().

◆ xml_to_paint()

Variable Documentation

◆ COLORS_BLACK

const Color Inkscape::Colors::COLORS_BLACK = Color(0x000000ff, false)

Definition at line 16 of file gamut.cpp.

Referenced by to_gamut_css().

◆ COLORS_WHITE

const Color Inkscape::Colors::COLORS_WHITE = Color(0xffffffff, false)

Definition at line 15 of file gamut.cpp.

Referenced by to_gamut_css().

◆ intentIds

std::map<RenderingIntent, std::string> Inkscape::Colors::intentIds
static
Initial value:
= {
{RenderingIntent::UNKNOWN, ""},
{RenderingIntent::AUTO, "auto"},
{RenderingIntent::PERCEPTUAL, "perceptual"},
{RenderingIntent::SATURATION, "saturation"},
{RenderingIntent::ABSOLUTE_COLORIMETRIC, "absolute-colorimetric"},
{RenderingIntent::RELATIVE_COLORIMETRIC, "relative-colorimetric"},
{RenderingIntent::RELATIVE_COLORIMETRIC_NOBPC, "relative-colorimetric-nobpc"},
}

Definition at line 34 of file enum.h.

Referenced by Inkscape::Colors::DocumentCMS::checkProfileName(), Inkscape::ColorProfile::createFromProfile(), Inkscape::Colors::Space::AnySpace::profileToProfile(), Inkscape::ColorProfile::set(), Inkscape::ColorProfile::setRenderingIntent(), and Inkscape::ColorProfile::write().

◆ mimeOSWB_COLOR

constexpr auto Inkscape::Colors::mimeOSWB_COLOR = "application/x-oswb-color"
inlineconstexpr

Definition at line 22 of file dragndrop.h.

Referenced by fromMIMEData(), and getMIMEData().

◆ mimeTEXT

constexpr auto Inkscape::Colors::mimeTEXT = "text/plain"
inlineconstexpr

Definition at line 24 of file dragndrop.h.

Referenced by fromMIMEData(), and getMIMEData().

◆ mimeX_COLOR

constexpr auto Inkscape::Colors::mimeX_COLOR = "application/x-color"
inlineconstexpr

Definition at line 23 of file dragndrop.h.

Referenced by fromMIMEData(), and getMIMEData().

◆ oklab_space

const auto Inkscape::Colors::oklab_space = Manager::get().find(Space::Type::OKLAB)

Definition at line 13 of file gamut.cpp.

◆ oklch_space

const auto Inkscape::Colors::oklch_space = Manager::get().find(Space::Type::OKLCH)

Definition at line 14 of file gamut.cpp.

Referenced by to_gamut_css().