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.

Android iOS Linux MacOS Web Windows
platform
Dart Flutter
SDK

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

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):

⬇️ model (channels)
cmyk
rgb
hsl
hsv
xyz
⬇️ num
double
int
⬇️ depth per channel
1
2
3
4
5
6
...
⬇️ channel view
dec
hex
percent
⬇️ alpha (transparency)
false
true
⬇️ structure
int
String
Iterable<double>
Iterable<int>
UniColor<double>
UniColor<int>

TODO A converter name using as extension and constructing by these schema: color[SourceModel]To[Structure][ResultModel]().

For example:

colorRgbToIntCmyk colorRgbToInt colorRgbToIntHsl ... colorRgbToStringCmyk colorRgbToString ... colorRgbToUniColorDoubleCmyk colorRgbToUniColorDouble ... colorRgbToUniColorIntCmyk ... colorCmykToIterableDoubleRgb colorCmykToIterableInt ... colorRgbToIterableIntHsv colorXyzToIterableIntXyz

Examples of uses:

// as ARGB model by default
0xFFCC00DE.colorToString();

// represent as XYZ model before transformation
0xCC00DE.model(ColorModel.hsl).colorToString();
// or with same result
0xCC00DE.colorModelHsl.colorToString();

// as ARGB model by default
'ffcc00de'.colorToInt();

// 255 is a max value for the channel for normalize a color to range [0.0; 1.0]
[1, 12, 128].colorToUniColorDouble(255);
// the result will be `(1.0, 1 / 255, 12 / 255, 128 / 255)`

// but in this case
[1, 12, 128].colorToUniColorDouble();
// the result will be `(255.0, 1.0, 12.0, 128.0)`

[0.1, 0.12, 0.128].colorToUniColorInt(255);
// the result for this example: `(255, 0.1 * 255, 0.12 * 255, 0.128 * 255)`

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