decolmor 1.0.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1633188a81e5b270b4e7ba878d9b72df23a864ea98e299428cef3cfb0948b906
4
- data.tar.gz: 5db8fee23dd5652b66943a715058ae04ea47bdbaaf3ceeed6711407e23fc5fff
3
+ metadata.gz: 4394b870f83f01ebe74db59131475d1d9a72bd32d307e36b775f903fbfe95b67
4
+ data.tar.gz: e9aad1484b539e938e666de21bd5eb1a630118646b3391da4d40d95a473ea766
5
5
  SHA512:
6
- metadata.gz: b9cf4ffd31d01c26bd2d78337ef316bcb81bd7ad06bc7471a5ccc4738e90103a6443008517a289889a0e0c9cc94e6e0387b188e08508f4ae01f312cf90c5ecd2
7
- data.tar.gz: 602694cadb39dbef406d503ca75e632a650e571710a30a1f1a7935b8aec425b6583e03148f1bc5a07f8128cd63e6b478b0bea5b442f9be1a7a34bd8833ce391d
6
+ metadata.gz: 939483bfc049fefab624f9ed62e10b081684ce020a3b0d96189036eb20747386f9693c831221684eb1403eeb0af899e29382459798fd3bbbebdbf232f8976aec
7
+ data.tar.gz: 606d35831d04dea98b8405e176240d2cf4ceedd9f7684170b0c972fc9b7db97964ab2c5080de897d3308b900fd5d0b9aeaafb1f8ce5ad899147f320796d6a45a
data/CHANGELOG.md CHANGED
@@ -1,5 +1,45 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.2.0 (September 21, 2021)
4
+
5
+ * `.hex_to_rgb` now support a returnable alpha in range `0..255`
6
+ `.rgb_to_hex` now support incoming alpha in range `0..255`
7
+ use the option: `alpha_255: true`
8
+ * refactor code for methods:
9
+ - hsl_to_rgb
10
+ - hsv_to_rgb
11
+ - hsb_to_rgb
12
+ - hsl_to_rgb_alt
13
+ - hsv_to_rgb_alt
14
+ - hsb_to_rgb_alt
15
+ Removed some inaccuracies in the math, which didn't affect the result.
16
+ Code in the _alt methods became clearer.
17
+ Improved performance, especially _alt methods
18
+ (but its still a bit slower than the main methods ~1.3X)
19
+
20
+ ## 1.1.2 (September 16, 2021)
21
+
22
+ * Migrate: Travis CI => Github Actions Workflow
23
+ * Fix: returned helper methods to private
24
+ * Now the main code is in one file: lib/decolmor/main.rb
25
+ You can just `include` it in and use it (separately from the gem)
26
+
27
+ ## 1.1.1 (September 16, 2021)
28
+
29
+ * Now you can `include` the module into your class
30
+ * gem methods will be available as class methods
31
+ * Fixed default branch in .gemspec metadata paths
32
+
33
+ ## 1.1.0 (September 14, 2021)
34
+
35
+ * .hex_to_rgb
36
+ * change default rounding 5 => 3 for Alpha channel
37
+ *reason: 3 digits is enough for a lossless conversion `0..255` -> `0..1` -> `0..255`*
38
+ * for the Alpha channel now you can set rounding as the second argument:
39
+ `Decolmor.hex_to_rgb(hex, 2)`
40
+ * support short version of HEX
41
+ e.g: `#CF3`, `0F9`, `#0F9F`
42
+
3
43
  ## 1.0.0 (September 13, 2021)
4
44
 
5
45
  * Initial release
data/NEWS.md CHANGED
@@ -1,4 +1,25 @@
1
1
  # News
2
2
 
3
+ ## 1.2.0 (September 21, 2021)
4
+
5
+ * `.hex_to_rgb` now support a returnable alpha in range `0..255`
6
+ `.rgb_to_hex` now support incoming alpha in range `0..255`
7
+ use the option: `alpha_255: true`
8
+ * Improved performance for HSL/HSV/HSB => RGB conversion
9
+
10
+ ## 1.1.2 (September 16, 2021)
11
+
12
+ * Migrate: Travis CI => Github Actions Workflow
13
+
14
+ ## 1.1.1 (September 16, 2021)
15
+
16
+ * Now you can `include` the module into your class
17
+ * gem methods will be available as class methods
18
+
19
+ ## 1.1.0 (September 14, 2021)
20
+
21
+ * `.hex_to_rgb` Now supports short version of HEX and rounding for the alpha channel
22
+
3
23
  ## 1.0.0 (September 13, 2021)
24
+
4
25
  * First version
data/README.md CHANGED
@@ -1,12 +1,15 @@
1
1
  # Decolmor
