Class: Color::CMYK

Inherits:
Base
  • Object
show all
Defined in:
lib/quadtone/color/cmyk.rb

Instance Attribute Summary

Attributes inherited from Base

#components

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#<=>, average, colorspace_name, #eql?, from_cgats, #hash, #initialize, num_components, #to_s, #to_str

Methods included from Math

#deg2rad, #rad2deg

Constructor Details

This class inherits a constructor from Color::Base

Class Method Details

.cgats_color_repObject



14
15
16
# File 'lib/quadtone/color/cmyk.rb', line 14

def self.cgats_color_rep
  'CMYKcmk1k'
end

.cgats_fieldsObject



9
10
11
12
# File 'lib/quadtone/color/cmyk.rb', line 9

def self.cgats_fields
  %w{CMYKcmk1k_C CMYKcmk1k_M CMYKcmk1k_Y CMYKcmk1k_K
     CMYKcmk1k_c CMYKcmk1k_m CMYKcmk1k_k CMYKcmk1k_1k}
end

.component_namesObject



5
6
7
# File 'lib/quadtone/color/cmyk.rb', line 5

def self.component_names
  [:c, :m, :y, :k, :lc, :lm, :lk, :llk]
end

Instance Method Details

#cObject



18
19
20
# File 'lib/quadtone/color/cmyk.rb', line 18

def c
  @components[0]
end

#kObject



30
31
32
# File 'lib/quadtone/color/cmyk.rb', line 30

def k
  @components[3]
end

#lcObject



34
35
36
# File 'lib/quadtone/color/cmyk.rb', line 34

def lc
  @components[4]
end

#lkObject



42
43
44
# File 'lib/quadtone/color/cmyk.rb', line 42

def lk
  @components[6]
end

#llkObject



46
47
48
# File 'lib/quadtone/color/cmyk.rb', line 46

def llk
  @components[7]
end

#lmObject



38
39
40
# File 'lib/quadtone/color/cmyk.rb', line 38

def lm
  @components[5]
end

#mObject



22
23
24
# File 'lib/quadtone/color/cmyk.rb', line 22

def m
  @components[1]
end

#to_aObject



106
107
108
# File 'lib/quadtone/color/cmyk.rb', line 106

def to_a
  @components
end

#to_cgatsObject



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/quadtone/color/cmyk.rb', line 50

def to_cgats
  {
    'CMYKcmk1k_C'  => c,
    'CMYKcmk1k_M'  => m,
    'CMYKcmk1k_Y'  => y,
    'CMYKcmk1k_K'  => k,
    'CMYKcmk1k_c'  => lc,
    'CMYKcmk1k_m'  => lm,
    'CMYKcmk1k_k'  => lk,
    'CMYKcmk1k_1k' => llk,
  }
end

#to_cmyObject



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/quadtone/color/cmyk.rb', line 77

def to_cmy
  # after http://www.easyrgb.com/index.php?X=MATH&H=14#text14

  c0, m0, y0, k0 = *to_cmyk
  c0 /= 100.0
  m0 /= 100.0
  y0 /= 100.0
  k0 /= 100.0

  c0 = (c0 * (1 - k0)) + k0
  m0 = (m0 * (1 - k0)) + k0
  y0 = (y0 * (1 - k0)) + k0

  Color::CMYK.new([c0 * 100, m0 * 100, y0 * 100])
end

#to_cmykObject



63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/quadtone/color/cmyk.rb', line 63

def to_cmyk
  # estimates for light & light-light inks
  l_factor = 0.5
  ll_factor = 0.25

  # first adjust for light inks
  c0 = c + (lc * l_factor)
  m0 = m + (lm * l_factor)
  y0 = y
  k0 = k + (lk * l_factor) + (llk * ll_factor)

  Color::CMYK.new([c0, m0, y0, k0])
end

#to_labObject



98
99
100
# File 'lib/quadtone/color/cmyk.rb', line 98

def to_lab
  to_xyz.to_lab
end

#to_rgbObject



93
94
95
96
# File 'lib/quadtone/color/cmyk.rb', line 93

def to_rgb
  cmy = to_cmy
  Color::RGB.new([1 - (cmy.c / 100), 1 - (cmy.m / 100), 1 - (cmy.y / 100)])
end

#to_xyzObject



102
103
104
# File 'lib/quadtone/color/cmyk.rb', line 102

def to_xyz
  to_rgb.to_xyz
end

#yObject



26
27
28
# File 'lib/quadtone/color/cmyk.rb', line 26

def y
  @components[2]
end