abachrome 0.1.0 → 0.1.2

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.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/.envrc +3 -0
  3. data/README.md +10 -0
  4. data/Rakefile +15 -0
  5. data/devenv.lock +88 -17
  6. data/devenv.nix +2 -1
  7. data/devenv.yaml +5 -12
  8. data/lib/abachrome/abc_decimal.rb +201 -7
  9. data/lib/abachrome/color.rb +88 -1
  10. data/lib/abachrome/color_mixins/blend.rb +53 -2
  11. data/lib/abachrome/color_mixins/lighten.rb +49 -2
  12. data/lib/abachrome/color_mixins/to_colorspace.rb +67 -2
  13. data/lib/abachrome/color_mixins/to_lrgb.rb +70 -2
  14. data/lib/abachrome/color_mixins/to_oklab.rb +67 -2
  15. data/lib/abachrome/color_mixins/to_oklch.rb +60 -2
  16. data/lib/abachrome/color_mixins/to_srgb.rb +77 -2
  17. data/lib/abachrome/color_models/hsv.rb +25 -2
  18. data/lib/abachrome/color_models/lms.rb +34 -0
  19. data/lib/abachrome/color_models/oklab.rb +19 -2
  20. data/lib/abachrome/color_models/oklch.rb +42 -2
  21. data/lib/abachrome/color_models/rgb.rb +28 -2
  22. data/lib/abachrome/color_models/xyz.rb +28 -0
  23. data/lib/abachrome/color_space.rb +88 -2
  24. data/lib/abachrome/converter.rb +56 -2
  25. data/lib/abachrome/converters/base.rb +69 -2
  26. data/lib/abachrome/converters/lms_to_lrgb.rb +36 -0
  27. data/lib/abachrome/converters/lms_to_srgb.rb +23 -0
  28. data/lib/abachrome/converters/lms_to_xyz.rb +30 -0
  29. data/lib/abachrome/converters/lrgb_to_lms.rb +0 -0
  30. data/lib/abachrome/converters/lrgb_to_oklab.rb +28 -2
  31. data/lib/abachrome/converters/lrgb_to_srgb.rb +27 -2
  32. data/lib/abachrome/converters/lrgb_to_xyz.rb +29 -0
  33. data/lib/abachrome/converters/oklab_to_lms.rb +41 -0
  34. data/lib/abachrome/converters/oklab_to_lrgb.rb +56 -29
  35. data/lib/abachrome/converters/oklab_to_oklch.rb +31 -2
  36. data/lib/abachrome/converters/oklab_to_srgb.rb +27 -2
  37. data/lib/abachrome/converters/oklch_to_lrgb.rb +66 -6
  38. data/lib/abachrome/converters/oklch_to_oklab.rb +29 -4
  39. data/lib/abachrome/converters/oklch_to_srgb.rb +26 -2
  40. data/lib/abachrome/converters/oklch_to_xyz.rb +66 -0
  41. data/lib/abachrome/converters/srgb_to_lrgb.rb +26 -2
  42. data/lib/abachrome/converters/srgb_to_oklab.rb +28 -2
  43. data/lib/abachrome/converters/srgb_to_oklch.rb +27 -2
  44. data/lib/abachrome/converters/xyz_to_lms.rb +30 -0
  45. data/lib/abachrome/converters/xyz_to_oklab.rb +38 -0
  46. data/lib/abachrome/gamut/base.rb +2 -2
  47. data/lib/abachrome/gamut/p3.rb +2 -2
  48. data/lib/abachrome/gamut/rec2020.rb +2 -2
  49. data/lib/abachrome/gamut/srgb.rb +20 -2
  50. data/lib/abachrome/illuminants/base.rb +2 -2
  51. data/lib/abachrome/illuminants/d50.rb +2 -2
  52. data/lib/abachrome/illuminants/d55.rb +2 -2
  53. data/lib/abachrome/illuminants/d65.rb +2 -2
  54. data/lib/abachrome/illuminants/d75.rb +2 -2
  55. data/lib/abachrome/named/css.rb +149 -158
  56. data/lib/abachrome/outputs/css.rb +2 -2
  57. data/lib/abachrome/palette.rb +112 -2
  58. data/lib/abachrome/palette_mixins/interpolate.rb +20 -2
  59. data/lib/abachrome/palette_mixins/resample.rb +2 -2
  60. data/lib/abachrome/palette_mixins/stretch_luminance.rb +2 -2
  61. data/lib/abachrome/parsers/hex.rb +2 -2
  62. data/lib/abachrome/to_abcd.rb +10 -2
  63. data/lib/abachrome/version.rb +2 -2
  64. data/lib/abachrome.rb +78 -2
  65. data/logo.png +0 -0
  66. data/logo.webp +0 -0
  67. metadata +26 -67
