Module: Origami::Graphics::Color

Defined in:
lib/origami/graphics/colors.rb

Defined Under Namespace

Modules: BlendMode, Intent, Space Classes: CMYK, GrayScale, ICCProfile, RGB

Class Method Summary collapse

Class Method Details

.cmyk_to_rgb(c, m, y, k) ⇒ Object



67
68
69
70
71
72
73
# File 'lib/origami/graphics/colors.rb', line 67

def self.cmyk_to_rgb(c, m, y, k)
  r = 1 - (( c * ( 1 - k ) + k ))
  g = 1 - (( m * ( 1 - k ) + k ))
  b = 1 - (( y * ( 1 - k ) + k ))
  
  [ r, g, b ]
end

.gray_to_rgb(g) ⇒ Object



75
76
77
# File 'lib/origami/graphics/colors.rb', line 75

def self.gray_to_rgb(g)
  [ g, g, g ]
end

.to_a(color) ⇒ Object



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/origami/graphics/colors.rb', line 113

def Color.to_a(color)
  return color if color.is_a?(::Array)
  
  if (color.respond_to? :r and color.respond_to? :g and color.respond_to? :b) 
    r = (color.respond_to?(:r) ? color.r : color[0]).to_f / 255
    g = (color.respond_to?(:g) ? color.g : color[1]).to_f / 255
    b = (color.respond_to?(:b) ? color.b : color[2]).to_f / 255
    return [r, g, b]

  elsif (color.respond_to? :c and color.respond_to? :m and color.respond_to? :y and color.respond_to? :k)
    c = (color.respond_to?(:c) ? color.c : color[0]).to_f
    m = (color.respond_to?(:m) ? color.m : color[1]).to_f
    y = (color.respond_to?(:y) ? color.y : color[2]).to_f
    k = (color.respond_to?(:k) ? color.k : color[3]).to_f
    return [c,m,y,k]
    
  elsif color.respond_to?:g or (0.0..1.0) === color 
    g = color.respond_to?(:g) ? color.g : color
    return [ g ]

  else
    raise TypeError, "Invalid color : #{color}"
  end
end