23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/color/palette/gimp.rb', line 23
def initialize(palette)
@colors = {}
@valid = false
@name = "(unnamed)"
index = 0
collision = {}
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
data.map! { |el| el.to_i }
@colors[index] = Color::RGB.new(*data)
if @colors.has_key?(name)
collision[name] = true
else
@colors[name] = @colors[index]
end
end
collision.each_key { |key| @colors.delete_at(key) }
end
|