Coder Social home page Coder Social logo

unilang / color Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dmilos/color

0.0 1.0 0.0 11.5 MB

C++ library thats implemets class color. Available models: RGB, HSL, HSV, CMY, CMYK, YIQ, YUV and growing.

License: Apache License 2.0

C++ 95.17% Shell 2.35% Batchfile 2.27% CMake 0.02% Python 0.20%

color's Introduction

Yet another c++ library that implements color.

Description

  • Yet another c++ library that implements color conversion and manipulation.

Key features:

  • No virtual functions
  • Minimal memory footprint
  • Ability to copy array/vector of colors with memcpy, memmove and initialize with memset.
  • Conversions from/to different models ( and its formats ).
  • Headers only
    • One file to include to start the fun
    • By using del or rm it is reducible in to only two of them.
  • No third parties
  • No additional binaries
  • Out of the box ready
    • No need to recompile or start some install process.
  • Color models:
    • GRAY,
    • RGB, CMY, CMYK,
    • HSI, HSL, HSV, HWB,
    • YIQ, YUV(BT.601, BT.709), YCgCo, YPbPr(BT.601, BT.709, BT.2020),
    • XYZ( sRGB, D65, 2° ), LAB( CIE, Hunter), LUV, LMS( von Kries D65, von Kries E, BFD, MCAT02 ), xyY, LabCH, LuvCH

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>         l( { 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:

  • GCC 4.8.4
  • GCC 5.4.0 20160609
  • GCC 7.4.0
  • MSVC 2017 (15.3.2)
  • MSVC 2015 Update 3
  • MSVC 2013 Update 5

License

Licensed under an Apache-2.0 license.

color's People

Contributors

dmilos avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.