class Color::RGB
Public Class Methods
cgats_fields()
click to toggle source
# File lib/quadtone/color/rgb.rb, line 9 def self.cgats_fields %w{RGB_R RGB_G RGB_B} end
component_names()
click to toggle source
# File lib/quadtone/color/rgb.rb, line 5 def self.component_names [:r, :g, :b] end
from_cgats(set)
click to toggle source
# File lib/quadtone/color/rgb.rb, line 13 def self.from_cgats(set) new(*set.values_at(*cgats_fields).map { |n| n / 100.0 }) end
Public Instance Methods
b()
click to toggle source
# File lib/quadtone/color/rgb.rb, line 25 def b @components[2] end
g()
click to toggle source
# File lib/quadtone/color/rgb.rb, line 21 def g @components[1] end
r()
click to toggle source
# File lib/quadtone/color/rgb.rb, line 17 def r @components[0] end
to_a()
click to toggle source
# File lib/quadtone/color/rgb.rb, line 61 def to_a [r, g, b] end
to_cgats()
click to toggle source
# File lib/quadtone/color/rgb.rb, line 29 def to_cgats { 'RGB_R' => r * 100, 'RGB_G' => g * 100, 'RGB_B' => b * 100, } end
to_pixel()
click to toggle source
# File lib/quadtone/color/rgb.rb, line 65 def to_pixel Magick::Pixel.new(*to_a.map { |n| n * Magick::QuantumRange }) end
to_xyz()
click to toggle source
# File lib/quadtone/color/rgb.rb, line 37 def to_xyz # after http://www.easyrgb.com/index.php?X=MATH&H=02#text2 r0, g0, b0 = [r, g, b].map do |n| if n > 0.04045 ((n + 0.055) / 1.055) ** 2.4 else n / 12.92 end end r0 *= 100 g0 *= 100 b0 *= 100 # Observer. = 2°, Illuminant = D65 x = (r0 * 0.4124) + (g0 * 0.3576) + (b0 * 0.1805) y = (r0 * 0.2126) + (g0 * 0.7152) + (b0 * 0.0722) z = (r0 * 0.0193) + (g0 * 0.1192) + (b0 * 0.9505) Color::XYZ.new([x, y, z]) end