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



59
60
61
62
63
64
65
# File 'lib/origami/graphics/colors.rb', line 59

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



67
68
69
# File 'lib/origami/graphics/colors.rb', line 67

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

.to_a(color) ⇒ Object



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/origami/graphics/colors.rb', line 105

def Color.to_a(color)
    return color if color.is_a?(::Array)

    if %i(r g b).all? {|c| color.respond_to?(c)}
        r = color.r.to_f / 255
        g = color.g.to_f / 255
        b = color.b.to_f / 255
        return [r, g, b]

    elsif %i(c m y k).all? {|c| color.respond_to?(c)}
        c = color.c
        m = color.m
        y = color.y
        k = color.k
        return [c,m,y,k]

    elsif color.respond_to?(:g)
        g = color.g
        return [g]

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