redgreenblue 0.8.0 → 0.9.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: 766113ae54ad00c066d264e8bd8d63610f5347e75d95aee3c34bacac0b027a99
4
- data.tar.gz: a91d7d49e36ebfc29328e32c2aa67df908e4fbc9d36c4ec957e1e6d8ed3220b7
3
+ metadata.gz: 3acd4edad3c6c358886e6c49138133f207571b610d8ea980fd6ff4d0cb38b7a8
4
+ data.tar.gz: 81833b3ed57dfcde3c0558f196e7be284ac040e56330019a994e214b39c75463
5
5
  SHA512:
6
- metadata.gz: 587d547ca6139b84ef36f8064a768aee1cdb3f5618f4f03c9ab606df477ad6ebffe82b00837fe55b06fcf2ba6275a1d85484f758394755567b1aab81351bf1df
7
- data.tar.gz: e5203156810f3f577bbe20de7d862f96518db292b1f848778dc2c9dc5223b16c9e15e6effc2e08ed4dba655891805873fdf95cda511c5a533f87462200401746
6
+ metadata.gz: 57a8b63684a52f0495ee14c47a391a42bce9ce40914b9eee7523d1685fc4a66135ccb453b9c5c2ab68900dc700266e71651cb420fd0cd3cbdcf57cecb3012d27
7
+ data.tar.gz: 78917822fe1a7cd67acc98912adf1107736609fd996300003bc7c77ff02cbfcdabf6efce4b86481f27dbb568612237dbee726563de76dab1b60188b9c27e2ef8
data/lib/redgreenblue.rb CHANGED
@@ -8,7 +8,9 @@ require 'redgreenblue/base'
8
8
  require 'redgreenblue/24bit'
9
9
  require 'redgreenblue/48bit'
10
10
  require 'redgreenblue/hex'
11
+ require 'redgreenblue/int'
11
12
 
13
+ require 'redgreenblue/gamma'
12
14
  require 'redgreenblue/hsl_hsv'
13
15
  require 'redgreenblue/cie'
14
16
 
@@ -66,7 +66,7 @@ class RGB
66
66
  ( self.class == other.class ) && ( self.values == other.values )
67
67
  end
68
68
 
69
- # Returns a sorted hash of 3 key/value pairs for red, green and blue,
69
+ # Returns a sorted hash of 3 key/value pairs for red, green, and blue,
70
70
  # sorted in order of decreasing value.
71
71
  def to_h
