Skip to content

Commit a5f4812

Browse files
committed
+ Agent.md
1 parent da9cf4a commit a5f4812

File tree

3 files changed

+78
-10
lines changed

3 files changed

+78
-10
lines changed

Agent.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Kolor Agent
2+
3+
## Overview
4+
5+
Kolor is a Swift library for working with various color spaces and performing color operations. It allows easy conversion between color spaces, color distance calculations, palette generation, image processing, and color grouping. It includes a large collection of predefined colors useful for design and scientific tasks.
6+
7+
## Features
8+
9+
* **Color Spaces:** Supports sRGB, Display P3, Rec. 2020, ProPhoto RGB, linear RGB, HSV, HSL, HWB, HSI, Okhsv/Okhsl, OkLCh, HPLuv, HSLuv, XYZ, Lab-like, LCh-like, ACES, CMYK, and more.
10+
* **Conversions:** Convert colors between different color spaces if possible.
11+
* **Color Distance:** Use `distance(from:)` or deltaE functions for Uniform Color Spaces (UCS) and sRGB.
12+
* **Palette Generation:** For cylindrical color spaces (Hue channel), generate palettes via `paletteGen(bySteps: Int, saturation: Double, value: Double)`.
13+
* **Image Processing:** Convert, analyze, and group image colors quickly and easily.
14+
* **Predefined Color Collections:** A large collection of artistic and scientific colors.
15+
16+
## Design Principles
17+
18+
* Simple and flexible logic for color manipulation.
19+
* sRGB stores values per channel as `UInt8` (0…255), other color spaces use normalized `Double` (0…1), except cylindrical color spaces where Hue is 0…360.
20+
* Built-in extensions for `CGImage` and `Image` classes to simplify image operations.
21+
22+
## Usage Examples
23+
24+
```swift
25+
// Converting a color from sRGB to HSL
26+
let hslColor = sRGBColor.red.toHSL()
27+
28+
// Generating a palette in HSV
29+
let palette = hsvColor.paletteGen(bySteps: 12, saturation: 0.8, value: 0.9)
30+
31+
// Calculating distance between two colors
32+
let distance = color1.distance(from: color2)
33+
34+
// Convert NSImage to array of pixels
35+
let image = NSImage(named: "cat").toCGImage()
36+
let pixels = image.toSRGB()
37+
38+
// Quantanize image
39+
let counts = pixels.makeQuantizedCounts(levels: 4)
40+
let hist = Histogram(from: counts, levels: 4, totalPixels: pixels.count)
41+
42+
// Identifies the most significant colors
43+
let colors = extractColorsWithRatio(from: image, maxDepth: 5)
44+
45+
// Posterize image
46+
let quantized = pixels.map { $0.toQuantized(by: 4) }
47+
let posterized = CGImage.initFrom(rgb: quantized, width: image.width, height: image.height)
48+
49+
```
50+
51+
## Notes
52+
53+
* Components and formulas are adapted from multiple sources and rewritten in Swift.
54+
* Other components translated from C, C++, C#, Python, and JavaScript libraries.
55+
* Library targets Swift 5.6+.

README.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
A library for color spaces and conversions in Swift 5.6+
44

5-
With this library, image conversion, analysis, color similarity, quantization, indexing, and grouping by tones can be implemented easily and quickly.
5+
With this library, image conversion, analysis, color similarity, quantization, indexing, histogram, and grouping by tones can be implemented easily and quickly.
66

77
In addition, the library includes a large collection of colors. These artistic and scientific values can be useful for design work or tasks involving color groups.
88

@@ -17,7 +17,14 @@ LUV › LCh › HSLuv / HPLuv
1717

1818
```Swift
1919
let srgb = sRGB(123, 223, 68)
20-
let lab = srgb.toLAB()
20+
let oklab = srgb.toOKLAB()
21+
22+
let rgb = RGB(r: 1, g: 0.5, b: 0.2)
23+
let p3 = rgb.toDisplayP3()
24+
25+
let xyz = rgb.toXYZ()
26+
let adapted = xyz.to_XYZ(fromWhiteRef: .D65, toWhiteRef: .D50)
27+
2128
```
2229

2330
In color spaces that are Uniform Color Spaces (UCS) and sRGB, the *distance(from:)* method or special deltaE functions can be applied.
@@ -26,6 +33,20 @@ In color spaces that include a cylindrical (Hue) channel, palette generation can
2633

2734
There are excellent and useful extensions for the CGImage and Image classes.
2835

36+
```Swift
37+
38+
let image = NSImage(named: "cat").toCGImage()
39+
let pixels = image.toSRGB()
40+
41+
let counts = pixels.makeQuantizedCounts(levels: 4)
42+
let hist = Histogram(from: counts, levels: 4, totalPixels: pixels.count)
43+
44+
let colors = extractColorsWithRatio(from: image, maxDepth: 5)
45+
46+
let quantized = pixels.map { $0.toQuantized(by: 4) }
47+
let posterized = CGImage.initFrom(rgb: quantized, width: image.width, height: image.height)
48+
49+
```
2950

3051
## Supported:
3152

ToDo.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1 @@
1-
kesselni a már átalakított cam16 képpontokat ... ( ha már megvan ne kelljen átalakítani az rgb-t)
21

3-
channels set -et átnézni, most direkt értéket adunk vagy a struct skálázza magának ?
4-
5-
https://culorijs.org/color-spaces/
6-
7-
HSI
8-
– I = (R+G+B)/3 (átlag)
9-
– A legjobban közelíti az emberi fényesség-érzetet.

0 commit comments

Comments
 (0)