tincture-apca 1.0.0 → 1.1.0
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 +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +1 -1
- data/lib/tincture/apca/version.rb +1 -1
- data/lib/tincture/apca.rb +11 -9
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4ec4fba8841d4a1abf8cb3098ba8a09fbdac6694ee06d1961eb8f72633470199
|
|
4
|
+
data.tar.gz: 5f7c3d4fa2a2091df2110be9bca3dc7acdf66ff96a0b6c911c07e583175de670
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e86c24c6b01ce4d9d1f8b074f08691cadb7c02b83671b059bd97081f96ae4d41391ee9c7740947ca7d18c95502a93c2514304c944f1824eb27ad25b366ee3960
|
|
7
|
+
data.tar.gz: ecd090a79025658f2765ef485b3822480ee858d36e1741d02a39d6c29508a1c408442d4701932d4e2f9055c4e8a4a9a0ee400962b8020563a56eabfaa739bb3e
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.1.0 (2026-10-21)
|
|
4
|
+
|
|
5
|
+
- Performance: `apca_contrast` is about 30% faster and `Apca.luminance` about 2.5 times faster. Luminance looks up each channel's linear value in a table and no longer computes a power. Results are unchanged.
|
|
6
|
+
- Performance: `Apca.contrast` is about 25% faster. It no longer builds an array to soft-clamp its two luminances.
|
|
7
|
+
- Performance: `apca_contrast` with translucent text is about 40% faster. It blends the channels without building a new colour.
|
|
8
|
+
|
|
3
9
|
## 1.0.0 (2026-10-21)
|
|
4
10
|
|
|
5
11
|
- `apca_contrast` and `contrast_color(method: :apca)` for `Tincture::Color`, ported from apca-w3 0.1.9.
|
data/README.md
CHANGED
|
@@ -50,4 +50,4 @@ bundle exec rake # tests and RuboCop
|
|
|
50
50
|
bundle exec rake rdoc # API docs in doc/
|
|
51
51
|
```
|
|
52
52
|
|
|
53
|
-
To release, set the version in `lib/tincture/apca/version.rb`, date the changelog entry, commit, and push a `vX.Y.Z` tag. GitHub Actions runs the checks
|
|
53
|
+
To release, set the version in `lib/tincture/apca/version.rb`, date the changelog entry, commit, and push a `vX.Y.Z` tag. GitHub Actions runs the checks, publishes the gem to rubygems.org through trusted publishing, and creates a GitHub release with that changelog entry as its notes.
|
data/lib/tincture/apca.rb
CHANGED
|
@@ -41,6 +41,8 @@ module Tincture # :nodoc:
|
|
|
41
41
|
loClip: 0.1
|
|
42
42
|
}.freeze
|
|
43
43
|
|
|
44
|
+
LINEAR_CHANNELS = Array.new(256) { (it / 255.0)**SA98G[:mainTRC] }.freeze # :nodoc:
|
|
45
|
+
|
|
44
46
|
module_function
|
|
45
47
|
|
|
46
48
|
# Lc for text on a background, from their #luminance values. Positive for
|
|
@@ -49,7 +51,8 @@ module Tincture # :nodoc:
|
|
|
49
51
|
#
|
|
50
52
|
#: (Float text_y, Float background_y) -> Float
|
|
51
53
|
def contrast(text_y, background_y)
|
|
52
|
-
text_y
|
|
54
|
+
text_y = soft_clamped(text_y)
|
|
55
|
+
background_y = soft_clamped(background_y)
|
|
53
56
|
|
|
54
57
|
lc =
|
|
55
58
|
if (background_y - text_y).abs < SA98G[:deltaYmin] then 0.0
|
|
@@ -65,11 +68,10 @@ module Tincture # :nodoc:
|
|
|
65
68
|
#
|
|
66
69
|
#: ([Integer, Integer, Integer] rgb) -> Float
|
|
67
70
|
def luminance((red, green, blue))
|
|
68
|
-
(SA98G[:sRco] *
|
|
71
|
+
(SA98G[:sRco] * LINEAR_CHANNELS[red]) + (SA98G[:sGco] * LINEAR_CHANNELS[green]) +
|
|
72
|
+
(SA98G[:sBco] * LINEAR_CHANNELS[blue])
|
|
69
73
|
end
|
|
70
74
|
|
|
71
|
-
def linear(channel) = (channel / 255.0)**SA98G[:mainTRC] # :nodoc:
|
|
72
|
-
|
|
73
75
|
def soft_clamped(luminance) # :nodoc:
|
|
74
76
|
luminance > SA98G[:blkThrs] ? luminance : luminance + ((SA98G[:blkThrs] - luminance)**SA98G[:blkClmp])
|
|
75
77
|
end
|
|
@@ -84,7 +86,7 @@ module Tincture # :nodoc:
|
|
|
84
86
|
sapc > -SA98G[:loClip] ? 0.0 : sapc + SA98G[:loWoBoffset]
|
|
85
87
|
end
|
|
86
88
|
|
|
87
|
-
private_class_method :
|
|
89
|
+
private_class_method :soft_clamped, :dark_on_light, :light_on_dark
|
|
88
90
|
|
|
89
91
|
# Added to Tincture::Color.
|
|
90
92
|
module ColorMethods
|
|
@@ -100,15 +102,15 @@ module Tincture # :nodoc:
|
|
|
100
102
|
#: (String | Color background) -> Float
|
|
101
103
|
def apca_contrast(background)
|
|
102
104
|
background = Color.parse(background)
|
|
103
|
-
|
|
105
|
+
text_rgb = opaque? ? rgb : rgb_blended_over(background)
|
|
104
106
|
|
|
105
|
-
Apca.contrast(Apca.luminance(
|
|
107
|
+
Apca.contrast(Apca.luminance(text_rgb), Apca.luminance(background.rgb))
|
|
106
108
|
end
|
|
107
109
|
|
|
108
110
|
private
|
|
109
111
|
|
|
110
|
-
def
|
|
111
|
-
|
|
112
|
+
def rgb_blended_over(background)
|
|
113
|
+
rgb.zip(background.rgb).map { |mine, theirs| ((theirs * (1 - alpha)) + (mine * alpha)).round }
|
|
112
114
|
end
|
|
113
115
|
end
|
|
114
116
|
end
|