Skip to content

AuburnSounds/colors

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Colors

colors DUB package is a CSS color parsing libraries. It defines basic types for colors, and a monomorphic Color type to use as interchange.

The problem is that screens and CSS now support the P3 colorspace, the end-goal is to be ready for more conversions than just staying sRGB forever. Color will be able to "do it all", in the future.

This is a work in progress. Only sRGB supported for now.

Current features

  • 🎨 color() function to parse a CSS color string.
  • 🎨 rgb() and rgba() functions, return a Color
  • 🎨 hsl() and hsla() functions, return a Color
  • 🎨 Color.toRGBA8() to get a 8-bit sRGB quadruplet
  • 🎨 Color.toRGBA16() to get a 16-bit sRGB quadruplet
  • 🎨 Color.toRGBAf() to get a 32-bit float sRGB quadruplet
  • 🎨 nothrow @nogc @safe
  • 🎨 See test-suite/ for exact syntax supported, the goal is to follow CSS recommendations.

Tip: Parsing a color string

import colors;

// Quick way:
Color c = color("red");
Color c = Color("blue"); // also works

// CSS support (WIP)
c = color("#ab9");
c = color("#0f1c4A43");
c = color("rgba(14.01, 25.0e+0%, 16, 0.5)");
c = color("hsl(180deg, 100%, 50%)");
c = color("gray(100%, 50%)");
c = color("lightgoldenrodyellow");

// More correct way:
string err;
if (!parseCSSColor(str, c, err)) 
    throw new Exception(err);

Making it useful

import std.stdio;
import colors;

void main()
{
    RGBA8 c = color("coral").toRGBA8;
    writefln("c is %s,%s,%s,%s", c.r, c.g, c.b, c.a);
}

About

Color parsing library a-la CSS Colors.

Resources

Stars

Watchers

Forks

Languages