Uni(fying) Color Model
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 | 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
sameint hex
- num bits == generelization of
double
andint
- int bits == use when
Constructors UniColor
argbInt8Color
,rgbInt8Color
, ...acmykInt8Color
,acmykInt8Color
, ...- ...
Structure int bits
0x0a1b2c
0xff0a1b2c
with alpha0xabc == 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:
- thecolorapi.com Pass in any valid color and get conversion into any other format, the name of the color, placeholder images and a multitude of schemes.
- colorhexmap.com Get Ready to Explore a World of Color.
- canva.com/learn/color-tips 10 color inspiration secrets only designers know about.
- canva.com/colors/color-wheel Color theory and the color wheel.
- canva.com/learn/100-color-combinations 100 inspiring color combinations & Free color palette generator.
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.
- Guide to Making a First Contribution. You will find the guide in your native language.
- How to Contribute to Open Source. Longread for deep diving for first-timers and for veterans.
- Summer Guide from Google.
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:
-
Feautures for this package into
README
. -
Dependency to
collection
package. We can do without. -
Structures
String<int dec>
. -
Structures
String<percent double>
. -
Structure
percent<int>
. -
Check out the Web platform.
-
Converters between palettes.
-
How to define your own map for color palette.
-
Range checker to each model.
-
Autodetect a model when constructing a
Palette
. -
operator[]
for getting a value by color name and vice versa. -
The range of values to check the integrity of the color.
-
A converter name using as extension and constructing by these schema:
color[SourceModel]To[Structure][ResultModel]()
. For example:colorRgbToIntCmyk
. -
Colors with transparent. ftp.pwg.org/pub/pwg/candidates/cs-pwgmsn20-20130328-5101.1.pdf
-
HKS color system. en.m.wikipedia.org/wiki/HKS_(colour_system)
-
Natural color system. en.m.wikipedia.org/wiki/Natural_Color_System
-
CIE-LAB, CIE-LCH, CIE-LUV, XYY, HUNTER-LAB. 1
-
Color characteristics? For ex., LRV: en.m.wikipedia.org/wiki/Light_reflectance_value -> thelandofcolor.com/lrv-light-reflectance-value-of-paint-colors CR: en.m.wikipedia.org/wiki/Color_rendering_index
-
Articles from en.m.wikipedia.org/wiki/Index_of_color-related_articles.
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 ❤️