okmain 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2c425619a6eb56aa2ab047e664de0d648f269decefd2c98e0f761e59b6a0b386
4
- data.tar.gz: 6d9a8f85c673daf3b64da8c8758887b86f581b6110feb32ca8533fab152ef7b4
3
+ metadata.gz: 56e572b6cb9c8626fa17484a93fb4b5172d4f34f653071b7ca223548dd067926
4
+ data.tar.gz: 200af9151a6a0efd3abb01374eba1899b952c4e3b61a6455cd651fdf97516ecc
5
5
  SHA512:
6
- metadata.gz: 8194c83b670eef20447272468737948914a0a845576f8e4a7b288b2c7389d5ed4c6a8b38eb6abd9b01d20e19fdd520bf2fd1155693e0eb4fe8374b46d5fc9762
7
- data.tar.gz: a3fb6d6f38a734d12911f94b0c6c63a91ef385dfb76eaaa70a94b1c260138004d20bb357831df70c2ced7178d36a11406758e02567d5673baa49d929360bb1f7
6
+ metadata.gz: 88803b1165696b26217ca5ed76f15b0f1e946e8280b73a084c62d7f37878ffef5465ceadb071f14a1c6fedf0e3d8699a1f3942f841f5c560a92b87b8c76e9f87
7
+ data.tar.gz: 11b17ecaef7d6cd283e6042674f07ab3a40e06ac8a15c1d1c80f147f31ba9da627f15757cdb80ab8ccc24c85da2fccc3281a297f83e6805317505f359a7bec57
data/CHANGELOG.md CHANGED
@@ -11,6 +11,13 @@ and this project might adhere to [Semantic Versioning](https://semver.org/spec/v
11
11
  - Adding a suite of test images and automating benchmarking new versions against old versions for speed and correctness would be cool.
12
12
  - Even starting this project was AI psychosis. Would have been smarter to see if I like the output of the algorithm for the one specific thing I need this for first, no?
13
13
 
14
+ ## [0.2.1] - 2026-04-25
15
+
16
+ ### Added
17
+ - `Okmain::Oklab` conversion helpers needed by a downstream app:
18
+ `srgb_to_linear`, `srgb8_to_oklab`, `oklab_to_oklch`, `oklch_to_oklab`,
19
+ `srgb8_to_oklch`. Hue is in degrees, normalized to `[0, 360)`.
20
+
14
21
  ## [0.2.0] - 2026-04-25
15
22
 
16
23
  ### Changed
@@ -37,6 +44,7 @@ and this project might adhere to [Semantic Versioning](https://semver.org/spec/v
37
44
  - Dual MIT / Apache-2.0 licensing matching the upstream crate.
38
45
  - README with install and usage examples.
39
46
 
40
- [Unreleased]: https://github.com/midnightmonster/okmain-ruby/compare/v0.2.0...HEAD
47
+ [Unreleased]: https://github.com/midnightmonster/okmain-ruby/compare/v0.2.1...HEAD
48
+ [0.2.1]: https://github.com/midnightmonster/okmain-ruby/compare/v0.2.0...v0.2.1
41
49
  [0.2.0]: https://github.com/midnightmonster/okmain-ruby/compare/v0.1.0...v0.2.0
42
50
  [0.1.0]: https://github.com/midnightmonster/okmain-ruby/releases/tag/v0.1.0
data/lib/okmain/oklab.rb CHANGED
@@ -49,10 +49,45 @@ module Okmain
49
49
  (c * 255.0).round.clamp(0, 255)
50
50
  end
51
51
 
52
+ # sRGB component (0..255) → linear (0..1)
53
+ def srgb_to_linear(c)
54
+ c = c / 255.0
55
+ if c <= 0.04045
56
+ c / 12.92
57
+ else
58
+ ((c + 0.055) / 1.055)**2.4
59
+ end
60
+ end
61
+
52
62
  # Oklab → sRGB [r, g, b] (0..255)
53
63
  def oklab_to_srgb8(l, a, b)
54
64
  r, g, b_ = oklab_to_linear_rgb(l, a, b)
55
65
  [linear_to_srgb(r), linear_to_srgb(g), linear_to_srgb(b_)]
56
66
  end
67
+
68
+ # sRGB [r, g, b] (0..255) → Oklab [L, a, b]
69
+ def srgb8_to_oklab(r, g, b)
70
+ linear_rgb_to_oklab(srgb_to_linear(r), srgb_to_linear(g), srgb_to_linear(b))
71
+ end
72
+
73
+ # Oklab [L, a, b] → OkLCh [L, C, h] with h in degrees [0, 360)
74
+ def oklab_to_oklch(l, a, b)
75
+ c = Math.sqrt(a * a + b * b)
76
+ h = Math.atan2(b, a) * 180.0 / Math::PI
77
+ h += 360.0 if h.negative?
78
+ [l, c, h]
79
+ end
80
+
81
+ # OkLCh [L, C, h] (h in degrees) → Oklab [L, a, b]
82
+ def oklch_to_oklab(l, c, h)
83
+ rad = h * Math::PI / 180.0
84
+ [l, c * Math.cos(rad), c * Math.sin(rad)]
85
+ end
86
+
87
+ # sRGB [r, g, b] (0..255) → OkLCh [L, C, h] with h in degrees [0, 360)
88
+ def srgb8_to_oklch(r, g, b)
89
+ l, a, b_ = srgb8_to_oklab(r, g, b)
90
+ oklab_to_oklch(l, a, b_)
91
+ end
57
92
  end
58
93
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Okmain
4
- VERSION = "0.2.0"
4
+ VERSION = "0.2.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: okmain
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua Paine