color-1.8/0000755000004100000410000000000012620676731012542 5ustar www-datawww-datacolor-1.8/Rakefile0000644000004100000410000000414212620676731014210 0ustar www-datawww-data# -*- ruby -*- require 'rubygems' require 'hoe' require 'rake/clean' Hoe.plugin :doofus Hoe.plugin :gemspec2 Hoe.plugin :git Hoe.plugin :minitest Hoe.plugin :travis Hoe.plugin :email unless ENV['CI'] or ENV['TRAVIS'] spec = Hoe.spec 'color' do developer('Austin Ziegler', 'halostatue@gmail.com') developer('Matt Lyon', 'matt@postsomnia.com') license 'MIT' self.history_file = 'History.rdoc' self.readme_file = 'README.rdoc' extra_dev_deps << ['hoe-doofus', '~> 1.0'] extra_dev_deps << ['hoe-gemspec2', '~> 1.1'] extra_dev_deps << ['hoe-git', '~> 1.6'] extra_dev_deps << ['hoe-travis', '~> 1.2'] extra_dev_deps << ['minitest', '~> 5.8'] extra_dev_deps << ['minitest-around', '~> 0.3'] extra_dev_deps << ['minitest-autotest', '~> 1.0'] extra_dev_deps << ['minitest-bisect', '~> 1.2'] extra_dev_deps << ['minitest-focus', '~> 1.1'] extra_dev_deps << ['minitest-moar', '~> 0.0'] extra_dev_deps << ['minitest-pretty_diff', '~> 0.1'] extra_dev_deps << ['rake', '~> 10.0'] if RUBY_VERSION >= '1.9' extra_dev_deps << ['simplecov', '~> 0.7'] extra_dev_deps << ['coveralls', '~> 0.7'] if ENV['CI'] or ENV['TRAVIS'] end end if RUBY_VERSION >= '1.9' namespace :test do if ENV['CI'] or ENV['TRAVIS'] desc "Submit test coverage to Coveralls" task :coveralls do spec.test_prelude = [ 'require "psych"', 'require "simplecov"', 'require "coveralls"', 'SimpleCov.formatter = Coveralls::SimpleCov::Formatter', 'SimpleCov.start("test_frameworks") { command_name "Minitest" }', 'gem "minitest"' ].join('; ') Rake::Task['test'].execute end Rake::Task['travis'].prerequisites.replace(%w(test:coveralls)) end desc "Runs test coverage. Only works Ruby 1.9+ and assumes 'simplecov' is installed." task :coverage do spec.test_prelude = [ 'require "simplecov"', 'SimpleCov.start("test_frameworks") { command_name "Minitest" }', 'gem "minitest"' ].join('; ') Rake::Task['test'].execute end CLOBBER << 'coverage' end end # vim: syntax=ruby color-1.8/.hoerc0000644000004100000410000000016112620676731013641 0ustar www-datawww-data--- exclude: !ruby/regexp /(tmp|swp)$|CVS|TAGS|\.(svn|git|hg|DS_Store|idea)|Gemfile\.lock|research\/|\.gemspec$/ color-1.8/.gemtest0000644000004100000410000000000012620676731014201 0ustar www-datawww-datacolor-1.8/Manifest.txt0000644000004100000410000000130012620676731015043 0ustar www-datawww-data.autotest .coveralls.yml .gemtest .hoerc .minitest.rb .travis.yml Code-of-Conduct.rdoc Contributing.rdoc Gemfile 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.rb lib/color/rgb/colors.rb lib/color/rgb/contrast.rb lib/color/rgb/metallic.rb lib/color/yiq.rb test/minitest_helper.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.8/Gemfile0000644000004100000410000000024612620676731014037 0ustar www-datawww-data# -*- ruby -*- # NOTE: This file is present to keep Travis CI happy. Edits to it will not # be accepted. source "https://rubygems.org/" gemspec # vim: syntax=ruby color-1.8/Contributing.rdoc0000644000004100000410000000413112620676731016061 0ustar www-datawww-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. * Dave Heitzman (contrast comparison) * Thomas Sawyer * Aaron Hill (CIE94 colour matching) * Luke Bennellick * Matthew Draper color-1.8/.coveralls.yml0000644000004100000410000000003412620676731015332 0ustar www-datawww-data--- service_name: travis-ci color-1.8/.autotest0000644000004100000410000000014512620676731014413 0ustar www-datawww-data# -*- ruby encoding: utf-8 -*- Autotest.add_hook :initialize do |at| at.testlib = ".minitest" end color-1.8/Code-of-Conduct.rdoc0000644000004100000410000000370212620676731016266 0ustar www-datawww-data== Contributor Code of Conduct As contributors and maintainers of this project, and in the interest of fostering an open and welcoming community, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities. We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, religion, or nationality. Examples of unacceptable behavior by participants include: * The use of sexualized language or imagery * Personal attacks * Trolling or insulting/derogatory comments * Public or private harassment * Publishing other's private information, such as physical or electronic addresses, without explicit permission * Other unethical or unprofessional conduct. Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. By adopting this Code of Conduct, project maintainers commit themselves to fairly and consistently applying these principles to every aspect of managing this project. Project maintainers who do not follow or enforce the Code of Conduct may be permanently removed from the project team. This code of conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers. This Code of Conduct is adapted from the {Contributor Covenant}[http://contributor-covenant.org], version 1.2.0, available at {http://contributor-covenant.org/version/1/2/0/}[http://contributor-covenant.org/version/1/2/0/]. color-1.8/History.rdoc0000644000004100000410000002037112620676731015057 0ustar www-datawww-data== 1.8 / 2015-10-26 * 1 minor enhancement: * Add an optional +alpha+ parameter to all #css_rgba calls. Thanks to Luke Bennellick (@bennell) and Alexander Popov (@AlexWayfer) for independently implemented submissions. Merged from #15. * 2 minor bug fixes: * Improve constant detection to prevent incorrectly identified name collisions with various other libraries such as Azure deployment tools. Based on work by Matthew Draper (@matthewd) in #24. * Prevent Color.equivalent? comparisons from using non-Color types for comparison. Fix provided by Benjamin Guest (@bguest) in #18. * 1 governance change * This project now has a {Code of Conduct}[Code-of-Conduct_rdoc.html] == 1.7.1 / 2014-06-12 * Minor enhancements: * Renamed Color::RGB::BeccaPurple to Color::RGB::RebeccaPurple as stipulated by Eric Meyer. http://meyerweb.com/eric/thoughts/2014/06/19/rebeccapurple/ For purposes of backwards compatibility, the previous name is still permitted, but its use is strongly discouraged, and it will be removed in the Color 2.0 release. == 1.7 / 2014-06-12 * Minor enhancements: * Added Color::RGB::BeccaPurple (#663399) in honour of Rebecca Meyer, the daughter of Eric Meyer, who passed away on the 7th of June, 2014. Her favourite colour was purple. #663399becca https://twitter.com/meyerweb/status/476089708674428929 http://www.zeldman.com/2014/06/10/the-color-purple/ http://discourse.specifiction.org/t/name-663399-becca-purple-in-css4-color/225 * Bug fixes: * Changed the homepage in the gem to point to github.com instead of RubyForge, which has been shut down. Fixes #10, reported by @voxik. == 1.6 / 2014-05-19 * Major enhancements: * Aaron Hill (@armahillo) implemented the CIE Delta E 94 method by which an RGB colour can be asked for the closest matching colour from a list of provided colours. Fixes #5. * To implement #closest_match and #delta_e94, conversion methods for sRGB to XYZ and XYZ to L*a*b* space were implemented. These should be considered experimental. * Tooling fixes: * Ensured that the gem manifest was up-to-date. Fixes #4 reported by @boutil. Thanks! * Fixed problems with Travis builds. Note that Ruby 1.9.2 is no longer tested. Rubinius remains in a “failure-tolerated” mode. * Color 1.6 is, barring security patches, the last release of Color that will support Ruby 1.8. == 1.5.1 / 2014-01-28 * color 1.5 was a yanked release. * Minor enhancements: * Added new methods to Color::RGB to make it so that the default defined colours can be looked up by hex, name, or both. * Added a method to Color::RGB to extract colours from text by hex, name, or both. * Added new common methods for colour names. Converted colours do not retain names. * Restructured color comparisons to use protocols instead of custom implementations. This makes it easier to implement new colour classes. To make this work, color classes should +include+ Color only need to implement #coerce(other), #to_a, and supported conversion methods (e.g., #to_rgb). * Added @daveheitzman’s initial implementation of an RGB contrast method as an extension file: require 'color/rgb/contrast'. This method and the value it returns should be considered experimental; it requires further examination to ensure that the results produced are consistent with the contrast comparisons used in Color::Palette::MonoContrast. * Reducing duplicated code. * Bug Fixes: * Moved +lib/color/rgb-colors.rb+ to +lib/color/rgb/colors.rb+. This should have no impact in general. * Improved the way that named colors are specified internally. * Fixed bugs with Ruby 1.8.7 that may have been introduced in color 1.4.2. * Tooling Changes: * Added simplecov for test coverage analysis. * Modernized Travis CI support. == 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.8/Licence.rdoc0000644000004100000410000000245012620676731014756 0ustar www-datawww-data== Licence This software is available under an MIT-style licence. * Copyright 2005–2014 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.8/README.rdoc0000644000004100000410000000460212620676731014352 0ustar www-datawww-data= Color home :: https://github.com/halostatue/color code :: https://github.com/halostatue/color bugs :: https://github.com/halostatue/color/issues rdoc :: http://rubydoc.info/github/halostatue/color continuous integration :: {}[https://travis-ci.org/halostatue/color] test coverage :: {Coverage Status}[https://coveralls.io/r/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 Color library performs purely 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 RGB and HSL colour spaces, this won't matter. Absolute colour spaces (like CIE L*a*b* and XYZ) and cannot be reliably converted to relative colour spaces (like RGB) without colour profiles. Color 1.8 adds an alpha parameter to all #css_rgba calls, fixes a bug exposed by new constant lookup semantics in Ruby 2, and ensures that Color.equivalent? can only be called on Color instances. Barring bugs introduced in this release, this (really) is the last version of color that supports Ruby 1.8, so make sure that your gem specification is set properly (to ~> 1.8) if that matters for your application. This version will no longer be supported one year after the release of color 2.0. == 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: Code-of-Conduct.rdoc :include: Contributing.rdoc :include: Licence.rdoc color-1.8/.travis.yml0000644000004100000410000000116212620676731014653 0ustar www-datawww-data--- language: ruby rvm: - 2.2.3 - 2.1.7 - 2.0.0-p647 - ruby-head - jruby-9.0 - jruby-head - rbx-2 - jruby-19mode - 1.9.3 - 1.8.7 - jruby-18mode - ree matrix: allow_failures: - rvm: 1.9.3 - rvm: rbx-2 - rvm: jruby-head - rvm: ruby-head gemfile: - Gemfile before_script: - | case "${TRAVIS_RUBY_VERSION}" in rbx*) gem install psych ;; esac - rake travis:before -t script: rake travis after_script: - rake travis:after -t notifications: email: recipients: - halostatue@gmail.com on_success: change on_failure: always sudo: false color-1.8/lib/0000755000004100000410000000000012620676731013310 5ustar www-datawww-datacolor-1.8/lib/color.rb0000644000004100000410000001251512620676731014757 0ustar www-datawww-data# :title: Color -- Colour Management with Ruby # :main: README.rdoc # = Colour Management with Ruby module Color COLOR_VERSION = '1.8' class RGB; end class CMYK; end class HSL; 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 # Compares the +other+ colour to this one. The +other+ colour will be # coerced to the same type as the current colour. Such converted colour # comparisons will always be more approximate than non-converted # comparisons. # # If the +other+ colour cannot be coerced to the current colour class, a # +NoMethodError+ exception will be raised. # # All values are compared as floating-point values, so two colours will be # reported equivalent if all component values are within COLOR_TOLERANCE # of each other. def ==(other) Color.equivalent?(self, other) end # The primary name for the colour. def name names.first end # All names for the colour. def names self.names = nil unless defined? @names @names end def names=(n) # :nodoc: @names = Array(n).flatten.compact.map(&:to_s).map(&:downcase).sort.uniq end alias_method :name=, :names= end class << Color # Returns +true+ if the value is less than COLOR_EPSILON. def near_zero?(value) (value.abs <= Color::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 # Returns +true+ if the two values provided are near each other. def near?(x, y) (x - y).abs <= Color::COLOR_TOLERANCE end # Returns +true+ if the two colours are roughly equivalent. If colour # conversions are required, this all conversions will be implemented # using the default conversion mechanism. def equivalent?(a, b) return false unless a.kind_of?(Color) && b.kind_of?(Color) a.to_a.zip(a.coerce(b).to_a).all? { |(x, y)| near?(x, y) } end # Coerces, if possible, the second given colour object to the first # given colour object type. This will probably involve colour # conversion and therefore a loss of fidelity. def coerce(a, b) a.coerce(b) 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 # Normalizes the value to the specified range. 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 require 'color/rgb' require 'color/cmyk' require 'color/grayscale' require 'color/hsl' require 'color/yiq' require 'color/css' class << Color def 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 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.8/lib/color/0000755000004100000410000000000012620676731014426 5ustar www-datawww-datacolor-1.8/lib/color/cmyk.rb0000644000004100000410000002001512620676731015714 0ustar www-datawww-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 include Color # 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" # Coerces the other Color object into CMYK. def coerce(other) other.to_cmyk end class << self # Creates a CMYK colour object from fractional values 0..1. # # Color::CMYK.from_fraction(0.3, 0, 0.8, 0.3) def from_fraction(c = 0, m = 0, y = 0, k = 0, &block) new(c, m, y, k, 1.0, &block) 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 from_percent(c = 0, m = 0, y = 0, k = 0, &block) new(c, m, y, k, &block) end 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, radix = 100.0, &block) # :yields self: @c, @m, @y, @k = [ c, m, y, k ].map { |v| Color.normalize(v / radix) } block.call(self) if block 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(alpha = 1) to_rgb.css_rgba(alpha) 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 Color::RGB.from_fraction(*adobe_cmyk_rgb) else Color::RGB.from_fraction(*standard_cmyk_rgb) end 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 def to_a [ c, m, y, k ] end private # Implements the Adobe PDF conversion of CMYK to RGB. def adobe_cmyk_rgb [ @c, @m, @y ].map { |v| 1.0 - [ 1.0, v + @k ].min } end # Implements the standard conversion of CMYK to RGB. def standard_cmyk_rgb [ @c, @m, @y ].map { |v| 1.0 - (v * (1.0 - k) + k) } end end color-1.8/lib/color/hsl.rb0000644000004100000410000001554112620676731015547 0ustar www-datawww-data# -*- ruby encoding: utf-8 -*- # 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 include Color class << self # Creates an HSL colour object from fractional values 0..1. def from_fraction(h = 0.0, s = 0.0, l = 0.0, &block) new(h, s, l, 1.0, 1.0, &block) end end # Coerces the other Color object into HSL. def coerce(other) other.to_hsl 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, radix1 = 360.0, radix2 = 100.0, &block) # :yields self: @h = Color.normalize(h / radix1) @s = Color.normalize(s / radix2) @l = Color.normalize(l / radix2) block.call if block 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(alpha = 1) to_rgb.css_rgba(alpha) 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 from HSL to RGB. As with all colour conversions, this is # approximate at best. The code here is adapted from fvd and van Dam, # originally found at [1] (implemented similarly at [2]). # # This simplifies the calculations with the following assumptions: # - Luminance values <= 0 always translate to Color::RGB::Black. # - Luminance values >= 1 always translate to Color::RGB::White. # - Saturation values <= 0 always translate to a shade of gray using # luminance as a percentage of gray. # # [1] http://bobpowell.net/RGBHSB.aspx # [2] http://support.microsoft.com/kb/29240 def to_rgb(*) if Color.near_zero_or_less?(l) Color::RGB::Black elsif Color.near_one_or_more?(l) Color::RGB::White elsif Color.near_zero?(s) Color::RGB.from_grayscale_fraction(l) else # Only needed for Ruby 1.8. For Ruby 1.9+, we can do: # Color::RGB.new(*compute_fvd_rgb, 1.0) Color::RGB.new(*(compute_fvd_rgb + [ 1.0 ])) end 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) v = to_a.zip(coerce(color).to_a).map { |(x, y)| ((y - x) * mix_percent) + x } self.class.from_fraction(*v) end def to_a [ h, s, l ] end private # This algorithm calculates based on a mixture of the saturation and # luminance, and then takes the RGB values from the hue + 1/3, hue, and # hue - 1/3 positions in a circular representation of colour divided into # four parts (confusing, I know, but it's the way that it works). See # #hue_to_rgb for more information. def compute_fvd_rgb t1, t2 = fvd_mix_sat_lum [ h + (1 / 3.0), h, h - (1 / 3.0) ].map { |v| hue_to_rgb(rotate_hue(v), t1, t2) } end # Mix saturation and luminance for use in hue_to_rgb. The base value is # different depending on whether luminance is <= 50% or > 50%. def fvd_mix_sat_lum t = if Color.near_zero_or_less?(l - 0.5) l * (1.0 + s.to_f) else l + s - (l * s.to_f) end [ 2.0 * l - t, t ] end # In HSL, hues are referenced as degrees in a colour circle. The flow # itself is endless; therefore, we can rotate around. The only thing our # implementation restricts is that you should not be > 1.0. def rotate_hue(h) h += 1.0 if Color.near_zero_or_less?(h) h -= 1.0 if Color.near_one_or_more?(h) h end # We calculate the interaction of the saturation/luminance mix (calculated # earlier) based on the position of the hue in the circular colour space # divided into quadrants. Our hue range is [0, 1), not [0, 360º). # # - The first quadrant covers the first 60º [0, 60º]. # - The second quadrant covers the next 120º (60º, 180º]. # - The third quadrant covers the next 60º (180º, 240º]. # - The fourth quadrant covers the final 120º (240º, 360º). def hue_to_rgb(h, t1, t2) if Color.near_zero_or_less?((6.0 * h) - 1.0) t1 + ((t2 - t1) * h * 6.0) elsif Color.near_zero_or_less?((2.0 * h) - 1.0) t2 elsif Color.near_zero_or_less?((3.0 * h) - 2.0) t1 + (t2 - t1) * ((2 / 3.0) - h) * 6.0 else t1 end end end color-1.8/lib/color/grayscale.rb0000644000004100000410000001222212620676731016724 0ustar www-datawww-data# A colour object representing shades of grey. Used primarily in PDF # document creation. class Color::GrayScale include Color # 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" class << self # Creates a greyscale colour object from fractional values 0..1. # # Color::GreyScale.from_fraction(0.5) def from_fraction(g = 0, &block) new(g, 1.0, &block) end # Creates a greyscale colour object from percentages 0..100. # # Color::GrayScale.from_percent(50) def from_percent(g = 0, &block) new(g, &block) end end # Creates a greyscale colour object from percentages 0..100. # # Color::GrayScale.new(50) def initialize(g = 0, radix = 100.0, &block) # :yields self: @g = Color.normalize(g / radix) block.call if block end # Coerces the other Color object to grayscale. def coerce(other) other.to_grayscale 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(alpha = 1) "rgba(%3.2f%%, %3.2f%%, %3.2f%%, %1.2f)" % [ gray, gray, gray, alpha ] 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) self.class.from_fraction(g + other.to_grayscale.g) 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) self + (-other) end def inspect "Gray [%.2f%%]" % [ gray ] end def to_a [ g ] end def -@ gs = self.dup gs.instance_variable_set(:@g, -g) gs end end # A synonym for Color::GrayScale. Color::GreyScale = Color::GrayScale color-1.8/lib/color/rgb/0000755000004100000410000000000012620676731015200 5ustar www-datawww-datacolor-1.8/lib/color/rgb/metallic.rb0000644000004100000410000000144512620676731017323 0ustar www-datawww-data# -*- ruby encoding: utf-8 -*- class Color::RGB # This namespace contains some RGB metallic colours suggested by Jim # Freeze. module Metallic; end class << self private def metallic(rgb, *names) __named_color(Metallic, new(*rgb), *names) end end metallic [0x99, 0x99, 0x99], :Aluminum metallic [0xd9, 0x87, 0x19], :CoolCopper metallic [0xb8, 0x73, 0x33], :Copper metallic [0x4c, 0x4c, 0x4c], :Iron metallic [0x19, 0x19, 0x19], :Lead metallic [0xb3, 0xb3, 0xb3], :Magnesium metallic [0xe6, 0xe6, 0xe6], :Mercury metallic [0x80, 0x80, 0x80], :Nickel metallic [0x60, 0x00, 0x00], :PolySilicon, :Poly metallic [0xcc, 0xcc, 0xcc], :Silver metallic [0x66, 0x66, 0x66], :Steel metallic [0x7f, 0x7f, 0x7f], :Tin metallic [0x33, 0x33, 0x33], :Tungsten end color-1.8/lib/color/rgb/colors.rb0000644000004100000410000001473512620676731017040 0ustar www-datawww-dataclass Color::RGB class << self private def named(rgb, *names) __named_color(self, new(*rgb), *names) end end named [0xf0, 0xf8, 0xff], :AliceBlue named [0xfa, 0xeb, 0xd7], :AntiqueWhite named [0x00, 0xff, 0xff], :Aqua named [0x7f, 0xff, 0xd4], :Aquamarine named [0xf0, 0xff, 0xff], :Azure named [0xf5, 0xf5, 0xdc], :Beige named [0xff, 0xe4, 0xc4], :Bisque named [0x66, 0x33, 0x99], :RebeccaPurple, :BeccaPurple named [0x00, 0x00, 0x00], :Black named [0xff, 0xeb, 0xcd], :BlanchedAlmond named [0x00, 0x00, 0xff], :Blue named [0x8a, 0x2b, 0xe2], :BlueViolet named [0xa5, 0x2a, 0x2a], :Brown named [0xde, 0xb8, 0x87], :BurlyWood, :Burlywood named [0x5f, 0x9e, 0xa0], :CadetBlue named [0xff, 0x5e, 0xd0], :Carnation named [0x8d, 0x00, 0x00], :Cayenne named [0x7f, 0xff, 0x00], :Chartreuse named [0xd2, 0x69, 0x1e], :Chocolate named [0xff, 0x7f, 0x50], :Coral named [0x64, 0x95, 0xed], :CornflowerBlue named [0xff, 0xf8, 0xdc], :Cornsilk named [0xdc, 0x14, 0x3c], :Crimson named [0x00, 0xff, 0xff], :Cyan named [0x00, 0x00, 0x8b], :DarkBlue named [0x00, 0x8b, 0x8b], :DarkCyan named [0xb8, 0x86, 0x0b], :DarkGoldenRod, :DarkGoldenrod named [0xa9, 0xa9, 0xa9], :DarkGray, :DarkGrey named [0x00, 0x64, 0x00], :DarkGreen named [0xbd, 0xb7, 0x6b], :DarkKhaki named [0x8b, 0x00, 0x8b], :DarkMagenta named [0x55, 0x6b, 0x2f], :DarkOliveGreen, :DarkoliveGreen named [0xff, 0x8c, 0x00], :DarkOrange named [0x99, 0x32, 0xcc], :DarkOrchid named [0x8b, 0x00, 0x00], :DarkRed named [0xe9, 0x96, 0x7a], :DarkSalmon, :Darksalmon named [0x8f, 0xbc, 0x8f], :DarkSeaGreen named [0x48, 0x3d, 0x8b], :DarkSlateBlue named [0x2f, 0x4f, 0x4f], :DarkSlateGray, :DarkSlateGrey named [0x00, 0xce, 0xd1], :DarkTurquoise named [0x94, 0x00, 0xd3], :DarkViolet named [0xff, 0x8c, 0x00], :Darkorange named [0xff, 0x14, 0x93], :DeepPink named [0x00, 0xbf, 0xbf], :DeepSkyBlue named [0x69, 0x69, 0x69], :DimGray, :DimGrey named [0x1e, 0x90, 0xff], :DodgerBlue named [0xd1, 0x92, 0x75], :Feldspar named [0xb2, 0x22, 0x22], :FireBrick, :Firebrick named [0xff, 0xfa, 0xf0], :FloralWhite named [0x22, 0x8b, 0x22], :ForestGreen named [0xff, 0x00, 0xff], :Fuchsia named [0xdc, 0xdc, 0xdc], :Gainsboro named [0xf8, 0xf8, 0xff], :GhostWhite named [0xff, 0xd7, 0x00], :Gold named [0xda, 0xa5, 0x20], :GoldenRod, :Goldenrod named [0x80, 0x80, 0x80], :Gray, :Grey named [10, 10, 10, 100.0], :Gray10, :Grey10 named [20, 20, 20, 100.0], :Gray20, :Grey20 named [30, 30, 30, 100.0], :Gray30, :Grey30 named [40, 40, 40, 100.0], :Gray40, :Grey40 named [50, 50, 50, 100.0], :Gray50, :Grey50 named [60, 60, 60, 100.0], :Gray60, :Grey60 named [70, 70, 70, 100.0], :Gray70, :Grey70 named [80, 80, 80, 100.0], :Gray80, :Grey80 named [90, 90, 90, 100.0], :Gray90, :Grey90 named [0x00, 0x80, 0x00], :Green named [0xad, 0xff, 0x2f], :GreenYellow named [0xf0, 0xff, 0xf0], :HoneyDew, :Honeydew named [0xff, 0x69, 0xb4], :HotPink named [0xcd, 0x5c, 0x5c], :IndianRed named [0x4b, 0x00, 0x82], :Indigo named [0xff, 0xff, 0xf0], :Ivory named [0xf0, 0xe6, 0x8c], :Khaki named [0xe6, 0xe6, 0xfa], :Lavender named [0xff, 0xf0, 0xf5], :LavenderBlush named [0x7c, 0xfc, 0x00], :LawnGreen named [0xff, 0xfa, 0xcd], :LemonChiffon named [0xad, 0xd8, 0xe6], :LightBlue named [0xf0, 0x80, 0x80], :LightCoral named [0xe0, 0xff, 0xff], :LightCyan named [0xfa, 0xfa, 0xd2], :LightGoldenRodYellow, :LightGoldenrodYellow named [0xd3, 0xd3, 0xd3], :LightGray, :LightGrey named [0x90, 0xee, 0x90], :LightGreen named [0xff, 0xb6, 0xc1], :LightPink named [0xff, 0xa0, 0x7a], :LightSalmon, :Lightsalmon named [0x20, 0xb2, 0xaa], :LightSeaGreen named [0x87, 0xce, 0xfa], :LightSkyBlue named [0x84, 0x70, 0xff], :LightSlateBlue named [0x77, 0x88, 0x99], :LightSlateGray, :LightSlateGrey named [0xb0, 0xc4, 0xde], :LightSteelBlue, :LightsteelBlue named [0xff, 0xff, 0xe0], :LightYellow named [0x00, 0xff, 0x00], :Lime named [0x32, 0xcd, 0x32], :LimeGreen named [0xfa, 0xf0, 0xe6], :Linen named [0xff, 0x00, 0xff], :Magenta named [0x80, 0x00, 0x00], :Maroon named [0x66, 0xcd, 0xaa], :MediumAquaMarine, :MediumAquamarine named [0x00, 0x00, 0xcd], :MediumBlue named [0xba, 0x55, 0xd3], :MediumOrchid named [0x93, 0x70, 0xdb], :MediumPurple named [0x3c, 0xb3, 0x71], :MediumSeaGreen named [0x7b, 0x68, 0xee], :MediumSlateBlue named [0x00, 0xfa, 0x9a], :MediumSpringGreen named [0x48, 0xd1, 0xcc], :MediumTurquoise named [0xc7, 0x15, 0x85], :MediumVioletRed named [0x19, 0x19, 0x70], :MidnightBlue named [0xf5, 0xff, 0xfa], :MintCream named [0xff, 0xe4, 0xe1], :MistyRose named [0xff, 0xe4, 0xb5], :Moccasin named [0xff, 0xde, 0xad], :NavajoWhite named [0x00, 0x00, 0x80], :Navy named [0xfd, 0xf5, 0xe6], :OldLace named [0x80, 0x80, 0x00], :Olive named [0x6b, 0x8e, 0x23], :OliveDrab, :Olivedrab named [0xff, 0xa5, 0x00], :Orange named [0xff, 0x45, 0x00], :OrangeRed named [0xda, 0x70, 0xd6], :Orchid named [0xee, 0xe8, 0xaa], :PaleGoldenRod, :PaleGoldenrod named [0x98, 0xfb, 0x98], :PaleGreen named [0xaf, 0xee, 0xee], :PaleTurquoise named [0xdb, 0x70, 0x93], :PaleVioletRed named [0xff, 0xef, 0xd5], :PapayaWhip named [0xff, 0xda, 0xb9], :PeachPuff, :Peachpuff named [0xcd, 0x85, 0x3f], :Peru named [0xff, 0xc0, 0xcb], :Pink named [0xdd, 0xa0, 0xdd], :Plum named [0xb0, 0xe0, 0xe6], :PowderBlue named [0x80, 0x00, 0x80], :Purple named [0xff, 0x00, 0x00], :Red named [0xbc, 0x8f, 0x8f], :RosyBrown named [0x41, 0x69, 0xe1], :RoyalBlue named [0x8b, 0x45, 0x13], :SaddleBrown named [0xfa, 0x80, 0x72], :Salmon named [0xf4, 0xa4, 0x60], :SandyBrown named [0x2e, 0x8b, 0x57], :SeaGreen named [0xff, 0xf5, 0xee], :SeaShell, :Seashell named [0xa0, 0x52, 0x2d], :Sienna named [0xc0, 0xc0, 0xc0], :Silver named [0x87, 0xce, 0xeb], :SkyBlue named [0x6a, 0x5a, 0xcd], :SlateBlue named [0x70, 0x80, 0x90], :SlateGray, :SlateGrey named [0xff, 0xfa, 0xfa], :Snow named [0x00, 0xff, 0x7f], :SpringGreen named [0x46, 0x82, 0xb4], :SteelBlue named [0xd2, 0xb4, 0x8c], :Tan named [0x00, 0x80, 0x80], :Teal named [0xd8, 0xbf, 0xd8], :Thistle named [0xff, 0x63, 0x47], :Tomato named [0x40, 0xe0, 0xd0], :Turquoise named [0xee, 0x82, 0xee], :Violet named [0xd0, 0x20, 0x90], :VioletRed named [0xf5, 0xde, 0xb3], :Wheat named [0xff, 0xff, 0xff], :White named [0xf5, 0xf5, 0xf5], :WhiteSmoke named [0xff, 0xff, 0x00], :Yellow named [0x9a, 0xcd, 0x32], :YellowGreen end require 'color/rgb/metallic' color-1.8/lib/color/rgb/contrast.rb0000644000004100000410000000341512620676731017365 0ustar www-datawww-data# -*- ruby encoding: utf-8 -*- class Color::RGB # Outputs how much contrast this color has with another RGB color. # Computes the same regardless of which one is considered foreground. If # the other color does not have a #to_rgb method, this will throw an # exception. Anything over about 0.22 should have a high likelihood of # being legible, but the larger the difference, the more contrast. # Otherwise, to be safe go with something > 0.3 def contrast(other) other = coerce(other) # The following numbers have been set with some care. ((diff_brightness(other) * 0.65) + (diff_hue(other) * 0.20) + (diff_luminosity(other) * 0.15)) end private # Provides the luminosity difference between two rbg vals def diff_luminosity(other) other = coerce(other) l1 = (0.2126 * (other.r) ** 2.2) + (0.7152 * (other.b) ** 2.2) + (0.0722 * (other.g) ** 2.2); l2 = (0.2126 * (self.r) ** 2.2) + (0.7152 * (self.b) ** 2.2) + (0.0722 * (self.g) ** 2.2); ((([l1, l2].max) + 0.05) / ( ([l1, l2].min) + 0.05 ) - 1) / 20.0 end # Provides the brightness difference. def diff_brightness(other) other = other.to_rgb br1 = (299 * other.r + 587 * other.g + 114 * other.b) br2 = (299 * self.r + 587 * self.g + 114 * self.b) (br1 - br2).abs / 1000.0; end # Provides the euclidean distance between the two color values def diff_euclidean(other) other = other.to_rgb ((((other.r - self.r) ** 2) + ((other.g - self.g) ** 2) + ((other.b - self.b) ** 2)) ** 0.5) / 1.7320508075688772 end # Difference in the two colors' hue def diff_hue(other) other = other.to_rgb ((self.r - other.r).abs + (self.g - other.g).abs + (self.b - other.b).abs) / 3 end end color-1.8/lib/color/css.rb0000644000004100000410000000031512620676731015542 0ustar www-datawww-data# 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) Color::RGB.by_name(name) { nil } end end color-1.8/lib/color/yiq.rb0000644000004100000410000000207712620676731015563 0ustar www-datawww-data# A colour object representing YIQ (NTSC) colour encoding. class Color::YIQ include Color # 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, &block) new(y, i, q, 1.0, &block) end # Creates a YIQ colour object from percentages 0 .. 100. # # Color::YIQ.new(10, 20, 30) def initialize(y = 0, i = 0, q = 0, radix = 100.0, &block) # :yields self: @y, @i, @q = [ y, i, q ].map { |v| Color.normalize(v / radix) } block.call if block end def coerce(other) other.to_yiq 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 def to_a [ y, i, q ] end end color-1.8/lib/color/palette/0000755000004100000410000000000012620676731016064 5ustar www-datawww-datacolor-1.8/lib/color/palette/monocontrast.rb0000644000004100000410000001377612620676731021155 0ustar www-datawww-datarequire '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_reader :minimum_brightness_diff def minimum_brightness_diff=(bd) #:nodoc: @minimum_brightness_diff = if bd.nil? DEFAULT_MINIMUM_BRIGHTNESS_DIFF elsif bd > 1.0 1.0 elsif bd < 0.0 0.0 else 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_reader :minimum_color_diff def minimum_color_diff=(cd) #:nodoc: @minimum_color_diff = if cd.nil? DEFAULT_MINIMUM_COLOR_DIFF elsif cd > 3.0 3.0 elsif cd < 0.0 0.0 else 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.8/lib/color/palette/gimp.rb0000644000004100000410000000503012620676731017343 0ustar www-datawww-datarequire '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.8/lib/color/palette/adobecolor.rb0000644000004100000410000001761412620676731020533 0ustar www-datawww-datarequire '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.8/lib/color/rgb.rb0000644000004100000410000005200312620676731015525 0ustar www-datawww-data# An RGB colour object. class Color::RGB include Color # 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" # Coerces the other Color object into RGB. def coerce(other) other.to_rgb 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, radix = 255.0, &block) # :yields self: @r, @g, @b = [ r, g, b ].map { |v| Color.normalize(v / radix) } block.call(self) if block 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 RGB hex triplet. def hex 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 HTML/CSS colour string. def html "##{hex}" 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 an optional alpha that defaults to 1) # 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. # # Color::RGB.by_hex('ff0000').css_rgba # => 'rgba(100.00%, 0.00%, 0.00%, 1.00)' # Color::RGB.by_hex('ff0000').css_rgba(0.2) # => 'rgba(100.00%, 0.00%, 0.00%, 0.20)' def css_rgba(alpha = 1) "rgba(%3.2f%%, %3.2f%%, %3.2f%%, %3.2f)" % [ red_p, green_p, blue_p, alpha ] 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 # Returns the XYZ colour encoding of the value. Based on the # {RGB to XYZ}[http://www.brucelindbloom.com/index.html?Eqn_RGB_to_XYZ.html] # formula presented by Bruce Lindbloom. # # Currently only the sRGB colour space is supported. def to_xyz(color_space = :sRGB) unless color_space.to_s.downcase == 'srgb' raise ArgumentError, "Unsupported colour space #{color_space}." end # Inverse sRGB companding. Linearizes RGB channels with respect to # energy. r, g, b = [ @r, @g, @b ].map { |v| if (v > 0.04045) (((v + 0.055) / 1.055) ** 2.4) * 100 else (v / 12.92) * 100 end } # Convert using the RGB/XYZ matrix at: # http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html#WSMatrices { :x => (r * 0.4124564 + g * 0.3575761 + b * 0.1804375), :y => (r * 0.2126729 + g * 0.7151522 + b * 0.0721750), :z => (r * 0.0193339 + g * 0.1191920 + b * 0.9503041) } end # Returns the L*a*b* colour encoding of the value via the XYZ colour # encoding. Based on the # {XYZ to Lab}[http://www.brucelindbloom.com/index.html?Eqn_XYZ_to_Lab.html] # formula presented by Bruce Lindbloom. # # Currently only the sRGB colour space is supported and defaults to using # a D65 reference white. def to_lab(color_space = :sRGB, reference_white = [ 95.047, 100.00, 108.883 ]) xyz = to_xyz # Calculate the ratio of the XYZ values to the reference white. # http://www.brucelindbloom.com/index.html?Equations.html xr = xyz[:x] / reference_white[0] yr = xyz[:y] / reference_white[1] zr = xyz[:z] / reference_white[2] # NOTE: This should be using Rational instead of floating point values, # otherwise there will be discontinuities. # http://www.brucelindbloom.com/LContinuity.html epsilon = (216 / 24389.0) kappa = (24389 / 27.0) # And now transform # http://en.wikipedia.org/wiki/Lab_color_space#Forward_transformation # There is a brief explanation there as far as the nature of the calculations, # as well as a much nicer looking modeling of the algebra. fx, fy, fz = [ xr, yr, zr ].map { |t| if (t > (epsilon)) t ** (1.0 / 3) else # t <= epsilon ((kappa * t) + 16) / 116.0 # The 4/29 here is for when t = 0 (black). 4/29 * 116 = 16, and 16 - # 16 = 0, which is the correct value for L* with black. # ((1.0/3)*((29.0/6)**2) * t) + (4.0/29) end } { :L => ((116 * fy) - 16), :a => (500 * (fx - fy)), :b => (200 * (fy - fz)) } 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 = normalize_percent(percent) 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 = normalize_percent(percent) 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 = normalize_percent(percent) hsl = to_hsl hsl.h *= percent hsl.to_rgb end # TODO: Identify the base colour profile used for L*a*b* and XYZ # conversions. # Calculates and returns the closest match to this colour from a list of # provided colours. Returns +nil+ if +color_list+ is empty or if there is # no colour within the +threshold_distance+. # # +threshold_distance+ is used to determine the minimum colour distance # permitted. Uses the CIE Delta E 1994 algorithm (CIE94) to find near # matches based on perceived visual colour. The default value (1000.0) is # an arbitrarily large number. The values :jnd and # :just_noticeable may be passed as the +threshold_distance+ to # use the value 2.3. def closest_match(color_list, threshold_distance = 1000.0) color_list = [ color_list ].flatten(1) return nil if color_list.empty? threshold_distance = case threshold_distance when :jnd, :just_noticeable 2.3 else threshold_distance.to_f end lab = to_lab closest_distance = threshold_distance best_match = nil color_list.each do |c| distance = delta_e94(lab, c.to_lab) if (distance < closest_distance) closest_distance = distance best_match = c end end best_match end # The Delta E (CIE94) algorithm # http://en.wikipedia.org/wiki/Color_difference#CIE94 # # There is a newer version, CIEDE2000, that uses slightly more complicated # math, but addresses "the perceptual uniformity issue" left lingering by # the CIE94 algorithm. color_1 and color_2 are both L*a*b* hashes, # rendered by #to_lab. # # Since our source is treated as sRGB, we use the "graphic arts" presets # for k_L, k_1, and k_2 # # The calculations go through LCH(ab). (?) # # See also http://www.brucelindbloom.com/index.html?Eqn_DeltaE_CIE94.html # # NOTE: This should be moved to Color::Lab. def delta_e94(color_1, color_2, weighting_type = :graphic_arts) case weighting_type when :graphic_arts k_1 = 0.045 k_2 = 0.015 k_L = 1 when :textiles k_1 = 0.048 k_2 = 0.014 k_L = 2 else raise ArgumentError, "Unsupported weighting type #{weighting_type}." end # delta_E = Math.sqrt( # ((delta_L / (k_L * s_L)) ** 2) + # ((delta_C / (k_C * s_C)) ** 2) + # ((delta_H / (k_H * s_H)) ** 2) # ) # # Under some circumstances in real computers, delta_H could be an # imaginary number (it's a square root value), so we're going to treat # this as: # # delta_E = Math.sqrt( # ((delta_L / (k_L * s_L)) ** 2) + # ((delta_C / (k_C * s_C)) ** 2) + # (delta_H2 / ((k_H * s_H) ** 2))) # ) # # And not perform the square root when calculating delta_H2. k_C = k_H = 1 l_1, a_1, b_1 = color_1.values_at(:L, :a, :b) l_2, a_2, b_2 = color_2.values_at(:L, :a, :b) delta_a = a_1 - a_2 delta_b = b_1 - b_2 c_1 = Math.sqrt((a_1 ** 2) + (b_1 ** 2)) c_2 = Math.sqrt((a_2 ** 2) + (b_2 ** 2)) delta_L = color_1[:L] - color_2[:L] delta_C = c_1 - c_2 delta_H2 = (delta_a ** 2) + (delta_b ** 2) - (delta_C ** 2) s_L = 1 s_C = 1 + k_1 * c_1 s_H = 1 + k_2 * c_1 composite_L = (delta_L / (k_L * s_L)) ** 2 composite_C = (delta_C / (k_C * s_C)) ** 2 composite_H = delta_H2 / ((k_H * s_H) ** 2) Math.sqrt(composite_L + composite_C + composite_H) 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) self.class.from_fraction(r + other.r, g + other.g, b + other.b) 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) self + (-other) 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 def to_a [ r, g, b ] end # Numerically negate the color. This results in a color that is only # usable for subtraction. def -@ rgb = self.dup rgb.instance_variable_set(:@r, -rgb.r) rgb.instance_variable_set(:@g, -rgb.g) rgb.instance_variable_set(:@b, -rgb.b) rgb end private def normalize_percent(percent) percent /= 100.0 percent += 1.0 percent = [ percent, 2.0 ].min percent = [ 0.0, percent ].max percent end end class << Color::RGB # 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, &block) new(r, g, b, 100.0, &block) 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, &block) new(r, g, b, 1.0, &block) end # Creates an RGB colour object from a grayscale fractional value 0..1. def from_grayscale_fraction(l = 0.0, &block) new(l, l, l, 1.0, &block) end alias_method :from_greyscale_fraction, :from_grayscale_fraction # 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, &block) # When we can move to 1.9+ only, this will be \h h = html_colour.scan(/[0-9a-f]/i) case h.size when 3 new(*h.map { |v| (v * 2).to_i(16) }, &block) when 6 new(*h.each_slice(2).map { |v| v.join.to_i(16) }, &block) else raise ArgumentError, "Not a supported HTML colour type." end end # Find or create a colour by an HTML hex code. This differs from the # #from_html method in that if the colour code matches a named colour, # the existing colour will be returned. # # Color::RGB.by_hex('ff0000').name # => 'red' # Color::RGB.by_hex('ff0001').name # => nil # # If a block is provided, the value that is returned by the block will # be returned instead of the exception caused by an error in providing a # correct hex format. def by_hex(hex, &block) __by_hex.fetch(html_hexify(hex)) { from_html(hex) } rescue if block block.call else raise end end # Return a colour as identified by the colour name. def by_name(name, &block) __by_name.fetch(name.to_s.downcase, &block) end # Return a colour as identified by the colour name, or by hex. def by_css(name_or_hex, &block) by_name(name_or_hex) { by_hex(name_or_hex, &block) } end # Extract named or hex colours from the provided text. def extract_colors(text, mode = :both) text = text.downcase regex = case mode when :name Regexp.union(__by_name.keys) when :hex Regexp.union(__by_hex.keys) when :both Regexp.union(__by_hex.keys + __by_name.keys) end text.scan(regex).map { |match| case mode when :name by_name(match) when :hex by_hex(match) when :both by_css(match) end } end end class << Color::RGB private def __named_color(mod, rgb, *names) used = names - mod.constants.map(&:to_sym) if used.length < names.length raise ArgumentError, "#{names.join(', ')} already defined in #{mod}" end names.each { |n| mod.const_set(n, rgb) } rgb.names = names rgb.names.each { |n| __by_name[n] = rgb } __by_hex[rgb.hex] = rgb rgb.freeze end def __by_hex @__by_hex ||= {} end def __by_name @__by_name ||= {} end def html_hexify(hex) # When we can move to 1.9+ only, this will be \h h = hex.to_s.downcase.scan(/[0-9a-f]/) case h.size when 3 h.map { |v| (v * 2) }.join when 6 h.join else raise ArgumentError, "Not a supported HTML colour type." end end end require 'color/rgb/colors' color-1.8/lib/color/palette.rb0000644000004100000410000000005312620676731016407 0ustar www-datawww-datarequire 'color' module Color::Palette end color-1.8/metadata.yml0000644000004100000410000002105612620676731015051 0ustar www-datawww-data--- !ruby/object:Gem::Specification name: color version: !ruby/object:Gem::Version version: '1.8' platform: ruby authors: - Austin Ziegler - Matt Lyon autorequire: bindir: bin cert_chain: [] date: 2015-10-26 00:00:00.000000000 Z dependencies: - !ruby/object:Gem::Dependency name: minitest requirement: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '5.8' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '5.8' - !ruby/object:Gem::Dependency name: rdoc requirement: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '4.0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '4.0' - !ruby/object:Gem::Dependency name: hoe-doofus requirement: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '1.0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '1.0' - !ruby/object:Gem::Dependency name: hoe-gemspec2 requirement: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '1.1' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '1.1' - !ruby/object:Gem::Dependency name: hoe-git requirement: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '1.6' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '1.6' - !ruby/object:Gem::Dependency name: hoe-travis requirement: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '1.2' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '1.2' - !ruby/object:Gem::Dependency name: minitest-around requirement: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '0.3' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '0.3' - !ruby/object:Gem::Dependency name: minitest-autotest requirement: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '1.0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '1.0' - !ruby/object:Gem::Dependency name: minitest-bisect requirement: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '1.2' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '1.2' - !ruby/object:Gem::Dependency name: minitest-focus requirement: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '1.1' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '1.1' - !ruby/object:Gem::Dependency name: minitest-moar requirement: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '0.0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '0.0' - !ruby/object:Gem::Dependency name: minitest-pretty_diff requirement: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '0.1' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '0.1' - !ruby/object:Gem::Dependency name: rake requirement: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '10.0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '10.0' - !ruby/object:Gem::Dependency name: simplecov requirement: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '0.7' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '0.7' - !ruby/object:Gem::Dependency name: hoe requirement: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '3.14' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '3.14' 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 Color library performs purely 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 RGB and HSL colour spaces, this won't matter. Absolute colour spaces (like CIE L*a*b* and XYZ) and cannot be reliably converted to relative colour spaces (like RGB) without colour profiles. Color 1.8 adds an alpha parameter to all #css_rgba calls, fixes a bug exposed by new constant lookup semantics in Ruby 2, and ensures that Color.equivalent? can only be called on Color instances. Barring bugs introduced in this release, this (really) is the last version of color that supports Ruby 1.8, so make sure that your gem specification is set properly (to ~> 1.8) if that matters for your application. This version will no longer be supported one year after the release of color 2.0. email: - halostatue@gmail.com - matt@postsomnia.com executables: [] extensions: [] extra_rdoc_files: - Code-of-Conduct.rdoc - Contributing.rdoc - History.rdoc - Licence.rdoc - Manifest.txt - README.rdoc files: - ".autotest" - ".coveralls.yml" - ".gemtest" - ".hoerc" - ".minitest.rb" - ".travis.yml" - Code-of-Conduct.rdoc - Contributing.rdoc - Gemfile - 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.rb - lib/color/rgb/colors.rb - lib/color/rgb/contrast.rb - lib/color/rgb/metallic.rb - lib/color/yiq.rb - test/minitest_helper.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 homepage: https://github.com/halostatue/color licenses: - MIT metadata: {} post_install_message: rdoc_options: - "--main" - README.rdoc require_paths: - lib required_ruby_version: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' required_rubygems_version: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' requirements: [] rubyforge_project: rubygems_version: 2.4.8 signing_key: specification_version: 4 summary: Color is a Ruby library to provide basic RGB, CMYK, HSL, and other colourspace manipulation support to applications that require it test_files: [] color-1.8/test/0000755000004100000410000000000012620676731013521 5ustar www-datawww-datacolor-1.8/test/test_gimp.rb0000644000004100000410000000361412620676731016045 0ustar www-datawww-data# -*- ruby encoding: utf-8 -*- require 'color' require 'color/palette/gimp' require 'minitest_helper' 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.8/test/test_yiq.rb0000644000004100000410000000323412620676731015711 0ustar www-datawww-data# -*- ruby encoding: utf-8 -*- require 'color' require 'minitest_helper' 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.8/test/test_rgb.rb0000644000004100000410000004352512620676731015670 0ustar www-datawww-data# -*- ruby encoding: utf-8 -*- require 'color' require 'minitest_helper' 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) assert_equal("rgba(100.00%, 0.00%, 0.00%, 0.50)", Color::RGB::Red.css_rgba(0.5)) 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_same(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_to_lab # Luminosity can be an absolute. assert_in_delta(0.0, Color::RGB::Black.to_lab[:L], Color::COLOR_TOLERANCE) assert_in_delta(100.0, Color::RGB::White.to_lab[:L], Color::COLOR_TOLERANCE) # It's not really possible to have absolute # numbers here because of how L*a*b* works, but # negative/positive comparisons work assert(Color::RGB::Green.to_lab[:a] < 0) assert(Color::RGB::Magenta.to_lab[:a] > 0) assert(Color::RGB::Blue.to_lab[:b] < 0) assert(Color::RGB::Yellow.to_lab[:b] > 0) end def test_closest_match # It should match Blue to Indigo (very simple match) match_from = [Color::RGB::Red, Color::RGB::Green, Color::RGB::Blue] assert_equal(Color::RGB::Blue, Color::RGB::Indigo.closest_match(match_from)) # But fails if using the :just_noticeable difference. assert_nil(Color::RGB::Indigo.closest_match(match_from, :just_noticeable)) # Crimson & Firebrick are visually closer than DarkRed and Firebrick # (more precise match) match_from += [Color::RGB::DarkRed, Color::RGB::Crimson] assert_equal(Color::RGB::Crimson, Color::RGB::Firebrick.closest_match(match_from)) # Specifying a threshold low enough will cause even that match to # fail, though. assert_nil(Color::RGB::Firebrick.closest_match(match_from, 8.0)) # If the match_from list is an empty array, it also returns nil assert_nil(Color::RGB::Red.closest_match([])) # RGB::Green is 0,128,0, so we'll pick something VERY close to it, visually jnd_green = Color::RGB.new(3, 132, 3) assert_equal(Color::RGB::Green, jnd_green.closest_match(match_from, :jnd)) # And then something that's just barely out of the tolerance range diff_green = Color::RGB.new(9, 142, 9) assert_nil(diff_green.closest_match(match_from, :jnd)) end def test_add 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_by_hex assert_same(Color::RGB::Cyan, Color::RGB.by_hex('#0ff')) assert_same(Color::RGB::Cyan, Color::RGB.by_hex('#00ffff')) assert_equal("RGB [#333333]", Color::RGB.by_hex("#333").inspect) assert_equal("RGB [#333333]", Color::RGB.by_hex("333").inspect) assert_raises(ArgumentError) { Color::RGB.by_hex("5555555") } assert_raises(ArgumentError) { Color::RGB.by_hex("#55555") } assert_equal(:boom, Color::RGB.by_hex('#55555') { :boom }) end def test_by_name assert_same(Color::RGB::Cyan, Color::RGB.by_name('cyan')) fetch_error = if RUBY_VERSION < "1.9" IndexError else KeyError end assert_raises(fetch_error) { Color::RGB.by_name('cyanide') } assert_equal(:boom, Color::RGB.by_name('cyanide') { :boom }) end def test_by_css assert_same(Color::RGB::Cyan, Color::RGB.by_css('#0ff')) assert_same(Color::RGB::Cyan, Color::RGB.by_css('cyan')) assert_raises(ArgumentError) { Color::RGB.by_css('cyanide') } assert_equal(:boom, Color::RGB.by_css('cyanide') { :boom }) end def test_extract_colors assert_equal([ Color::RGB::BlanchedAlmond, Color::RGB::Cyan ], Color::RGB.extract_colors('BlanchedAlmond is a nice shade, but #00ffff is not.')) 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.8/test/test_adobecolor.rb0000644000004100000410000005120712620676731017223 0ustar www-datawww-data# -*- ruby encoding: utf-8 -*- require 'color' require 'color/palette/adobecolor' require 'minitest_helper' 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 A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AAABmAAAA/wAAAAAAmQAzAP8AAAAAAGYAAADMAAAAAADMAJkA /wAAAAAAmQBmAMwAAAAAAGYAMwCZAAAAAAAzAAAAZgAAAAAAmQAAAP8AAAAA AMwAZgD/AAAAAACZADMAzAAAAAAAZgAAAJkAAAAAAMwAMwD/AAAAAACZAAAA zAAAAAAAzAAAAP8AAAAAAP8AAAD/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/ ADMAMwAAAAAAAA8ATABpAGcAaAB0ACAASABhA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AAAAAP8AAABmAAAAAAAADgBQAGkAbgBrAC0AUABpAG4AawAtAFIA 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.8/test/test_hsl.rb0000644000004100000410000001154412620676731015700 0ustar www-datawww-data# -*- ruby encoding: utf-8 -*- require 'color' require 'minitest_helper' 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 assert_equal "rgba(24.00%, 36.00%, 29.00%, 0.20)", @hsl.css_rgba(0.2) # 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.8/test/test_grayscale.rb0000644000004100000410000000624712620676731017070 0ustar www-datawww-data# -*- ruby encoding: utf-8 -*- require 'color' require 'minitest_helper' 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) assert_equal("rgba(33.00%, 33.00%, 33.00%, 0.20)", @gs.css_rgba(0.2)) 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.8/test/test_css.rb0000644000004100000410000000111012620676731015666 0ustar www-datawww-datarequire 'color' require 'color/css' require 'minitest_helper' module TestColor class TestCSS < Minitest::Test def test_index_with_known_name assert_same(Color::RGB::AliceBlue, Color::CSS[:aliceblue]) assert_same(Color::RGB::AliceBlue, Color::CSS["AliceBlue"]) assert_same(Color::RGB::AliceBlue, Color::CSS["aliceBlue"]) assert_same(Color::RGB::AliceBlue, Color::CSS["aliceblue"]) assert_same(Color::RGB::AliceBlue, Color::CSS[:AliceBlue]) end def test_index_with_unknown_name assert_equal(nil, Color::CSS['redx']) end end end color-1.8/test/minitest_helper.rb0000644000004100000410000000013312620676731017236 0ustar www-datawww-data# -*- ruby encoding: utf-8 -*- require 'color' gem 'minitest' require 'minitest/autorun' color-1.8/test/test_monocontrast.rb0000644000004100000410000001334612620676731017642 0ustar www-datawww-data# -*- ruby encoding: utf-8 -*- require 'color' require 'color/palette/monocontrast' require 'minitest_helper' 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.8/test/test_color.rb0000644000004100000410000001162712620676731016232 0ustar www-datawww-data# -*- ruby encoding: utf-8 -*- require 'color' require 'minitest_helper' 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_equivalent assert Color.equivalent?(Color::RGB::Red, Color::HSL.new(0, 100, 50)) refute Color.equivalent?(Color::RGB::Red, nil) refute Color.equivalent?(nil, Color::RGB::Red) 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.8/test/test_cmyk.rb0000644000004100000410000000735112620676731016056 0ustar www-datawww-data# -*- ruby encoding: utf-8 -*- require 'color' require 'minitest_helper' 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) assert_equal("rgba(54.00%, 48.00%, 42.00%, 0.20)", @cmyk.css_rgba(0.2)) 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.8/.minitest.rb0000644000004100000410000000005212620676731014776 0ustar www-datawww-datagem "minitest" require "minitest/autorun"