Class: ASE::Color::CMYK
- Inherits:
-
Object
- Object
- ASE::Color::CMYK
- Defined in:
- lib/ase/color_modes/cmyk.rb
Instance Attribute Summary collapse
-
#c ⇒ Object
Returns the value of attribute c.
-
#k ⇒ Object
Returns the value of attribute k.
-
#m ⇒ Object
Returns the value of attribute m.
-
#y ⇒ Object
Returns the value of attribute y.
Instance Method Summary collapse
-
#initialize(c = 0, m = 0, y = 0, k = 0) ⇒ CMYK
constructor
A new instance of CMYK.
- #read!(file) ⇒ Object
- #to_a ⇒ Object
- #to_rgb ⇒ Object
- #write!(file) ⇒ Object
Constructor Details
#initialize(c = 0, m = 0, y = 0, k = 0) ⇒ CMYK
8 9 10 11 12 13 |
# File 'lib/ase/color_modes/cmyk.rb', line 8 def initialize(c=0, m=0, y=0, k=0) @c = c @m = m @y = y @k = k end |
Instance Attribute Details
#c ⇒ Object
Returns the value of attribute c.
6 7 8 |
# File 'lib/ase/color_modes/cmyk.rb', line 6 def c @c end |
#k ⇒ Object
Returns the value of attribute k.
6 7 8 |
# File 'lib/ase/color_modes/cmyk.rb', line 6 def k @k end |
#m ⇒ Object
Returns the value of attribute m.
6 7 8 |
# File 'lib/ase/color_modes/cmyk.rb', line 6 def m @m end |
#y ⇒ Object
Returns the value of attribute y.
6 7 8 |
# File 'lib/ase/color_modes/cmyk.rb', line 6 def y @y end |
Instance Method Details
#read!(file) ⇒ Object
15 16 17 18 19 |
# File 'lib/ase/color_modes/cmyk.rb', line 15 def read!(file) @c, @m, @y, @k = 4.times.map do file.read(4).unpack('g')[0].round(4) end end |
#to_a ⇒ Object
39 40 41 |
# File 'lib/ase/color_modes/cmyk.rb', line 39 def to_a [@c, @m, @y, @k] end |
#to_rgb ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/ase/color_modes/cmyk.rb', line 26 def to_rgb r = (1 - (@c * (1 - @k) + @k)) * 255 g = (1 - (@m * (1 - @k) + @k)) * 255 b = (1 - (@y * (1 - @k) + @k)) * 255 # Clamp r = [0, r, 255].sort[1].to_i g = [0, g, 255].sort[1].to_i b = [0, b, 255].sort[1].to_i RGB.new(r, g, b) end |
#write!(file) ⇒ Object
21 22 23 24 |
# File 'lib/ase/color_modes/cmyk.rb', line 21 def write!(file) file.write 'CMYK' to_a.each { |c| file.write [c].pack('g') } end |