Home

Awesome

Yet another c++ library that implements color.

Description

Key features:

Code sample - Initialization:

// Initialize with constant.
color::bgr<std::uint8_t>  b( ::color::constant::aqua_t{} );

//!< Use x11 green.
color::yiq<std::uint8_t>  y( ::color::constant::x11::green_t{} );

// Use intuitive/natural values for initialization.
// hue goes from 0 to 360, saturation and value from 0 to 100.
color::hsv<double>        h( { 120.0, 50.0, 60.0 } );

// Lightens will goes from 0 to 100. a and b from -127 to 127.
color::lab<float>         l( { 50.0, -10, 90 } );

// Well known rgb. Values are between 0 and 1.
color::rgb<float>         r( { 0.5, 0, 0.9 } );

Code sample - Conversion:

// any model/format to any model/format by use of operator=

b = r; //!< Reformat and convert.
r = b; //!< Reformat and convert in opposite direction.
h = b; //!< Reformat and convert from bgr<std::uint8_t> to hsv<double>
h = y; //!< Reformat and convert from yiq<std::uint8_t> to hsv<double>
l = y; //!< Reformat and convert from yiq<std::uint8_t> to lab<float>

Code sample - Feature Extraction:

color::rgb<std::uint8_t>  r = ::color::constant::aqua_t{};
::color::get::red( r ); //!< Extract red

color::yiq<std::uint8_t>  y = ::color::constant::orange_t{};
::color::get::red( y ); //!< Extract red

Code sample - Distance:

using namespace std;
using namespace color;
using namespace color::operation;
using namespace color::constant;
using namespace color::constant::distance;

rgb<uint8_t>  r0 = aqua_t{};
rgb<uint8_t>  r1 = turquoise_t{};
yiq<uint8_t>  y  = orange_t{};

cout << distance< euclid_entity  >( r0, r1 ) << endl;
cout << distance< CIE76_entity >( r0, y ) << endl;
cout << distance< CIE94_graphics_entity >( r0, y ) << endl;
cout << distance< CIE94_textile_entity >( r0, y ) << endl;
cout << distance< CIEDE2000_entity >( r0, y ) << endl;
cout << distance< CMC1984_entity >( r0, y, 1, 2 ) << endl;
cout << distance< delta_gray_entity >( r0, r1 ) << endl;

Code sample - Blending:

color::yiq<std::uint8_t>  y1 = ::color::constant::turquoise_t{};
color::yiq<std::uint8_t>  y2 = ::color::constant::orange_t{};
color::yiq<std::uint8_t>  yr;

::color::operation::blend(  y1, 0.1, y2 ); //!< Blend two colors for given alpha. Accumulation style.
yr = color::operation::mix( y2, 0.5, y2 ); //!< Blend two colors for given alpha. return style.

Install:

  1. Clone this Repository:
    Examples:
  2. Inform compiler where to find headers:
    Examples:
    • MSVC : /Ic:\my-work-folder\my-git-folder\color\src
    • gcc : -I/home/my-user-name/my-work-folder/my-git-folder/color/src

Want to see more:

Tested against:

(Links

License

Licensed under an Apache-2.0 license.