2
- [![Gem Version](https://badge.fury.io/rb/decolmor.svg)](http://badge.fury.io/rb/decolmor)
3
- [![Build Status](https://app.travis-ci.com/ChildrenofkoRn/decolmor.svg?token=ssJ5zvqjK7iZ4F1TaeQn&branch=main)](https://app.travis-ci.com/ChildrenofkoRn/decolmor)
4
- [![codecov](https://codecov.io/gh/ChildrenofkoRn/decolmor/branch/main/graph/badge.svg?token=5P4OQUXC3N)](https://codecov.io/gh/ChildrenofkoRn/decolmor)
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 the color spaces from/to: HEX/RGB/HSL/HSV/HSB/CMYK
7
+ Gem for converting color spaces from/to: HEX/RGB/HSL/HSV/HSB/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,39 +35,69 @@ gem install decolmor
32
35
  require 'decolmor'
33
36
 
34
37
  rgb = [29, 128, 86]
35
- Decolmor::rgb_to_hsb(rgb)
38
+ Decolmor.rgb_to_hsb(rgb)
36
39
  => [154.5, 77.3, 50.2]
37
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
+
38
53
  ## Rounding for HSL/HSV/HSB/CMYK
39
54
  By default, rounding 1 is used to convert to HSL/HSV/HSB/CMYK.
40
55
  This is enough to loselessly convert RGB -> HSL/HSV/HSB/CMYK -> RGB:
41
56
  ```ruby
42
57
  rgb = [224, 23, 131]
43
- hsl = Decolmor::rgb_to_hsl(rgb) # => [327.8, 81.4, 48.4]
44
- hsv = Decolmor::rgb_to_hsv(rgb) # => [327.8, 89.7, 87.8]
45
- Decolmor::hsv_to_rgb(hsv) # => [224, 23, 131]
46
- Decolmor::hsl_to_rgb(hsl) # => [224, 23, 131]
58
+ hsl = Decolmor.rgb_to_hsl(rgb) # => [327.8, 81.4, 48.4]
59
+ hsv = Decolmor.rgb_to_hsv(rgb) # => [327.8, 89.7, 87.8]
60
+ Decolmor.hsv_to_rgb(hsv) # => [224, 23, 131]
61
+ Decolmor.hsl_to_rgb(hsl) # => [224, 23, 131]
47
62
  ```
48
63
  If you convert between HSL <==> HSV (HSB) with a rounding of 2, you can get more accurate results.
64
+ This can also be useful if you use HSL/HSB for intermediate changes and then go back to RGB.
49
65
  You can change rounding globally:
50
66
  ```ruby
51
- Decolmor::hsx_round = 2
52
- Decolmor::rgb_to_hsl(rgb) # => [154.55, 63.06, 30.78]
53
- Decolmor::hsx_round # => 2
67
+ Decolmor.hsx_round = 2
68
+ Decolmor.rgb_to_hsl(rgb) # => [154.55, 63.06, 30.78]
69
+ Decolmor.hsx_round # => 2
54
70
  ```
55
71
  You can also specify rounding as a second argument when calling the method:
56
72
  ```ruby
57
- Decolmor::rgb_to_hsl(rgb, 3) # => [154.545, 63.057, 30.784]
73
+ Decolmor.rgb_to_hsl(rgb, 3) # => [154.545, 63.057, 30.784]
58
74
  ```
59
75
  In this case, the global rounding will be ignored.
60
76
  If you need to get integers, use 0.
61
-
77
+
78
+ ## HEX to RGB(A)
79
+ - with & without prefix `#`
80
+ - short HEX are supported (including Alpha)
81
+ - can be set rounding for the Alpha channel
82
+
62
83
  ## Alpha channel
63
- When converting from HEX to RGBA Alpha channel is converted to a value from the range `0..1` with rounding 5:
84
+ When converting from HEX to RGBA Alpha channel is converted to a value from the range `0..1` with rounding 3:
85
+ - 3 digits is enough for a lossless conversion `0..255` -> `0..1` -> `0..255`
64
86
  ```ruby
65
- Decolmor::hex_to_rgb('#19988BB8') # => [25, 152, 139, 0.72157]
87
+ Decolmor.hex_to_rgb('#19988BB8') # => [25, 152, 139, 0.722]
88
+ Decolmor.hex_to_rgb([25, 152, 139, 0.722) # => "#19988BB8"
66
89
  ```
67
90
  Consequently, when converting to HEX from RGBA, Alpha from the range `0..1` is assumed.
91
+ But you can set range 0..255 for alpha channel:
92
+ ```ruby
93
+ Decolmor.hex_to_rgb('#19988BB8', alpha_255: true) # => [25, 152, 139, 184]
94
+ Decolmor.rgb_to_hex([25, 152, 139, 184], alpha_255: true) # => "#19988BB8"
95
+ ```
96
+ You can also set rounding for Alpha channel as a second argument:
97
+ ```ruby
98
+ Decolmor.hex_to_rgb('#19988BB8', 2) # => [25, 152, 139, 0.72]
99
+ ```
100
+ This only works for converting HEX to RGBA.
68
101
  In other cases (conversions between RGB/HSL/HSV/HSB/CMYK) Alpha channel remains unchanged.
69
102
 
70
103
  ## HSV or HSB
@@ -72,8 +105,8 @@ HSB is an alternative name for HSV, it is the same thing.
72
105
  However, for convenience, aliasing methods are made for HSB from HSV.
73
106
  ```ruby
74
107
  rgb = [255, 109, 55]
75
- Decolmor::rgb_to_hsv(rgb) # => [16.2, 78.4, 100.0]
76
- Decolmor::rgb_to_hsb(rgb) # => [16.2, 78.4, 100.0]
108
+ Decolmor.rgb_to_hsv(rgb) # => [16.2, 78.4, 100.0]
109
+ Decolmor.rgb_to_hsb(rgb) # => [16.2, 78.4, 100.0]
77
110
  ```
78
111
  ## HSL/HSV/HSB to RGB conversion
79
112
  HSL/HSV/HSB to RGB conversion has two implementations, the gem includes both:
@@ -86,7 +119,7 @@ or
86
119
  - hsv_to_rgb_alt
87
120
  - hsb_to_rgb_alt
88
121
 
89
- The results of the two implementations are identical, but the alternative versions (postfix `_alt`) are ~1.6X slower.
122
+ The results of the two implementations are identical, but the alternative versions (postfix `_alt`) are ~1.35X slower.
90
123
 
91
124
  ## Attention for CMYK !
92
125
  Unfortunately, there is no simple formula for linear RGB to/from CMYK conversion.
@@ -94,13 +127,13 @@ This implementation is a simplified/dirty/simulation.
94
127
  CMYK is used for printing and the correct conversion will be non-linear, based on the color profile for the particular printing device.
95
128
  Therefore, the CMYK conversion results will not match Adobe products.
96
129
  **BUT:**
97
- Conversion to HEX/RGB/HSL/HSV/HSB is simple and is described by formulas.
130
+ Conversion from/to HEX/RGB/HSL/HSV/HSB is simple and is described by formulas.
98
131
  Read more: https://en.wikipedia.org/wiki/HSL_and_HSV
99
132
  The results when rounded to an integer will be the same as when using graphics editors, such as CorelDRAW or Adobe Photoshop.
100
133
 
101
134
  ## Supported Methods
102
135
  - Setter global rounding for conversion to HSL/HSV/HSB/CMYK
103
- - Decolmor::hsx_round =
136
+ - hsx_round =
104
137
  - HEX <==> RGB(A)
105
138
  - hex_to_rgb
106
139
  - rgb_to_hex
@@ -114,7 +147,7 @@ The results when rounded to an integer will be the same as when using graphics e
114
147
  - hsl_to_rgb
115
148
  - hsv_to_rgb
116
149
  - hsb_to_rgb
117
- - Alternative implementation HSL/HSV/HSB to RGB(A) (~1.6X slower)
150
+ - Alternative implementation HSL/HSV/HSB to RGB(A) (a little slower)
118
151
  - hsl_to_rgb_alt
119
152
  - hsv_to_rgb_alt
120
153
  - hsb_to_rgb_alt
@@ -131,3 +164,20 @@ The results when rounded to an integer will be the same as when using graphics e
131
164
  MIT License
132
165
  Copyright (c) 2021 ChildrenofkoRn
133
166
  [LICENSE](https://github.com/ChildrenofkoRn/decolmor/blob/master/LICENSE)
167
+
168
+
169
+
170
+ [gem]: https://badge.fury.io/rb/decolmor "gem version"
171
+ [badge-gem]: https://badge.fury.io/rb/decolmor.svg "gem version"
172
+ [codecov]: https://codecov.io/gh/ChildrenofkoRn/decolmor "codecov"
173
+ [badge-codecov]: https://codecov.io/gh/ChildrenofkoRn/decolmor/branch/main/graph/badge.svg?token=5P4OQUXC3N "codecov"
174
+ [github-workflow]: https://github.com/ChildrenofkoRn/decolmor/actions/workflows/build.yml "build"
175
+ [badge-build]: https://img.shields.io/github/workflow/status/ChildrenofkoRn/decolmor/build/main "build status"
176
+ [license]: https://github.com/ChildrenofkoRn/decolmor/blob/main/LICENSE "MIT"
177
+ [badge-license]: https://img.shields.io/github/license/ChildrenofkoRn/decolmor?color=%23239393 "license"
178
+
179
+
180
+ [changelog]: https://github.com/ChildrenofkoRn/decolmor/blob/main/CHANGELOG.md "changelog"
181
+ [news]: https://github.com/ChildrenofkoRn/decolmor/blob/main/NEWS.md "news"
182
+ [releases]: https://github.com/ChildrenofkoRn/decolmor/releases "releases"
183
+ [wiki]: https://github.com/ChildrenofkoRn/decolmor/wiki "wiki"
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 = "Gem for converting color spaces from/to: HEX/RGB/HSL/HSV/HSB/CMYK\n" \
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"]
@@ -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/master/NEWS.md",
28
- "changelog_uri" => "#{spec.homepage}/blob/master/CHANGELOG.md",
29
- "documentation_uri" => "#{spec.homepage}/blob/master/README.md",
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
  }