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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '03519433f7f021e7c641da9814503f7175233ebab635f70599c419616ac18d15'
4
- data.tar.gz: 58cb22824f9af6a9d99970e0213b8a761b8597fbcf65aa16b60d51a40ce61ca1
3
+ metadata.gz: 4ec4fba8841d4a1abf8cb3098ba8a09fbdac6694ee06d1961eb8f72633470199
4
+ data.tar.gz: 5f7c3d4fa2a2091df2110be9bca3dc7acdf66ff96a0b6c911c07e583175de670
5
5
  SHA512:
6
- metadata.gz: 3014dc7a59b1deb07bc0686482cb4f2a077df8a73f9db6888f7e5abb140e0c9d391b35459e429ed70d232e91dd6445d9f38582a470f66450e221effb10e78c4e
7
- data.tar.gz: 05b97f7f2f23d18296b530945be9fb9c5cfea664b5e3fc36dfc3340c96761572cc64a84bc116a8cd31546d6444180909f0b94db7b536a883d1bcb3a28c703d41
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 and publishes the gem to rubygems.org through trusted publishing.
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.
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Tincture
4
4
  module Apca
5
- VERSION = '1.0.0' # :nodoc:
5
+ VERSION = '1.1.0' # :nodoc:
6
6
  end
7
7
  end
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, background_y = [text_y, background_y].map { soft_clamped(it) }
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] * linear(red)) + (SA98G[:sGco] * linear(green)) + (SA98G[:sBco] * linear(blue))
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 :linear, :soft_clamped, :dark_on_light, :light_on_dark
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
- text = opaque? ? self : blended_over(background)
105
+ text_rgb = opaque? ? rgb : rgb_blended_over(background)
104
106
 
105
- Apca.contrast(Apca.luminance(text.rgb), Apca.luminance(background.rgb))
107
+ Apca.contrast(Apca.luminance(text_rgb), Apca.luminance(background.rgb))
106
108
  end
107
109
 
108
110
  private
109
111
 
110
- def blended_over(background)
111
- Color.rgb(*rgb.zip(background.rgb).map { |mine, theirs| (theirs * (1 - alpha)) + (mine * alpha) })
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tincture-apca
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Croll