Giter Site home page Giter Site logo

color-converter's Introduction

Color converter

This is a little header-only library providing such data types for color representation as RGB, RGBA, CMYK, HSL and HSV. For HEX use a plain integer.

Note

To know more about the API and code in general, see color_convert.h.

Usage example

#include <stdio.h>

#define COLOR_CONVERT_IMPLEMENTATION
#include "color_convert.h"

int main(void)
{
    struct rgb  c1 = { 127, 63, 31 };
    struct hsl  c2 = { 180.f, .75f, .40f };
    int         c3 = 0xABCDEF;
    struct rgba c4 = { 148, 42, 89, 51 };

    printf("rgb(%d, %d, %d)\n", c1.r, c1.g, c1.b);
    printf("hsl(%.0f deg, %.0f %%, %.0f %%)\n", c2.h, c2.s * 100, c2.l * 100);
    printf("hex(#%06X)", c3);

    rgb2hsl(&c1, &c2);
    hsl2rgb(&c2, &c1);

    c2.h += 60.f;
    if (!hsl_valid(&c2))
        return -1; /* will never return */

    rgb_invert(&c1);

    /* c1 and c4 are blended and then the result is stored back in c1 */
    rgb_blend(&c1, &c4);

    return 0;
}

color-converter's People

Contributors

pavelsytnik 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.