A color component calculation library written in Swift.
Add the following dependency to your
.package(url: "https://github.com/sersoft-gmbh/color-components.git", from: "1.0.0"),
Or add it via Xcode (as of Xcode 11).
There are currently three color component implementations included in
Each implementation is generic and supports both integer values (0 - 255) and floating point values (0.0 - 1.0). Also, each implementation allows converting between them.
If available, each implementation also provides conversion options from and to the platform native colors (e.g.
UIColor on iOS, tvOS & watchOS and
NSColor on macOS).
SwiftUI.Color is also supported as of macOS 11, iOS 14, tvOS 14 and watchOS 7. Due to the lack of direct component accessors,
SwiftUI.Color support goes through the aforementioned platform colors.
While not yet integrated, the following features might provide added value and could make it into this package in the future:
- CMYK color components.
- Color space support.
- More ways of converting between the components.
The API is documented using header doc. If you prefer to view the documentation as a webpage, there is an online version available for you.
If you find a bug / like to see a new feature in this package there are a few ways of helping out:
- If you can fix the bug / implement the feature yourself please do and open a PR.
- If you know how to code (which you probably do), please add a (failing) test and open a PR. We'll try to get your test green ASAP.
- If you can do neither, then open an issue. While this might be the easiest way, it will likely take the longest for the bug to be fixed / feature to be implemented.
See LICENSE file.
You may find interesting
v1.4.0 - 2021-01-14T19:23:51
- Add overloads to use hex values (
hexValue()) also with floating point types on RGB/A
hexValueon RGB/A that returns the hex value as an integer (e.g.
RGB<UInt8>(red: 0xAB, green: 0x34, blue: 0xD3).hexValue(as: UInt64)returns
v1.3.0 - 2021-01-14T08:33:00
- Add feature to color calculations for calculating
prominentColors(as well as an accessor for the
v1.2.0 - 2021-01-06T14:20:21
- Add more convenience conversions between floating point and integer components.
- Add hex string initializer for RGB.
- Add overload of hex initializer with differently sized integer, e.g. to allow
RGBA<UInt8>to be created from hex (w/o overflowing).
v1.1.1 - 2021-01-05T17:29:20
- Only create one
v1.1.0 - 2021-01-05T14:25:27
- Adds a new library
CoreImageto extract various colors from images.
v1.0.1 - 2020-12-29T15:50:39
- Fixes the header in the README
- Fix mistakes in the header doc.
No functional changes were made. Release is merely to redeploy the docs.
v1.0.0 - 2020-12-29T12:50:25