color 1.7.1 → 2.0.0.pre.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -13
- data/CHANGELOG.md +298 -0
- data/CODE_OF_CONDUCT.md +128 -0
- data/CONTRIBUTING.md +70 -0
- data/CONTRIBUTORS.md +10 -0
- data/LICENCE.md +27 -0
- data/Manifest.txt +11 -21
- data/README.md +54 -0
- data/Rakefile +74 -53
- data/SECURITY.md +34 -0
- data/lib/color/cielab.rb +348 -0
- data/lib/color/cmyk.rb +279 -213
- data/lib/color/grayscale.rb +128 -160
- data/lib/color/hsl.rb +205 -173
- data/lib/color/rgb/colors.rb +177 -163
- data/lib/color/rgb.rb +534 -537
- data/lib/color/version.rb +5 -0
- data/lib/color/xyz.rb +214 -0
- data/lib/color/yiq.rb +91 -46
- data/lib/color.rb +208 -141
- data/test/fixtures/cielab.json +444 -0
- data/test/minitest_helper.rb +20 -4
- data/test/test_cmyk.rb +49 -71
- data/test/test_color.rb +58 -106
- data/test/test_grayscale.rb +35 -56
- data/test/test_hsl.rb +72 -76
- data/test/test_rgb.rb +195 -267
- data/test/test_yiq.rb +12 -30
- metadata +165 -150
- checksums.yaml.gz.sig +0 -0
- data/.autotest +0 -5
- data/.gemtest +0 -0
- data/.hoerc +0 -2
- data/.minitest.rb +0 -2
- data/.travis.yml +0 -35
- data/Contributing.rdoc +0 -60
- data/Gemfile +0 -9
- data/History.rdoc +0 -172
- data/Licence.rdoc +0 -27
- data/README.rdoc +0 -50
- data/lib/color/css.rb +0 -7
- data/lib/color/palette/adobecolor.rb +0 -260
- data/lib/color/palette/gimp.rb +0 -104
- data/lib/color/palette/monocontrast.rb +0 -164
- data/lib/color/palette.rb +0 -4
- data/lib/color/rgb/contrast.rb +0 -57
- data/lib/color/rgb/metallic.rb +0 -28
- data/test/test_adobecolor.rb +0 -405
- data/test/test_css.rb +0 -19
- data/test/test_gimp.rb +0 -87
- data/test/test_monocontrast.rb +0 -130
- data.tar.gz.sig +0 -0
- metadata.gz.sig +0 -0
data/History.rdoc
DELETED
@@ -1,172 +0,0 @@
|
|
1
|
-
== 1.7.1 / 2014-06-12
|
2
|
-
|
3
|
-
* Minor enhancements:
|
4
|
-
* Renamed Color::RGB::BeccaPurple to Color::RGB::RebeccaPurple as stipulated
|
5
|
-
by Eric Meyer. http://meyerweb.com/eric/thoughts/2014/06/19/rebeccapurple/
|
6
|
-
For purposes of backwards compatibility, the previous name is still
|
7
|
-
permitted, but its use is strongly discouraged, and it will be removed in
|
8
|
-
the Color 2.0 release.
|
9
|
-
|
10
|
-
== 1.7 / 2014-06-12
|
11
|
-
|
12
|
-
* Minor enhancements:
|
13
|
-
* Added Color::RGB::BeccaPurple (#663399) in honour of Rebecca Meyer, the
|
14
|
-
daughter of Eric Meyer, who passed away on the 7th of June, 2014. Her
|
15
|
-
favourite colour was purple. #663399becca
|
16
|
-
https://twitter.com/meyerweb/status/476089708674428929
|
17
|
-
http://www.zeldman.com/2014/06/10/the-color-purple/
|
18
|
-
http://discourse.specifiction.org/t/name-663399-becca-purple-in-css4-color/225
|
19
|
-
|
20
|
-
* Bug fixes:
|
21
|
-
* Changed the homepage in the gem to point to github.com instead of
|
22
|
-
RubyForge, which has been shut down. Fixes #10, reported by @voxik.
|
23
|
-
|
24
|
-
== 1.6 / 2014-05-19
|
25
|
-
|
26
|
-
* Major enhancements:
|
27
|
-
* Aaron Hill (@armahillo) implemented the CIE Delta E 94 method by which an
|
28
|
-
RGB colour can be asked for the closest matching colour from a list of
|
29
|
-
provided colours. Fixes #5.
|
30
|
-
* To implement #closest_match and #delta_e94, conversion methods for sRGB to
|
31
|
-
XYZ and XYZ to L*a*b* space were implemented. These should be considered
|
32
|
-
experimental.
|
33
|
-
|
34
|
-
* Tooling fixes:
|
35
|
-
* Ensured that the gem manifest was up-to-date. Fixes #4 reported by @boutil.
|
36
|
-
Thanks!
|
37
|
-
* Fixed problems with Travis builds. Note that Ruby 1.9.2 is no longer
|
38
|
-
tested. Rubinius remains in a “failure-tolerated” mode.
|
39
|
-
* Color 1.6 is, barring security patches, the last release of Color that will
|
40
|
-
support Ruby 1.8.
|
41
|
-
|
42
|
-
== 1.5.1 / 2014-01-28
|
43
|
-
|
44
|
-
* color 1.5 was a yanked release.
|
45
|
-
|
46
|
-
* Minor enhancements:
|
47
|
-
* Added new methods to Color::RGB to make it so that the default defined
|
48
|
-
colours can be looked up by hex, name, or both.
|
49
|
-
* Added a method to Color::RGB to extract colours from text by hex, name, or
|
50
|
-
both.
|
51
|
-
* Added new common methods for colour names. Converted colours do not retain
|
52
|
-
names.
|
53
|
-
* Restructured color comparisons to use protocols instead of custom
|
54
|
-
implementations. This makes it easier to implement new colour classes. To
|
55
|
-
make this work, color classes should +include+ Color only need to implement
|
56
|
-
<tt>#coerce(other)</tt>, <tt>#to_a</tt>, and supported conversion methods
|
57
|
-
(e.g., <tt>#to_rgb</tt>).
|
58
|
-
* Added @daveheitzman’s initial implementation of an RGB contrast method as
|
59
|
-
an extension file: <tt>require 'color/rgb/contrast'</tt>. This method and
|
60
|
-
the value it returns should be considered experimental; it requires further
|
61
|
-
examination to ensure that the results produced are consistent with the
|
62
|
-
contrast comparisons used in Color::Palette::MonoContrast.
|
63
|
-
* Reducing duplicated code.
|
64
|
-
|
65
|
-
* Bug Fixes:
|
66
|
-
* Moved +lib/color/rgb-colors.rb+ to +lib/color/rgb/colors.rb+. This should
|
67
|
-
have no impact in general.
|
68
|
-
* Improved the way that named colors are specified internally.
|
69
|
-
* Fixed bugs with Ruby 1.8.7 that may have been introduced in color 1.4.2.
|
70
|
-
|
71
|
-
* Tooling Changes:
|
72
|
-
* Added simplecov for test coverage analysis.
|
73
|
-
* Modernized Travis CI support.
|
74
|
-
|
75
|
-
== 1.4.2 / 2013-06-30
|
76
|
-
|
77
|
-
Maintenance:
|
78
|
-
* Modernized Hoe installation of Color, removing some dependencies.
|
79
|
-
* Switched to Minitest.
|
80
|
-
* Turned on Travis CI.
|
81
|
-
* Started using Code Climate.
|
82
|
-
* Small code formatting cleanup that touched pretty much every file.
|
83
|
-
|
84
|
-
== 1.4.1 / 2010-02-03
|
85
|
-
|
86
|
-
* Imported to github.
|
87
|
-
* Converted to Hoe 2.5 spec format.
|
88
|
-
|
89
|
-
== 1.4.0 / 2007-02-11
|
90
|
-
|
91
|
-
* Merged Austin Ziegler's color-tools library (previously part of the Ruby
|
92
|
-
PDF Tools project) with Matt Lyon's color library.
|
93
|
-
- The HSL implementation from the Color class has been merged into
|
94
|
-
Color::HSL. Color is a module the way it was for color-tools.
|
95
|
-
- A thin veneer has been written to allow Color::new to return a Color::HSL
|
96
|
-
instance; Color::HSL supports as many methods as possible that were
|
97
|
-
previously supported by the Color class.
|
98
|
-
- Values that were previously rounded by Color are no longer rounded;
|
99
|
-
fractional values matter.
|
100
|
-
* Converted to hoe for project management.
|
101
|
-
* Moved to the next step of deprecating Color::Name values; printing a
|
102
|
-
warning for each use (see the history for color-tools 1.3.0).
|
103
|
-
* Print a warning on the access of either VERSION or COLOR_TOOLS_VERSION; the
|
104
|
-
version constant is now COLOR_VERSION.
|
105
|
-
* Added humanized versions of accessors (e.g., CMYK colours now have both #cyan
|
106
|
-
and #c to access the cyan component of the colour; #cyan provides the value
|
107
|
-
as a percentage).
|
108
|
-
* Added CSS3 formatters for RGB, RGBA, HSL, and HSLA outputs. Note that the
|
109
|
-
Color library does not yet have a way of setting alpha opacity, so the
|
110
|
-
output for RGBA and HSLA are at full alpha opacity (1.0). The values are
|
111
|
-
output with two decimal places.
|
112
|
-
* Applied a patch to provide simple arithmetic colour addition and subtraction
|
113
|
-
to Color::GrayScale and Color::RGB. The patch was contributed by Jeremy
|
114
|
-
Hinegardner <jeremy@hinegardner.org>. This patch also provides the ability to
|
115
|
-
return the maximum RGB value as a grayscale colour.
|
116
|
-
* Fixed two problems reported by Jean Krohn <jb.krohn@free.fr> against
|
117
|
-
color-tools relating to RGB-to-HSL and HSL-to-RGB conversion. (Color and
|
118
|
-
color-tools use the same formulas, but the ordering of the calculations is
|
119
|
-
slightly different with Color and did not suffer from this problem;
|
120
|
-
color-tools was more sensitive to floating-point values and precision
|
121
|
-
errors.)
|
122
|
-
* Fixed an issue with HSL/RGB conversions reported by Adam Johnson
|
123
|
-
<adam.sven.johnson@gmail.com>.
|
124
|
-
* Added an Adobe Color swatch (Photoshop) palette reader,
|
125
|
-
Color::Palette::AdobeColor (for .aco files only).
|
126
|
-
|
127
|
-
== Color 0.1.0 / 2006-08-05
|
128
|
-
|
129
|
-
* Added HSL (degree, percent, percent) interface.
|
130
|
-
* Removed RGB instance variable; color is managed internally as HSL floating
|
131
|
-
point.
|
132
|
-
* Tests!
|
133
|
-
|
134
|
-
== color-tools 1.3.0
|
135
|
-
|
136
|
-
* Added new metallic colours suggested by Jim Freeze <jfn@freeze.org>. These
|
137
|
-
are in the namespace Color::Metallic.
|
138
|
-
* Colours that were defined in the Color namespace (e.g., Color::Red,
|
139
|
-
Color::AliceBlue) are now defined in Color::RGB (e.g., Color::RGB::Red,
|
140
|
-
Color::RGB::AliceBlue). They are added back to the Color namespace on the
|
141
|
-
first use of the old colours and a warning is printed. In version 1.4, this
|
142
|
-
warning will be printed on every use of the old colours. In version 1.5,
|
143
|
-
the backwards compatible support for colours like Color::Red will be
|
144
|
-
removed completely.
|
145
|
-
* Added the Color::CSS module, color/css or Color::CSS that provides a name
|
146
|
-
lookup of Color::RGB-namespaced constants with Color::CSS[name]. Most of
|
147
|
-
these colours (which are mirrored from the Color::RGB default colours) are
|
148
|
-
only "officially" recognised under the CSS3 colour module or SVG.
|
149
|
-
* Added the Color::HSL colour space and some helper utilities to Color::RGB
|
150
|
-
for colour manipulation using the HSL value.
|
151
|
-
* Controlled internal value replacement to be between 0 and 1 for all
|
152
|
-
colours.
|
153
|
-
* Updated Color::Palette::Gimp to more meaningfully deal with duplicate named
|
154
|
-
colours. Named colours now return an array of colours.
|
155
|
-
* Indicated the plans for some methods and constants out to color-tools 2.0.
|
156
|
-
* Added unit tests and fixed a number of hidden bugs because of them.
|
157
|
-
|
158
|
-
== color-tools 1.2.0
|
159
|
-
* Changed installer from a custom-written install.rb to setup.rb
|
160
|
-
3.3.1-modified.
|
161
|
-
* Added Color::GreyScale (or Color::GrayScale).
|
162
|
-
* Added Color::YIQ. This colour definition is incomplete; it does not have
|
163
|
-
conversions from YIQ to other colour spaces.
|
164
|
-
|
165
|
-
== color-tools 1.1.0
|
166
|
-
|
167
|
-
* Added color/palette/gimp to support the reading and use of GIMP color
|
168
|
-
palettes.
|
169
|
-
|
170
|
-
== color-tools 1.0.0
|
171
|
-
|
172
|
-
* Initial release.
|
data/Licence.rdoc
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
== Licence
|
2
|
-
|
3
|
-
This software is available under an MIT-style licence.
|
4
|
-
|
5
|
-
* Copyright 2005–2014 Austin Ziegler, Matt Lyon, and other contributors
|
6
|
-
|
7
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
8
|
-
this software and associated documentation files (the "Software"), to deal in
|
9
|
-
the Software without restriction, including without limitation the rights to
|
10
|
-
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
11
|
-
of the Software, and to permit persons to whom the Software is furnished to do
|
12
|
-
so, subject to the following conditions:
|
13
|
-
|
14
|
-
* The names of its contributors may not be used to endorse or promote
|
15
|
-
products derived from this software without specific prior written
|
16
|
-
permission.
|
17
|
-
|
18
|
-
The above copyright notice and this permission notice shall be included in all
|
19
|
-
copies or substantial portions of the Software.
|
20
|
-
|
21
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
22
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
23
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
24
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
25
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
26
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
27
|
-
SOFTWARE.
|
data/README.rdoc
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
= Color
|
2
|
-
|
3
|
-
home :: https://github.com/halostatue/color
|
4
|
-
code :: https://github.com/halostatue/color
|
5
|
-
bugs :: https://github.com/halostatue/color/issues
|
6
|
-
rdoc :: http://rubydoc.info/github/halostatue/color
|
7
|
-
continuous integration :: {<img src="https://travis-ci.org/halostatue/color.png" />}[https://travis-ci.org/halostatue/color]
|
8
|
-
test coverage :: {<img src="https://coveralls.io/repos/halostatue/color/badge.png" alt="Coverage Status" />}[https://coveralls.io/r/halostatue/color]
|
9
|
-
|
10
|
-
== Description
|
11
|
-
|
12
|
-
Color is a Ruby library to provide basic RGB, CMYK, HSL, and other colourspace
|
13
|
-
manipulation support to applications that require it. It also provides 152
|
14
|
-
named RGB colours (184 with spelling variations) that are commonly supported in
|
15
|
-
HTML, SVG, and X11 applications. A technique for generating monochromatic
|
16
|
-
contrasting palettes is also included.
|
17
|
-
|
18
|
-
The Color library performs purely mathematical manipulation of the colours
|
19
|
-
based on colour theory without reference to colour profiles (such as sRGB or
|
20
|
-
Adobe RGB). For most purposes, when working with RGB and HSL colour spaces,
|
21
|
-
this won't matter. Absolute colour spaces (like CIE L*a*b* and XYZ) and cannot
|
22
|
-
be reliably converted to relative colour spaces (like RGB) without colour
|
23
|
-
profiles.
|
24
|
-
|
25
|
-
Color version 1.7.1 adds Color::RGB::RebeccaPurple for the colour #663399 in
|
26
|
-
honour of Rebecca Meyer, the daughter of Eric Meyer, who passed away on the 7th
|
27
|
-
of June, 2014. Her favourite colour was purple.
|
28
|
-
{rebeccapurple}[http://meyerweb.com/eric/thoughts/2014/06/19/rebeccapurple/]
|
29
|
-
|
30
|
-
Barring bugs introduced in this release, this is the last version of color that
|
31
|
-
supports Ruby 1.8, so make sure that your gem specification is set properly (to
|
32
|
-
<tt>~> 1.6</tt>) if that matters for your application.
|
33
|
-
|
34
|
-
== History
|
35
|
-
|
36
|
-
Color is the result of a project merge between color.rb 0.1.0 by
|
37
|
-
Matt Lyon and color-tools 1.3 by Austin Ziegler. Please see History.txt for
|
38
|
-
details on the changes this merge brings.
|
39
|
-
|
40
|
-
Color::Palette::MonoContrast was developed based on techniques described by
|
41
|
-
Andy “Malarkey” Clarke[1], implemented in JavaScript by Steve G. Chipman at
|
42
|
-
SlayerOffice[2] and by Patrick Fitzgerald of BarelyFitz[3] in PHP.
|
43
|
-
|
44
|
-
[1] http://www.stuffandnonsense.co.uk/archives/creating_colour_palettes.html
|
45
|
-
[2] http://slayeroffice.com/tools/color_palette/
|
46
|
-
[3] http://www.barelyfitz.com/projects/csscolor/
|
47
|
-
|
48
|
-
:include: Contributing.rdoc
|
49
|
-
|
50
|
-
:include: Licence.rdoc
|
data/lib/color/css.rb
DELETED
@@ -1,260 +0,0 @@
|
|
1
|
-
require 'color/palette'
|
2
|
-
|
3
|
-
# A class that can read an Adobe Color palette file (used for Photoshop
|
4
|
-
# swatches) and provide a Hash-like interface to the contents. Not all
|
5
|
-
# colour formats in ACO files are supported. Based largely off the
|
6
|
-
# information found by Larry Tesler[http://www.nomodes.com/aco.html].
|
7
|
-
#
|
8
|
-
# Not all Adobe Color files have named colours; all named entries are
|
9
|
-
# returned as an array.
|
10
|
-
#
|
11
|
-
# pal = Color::Palette::AdobeColor.from_file(my_aco_palette)
|
12
|
-
# pal[0] => Color::RGB<...>
|
13
|
-
# pal["white"] => [ Color::RGB<...> ]
|
14
|
-
# pal["unknown"] => [ Color::RGB<...>, Color::RGB<...>, ... ]
|
15
|
-
#
|
16
|
-
# AdobeColor palettes are always indexable by insertion order (an integer
|
17
|
-
# key).
|
18
|
-
#
|
19
|
-
# Version 2 palettes use UTF-16 colour names.
|
20
|
-
class Color::Palette::AdobeColor
|
21
|
-
include Enumerable
|
22
|
-
|
23
|
-
class << self
|
24
|
-
# Create an AdobeColor palette object from the named file.
|
25
|
-
def from_file(filename)
|
26
|
-
File.open(filename, "rb") { |io| Color::Palette::AdobeColor.from_io(io) }
|
27
|
-
end
|
28
|
-
|
29
|
-
# Create an AdobeColor palette object from the provided IO.
|
30
|
-
def from_io(io)
|
31
|
-
Color::Palette::AdobeColor.new(io.read)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
# Returns statistics about the nature of the colours loaded.
|
36
|
-
attr_reader :statistics
|
37
|
-
# Contains the "lost" colours in the palette. These colours could not be
|
38
|
-
# properly loaded (e.g., L*a*b* is not supported by Color, so it is
|
39
|
-
# "lost") or are not understood by the algorithms.
|
40
|
-
attr_reader :lost
|
41
|
-
|
42
|
-
# Use this to convert the unsigned word to the signed word, if necessary.
|
43
|
-
UwToSw = proc { |n| (n >= (2 ** 16)) ? n - (2 ** 32) : n } #:nodoc:
|
44
|
-
|
45
|
-
# Create a new AdobeColor palette from the palette file as a string.
|
46
|
-
def initialize(palette)
|
47
|
-
@colors = []
|
48
|
-
@names = {}
|
49
|
-
@statistics = Hash.new(0)
|
50
|
-
@lost = []
|
51
|
-
@order = []
|
52
|
-
@version = nil
|
53
|
-
|
54
|
-
class << palette
|
55
|
-
def readwords(count = 1)
|
56
|
-
@offset ||= 0
|
57
|
-
raise IndexError if @offset >= self.size
|
58
|
-
val = self[@offset, count * 2]
|
59
|
-
raise IndexError if val.nil? or val.size < (count * 2)
|
60
|
-
val = val.unpack("n" * count)
|
61
|
-
@offset += count * 2
|
62
|
-
val
|
63
|
-
end
|
64
|
-
|
65
|
-
def readutf16(count = 1)
|
66
|
-
@offset ||= 0
|
67
|
-
raise IndexError if @offset >= self.size
|
68
|
-
val = self[@offset, count * 2]
|
69
|
-
raise IndexError if val.nil? or val.size < (count * 2)
|
70
|
-
@offset += count * 2
|
71
|
-
val
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
@version, count = palette.readwords 2
|
76
|
-
|
77
|
-
raise "Unknown AdobeColor palette version #@version." unless @version.between?(1, 2)
|
78
|
-
|
79
|
-
count.times do
|
80
|
-
space, w, x, y, z = palette.readwords 5
|
81
|
-
name = nil
|
82
|
-
if @version == 2
|
83
|
-
raise IndexError unless palette.readwords == [ 0 ]
|
84
|
-
len = palette.readwords
|
85
|
-
name = palette.readutf16(len[0] - 1)
|
86
|
-
raise IndexError unless palette.readwords == [ 0 ]
|
87
|
-
end
|
88
|
-
|
89
|
-
color = case space
|
90
|
-
when 0 then # RGB
|
91
|
-
@statistics[:rgb] += 1
|
92
|
-
|
93
|
-
Color::RGB.new(w / 256, x / 256, y / 256)
|
94
|
-
when 1 then # HS[BV] -- Convert to RGB
|
95
|
-
@statistics[:hsb] += 1
|
96
|
-
|
97
|
-
h = w / 65535.0
|
98
|
-
s = x / 65535.0
|
99
|
-
v = y / 65535.0
|
100
|
-
|
101
|
-
if defined?(Color::HSB)
|
102
|
-
Color::HSB.from_fraction(h, s, v)
|
103
|
-
else
|
104
|
-
@statistics[:converted] += 1
|
105
|
-
if Color.near_zero_or_less?(s)
|
106
|
-
Color::RGB.from_fraction(v, v, v)
|
107
|
-
else
|
108
|
-
if Color.near_one_or_more?(h)
|
109
|
-
vh = 0
|
110
|
-
else
|
111
|
-
vh = h * 6.0
|
112
|
-
end
|
113
|
-
|
114
|
-
vi = vh.floor
|
115
|
-
v1 = v.to_f * (1 - s.to_f)
|
116
|
-
v2 = v.to_f * (1 - s.to_f * (vh - vi))
|
117
|
-
v3 = v.to_f * (1 - s.to_f * (1 - (vh - vi)))
|
118
|
-
|
119
|
-
case vi
|
120
|
-
when 0 then Color::RGB.from_fraction(v, v3, v1)
|
121
|
-
when 1 then Color::RGB.from_fraction(v2, v, v1)
|
122
|
-
when 2 then Color::RGB.from_fraction(v1, v, v3)
|
123
|
-
when 3 then Color::RGB.from_fraction(v1, v2, v)
|
124
|
-
when 4 then Color::RGB.from_fraction(v3, v1, v)
|
125
|
-
else Color::RGB.from_fraction(v, v1, v2)
|
126
|
-
end
|
127
|
-
end
|
128
|
-
end
|
129
|
-
when 2 then # CMYK
|
130
|
-
@statistics[:cmyk] += 1
|
131
|
-
Color::CMYK.from_percent(100 - (w / 655.35),
|
132
|
-
100 - (x / 655.35),
|
133
|
-
100 - (y / 655.35),
|
134
|
-
100 - (z / 655.35))
|
135
|
-
when 7 then # L*a*b*
|
136
|
-
@statistics[:lab] += 1
|
137
|
-
|
138
|
-
l = [w, 10000].min / 100.0
|
139
|
-
a = [[-12800, UwToSw[x]].max, 12700].min / 100.0
|
140
|
-
b = [[-12800, UwToSw[x]].max, 12700].min / 100.0
|
141
|
-
|
142
|
-
if defined? Color::Lab
|
143
|
-
Color::Lab.new(l, a, b)
|
144
|
-
else
|
145
|
-
[ space, w, x, y, z ]
|
146
|
-
end
|
147
|
-
when 8 then # Grayscale
|
148
|
-
@statistics[:gray] += 1
|
149
|
-
|
150
|
-
g = [w, 10000].min / 100.0
|
151
|
-
Color::GrayScale.new(g)
|
152
|
-
when 9 then # Wide CMYK
|
153
|
-
@statistics[:wcmyk] += 1
|
154
|
-
|
155
|
-
c = [w, 10000].min / 100.0
|
156
|
-
m = [x, 10000].min / 100.0
|
157
|
-
y = [y, 10000].min / 100.0
|
158
|
-
k = [z, 10000].min / 100.0
|
159
|
-
Color::CMYK.from_percent(c, m, y, k)
|
160
|
-
else
|
161
|
-
@statistics[space] += 1
|
162
|
-
[ space, w, x, y, z ]
|
163
|
-
end
|
164
|
-
|
165
|
-
@order << [ color, name ]
|
166
|
-
|
167
|
-
if color.kind_of? Array
|
168
|
-
@lost << color
|
169
|
-
else
|
170
|
-
@colors << color
|
171
|
-
|
172
|
-
if name
|
173
|
-
@names[name] ||= []
|
174
|
-
@names[name] << color
|
175
|
-
end
|
176
|
-
end
|
177
|
-
end
|
178
|
-
end
|
179
|
-
|
180
|
-
# Provides the colour or colours at the provided selectors.
|
181
|
-
def values_at(*selectors)
|
182
|
-
@colors.values_at(*selectors)
|
183
|
-
end
|
184
|
-
|
185
|
-
# If a Numeric +key+ is provided, the single colour value at that position
|
186
|
-
# will be returned. If a String +key+ is provided, the colour set (an
|
187
|
-
# array) for that colour name will be returned.
|
188
|
-
def [](key)
|
189
|
-
if key.kind_of?(Numeric)
|
190
|
-
@colors[key]
|
191
|
-
else
|
192
|
-
@names[key]
|
193
|
-
end
|
194
|
-
end
|
195
|
-
|
196
|
-
# Loops through each colour.
|
197
|
-
def each
|
198
|
-
@colors.each { |el| yield el }
|
199
|
-
end
|
200
|
-
|
201
|
-
# Loops through each named colour set.
|
202
|
-
def each_name #:yields color_name, color_set:#
|
203
|
-
@names.each { |color_name, color_set| yield color_name, color_set }
|
204
|
-
end
|
205
|
-
|
206
|
-
def size
|
207
|
-
@colors.size
|
208
|
-
end
|
209
|
-
|
210
|
-
attr_reader :version
|
211
|
-
|
212
|
-
def to_aco(version = @version) #:nodoc:
|
213
|
-
res = ""
|
214
|
-
|
215
|
-
res << [ version, @order.size ].pack("nn")
|
216
|
-
|
217
|
-
@order.each do |cnpair|
|
218
|
-
color, name = *cnpair
|
219
|
-
|
220
|
-
# Note: HSB and CMYK formats are lost by the conversions performed on
|
221
|
-
# import. They are turned into RGB and WCMYK, respectively.
|
222
|
-
|
223
|
-
cstr = case color
|
224
|
-
when Array
|
225
|
-
color
|
226
|
-
when Color::RGB
|
227
|
-
r = [(color.red * 256).round, 65535].min
|
228
|
-
g = [(color.green * 256).round, 65535].min
|
229
|
-
b = [(color.blue * 256).round, 65535].min
|
230
|
-
[ 0, r, g, b, 0 ]
|
231
|
-
when Color::GrayScale
|
232
|
-
g = [(color.gray * 100).round, 10000].min
|
233
|
-
[ 8, g, 0, 0, 0 ]
|
234
|
-
when Color::CMYK
|
235
|
-
c = [(color.cyan * 100).round, 10000].min
|
236
|
-
m = [(color.magenta * 100).round, 10000].min
|
237
|
-
y = [(color.yellow * 100).round, 10000].min
|
238
|
-
k = [(color.black * 100).round, 10000].min
|
239
|
-
[ 9, c, m, y, k ]
|
240
|
-
end
|
241
|
-
cstr = cstr.pack("nnnnn")
|
242
|
-
|
243
|
-
nstr = ""
|
244
|
-
|
245
|
-
if version == 2
|
246
|
-
if (name.size / 2 * 2) == name.size # only where s[0] == byte!
|
247
|
-
nstr << [ 0, (name.size / 2) + 1 ].pack("nn")
|
248
|
-
nstr << name
|
249
|
-
nstr << [ 0 ].pack("n")
|
250
|
-
else
|
251
|
-
nstr << [ 0, 1, 0 ].pack("nnn")
|
252
|
-
end
|
253
|
-
end
|
254
|
-
|
255
|
-
res << cstr << nstr
|
256
|
-
end
|
257
|
-
|
258
|
-
res
|
259
|
-
end
|
260
|
-
end
|
data/lib/color/palette/gimp.rb
DELETED
@@ -1,104 +0,0 @@
|
|
1
|
-
require 'color/palette'
|
2
|
-
|
3
|
-
# A class that can read a GIMP (GNU Image Manipulation Program) palette file
|
4
|
-
# and provide a Hash-like interface to the contents. GIMP colour palettes
|
5
|
-
# are RGB values only.
|
6
|
-
#
|
7
|
-
# Because two or more entries in a GIMP palette may have the same name, all
|
8
|
-
# named entries are returned as an array.
|
9
|
-
#
|
10
|
-
# pal = Color::Palette::Gimp.from_file(my_gimp_palette)
|
11
|
-
# pal[0] => Color::RGB<...>
|
12
|
-
# pal["white"] => [ Color::RGB<...> ]
|
13
|
-
# pal["unknown"] => [ Color::RGB<...>, Color::RGB<...>, ... ]
|
14
|
-
#
|
15
|
-
# GIMP Palettes are always indexable by insertion order (an integer key).
|
16
|
-
class Color::Palette::Gimp
|
17
|
-
include Enumerable
|
18
|
-
|
19
|
-
class << self
|
20
|
-
# Create a GIMP palette object from the named file.
|
21
|
-
def from_file(filename)
|
22
|
-
File.open(filename, "rb") { |io| Color::Palette::Gimp.from_io(io) }
|
23
|
-
end
|
24
|
-
|
25
|
-
# Create a GIMP palette object from the provided IO.
|
26
|
-
def from_io(io)
|
27
|
-
Color::Palette::Gimp.new(io.read)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
# Create a new GIMP palette from the palette file as a string.
|
32
|
-
def initialize(palette)
|
33
|
-
@colors = []
|
34
|
-
@names = {}
|
35
|
-
@valid = false
|
36
|
-
@name = "(unnamed)"
|
37
|
-
|
38
|
-
palette.split($/).each do |line|
|
39
|
-
line.chomp!
|
40
|
-
line.gsub!(/\s*#.*\Z/, '')
|
41
|
-
|
42
|
-
next if line.empty?
|
43
|
-
|
44
|
-
if line =~ /\AGIMP Palette\Z/
|
45
|
-
@valid = true
|
46
|
-
next
|
47
|
-
end
|
48
|
-
|
49
|
-
info = /(\w+):\s(.*$)/.match(line)
|
50
|
-
if info
|
51
|
-
@name = info.captures[1] if info.captures[0] =~ /name/i
|
52
|
-
next
|
53
|
-
end
|
54
|
-
|
55
|
-
line.gsub!(/^\s+/, '')
|
56
|
-
data = line.split(/\s+/, 4)
|
57
|
-
name = data.pop.strip
|
58
|
-
data.map! { |el| el.to_i }
|
59
|
-
|
60
|
-
color = Color::RGB.new(*data)
|
61
|
-
|
62
|
-
@colors << color
|
63
|
-
@names[name] ||= []
|
64
|
-
@names[name] << color
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
# Provides the colour or colours at the provided selectors.
|
69
|
-
def values_at(*selectors)
|
70
|
-
@colors.values_at(*selectors)
|
71
|
-
end
|
72
|
-
|
73
|
-
# If a Numeric +key+ is provided, the single colour value at that position
|
74
|
-
# will be returned. If a String +key+ is provided, the colour set (an
|
75
|
-
# array) for that colour name will be returned.
|
76
|
-
def [](key)
|
77
|
-
if key.kind_of?(Numeric)
|
78
|
-
@colors[key]
|
79
|
-
else
|
80
|
-
@names[key]
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
# Loops through each colour.
|
85
|
-
def each
|
86
|
-
@colors.each { |el| yield el }
|
87
|
-
end
|
88
|
-
|
89
|
-
# Loops through each named colour set.
|
90
|
-
def each_name #:yields color_name, color_set:#
|
91
|
-
@names.each { |color_name, color_set| yield color_name, color_set }
|
92
|
-
end
|
93
|
-
|
94
|
-
# Returns true if this is believed to be a valid GIMP palette.
|
95
|
-
def valid?
|
96
|
-
@valid
|
97
|
-
end
|
98
|
-
|
99
|
-
def size
|
100
|
-
@colors.size
|
101
|
-
end
|
102
|
-
|
103
|
-
attr_reader :name
|
104
|
-
end
|