@@ -1,7 +1,15 @@
1
- # frozen_string_literal: true
1
+ #
2
2
 
3
3
  module Abachrome
4
4
  module ToAbcd
5
+ # Converts the receiver to an AbcDecimal object.
6
+ #
7
+ # This method converts the receiver (typically a numeric value) to an AbcDecimal
8
+ # instance, which provides high precision decimal arithmetic capabilities for
9
+ # color space calculations.
10
+ #
11
+ # @return [Abachrome::AbcDecimal] a new AbcDecimal instance representing the
12
+ # same numeric value as the receiver
5
13
  def to_abcd
6
14
  AbcDecimal.new(self)
7
15
  end
@@ -10,4 +18,4 @@ end
10
18
 
11
19
  [Numeric, String, Rational].each do |klass|
12
20
  klass.include(Abachrome::ToAbcd)
13
- end
21
+ end
@@ -1,5 +1,5 @@
1
- # frozen_string_literal: true
1
+ #
2
2
 
3
3
  module Abachrome
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.2"
5
5
  end
data/lib/abachrome.rb CHANGED
@@ -1,4 +1,18 @@
1
- # frozen_string_literal: true
1
+ # Abachrome - A Ruby color manipulation library
2
+ #
3
+ # This is the main entry point for the Abachrome library, providing color creation,
4
+ # conversion, and manipulation capabilities across multiple color spaces including
5
+ # sRGB, OKLAB, OKLCH, and linear RGB.
6
+ #
7
+ # Key features:
8
+ # - Create colors from RGB, OKLAB, OKLCH values or hex strings
9
+ # - Convert between different color spaces
10
+ # - Parse colors from hex codes and CSS color names
11
+ # - Register custom color spaces and converters
12
+ # - High-precision decimal arithmetic for accurate color calculations
13
+ #
14
+ # The library uses autoloading for efficient memory usage and provides both
15
+ # functional and object-oriented APIs for color operations.
2
16
 
3
17
  require_relative "abachrome/to_abcd"
4
18
 
@@ -57,27 +71,69 @@ module Abachrome
57
71
  autoload :Hex, "abachrome/parsers/hex"
58
72
  end
59
73
 
74
+ # Creates a new color in the specified color space with given coordinates and alpha value.
75
+ #
76
+ # @param space_name [Symbol, String] The name of the color space (e.g., :srgb, :oklch)
77
+ # @param coordinates [Array<Numeric>] The color coordinates in the specified color space
78
+ # @param alpha [Float] The alpha (opacity) value of the color, defaults to 1.0 (fully opaque)
79
+ # @return [Abachrome::Color] A new Color object in the specified color space with the given coordinates
60
80
  def create_color(space_name, *coordinates, alpha: 1.0)
61
81
  space = ColorSpace.find(space_name)
62
82
  Color.new(space, coordinates, alpha)
63
83
  end
64
84
 
85
+ # Creates a color object from RGB values.
86
+ #
87
+ # @param r [Numeric] The red component value (typically 0-255 or 0.0-1.0)
88
+ # @param g [Numeric] The green component value (typically 0-255 or 0.0-1.0)
89
+ # @param b [Numeric] The blue component value (typically 0-255 or 0.0-1.0)
90
+ # @param alpha [Float] The alpha (opacity) component value (0.0-1.0), defaults to 1.0 (fully opaque)
91
+ # @return [Abachrome::Color] A new Color object initialized with the specified RGB values
65
92
  def from_rgb(r, g, b, alpha = 1.0)
66
93
  Color.from_rgb(r, g, b, alpha)
67
94
  end
68
95
 
96
+ # Creates a color in the OKLAB color space.
97
+ #
98
+ # @param l [Numeric] The lightness component (L) in the OKLAB color space, typically in range 0 to 1
99
+ # @param a [Numeric] The green-red component (a) in the OKLAB color space
100
+ # @param b [Numeric] The blue-yellow component (b) in the OKLAB color space
101
+ # @param alpha [Float] The alpha (opacity) value, ranging from 0.0 (transparent) to 1.0 (opaque), defaults to 1.0
102
+ # @return [Abachrome::Color] A new Color object in the OKLAB color space
69
103
  def from_oklab(l, a, b, alpha = 1.0)
70
104
  Color.from_oklab(l, a, b, alpha)
71
105
  end
72
106
 
107
+ # Creates a new color from OKLCH color space values.
108
+ #
109
+ # @param l [Numeric] The lightness value, typically in range 0-1
110
+ # @param a [Numeric] The chroma (colorfulness) value
111
+ # @param b [Numeric] The hue angle value in degrees (0-360)
112
+ # @param alpha [Numeric] The alpha (opacity) value, between 0-1 (default: 1.0)
113
+ # @return [Abachrome::Color] A new color object initialized with the given OKLCH values
73
114
  def from_oklch(l, a, b, alpha = 1.0)
74
115
  Color.from_oklch(l, a, b, alpha)
75
116
  end
76
117
 
118
+ # Creates a color object from a hexadecimal color code string.
119
+ #
120
+ # @param hex_str [String] The hexadecimal color code string to parse. Can be in formats like
121
+ # "#RGB", "#RRGGBB", "RGB", or "RRGGBB", with or without the leading "#" character.
122
+ # @return [Abachrome::Color] A new Color object representing the parsed hexadecimal color.
123
+ # @example
124
+ # Abachrome.from_hex("#ff0000") # => returns a red Color object
125
+ # Abachrome.from_hex("00ff00") # => returns a green Color object
126
+ # @see Abachrome::Parsers::Hex.parse
77
127
  def from_hex(hex_str)
78
128
  Parsers::Hex.parse(hex_str)
79
129
  end
80
130
 
131
+ # Creates a color object from a CSS color name.
132
+ #
133
+ # @param color_name [String] The CSS color name (e.g., 'red', 'blue', 'cornflowerblue').
134
+ # Case-insensitive.
135
+ # @return [Abachrome::Color, nil] A color object in the RGB color space if the name is valid,
136
+ # nil if the color name is not recognized.
81
137
  def from_name(color_name)
82
138
  rgb_values = Named::CSS::ColorNames[color_name.downcase]
83
139
  return nil unless rgb_values
@@ -85,15 +141,35 @@ module Abachrome
85
141
  from_rgb(*rgb_values.map { |v| v / 255.0 })
86
142
  end
87
143
 
144
+ # Convert a color from its current color space to another color space.
145
+ #
146
+ # @param color [Abachrome::Color] The color object to convert
147
+ # @param to_space [Symbol, String] The destination color space identifier (e.g. :srgb, :oklch)
148
+ # @return [Abachrome::Color] A new color object in the specified color space
88
149
  def convert(color, to_space)
89
150
  Converter.convert(color, to_space)
90
151
  end
91
152
 
153
+ # Register a new color space with the Abachrome library.
154
+ #
155
+ # @param name [Symbol, String] The identifier for the color space being registered
156
+ # @param block [Proc] A block that defines the color space properties and conversion rules
157
+ # @return [Abachrome::ColorSpace] The newly registered color space object
92
158
  def register_color_space(name, &block)
93
159
  ColorSpace.register(name, &block)
94
160
  end
95
161
 
162
+ # Register a new color space converter in the Abachrome system.
163
+ #
164
+ # This method allows registering custom converters between color spaces.
165
+ # Converters are used to transform color representations from one color
166
+ # space to another.
167
+ #
168
+ # @param from_space [Symbol, String] The source color space identifier
169
+ # @param to_space [Symbol, String] The destination color space identifier
170
+ # @param converter [#call] An object responding to #call that performs the conversion
171
+ # @return [void]
96
172
  def register_converter(from_space, to_space, converter)
97
173
  Converter.register(from_space, to_space, converter)
98
174
  end
99
- end
175
+ end
data/logo.png ADDED
Binary file
data/logo.webp ADDED
Binary file
metadata CHANGED
@@ -1,96 +1,44 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: abachrome
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
- - Durable Programming, LLC
7
+ - Durable Programming
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
11
  date: 1980-01-01 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: bigdecimal
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: 3.0.0
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: 3.0.0
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: dry-inflector
29
15
  requirement: !ruby/object:Gem::Requirement
30
16
  requirements:
31
17
  - - "~>"
32
18
  - !ruby/object:Gem::Version
33
- version: 1.2.0
19
+ version: '1.0'
34
20
  type: :runtime
35
21
  prerelease: false
36
22
  version_requirements: !ruby/object:Gem::Requirement
37
23
  requirements:
38
24
  - - "~>"
39
25
  - !ruby/object:Gem::Version
40
- version: 1.2.0
41
- - !ruby/object:Gem::Dependency
42
- name: minitest
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: 5.25.0
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: 5.25.0
55
- - !ruby/object:Gem::Dependency
56
- name: rake
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '13.0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '13.0'
69
- - !ruby/object:Gem::Dependency
70
- name: simplecov
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: 0.22.0
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: 0.22.0
83
- description: 'Abachrome provides a robust set of tools for working with colors: parsing,
84
- manipulation, conversion, etc. Supports RGB, HSV, OkLab and OkLch.'
26
+ version: '1.0'
27
+ description: Abachrome provides a robust set of tools for working with various color
28
+ formats including hex, RGB, HSL, and named colors. Features support for multiple
29
+ color spaces (RGB, HSL, Lab, Oklab), color space conversion, gamut mapping, CSS
30
+ color parsing and formatting, and high-precision color calculations using BigDecimal.
85
31
  email:
86
- - info@durableprogramming.com
32
+ - commercial@durableprogramming.com
87
33
  executables: []
88
34
  extensions: []
89
35
  extra_rdoc_files: []
90
36
  files:
37
+ - ".envrc"
91
38
  - ".rubocop.yml"
92
39
  - CHANGELOG.md
93
40
  - README.md
41
+ - Rakefile
94
42
  - demos/ncurses/plasma.rb
95
43
  - devenv.lock
96
44
  - devenv.nix
@@ -106,23 +54,34 @@ files:
106
54
  - lib/abachrome/color_mixins/to_oklch.rb
107
55
  - lib/abachrome/color_mixins/to_srgb.rb
108
56
  - lib/abachrome/color_models/hsv.rb
57
+ - lib/abachrome/color_models/lms.rb
109
58
  - lib/abachrome/color_models/oklab.rb
110
59
  - lib/abachrome/color_models/oklch.rb
111
60
  - lib/abachrome/color_models/rgb.rb
61
+ - lib/abachrome/color_models/xyz.rb
112
62
  - lib/abachrome/color_space.rb
113
63
  - lib/abachrome/converter.rb
114
64
  - lib/abachrome/converters/base.rb
65
+ - lib/abachrome/converters/lms_to_lrgb.rb
66
+ - lib/abachrome/converters/lms_to_srgb.rb
67
+ - lib/abachrome/converters/lms_to_xyz.rb
68
+ - lib/abachrome/converters/lrgb_to_lms.rb
115
69
  - lib/abachrome/converters/lrgb_to_oklab.rb
116
70
  - lib/abachrome/converters/lrgb_to_srgb.rb
71
+ - lib/abachrome/converters/lrgb_to_xyz.rb
72
+ - lib/abachrome/converters/oklab_to_lms.rb
117
73
  - lib/abachrome/converters/oklab_to_lrgb.rb
118
74
  - lib/abachrome/converters/oklab_to_oklch.rb
119
75
  - lib/abachrome/converters/oklab_to_srgb.rb
120
76
  - lib/abachrome/converters/oklch_to_lrgb.rb
121
77
  - lib/abachrome/converters/oklch_to_oklab.rb
122
78
  - lib/abachrome/converters/oklch_to_srgb.rb
79
+ - lib/abachrome/converters/oklch_to_xyz.rb
123
80
  - lib/abachrome/converters/srgb_to_lrgb.rb
124
81
  - lib/abachrome/converters/srgb_to_oklab.rb
125
82
  - lib/abachrome/converters/srgb_to_oklch.rb
83
+ - lib/abachrome/converters/xyz_to_lms.rb
84
+ - lib/abachrome/converters/xyz_to_oklab.rb
126
85
  - lib/abachrome/gamut/base.rb
127
86
  - lib/abachrome/gamut/p3.rb
128
87
  - lib/abachrome/gamut/rec2020.rb
@@ -141,15 +100,15 @@ files:
141
100
  - lib/abachrome/parsers/hex.rb
142
101
  - lib/abachrome/to_abcd.rb
143
102
  - lib/abachrome/version.rb
103
+ - logo.png
104
+ - logo.webp
144
105
  homepage: https://github.com/durableprogramming/abachrome
145
106
  licenses:
146
107
  - MIT
147
108
  metadata:
148
- allowed_push_host: https://rubygems.org
149
109
  homepage_uri: https://github.com/durableprogramming/abachrome
150
110
  source_code_uri: https://github.com/durableprogramming/abachrome
151
111
  changelog_uri: https://github.com/durableprogramming/abachrome/blob/main/CHANGELOG.md
152
- rubygems_mfa_required: 'true'
153
112
  post_install_message:
154
113
  rdoc_options: []
155
114
  require_paths:
@@ -165,8 +124,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
165
124
  - !ruby/object:Gem::Version
166
125
  version: '0'
167
126
  requirements: []
168
- rubygems_version: 3.5.22
127
+ rubygems_version: 3.5.9
169
128
  signing_key:
170
129
  specification_version: 4
171
- summary: Color parsing, manipulation, and formatting tools.
130
+ summary: A Ruby gem for parsing, manipulating, and managing colors
172
131
  test_files: []