color-1.4.2/ 0000755 0000041 0000041 00000000000 12222570513 012663 5 ustar www-data www-data color-1.4.2/test/ 0000755 0000041 0000041 00000000000 12222570513 013642 5 ustar www-data www-data color-1.4.2/test/test_hsl.rb 0000644 0000041 0000041 00000011410 12222570513 016011 0 ustar www-data www-data gem 'minitest'
require 'minitest/autorun'
require 'color'
module TestColor
class TestHSL < Minitest::Test
def setup
# @hsl = Color::HSL.new(262, 67, 42)
@hsl = Color::HSL.new(145, 20, 30)
# @rgb = Color::RGB.new(88, 35, 179)
end
def test_rgb_roundtrip_conversion
hsl = Color::HSL.new(262, 67, 42)
c = hsl.to_rgb.to_hsl
assert_in_delta hsl.h, c.h, Color::COLOR_TOLERANCE, "Hue"
assert_in_delta hsl.s, c.s, Color::COLOR_TOLERANCE, "Saturation"
assert_in_delta hsl.l, c.l, Color::COLOR_TOLERANCE, "Luminance"
end
def test_brightness
assert_in_delta 0.3, @hsl.brightness, Color::COLOR_TOLERANCE
end
def test_hue
assert_in_delta 0.4027, @hsl.h, Color::COLOR_TOLERANCE
assert_in_delta 145, @hsl.hue, Color::COLOR_TOLERANCE
@hsl.hue = 33
assert_in_delta 0.09167, @hsl.h, Color::COLOR_TOLERANCE
@hsl.hue = -33
assert_in_delta 0.90833, @hsl.h, Color::COLOR_TOLERANCE
@hsl.h = 3.3
assert_in_delta 360, @hsl.hue, Color::COLOR_TOLERANCE
@hsl.h = -3.3
assert_in_delta 0.0, @hsl.h, Color::COLOR_TOLERANCE
@hsl.hue = 0
@hsl.hue -= 20
assert_in_delta 340, @hsl.hue, Color::COLOR_TOLERANCE
@hsl.hue += 45
assert_in_delta 25, @hsl.hue, Color::COLOR_TOLERANCE
end
def test_saturation
assert_in_delta 0.2, @hsl.s, Color::COLOR_TOLERANCE
assert_in_delta 20, @hsl.saturation, Color::COLOR_TOLERANCE
@hsl.saturation = 33
assert_in_delta 0.33, @hsl.s, Color::COLOR_TOLERANCE
@hsl.s = 3.3
assert_in_delta 100, @hsl.saturation, Color::COLOR_TOLERANCE
@hsl.s = -3.3
assert_in_delta 0.0, @hsl.s, Color::COLOR_TOLERANCE
end
def test_luminance
assert_in_delta 0.3, @hsl.l, Color::COLOR_TOLERANCE
assert_in_delta 30, @hsl.luminosity, Color::COLOR_TOLERANCE
@hsl.luminosity = 33
assert_in_delta 0.33, @hsl.l, Color::COLOR_TOLERANCE
@hsl.l = 3.3
assert_in_delta 100, @hsl.lightness, Color::COLOR_TOLERANCE
@hsl.l = -3.3
assert_in_delta 0.0, @hsl.l, Color::COLOR_TOLERANCE
end
def test_html_css
assert_equal "hsl(145.00, 20.00%, 30.00%)", @hsl.css_hsl
assert_equal "hsla(145.00, 20.00%, 30.00%, 1.00)", @hsl.css_hsla
end
def test_to_cmyk
cmyk = @hsl.to_cmyk
assert_kind_of Color::CMYK, cmyk
assert_in_delta 0.3223, cmyk.c, Color::COLOR_TOLERANCE
assert_in_delta 0.2023, cmyk.m, Color::COLOR_TOLERANCE
assert_in_delta 0.2723, cmyk.y, Color::COLOR_TOLERANCE
assert_in_delta 0.4377, cmyk.k, Color::COLOR_TOLERANCE
end
def test_to_grayscale
gs = @hsl.to_grayscale
assert_kind_of Color::GreyScale, gs
assert_in_delta 30, gs.gray, Color::COLOR_TOLERANCE
end
def test_to_rgb
rgb = @hsl.to_rgb
assert_kind_of Color::RGB, rgb
assert_in_delta 0.24, rgb.r, Color::COLOR_TOLERANCE
assert_in_delta 0.36, rgb.g, Color::COLOR_TOLERANCE
assert_in_delta 0.29, rgb.b, Color::COLOR_TOLERANCE
assert_equal "#3d5c4a", @hsl.html
assert_equal "rgb(24.00%, 36.00%, 29.00%)", @hsl.css_rgb
assert_equal "rgba(24.00%, 36.00%, 29.00%, 1.00)", @hsl.css_rgba
# The following tests address a bug reported by Jean Krohn on June 6,
# 2006 and excercise some previously unexercised code in to_rgb.
assert_equal Color::RGB::Black, Color::HSL.new(75, 75, 0)
assert_equal Color::RGB::White, Color::HSL.new(75, 75, 100)
assert_equal Color::RGB::Gray80, Color::HSL.new(75, 0, 80)
# The following tests a bug reported by Adam Johnson on 29 October
# 2010.
rgb = Color::RGB.from_fraction(0.34496, 0.1386, 0.701399)
c = Color::HSL.new(262, 67, 42).to_rgb
assert_in_delta rgb.r, c.r, Color::COLOR_TOLERANCE, "Red"
assert_in_delta rgb.g, c.g, Color::COLOR_TOLERANCE, "Green"
assert_in_delta rgb.b, c.b, Color::COLOR_TOLERANCE, "Blue"
end
def test_to_yiq
yiq = @hsl.to_yiq
assert_kind_of Color::YIQ, yiq
assert_in_delta 0.3161, yiq.y, Color::COLOR_TOLERANCE
assert_in_delta 0.0, yiq.i, Color::COLOR_TOLERANCE
assert_in_delta 0.0, yiq.q, Color::COLOR_TOLERANCE
end
def test_mix_with
red = Color::RGB::Red.to_hsl
yellow = Color::RGB::Yellow.to_hsl
assert_in_delta 0, red.hue, Color::COLOR_TOLERANCE
assert_in_delta 60, yellow.hue, Color::COLOR_TOLERANCE
ry25 = red.mix_with yellow, 0.25
assert_in_delta 15, ry25.hue, Color::COLOR_TOLERANCE
ry50 = red.mix_with yellow, 0.50
assert_in_delta 30, ry50.hue, Color::COLOR_TOLERANCE
ry75 = red.mix_with yellow, 0.75
assert_in_delta 45, ry75.hue, Color::COLOR_TOLERANCE
end
def test_inspect
assert_equal "HSL [145.00 deg, 20.00%, 30.00%]", @hsl.inspect
end
end
end
color-1.4.2/test/test_yiq.rb 0000644 0000041 0000041 00000003215 12222570513 016031 0 ustar www-data www-data gem 'minitest'
require 'minitest/autorun'
require 'color'
module TestColor
class TestYIQ < Minitest::Test
def setup
@yiq = Color::YIQ.from_fraction(0.1, 0.2, 0.3)
end
def test_brightness
assert_in_delta(0.1, @yiq.brightness, Color::COLOR_TOLERANCE)
end
def test_i
assert_in_delta(0.2, @yiq.i, Color::COLOR_TOLERANCE)
assert_in_delta(0.2, @yiq.i, Color::COLOR_TOLERANCE)
@yiq.i = 0.5
assert_in_delta(0.5, @yiq.i, Color::COLOR_TOLERANCE)
@yiq.i = 5
assert_in_delta(1.0, @yiq.i, Color::COLOR_TOLERANCE)
@yiq.i = -5
assert_in_delta(0.0, @yiq.i, Color::COLOR_TOLERANCE)
end
def test_q
assert_in_delta(0.3, @yiq.q, Color::COLOR_TOLERANCE)
assert_in_delta(0.3, @yiq.q, Color::COLOR_TOLERANCE)
@yiq.q = 0.5
assert_in_delta(0.5, @yiq.q, Color::COLOR_TOLERANCE)
@yiq.q = 5
assert_in_delta(1.0, @yiq.q, Color::COLOR_TOLERANCE)
@yiq.q = -5
assert_in_delta(0.0, @yiq.q, Color::COLOR_TOLERANCE)
end
def test_to_grayscale
assert_equal(Color::GrayScale.new(0.1), @yiq.to_grayscale)
end
def test_to_yiq
assert_equal(@yiq, @yiq.to_yiq)
end
def test_y
assert_in_delta(0.1, @yiq.y, Color::COLOR_TOLERANCE)
assert_in_delta(0.1, @yiq.y, Color::COLOR_TOLERANCE)
@yiq.y = 0.5
assert_in_delta(0.5, @yiq.y, Color::COLOR_TOLERANCE)
@yiq.y = 5
assert_in_delta(1.0, @yiq.y, Color::COLOR_TOLERANCE)
@yiq.y = -5
assert_in_delta(0.0, @yiq.y, Color::COLOR_TOLERANCE)
end
def test_inspect
assert_equal("YIQ [10.00%, 20.00%, 30.00%]", @yiq.inspect)
end
end
end
color-1.4.2/test/test_rgb.rb 0000644 0000041 0000041 00000035075 12222570513 016012 0 ustar www-data www-data gem 'minitest'
require 'minitest/autorun'
require 'color'
module TestColor
class TestRGB < Minitest::Test
def test_adjust_brightness
assert_equal("#1a1aff", Color::RGB::Blue.adjust_brightness(10).html)
assert_equal("#0000e6", Color::RGB::Blue.adjust_brightness(-10).html)
end
def test_adjust_hue
assert_equal("#6600ff", Color::RGB::Blue.adjust_hue(10).html)
assert_equal("#0066ff", Color::RGB::Blue.adjust_hue(-10).html)
end
def test_adjust_saturation
assert_equal("#ef9374",
Color::RGB::DarkSalmon.adjust_saturation(10).html)
assert_equal("#e39980",
Color::RGB::DarkSalmon.adjust_saturation(-10).html)
end
def test_red
red = Color::RGB::Red.dup
assert_in_delta(1.0, red.r, Color::COLOR_TOLERANCE)
assert_in_delta(100, red.red_p, Color::COLOR_TOLERANCE)
assert_in_delta(255, red.red, Color::COLOR_TOLERANCE)
assert_in_delta(1.0, red.r, Color::COLOR_TOLERANCE)
red.red_p = 33
assert_in_delta(0.33, red.r, Color::COLOR_TOLERANCE)
red.red = 330
assert_in_delta(1.0, red.r, Color::COLOR_TOLERANCE)
red.r = -3.3
assert_in_delta(0.0, red.r, Color::COLOR_TOLERANCE)
end
def test_green
lime = Color::RGB::Lime.dup
assert_in_delta(1.0, lime.g, Color::COLOR_TOLERANCE)
assert_in_delta(100, lime.green_p, Color::COLOR_TOLERANCE)
assert_in_delta(255, lime.green, Color::COLOR_TOLERANCE)
lime.green_p = 33
assert_in_delta(0.33, lime.g, Color::COLOR_TOLERANCE)
lime.green = 330
assert_in_delta(1.0, lime.g, Color::COLOR_TOLERANCE)
lime.g = -3.3
assert_in_delta(0.0, lime.g, Color::COLOR_TOLERANCE)
end
def test_blue
blue = Color::RGB::Blue.dup
assert_in_delta(1.0, blue.b, Color::COLOR_TOLERANCE)
assert_in_delta(255, blue.blue, Color::COLOR_TOLERANCE)
assert_in_delta(100, blue.blue_p, Color::COLOR_TOLERANCE)
blue.blue_p = 33
assert_in_delta(0.33, blue.b, Color::COLOR_TOLERANCE)
blue.blue = 330
assert_in_delta(1.0, blue.b, Color::COLOR_TOLERANCE)
blue.b = -3.3
assert_in_delta(0.0, blue.b, Color::COLOR_TOLERANCE)
end
def test_brightness
assert_in_delta(0.0, Color::RGB::Black.brightness, Color::COLOR_TOLERANCE)
assert_in_delta(0.5, Color::RGB::Grey50.brightness, Color::COLOR_TOLERANCE)
assert_in_delta(1.0, Color::RGB::White.brightness, Color::COLOR_TOLERANCE)
end
def test_darken_by
assert_in_delta(0.5, Color::RGB::Blue.darken_by(50).b,
Color::COLOR_TOLERANCE)
end
def test_html
assert_equal("#000000", Color::RGB::Black.html)
assert_equal(Color::RGB::Black, Color::RGB.from_html("#000000"))
assert_equal("#0000ff", Color::RGB::Blue.html)
assert_equal("#00ff00", Color::RGB::Lime.html)
assert_equal("#ff0000", Color::RGB::Red.html)
assert_equal("#ffffff", Color::RGB::White.html)
assert_equal("rgb(0.00%, 0.00%, 0.00%)", Color::RGB::Black.css_rgb)
assert_equal("rgb(0.00%, 0.00%, 100.00%)", Color::RGB::Blue.css_rgb)
assert_equal("rgb(0.00%, 100.00%, 0.00%)", Color::RGB::Lime.css_rgb)
assert_equal("rgb(100.00%, 0.00%, 0.00%)", Color::RGB::Red.css_rgb)
assert_equal("rgb(100.00%, 100.00%, 100.00%)", Color::RGB::White.css_rgb)
assert_equal("rgba(0.00%, 0.00%, 0.00%, 1.00)", Color::RGB::Black.css_rgba)
assert_equal("rgba(0.00%, 0.00%, 100.00%, 1.00)", Color::RGB::Blue.css_rgba)
assert_equal("rgba(0.00%, 100.00%, 0.00%, 1.00)", Color::RGB::Lime.css_rgba)
assert_equal("rgba(100.00%, 0.00%, 0.00%, 1.00)", Color::RGB::Red.css_rgba)
assert_equal("rgba(100.00%, 100.00%, 100.00%, 1.00)",
Color::RGB::White.css_rgba)
end
def test_lighten_by
assert_in_delta(1.0, Color::RGB::Blue.lighten_by(50).b,
Color::COLOR_TOLERANCE)
assert_in_delta(0.5, Color::RGB::Blue.lighten_by(50).r,
Color::COLOR_TOLERANCE)
assert_in_delta(0.5, Color::RGB::Blue.lighten_by(50).g,
Color::COLOR_TOLERANCE)
end
def test_mix_with
assert_in_delta(0.5, Color::RGB::Red.mix_with(Color::RGB::Blue, 50).r,
Color::COLOR_TOLERANCE)
assert_in_delta(0.0, Color::RGB::Red.mix_with(Color::RGB::Blue, 50).g,
Color::COLOR_TOLERANCE)
assert_in_delta(0.5, Color::RGB::Red.mix_with(Color::RGB::Blue, 50).b,
Color::COLOR_TOLERANCE)
assert_in_delta(0.5, Color::RGB::Blue.mix_with(Color::RGB::Red, 50).r,
Color::COLOR_TOLERANCE)
assert_in_delta(0.0, Color::RGB::Blue.mix_with(Color::RGB::Red, 50).g,
Color::COLOR_TOLERANCE)
assert_in_delta(0.5, Color::RGB::Blue.mix_with(Color::RGB::Red, 50).b,
Color::COLOR_TOLERANCE)
end
def test_pdf_fill
assert_equal("0.000 0.000 0.000 rg", Color::RGB::Black.pdf_fill)
assert_equal("0.000 0.000 1.000 rg", Color::RGB::Blue.pdf_fill)
assert_equal("0.000 1.000 0.000 rg", Color::RGB::Lime.pdf_fill)
assert_equal("1.000 0.000 0.000 rg", Color::RGB::Red.pdf_fill)
assert_equal("1.000 1.000 1.000 rg", Color::RGB::White.pdf_fill)
assert_equal("0.000 0.000 0.000 RG", Color::RGB::Black.pdf_stroke)
assert_equal("0.000 0.000 1.000 RG", Color::RGB::Blue.pdf_stroke)
assert_equal("0.000 1.000 0.000 RG", Color::RGB::Lime.pdf_stroke)
assert_equal("1.000 0.000 0.000 RG", Color::RGB::Red.pdf_stroke)
assert_equal("1.000 1.000 1.000 RG", Color::RGB::White.pdf_stroke)
end
def test_to_cmyk
assert_kind_of(Color::CMYK, Color::RGB::Black.to_cmyk)
assert_equal(Color::CMYK.new(0, 0, 0, 100), Color::RGB::Black.to_cmyk)
assert_equal(Color::CMYK.new(0, 0, 100, 0),
Color::RGB::Yellow.to_cmyk)
assert_equal(Color::CMYK.new(100, 0, 0, 0), Color::RGB::Cyan.to_cmyk)
assert_equal(Color::CMYK.new(0, 100, 0, 0),
Color::RGB::Magenta.to_cmyk)
assert_equal(Color::CMYK.new(0, 100, 100, 0), Color::RGB::Red.to_cmyk)
assert_equal(Color::CMYK.new(100, 0, 100, 0),
Color::RGB::Lime.to_cmyk)
assert_equal(Color::CMYK.new(100, 100, 0, 0),
Color::RGB::Blue.to_cmyk)
assert_equal(Color::CMYK.new(10.32, 60.52, 10.32, 39.47),
Color::RGB::Purple.to_cmyk)
assert_equal(Color::CMYK.new(10.90, 59.13, 59.13, 24.39),
Color::RGB::Brown.to_cmyk)
assert_equal(Color::CMYK.new(0, 63.14, 18.43, 0),
Color::RGB::Carnation.to_cmyk)
assert_equal(Color::CMYK.new(7.39, 62.69, 62.69, 37.32),
Color::RGB::Cayenne.to_cmyk)
end
def test_to_grayscale
assert_kind_of(Color::GrayScale, Color::RGB::Black.to_grayscale)
assert_equal(Color::GrayScale.from_fraction(0),
Color::RGB::Black.to_grayscale)
assert_equal(Color::GrayScale.from_fraction(0.5),
Color::RGB::Yellow.to_grayscale)
assert_equal(Color::GrayScale.from_fraction(0.5),
Color::RGB::Cyan.to_grayscale)
assert_equal(Color::GrayScale.from_fraction(0.5),
Color::RGB::Magenta.to_grayscale)
assert_equal(Color::GrayScale.from_fraction(0.5),
Color::RGB::Red.to_grayscale)
assert_equal(Color::GrayScale.from_fraction(0.5),
Color::RGB::Lime.to_grayscale)
assert_equal(Color::GrayScale.from_fraction(0.5),
Color::RGB::Blue.to_grayscale)
assert_equal(Color::GrayScale.from_fraction(0.2510),
Color::RGB::Purple.to_grayscale)
assert_equal(Color::GrayScale.new(40.58),
Color::RGB::Brown.to_grayscale)
assert_equal(Color::GrayScale.new(68.43),
Color::RGB::Carnation.to_grayscale)
assert_equal(Color::GrayScale.new(27.65),
Color::RGB::Cayenne.to_grayscale)
end
def test_to_hsl
assert_kind_of(Color::HSL, Color::RGB::Black.to_hsl)
assert_equal(Color::HSL.new, Color::RGB::Black.to_hsl)
assert_equal(Color::HSL.new(60, 100, 50), Color::RGB::Yellow.to_hsl)
assert_equal(Color::HSL.new(180, 100, 50), Color::RGB::Cyan.to_hsl)
assert_equal(Color::HSL.new(300, 100, 50), Color::RGB::Magenta.to_hsl)
assert_equal(Color::HSL.new(0, 100, 50), Color::RGB::Red.to_hsl)
assert_equal(Color::HSL.new(120, 100, 50), Color::RGB::Lime.to_hsl)
assert_equal(Color::HSL.new(240, 100, 50), Color::RGB::Blue.to_hsl)
assert_equal(Color::HSL.new(300, 100, 25.10),
Color::RGB::Purple.to_hsl)
assert_equal(Color::HSL.new(0, 59.42, 40.59),
Color::RGB::Brown.to_hsl)
assert_equal(Color::HSL.new(317.5, 100, 68.43),
Color::RGB::Carnation.to_hsl)
assert_equal(Color::HSL.new(0, 100, 27.64),
Color::RGB::Cayenne.to_hsl)
assert_equal("hsl(0.00, 0.00%, 0.00%)", Color::RGB::Black.css_hsl)
assert_equal("hsl(60.00, 100.00%, 50.00%)",
Color::RGB::Yellow.css_hsl)
assert_equal("hsl(180.00, 100.00%, 50.00%)", Color::RGB::Cyan.css_hsl)
assert_equal("hsl(300.00, 100.00%, 50.00%)",
Color::RGB::Magenta.css_hsl)
assert_equal("hsl(0.00, 100.00%, 50.00%)", Color::RGB::Red.css_hsl)
assert_equal("hsl(120.00, 100.00%, 50.00%)", Color::RGB::Lime.css_hsl)
assert_equal("hsl(240.00, 100.00%, 50.00%)", Color::RGB::Blue.css_hsl)
assert_equal("hsl(300.00, 100.00%, 25.10%)",
Color::RGB::Purple.css_hsl)
assert_equal("hsl(0.00, 59.42%, 40.59%)", Color::RGB::Brown.css_hsl)
assert_equal("hsl(317.52, 100.00%, 68.43%)",
Color::RGB::Carnation.css_hsl)
assert_equal("hsl(0.00, 100.00%, 27.65%)", Color::RGB::Cayenne.css_hsl)
assert_equal("hsla(0.00, 0.00%, 0.00%, 1.00)",
Color::RGB::Black.css_hsla)
assert_equal("hsla(60.00, 100.00%, 50.00%, 1.00)",
Color::RGB::Yellow.css_hsla)
assert_equal("hsla(180.00, 100.00%, 50.00%, 1.00)",
Color::RGB::Cyan.css_hsla)
assert_equal("hsla(300.00, 100.00%, 50.00%, 1.00)",
Color::RGB::Magenta.css_hsla)
assert_equal("hsla(0.00, 100.00%, 50.00%, 1.00)",
Color::RGB::Red.css_hsla)
assert_equal("hsla(120.00, 100.00%, 50.00%, 1.00)",
Color::RGB::Lime.css_hsla)
assert_equal("hsla(240.00, 100.00%, 50.00%, 1.00)",
Color::RGB::Blue.css_hsla)
assert_equal("hsla(300.00, 100.00%, 25.10%, 1.00)",
Color::RGB::Purple.css_hsla)
assert_equal("hsla(0.00, 59.42%, 40.59%, 1.00)",
Color::RGB::Brown.css_hsla)
assert_equal("hsla(317.52, 100.00%, 68.43%, 1.00)",
Color::RGB::Carnation.css_hsla)
assert_equal("hsla(0.00, 100.00%, 27.65%, 1.00)",
Color::RGB::Cayenne.css_hsla)
# The following tests a bug reported by Jean Krohn on 10 June 2006
# where HSL conversion was not quite correct, resulting in a bad
# round-trip.
assert_equal("#008800", Color::RGB.from_html("#008800").to_hsl.html)
refute_equal("#002288", Color::RGB.from_html("#008800").to_hsl.html)
# The following tests a bug reported by Adam Johnson on 29 October
# 2010.
hsl = Color::HSL.new(262, 67, 42)
c = Color::RGB.from_fraction(0.34496, 0.1386, 0.701399).to_hsl
assert_in_delta hsl.h, c.h, Color::COLOR_TOLERANCE, "Hue"
assert_in_delta hsl.s, c.s, Color::COLOR_TOLERANCE, "Saturation"
assert_in_delta hsl.l, c.l, Color::COLOR_TOLERANCE, "Luminance"
end
def test_to_rgb
assert_equal(Color::RGB::Black, Color::RGB::Black.to_rgb)
end
def test_to_yiq
assert_kind_of(Color::YIQ, Color::RGB::Black.to_yiq)
assert_equal(Color::YIQ.new, Color::RGB::Black.to_yiq)
assert_equal(Color::YIQ.new(88.6, 32.1, 0), Color::RGB::Yellow.to_yiq)
assert_equal(Color::YIQ.new(70.1, 0, 0), Color::RGB::Cyan.to_yiq)
assert_equal(Color::YIQ.new(41.3, 27.5, 52.3),
Color::RGB::Magenta.to_yiq)
assert_equal(Color::YIQ.new(29.9, 59.6, 21.2), Color::RGB::Red.to_yiq)
assert_equal(Color::YIQ.new(58.7, 0, 0), Color::RGB::Lime.to_yiq)
assert_equal(Color::YIQ.new(11.4, 0, 31.1), Color::RGB::Blue.to_yiq)
assert_equal(Color::YIQ.new(20.73, 13.80, 26.25),
Color::RGB::Purple.to_yiq)
assert_equal(Color::YIQ.new(30.89, 28.75, 10.23),
Color::RGB::Brown.to_yiq)
assert_equal(Color::YIQ.new(60.84, 23.28, 27.29),
Color::RGB::Carnation.to_yiq)
assert_equal(Color::YIQ.new(16.53, 32.96, 11.72),
Color::RGB::Cayenne.to_yiq)
end
def test_add
Color::RGB::Cyan + Color::RGB::Yellow
white = Color::RGB::Cyan + Color::RGB::Yellow
refute_nil(white)
assert_equal(Color::RGB::White, white)
c1 = Color::RGB.new(0x80, 0x80, 0x00)
c2 = Color::RGB.new(0x45, 0x20, 0xf0)
cr = Color::RGB.new(0xc5, 0xa0, 0xf0)
assert_equal(cr, c1 + c2)
end
def test_subtract
black = Color::RGB::LightCoral - Color::RGB::Honeydew
assert_equal(Color::RGB::Black, black)
c1 = Color::RGB.new(0x85, 0x80, 0x00)
c2 = Color::RGB.new(0x40, 0x20, 0xf0)
cr = Color::RGB.new(0x45, 0x60, 0x00)
assert_equal(cr, c1 - c2)
end
def test_mean_grayscale
c1 = Color::RGB.new(0x85, 0x80, 0x00)
c1_max = c1.max_rgb_as_greyscale
c1_max = c1.max_rgb_as_greyscale
c1_result = Color::GrayScale.from_fraction(0x85 / 255.0)
assert_equal(c1_result, c1_max)
end
def test_from_html
assert_equal("RGB [#333333]", Color::RGB.from_html("#333").inspect)
assert_equal("RGB [#333333]", Color::RGB.from_html("333").inspect)
assert_equal("RGB [#555555]", Color::RGB.from_html("#555555").inspect)
assert_equal("RGB [#555555]", Color::RGB.from_html("555555").inspect)
assert_raises(ArgumentError) { Color::RGB.from_html("#5555555") }
assert_raises(ArgumentError) { Color::RGB.from_html("5555555") }
assert_raises(ArgumentError) { Color::RGB.from_html("#55555") }
assert_raises(ArgumentError) { Color::RGB.from_html("55555") }
end
def test_inspect
assert_equal("RGB [#000000]", Color::RGB::Black.inspect)
assert_equal("RGB [#0000ff]", Color::RGB::Blue.inspect)
assert_equal("RGB [#00ff00]", Color::RGB::Lime.inspect)
assert_equal("RGB [#ff0000]", Color::RGB::Red.inspect)
assert_equal("RGB [#ffffff]", Color::RGB::White.inspect)
end
end
end
color-1.4.2/test/test_grayscale.rb 0000644 0000041 0000041 00000006114 12222570513 017202 0 ustar www-data www-data gem 'minitest'
require 'minitest/autorun'
require 'color'
module TestColor
class TestGrayScale < Minitest::Test
def setup
@gs = Color::GrayScale.from_percent(33)
end
def test_brightness
assert_in_delta(0.33, @gs.brightness, Color::COLOR_TOLERANCE)
end
def test_darken_by
assert_in_delta(29.7, @gs.darken_by(10).gray, Color::COLOR_TOLERANCE)
end
def test_g
assert_in_delta(0.33, @gs.g, Color::COLOR_TOLERANCE)
assert_in_delta(33, @gs.grey, Color::COLOR_TOLERANCE)
@gs.gray = 40
assert_in_delta(0.4, @gs.g, Color::COLOR_TOLERANCE)
@gs.g = 2.0
assert_in_delta(100, @gs.gray, Color::COLOR_TOLERANCE)
@gs.grey = -2.0
assert_in_delta(0.0, @gs.g, Color::COLOR_TOLERANCE)
end
def test_html_css
assert_equal("#545454", @gs.html)
assert_equal("rgb(33.00%, 33.00%, 33.00%)", @gs.css_rgb)
assert_equal("rgba(33.00%, 33.00%, 33.00%, 1.00)", @gs.css_rgba)
end
def test_lighten_by
assert_in_delta(0.363, @gs.lighten_by(10).g, Color::COLOR_TOLERANCE)
end
def test_pdf_fill
assert_equal("0.330 g", @gs.pdf_fill)
assert_equal("0.330 G", @gs.pdf_stroke)
end
def test_to_cmyk
cmyk = @gs.to_cmyk
assert_kind_of(Color::CMYK, cmyk)
assert_in_delta(0.0, cmyk.c, Color::COLOR_TOLERANCE)
assert_in_delta(0.0, cmyk.m, Color::COLOR_TOLERANCE)
assert_in_delta(0.0, cmyk.y, Color::COLOR_TOLERANCE)
assert_in_delta(0.67, cmyk.k, Color::COLOR_TOLERANCE)
end
def test_to_grayscale
assert_equal(@gs, @gs.to_grayscale)
assert_equal(@gs, @gs.to_greyscale)
end
def test_to_hsl
hsl = @gs.to_hsl
assert_kind_of(Color::HSL, hsl)
assert_in_delta(0.0, hsl.h, Color::COLOR_TOLERANCE)
assert_in_delta(0.0, hsl.s, Color::COLOR_TOLERANCE)
assert_in_delta(0.33, hsl.l, Color::COLOR_TOLERANCE)
assert_equal("hsl(0.00, 0.00%, 33.00%)", @gs.css_hsl)
assert_equal("hsla(0.00, 0.00%, 33.00%, 1.00)", @gs.css_hsla)
end
def test_to_rgb
rgb = @gs.to_rgb
assert_kind_of(Color::RGB, rgb)
assert_in_delta(0.33, rgb.r, Color::COLOR_TOLERANCE)
assert_in_delta(0.33, rgb.g, Color::COLOR_TOLERANCE)
assert_in_delta(0.33, rgb.b, Color::COLOR_TOLERANCE)
end
def test_to_yiq
yiq = @gs.to_yiq
assert_kind_of(Color::YIQ, yiq)
assert_in_delta(0.33, yiq.y, Color::COLOR_TOLERANCE)
assert_in_delta(0.0, yiq.i, Color::COLOR_TOLERANCE)
assert_in_delta(0.0, yiq.q, Color::COLOR_TOLERANCE)
end
def test_add
delta = @gs + Color::GrayScale.new(20)
max = @gs + Color::GrayScale.new(80)
assert_in_delta(1.0, max.g, Color::COLOR_TOLERANCE)
assert_in_delta(0.53, delta.g, Color::COLOR_TOLERANCE)
end
def test_subtract
delta = @gs - Color::GrayScale.new(20)
max = @gs - Color::GrayScale.new(80)
assert_in_delta(0.0, max.g, Color::COLOR_TOLERANCE)
assert_in_delta(0.13, delta.g, Color::COLOR_TOLERANCE)
end
def test_inspect
assert_equal("Gray [33.00%]", @gs.inspect)
end
end
end
color-1.4.2/test/test_cmyk.rb 0000644 0000041 0000041 00000007214 12222570513 016175 0 ustar www-data www-data gem 'minitest'
require 'minitest/autorun'
require 'color'
module TestColor
class TestCMYK < Minitest::Test
def setup
@cmyk = Color::CMYK.new(10, 20, 30, 40)
end
def test_cyan
assert_in_delta(0.1, @cmyk.c, Color::COLOR_TOLERANCE)
assert_in_delta(10, @cmyk.cyan, Color::COLOR_TOLERANCE)
@cmyk.cyan = 20
assert_in_delta(0.2, @cmyk.c, Color::COLOR_TOLERANCE)
@cmyk.c = 2.0
assert_in_delta(100, @cmyk.cyan, Color::COLOR_TOLERANCE)
@cmyk.c = -1.0
assert_in_delta(0.0, @cmyk.c, Color::COLOR_TOLERANCE)
end
def test_magenta
assert_in_delta(0.2, @cmyk.m, Color::COLOR_TOLERANCE)
assert_in_delta(20, @cmyk.magenta, Color::COLOR_TOLERANCE)
@cmyk.magenta = 30
assert_in_delta(0.3, @cmyk.m, Color::COLOR_TOLERANCE)
@cmyk.m = 2.0
assert_in_delta(100, @cmyk.magenta, Color::COLOR_TOLERANCE)
@cmyk.m = -1.0
assert_in_delta(0.0, @cmyk.m, Color::COLOR_TOLERANCE)
end
def test_yellow
assert_in_delta(0.3, @cmyk.y, Color::COLOR_TOLERANCE)
assert_in_delta(30, @cmyk.yellow, Color::COLOR_TOLERANCE)
@cmyk.yellow = 20
assert_in_delta(0.2, @cmyk.y, Color::COLOR_TOLERANCE)
@cmyk.y = 2.0
assert_in_delta(100, @cmyk.yellow, Color::COLOR_TOLERANCE)
@cmyk.y = -1.0
assert_in_delta(0.0, @cmyk.y, Color::COLOR_TOLERANCE)
end
def test_black
assert_in_delta(0.4, @cmyk.k, Color::COLOR_TOLERANCE)
assert_in_delta(40, @cmyk.black, Color::COLOR_TOLERANCE)
@cmyk.black = 20
assert_in_delta(0.2, @cmyk.k, Color::COLOR_TOLERANCE)
@cmyk.k = 2.0
assert_in_delta(100, @cmyk.black, Color::COLOR_TOLERANCE)
@cmyk.k = -1.0
assert_in_delta(0.0, @cmyk.k, Color::COLOR_TOLERANCE)
end
def test_pdf
assert_equal("0.100 0.200 0.300 0.400 k", @cmyk.pdf_fill)
assert_equal("0.100 0.200 0.300 0.400 K", @cmyk.pdf_stroke)
end
def test_to_cmyk
assert(@cmyk.to_cmyk == @cmyk)
end
def test_to_grayscale
gs = @cmyk.to_grayscale
assert_kind_of(Color::GrayScale, gs)
assert_in_delta(0.4185, gs.g, Color::COLOR_TOLERANCE)
assert_kind_of(Color::GreyScale, @cmyk.to_greyscale)
end
def test_to_hsl
hsl = @cmyk.to_hsl
assert_kind_of(Color::HSL, hsl)
assert_in_delta(0.48, hsl.l, Color::COLOR_TOLERANCE)
assert_in_delta(0.125, hsl.s, Color::COLOR_TOLERANCE)
assert_in_delta(0.08333, hsl.h, Color::COLOR_TOLERANCE)
assert_equal("hsl(30.00, 12.50%, 48.00%)", @cmyk.css_hsl)
assert_equal("hsla(30.00, 12.50%, 48.00%, 1.00)", @cmyk.css_hsla)
end
def test_to_rgb
rgb = @cmyk.to_rgb(true)
assert_kind_of(Color::RGB, rgb)
assert_in_delta(0.5, rgb.r, Color::COLOR_TOLERANCE)
assert_in_delta(0.4, rgb.g, Color::COLOR_TOLERANCE)
assert_in_delta(0.3, rgb.b, Color::COLOR_TOLERANCE)
rgb = @cmyk.to_rgb
assert_kind_of(Color::RGB, rgb)
assert_in_delta(0.54, rgb.r, Color::COLOR_TOLERANCE)
assert_in_delta(0.48, rgb.g, Color::COLOR_TOLERANCE)
assert_in_delta(0.42, rgb.b, Color::COLOR_TOLERANCE)
assert_equal("#8a7a6b", @cmyk.html)
assert_equal("rgb(54.00%, 48.00%, 42.00%)", @cmyk.css_rgb)
assert_equal("rgba(54.00%, 48.00%, 42.00%, 1.00)", @cmyk.css_rgba)
end
def test_inspect
assert_equal("CMYK [10.00%, 20.00%, 30.00%, 40.00%]", @cmyk.inspect)
end
def test_to_yiq
yiq = @cmyk.to_yiq
assert_kind_of(Color::YIQ, yiq)
assert_in_delta(0.4911, yiq.y, Color::COLOR_TOLERANCE)
assert_in_delta(0.05502, yiq.i, Color::COLOR_TOLERANCE)
assert_in_delta(0.0, yiq.q, Color::COLOR_TOLERANCE)
end
end
end
color-1.4.2/test/test_monocontrast.rb 0000644 0000041 0000041 00000013327 12222570513 017762 0 ustar www-data www-data gem 'minitest'
require 'minitest/autorun'
require 'color'
require 'color/palette/monocontrast'
module TestColor
module TestPalette
class TestMonoContrast < Minitest::Test
include Color::Palette
def setup
@high = Color::RGB.from_html("#c9e3a6")
@low = Color::RGB.from_html("#746b8e")
@mcp1 = MonoContrast.new(@high)
@mcp2 = MonoContrast.new(@low)
end
def test_background
assert_equal("#141711", @mcp1.background[-5].html)
assert_equal("#32392a", @mcp1.background[-4].html)
assert_equal("#657253", @mcp1.background[-3].html)
assert_equal("#97aa7d", @mcp1.background[-2].html)
assert_equal("#abc18d", @mcp1.background[-1].html)
assert_equal("#c9e3a6", @mcp1.background[ 0].html)
assert_equal("#d1e7b3", @mcp1.background[+1].html)
assert_equal("#d7eabc", @mcp1.background[+2].html) # d7eabd
assert_equal("#e4f1d3", @mcp1.background[+3].html) # e5f2d3
assert_equal("#f2f8e9", @mcp1.background[+4].html) # f1f8e9
assert_equal("#fafcf6", @mcp1.background[+5].html) # fafdf7
assert_equal("#0c0b0e", @mcp2.background[-5].html)
assert_equal("#1d1b24", @mcp2.background[-4].html)
assert_equal("#3a3647", @mcp2.background[-3].html)
assert_equal("#57506b", @mcp2.background[-2].html)
assert_equal("#635b79", @mcp2.background[-1].html)
assert_equal("#746b8e", @mcp2.background[ 0].html)
assert_equal("#89819f", @mcp2.background[+1].html)
assert_equal("#9790aa", @mcp2.background[+2].html) # 9790ab
assert_equal("#bab5c7", @mcp2.background[+3].html) # bab6c7
assert_equal("#dcdae3", @mcp2.background[+4].html)
assert_equal("#f1f0f4", @mcp2.background[+5].html) # f2f1f4
end
def test_brightness_diff
bd1 = @mcp1.brightness_diff(@high, @low)
bd2 = @mcp1.brightness_diff(@low, @high)
assert_in_delta(bd1, bd2, Color::COLOR_TOLERANCE)
end
def test_calculate_foreground
assert_equal("#ffffff", @mcp1.calculate_foreground(@low, @high).html)
assert_equal("#1d1b24", @mcp1.calculate_foreground(@high, @low).html)
end
def test_color_diff
assert_in_delta(@mcp1.color_diff(@low, @high),
@mcp1.color_diff(@high, @low),
Color::COLOR_TOLERANCE)
end
def test_foreground
assert_equal("#c9e3a6", @mcp1.foreground[-5].html)
assert_equal("#e4f1d3", @mcp1.foreground[-4].html) # e5f2d3
assert_equal("#ffffff", @mcp1.foreground[-3].html)
assert_equal("#000000", @mcp1.foreground[-2].html)
assert_equal("#000000", @mcp1.foreground[-1].html)
assert_equal("#000000", @mcp1.foreground[ 0].html)
assert_equal("#000000", @mcp1.foreground[+1].html)
assert_equal("#000000", @mcp1.foreground[+2].html)
assert_equal("#32392a", @mcp1.foreground[+3].html)
assert_equal("#32392a", @mcp1.foreground[+4].html)
assert_equal("#32392a", @mcp1.foreground[+5].html)
assert_equal("#bab5c7", @mcp2.foreground[-5].html) # bab6c7
assert_equal("#dcdae3", @mcp2.foreground[-4].html)
assert_equal("#ffffff", @mcp2.foreground[-3].html)
assert_equal("#ffffff", @mcp2.foreground[-2].html)
assert_equal("#ffffff", @mcp2.foreground[-1].html)
assert_equal("#ffffff", @mcp2.foreground[ 0].html)
assert_equal("#000000", @mcp2.foreground[+1].html)
assert_equal("#000000", @mcp2.foreground[+2].html)
assert_equal("#000000", @mcp2.foreground[+3].html)
assert_equal("#1d1b24", @mcp2.foreground[+4].html)
assert_equal("#3a3647", @mcp2.foreground[+5].html)
end
def test_minimum_brightness_diff
assert_in_delta(MonoContrast::DEFAULT_MINIMUM_BRIGHTNESS_DIFF,
@mcp1.minimum_brightness_diff, Color::COLOR_TOLERANCE)
end
def test_minimum_brightness_diff_equals
assert_in_delta(MonoContrast::DEFAULT_MINIMUM_BRIGHTNESS_DIFF,
@mcp1.minimum_brightness_diff, Color::COLOR_TOLERANCE)
mcps = @mcp1.dup
@mcp1.minimum_brightness_diff = 0.75
assert_in_delta(0.75, @mcp1.minimum_brightness_diff, Color::COLOR_TOLERANCE)
refute_equal(@mcp1.foreground[-5], mcps.foreground[-5])
@mcp1.minimum_brightness_diff = 4.0
assert_in_delta(1, @mcp1.minimum_brightness_diff, Color::COLOR_TOLERANCE)
@mcp1.minimum_brightness_diff = -4.0
assert_in_delta(0, @mcp1.minimum_brightness_diff, Color::COLOR_TOLERANCE)
@mcp1.minimum_brightness_diff = nil
assert_in_delta(MonoContrast::DEFAULT_MINIMUM_BRIGHTNESS_DIFF,
@mcp1.minimum_brightness_diff, Color::COLOR_TOLERANCE)
end
def test_minimum_color_diff
assert_in_delta(MonoContrast::DEFAULT_MINIMUM_COLOR_DIFF,
@mcp1.minimum_color_diff, Color::COLOR_TOLERANCE)
end
def test_minimum_color_diff_equals
assert_in_delta(MonoContrast::DEFAULT_MINIMUM_COLOR_DIFF,
@mcp1.minimum_color_diff, Color::COLOR_TOLERANCE)
mcps = @mcp1.dup
@mcp1.minimum_color_diff = 0.75
assert_in_delta(0.75, @mcp1.minimum_color_diff, Color::COLOR_TOLERANCE)
refute_equal(@mcp1.foreground[-5], mcps.foreground[-5])
@mcp1.minimum_color_diff = 4.0
assert_in_delta(3, @mcp1.minimum_color_diff, Color::COLOR_TOLERANCE)
@mcp1.minimum_color_diff = -4.0
assert_in_delta(0, @mcp1.minimum_color_diff, Color::COLOR_TOLERANCE)
@mcp1.minimum_color_diff = nil
assert_in_delta(MonoContrast::DEFAULT_MINIMUM_COLOR_DIFF,
@mcp1.minimum_color_diff, Color::COLOR_TOLERANCE)
end
end
end
end
color-1.4.2/test/test_adobecolor.rb 0000644 0000041 0000041 00000051170 12222570513 017343 0 ustar www-data www-data gem 'minitest'
require 'minitest/autorun'
require 'color'
require 'color/palette/adobecolor'
module TestColor
module TestPalette
class TestAdobeColor < Minitest::Test
include Color::Palette
# This is based on the Visibone Anglo-Centric Color Code List; this is
# an Adobe Color swatch version 1 (RGB colours only).
VISIBONE_V1 = <<-EOS
AAEA2AAA/wD/AP8AAAAAAMwAzADMAAAAAACZAJkAmQAAAAAAZgBmAGYAAAAA
ADMAMwAzAAAAAAAAAAAAAAAAAAAA/wAAAAAAAAAAAP8AMwAzAAAAAADMAAAA
AAAAAAAA/wBmAGYAAAAAAMwAMwAzAAAAAACZAAAAAAAAAAAA/wCZAJkAAAAA
AMwAZgBmAAAAAACZADMAMwAAAAAAZgAAAAAAAAAAAP8AzADMAAAAAADMAJkA
mQAAAAAAmQBmAGYAAAAAAGYAMwAzAAAAAAAzAAAAAAAAAAAA/wAzAAAAAAAA
AP8AZgAzAAAAAADMADMAAAAAAAAA/wCZAGYAAAAAAMwAZgAzA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AAAD/AAAAAAD/ADMA/wAAAAAAzAAAAMwAAAAA
AP8AZgD/AAAAAADMADMAzAAAAAAAmQAAAJkAAAAAAP8AmQD/AAAAAADMAGYA
zAAAAAAAmQAzAJkAAAAAAGYAAABmAAAAAAD/AMwA/wAAAAAAzACZAMwAAAAA
AJkAZgCZAAAAAABmADMAZgAAAAAAMwAAADMAAAAAAP8AAADMAAAAAAD/ADMA
zAAAAAAAzAAAAJkAAAAAAP8AZgDMAAAAAADMADMAmQAAAAAAmQAAAGYAAAAA
AP8AAACZAAAAAAD/ADMAmQAAAAAAzAAAAGYAAAAAAP8AmQDMAAAAAADMAGYA
mQAAAAAAmQAzAGYAAAAAAGYAAAAzAAAAAAD/AAAAZgAAAAAA/wBmAJkAAAAA
AMwAMwBmAAAAAACZAAAAMwAAAAAA/wAzAGYAAAAAAMwAAAAzAAAAAAD/AAAA
MwAAAA==
EOS
# This is based on the Visibone Anglo-Centric Color Code List; this is
# an Adobe Color swatch version 2 (with names).
VISIBONE_V2 = <<-EOS
AAIA2AAA/wD/AP8AAAAAAAAGAFcAaABpAHQAZQAAAADMAMwAzAAAAAAAAAoA
UABhAGwAZQAgAEcAcgBhAHkAAAAAmQCZAJkAAAAAAAALAEwAaQBnAGgAdAAg
AEcAcgBhAHkAAAAAZgBmAGYAAAAAAAAKAEQAYQByAGsAIABHAHIAYQB5AAAA
ADMAMwAzAAAAAAAADQBPAGIAcwBjAHUAcgBlACAARwByAGEAeQAAAAAAAAAA
AAAAAAAAAAYAQgBsAGEAYwBrAAAAAP8AAAAAAAAAAAAABABSAGUAZAAAAAD/
ADMAMwAAAAAAAA8ATABpAGcAaAB0ACAASABhAHIAZAAgAFIAZQBkAAAAAMwA
AAAAAAAAAAAADgBEAGEAcgBrACAASABhAHIAZAAgAFIAZQBkAAAAAP8AZgBm
AAAAAAAAEABMAGkAZwBoAHQAIABGAGEAZABlAGQAIABSAGUAZAAAAADMADMA
MwAAAAAAABEATQBlAGQAaQB1AG0AIABGAGEA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ATwBiAHMAYwB1AHIAZQAgAEQAdQBsAGwAIABQ
AGkAbgBrAAAAAP8AAABmAAAAAAAADgBQAGkAbgBrAC0AUABpAG4AawAtAFIA
ZQBkAAAAAP8AZgCZAAAAAAAADwBMAGkAZwBoAHQAIABQAGkAbgBrAC0AUgBl
AGQAAAAAzAAzAGYAAAAAAAAQAE0AZQBkAGkAdQBtACAAUABpAG4AawAtAFIA
ZQBkAAAAAJkAAAAzAAAAAAAADgBEAGEAcgBrACAAUABpAG4AawAtAFIAZQBk
AAAAAP8AMwBmAAAAAAAADwBMAGkAZwBoAHQAIABSAGUAZAAtAFAAaQBuAGsA
AAAAzAAAADMAAAAAAAAOAEQAYQByAGsAIABSAGUAZAAtAFAAaQBuAGsAAAAA
/wAAADMAAAAAAAANAFIAZQBkAC0AUgBlAGQALQBQAGkAbgBrAAA=
EOS
EXERCISE = <<-EOS
AAIABwAAHgA8AFoAAAAAAAAEAFIARwBCAAAAAQKPGZn//wAAAAAABABIAFMA
QgAAAAIMzH//GZn//wAAAAUAQwBNAFkASwAAAAcbWOiQG1gAAAAAAAQATABB
AEIAAAAIFXwAAAAAAAAAAAAFAEcAcgBhAHkAAAAJCcQNrBGUBdwAAAAGAFcA
QwBNAFkASwAAAA0JxA2sEZQF3AAAAAsAVQBOAEsATgBPAFcATgAgADEAMwAA
EOS
# http://www.visibone.com/swatches/VisiBone.aco
# http://www.visibone.com/swatches/VisiBone2.aco
# http://www.visibone.com/swatches/VisiBone2_km.psppalette
# http://www.visibone.com/swatches/VisiBone2_km.pal
# http://www.visibone.com/swatches/VisiBone2_vaccc.ai
# http://www.visibone.com/swatches/VisiBone.gimp
# http://www.visibone.com/swatches/VisiBone.act
def setup
@filename = "test#{Process.pid}.aco"
end
def teardown
require 'fileutils'
FileUtils.rm_f @filename if File.exist? @filename
end
def test_version1
v1 = VISIBONE_V1.unpack("m*")[0]
@aco = AdobeColor.new(v1)
assert_equal(216, @aco.size)
assert_equal(1, @aco.version)
assert_equal({:rgb => 216}, @aco.statistics)
assert_equal(Color::RGB::White, @aco[0])
assert_equal("#ff0033", @aco[-1].html)
assert_equal(v1, @aco.to_aco)
end
def test_version2
v2 = VISIBONE_V2.unpack("m*")[0]
@aco = AdobeColor.new(v2)
assert_equal(216, @aco.size)
assert_equal(2, @aco.version)
assert_equal({:rgb => 216}, @aco.statistics)
assert_equal(Color::RGB::White, @aco[0])
assert_equal(Color::RGB::White,
@aco["\000W\000h\000i\000t\000e"][0])
assert_equal("#ff0033", @aco[-1].html)
assert_equal("#ff0033",
@aco["\000R\000e\000d\000-\000R\000e\000d\000-\000P\000i\000n\000k"][0].html)
assert_equal(v2, @aco.to_aco)
end
def test_bogus
o = VISIBONE_V2.unpack("m*")[0]
v = o.dup
v[0, 2] = [ 322 ].pack("n") # break the version
assert_raises(RuntimeError) { AdobeColor.new(v) }
v = o.dup
v[2, 2] = [ 217 ].pack("n") # break the colour count
assert_raises(IndexError) { @aco = AdobeColor.new(v) }
v = o.dup
v[14, 2] = [ 99 ].pack("n") # break the NULL before the name
assert_raises(IndexError) { @aco = AdobeColor.new(v) }
v = o.dup
v[16, 2] = [ 18 ].pack("n") # break the length of the name
assert_raises(IndexError) { @aco = AdobeColor.new(v) }
v = o.dup
v[28, 2] = [ 99 ].pack("n") # break the trailing null of the name
end
def test_exercise
File.open(@filename, "wb") do |f|
f.write EXERCISE.unpack("m*")[0]
end
@aco = AdobeColor.from_file(@filename)
assert_equal(5, @aco.size)
assert_equal(7, @aco.instance_variable_get(:@order).size)
end
def test_each
v1 = VISIBONE_V1.unpack("m*")[0]
@aco = AdobeColor.new(v1)
@aco.each { |c| assert_kind_of(Color::RGB, c) }
end
def test_each_name
v2 = VISIBONE_V2.unpack("m*")[0]
@aco = AdobeColor.new(v2)
assert_equal(216, @aco.size)
assert_equal(2, @aco.version)
@aco.each_name do |n, s|
assert_equal(0, n[0]) if RUBY_VERSION < "1.9"
assert_equal(1, s.size)
assert_kind_of(Color::RGB, s[0])
end
end
def test_values_at
v2 = VISIBONE_V2.unpack("m*")[0]
@aco = AdobeColor.new(v2)
assert_equal(216, @aco.size)
assert_equal(2, @aco.version)
assert_equal([Color::RGB::White, Color::RGB.from_html("#ff0033")],
@aco.values_at(0, -1))
end
end
end
end
color-1.4.2/test/test_css.rb 0000644 0000041 0000041 00000000764 12222570513 016025 0 ustar www-data www-data gem 'minitest'
require 'minitest/autorun'
require 'color'
require 'color/css'
module TestColor
class TestCSS < Minitest::Test
def test_index
assert_equal(Color::RGB::AliceBlue, Color::CSS[:aliceblue])
assert_equal(Color::RGB::AliceBlue, Color::CSS["AliceBlue"])
assert_equal(Color::RGB::AliceBlue, Color::CSS["aliceBlue"])
assert_equal(Color::RGB::AliceBlue, Color::CSS["aliceblue"])
assert_equal(Color::RGB::AliceBlue, Color::CSS[:AliceBlue])
end
end
end
color-1.4.2/test/test_gimp.rb 0000644 0000041 0000041 00000003575 12222570513 016174 0 ustar www-data www-data gem 'minitest'
require 'minitest/autorun'
require 'color'
require 'color/palette/gimp'
module TestColor
module TestPalette
class TestGimp < Minitest::Test
include Color::Palette
GIMP_W3C = <<-EOS
GIMP Palette
Name: W3C Named Colors
Columns: 2
#
# ColorZilla W3C Named Colors
#
255 255 255 White
255 255 0 Yclow
255 0 255 Fuchsia
255 0 0 Red
192 192 192 Silver
128 128 128 Gray
128 128 0 Olive
128 0 128 Purple
128 0 0 Maroon
0 255 255 Aqua
0 255 0 Lime
0 128 128 Teal
0 128 0 Green
0 0 255 Blue
0 0 128 Navy
0 0 0 Black
EOS
def setup
@filename = "test#{Process.pid}.gimp"
end
def teardown
require 'fileutils'
FileUtils.rm_f @filename if File.exist? @filename
end
def test_each
@gimp = Gimp.new(GIMP_W3C)
assert_equal(16, @gimp.instance_variable_get(:@colors).size)
@gimp.each { |c| assert_kind_of(Color::RGB, c) }
end
def test_each_name
@gimp = Gimp.new(GIMP_W3C)
assert_equal(16, @gimp.instance_variable_get(:@names).size)
@gimp.each_name { |color_name, color_set|
assert_kind_of(Array, color_set)
color_set.each { |c|
assert_kind_of(Color::RGB, c)
}
}
end
def test_index
File.open(@filename, "wb") do |f|
f.write GIMP_W3C
end
@gimp = Gimp.from_file(@filename)
assert_equal(Color::RGB::White, @gimp[0])
assert_equal(Color::RGB::White, @gimp["White"][0])
assert_equal([Color::RGB::White, Color::RGB::Black],
@gimp.values_at(0, -1))
assert_equal(16, @gimp.size)
end
def test_valid_eh
@gimp = Gimp.new(GIMP_W3C)
assert(@gimp.valid?)
end
def test_name
@gimp = Gimp.new(GIMP_W3C)
assert_equal("W3C Named Colors", @gimp.name)
end
end
end
end
color-1.4.2/test/test_color.rb 0000644 0000041 0000041 00000011305 12222570513 016344 0 ustar www-data www-data gem 'minitest'
require 'minitest/autorun'
require 'color'
require 'color/css'
module TestColor
class TestColor < Minitest::Test
def setup
Kernel.module_eval do
alias old_warn warn
def warn(message)
$last_warn = message
end
end
end
def teardown
Kernel.module_eval do
undef warn
alias warn old_warn
undef old_warn
end
end
def test_const
$last_warn = nil
assert_equal(Color::RGB::AliceBlue, Color::AliceBlue)
assert_equal("Color::AliceBlue has been deprecated. Use Color::RGB::AliceBlue instead.", $last_warn)
$last_warn = nil # Do this twice to make sure it always happens...
assert(Color::AliceBlue)
assert_equal("Color::AliceBlue has been deprecated. Use Color::RGB::AliceBlue instead.", $last_warn)
$last_warn = nil
assert_equal(Color::COLOR_VERSION, Color::VERSION)
assert_equal("Color::VERSION has been deprecated. Use Color::COLOR_VERSION instead.", $last_warn)
$last_warn = nil
assert_equal(Color::COLOR_VERSION, Color::COLOR_TOOLS_VERSION)
assert_equal("Color::COLOR_TOOLS_VERSION has been deprecated. Use Color::COLOR_VERSION instead.", $last_warn)
$last_warn = nil
assert(Color::COLOR_VERSION)
assert_nil($last_warn)
assert(Color::COLOR_EPSILON)
assert_nil($last_warn)
assert_raises(NameError) { assert(Color::MISSING_VALUE) }
end
def test_normalize
(1..10).each do |i|
assert_equal(0.0, Color.normalize(-7 * i))
assert_equal(0.0, Color.normalize(-7 / i))
assert_equal(0.0, Color.normalize(0 - i))
assert_equal(1.0, Color.normalize(255 + i))
assert_equal(1.0, Color.normalize(256 * i))
assert_equal(1.0, Color.normalize(65536 / i))
end
(0..255).each do |i|
assert_in_delta(i / 255.0, Color.normalize(i / 255.0),
1e-2)
end
end
def test_normalize_range
assert_equal(0, Color.normalize_8bit(-1))
assert_equal(0, Color.normalize_8bit(0))
assert_equal(127, Color.normalize_8bit(127))
assert_equal(172, Color.normalize_8bit(172))
assert_equal(255, Color.normalize_8bit(255))
assert_equal(255, Color.normalize_8bit(256))
assert_equal(0, Color.normalize_16bit(-1))
assert_equal(0, Color.normalize_16bit(0))
assert_equal(127, Color.normalize_16bit(127))
assert_equal(172, Color.normalize_16bit(172))
assert_equal(255, Color.normalize_16bit(255))
assert_equal(256, Color.normalize_16bit(256))
assert_equal(65535, Color.normalize_16bit(65535))
assert_equal(65535, Color.normalize_16bit(66536))
assert_equal(-100, Color.normalize_to_range(-101, -100..100))
assert_equal(-100, Color.normalize_to_range(-100.5, -100..100))
assert_equal(-100, Color.normalize_to_range(-100, -100..100))
assert_equal(-100, Color.normalize_to_range(-100.0, -100..100))
assert_equal(-99.5, Color.normalize_to_range(-99.5, -100..100))
assert_equal(-50, Color.normalize_to_range(-50, -100..100))
assert_equal(-50.5, Color.normalize_to_range(-50.5, -100..100))
assert_equal(0, Color.normalize_to_range(0, -100..100))
assert_equal(50, Color.normalize_to_range(50, -100..100))
assert_equal(50.5, Color.normalize_to_range(50.5, -100..100))
assert_equal(99, Color.normalize_to_range(99, -100..100))
assert_equal(99.5, Color.normalize_to_range(99.5, -100..100))
assert_equal(100, Color.normalize_to_range(100, -100..100))
assert_equal(100, Color.normalize_to_range(100.0, -100..100))
assert_equal(100, Color.normalize_to_range(100.5, -100..100))
assert_equal(100, Color.normalize_to_range(101, -100..100))
end
def test_new
$last_warn = nil
c = Color.new("#fff")
assert_kind_of(Color::HSL, c)
assert_equal(Color::RGB::White.to_hsl, c)
assert_equal("Color.new has been deprecated. Use Color::RGB.new instead.", $last_warn)
$last_warn = nil
c = Color.new([0, 0, 0])
assert_kind_of(Color::HSL, c)
assert_equal(Color::RGB::Black.to_hsl, c)
assert_equal("Color.new has been deprecated. Use Color::RGB.new instead.", $last_warn)
$last_warn = nil
c = Color.new([10, 20, 30], :hsl)
assert_kind_of(Color::HSL, c)
assert_equal(Color::HSL.new(10, 20, 30), c)
assert_equal("Color.new has been deprecated. Use Color::HSL.new instead.", $last_warn)
$last_warn = nil
c = Color.new([10, 20, 30, 40], :cmyk)
assert_kind_of(Color::HSL, c)
assert_equal(Color::CMYK.new(10, 20, 30, 40).to_hsl, c)
assert_equal("Color.new has been deprecated. Use Color::CMYK.new instead.", $last_warn)
end
end
end
color-1.4.2/README.rdoc 0000644 0000041 0000041 00000004125 12222570513 014473 0 ustar www-data www-data = Color
home :: http://color.rubyforge.org
code :: https://github.com/halostatue/color
bugs :: https://github.com/halostatue/color/issues
rdoc :: http://rubydoc.info/github/halostatue/color
code climate :: {
}[https://codeclimate.com/github/halostatue/color]
continuous integration :: {
}[https://travis-ci.org/halostatue/color]
== Description
Color is a Ruby library to provide basic RGB, CMYK, HSL, and other colourspace
manipulation support to applications that require it. It also provides 152
named RGB colours (184 with spelling variations) that are commonly supported in
HTML, SVG, and X11 applications. A technique for generating monochromatic
contrasting palettes is also included.
The capabilities of the Color library are limited to pure mathematical
manipulation of the colours based on colour theory without reference to colour
profiles (such as sRGB or Adobe RGB). For most purposes, when working with the
RGB and HSL colours, this won't matter. However, some colour models (like CIE
L*a*b*) are not supported because Color does not yet support colour profiles,
giving no meaningful way to convert colours in absolute colour spaces (like
L*a*b*, XYZ) to non-absolute colour spaces (like RGB).
Color version 1.4.2 updates the release and install as a RubyGem to remove an
unnecessary dependency, adds code climate analysis, and Travis CI support.
== History
Color is the result of a project merge between color.rb 0.1.0 by
Matt Lyon and color-tools 1.3 by Austin Ziegler. Please see History.txt for
details on the changes this merge brings.
Color::Palette::MonoContrast was developed based on techniques described by
Andy “Malarkey†Clarke[1], implemented in JavaScript by Steve G. Chipman at
SlayerOffice[2] and by Patrick Fitzgerald of BarelyFitz[3] in PHP.
[1] http://www.stuffandnonsense.co.uk/archives/creating_colour_palettes.html
[2] http://slayeroffice.com/tools/color_palette/
[3] http://www.barelyfitz.com/projects/csscolor/
:include: Contributing.rdoc
:include: Licence.rdoc
color-1.4.2/Rakefile 0000644 0000041 0000041 00000001653 12222570513 014335 0 ustar www-data www-data # -*- ruby encoding: utf-8 -*-
require 'rubygems'
require 'hoe'
Hoe.plugin :bundler
Hoe.plugin :doofus
Hoe.plugin :email
Hoe.plugin :gemspec2
Hoe.plugin :git
Hoe.plugin :minitest
Hoe.plugin :rubyforge
Hoe.plugin :travis
Hoe.spec 'color' do
developer "Austin Ziegler", "austin@rubyforge.org"
developer "Matt Lyon", "matt@postsomnia.com"
self.remote_rdoc_dir = '.'
self.rsync_args << ' --exclude=statsvn/'
self.history_file = 'History.rdoc'
self.readme_file = 'README.rdoc'
self.extra_rdoc_files = FileList["*.rdoc"].to_a
self.extra_dev_deps << ['hoe-bundler', '~> 1.2']
self.extra_dev_deps << ['hoe-doofus', '~> 1.0']
self.extra_dev_deps << ['hoe-gemspec2', '~> 1.1']
self.extra_dev_deps << ['hoe-git', '~> 1.5']
self.extra_dev_deps << ['hoe-rubygems', '~> 1.0']
self.extra_dev_deps << ['hoe-travis', '~> 1.2']
self.extra_dev_deps << ['minitest', '~> 5.0']
self.extra_dev_deps << ['rake', '~> 10.0']
end
color-1.4.2/Contributing.rdoc 0000644 0000041 0000041 00000003733 12222570513 016211 0 ustar www-data www-data == Contributing
I value any contribution to Color you can provide: a bug report, a feature
request, or code contributions.
Code contributions to Color are especially welcomeencouraged.
Because Color is a complex codebase, there are a few guidelines:
* Changes will not be accepted without tests.
* Match my coding style.
* Use a thoughtfully-named topic branch that contains your change. Rebase your
commits into logical chunks as necessary.
* Use {quality commit messages}[http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html].
* Do not change the version number; when your patch is accepted and a release
is made, the version will be updated at that point.
* Submit a GitHub pull request with your changes.
* New features require new documentation.
=== Test Dependencies
To run the test suite, you will need to install the development dependencies
for Color. If you have Bundler, you can accomplish this easily:
$ bundle install
Color uses Ryan Davis’s excellent {Hoe}[https://github.com/seattlerb/hoe]
to manage the release process, and it adds a number of rake tasks. You will
mostly be interested in:
$ rake
which runs the tests the same way that:
$ rake spec
$ rake test
$ rake travis
will do.
=== Workflow
Here's the most direct way to get your work merged into the project:
* Fork the project.
* Clone down your fork (+git clone git://github.com//color.git+).
* Create a topic branch to contain your change (+git checkout -b my\_awesome\_feature+).
* Hack away, add tests. Not necessarily in that order.
* Make sure everything still passes by running `rake`.
* If necessary, rebase your commits into logical chunks, without errors.
* Push the branch up (+git push origin my\_awesome\_feature+).
* Create a pull request against halostatue/color and describe what your
change does and the why you think it should be merged.
=== Contributors
* Austin Ziegler created color-tools.
* Matt Lyons created color.
color-1.4.2/.hoerc 0000644 0000041 0000041 00000000161 12222570513 013762 0 ustar www-data www-data ---
exclude: !ruby/regexp /(tmp|swp)$|CVS|TAGS|\.(svn|git|hg|DS_Store|idea)|Gemfile\.lock|research\/|\.gemspec$/
color-1.4.2/.gemtest 0000644 0000041 0000041 00000000000 12222570513 014322 0 ustar www-data www-data color-1.4.2/Licence.rdoc 0000644 0000041 0000041 00000002450 12222570513 015077 0 ustar www-data www-data == Licence
This software is available under an MIT-style licence.
* Copyright 2005–2013 Austin Ziegler, Matt Lyon, and other contributors
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
* The names of its contributors may not be used to endorse or promote
products derived from this software without specific prior written
permission.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
color-1.4.2/metadata.yml 0000644 0000041 0000041 00000020666 12222570513 015200 0 ustar www-data www-data --- !ruby/object:Gem::Specification
name: color
version: !ruby/object:Gem::Version
version: 1.4.2
prerelease:
platform: ruby
authors:
- Austin Ziegler
- Matt Lyon
autorequire:
bindir: bin
cert_chain:
- ! '-----BEGIN CERTIFICATE-----
MIIDNjCCAh6gAwIBAgIBADANBgkqhkiG9w0BAQUFADBBMQ8wDQYDVQQDDAZhdXN0
aW4xGTAXBgoJkiaJk/IsZAEZFglydWJ5Zm9yZ2UxEzARBgoJkiaJk/IsZAEZFgNv
cmcwHhcNMTMwMjA0MDMzMzI3WhcNMTQwMjA0MDMzMzI3WjBBMQ8wDQYDVQQDDAZh
dXN0aW4xGTAXBgoJkiaJk/IsZAEZFglydWJ5Zm9yZ2UxEzARBgoJkiaJk/IsZAEZ
FgNvcmcwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC2mPNf4L37GhKI
SPCYsvYWXA2/R9u5+pyUnbJ2R1o2CiRq2ZA/AIzY6N3hGnsgoWnh5RzvgTN1Lt08
DNIrsIG2VDYk/JVt6f9J6zZ8EQHbznWa3cWYoCFaaICdk7jV1n/42hg70jEDYXl9
gDOl0k6JmyF/rtfFu/OIkFGWeFYIuFHvRuLyUbw66+QDTOzKb3t8o55Ihgy1GVwT
i6pkDs8LhZWXdOD+921l2Z1NZGZa9KNbJIg6vtgYKU98jQ5qr9iY3ikBAspHrFas
K6USvGgAg8fCD5YiotBEvCBMYtfqmfrhpdU2p+gvTgeLW1Kaevwqd7ngQmFUrFG1
eUJSURv5AgMBAAGjOTA3MAkGA1UdEwQCMAAwHQYDVR0OBBYEFAtJKMp6YYNqlgR3
9TiZLWqvLagSMAsGA1UdDwQEAwIEsDANBgkqhkiG9w0BAQUFAAOCAQEApTPkvDm8
7gJlUT4FfumXPvtuqP67LxUtGE8syvR0A4As+0P/wylLJFUOsGTTdZYtThhxCSJG
+7KG2FfIcH4Zz2d97arZGAzBoi8iPht2/UtSl1fCcUI5vmJa1MiXZT2oqdW7Wydq
rAZcBPlrYYuiwtGI0yqIOgBfXSZCWWsJsuyTKELep6mCLgz0YZUfmvKr8W/Ab3ax
DuLzH92LSRjZJyjyAUpw/Vc2rM4giiP5jtByrb1Y1dGnQhHTMHf1GfucWm7Nw/V9
twEPVw8+0f88JQucxOTmTF1NbLFpiRwQUZ1zoZbNg2e7mShc/eexnVLWKFKxRoP6
KPj3WoD+spB8fA==
-----END CERTIFICATE-----
'
date: 2013-07-01 00:00:00.000000000 Z
dependencies:
- !ruby/object:Gem::Dependency
name: minitest
requirement: !ruby/object:Gem::Requirement
none: false
requirements:
- - ~>
- !ruby/object:Gem::Version
version: '5.0'
type: :development
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
none: false
requirements:
- - ~>
- !ruby/object:Gem::Version
version: '5.0'
- !ruby/object:Gem::Dependency
name: rubyforge
requirement: !ruby/object:Gem::Requirement
none: false
requirements:
- - ! '>='
- !ruby/object:Gem::Version
version: 2.0.4
type: :development
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
none: false
requirements:
- - ! '>='
- !ruby/object:Gem::Version
version: 2.0.4
- !ruby/object:Gem::Dependency
name: rdoc
requirement: !ruby/object:Gem::Requirement
none: false
requirements:
- - ~>
- !ruby/object:Gem::Version
version: '4.0'
type: :development
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
none: false
requirements:
- - ~>
- !ruby/object:Gem::Version
version: '4.0'
- !ruby/object:Gem::Dependency
name: hoe-bundler
requirement: !ruby/object:Gem::Requirement
none: false
requirements:
- - ~>
- !ruby/object:Gem::Version
version: '1.2'
type: :development
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
none: false
requirements:
- - ~>
- !ruby/object:Gem::Version
version: '1.2'
- !ruby/object:Gem::Dependency
name: hoe-doofus
requirement: !ruby/object:Gem::Requirement
none: false
requirements:
- - ~>
- !ruby/object:Gem::Version
version: '1.0'
type: :development
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
none: false
requirements:
- - ~>
- !ruby/object:Gem::Version
version: '1.0'
- !ruby/object:Gem::Dependency
name: hoe-gemspec2
requirement: !ruby/object:Gem::Requirement
none: false
requirements:
- - ~>
- !ruby/object:Gem::Version
version: '1.1'
type: :development
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
none: false
requirements:
- - ~>
- !ruby/object:Gem::Version
version: '1.1'
- !ruby/object:Gem::Dependency
name: hoe-git
requirement: !ruby/object:Gem::Requirement
none: false
requirements:
- - ~>
- !ruby/object:Gem::Version
version: '1.5'
type: :development
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
none: false
requirements:
- - ~>
- !ruby/object:Gem::Version
version: '1.5'
- !ruby/object:Gem::Dependency
name: hoe-rubygems
requirement: !ruby/object:Gem::Requirement
none: false
requirements:
- - ~>
- !ruby/object:Gem::Version
version: '1.0'
type: :development
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
none: false
requirements:
- - ~>
- !ruby/object:Gem::Version
version: '1.0'
- !ruby/object:Gem::Dependency
name: hoe-travis
requirement: !ruby/object:Gem::Requirement
none: false
requirements:
- - ~>
- !ruby/object:Gem::Version
version: '1.2'
type: :development
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
none: false
requirements:
- - ~>
- !ruby/object:Gem::Version
version: '1.2'
- !ruby/object:Gem::Dependency
name: rake
requirement: !ruby/object:Gem::Requirement
none: false
requirements:
- - ~>
- !ruby/object:Gem::Version
version: '10.0'
type: :development
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
none: false
requirements:
- - ~>
- !ruby/object:Gem::Version
version: '10.0'
- !ruby/object:Gem::Dependency
name: hoe
requirement: !ruby/object:Gem::Requirement
none: false
requirements:
- - ~>
- !ruby/object:Gem::Version
version: '3.6'
type: :development
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
none: false
requirements:
- - ~>
- !ruby/object:Gem::Version
version: '3.6'
description: ! 'Color is a Ruby library to provide basic RGB, CMYK, HSL, and other
colourspace
manipulation support to applications that require it. It also provides 152
named RGB colours (184 with spelling variations) that are commonly supported in
HTML, SVG, and X11 applications. A technique for generating monochromatic
contrasting palettes is also included.
The capabilities of the Color library are limited to pure mathematical
manipulation of the colours based on colour theory without reference to colour
profiles (such as sRGB or Adobe RGB). For most purposes, when working with the
RGB and HSL colours, this won''t matter. However, some colour models (like CIE
L*a*b*) are not supported because Color does not yet support colour profiles,
giving no meaningful way to convert colours in absolute colour spaces (like
L*a*b*, XYZ) to non-absolute colour spaces (like RGB).
Color version 1.4.2 updates the release and install as a RubyGem to remove an
unnecessary dependency, adds code climate analysis, and Travis CI support.'
email:
- austin@rubyforge.org
- matt@postsomnia.com
executables: []
extensions: []
extra_rdoc_files:
- History.rdoc
- Licence.rdoc
- Manifest.txt
- README.rdoc
- Contributing.rdoc
files:
- .hoerc
- History.rdoc
- Licence.rdoc
- Manifest.txt
- README.rdoc
- Rakefile
- lib/color.rb
- lib/color/cmyk.rb
- lib/color/css.rb
- lib/color/grayscale.rb
- lib/color/hsl.rb
- lib/color/palette.rb
- lib/color/palette/adobecolor.rb
- lib/color/palette/gimp.rb
- lib/color/palette/monocontrast.rb
- lib/color/rgb-colors.rb
- lib/color/rgb.rb
- lib/color/rgb/metallic.rb
- lib/color/yiq.rb
- test/test_adobecolor.rb
- test/test_cmyk.rb
- test/test_color.rb
- test/test_css.rb
- test/test_gimp.rb
- test/test_grayscale.rb
- test/test_hsl.rb
- test/test_monocontrast.rb
- test/test_rgb.rb
- test/test_yiq.rb
- Contributing.rdoc
- .gemtest
homepage: http://color.rubyforge.org
licenses: []
post_install_message:
rdoc_options:
- --main
- README.rdoc
require_paths:
- lib
required_ruby_version: !ruby/object:Gem::Requirement
none: false
requirements:
- - ! '>='
- !ruby/object:Gem::Version
version: '0'
required_rubygems_version: !ruby/object:Gem::Requirement
none: false
requirements:
- - ! '>='
- !ruby/object:Gem::Version
version: '0'
requirements: []
rubyforge_project: color
rubygems_version: 1.8.25
signing_key:
specification_version: 3
summary: Color is a Ruby library to provide basic RGB, CMYK, HSL, and other colourspace
manipulation support to applications that require it
test_files:
- test/test_adobecolor.rb
- test/test_cmyk.rb
- test/test_color.rb
- test/test_css.rb
- test/test_gimp.rb
- test/test_grayscale.rb
- test/test_hsl.rb
- test/test_monocontrast.rb
- test/test_rgb.rb
- test/test_yiq.rb
color-1.4.2/metadata.gz.sig 0000644 0000041 0000041 00000000400 12222570513 015560 0 ustar www-data www-data lˆ“þ†oÕ8¦ÄÄÇ.YŒlTdñÆ35ªì$„îú÷ñn„¨%å@°í¾à¶mr‰ˆ´;…!ì*2I´2ö‰j‰
[ç.Ö´À4ÂïpÆPÆ\&¥/R608Ÿcèôþ´+ž®Õ'T$dHEÛL’•‡È`}týÿd¹Z±”ç>k‰)–Ì<ŒÔ–G‚CT+RÉ&g õ àufé×ç:84µVÛ color-1.4.2/Manifest.txt 0000644 0000041 0000041 00000001044 12222570513 015171 0 ustar www-data www-data .hoerc
History.rdoc
Licence.rdoc
Manifest.txt
README.rdoc
Rakefile
lib/color.rb
lib/color/cmyk.rb
lib/color/css.rb
lib/color/grayscale.rb
lib/color/hsl.rb
lib/color/palette.rb
lib/color/palette/adobecolor.rb
lib/color/palette/gimp.rb
lib/color/palette/monocontrast.rb
lib/color/rgb-colors.rb
lib/color/rgb.rb
lib/color/rgb/metallic.rb
lib/color/yiq.rb
test/test_adobecolor.rb
test/test_cmyk.rb
test/test_color.rb
test/test_css.rb
test/test_gimp.rb
test/test_grayscale.rb
test/test_hsl.rb
test/test_monocontrast.rb
test/test_rgb.rb
test/test_yiq.rb
color-1.4.2/data.tar.gz.sig 0000644 0000041 0000041 00000000400 12222570513 015476 0 ustar www-data www-data xn)Zn•ÿ§‘Q”P²ÜñVUõGO¤(Ü%È©0(¼i[ò—pÊ̽pÅ[ÎqøÁ:
‚Û€¹)¢§ˆá€ï¨¼{èYÚ“ùšŠ}þ:†×d£ëE™Œÿ¢Ùú'I˜¡ŽÆ2Œ§6È;Œ„d$ÙH¥ç8Ùš«7/£ë¨‡m˜£µ=í$&`DÁ7È8̼¼<ݳ¤Æ}U'!~dZƒ‹ü’ËíÙŸì§wrŸÿŽÑ©c2嬼ž]g„LãýGÐé¨
•²ÔG²I@øiLDcPÉßPÿ”©ä¤Ó£B<Y÷®é(¬„Ô,ì;ôr_º3™Ô.‘³ color-1.4.2/History.rdoc 0000644 0000041 0000041 00000010635 12222570513 015202 0 ustar www-data www-data == 1.4.2 / 2013-06-30
Maintenance:
* Modernized Hoe installation of Color, removing some dependencies.
* Switched to Minitest.
* Turned on Travis CI.
* Started using Code Climate.
* Small code formatting cleanup that touched pretty much every file.
== 1.4.1 / 2010-02-03
* Imported to github.
* Converted to Hoe 2.5 spec format.
== 1.4.0 / 2007-02-11
* Merged Austin Ziegler's color-tools library (previously part of the Ruby
PDF Tools project) with Matt Lyon's color library.
- The HSL implementation from the Color class has been merged into
Color::HSL. Color is a module the way it was for color-tools.
- A thin veneer has been written to allow Color::new to return a Color::HSL
instance; Color::HSL supports as many methods as possible that were
previously supported by the Color class.
- Values that were previously rounded by Color are no longer rounded;
fractional values matter.
* Converted to hoe for project management.
* Moved to the next step of deprecating Color::Name values; printing a
warning for each use (see the history for color-tools 1.3.0).
* Print a warning on the access of either VERSION or COLOR_TOOLS_VERSION; the
version constant is now COLOR_VERSION.
* Added humanized versions of accessors (e.g., CMYK colours now have both #cyan
and #c to access the cyan component of the colour; #cyan provides the value
as a percentage).
* Added CSS3 formatters for RGB, RGBA, HSL, and HSLA outputs. Note that the
Color library does not yet have a way of setting alpha opacity, so the
output for RGBA and HSLA are at full alpha opacity (1.0). The values are
output with two decimal places.
* Applied a patch to provide simple arithmetic colour addition and subtraction
to Color::GrayScale and Color::RGB. The patch was contributed by Jeremy
Hinegardner . This patch also provides the ability to
return the maximum RGB value as a grayscale colour.
* Fixed two problems reported by Jean Krohn against
color-tools relating to RGB-to-HSL and HSL-to-RGB conversion. (Color and
color-tools use the same formulas, but the ordering of the calculations is
slightly different with Color and did not suffer from this problem;
color-tools was more sensitive to floating-point values and precision
errors.)
* Fixed an issue with HSL/RGB conversions reported by Adam Johnson
.
* Added an Adobe Color swatch (Photoshop) palette reader,
Color::Palette::AdobeColor (for .aco files only).
== Color 0.1.0 / 2006-08-05
* Added HSL (degree, percent, percent) interface.
* Removed RGB instance variable; color is managed internally as HSL floating
point.
* Tests!
== color-tools 1.3.0
* Added new metallic colours suggested by Jim Freeze . These
are in the namespace Color::Metallic.
* Colours that were defined in the Color namespace (e.g., Color::Red,
Color::AliceBlue) are now defined in Color::RGB (e.g., Color::RGB::Red,
Color::RGB::AliceBlue). They are added back to the Color namespace on the
first use of the old colours and a warning is printed. In version 1.4, this
warning will be printed on every use of the old colours. In version 1.5,
the backwards compatible support for colours like Color::Red will be
removed completely.
* Added the Color::CSS module, color/css or Color::CSS that provides a name
lookup of Color::RGB-namespaced constants with Color::CSS[name]. Most of
these colours (which are mirrored from the Color::RGB default colours) are
only "officially" recognised under the CSS3 colour module or SVG.
* Added the Color::HSL colour space and some helper utilities to Color::RGB
for colour manipulation using the HSL value.
* Controlled internal value replacement to be between 0 and 1 for all
colours.
* Updated Color::Palette::Gimp to more meaningfully deal with duplicate named
colours. Named colours now return an array of colours.
* Indicated the plans for some methods and constants out to color-tools 2.0.
* Added unit tests and fixed a number of hidden bugs because of them.
== color-tools 1.2.0
* Changed installer from a custom-written install.rb to setup.rb
3.3.1-modified.
* Added Color::GreyScale (or Color::GrayScale).
* Added Color::YIQ. This colour definition is incomplete; it does not have
conversions from YIQ to other colour spaces.
== color-tools 1.1.0
* Added color/palette/gimp to support the reading and use of GIMP color
palettes.
== color-tools 1.0.0
* Initial release.
color-1.4.2/lib/ 0000755 0000041 0000041 00000000000 12222570513 013431 5 ustar www-data www-data color-1.4.2/lib/color.rb 0000644 0000041 0000041 00000007467 12222570513 015112 0 ustar www-data www-data # :title: Color -- Colour Management with Ruby
# :main: README.rdoc
# = Colour Management with Ruby
module Color
COLOR_VERSION = '1.4.2'
class RGB; end
class CMYK; end
class GrayScale; end
class YIQ; end
# The maximum "resolution" for colour math; if any value is less than or
# equal to this value, it is treated as zero.
COLOR_EPSILON = 1e-5
# The tolerance for comparing the components of two colours. In general,
# colours are considered equal if all of their components are within this
# tolerance value of each other.
COLOR_TOLERANCE = 1e-4
class << self
# Returns +true+ if the value is less than COLOR_EPSILON.
def near_zero?(value)
(value.abs <= COLOR_EPSILON)
end
# Returns +true+ if the value is within COLOR_EPSILON of zero or less than
# zero.
def near_zero_or_less?(value)
(value < 0.0 or near_zero?(value))
end
# Returns +true+ if the value is within COLOR_EPSILON of one.
def near_one?(value)
near_zero?(value - 1.0)
end
# Returns +true+ if the value is within COLOR_EPSILON of one or more than
# one.
def near_one_or_more?(value)
(value > 1.0 or near_one?(value))
end
# Normalizes the value to the range (0.0) .. (1.0).
def normalize(value)
if near_zero_or_less? value
0.0
elsif near_one_or_more? value
1.0
else
value
end
end
alias normalize_fractional normalize
def normalize_to_range(value, range)
range = (range.end..range.begin) if (range.end < range.begin)
if value <= range.begin
range.begin
elsif value >= range.end
range.end
else
value
end
end
# Normalize the value to the range (0) .. (255).
def normalize_byte(value)
normalize_to_range(value, 0..255).to_i
end
alias normalize_8bit normalize_byte
# Normalize the value to the range (0) .. (65535).
def normalize_word(value)
normalize_to_range(value, 0..65535).to_i
end
alias normalize_16bit normalize_word
end
end
require 'color/rgb'
require 'color/cmyk'
require 'color/grayscale'
require 'color/hsl'
require 'color/yiq'
require 'color/rgb/metallic'
module Color
def self.const_missing(name) #:nodoc:
case name
when "VERSION", :VERSION, "COLOR_TOOLS_VERSION", :COLOR_TOOLS_VERSION
warn "Color::#{name} has been deprecated. Use Color::COLOR_VERSION instead."
Color::COLOR_VERSION
else
if Color::RGB.const_defined?(name)
warn "Color::#{name} has been deprecated. Use Color::RGB::#{name} instead."
Color::RGB.const_get(name)
else
super
end
end
end
# Provides a thin veneer over the Color module to make it seem like this
# is Color 0.1.0 (a class) and not Color 1.4 (a module). This
# "constructor" will be removed in the future.
#
# mode = :hsl:: +values+ must be an array of [ hue deg, sat %, lum % ].
# A Color::HSL object will be created.
# mode = :rgb:: +values+ will either be an HTML-style colour string or
# an array of [ red, green, blue ] (range 0 .. 255). A
# Color::RGB object will be created.
# mode = :cmyk:: +values+ must be an array of [ cyan %, magenta %, yellow
# %, black % ]. A Color::CMYK object will be created.
def self.new(values, mode = :rgb)
warn "Color.new has been deprecated. Use Color::#{mode.to_s.upcase}.new instead."
color = case mode
when :hsl
Color::HSL.new(*values)
when :rgb
values = [ values ].flatten
if values.size == 1
Color::RGB.from_html(*values)
else
Color::RGB.new(*values)
end
when :cmyk
Color::CMYK.new(*values)
end
color.to_hsl
end
end
color-1.4.2/lib/color/ 0000755 0000041 0000041 00000000000 12222570513 014547 5 ustar www-data www-data color-1.4.2/lib/color/rgb.rb 0000644 0000041 0000041 00000031511 12222570513 015647 0 ustar www-data www-data # An RGB colour object.
class Color::RGB
# The format of a DeviceRGB colour for PDF. In color-tools 2.0 this will
# be removed from this package and added back as a modification by the
# PDF::Writer package.
PDF_FORMAT_STR = "%.3f %.3f %.3f %s"
class << self
# Creates an RGB colour object from percentages 0..100.
#
# Color::RGB.from_percentage(10, 20 30)
def from_percentage(r = 0, g = 0, b = 0)
from_fraction(r / 100.0, g / 100.0, b / 100.0)
end
# Creates an RGB colour object from fractional values 0..1.
#
# Color::RGB.from_fraction(.3, .2, .1)
def from_fraction(r = 0.0, g = 0.0, b = 0.0)
colour = Color::RGB.new
colour.r = r
colour.g = g
colour.b = b
colour
end
# Creates an RGB colour object from an HTML colour descriptor (e.g.,
# "fed" or "#cabbed;".
#
# Color::RGB.from_html("fed")
# Color::RGB.from_html("#fed")
# Color::RGB.from_html("#cabbed")
# Color::RGB.from_html("cabbed")
def from_html(html_colour)
html_colour = html_colour.gsub(%r{[#;]}, '')
case html_colour.size
when 3
colours = html_colour.scan(%r{[0-9A-Fa-f]}).map { |el| (el * 2).to_i(16) }
when 6
colours = html_colour.scan(%r<[0-9A-Fa-f]{2}>).map { |el| el.to_i(16) }
else
raise ArgumentError
end
Color::RGB.new(*colours)
end
end
# Compares the other colour to this one. The other colour will be
# converted to RGB before comparison, so the comparison between a RGB
# colour and a non-RGB colour will be approximate and based on the other
# colour's default #to_rgb conversion. If there is no #to_rgb conversion,
# this will raise an exception. This will report that two RGB colours are
# equivalent if all component values are within COLOR_TOLERANCE of each
# other.
def ==(other)
other = other.to_rgb
other.kind_of?(Color::RGB) and
((@r - other.r).abs <= Color::COLOR_TOLERANCE) and
((@g - other.g).abs <= Color::COLOR_TOLERANCE) and
((@b - other.b).abs <= Color::COLOR_TOLERANCE)
end
# Creates an RGB colour object from the standard range 0..255.
#
# Color::RGB.new(32, 64, 128)
# Color::RGB.new(0x20, 0x40, 0x80)
def initialize(r = 0, g = 0, b = 0)
@r = r / 255.0
@g = g / 255.0
@b = b / 255.0
end
# Present the colour as a DeviceRGB fill colour string for PDF. This will
# be removed from the default package in color-tools 2.0.
def pdf_fill
PDF_FORMAT_STR % [ @r, @g, @b, "rg" ]
end
# Present the colour as a DeviceRGB stroke colour string for PDF. This
# will be removed from the default package in color-tools 2.0.
def pdf_stroke
PDF_FORMAT_STR % [ @r, @g, @b, "RG" ]
end
# Present the colour as an HTML/CSS colour string.
def html
r = (@r * 255).round
r = 255 if r > 255
g = (@g * 255).round
g = 255 if g > 255
b = (@b * 255).round
b = 255 if b > 255
"#%02x%02x%02x" % [ r, g, b ]
end
# Present the colour as an RGB HTML/CSS colour string (e.g., "rgb(0%, 50%,
# 100%)"). Note that this will perform a #to_rgb operation using the
# default conversion formula.
def css_rgb
"rgb(%3.2f%%, %3.2f%%, %3.2f%%)" % [ red_p, green_p, blue_p ]
end
# Present the colour as an RGBA (with alpha) HTML/CSS colour string (e.g.,
# "rgb(0%, 50%, 100%, 1)"). Note that this will perform a #to_rgb
# operation using the default conversion formula.
def css_rgba
"rgba(%3.2f%%, %3.2f%%, %3.2f%%, %3.2f)" % [ red_p, green_p, blue_p, 1 ]
end
# Present the colour as an HSL HTML/CSS colour string (e.g., "hsl(180,
# 25%, 35%)"). Note that this will perform a #to_hsl operation using the
# default conversion formula.
def css_hsl
to_hsl.css_hsl
end
# Present the colour as an HSLA (with alpha) HTML/CSS colour string (e.g.,
# "hsla(180, 25%, 35%, 1)"). Note that this will perform a #to_hsl
# operation using the default conversion formula.
def css_hsla
to_hsl.css_hsla
end
# Converts the RGB colour to CMYK. Most colour experts strongly suggest
# that this is not a good idea (some even suggesting that it's a very bad
# idea). CMYK represents additive percentages of inks on white paper,
# whereas RGB represents mixed colour intensities on a black screen.
#
# However, the colour conversion can be done. The basic method is
# multi-step:
#
# 1. Convert the R, G, and B components to C, M, and Y components.
# c = 1.0 - r
# m = 1.0 - g
# y = 1.0 - b
# 2. Compute the minimum amount of black (K) required to smooth the colour
# in inks.
# k = min(c, m, y)
# 3. Perform undercolour removal on the C, M, and Y components of the
# colours because less of each colour is needed for each bit of black.
# Also, regenerate the black (K) based on the undercolour removal so
# that the colour is more accurately represented in ink.
# c = min(1.0, max(0.0, c - UCR(k)))
# m = min(1.0, max(0.0, m - UCR(k)))
# y = min(1.0, max(0.0, y - UCR(k)))
# k = min(1.0, max(0.0, BG(k)))
#
# The undercolour removal function and the black generation functions
# return a value based on the brightness of the RGB colour.
def to_cmyk
c = 1.0 - @r.to_f
m = 1.0 - @g.to_f
y = 1.0 - @b.to_f
k = [c, m, y].min
k = k - (k * brightness)
c = [1.0, [0.0, c - k].max].min
m = [1.0, [0.0, m - k].max].min
y = [1.0, [0.0, y - k].max].min
k = [1.0, [0.0, k].max].min
Color::CMYK.from_fraction(c, m, y, k)
end
def to_rgb(ignored = nil)
self
end
# Returns the YIQ (NTSC) colour encoding of the RGB value.
def to_yiq
y = (@r * 0.299) + (@g * 0.587) + (@b * 0.114)
i = (@r * 0.596) + (@g * -0.275) + (@b * -0.321)
q = (@r * 0.212) + (@g * -0.523) + (@b * 0.311)
Color::YIQ.from_fraction(y, i, q)
end
# Returns the HSL colour encoding of the RGB value. The conversions here
# are based on forumlas from http://www.easyrgb.com/math.php and
# elsewhere.
def to_hsl
min = [ @r, @g, @b ].min
max = [ @r, @g, @b ].max
delta = (max - min).to_f
lum = (max + min) / 2.0
if Color.near_zero?(delta) # close to 0.0, so it's a grey
hue = 0
sat = 0
else
if Color.near_zero_or_less?(lum - 0.5)
sat = delta / (max + min).to_f
else
sat = delta / (2 - max - min).to_f
end
# This is based on the conversion algorithm from
# http://en.wikipedia.org/wiki/HSV_color_space#Conversion_from_RGB_to_HSL_or_HSV
# Contributed by Adam Johnson
sixth = 1 / 6.0
if @r == max # Color.near_zero_or_less?(@r - max)
hue = (sixth * ((@g - @b) / delta))
hue += 1.0 if @g < @b
elsif @g == max # Color.near_zero_or_less(@g - max)
hue = (sixth * ((@b - @r) / delta)) + (1.0 / 3.0)
elsif @b == max # Color.near_zero_or_less?(@b - max)
hue = (sixth * ((@r - @g) / delta)) + (2.0 / 3.0)
end
hue += 1 if hue < 0
hue -= 1 if hue > 1
end
Color::HSL.from_fraction(hue, sat, lum)
end
# Mix the RGB hue with White so that the RGB hue is the specified
# percentage of the resulting colour. Strictly speaking, this isn't a
# darken_by operation.
def lighten_by(percent)
mix_with(White, percent)
end
# Mix the RGB hue with Black so that the RGB hue is the specified
# percentage of the resulting colour. Strictly speaking, this isn't a
# darken_by operation.
def darken_by(percent)
mix_with(Black, percent)
end
# Mix the mask colour (which must be an RGB object) with the current
# colour at the stated opacity percentage (0..100).
def mix_with(mask, opacity)
opacity /= 100.0
rgb = self.dup
rgb.r = (@r * opacity) + (mask.r * (1 - opacity))
rgb.g = (@g * opacity) + (mask.g * (1 - opacity))
rgb.b = (@b * opacity) + (mask.b * (1 - opacity))
rgb
end
# Returns the brightness value for a colour, a number between 0..1. Based
# on the Y value of YIQ encoding, representing luminosity, or perceived
# brightness.
#
# This may be modified in a future version of color-tools to use the
# luminosity value of HSL.
def brightness
to_yiq.y
end
# Convert to grayscale.
def to_grayscale
Color::GrayScale.from_fraction(to_hsl.l)
end
alias to_greyscale to_grayscale
# Returns a new colour with the brightness adjusted by the specified
# percentage. Negative percentages will darken the colour; positive
# percentages will brighten the colour.
#
# Color::RGB::DarkBlue.adjust_brightness(10)
# Color::RGB::DarkBlue.adjust_brightness(-10)
def adjust_brightness(percent)
percent /= 100.0
percent += 1.0
percent = [ percent, 2.0 ].min
percent = [ 0.0, percent ].max
hsl = to_hsl
hsl.l *= percent
hsl.to_rgb
end
# Returns a new colour with the saturation adjusted by the specified
# percentage. Negative percentages will reduce the saturation; positive
# percentages will increase the saturation.
#
# Color::RGB::DarkBlue.adjust_saturation(10)
# Color::RGB::DarkBlue.adjust_saturation(-10)
def adjust_saturation(percent)
percent /= 100.0
percent += 1.0
percent = [ percent, 2.0 ].min
percent = [ 0.0, percent ].max
hsl = to_hsl
hsl.s *= percent
hsl.to_rgb
end
# Returns a new colour with the hue adjusted by the specified percentage.
# Negative percentages will reduce the hue; positive percentages will
# increase the hue.
#
# Color::RGB::DarkBlue.adjust_hue(10)
# Color::RGB::DarkBlue.adjust_hue(-10)
def adjust_hue(percent)
percent /= 100.0
percent += 1.0
percent = [ percent, 2.0 ].min
percent = [ 0.0, percent ].max
hsl = to_hsl
hsl.h *= percent
hsl.to_rgb
end
# Returns the red component of the colour in the normal 0 .. 255 range.
def red
@r * 255.0
end
# Returns the red component of the colour as a percentage.
def red_p
@r * 100.0
end
# Returns the red component of the colour as a fraction in the range 0.0
# .. 1.0.
def r
@r
end
# Sets the red component of the colour in the normal 0 .. 255 range.
def red=(rr)
@r = Color.normalize(rr / 255.0)
end
# Sets the red component of the colour as a percentage.
def red_p=(rr)
@r = Color.normalize(rr / 100.0)
end
# Sets the red component of the colour as a fraction in the range 0.0 ..
# 1.0.
def r=(rr)
@r = Color.normalize(rr)
end
# Returns the green component of the colour in the normal 0 .. 255 range.
def green
@g * 255.0
end
# Returns the green component of the colour as a percentage.
def green_p
@g * 100.0
end
# Returns the green component of the colour as a fraction in the range 0.0
# .. 1.0.
def g
@g
end
# Sets the green component of the colour in the normal 0 .. 255 range.
def green=(gg)
@g = Color.normalize(gg / 255.0)
end
# Sets the green component of the colour as a percentage.
def green_p=(gg)
@g = Color.normalize(gg / 100.0)
end
# Sets the green component of the colour as a fraction in the range 0.0 ..
# 1.0.
def g=(gg)
@g = Color.normalize(gg)
end
# Returns the blue component of the colour in the normal 0 .. 255 range.
def blue
@b * 255.0
end
# Returns the blue component of the colour as a percentage.
def blue_p
@b * 100.0
end
# Returns the blue component of the colour as a fraction in the range 0.0
# .. 1.0.
def b
@b
end
# Sets the blue component of the colour in the normal 0 .. 255 range.
def blue=(bb)
@b = Color.normalize(bb / 255.0)
end
# Sets the blue component of the colour as a percentage.
def blue_p=(bb)
@b = Color.normalize(bb / 100.0)
end
# Sets the blue component of the colour as a fraction in the range 0.0 ..
# 1.0.
def b=(bb)
@b = Color.normalize(bb)
end
# Adds another colour to the current colour. The other colour will be
# converted to RGB before addition. This conversion depends upon a #to_rgb
# method on the other colour.
#
# The addition is done using the RGB Accessor methods to ensure a valid
# colour in the result.
def +(other)
other = other.to_rgb
rgb = self.dup
rgb.r += other.r
rgb.g += other.g
rgb.b += other.b
rgb
end
# Subtracts another colour to the current colour. The other colour will be
# converted to RGB before subtraction. This conversion depends upon a
# #to_rgb method on the other colour.
#
# The subtraction is done using the RGB Accessor methods to ensure a valid
# colour in the result.
def -(other)
other = other.to_rgb
rgb = self.dup
rgb.r -= other.r
rgb.g -= other.g
rgb.b -= other.b
rgb
end
# Retrieve the maxmum RGB value from the current colour as a GrayScale
# colour
def max_rgb_as_grayscale
Color::GrayScale.from_fraction([@r, @g, @b].max)
end
alias max_rgb_as_greyscale max_rgb_as_grayscale
def inspect
"RGB [#{html}]"
end
end
require 'color/rgb-colors'
color-1.4.2/lib/color/rgb/ 0000755 0000041 0000041 00000000000 12222570513 015321 5 ustar www-data www-data color-1.4.2/lib/color/rgb/metallic.rb 0000644 0000041 0000041 00000001740 12222570513 017442 0 ustar www-data www-data # This namespace contains some RGB metallic colours suggested by Jim Freeze.
module Color::RGB::Metallic
Aluminum = Color::RGB.new(0x99, 0x99, 0x99)
CoolCopper = Color::RGB.new(0xd9, 0x87, 0x19)
Copper = Color::RGB.new(0xb8, 0x73, 0x33)
Iron = Color::RGB.new(0x4c, 0x4c, 0x4c)
Lead = Color::RGB.new(0x19, 0x19, 0x19)
Magnesium = Color::RGB.new(0xb3, 0xb3, 0xb3)
Mercury = Color::RGB.new(0xe6, 0xe6, 0xe6)
Nickel = Color::RGB.new(0x80, 0x80, 0x80)
PolySilicon = Color::RGB.new(0x60, 0x00, 0x00)
Poly = PolySilicon
Silver = Color::RGB.new(0xcc, 0xcc, 0xcc)
Steel = Color::RGB.new(0x66, 0x66, 0x66)
Tin = Color::RGB.new(0x7f, 0x7f, 0x7f)
Tungsten = Color::RGB.new(0x33, 0x33, 0x33)
Aluminum.freeze
CoolCopper.freeze
Copper.freeze
Iron.freeze
Lead.freeze
Magnesium.freeze
Mercury.freeze
Nickel.freeze
PolySilicon.freeze
Silver.freeze
Steel.freeze
Tin.freeze
Tungsten.freeze
end
color-1.4.2/lib/color/rgb-colors.rb 0000644 0000041 0000041 00000031651 12222570513 017153 0 ustar www-data www-data class Color::RGB
AliceBlue = Color::RGB.new(0xf0, 0xf8, 0xff)
AntiqueWhite = Color::RGB.new(0xfa, 0xeb, 0xd7)
Aqua = Color::RGB.new(0x00, 0xff, 0xff)
Aquamarine = Color::RGB.new(0x7f, 0xff, 0xd4)
Azure = Color::RGB.new(0xf0, 0xff, 0xff)
Beige = Color::RGB.new(0xf5, 0xf5, 0xdc)
Bisque = Color::RGB.new(0xff, 0xe4, 0xc4)
Black = Color::RGB.new(0, 0, 0)
BlanchedAlmond = Color::RGB.new(0xff, 0xeb, 0xcd)
Blue = Color::RGB.new(0x00, 0x00, 0xff)
BlueViolet = Color::RGB.new(0x8a, 0x2b, 0xe2)
Brown = Color::RGB.new(0xa5, 0x2a, 0x2a)
BurlyWood = Color::RGB.new(0xde, 0xb8, 0x87)
Burlywood = BurlyWood
CadetBlue = Color::RGB.new(0x5f, 0x9e, 0xa0)
Carnation = Color::RGB.new(0xff, 0x5e, 0xd0)
Cayenne = Color::RGB.new(0x8d, 0x00, 0x00)
Chartreuse = Color::RGB.new(0x7f, 0xff, 0x00)
Chocolate = Color::RGB.new(0xd2, 0x69, 0x1e)
Coral = Color::RGB.new(0xff, 0x7f, 0x50)
CornflowerBlue = Color::RGB.new(0x64, 0x95, 0xed)
Cornsilk = Color::RGB.new(0xff, 0xf8, 0xdc)
Crimson = Color::RGB.new(0xdc, 0x14, 0x3c)
Cyan = Color::RGB.new(0x00, 0xff, 0xff)
DarkBlue = Color::RGB.new(0x00, 0x00, 0x8b)
DarkCyan = Color::RGB.new(0x00, 0x8b, 0x8b)
DarkGoldenRod = Color::RGB.new(0xb8, 0x86, 0x0b)
DarkGoldenrod = DarkGoldenRod
DarkGray = Color::RGB.new(0xa9, 0xa9, 0xa9)
DarkGreen = Color::RGB.new(0x00, 0x64, 0x00)
DarkGrey = DarkGray
DarkKhaki = Color::RGB.new(0xbd, 0xb7, 0x6b)
DarkMagenta = Color::RGB.new(0x8b, 0x00, 0x8b)
DarkOliveGreen = Color::RGB.new(0x55, 0x6b, 0x2f)
DarkOrange = Color::RGB.new(0xff, 0x8c, 0x00)
DarkOrchid = Color::RGB.new(0x99, 0x32, 0xcc)
DarkRed = Color::RGB.new(0x8b, 0x00, 0x00)
DarkSalmon = Color::RGB.new(0xe9, 0x96, 0x7a)
DarkSeaGreen = Color::RGB.new(0x8f, 0xbc, 0x8f)
DarkSlateBlue = Color::RGB.new(0x48, 0x3d, 0x8b)
DarkSlateGray = Color::RGB.new(0x2f, 0x4f, 0x4f)
DarkSlateGrey = DarkSlateGray
DarkTurquoise = Color::RGB.new(0x00, 0xce, 0xd1)
DarkViolet = Color::RGB.new(0x94, 0x00, 0xd3)
DarkoliveGreen = DarkOliveGreen
Darkorange = Color::RGB.new(0xff, 0x8c, 0x00)
Darksalmon = DarkSalmon
DeepPink = Color::RGB.new(0xff, 0x14, 0x93)
DeepSkyBlue = Color::RGB.new(0x00, 0xbf, 0xbf)
DimGray = Color::RGB.new(0x69, 0x69, 0x69)
DimGrey = DimGray
DodgerBlue = Color::RGB.new(0x1e, 0x90, 0xff)
Feldspar = Color::RGB.new(0xd1, 0x92, 0x75)
FireBrick = Color::RGB.new(0xb2, 0x22, 0x22)
Firebrick = FireBrick
FloralWhite = Color::RGB.new(0xff, 0xfa, 0xf0)
ForestGreen = Color::RGB.new(0x22, 0x8b, 0x22)
Fuchsia = Color::RGB.new(0xff, 0x00, 0xff)
Gainsboro = Color::RGB.new(0xdc, 0xdc, 0xdc)
GhostWhite = Color::RGB.new(0xf8, 0xf8, 0xff)
Gold = Color::RGB.new(0xff, 0xd7, 0x00)
GoldenRod = Color::RGB.new(0xda, 0xa5, 0x20)
Goldenrod = GoldenRod
Gray = Color::RGB.new(0x80, 0x80, 0x80)
Gray10 = Color::RGB.from_percentage(10, 10, 10)
Gray20 = Color::RGB.from_percentage(20, 20, 20)
Gray30 = Color::RGB.from_percentage(30, 30, 30)
Gray40 = Color::RGB.from_percentage(40, 40, 40)
Gray50 = Color::RGB.from_percentage(50, 50, 50)
Gray60 = Color::RGB.from_percentage(60, 60, 60)
Gray70 = Color::RGB.from_percentage(70, 70, 70)
Gray80 = Color::RGB.from_percentage(80, 80, 80)
Gray90 = Color::RGB.from_percentage(90, 90, 90)
Green = Color::RGB.new(0x00, 0x80, 0x00)
GreenYellow = Color::RGB.new(0xad, 0xff, 0x2f)
Grey = Gray
Grey10 = Gray10
Grey20 = Gray20
Grey30 = Gray30
Grey40 = Gray40
Grey50 = Gray50
Grey60 = Gray60
Grey70 = Gray70
Grey80 = Gray80
Grey90 = Gray90
HoneyDew = Color::RGB.new(0xf0, 0xff, 0xf0)
Honeydew = HoneyDew
HotPink = Color::RGB.new(0xff, 0x69, 0xb4)
IndianRed = Color::RGB.new(0xcd, 0x5c, 0x5c)
Indigo = Color::RGB.new(0x4b, 0x00, 0x82)
Ivory = Color::RGB.new(0xff, 0xff, 0xf0)
Khaki = Color::RGB.new(0xf0, 0xe6, 0x8c)
Lavender = Color::RGB.new(0xe6, 0xe6, 0xfa)
LavenderBlush = Color::RGB.new(0xff, 0xf0, 0xf5)
LawnGreen = Color::RGB.new(0x7c, 0xfc, 0x00)
LemonChiffon = Color::RGB.new(0xff, 0xfa, 0xcd)
LightBlue = Color::RGB.new(0xad, 0xd8, 0xe6)
LightCoral = Color::RGB.new(0xf0, 0x80, 0x80)
LightCyan = Color::RGB.new(0xe0, 0xff, 0xff)
LightGoldenRodYellow = Color::RGB.new(0xfa, 0xfa, 0xd2)
LightGoldenrodYellow = LightGoldenRodYellow
LightGray = Color::RGB.new(0xd3, 0xd3, 0xd3)
LightGreen = Color::RGB.new(0x90, 0xee, 0x90)
LightGrey = LightGray
LightPink = Color::RGB.new(0xff, 0xb6, 0xc1)
LightSalmon = Color::RGB.new(0xff, 0xa0, 0x7a)
LightSeaGreen = Color::RGB.new(0x20, 0xb2, 0xaa)
LightSkyBlue = Color::RGB.new(0x87, 0xce, 0xfa)
LightSlateBlue = Color::RGB.new(0x84, 0x70, 0xff)
LightSlateGray = Color::RGB.new(0x77, 0x88, 0x99)
LightSlateGrey = LightSlateGray
LightSteelBlue = Color::RGB.new(0xb0, 0xc4, 0xde)
LightYellow = Color::RGB.new(0xff, 0xff, 0xe0)
Lightsalmon = LightSalmon
LightsteelBlue = LightSteelBlue
Lime = Color::RGB.new(0x00, 0xff, 0x00)
LimeGreen = Color::RGB.new(0x32, 0xcd, 0x32)
Linen = Color::RGB.new(0xfa, 0xf0, 0xe6)
Magenta = Color::RGB.new(0xff, 0x00, 0xff)
Maroon = Color::RGB.new(0x80, 0x00, 0x00)
MediumAquaMarine = Color::RGB.new(0x66, 0xcd, 0xaa)
MediumAquamarine = MediumAquaMarine
MediumBlue = Color::RGB.new(0x00, 0x00, 0xcd)
MediumOrchid = Color::RGB.new(0xba, 0x55, 0xd3)
MediumPurple = Color::RGB.new(0x93, 0x70, 0xdb)
MediumSeaGreen = Color::RGB.new(0x3c, 0xb3, 0x71)
MediumSlateBlue = Color::RGB.new(0x7b, 0x68, 0xee)
MediumSpringGreen = Color::RGB.new(0x00, 0xfa, 0x9a)
MediumTurquoise = Color::RGB.new(0x48, 0xd1, 0xcc)
MediumVioletRed = Color::RGB.new(0xc7, 0x15, 0x85)
MidnightBlue = Color::RGB.new(0x19, 0x19, 0x70)
MintCream = Color::RGB.new(0xf5, 0xff, 0xfa)
MistyRose = Color::RGB.new(0xff, 0xe4, 0xe1)
Moccasin = Color::RGB.new(0xff, 0xe4, 0xb5)
NavajoWhite = Color::RGB.new(0xff, 0xde, 0xad)
Navy = Color::RGB.new(0x00, 0x00, 0x80)
OldLace = Color::RGB.new(0xfd, 0xf5, 0xe6)
Olive = Color::RGB.new(0x80, 0x80, 0x00)
OliveDrab = Color::RGB.new(0x6b, 0x8e, 0x23)
Olivedrab = OliveDrab
Orange = Color::RGB.new(0xff, 0xa5, 0x00)
OrangeRed = Color::RGB.new(0xff, 0x45, 0x00)
Orchid = Color::RGB.new(0xda, 0x70, 0xd6)
PaleGoldenRod = Color::RGB.new(0xee, 0xe8, 0xaa)
PaleGoldenrod = PaleGoldenRod
PaleGreen = Color::RGB.new(0x98, 0xfb, 0x98)
PaleTurquoise = Color::RGB.new(0xaf, 0xee, 0xee)
PaleVioletRed = Color::RGB.new(0xdb, 0x70, 0x93)
PapayaWhip = Color::RGB.new(0xff, 0xef, 0xd5)
PeachPuff = Color::RGB.new(0xff, 0xda, 0xb9)
Peachpuff = PeachPuff
Peru = Color::RGB.new(0xcd, 0x85, 0x3f)
Pink = Color::RGB.new(0xff, 0xc0, 0xcb)
Plum = Color::RGB.new(0xdd, 0xa0, 0xdd)
PowderBlue = Color::RGB.new(0xb0, 0xe0, 0xe6)
Purple = Color::RGB.new(0x80, 0x00, 0x80)
Red = Color::RGB.new(0xff, 0x00, 0x00)
RosyBrown = Color::RGB.new(0xbc, 0x8f, 0x8f)
RoyalBlue = Color::RGB.new(0x41, 0x69, 0xe1)
SaddleBrown = Color::RGB.new(0x8b, 0x45, 0x13)
Salmon = Color::RGB.new(0xfa, 0x80, 0x72)
SandyBrown = Color::RGB.new(0xf4, 0xa4, 0x60)
SeaGreen = Color::RGB.new(0x2e, 0x8b, 0x57)
SeaShell = Color::RGB.new(0xff, 0xf5, 0xee)
Seashell = SeaShell
Sienna = Color::RGB.new(0xa0, 0x52, 0x2d)
Silver = Color::RGB.new(0xc0, 0xc0, 0xc0)
SkyBlue = Color::RGB.new(0x87, 0xce, 0xeb)
SlateBlue = Color::RGB.new(0x6a, 0x5a, 0xcd)
SlateGray = Color::RGB.new(0x70, 0x80, 0x90)
SlateGrey = SlateGray
Snow = Color::RGB.new(0xff, 0xfa, 0xfa)
SpringGreen = Color::RGB.new(0x00, 0xff, 0x7f)
SteelBlue = Color::RGB.new(0x46, 0x82, 0xb4)
Tan = Color::RGB.new(0xd2, 0xb4, 0x8c)
Teal = Color::RGB.new(0x00, 0x80, 0x80)
Thistle = Color::RGB.new(0xd8, 0xbf, 0xd8)
Tomato = Color::RGB.new(0xff, 0x63, 0x47)
Turquoise = Color::RGB.new(0x40, 0xe0, 0xd0)
Violet = Color::RGB.new(0xee, 0x82, 0xee)
VioletRed = Color::RGB.new(0xd0, 0x20, 0x90)
Wheat = Color::RGB.new(0xf5, 0xde, 0xb3)
White = Color::RGB.new(0xff, 0xff, 0xff)
WhiteSmoke = Color::RGB.new(0xf5, 0xf5, 0xf5)
Yellow = Color::RGB.new(0xff, 0xff, 0x00)
YellowGreen = Color::RGB.new(0x9a, 0xcd, 0x32)
AliceBlue.freeze
AntiqueWhite.freeze
Aqua.freeze
Aquamarine.freeze
Azure.freeze
Beige.freeze
Bisque.freeze
Black.freeze
BlanchedAlmond.freeze
Blue.freeze
BlueViolet.freeze
Brown.freeze
Burlywood.freeze
CadetBlue.freeze
Cayenne.freeze
Carnation.freeze
Chartreuse.freeze
Chocolate.freeze
Coral.freeze
CornflowerBlue.freeze
Cornsilk.freeze
Crimson.freeze
Cyan.freeze
DarkBlue.freeze
DarkCyan.freeze
DarkGoldenrod.freeze
DarkGray.freeze
DarkGreen.freeze
DarkKhaki.freeze
DarkMagenta.freeze
DarkoliveGreen.freeze
Darkorange.freeze
DarkOrchid.freeze
DarkRed.freeze
Darksalmon.freeze
DarkSeaGreen.freeze
DarkSlateBlue.freeze
DarkSlateGray.freeze
DarkTurquoise.freeze
DarkViolet.freeze
DeepPink.freeze
DeepSkyBlue.freeze
DimGray.freeze
DodgerBlue.freeze
Feldspar.freeze
Firebrick.freeze
FloralWhite.freeze
ForestGreen.freeze
Fuchsia.freeze
Gainsboro.freeze
GhostWhite.freeze
Gold.freeze
Goldenrod.freeze
Gray.freeze
Green.freeze
GreenYellow.freeze
Honeydew.freeze
HotPink.freeze
IndianRed.freeze
Indigo.freeze
Ivory.freeze
Khaki.freeze
Lavender.freeze
LavenderBlush.freeze
LawnGreen.freeze
LemonChiffon.freeze
LightBlue.freeze
LightCoral.freeze
LightCyan.freeze
LightGoldenrodYellow.freeze
LightGray.freeze
LightGreen.freeze
LightPink.freeze
Lightsalmon.freeze
LightSeaGreen.freeze
LightSkyBlue.freeze
LightSlateBlue.freeze
LightSlateGray.freeze
LightsteelBlue.freeze
LightYellow.freeze
Lime.freeze
LimeGreen.freeze
Linen.freeze
Magenta.freeze
Maroon.freeze
MediumAquamarine.freeze
MediumBlue.freeze
MediumOrchid.freeze
MediumPurple.freeze
MediumSeaGreen.freeze
MediumSlateBlue.freeze
MediumSpringGreen.freeze
MediumTurquoise.freeze
MediumVioletRed.freeze
MidnightBlue.freeze
MintCream.freeze
MistyRose.freeze
Moccasin.freeze
NavajoWhite.freeze
Navy.freeze
OldLace.freeze
Olive.freeze
Olivedrab.freeze
Orange.freeze
OrangeRed.freeze
Orchid.freeze
PaleGoldenrod.freeze
PaleGreen.freeze
PaleTurquoise.freeze
PaleVioletRed.freeze
PapayaWhip.freeze
Peachpuff.freeze
Peru.freeze
Pink.freeze
Plum.freeze
PowderBlue.freeze
Purple.freeze
Red.freeze
RosyBrown.freeze
RoyalBlue.freeze
SaddleBrown.freeze
Salmon.freeze
SandyBrown.freeze
SeaGreen.freeze
Seashell.freeze
Sienna.freeze
Silver.freeze
SkyBlue.freeze
SlateBlue.freeze
SlateGray.freeze
Snow.freeze
SpringGreen.freeze
SteelBlue.freeze
Tan.freeze
Teal.freeze
Thistle.freeze
Tomato.freeze
Turquoise.freeze
Violet.freeze
VioletRed.freeze
Wheat.freeze
White.freeze
WhiteSmoke.freeze
Yellow.freeze
YellowGreen.freeze
Gray10.freeze
Gray20.freeze
Gray30.freeze
Gray40.freeze
Gray50.freeze
Gray60.freeze
Gray70.freeze
Gray80.freeze
Gray90.freeze
end
color-1.4.2/lib/color/css.rb 0000644 0000041 0000041 00000000646 12222570513 015672 0 ustar www-data www-data require 'color'
# This namespace contains some CSS colour names.
module Color::CSS
# Returns the RGB colour for name or +nil+ if the name is not valid.
def self.[](name)
@colors[name.to_s.downcase.to_sym]
end
@colors = {}
Color::RGB.constants.each do |const|
next if const == "PDF_FORMAT_STR"
next if const == "Metallic"
@colors[const.downcase.to_sym] ||= Color::RGB.const_get(const)
end
end
color-1.4.2/lib/color/grayscale.rb 0000644 0000041 0000041 00000012772 12222570513 017057 0 ustar www-data www-data # A colour object representing shades of grey. Used primarily in PDF
# document creation.
class Color::GrayScale
# The format of a DeviceGrey colour for PDF. In color-tools 2.0 this will
# be removed from this package and added back as a modification by the
# PDF::Writer package.
PDF_FORMAT_STR = "%.3f %s"
# Creates a greyscale colour object from fractional values 0..1.
#
# Color::GreyScale.from_fraction(0.5)
def self.from_fraction(g = 0)
color = Color::GrayScale.new
color.g = g
color
end
# Creates a greyscale colour object from percentages 0..100.
#
# Color::GrayScale.from_percent(50)
def self.from_percent(g = 0)
Color::GrayScale.new(g)
end
# Creates a greyscale colour object from percentages 0..100.
#
# Color::GrayScale.new(50)
def initialize(g = 0)
@g = g / 100.0
end
# Compares the other colour to this one. The other colour will be
# converted to GreyScale before comparison, so the comparison between a
# GreyScale colour and a non-GreyScale colour will be approximate and
# based on the other colour's #to_greyscale conversion. If there is no
# #to_greyscale conversion, this will raise an exception. This will report
# that two GreyScale values are equivalent if they are within
# COLOR_TOLERANCE of each other.
def ==(other)
other = other.to_grayscale
other.kind_of?(Color::GrayScale) and
((@g - other.g).abs <= Color::COLOR_TOLERANCE)
end
# Present the colour as a DeviceGrey fill colour string for PDF. This will
# be removed from the default package in color-tools 2.0.
def pdf_fill
PDF_FORMAT_STR % [ @g, "g" ]
end
# Present the colour as a DeviceGrey stroke colour string for PDF. This
# will be removed from the default package in color-tools 2.0.
def pdf_stroke
PDF_FORMAT_STR % [ @g, "G" ]
end
def to_255
[(@g * 255).round, 255].min
end
private :to_255
# Present the colour as an HTML/CSS colour string.
def html
gs = "%02x" % to_255
"##{gs * 3}"
end
# Present the colour as an RGB HTML/CSS colour string (e.g., "rgb(0%, 50%,
# 100%)").
def css_rgb
"rgb(%3.2f%%, %3.2f%%, %3.2f%%)" % [ gray, gray, gray ]
end
# Present the colour as an RGBA (with alpha) HTML/CSS colour string (e.g.,
# "rgb(0%, 50%, 100%, 1)").
def css_rgba
"rgba(%3.2f%%, %3.2f%%, %3.2f%%, %1.2f)" % [ gray, gray, gray, 1 ]
end
# Present the colour as an HSL HTML/CSS colour string (e.g., "hsl(180,
# 25%, 35%)"). Note that this will perform a #to_hsl operation.
def css_hsl
to_hsl.css_hsl
end
# Present the colour as an HSLA (with alpha) HTML/CSS colour string (e.g.,
# "hsla(180, 25%, 35%, 1)"). Note that this will perform a #to_hsl
# operation.
def css_hsla
to_hsl.css_hsla
end
# Convert the greyscale colour to CMYK.
def to_cmyk
k = 1.0 - @g.to_f
Color::CMYK.from_fraction(0, 0, 0, k)
end
# Convert the greyscale colour to RGB.
def to_rgb(ignored = true)
Color::RGB.from_fraction(g, g, g)
end
# Reflexive conversion.
def to_grayscale
self
end
alias to_greyscale to_grayscale
# Lightens the greyscale colour by the stated percent.
def lighten_by(percent)
g = [@g + (@g * (percent / 100.0)), 1.0].min
Color::GrayScale.from_fraction(g)
end
# Darken the greyscale colour by the stated percent.
def darken_by(percent)
g = [@g - (@g * (percent / 100.0)), 0.0].max
Color::GrayScale.from_fraction(g)
end
# Returns the YIQ (NTSC) colour encoding of the greyscale value. This is
# an approximation, as the values for I and Q are calculated by treating
# the greyscale value as an RGB value. The Y (intensity or brightness)
# value is the same as the greyscale value.
def to_yiq
y = @g
i = (@g * 0.596) + (@g * -0.275) + (@g * -0.321)
q = (@g * 0.212) + (@g * -0.523) + (@g * 0.311)
Color::YIQ.from_fraction(y, i, q)
end
# Returns the HSL colour encoding of the greyscale value.
def to_hsl
Color::HSL.from_fraction(0, 0, @g)
end
# Returns the brightness value for this greyscale value; this is the
# greyscale value itself.
def brightness
@g
end
# Returns the grayscale value as a percentage of white (100% gray is
# white).
def gray
@g * 100.0
end
alias grey gray
# Returns the grayscale value as a fractional value of white in the range
# 0.0 .. 1.0.
def g
@g
end
# Sets the grayscale value as a percentage of white.
def gray=(gg)
@g = Color.normalize(gg / 100.0)
end
alias grey= gray= ;
# Returns the grayscale value as a fractional value of white in the range
# 0.0 .. 1.0.
def g=(gg)
@g = Color.normalize(gg)
end
# Adds another colour to the current colour. The other colour will be
# converted to grayscale before addition. This conversion depends upon a
# #to_grayscale method on the other colour.
#
# The addition is done using the grayscale accessor methods to ensure a
# valid colour in the result.
def +(other)
other = other.to_grayscale
ng = self.dup
ng.g += other.g
ng
end
# Subtracts another colour to the current colour. The other colour will be
# converted to grayscale before subtraction. This conversion depends upon
# a #to_grayscale method on the other colour.
#
# The subtraction is done using the grayscale accessor methods to ensure a
# valid colour in the result.
def -(other)
other = other.to_grayscale
ng = self.dup
ng.g -= other.g
ng
end
def inspect
"Gray [%.2f%%]" % [ gray ]
end
end
# A synonym for Color::GrayScale.
Color::GreyScale = Color::GrayScale
color-1.4.2/lib/color/cmyk.rb 0000644 0000041 0000041 00000020726 12222570513 016046 0 ustar www-data www-data # An CMYK colour object. CMYK (cyan, magenta, yellow, and black) colours are
# based on additive percentages of ink. A CMYK colour of (0.3, 0, 0.8, 0.3)
# would be mixed from 30% cyan, 0% magenta, 80% yellow, and 30% black.
# Primarily used in four-colour printing processes.
class Color::CMYK
# The format of a DeviceCMYK colour for PDF. In color-tools 2.0 this will
# be removed from this package and added back as a modification by the
# PDF::Writer package.
PDF_FORMAT_STR = "%.3f %.3f %.3f %.3f %s"
# Compares the other colour to this one. The other colour will be
# converted to CMYK before comparison, so the comparison between a CMYK
# colour and a non-CMYK colour will be approximate and based on the other
# colour's #to_cmyk conversion. If there is no #to_cmyk conversion, this
# will raise an exception. This will report that two CMYK colours are
# equivalent if all component values are within COLOR_TOLERANCE of each
# other.
def ==(other)
other = other.to_cmyk
other.kind_of?(Color::CMYK) and
((@c - other.c).abs <= Color::COLOR_TOLERANCE) and
((@m - other.m).abs <= Color::COLOR_TOLERANCE) and
((@y - other.y).abs <= Color::COLOR_TOLERANCE) and
((@k - other.k).abs <= Color::COLOR_TOLERANCE)
end
# Creates a CMYK colour object from fractional values 0..1.
#
# Color::CMYK.from_fraction(0.3, 0, 0.8, 0.3)
def self.from_fraction(c = 0, m = 0, y = 0, k = 0)
colour = Color::CMYK.new
colour.c = c
colour.m = m
colour.y = y
colour.k = k
colour
end
# Creates a CMYK colour object from percentages. Internally, the colour is
# managed as fractional values 0..1.
#
# Color::CMYK.new(30, 0, 80, 30)
def self.from_percent(c = 0, m = 0, y = 0, k = 0)
Color::CMYK.new(c, m, y, k)
end
# Creates a CMYK colour object from percentages. Internally, the colour is
# managed as fractional values 0..1.
#
# Color::CMYK.new(30, 0, 80, 30)
def initialize(c = 0, m = 0, y = 0, k = 0)
@c = c / 100.0
@m = m / 100.0
@y = y / 100.0
@k = k / 100.0
end
# Present the colour as a DeviceCMYK fill colour string for PDF. This will
# be removed from the default package in color-tools 2.0.
def pdf_fill
PDF_FORMAT_STR % [ @c, @m, @y, @k, "k" ]
end
# Present the colour as a DeviceCMYK stroke colour string for PDF. This
# will be removed from the default package in color-tools 2.0.
def pdf_stroke
PDF_FORMAT_STR % [ @c, @m, @y, @k, "K" ]
end
# Present the colour as an RGB HTML/CSS colour string (e.g., "#aabbcc").
# Note that this will perform a #to_rgb operation using the default
# conversion formula.
def html
to_rgb.html
end
# Present the colour as an RGB HTML/CSS colour string (e.g., "rgb(0%, 50%,
# 100%)"). Note that this will perform a #to_rgb operation using the
# default conversion formula.
def css_rgb
to_rgb.css_rgb
end
# Present the colour as an RGBA (with alpha) HTML/CSS colour string (e.g.,
# "rgb(0%, 50%, 100%, 1)"). Note that this will perform a #to_rgb
# operation using the default conversion formula.
def css_rgba
to_rgb.css_rgba
end
# Present the colour as an HSL HTML/CSS colour string (e.g., "hsl(180,
# 25%, 35%)"). Note that this will perform a #to_hsl operation using the
# default conversion formula.
def css_hsl
to_hsl.css_hsl
end
# Present the colour as an HSLA (with alpha) HTML/CSS colour string (e.g.,
# "hsla(180, 25%, 35%, 1)"). Note that this will perform a #to_hsl
# operation using the default conversion formula.
def css_hsla
to_hsl.css_hsla
end
# Converts the CMYK colour to RGB. Most colour experts strongly suggest
# that this is not a good idea (some even suggesting that it's a very bad
# idea). CMYK represents additive percentages of inks on white paper,
# whereas RGB represents mixed colour intensities on a black screen.
#
# However, the colour conversion can be done, and there are two different
# methods for the conversion that provide slightly different results.
# Adobe PDF conversions are done with the first form.
#
# # Adobe PDF Display Formula
# r = 1.0 - min(1.0, c + k)
# g = 1.0 - min(1.0, m + k)
# b = 1.0 - min(1.0, y + k)
#
# # Other
# r = 1.0 - (c * (1.0 - k) + k)
# g = 1.0 - (m * (1.0 - k) + k)
# b = 1.0 - (y * (1.0 - k) + k)
#
# If we have a CMYK colour of [33% 66% 83% 25%], the first method will
# give an approximate RGB colour of (107, 23, 0) or #6b1700. The second
# method will give an approximate RGB colour of (128, 65, 33) or #804121.
# Which is correct? Although the colours may seem to be drastically
# different in the RGB colour space, they are very similar colours,
# differing mostly in intensity. The first is a darker, slightly redder
# brown; the second is a lighter brown.
#
# Because of this subtlety, both methods are now offered for conversion.
# The Adobe method is not used by default; to enable it, pass +true+ to
# #to_rgb.
#
# Future versions of Color may offer other conversion mechanisms that
# offer greater colour fidelity, including recognition of ICC colour
# profiles.
def to_rgb(use_adobe_method = false)
if use_adobe_method
r = 1.0 - [1.0, @c + @k].min
g = 1.0 - [1.0, @m + @k].min
b = 1.0 - [1.0, @y + @k].min
else
r = 1.0 - (@c.to_f * (1.0 - @k.to_f) + @k.to_f)
g = 1.0 - (@m.to_f * (1.0 - @k.to_f) + @k.to_f)
b = 1.0 - (@y.to_f * (1.0 - @k.to_f) + @k.to_f)
end
Color::RGB.from_fraction(r, g, b)
end
# Converts the CMYK colour to a single greyscale value. There are
# undoubtedly multiple methods for this conversion, but only a minor
# variant of the Adobe conversion method will be used:
#
# g = 1.0 - min(1.0, 0.299 * c + 0.587 * m + 0.114 * y + k)
#
# This treats the CMY values similarly to YIQ (NTSC) values and then adds
# the level of black. This is a variant of the Adobe version because it
# uses the more precise YIQ (NTSC) conversion values for Y (intensity)
# rather than the approximates provided by Adobe (0.3, 0.59, and 0.11).
def to_grayscale
c = 0.299 * @c.to_f
m = 0.587 * @m.to_f
y = 0.114 * @y.to_f
g = 1.0 - [1.0, c + m + y + @k].min
Color::GrayScale.from_fraction(g)
end
alias to_greyscale to_grayscale
def to_cmyk
self
end
def inspect
"CMYK [%.2f%%, %.2f%%, %.2f%%, %.2f%%]" % [ cyan, magenta, yellow, black ]
end
# Converts to RGB then YIQ.
def to_yiq
to_rgb.to_yiq
end
# Converts to RGB then HSL.
def to_hsl
to_rgb.to_hsl
end
# Returns the cyan (C) component of the CMYK colour as a percentage value.
def cyan
@c * 100.0
end
# Returns the cyan (C) component of the CMYK colour as a value in the
# range 0.0 .. 1.0.
def c
@c
end
# Sets the cyan (C) component of the CMYK colour as a percentage value.
def cyan=(cc)
@c = Color.normalize(cc / 100.0)
end
# Sets the cyan (C) component of the CMYK colour as a value in the range
# 0.0 .. 1.0.
def c=(cc)
@c = Color.normalize(cc)
end
# Returns the magenta (M) component of the CMYK colour as a percentage
# value.
def magenta
@m * 100.0
end
# Returns the magenta (M) component of the CMYK colour as a value in the
# range 0.0 .. 1.0.
def m
@m
end
# Sets the magenta (M) component of the CMYK colour as a percentage value.
def magenta=(mm)
@m = Color.normalize(mm / 100.0)
end
# Sets the magenta (M) component of the CMYK colour as a value in the
# range 0.0 .. 1.0.
def m=(mm)
@m = Color.normalize(mm)
end
# Returns the yellow (Y) component of the CMYK colour as a percentage
# value.
def yellow
@y * 100.0
end
# Returns the yellow (Y) component of the CMYK colour as a value in the
# range 0.0 .. 1.0.
def y
@y
end
# Sets the yellow (Y) component of the CMYK colour as a percentage value.
def yellow=(yy)
@y = Color.normalize(yy / 100.0)
end
# Sets the yellow (Y) component of the CMYK colour as a value in the range
# 0.0 .. 1.0.
def y=(kk)
@y = Color.normalize(kk)
end
# Returns the black (K) component of the CMYK colour as a percentage
# value.
def black
@k * 100.0
end
# Returns the black (K) component of the CMYK colour as a value in the
# range 0.0 .. 1.0.
def k
@k
end
# Sets the black (K) component of the CMYK colour as a percentage value.
def black=(kk)
@k = Color.normalize(kk / 100.0)
end
# Sets the black (K) component of the CMYK colour as a value in the range
# 0.0 .. 1.0.
def k=(kk)
@k = Color.normalize(kk)
end
end
color-1.4.2/lib/color/palette.rb 0000644 0000041 0000041 00000000053 12222570513 016530 0 ustar www-data www-data require 'color'
module Color::Palette
end
color-1.4.2/lib/color/hsl.rb 0000644 0000041 0000041 00000013535 12222570513 015671 0 ustar www-data www-data # An HSL colour object. Internally, the hue (#h), saturation (#s), and
# luminosity/lightness (#l) values are dealt with as fractional values in
# the range 0..1.
class Color::HSL
class << self
# Creates an HSL colour object from fractional values 0..1.
def from_fraction(h = 0.0, s = 0.0, l = 0.0)
colour = Color::HSL.new
colour.h = h
colour.s = s
colour.l = l
colour
end
end
# Compares the other colour to this one. The other colour will be
# converted to HSL before comparison, so the comparison between a HSL
# colour and a non-HSL colour will be approximate and based on the other
# colour's #to_hsl conversion. If there is no #to_hsl conversion, this
# will raise an exception. This will report that two HSL values are
# equivalent if all component values are within Color::COLOR_TOLERANCE of
# each other.
def ==(other)
other = other.to_hsl
other.kind_of?(Color::HSL) and
((@h - other.h).abs <= Color::COLOR_TOLERANCE) and
((@s - other.s).abs <= Color::COLOR_TOLERANCE) and
((@l - other.l).abs <= Color::COLOR_TOLERANCE)
end
# Creates an HSL colour object from the standard values of degrees and
# percentages (e.g., 145 deg, 30%, 50%).
def initialize(h = 0, s = 0, l = 0)
@h = h / 360.0
@s = s / 100.0
@l = l / 100.0
end
# Present the colour as an HTML/CSS colour string.
def html
to_rgb.html
end
# Present the colour as an RGB HTML/CSS colour string (e.g., "rgb(0%, 50%,
# 100%)"). Note that this will perform a #to_rgb operation using the
# default conversion formula.
def css_rgb
to_rgb.css_rgb
end
# Present the colour as an RGBA (with alpha) HTML/CSS colour string (e.g.,
# "rgb(0%, 50%, 100%, 1)"). Note that this will perform a #to_rgb
# operation using the default conversion formula.
def css_rgba
to_rgb.css_rgba
end
# Present the colour as an HSL HTML/CSS colour string (e.g., "hsl(180,
# 25%, 35%)").
def css_hsl
"hsl(%3.2f, %3.2f%%, %3.2f%%)" % [ hue, saturation, luminosity ]
end
# Present the colour as an HSLA (with alpha) HTML/CSS colour string (e.g.,
# "hsla(180, 25%, 35%, 1)").
def css_hsla
"hsla(%3.2f, %3.2f%%, %3.2f%%, %3.2f)" % [ hue, saturation, luminosity, 1 ]
end
# Converting to HSL as adapted from Foley and Van-Dam from
# http://www.bobpowell.net/RGBHSB.htm.
#
# NOTE:
# * If the colour's luminosity is near zero, the colour is always black.
# * If the colour's luminosity is near one, the colour is always white.
# * If the colour's saturation is near zero, the colour is always a shade
# of grey and is based only on the luminosity of the colour.
#
def to_rgb(ignored = nil)
return Color::RGB.new if Color.near_zero_or_less?(@l)
return Color::RGB.new(0xff, 0xff, 0xff) if Color.near_one_or_more?(@l)
return Color::RGB.from_fraction(@l, @l, @l) if Color.near_zero?(@s)
# Is the value less than 0.5?
if Color.near_zero_or_less?(@l - 0.5)
tmp2 = @l * (1.0 + @s.to_f)
else
tmp2 = @l + @s - (@l * @s.to_f)
end
tmp1 = 2.0 * @l - tmp2
tmp3 = [ @h + (1.0 / 3.0), @h, @h - (1.0 / 3.0) ]
rgb = tmp3.map { |hue|
hue += 1.0 if Color.near_zero_or_less?(hue)
hue -= 1.0 if Color.near_one_or_more?(hue)
if Color.near_zero_or_less?((6.0 * hue) - 1.0)
tmp1 + ((tmp2 - tmp1) * hue * 6.0)
elsif Color.near_zero_or_less?((2.0 * hue) - 1.0)
tmp2
elsif Color.near_zero_or_less?((3.0 * hue) - 2.0)
tmp1 + (tmp2 - tmp1) * ((2 / 3.0) - hue) * 6.0
else
tmp1
end
}
Color::RGB.from_fraction(*rgb)
end
# Converts to RGB then YIQ.
def to_yiq
to_rgb.to_yiq
end
# Converts to RGB then CMYK.
def to_cmyk
to_rgb.to_cmyk
end
# Returns the luminosity (#l) of the colour.
def brightness
@l
end
def to_greyscale
Color::GrayScale.from_fraction(@l)
end
alias to_grayscale to_greyscale
# Returns the hue of the colour in degrees.
def hue
@h * 360.0
end
# Returns the hue of the colour in the range 0.0 .. 1.0.
def h
@h
end
# Sets the hue of the colour in degrees. Colour is perceived as a wheel,
# so values should be set properly even with negative degree values.
def hue=(hh)
hh = hh / 360.0
hh += 1.0 if hh < 0.0
hh -= 1.0 if hh > 1.0
@h = Color.normalize(hh)
end
# Sets the hue of the colour in the range 0.0 .. 1.0.
def h=(hh)
@h = Color.normalize(hh)
end
# Returns the percentage of saturation of the colour.
def saturation
@s * 100.0
end
# Returns the saturation of the colour in the range 0.0 .. 1.0.
def s
@s
end
# Sets the percentage of saturation of the colour.
def saturation=(ss)
@s = Color.normalize(ss / 100.0)
end
# Sets the saturation of the colour in the ragne 0.0 .. 1.0.
def s=(ss)
@s = Color.normalize(ss)
end
# Returns the percentage of luminosity of the colour.
def luminosity
@l * 100.0
end
alias lightness luminosity
# Returns the luminosity of the colour in the range 0.0 .. 1.0.
def l
@l
end
# Sets the percentage of luminosity of the colour.
def luminosity=(ll)
@l = Color.normalize(ll / 100.0)
end
alias lightness= luminosity= ;
# Sets the luminosity of the colour in the ragne 0.0 .. 1.0.
def l=(ll)
@l = Color.normalize(ll)
end
def to_hsl
self
end
def inspect
"HSL [%.2f deg, %.2f%%, %.2f%%]" % [ hue, saturation, luminosity ]
end
# Mix the mask colour (which will be converted to an HSL colour) with the
# current colour at the stated mix percentage as a decimal value.
#
# NOTE:: This differs from Color::RGB#mix_with.
def mix_with(color, mix_percent = 0.5)
color = color.to_hsl
_h = ((color.h - self.h) * mix_percent) + self.h
_s = ((color.s - self.s) * mix_percent) + self.s
_l = ((color.l - self.l) * mix_percent) + self.l
self.class.from_fraction(_h, _s, _l)
end
end
color-1.4.2/lib/color/palette/ 0000755 0000041 0000041 00000000000 12222570513 016205 5 ustar www-data www-data color-1.4.2/lib/color/palette/monocontrast.rb 0000644 0000041 0000041 00000013535 12222570513 021267 0 ustar www-data www-data require 'color/palette'
# Generates a monochromatic constrasting colour palette for background and
# foreground. What does this mean?
#
# Monochromatic: A single colour is used to generate the base palette, and
# this colour is lightened five times and darkened five times to provide
# eleven distinct colours.
#
# Contrasting: The foreground is also generated as a monochromatic colour
# palette; however, all generated colours are tested to see that they are
# appropriately contrasting to ensure maximum readability of the foreground
# against the background.
class Color::Palette::MonoContrast
# Hash of CSS background colour values.
#
# This is always 11 values:
#
# 0:: The starting colour.
# +1..+5:: Lighter colours.
# -1..-5:: Darker colours.
attr_reader :background
# Hash of CSS foreground colour values.
#
# This is always 11 values:
#
# 0:: The starting colour.
# +1..+5:: Lighter colours.
# -1..-5:: Darker colours.
attr_reader :foreground
DEFAULT_MINIMUM_BRIGHTNESS_DIFF = (125.0 / 255.0)
# The minimum brightness difference between the background and the
# foreground, and must be between 0..1. Setting this value will regenerate
# the palette based on the base colours. The default value for this is 125
# / 255.0. If this value is set to +nil+, it will be restored to the
# default.
attr_accessor :minimum_brightness_diff
remove_method :minimum_brightness_diff= ;
def minimum_brightness_diff=(bd) #:nodoc:
if bd.nil?
@minimum_brightness_diff = DEFAULT_MINIMUM_BRIGHTNESS_DIFF
elsif bd > 1.0
@minimum_brightness_diff = 1.0
elsif bd < 0.0
@minimum_brightness_diff = 0.0
else
@minimum_brightness_diff = bd
end
regenerate(@background[0], @foreground[0])
end
DEFAULT_MINIMUM_COLOR_DIFF = (500.0 / 255.0)
# The minimum colour difference between the background and the foreground,
# and must be between 0..3. Setting this value will regenerate the palette
# based on the base colours. The default value for this is 500 / 255.0.
attr_accessor :minimum_color_diff
remove_method :minimum_color_diff= ;
def minimum_color_diff=(cd) #:noco:
if cd.nil?
@minimum_color_diff = DEFAULT_MINIMUM_COLOR_DIFF
elsif cd > 3.0
@minimum_color_diff = 3.0
elsif cd < 0.0
@minimum_color_diff = 0.0
else
@minimum_color_diff = cd
end
regenerate(@background[0], @foreground[0])
end
# Generate the initial palette.
def initialize(background, foreground = nil)
@minimum_brightness_diff = DEFAULT_MINIMUM_BRIGHTNESS_DIFF
@minimum_color_diff = DEFAULT_MINIMUM_COLOR_DIFF
regenerate(background, foreground)
end
# Generate the colour palettes.
def regenerate(background, foreground = nil)
foreground ||= background
background = background.to_rgb
foreground = foreground.to_rgb
@background = {}
@foreground = {}
@background[-5] = background.darken_by(10)
@background[-4] = background.darken_by(25)
@background[-3] = background.darken_by(50)
@background[-2] = background.darken_by(75)
@background[-1] = background.darken_by(85)
@background[ 0] = background
@background[+1] = background.lighten_by(85)
@background[+2] = background.lighten_by(75)
@background[+3] = background.lighten_by(50)
@background[+4] = background.lighten_by(25)
@background[+5] = background.lighten_by(10)
@foreground[-5] = calculate_foreground(@background[-5], foreground)
@foreground[-4] = calculate_foreground(@background[-4], foreground)
@foreground[-3] = calculate_foreground(@background[-3], foreground)
@foreground[-2] = calculate_foreground(@background[-2], foreground)
@foreground[-1] = calculate_foreground(@background[-1], foreground)
@foreground[ 0] = calculate_foreground(@background[ 0], foreground)
@foreground[+1] = calculate_foreground(@background[+1], foreground)
@foreground[+2] = calculate_foreground(@background[+2], foreground)
@foreground[+3] = calculate_foreground(@background[+3], foreground)
@foreground[+4] = calculate_foreground(@background[+4], foreground)
@foreground[+5] = calculate_foreground(@background[+5], foreground)
end
# Given a background colour and a foreground colour, modifies the
# foreground colour so that it will have enough contrast to be seen
# against the background colour.
#
# Uses #mininum_brightness_diff and #minimum_color_diff.
def calculate_foreground(background, foreground)
nfg = nil
# Loop through brighter and darker versions of the foreground color. The
# numbers here represent the amount of foreground color to mix with
# black and white.
[100, 75, 50, 25, 0].each do |percent|
dfg = foreground.darken_by(percent)
lfg = foreground.lighten_by(percent)
dbd = brightness_diff(background, dfg)
lbd = brightness_diff(background, lfg)
if lbd > dbd
nfg = lfg
nbd = lbd
else
nfg = dfg
nbd = dbd
end
ncd = color_diff(background, nfg)
break if nbd >= @minimum_brightness_diff and ncd >= @minimum_color_diff
end
nfg
end
# Returns the absolute difference between the brightness levels of two
# colours. This will be a decimal value between 0 and 1. W3C accessibility
# guidelines for colour contrast[http://www.w3.org/TR/AERT#color-contrast]
# suggest that this value be at least approximately 0.49 (125 / 255.0) for
# proper contrast.
def brightness_diff(c1, c2)
(c1.brightness - c2.brightness).abs
end
# Returns the contrast between to colours, a decimal value between 0 and
# 3. W3C accessibility guidelines for colour
# contrast[http://www.w3.org/TR/AERT#color-contrast] suggest that this
# value be at least approximately 1.96 (500 / 255.0) for proper contrast.
def color_diff(c1, c2)
r = (c1.r - c2.r).abs
g = (c1.g - c2.g).abs
b = (c1.b - c2.b).abs
r + g + b
end
end
color-1.4.2/lib/color/palette/gimp.rb 0000644 0000041 0000041 00000005030 12222570513 017464 0 ustar www-data www-data require 'color/palette'
# A class that can read a GIMP (GNU Image Manipulation Program) palette file
# and provide a Hash-like interface to the contents. GIMP colour palettes
# are RGB values only.
#
# Because two or more entries in a GIMP palette may have the same name, all
# named entries are returned as an array.
#
# pal = Color::Palette::Gimp.from_file(my_gimp_palette)
# pal[0] => Color::RGB<...>
# pal["white"] => [ Color::RGB<...> ]
# pal["unknown"] => [ Color::RGB<...>, Color::RGB<...>, ... ]
#
# GIMP Palettes are always indexable by insertion order (an integer key).
class Color::Palette::Gimp
include Enumerable
class << self
# Create a GIMP palette object from the named file.
def from_file(filename)
File.open(filename, "rb") { |io| Color::Palette::Gimp.from_io(io) }
end
# Create a GIMP palette object from the provided IO.
def from_io(io)
Color::Palette::Gimp.new(io.read)
end
end
# Create a new GIMP palette from the palette file as a string.
def initialize(palette)
@colors = []
@names = {}
@valid = false
@name = "(unnamed)"
palette.split($/).each do |line|
line.chomp!
line.gsub!(/\s*#.*\Z/, '')
next if line.empty?
if line =~ /\AGIMP Palette\Z/
@valid = true
next
end
info = /(\w+):\s(.*$)/.match(line)
if info
@name = info.captures[1] if info.captures[0] =~ /name/i
next
end
line.gsub!(/^\s+/, '')
data = line.split(/\s+/, 4)
name = data.pop.strip
data.map! { |el| el.to_i }
color = Color::RGB.new(*data)
@colors << color
@names[name] ||= []
@names[name] << color
end
end
# Provides the colour or colours at the provided selectors.
def values_at(*selectors)
@colors.values_at(*selectors)
end
# If a Numeric +key+ is provided, the single colour value at that position
# will be returned. If a String +key+ is provided, the colour set (an
# array) for that colour name will be returned.
def [](key)
if key.kind_of?(Numeric)
@colors[key]
else
@names[key]
end
end
# Loops through each colour.
def each
@colors.each { |el| yield el }
end
# Loops through each named colour set.
def each_name #:yields color_name, color_set:#
@names.each { |color_name, color_set| yield color_name, color_set }
end
# Returns true if this is believed to be a valid GIMP palette.
def valid?
@valid
end
def size
@colors.size
end
attr_reader :name
end
color-1.4.2/lib/color/palette/adobecolor.rb 0000644 0000041 0000041 00000017614 12222570513 020654 0 ustar www-data www-data require 'color/palette'
# A class that can read an Adobe Color palette file (used for Photoshop
# swatches) and provide a Hash-like interface to the contents. Not all
# colour formats in ACO files are supported. Based largely off the
# information found by Larry Tesler[http://www.nomodes.com/aco.html].
#
# Not all Adobe Color files have named colours; all named entries are
# returned as an array.
#
# pal = Color::Palette::AdobeColor.from_file(my_aco_palette)
# pal[0] => Color::RGB<...>
# pal["white"] => [ Color::RGB<...> ]
# pal["unknown"] => [ Color::RGB<...>, Color::RGB<...>, ... ]
#
# AdobeColor palettes are always indexable by insertion order (an integer
# key).
#
# Version 2 palettes use UTF-16 colour names.
class Color::Palette::AdobeColor
include Enumerable
class << self
# Create an AdobeColor palette object from the named file.
def from_file(filename)
File.open(filename, "rb") { |io| Color::Palette::AdobeColor.from_io(io) }
end
# Create an AdobeColor palette object from the provided IO.
def from_io(io)
Color::Palette::AdobeColor.new(io.read)
end
end
# Returns statistics about the nature of the colours loaded.
attr_reader :statistics
# Contains the "lost" colours in the palette. These colours could not be
# properly loaded (e.g., L*a*b* is not supported by Color, so it is
# "lost") or are not understood by the algorithms.
attr_reader :lost
# Use this to convert the unsigned word to the signed word, if necessary.
UwToSw = proc { |n| (n >= (2 ** 16)) ? n - (2 ** 32) : n } #:nodoc:
# Create a new AdobeColor palette from the palette file as a string.
def initialize(palette)
@colors = []
@names = {}
@statistics = Hash.new(0)
@lost = []
@order = []
@version = nil
class << palette
def readwords(count = 1)
@offset ||= 0
raise IndexError if @offset >= self.size
val = self[@offset, count * 2]
raise IndexError if val.nil? or val.size < (count * 2)
val = val.unpack("n" * count)
@offset += count * 2
val
end
def readutf16(count = 1)
@offset ||= 0
raise IndexError if @offset >= self.size
val = self[@offset, count * 2]
raise IndexError if val.nil? or val.size < (count * 2)
@offset += count * 2
val
end
end
@version, count = palette.readwords 2
raise "Unknown AdobeColor palette version #@version." unless @version.between?(1, 2)
count.times do
space, w, x, y, z = palette.readwords 5
name = nil
if @version == 2
raise IndexError unless palette.readwords == [ 0 ]
len = palette.readwords
name = palette.readutf16(len[0] - 1)
raise IndexError unless palette.readwords == [ 0 ]
end
color = case space
when 0 then # RGB
@statistics[:rgb] += 1
Color::RGB.new(w / 256, x / 256, y / 256)
when 1 then # HS[BV] -- Convert to RGB
@statistics[:hsb] += 1
h = w / 65535.0
s = x / 65535.0
v = y / 65535.0
if defined?(Color::HSB)
Color::HSB.from_fraction(h, s, v)
else
@statistics[:converted] += 1
if Color.near_zero_or_less?(s)
Color::RGB.from_fraction(v, v, v)
else
if Color.near_one_or_more?(h)
vh = 0
else
vh = h * 6.0
end
vi = vh.floor
v1 = v.to_f * (1 - s.to_f)
v2 = v.to_f * (1 - s.to_f * (vh - vi))
v3 = v.to_f * (1 - s.to_f * (1 - (vh - vi)))
case vi
when 0 then Color::RGB.from_fraction(v, v3, v1)
when 1 then Color::RGB.from_fraction(v2, v, v1)
when 2 then Color::RGB.from_fraction(v1, v, v3)
when 3 then Color::RGB.from_fraction(v1, v2, v)
when 4 then Color::RGB.from_fraction(v3, v1, v)
else Color::RGB.from_fraction(v, v1, v2)
end
end
end
when 2 then # CMYK
@statistics[:cmyk] += 1
Color::CMYK.from_percent(100 - (w / 655.35),
100 - (x / 655.35),
100 - (y / 655.35),
100 - (z / 655.35))
when 7 then # L*a*b*
@statistics[:lab] += 1
l = [w, 10000].min / 100.0
a = [[-12800, UwToSw[x]].max, 12700].min / 100.0
b = [[-12800, UwToSw[x]].max, 12700].min / 100.0
if defined? Color::Lab
Color::Lab.new(l, a, b)
else
[ space, w, x, y, z ]
end
when 8 then # Grayscale
@statistics[:gray] += 1
g = [w, 10000].min / 100.0
Color::GrayScale.new(g)
when 9 then # Wide CMYK
@statistics[:wcmyk] += 1
c = [w, 10000].min / 100.0
m = [x, 10000].min / 100.0
y = [y, 10000].min / 100.0
k = [z, 10000].min / 100.0
Color::CMYK.from_percent(c, m, y, k)
else
@statistics[space] += 1
[ space, w, x, y, z ]
end
@order << [ color, name ]
if color.kind_of? Array
@lost << color
else
@colors << color
if name
@names[name] ||= []
@names[name] << color
end
end
end
end
# Provides the colour or colours at the provided selectors.
def values_at(*selectors)
@colors.values_at(*selectors)
end
# If a Numeric +key+ is provided, the single colour value at that position
# will be returned. If a String +key+ is provided, the colour set (an
# array) for that colour name will be returned.
def [](key)
if key.kind_of?(Numeric)
@colors[key]
else
@names[key]
end
end
# Loops through each colour.
def each
@colors.each { |el| yield el }
end
# Loops through each named colour set.
def each_name #:yields color_name, color_set:#
@names.each { |color_name, color_set| yield color_name, color_set }
end
def size
@colors.size
end
attr_reader :version
def to_aco(version = @version) #:nodoc:
res = ""
res << [ version, @order.size ].pack("nn")
@order.each do |cnpair|
color, name = *cnpair
# Note: HSB and CMYK formats are lost by the conversions performed on
# import. They are turned into RGB and WCMYK, respectively.
cstr = case color
when Array
color
when Color::RGB
r = [(color.red * 256).round, 65535].min
g = [(color.green * 256).round, 65535].min
b = [(color.blue * 256).round, 65535].min
[ 0, r, g, b, 0 ]
when Color::GrayScale
g = [(color.gray * 100).round, 10000].min
[ 8, g, 0, 0, 0 ]
when Color::CMYK
c = [(color.cyan * 100).round, 10000].min
m = [(color.magenta * 100).round, 10000].min
y = [(color.yellow * 100).round, 10000].min
k = [(color.black * 100).round, 10000].min
[ 9, c, m, y, k ]
end
cstr = cstr.pack("nnnnn")
nstr = ""
if version == 2
if (name.size / 2 * 2) == name.size # only where s[0] == byte!
nstr << [ 0, (name.size / 2) + 1 ].pack("nn")
nstr << name
nstr << [ 0 ].pack("n")
else
nstr << [ 0, 1, 0 ].pack("nnn")
end
end
res << cstr << nstr
end
res
end
end
color-1.4.2/lib/color/yiq.rb 0000644 0000041 0000041 00000003165 12222570513 015703 0 ustar www-data www-data # A colour object representing YIQ (NTSC) colour encoding.
class Color::YIQ
# Creates a YIQ colour object from fractional values 0 .. 1.
#
# Color::YIQ.new(0.3, 0.2, 0.1)
def self.from_fraction(y = 0, i = 0, q = 0)
color = Color::YIQ.new
color.y = y
color.i = i
color.q = q
color
end
# Creates a YIQ colour object from percentages 0 .. 100.
#
# Color::YIQ.new(10, 20, 30)
def initialize(y = 0, i = 0, q = 0)
@y = y / 100.0
@i = i / 100.0
@q = q / 100.0
end
# Compares the other colour to this one. The other colour will be
# converted to YIQ before comparison, so the comparison between a YIQ
# colour and a non-YIQ colour will be approximate and based on the other
# colour's #to_yiq conversion. If there is no #to_yiq conversion, this
# will raise an exception. This will report that two YIQ values are
# equivalent if all component colours are within COLOR_TOLERANCE of each
# other.
def ==(other)
other = other.to_yiq
other.kind_of?(Color::YIQ) and
((@y - other.y).abs <= Color::COLOR_TOLERANCE) and
((@i - other.i).abs <= Color::COLOR_TOLERANCE) and
((@q - other.q).abs <= Color::COLOR_TOLERANCE)
end
def to_yiq
self
end
def brightness
@y
end
def to_grayscale
Color::GrayScale.new(@y)
end
alias to_greyscale to_grayscale
def y
@y
end
def y=(yy)
@y = Color.normalize(yy)
end
def i
@i
end
def i=(ii)
@i = Color.normalize(ii)
end
def q
@q
end
def q=(qq)
@q = Color.normalize(qq)
end
def inspect
"YIQ [%.2f%%, %.2f%%, %.2f%%]" % [ @y * 100, @i * 100, @q * 100 ]
end
end