decolmor 1.1.0 → 1.3.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 +47 -5
- data/NEWS.md +24 -3
- data/README.md +88 -30
- data/decolmor.gemspec +5 -5
- data/lib/decolmor/main.rb +353 -225
- data/lib/decolmor/version.rb +1 -1
- data/lib/decolmor.rb +0 -14
- data/spec/decolmor_spec.rb +373 -90
- data/spec/factories/colors.rb +51 -24
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9bad9f3f292018ddb773baabedc9fd9d7cd6da14d7932dae3768640124ec8c0a
|
4
|
+
data.tar.gz: 1846c3b81edf98d162ce5c3ac8be9a48475f60d35c4ca57c83ae0c3590fd79c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a3bb07b37d6f970dd81c29cd4aca46f01d8eb6131cd2f2516f43b8e618ef18d4c65ea72c5a26c51f1c0b7ee6b1f63df3f21931fc886610100eb8815eac2e4119
|
7
|
+
data.tar.gz: a3984305b33fd84a30ef1faee7129bcb4da307ee702830f69cf1873f9c0557e6dceee25238d054d42e16deba276e24d1d9293cf9ed6a7b92546ef2a10da079ef
|
data/CHANGELOG.md
CHANGED
@@ -1,15 +1,57 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
-
## 1.
|
3
|
+
## 1.3.0 (September 27, 2021)
|
4
4
|
|
5
|
-
*
|
5
|
+
* Added support HSI <==> RGB
|
6
|
+
> _RGB => HSI when rounding 1 ~2k RGB colors will be slightly different, 2 will fix this_
|
7
|
+
* Added methods for HEX <==> HSL/HSV/HSB/HSI/CMYK
|
8
|
+
* Fixed incorrect conversion to RGB when HUE == 360
|
9
|
+
it was about the methods:
|
10
|
+
* hsl_to_rgb_alt
|
11
|
+
* hsv_to_rgb_alt
|
12
|
+
and new:
|
13
|
+
* hsi_to_rgb
|
14
|
+
|
15
|
+
## 1.2.0 (September 21, 2021)
|
16
|
+
|
17
|
+
* `.hex_to_rgb` now support a returnable alpha in range `0..255`
|
18
|
+
`.rgb_to_hex` now support incoming alpha in range `0..255`
|
19
|
+
use the option: `alpha_255: true`
|
20
|
+
* refactor code for methods:
|
21
|
+
- hsl_to_rgb
|
22
|
+
- hsv_to_rgb
|
23
|
+
- hsb_to_rgb
|
24
|
+
- hsl_to_rgb_alt
|
25
|
+
- hsv_to_rgb_alt
|
26
|
+
- hsb_to_rgb_alt
|
27
|
+
Removed some inaccuracies in the math, which didn't affect the result.
|
28
|
+
Code in the _alt methods became clearer.
|
29
|
+
Improved performance, especially _alt methods
|
30
|
+
(but its still a bit slower than the main methods ~1.3X)
|
31
|
+
|
32
|
+
## 1.1.2 (September 16, 2021)
|
33
|
+
|
34
|
+
* Migrate: Travis CI => Github Actions Workflow
|
35
|
+
* Fix: returned helper methods to private
|
36
|
+
* Now the main code is in one file: lib/decolmor/main.rb
|
37
|
+
You can just `include` it in and use it (separately from the gem)
|
38
|
+
|
39
|
+
## 1.1.1 (September 16, 2021)
|
40
|
+
|
41
|
+
* Now you can `include` the module into your class
|
42
|
+
* gem methods will be available as class methods
|
43
|
+
* Fixed default branch in .gemspec metadata paths
|
6
44
|
|
7
45
|
## 1.1.0 (September 14, 2021)
|
8
46
|
|
9
|
-
*
|
47
|
+
* .hex_to_rgb
|
10
48
|
* change default rounding 5 => 3 for Alpha channel
|
11
49
|
*reason: 3 digits is enough for a lossless conversion `0..255` -> `0..1` -> `0..255`*
|
12
|
-
* for the Alpha channel you can
|
13
|
-
`Decolmor
|
50
|
+
* for the Alpha channel now you can set rounding as the second argument:
|
51
|
+
`Decolmor.hex_to_rgb(hex, 2)`
|
14
52
|
* support short version of HEX
|
15
53
|
e.g: `#CF3`, `0F9`, `#0F9F`
|
54
|
+
|
55
|
+
## 1.0.0 (September 13, 2021)
|
56
|
+
|
57
|
+
* Initial release
|
data/NEWS.md
CHANGED
@@ -1,9 +1,30 @@
|
|
1
1
|
# News
|
2
2
|
|
3
|
-
## 1.
|
3
|
+
## 1.3.0 (September 27, 2021)
|
4
4
|
|
5
|
-
*
|
5
|
+
* added support HSI <==> RGB
|
6
|
+
* added methods for HEX <==> HSL/HSV/HSB/HSI/CMYK
|
7
|
+
|
8
|
+
## 1.2.0 (September 21, 2021)
|
9
|
+
|
10
|
+
* `.hex_to_rgb` now support a returnable alpha in range `0..255`
|
11
|
+
`.rgb_to_hex` now support incoming alpha in range `0..255`
|
12
|
+
use the option: `alpha_255: true`
|
13
|
+
* Improved performance for HSL/HSV/HSB => RGB conversion
|
14
|
+
|
15
|
+
## 1.1.2 (September 16, 2021)
|
16
|
+
|
17
|
+
* Migrate: Travis CI => Github Actions Workflow
|
18
|
+
|
19
|
+
## 1.1.1 (September 16, 2021)
|
20
|
+
|
21
|
+
* Now you can `include` the module into your class
|
22
|
+
* gem methods will be available as class methods
|
6
23
|
|
7
24
|
## 1.1.0 (September 14, 2021)
|
8
25
|
|
9
|
-
*
|
26
|
+
* `.hex_to_rgb` Now supports short version of HEX and rounding for the alpha channel
|
27
|
+
|
28
|
+
## 1.0.0 (September 13, 2021)
|
29
|
+
|
30
|
+
* First version
|
data/README.md
CHANGED
@@ -1,12 +1,15 @@
|
|
1
1
|
# Decolmor
|
2
|
-
[![
|
3
|
-
[![
|
4
|
-
[![codecov]
|
2
|
+
[![badge-gem][badge-gem]][gem]
|
3
|
+
[![badge-build][badge-build]][github-workflow]
|
4
|
+
[![badge-codecov][badge-codecov]][codecov]
|
5
|
+
[![badge-license][badge-license]][license]
|
5
6
|
|
6
|
-
Gem for converting color spaces from/to: HEX/RGB/HSL/HSV/HSB/CMYK
|
7
|
+
Gem for converting color spaces from/to: HEX/RGB/HSL/HSV/HSB/HSI/CMYK
|
7
8
|
The Alpha channel (transparency) is supported.
|
8
9
|
There is also a simple RGB generator.
|
9
10
|
|
11
|
+
[News][news] . [Recent releases][releases] . [Changelog][changelog] . [Wiki][wiki]
|
12
|
+
|
10
13
|
## Install
|
11
14
|
Add the following line to Gemfile:
|
12
15
|
|
@@ -32,35 +35,48 @@ gem install decolmor
|
|
32
35
|
require 'decolmor'
|
33
36
|
|
34
37
|
rgb = [29, 128, 86]
|
35
|
-
Decolmor
|
38
|
+
Decolmor.rgb_to_hsb(rgb)
|
36
39
|
=> [154.5, 77.3, 50.2]
|
37
40
|
```
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
+
or `include` into class:
|
42
|
+
```ruby
|
43
|
+
class SomeClass
|
44
|
+
include Decolmor
|
45
|
+
end
|
46
|
+
SomeClass.rgb_to_hsb(rgb)
|
47
|
+
=> [154.5, 77.3, 50.2]
|
48
|
+
```
|
49
|
+
Gem methods will be available as class methods.
|
50
|
+
|
51
|
+
See [WIKI](https://github.com/ChildrenofkoRn/decolmor/wiki/Examples) for more examples.
|
52
|
+
|
53
|
+
## Rounding for HSL/HSV/HSB/HSI/CMYK
|
54
|
+
By default, rounding 1 is used to convert to HSL/HSV/HSB/HSI/CMYK.
|
55
|
+
This is enough to loselessly convert RGB -> HSL/HSV/HSB/HSI/CMYK -> RGB:
|
56
|
+
* _for HSI this is not quite true ~2k (of 16.6M) RGB colors will be slightly different, rounding 2 fixes this._
|
41
57
|
```ruby
|
42
58
|
rgb = [224, 23, 131]
|
43
|
-
hsl = Decolmor
|
44
|
-
hsv = Decolmor
|
45
|
-
Decolmor
|
46
|
-
Decolmor
|
59
|
+
hsl = Decolmor.rgb_to_hsl(rgb) # => [327.8, 81.4, 48.4]
|
60
|
+
hsv = Decolmor.rgb_to_hsv(rgb) # => [327.8, 89.7, 87.8]
|
61
|
+
Decolmor.hsv_to_rgb(hsv) # => [224, 23, 131]
|
62
|
+
Decolmor.hsl_to_rgb(hsl) # => [224, 23, 131]
|
47
63
|
```
|
48
64
|
If you convert between HSL <==> HSV (HSB) with a rounding of 2, you can get more accurate results.
|
49
65
|
This can also be useful if you use HSL/HSB for intermediate changes and then go back to RGB.
|
50
66
|
You can change rounding globally:
|
51
67
|
```ruby
|
52
|
-
Decolmor
|
53
|
-
Decolmor
|
54
|
-
Decolmor
|
68
|
+
Decolmor.hsx_round = 2
|
69
|
+
Decolmor.rgb_to_hsl(rgb) # => [154.55, 63.06, 30.78]
|
70
|
+
Decolmor.hsx_round # => 2
|
55
71
|
```
|
56
72
|
You can also specify rounding as a second argument when calling the method:
|
57
73
|
```ruby
|
58
|
-
Decolmor
|
74
|
+
Decolmor.rgb_to_hsl(rgb, 3) # => [154.545, 63.057, 30.784]
|
59
75
|
```
|
60
76
|
In this case, the global rounding will be ignored.
|
61
77
|
If you need to get integers, use 0.
|
62
78
|
|
63
|
-
## HEX to
|
79
|
+
## HEX to
|
64
80
|
- with & without prefix `#`
|
65
81
|
- short HEX are supported (including Alpha)
|
66
82
|
- can be set rounding for the Alpha channel
|
@@ -69,23 +85,34 @@ If you need to get integers, use 0.
|
|
69
85
|
When converting from HEX to RGBA Alpha channel is converted to a value from the range `0..1` with rounding 3:
|
70
86
|
- 3 digits is enough for a lossless conversion `0..255` -> `0..1` -> `0..255`
|
71
87
|
```ruby
|
72
|
-
Decolmor
|
88
|
+
Decolmor.hex_to_rgb('#19988BB8') # => [25, 152, 139, 0.722]
|
89
|
+
Decolmor.hex_to_rgb([25, 152, 139, 0.722) # => "#19988BB8"
|
73
90
|
```
|
74
91
|
Consequently, when converting to HEX from RGBA, Alpha from the range `0..1` is assumed.
|
92
|
+
But you can set range 0..255 for alpha channel:
|
93
|
+
```ruby
|
94
|
+
Decolmor.hex_to_rgb('#19988BB8', alpha_255: true) # => [25, 152, 139, 184]
|
95
|
+
Decolmor.rgb_to_hex([25, 152, 139, 184], alpha_255: true) # => "#19988BB8"
|
96
|
+
```
|
75
97
|
You can also set rounding for Alpha channel as a second argument:
|
76
98
|
```ruby
|
77
|
-
Decolmor
|
99
|
+
Decolmor.hex_to_rgb('#19988BB8', 2) # => [25, 152, 139, 0.72]
|
78
100
|
```
|
79
|
-
This only works for converting HEX
|
80
|
-
In other cases (conversions between RGB/HSL/HSV/HSB/CMYK) Alpha channel remains unchanged.
|
101
|
+
This only works for converting from HEX.
|
102
|
+
In other cases (conversions between RGB/HSL/HSV/HSB/HSI/CMYK) Alpha channel remains unchanged.
|
103
|
+
|
104
|
+
## HSL, HSI, HSV or HSB
|
105
|
+
**HSL**, **HSI**, **HSV** - are three _different_ color spaces.
|
106
|
+
They have only one common parameter **HUE**.
|
107
|
+
**S** - **Suturation**, despite the same name, is _different_ in all three spaces,
|
108
|
+
like the last component: **Lightness** / **Intensity** / **Value** (**Brightness**).
|
81
109
|
|
82
|
-
|
83
|
-
HSB is an alternative name for HSV, it is the same thing.
|
110
|
+
**HSB** is an alternative name for **HSV**, it is the same thing.
|
84
111
|
However, for convenience, aliasing methods are made for HSB from HSV.
|
85
112
|
```ruby
|
86
113
|
rgb = [255, 109, 55]
|
87
|
-
Decolmor
|
88
|
-
Decolmor
|
114
|
+
Decolmor.rgb_to_hsv(rgb) # => [16.2, 78.4, 100.0]
|
115
|
+
Decolmor.rgb_to_hsb(rgb) # => [16.2, 78.4, 100.0]
|
89
116
|
```
|
90
117
|
## HSL/HSV/HSB to RGB conversion
|
91
118
|
HSL/HSV/HSB to RGB conversion has two implementations, the gem includes both:
|
@@ -98,7 +125,7 @@ or
|
|
98
125
|
- hsv_to_rgb_alt
|
99
126
|
- hsb_to_rgb_alt
|
100
127
|
|
101
|
-
The results of the two implementations are identical, but the alternative versions (postfix `_alt`) are
|
128
|
+
The results of the two implementations are identical, but the alternative versions (postfix `_alt`) are slightly slower.
|
102
129
|
|
103
130
|
## Attention for CMYK !
|
104
131
|
Unfortunately, there is no simple formula for linear RGB to/from CMYK conversion.
|
@@ -106,7 +133,7 @@ This implementation is a simplified/dirty/simulation.
|
|
106
133
|
CMYK is used for printing and the correct conversion will be non-linear, based on the color profile for the particular printing device.
|
107
134
|
Therefore, the CMYK conversion results will not match Adobe products.
|
108
135
|
**BUT:**
|
109
|
-
Conversion to HEX/RGB/HSL/HSV/HSB is simple and is described by formulas.
|
136
|
+
Conversion from/to HEX/RGB/HSL/HSV/HSB/HSI is simple and is described by formulas.
|
110
137
|
Read more: https://en.wikipedia.org/wiki/HSL_and_HSV
|
111
138
|
The results when rounded to an integer will be the same as when using graphics editors, such as CorelDRAW or Adobe Photoshop.
|
112
139
|
|
@@ -118,15 +145,17 @@ The results when rounded to an integer will be the same as when using graphics e
|
|
118
145
|
- rgb_to_hex
|
119
146
|
- Simple generator RGB, you can set any channel(s)
|
120
147
|
- new_rgb
|
121
|
-
- RGB(A) to HSL/HSV/HSB
|
148
|
+
- RGB(A) to HSL/HSV/HSB/HSI
|
122
149
|
- rgb_to_hsl
|
123
150
|
- rgb_to_hsv
|
124
151
|
- rgb_to_hsb
|
125
|
-
|
152
|
+
- rgb_to_hsi
|
153
|
+
- HSL/HSV/HSB/HSI to RGB(A)
|
126
154
|
- hsl_to_rgb
|
127
155
|
- hsv_to_rgb
|
128
156
|
- hsb_to_rgb
|
129
|
-
|
157
|
+
- hsi_to_rgb
|
158
|
+
- Alternative implementation HSL/HSV/HSB to RGB(A) (a little slower)
|
130
159
|
- hsl_to_rgb_alt
|
131
160
|
- hsv_to_rgb_alt
|
132
161
|
- hsb_to_rgb_alt
|
@@ -138,8 +167,37 @@ The results when rounded to an integer will be the same as when using graphics e
|
|
138
167
|
- RGB(A) <==> CMYK
|
139
168
|
- rgb_to_cmyk
|
140
169
|
- cmyk_to_rgb
|
170
|
+
- HEX => HSL/HSV/HSB/HSI/CMYK
|
171
|
+
- hex_to_hsl
|
172
|
+
- hex_to_hsv
|
173
|
+
- hex_to_hsb
|
174
|
+
- hex_to_hsi
|
175
|
+
- hex_to_cmyk
|
176
|
+
- HSL/HSV/HSB/HSI/CMYK => HEX
|
177
|
+
- hsl_to_hex
|
178
|
+
- hsv_to_hex
|
179
|
+
- hsb_to_hex
|
180
|
+
- hsi_to_hex
|
181
|
+
- cmyk_to_hex
|
141
182
|
|
142
183
|
## License
|
143
184
|
MIT License
|
144
185
|
Copyright (c) 2021 ChildrenofkoRn
|
145
186
|
[LICENSE](https://github.com/ChildrenofkoRn/decolmor/blob/master/LICENSE)
|
187
|
+
|
188
|
+
|
189
|
+
|
190
|
+
[gem]: https://rubygems.org/gems/decolmor "gem version"
|
191
|
+
[badge-gem]: https://img.shields.io/gem/v/decolmor?color=bri&label=gem%20version&logo=ruby&logoColor=f01f7a "gem version"
|
192
|
+
[codecov]: https://codecov.io/gh/ChildrenofkoRn/decolmor "codecov"
|
193
|
+
[badge-codecov]: https://codecov.io/gh/ChildrenofkoRn/decolmor/branch/main/graph/badge.svg?token=5P4OQUXC3N "codecov"
|
194
|
+
[github-workflow]: https://github.com/ChildrenofkoRn/decolmor/actions/workflows/build.yml "build"
|
195
|
+
[badge-build]: https://img.shields.io/github/workflow/status/ChildrenofkoRn/decolmor/build/main "build status"
|
196
|
+
[license]: https://github.com/ChildrenofkoRn/decolmor/blob/main/LICENSE "MIT"
|
197
|
+
[badge-license]: https://img.shields.io/github/license/ChildrenofkoRn/decolmor?color=%23239393 "license"
|
198
|
+
|
199
|
+
|
200
|
+
[changelog]: https://github.com/ChildrenofkoRn/decolmor/blob/main/CHANGELOG.md "changelog"
|
201
|
+
[news]: https://github.com/ChildrenofkoRn/decolmor/blob/main/NEWS.md "news"
|
202
|
+
[releases]: https://github.com/ChildrenofkoRn/decolmor/releases "releases"
|
203
|
+
[wiki]: https://github.com/ChildrenofkoRn/decolmor/wiki "wiki"
|
data/decolmor.gemspec
CHANGED
@@ -4,8 +4,8 @@ Gem::Specification.new do |spec|
|
|
4
4
|
spec.name = 'decolmor'
|
5
5
|
spec.version = Decolmor::VERSION
|
6
6
|
spec.licenses = ['MIT']
|
7
|
-
spec.summary = "Converter color spaces from/to: HEX/RGB/HSL/HSV/HSB/CMYK"
|
8
|
-
spec.description = "Converter color spaces from/to: HEX/RGB/HSL/HSV/HSB/CMYK.\n" \
|
7
|
+
spec.summary = "Converter color spaces from/to: HEX/RGB/HSL/HSV/HSB/HSI/CMYK"
|
8
|
+
spec.description = "Converter color spaces from/to: HEX/RGB/HSL/HSV/HSB/HSI/CMYK.\n" \
|
9
9
|
"The Alpha channel (transparency) is supported.\n" \
|
10
10
|
"There is also a simple RGB generator."
|
11
11
|
spec.authors = ["ChildrenofkoRn"]
|
@@ -24,9 +24,9 @@ Gem::Specification.new do |spec|
|
|
24
24
|
if spec.respond_to?(:metadata)
|
25
25
|
spec.metadata = {
|
26
26
|
"homepage_uri" => spec.homepage.to_s,
|
27
|
-
"news_uri" => "#{spec.homepage}/blob/
|
28
|
-
"changelog_uri" => "#{spec.homepage}/blob/
|
29
|
-
"documentation_uri" => "#{spec.homepage}/blob/
|
27
|
+
"news_uri" => "#{spec.homepage}/blob/main/NEWS.md",
|
28
|
+
"changelog_uri" => "#{spec.homepage}/blob/main/CHANGELOG.md",
|
29
|
+
"documentation_uri" => "#{spec.homepage}/blob/main/README.md",
|
30
30
|
"bug_tracker_uri" => "#{spec.homepage}/issues",
|
31
31
|
"source_code_uri" => spec.homepage.to_s
|
32
32
|
}
|