72
72
  ([:red, :green, :blue].zip values).sort_by {
@@ -8,7 +8,7 @@ class RGB
8
8
  # sRGB to XYZ matrix for D65 reference white by Bruce Lindbloom:
9
9
  # - http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html
10
10
  def cie_xyz
11
- r, g, b = expanded_srgb_values
11
+ r, g, b = linear_values
12
12
  [
13
13
  r * 0.4124564 + g * 0.3575761 + b * 0.1804375,
14
14
  r * 0.2126729 + g * 0.7151522 + b * 0.0721750,
@@ -42,21 +42,4 @@ class RGB
42
42
 
43
43
  alias xy cie_xy
44
44
 
45
- private
46
-
47
- # Returns gamma-expanded (inverse-companded) RGB values for sRGB.
48
- #
49
- # Based on:
50
- # - https://en.wikipedia.org/wiki/SRGB
51
- # - http://www.brucelindbloom.com/Eqn_RGB_to_XYZ.html
52
- def expanded_srgb_values
53
- values.map { |v|
54
- if v <= 0.04045
55
- v / 12.92
56
- else
57
- ( ( v + 0.055 ) / 1.055 ) ** 2.4
58
- end
59
- }
60
- end
61
-
62
45
  end
@@ -0,0 +1,44 @@
1
+ class RGB
2
+
3
+ # Returns gamma-expanded (inverse-companded) RGB values for the object (three values between 0 and 1).
4
+ #
5
+ # Based on:
6
+ # - https://en.wikipedia.org/wiki/SRGB
7
+ # - http://www.brucelindbloom.com/Eqn_RGB_to_XYZ.html
8
+ # - https://entropymine.com/imageworsener/srgbformula/
9
+ def linear_values
10
+ if color_space == 'sRGB'
11
+ values.map { |v|
12
+ if v <= 0.04045
13
+ v / 12.92
14
+ else
15
+ ( ( v + 0.055 ) / 1.055 ) ** 2.4
16
+ end
17
+ }
18
+ else
19
+ raise "can not compute gamma for color space '#{color_space}'"
20
+ end
21
+ end
22
+
23
+ # Sets the object's RGB values using three linear RGB values, each between 0 and 1.
24
+ # Linear values will be converted to the object's gamma (gamma-companded).
25
+ #
26
+ # Based on:
27
+ # - https://en.wikipedia.org/wiki/SRGB
28
+ # - http://www.brucelindbloom.com/Eqn_XYZ_to_RGB.html
29
+ # - https://entropymine.com/imageworsener/srgbformula/
30
+ def linear_values=(*a)
31
+ if color_space == 'sRGB'
32
+ self.values = a.flatten.map { |v|
33
+ if v <= 0.0031308
34
+ v * 12.92
35
+ else
36
+ 1.055 * ( v ** ( 1/2.4 ) ) - 0.055
37
+ end
38
+ }.map { |v| v.round(9) }
39
+ else
40
+ raise "can not compute gamma for color space '#{color_space}'"
41
+ end
42
+ end
43
+
44
+ end
@@ -14,16 +14,24 @@ class RGB
14
14
  terminal_background + " \e[0m"
15
15
  end
16
16
 
17
+ def _inspect_short
18
+ _inspect_swatch + " ##{hex}"
19
+ end
20
+
17
21
  def _inspect_simple
18
22
  _inspect_default _inspect_swatch
19
23
  end
20
24
 
21
25
  public
22
26
 
27
+ # Returns a programmer-friendly representation of the object.
28
+ #
29
+ # You can choose among several inspect styles. See the styles, style, and style= class methods.
23
30
  def inspect
24
31
  send "_inspect_#{self.class.style}"
25
32
  end
26
33
 
34
+ # Returns a string representation of the object.
27
35
  def to_s
28
36
  _inspect_default
29
37
  end
@@ -44,6 +52,8 @@ class RGB
44
52
  end
45
53
 
46
54
  # Selects an inspect style.
55
+ #
56
+ # Only the first few characters of your preferred style are required.
47
57
  def self.style=(s)
48
58
  @@style = styles.grep( /^#{s.to_s.downcase}/ ).first || style
49
59
  end
@@ -0,0 +1,22 @@
1
+ class RGB
2
+
3
+ # Returns the color as a 24-bit integer in the range 0..16777215.
4
+ def to_i
5
+ ( r << 16 ) + ( g << 8 ) + b
6
+ end
7
+
8
+ # Creates a new RGB object from a 24-bit integer in the range 0..16777215.
9
+ def self.at(number)
10
+ n = number.to_i
11
+ if (0..16777215) === n
12
+ rgb(
13
+ ( n & 0xff0000 ) >> 16,
14
+ ( n & 0x00ff00 ) >> 8,
15
+ ( n & 0x0000ff )
16
+ )
17
+ else
18
+ raise ArgumentError, "Argument '#{number}' not in range 0..16777215"
19
+ end
20
+ end
21
+
22
+ end
@@ -35,4 +35,19 @@ class RGB
35
35
  new(0,0,1)
36
36
  end
37
37
 
38
+ # Creates a yellow RGB object.
39
+ def self.yellow
40
+ new(1,1,0)
41
+ end
42
+
43
+ # Creates a cyan RGB object.
44
+ def self.cyan
45
+ new(0,1,1)
46
+ end
47
+
48
+ # Creates a magenta RGB object.
49
+ def self.magenta
50
+ new(1,0,1)
51
+ end
52
+
38
53
  end
@@ -13,8 +13,8 @@ class RGB
13
13
 
14
14
  # Returns an array of RGB objects for all possible ways in which the red, green, and blue values of this object can be exchanged.
15
15
  #
16
- # Example: RGB.red.permutation returns [ RGB.red, RGB.green, RGB.blue ]
17
- # See also: shuffle
16
+ # Example: RGB.red.permutation returns [ RGB.red, RGB.green, RGB.blue ].
17
+ # See also: shuffle.
18
18
  def permutation
19
19
  values.permutation.to_a.uniq.map { |v| RGB.new v }
20
20
  end
@@ -24,4 +24,10 @@ class RGB
24
24
  [ RGB.new(red,0,0), RGB.new(0,green,0), RGB.new(0,0,blue) ]
25
25
  end
26
26
 
27
+ # Creates a new RGB object from three RGB objects representing the red, green, and blue components.
28
+ def self.assemble(*a)
29
+ v = a.flatten
30
+ RGB.new(v[0].red, v[1].green, v[2].blue)
31
+ end
32
+
27
33
  end
@@ -31,6 +31,19 @@ class RGB
31
31
  mix(RGB.black, portion)
32
32
  end
33
33
 
34
+ # Returns a set of colors between this color and another. That other color is included.
35
+ #
36
+ # The resulting colors are spaced evenly in the RGB color space using a straightforward calculation.
37
+ # You will likely experience these colors as not exactly evenly spaced.
38
+ def steps(another,step_count=1,include_begin=false)
39
+ # origin (self, optional)
40
+ ( include_begin ? [self.dup] : [] ) +
41
+ # ...plus intermediate colors
42
+ (1..step_count-1).map { |c| mix(another, c.to_f/step_count) } +
43
+ # ...plus destination color
44
+ [another.dup]
45
+ end
46
+
34
47
  private
35
48
 
36
49
  def mix_values(some_values, portion)
@@ -1,4 +1,8 @@
1
1
  # Optional support for Philips Hue lights.
2
+ #
3
+ # Conforms to Bridge API 1.35 for Philips Hue, published 20-Nov-2019.
4
+ # See (regrettably requires registration):
5
+ # - https://developers.meethue.com/develop/hue-api/
2
6
 
3
7
  # Automatically load core RGB class before loading options.
4
8
  require 'redgreenblue'
@@ -8,6 +12,7 @@ class RGB
8
12
  # Returns the arguments required by the Philips Hue API to set a light to this RGB object's hue, saturation and brightness (HSB).
9
13
  #
10
14
  # When formatted as JSON, this hash can be used directly to set a light's state.
15
+ # Only available when optional support for Philips Hue lights is loaded (require 'redgreenblue/opt/philipshue').
11
16
  def to_philips_hue_api_hsb_arguments(black_off=true)
12
17
  my_hsb = hsb
13
18
 
@@ -1,6 +1,7 @@
1
1
  class RGB
2
2
 
3
- # Shows the Mac OS color picker to choose a color for the RGB object.
3
+ # On Mac OS, shows the color picker to choose a color for the RGB object.
4
+ # Not available on other platforms.
4
5
  def pick
5
6
  result = RGB.mac_choose(rrggbb)
6
7
  if result
@@ -8,7 +9,9 @@ class RGB
8
9
  end
9
10
  end
10
11
 
11
- # Shows the Mac OS color picker and creates an RGB object with the chosen color.
12
+ # On Mac OS, shows the color picker and creates an RGB object with the chosen color.
13
+ # Not available on other platforms.
14
+ #
12
15
  # If no default color is specified, the picker defaults to a middle grey.
13
16
  def self.pick(default_color=RGB.new)
14
17
  result = RGB.mac_choose(default_color.rrggbb)
@@ -15,8 +15,13 @@ class RGB
15
15
  self.b = ( ( v & 0x001f ) ) << 3
16
16
  end
17
17
 
18
- # Returns the color in 16-bit RGB565 format as a string of 0's and 1's
18
+ # Deprecated: this method will be removed in a future version.
19
+ # Returns the color in 16-bit RGB565 format as a string of 0's and 1's.
19
20
  def rgb565_binary
21
+ unless defined? @@warned_rgb565_binary_deprecation
22
+ warn "Warning: 'rgb565_binary' has been deprecated and will be removed in a future version of redgreenblue."
23
+ @@warned_rgb565_binary_deprecation = true
24
+ end
20
25
  rgb565.bytes.reverse.map { |b| "%08b" % b }.join
21
26
  end
22
27
 
@@ -1,3 +1,11 @@
1
1
  class RGB
2
- VERSION = '0.8.0'
2
+
3
+ # redgreenblue version.
4
+ VERSION = '0.9.0'
5
+
6
+ # Returns RGB::VERSION.
7
+ def self.version
8
+ VERSION
9
+ end
10
+
3
11
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redgreenblue
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - lllist.eu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-20 00:00:00.000000000 Z
11
+ date: 2020-03-02 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
@@ -22,10 +22,12 @@ files:
22
22
  - lib/redgreenblue/base.rb
23
23
  - lib/redgreenblue/bgr24bit.rb
24
24
  - lib/redgreenblue/cie.rb
25
+ - lib/redgreenblue/gamma.rb
25
26
  - lib/redgreenblue/gif.rb
26
27
  - lib/redgreenblue/hex.rb
27
28
  - lib/redgreenblue/hsl_hsv.rb
28
29
  - lib/redgreenblue/inspect.rb
30
+ - lib/redgreenblue/int.rb
29
31
  - lib/redgreenblue/lazy.rb
30
32
  - lib/redgreenblue/misc.rb
31
33
  - lib/redgreenblue/mix.rb
@@ -40,7 +42,8 @@ files:
40
42
  homepage: https://github.com/lllisteu/redgreenblue
41
43
  licenses:
42
44
  - MIT
43
- metadata: {}
45
+ metadata:
46
+ changelog_uri: https://github.com/lllisteu/redgreenblue/blob/master/History.md
44
47
  post_install_message:
45
48
  rdoc_options: []
46
49
  require_paths: