Skip to content

New Color System 馃巰

Martin Owens requested to merge doctormo/inkscape:add-new-colors-code into master

The new system

The first commit is the addition of a new system for colour management, conversion, and profile tracking. It's made up of these parts:

The Color Object

Found in colors/color.h this API is a light-weight object which can be copied and moved as needed.

  1. It's a list of doubles which are ALWAYS set between 0.0 and 1.0 of the expected or reasonable range for each channel in the color.
  2. It's linked to a Color Space object which describes the color, it's channels and provides conversion services.
  3. It may optionally have an opacity which can be controlled as a final value in the list of doubles.

The Color Space Object

Found in colors/spaces/*.h these modules each provide a way of identifying what color space a set of values are in, as well as all the labels, icons, icc color profiles and other elements needed to do conversions.

  1. Each color space ALWAYS has an icc profile. The default is sRGB, though this could change if we want better color conversions in the future.
  2. Spaces may be inbuilt, or they may be specified by icc profiles used in a document.
  3. Conversion is done using virtual methods to support the transparent conversion of color objects regardless of their nature.
  4. The CMYK color space IS NOT a real CMYK color space, it is pretend "DeviceCMYK" which is based on sRGB, as confusing as this might seem at first.

Spaces

  • RGB
  • LinearRGB
  • DeviceCMYK
  • Gray
  • Lab
  • Lch
  • Luv
  • CMS - Color managed ICC profile based
  • HSL
  • HSV
  • HSLuv
  • OkLab
  • OkLch
  • OkHsl
  • XYZ

Printers and Parsers

There are a set of functions for parsing and printing many (BUT NOT ALL) of the color spaces into CSS color modules.

  1. Expected public API through the Color object's constructor and toString method
  2. Used by Color Space and Color Manager internally to perform their jobs

Manager and Tracker

The color manager tracks all color spaces and color parsers globally. While the Colour tracker watches a specific document for changes to it's icc profiles.

Color Management System (CMS)

The Color CMS API expects to wrap the lcms2 functionality and icc profile finding functions. There should be no use of lcms2 outside of this part of the code in the future.

  1. List all available icc profiles from a set of system directories
  2. Find icc profiles by name or id (including generating spec-correct ID numbers when missing)
  3. Load icc profiles and keep track of their memory
  4. Load icc transformers for various uses in cairo, color transforms and screen uses.

Color Set

A dictionary of colors with added signalling. This API allows a set of different colors of different or same color spaces to be modified together.

XML-Color and Drag and Drop

The construction of various color formats used in copy and paste and drag-and-drop functionality is housed in xml-color and dragndrop files. This is mainly to prevent duplication and provide much more robust tests.

Color Profile

The object/color-profile object was refactored to move most of it's functionality and it's now a fairly bare bones XML attribute watcher.

Unit Testing

A new set of tests are provided in testfiles/src/colors/ and new data in testfiles/data/colors/ which cover each color space and unit test all the above APIs.

Refactoring

Reactor Inkscape to use the new color model framework

Deletions and Movements

  • Removal of color.cpp, which is now replaced by the class in colors/color
  • Removal of svg/svg-color.cpp, which is now replaced by colors/color for full color handling and colors/parser for parsing.
  • Removal of color-rgba.h which is now replaced by colors/color and ui/utils for Gdk conversions
  • Removal of color/color-conv.cpp into colors/parser
  • Removal of color/color-profile-cms-fns.h as all the cms encapsulation is already done above.
  • Removal of widgets/paintdef.cpp, which was a duplicate color structure, xml functionality moved to colors/xml-color.cpp
  • Removal of svg/svg-renderer.cpp color code, Gdk coversions moved to ui/utils and css code is now an Inkscape::Color object.
  • Removal of svg-color and oklab tests which are entirely replaced by colors/*tests
  • Refactor global-palettes.cpp to remove all custom rgb building and instead build Color objects directly.
  • Refactor color-icc-selector removing most of it's own code in favor of the cms and color space API
  • Moving of color/cmyk-conv.cpp into colors/spaces/cmyk and regularised into a color space class.
  • Moving of hsluv.cpp and oklab.cpp which are split and regularised into many colors/spaces/hsluv and ok color space classes
  • Moving of color/cms-* into colors/cms/* with some of the code from object/colorprofile.cpp to restrict the use of lcms2 to just this directory and make the accessing of cms profiles and transforms predictable and less error prone.
  • Moving of profile-manager.cpp functionality colors/tracker.cpp rewritten to create the new icc color space objects.
  • Moving of ui/selected-color.cpp functionality to colors/color-set rewritten to be a collection of trackable color objects.

Changes

  • Refactor style color to remove SPColor and Href values, add a private Inkscape::Color and getter/setter functions.
  • Refactor style alpha so it can be used as a double transparently without conversion.
  • Refactor SP-Stop color to bundle opacity and simplify how color is used.
  • Refactor filter constructors to stop constructing their own rgb css color formats
  • Remove extract color functions from preferences and replace with getColor and setColor which take the new color object.
  • Remove use of SPColor from anywhere it's being used and replace with Inkscape::Color object
  • Remove SP_RGBA32_G_F and similar macros to construct colors, or convert them from preferences.
  • Remove custom checkerboard darken and use new color utils and cairo utils
  • Remove custom HSL tweaking code from selected-style
  • Remove SPIPaint::read function used in sp-stop, it was basically just a color parser
  • Add cairo color functions into display/cairo-utils.cpp which centralise conversion to RGBA; to make it easier to replace later.
  • Use colors/utils make_contrasted_color for finding consistant contrasting colors, replacing copy pasta calculations.
  • Removal of icc profile specific code in display/nr-filter-* code
  • Use Color Tracker object in document.cpp instead of the now deleted Profile Manager
  • Use Color utils hex parsing for Gtk/css handling in themes instead of sp_svg_write_color
  • Use Color in lpe color values, removing duplicated color parsing and printing.
  • Use Color for item highlight color and plug into various gtk widgets.
  • Use average color util in GrDrag instead of internal rgb calculation.
  • Drag and drop colors using new xml and mime type code in colors/dragndrop.cpp
  • Parse colors directly out of SP-Object attr code using parseAttr to make optional Color objects.
  • Convert SP Grid to use color objects instead of RGBA ints
  • Use color/cms framework instead of lcms2 directly in sp-image
  • Use getColor to handle opacity and color in gradients and mesh gradients
  • Use Color object in extensions param color.
  • Parse colors using new parsers in internal extensions.
  • Replace color average or blending with colors/utils average color methods
  • Use color module in swatches and palettes for parsing out any color needed
  • Use of HSL space inside color object instead of converting to and fro in color manipulation code
  • Use average_color_between for all color dividers such as gradient-dragging and desktop-style
  • Focus all uses of cairo context setting through display/cairo-utils.cpp color setting functions
  • Use a standard toColorRef function in emf/wmf extensions to convert colors.
  • Generate base64 from icc profiles found in pdf files using the cms object
  • Document properties to use the internal ColorProfile generator instead of it's own xml code
  • Convert tool and desktop prefs color from guint32 to optional Color objects for preference setting/getting
  • Use util Colors::lightness instead of SP_RGBA32_LUMINANCE
  • Fix TODO issue with selected color not calling update when dragging had finished
  • Move color wheels to use color objects and tie in where possible.

Other Refactoring

  • Add sp_repr_css_set_property_string to xml/repr.h to handle setting std::string
  • Add gtk adjustment functions to ui/util.cpp to replace color-scale specific code
  • Give SPIScale24 a setter and getter for double instead of requiring the use of SP_SCALE24_TO/FROM_FLOAT at every use.
  • Removed a useless _cmp method in document-properties
Edited by Martin Owens

Merge request reports