decolmor 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/NEWS.md +5 -0
- data/README.md +18 -6
- data/decolmor.gemspec +1 -1
- data/lib/decolmor/main.rb +9 -3
- data/lib/decolmor/version.rb +1 -1
- data/spec/decolmor_spec.rb +19 -1
- data/spec/factories/alpha.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 54f8407f171d29fb366e8a75caa8dde7f133bfe8d035495936ccc467272ed135
|
4
|
+
data.tar.gz: 982d9f6c6e640a5485783d189c00bb9d0edeae24dbf4e05ac4a77d8f38513742
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 25f9e5569646ce8d1bcc4744caa7a1b372e2ff146a1087b1c0785077353e12dda0687052b93a3ae689c7ce3c871a58979424fb95961e609a979990415327370a
|
7
|
+
data.tar.gz: 9ffb5732412c5771da28c3344806aab52d278b7374de18b368bf38713ad93933983629ffc8bd8f9f48fe8cc61ef93854387773d55880af0b3ce333230bb823a0
|
data/CHANGELOG.md
CHANGED
@@ -3,3 +3,13 @@
|
|
3
3
|
## 1.0.0 (September 13, 2021)
|
4
4
|
|
5
5
|
* Initial release
|
6
|
+
|
7
|
+
## 1.1.0 (September 14, 2021)
|
8
|
+
|
9
|
+
* ::hex_to_rgb
|
10
|
+
* change default rounding 5 => 3 for Alpha channel
|
11
|
+
*reason: 3 digits is enough for a lossless conversion `0..255` -> `0..1` -> `0..255`*
|
12
|
+
* for the Alpha channel you can now set rounding as the second argument:
|
13
|
+
`Decolmor::hex_to_rgb(hex, 2)`
|
14
|
+
* support short version of HEX
|
15
|
+
e.g: `#CF3`, `0F9`, `#0F9F`
|
data/NEWS.md
CHANGED
data/README.md
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# Decolmor
|
2
|
-
[![Gem Version](https://badge.fury.io/rb/decolmor.svg)](
|
2
|
+
[![Gem Version](https://badge.fury.io/rb/decolmor.svg)](https://badge.fury.io/rb/decolmor)
|
3
3
|
[![Build Status](https://app.travis-ci.com/ChildrenofkoRn/decolmor.svg?token=ssJ5zvqjK7iZ4F1TaeQn&branch=main)](https://app.travis-ci.com/ChildrenofkoRn/decolmor)
|
4
4
|
[![codecov](https://codecov.io/gh/ChildrenofkoRn/decolmor/branch/main/graph/badge.svg?token=5P4OQUXC3N)](https://codecov.io/gh/ChildrenofkoRn/decolmor)
|
5
5
|
|
6
|
-
Gem for converting
|
6
|
+
Gem for converting color spaces from/to: HEX/RGB/HSL/HSV/HSB/CMYK
|
7
7
|
The Alpha channel (transparency) is supported.
|
8
8
|
There is also a simple RGB generator.
|
9
9
|
|
@@ -46,6 +46,7 @@ This is enough to loselessly convert RGB -> HSL/HSV/HSB/CMYK -> RGB:
|
|
46
46
|
Decolmor::hsl_to_rgb(hsl) # => [224, 23, 131]
|
47
47
|
```
|
48
48
|
If you convert between HSL <==> HSV (HSB) with a rounding of 2, you can get more accurate results.
|
49
|
+
This can also be useful if you use HSL/HSB for intermediate changes and then go back to RGB.
|
49
50
|
You can change rounding globally:
|
50
51
|
```ruby
|
51
52
|
Decolmor::hsx_round = 2
|
@@ -58,13 +59,24 @@ You can also specify rounding as a second argument when calling the method:
|
|
58
59
|
```
|
59
60
|
In this case, the global rounding will be ignored.
|
60
61
|
If you need to get integers, use 0.
|
61
|
-
|
62
|
+
|
63
|
+
## HEX to RGB(A)
|
64
|
+
- with & without prefix `#`
|
65
|
+
- short HEX are supported (including Alpha)
|
66
|
+
- can be set rounding for the Alpha channel
|
67
|
+
|
62
68
|
## Alpha channel
|
63
|
-
When converting from HEX to RGBA Alpha channel is converted to a value from the range `0..1` with rounding
|
69
|
+
When converting from HEX to RGBA Alpha channel is converted to a value from the range `0..1` with rounding 3:
|
70
|
+
- 3 digits is enough for a lossless conversion `0..255` -> `0..1` -> `0..255`
|
64
71
|
```ruby
|
65
|
-
Decolmor::hex_to_rgb('#19988BB8') # => [25, 152, 139, 0.
|
72
|
+
Decolmor::hex_to_rgb('#19988BB8') # => [25, 152, 139, 0.722]
|
66
73
|
```
|
67
74
|
Consequently, when converting to HEX from RGBA, Alpha from the range `0..1` is assumed.
|
75
|
+
You can also set rounding for Alpha channel as a second argument:
|
76
|
+
```ruby
|
77
|
+
Decolmor::hex_to_rgb('#19988BB8', 2) # => [25, 152, 139, 0.72]
|
78
|
+
```
|
79
|
+
This only works for converting HEX to RGBA.
|
68
80
|
In other cases (conversions between RGB/HSL/HSV/HSB/CMYK) Alpha channel remains unchanged.
|
69
81
|
|
70
82
|
## HSV or HSB
|
@@ -100,7 +112,7 @@ The results when rounded to an integer will be the same as when using graphics e
|
|
100
112
|
|
101
113
|
## Supported Methods
|
102
114
|
- Setter global rounding for conversion to HSL/HSV/HSB/CMYK
|
103
|
-
-
|
115
|
+
- hsx_round =
|
104
116
|
- HEX <==> RGB(A)
|
105
117
|
- hex_to_rgb
|
106
118
|
- rgb_to_hex
|
data/decolmor.gemspec
CHANGED
@@ -5,7 +5,7 @@ Gem::Specification.new do |spec|
|
|
5
5
|
spec.version = Decolmor::VERSION
|
6
6
|
spec.licenses = ['MIT']
|
7
7
|
spec.summary = "Converter color spaces from/to: HEX/RGB/HSL/HSV/HSB/CMYK"
|
8
|
-
spec.description = "
|
8
|
+
spec.description = "Converter color spaces from/to: HEX/RGB/HSL/HSV/HSB/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"]
|
data/lib/decolmor/main.rb
CHANGED
@@ -2,9 +2,15 @@ module Decolmor
|
|
2
2
|
|
3
3
|
#========= HEX <==> RGB(A) =============================================
|
4
4
|
|
5
|
-
def self.hex_to_rgb(hex)
|
6
|
-
|
7
|
-
|
5
|
+
def self.hex_to_rgb(hex, alpha_round = 3)
|
6
|
+
hex = hex.gsub('#','')
|
7
|
+
hex = if [3, 4].include? hex.length
|
8
|
+
hex.chars.map{ |char| char * 2 }
|
9
|
+
else
|
10
|
+
hex.scan(/../)
|
11
|
+
end
|
12
|
+
rgb = hex.map(&:hex)
|
13
|
+
rgb.size == 4 ? rgb + [(rgb.delete_at(3) / 255.to_f).round(alpha_round)] : rgb
|
8
14
|
end
|
9
15
|
|
10
16
|
def self.rgb_to_hex(rgb)
|
data/lib/decolmor/version.rb
CHANGED
data/spec/decolmor_spec.rb
CHANGED
@@ -37,7 +37,7 @@ RSpec.describe Decolmor do
|
|
37
37
|
end
|
38
38
|
|
39
39
|
it "HEX w alpha channel and prefix # to RGBA" do
|
40
|
-
docs "alpha into range 0..1 and rounding
|
40
|
+
docs "alpha into range 0..1 and rounding 3"
|
41
41
|
color = colors.keys.sample
|
42
42
|
alphas.each_pair do |hex_alpha, alpha|
|
43
43
|
hex = format('%s%s', color, hex_alpha)
|
@@ -46,6 +46,16 @@ RSpec.describe Decolmor do
|
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
+
it "set rounding for alpha channel" do
|
50
|
+
color = colors.keys.sample
|
51
|
+
alphas.each_pair do |hex_alpha, alpha|
|
52
|
+
rounding = 2
|
53
|
+
hex = format('%s%s', color, hex_alpha)
|
54
|
+
rgba = colors[color][:rgb] + [alpha[:rgb].round(rounding)]
|
55
|
+
expect( Decolmor::hex_to_rgb(hex, rounding) ).to eq rgba
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
49
59
|
it "HEX w alpha channel and w/o prefix # to RGBA" do
|
50
60
|
color = colors.keys.sample
|
51
61
|
|
@@ -55,6 +65,14 @@ RSpec.describe Decolmor do
|
|
55
65
|
expect( Decolmor::hex_to_rgb(hex) ).to eq rgba
|
56
66
|
end
|
57
67
|
end
|
68
|
+
|
69
|
+
it "HEX short version to RGB(A)" do
|
70
|
+
colors = {'6FC' => [102, 255, 204], '#9C3' => [153, 204, 51], '36FF' => [51, 102, 255, 1]}
|
71
|
+
|
72
|
+
colors.each_pair do |hex_short, rgb|
|
73
|
+
expect( Decolmor::hex_to_rgb(hex_short) ).to eq rgb
|
74
|
+
end
|
75
|
+
end
|
58
76
|
end
|
59
77
|
|
60
78
|
describe ".rgb_to_hex" do
|
data/spec/factories/alpha.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: decolmor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ChildrenofkoRn
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-09-
|
11
|
+
date: 2021-09-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -93,7 +93,7 @@ dependencies:
|
|
93
93
|
- !ruby/object:Gem::Version
|
94
94
|
version: '7.0'
|
95
95
|
description: |-
|
96
|
-
|
96
|
+
Converter color spaces from/to: HEX/RGB/HSL/HSV/HSB/CMYK.
|
97
97
|
The Alpha channel (transparency) is supported.
|
98
98
|
There is also a simple RGB generator.
|
99
99
|
email: Rick-ROR@ya.ru
|