color_space_converter 0.1.0 → 0.2.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: 20cb71e19d5243302559a2388d69a354d8decf4bf3ce06627e07542b6347eba5
4
- data.tar.gz: cb64045e462e2f85663da9d8fe0bd4c6c78f040db1e442b42e1465806da5a4cc
3
+ metadata.gz: 582345d61fdef236cd98617a7dce4ae4695c6a152e658d04f8f64e5cbf23da60
4
+ data.tar.gz: 3b4aaa2942bb5d0ba5c765b525a2fc52f7257fbebbfd5bcabedf1eb4be8d7664
5
5
  SHA512:
6
- metadata.gz: 33decd7be1dd6331ac4d397315f500ca714dc447d5729774db836469efa46cb9e08e27eabf3833344204b275a93e0c4f3fb05b9a433e1aad41092d8139265e1f
7
- data.tar.gz: c2bb4e71430069e64ec5f1fbaa295a746d8bd98ce77dfbee8d214e7dc743a1dde3e4d4a71b92fc7fad2b38025fd0518fb525035aa709b87a29c4aecfab474fd3
6
+ metadata.gz: f188a88219ac8e17734d5b202a915612992e5352dad4de974125d7ecb266e85a30dcd6c65d4eb5061568bbe3143db269b0380168aed0d4e031164039aedf6b9f
7
+ data.tar.gz: 2bac0b2bcd8976465ca2760253b102cf0b1b522ad81158c30b79a975200e55d172719c87ce099d86e41b3304f6e35f03d294b589679eddef421b3ddebdf46f46
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- color_space_converter (0.1.0)
4
+ color_space_converter (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1,10 +1,13 @@
1
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/TaigaMikami/color_space_converter/blob/master/LICENSE.txt)
1
2
  [![Build Status](https://travis-ci.org/TaigaMikami/color_space_converter.svg?branch=master)](https://travis-ci.org/TaigaMikami/color_space_converter)
2
3
  [![Coverage Status](https://coveralls.io/repos/github/TaigaMikami/color_space_converter/badge.svg?branch=master)](https://coveralls.io/github/TaigaMikami/color_space_converter?branch=master)
4
+ [![Gem Version](https://badge.fury.io/rb/color_space_converter.svg)](https://badge.fury.io/rb/color_space_converter)
3
5
 
4
6
  # ColorSpaceConverter
5
7
 
6
8
  Welcome to ColorSpaceConverter gem!
7
9
  It is a gem for easy conversion of color space such as rgb, xyz, lab.
10
+ This gem allows you to take into account the brightness of your display (if your display's gamut setting is sRGB).
8
11
 
9
12
  ## Corresponding color space
10
13
  - rgb(hex)
@@ -63,7 +66,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
63
66
 
64
67
  ## Contributing
65
68
 
66
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/color_space_converter. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
69
+ Bug reports and pull requests are welcome on GitHub at https://github.com/TaigaMikami/color_space_converter. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
67
70
 
68
71
  ## License
69
72
 
@@ -74,4 +77,13 @@ The gem is available as open source under the terms of the [MIT License](https:/
74
77
  Everyone interacting in the ColorSpaceConverter project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/color_space_converter/blob/master/CODE_OF_CONDUCT.md).
75
78
 
76
79
  ## Author
77
- [TaigaMikami](https://github.com/TaigaMikami)
80
+ [TaigaMikami](https://github.com/TaigaMikami)
81
+
82
+ ## TODO
83
+ Correspond to the following color space.
84
+ - [x] RGB
85
+ - [x] XYZ
86
+ - [x] LAB
87
+ - [x] HSV
88
+ - [ ] PCCS
89
+ - [ ] NCS
@@ -123,5 +123,71 @@ module ColorSpaceConverter
123
123
  x, y, z = lab2xyz(l, a, b, x_n: x_n, y_n: y_n, z_n: z_n)
124
124
  xyz2rgb(x, y, z)
125
125
  end
126
+
127
+ def rgb2hsv(r, g, b)
128
+ max = [r, g, b].max
129
+ min = [r, g, b].min
130
+ h = 0.0
131
+ s = 0.0
132
+ v = max.to_f
133
+
134
+ if max != min
135
+ if max == r
136
+ h = (b-g).to_f/(max-min) * 60
137
+ elsif max == g
138
+ h = (2 + (r-b).to_f/(max-min)) * 60
139
+ elsif max == b
140
+ h = (4 + (g-r).to_f/(max-min)) * 60
141
+ end
142
+ s = (max - min).to_f/ max
143
+ end
144
+
145
+ h += 360 if h < 0
146
+ h = h.round
147
+ s = (s*100).round
148
+ v = ((v/255)*100).round
149
+ [h, s, v]
150
+ end
151
+
152
+ def hsv2rgb(h, s, v)
153
+ rgb = []
154
+ h = 0 if h == 360
155
+ s = s.to_f / 100
156
+ v = v.to_f / 100
157
+
158
+ if s.zero?
159
+ r = v * 255
160
+ g = v * 255
161
+ b = v * 255
162
+ return [r.to_i, g.to_i, b.to_i]
163
+ end
164
+
165
+ dh = h.to_f / 60
166
+ p = v * (1 - s)
167
+ q = v * (1 - s * (h.to_f / 60 - dh))
168
+ t = v * (1 - s * (1 - (h.to_f / 60 - dh)))
169
+
170
+ # rubocop: disable Style/Semicolon
171
+ case dh
172
+ when 0
173
+ r = v; g = t; b = p;
174
+ when 1
175
+ r = q; g = v; b = p;
176
+ when 2
177
+ r = p; g = v; b = t;
178
+ when 3
179
+ r = p; g = q; b = v;
180
+ when 4
181
+ r = t; g = p; b = v;
182
+ when 5
183
+ r = v; g = p; b = q;
184
+ end
185
+ # rubocop: enable Style/Semicolon
186
+
187
+ [r, g, b].each do |n|
188
+ rgb << (n * 255).round
189
+ end
190
+ rgb
191
+ end
126
192
  end
127
- end
193
+ end
@@ -1,3 +1,3 @@
1
1
  module ColorSpaceConverter
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: color_space_converter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - TaigaMikami
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-12-27 00:00:00.000000000 Z
11
+ date: 2019-01-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler