Uni(fying) Color Model

Cover - Unifying Color Model

GitHub License Pub Package Code Size Publisher

Build Status Pull Requests Issues Pub Score

Unified color structure for represent any color: model (CMYK, RGB, HSL, etc.), with or without alpha, depth per channel, channel-by-channel view (hex, dec, int, double, percentage. string), etc. Сan transform the structures.

The easy-to-use and well-tested package. Feel free to use it in your awesome projects.

When you need to determine the color value by name or vice versa, refer to the package UniColorName.

If you're looking for a structured color palette, look at UniColorPalette.

Share some ❤️ and star repo to support the project.

Android iOS Linux MacOS Windows
platform
Dart Flutter
SDK

Usage

final c = 0x1805db.rgbInt8Color;
print(c.int24Hex);
print(c.hasAlpha);
print('Red channel: #${c.r.hex()}');
1805db
false
Red channel: #18

See also UniColorPalette example/all_palettes folder with Flutter example that visualize palette.

Color Palettes

See the package uni_color_palette.

Glossary

Color depth or Bit depth

The number of bits per pixel in a bitmap image. List of common depths.

Color Converters

The formulas for color conversion are easily programmable, but we have many converters. So let's summarize them (TODO):

alpha model type depth structure tone
false cmyk double 4 double int bits
true rgb int 8 int int dec
hsl 10 List int hex
hsv 16 String num bits
xyz UniColor percent double
percent int
  • alpha == transparency (channel 0)
  • model == channels (1..4)
  • type == type channel
  • depth == depth per channel, for type int only
  • structure == how to keep a color
  • tone == how to represent a structure
    • int bits == use when int dec same int hex
    • num bits == generelization of double and int

Constructors UniColor

  • argbInt8Color, rgbInt8Color, ...
  • acmykInt8Color, acmykInt8Color, ...
  • ...

Structure int bits

  • 0x0a1b2c
  • 0xff0a1b2c with alpha
  • 0xabc == 0xaabbcc
  • 0xa == 0xaaaaaa

Structure String<int hex>

Case insensetivity.

Spaces between channels are allowed.

  • '#0a1b2c' == '0a1b2c' == '0a 1b 2c'
  • '#ff0a1b2c' == 'ff0a1b2c' == 'ff 0a 1b 2c'
  • '#abc' == 'a b c' == 'aabbcc'
  • '#a' == 'aaaaaa'

Structure String<int dec>

Included to TODO below.

  • '12 134 205'
  • '255 12 134 205'
  • '120' == '120 120 120'

Structure String<percent double>

Included to TODO below.

  • '0.12 0.134 0.205'
  • '1.0 0.12 0.134 0.205'
  • '0.120' == '0.12 0.12 0.12'

Structure percent<int>

Included to TODO below.

  • '12% 13% 95%'
  • '100% 12% 13% 95%'
  • '20%' == '20% 20% 20%'

A converter name using a these schema:

[model][type][depth]To[model][type][depth][structure][tone].

Examples of uses:

// as ARGB model
0xff0a1b2c.argbInt8ToArgbInt8StringIntHex();
ff0a1b2c
// as ARGB model, auto added alpha
0x0a1b2c.rgbInt8ToArgbInt8StringIntHex();
ff0a1b2c
// as RGB UniColor with int, 16 bits per channel
0x0a1b2c.rgbInt8ToRgbInt16Color();
// type: RgbInt16Color
0a1b2c
// as RGB int, 16 bits per channel
0x0a1b2c.rgbInt8ToRgbInt16();
// type: int
000a001b002c

Resources

Working on this project, I found amazing resources and am grateful to the authors:

Welcome to Inspiration

Requests and suggestions are warmly welcome.

Contributions are what make the open-source community such a great place to learn, create, and be inspired.

If this is your first contribution, I'll leave you with some of the best links I've found: they will help you get started or/and become even more efficient.

The package UniColorModel is open-source, stable and well-tested. Development happens on GitHub. Feel free to report issues or create a pull-request there.

General questions are best asked on StackOverflow.

And here is a curated list of how you can help:

  • Report parts of the documentation that are unclear.
  • Fix typos/grammar mistakes.
  • Update the documentation or add examples.
  • Report bugs and scenarios that are difficult to implement.
  • Implement new features by making a pull-request (look below).

TODO (perhaps)

Once you start using the UniColorModel, it will become easy to choose the functionality to contribute. But if you already get everything you need from this package but have some free time, let me write here what I have planned:

It's just a habit of mine: writing down ideas that come to mind while working on a project. I confess that I rarely return to these notes. But now, hopefully, even if you don't have an idea yet, the above notes will help you choose the suitable "feature" and become a contributor to the open-source community.

Created with ❤️

Libraries

uni_color_model