ase 1.0.3 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -3
- data/examples/read.rb +7 -0
- data/lib/ase.rb +5 -2
- data/lib/ase/color.rb +2 -54
- data/lib/ase/color_modes/cmyk.rb +44 -0
- data/lib/ase/color_modes/gray.rb +38 -0
- data/lib/ase/color_modes/rgb.rb +74 -0
- data/lib/ase/palette.rb +6 -0
- data/lib/ase/reader.rb +32 -23
- data/lib/ase/version.rb +1 -1
- data/lib/ase/writer.rb +32 -26
- data/spec/ase_spec.rb +4 -36
- data/spec/color_spec.rb +96 -0
- data/spec/file_spec.rb +16 -7
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 203efd29143fde0efedd8fe1b9eb3f0434393842
|
4
|
+
data.tar.gz: da48c549c3ee08b188d2df5ebb3085d8767780c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5fc9481aac21f3cbaeec567f27083b4629965a19ada5320c80d13f6f819831294c32b805ba18932ea7dc6f65b62d6890dfa0c951e05eb3e4eb804b557dedfd3b
|
7
|
+
data.tar.gz: dff49640e93873d3f06c2115942008d4491d79ed1fe713ff40d1ebbe1f5e3ca8190db8f846709fc913099d6daf1043c38e7e3296c22fd6fcf3829fb9102f1f70
|
data/README.md
CHANGED
@@ -24,8 +24,10 @@ Or install it yourself as:
|
|
24
24
|
doc = ASE.new
|
25
25
|
|
26
26
|
palette = ASE::Palette.new('My Colors')
|
27
|
-
palette.add 'Black', ASE::Color.new(0, 0, 0)
|
28
|
-
palette.add 'Red', ASE::Color.from_hex('#ff0000')
|
27
|
+
palette.add 'Black', ASE::Color::RGB.new(0, 0, 0)
|
28
|
+
palette.add 'Red', ASE::Color::RGB.from_hex('#ff0000')
|
29
|
+
palette.add 'Blue', ASE::Color::CMYK.new(0.92, 0.68, 0.2, 0)
|
30
|
+
palette.add 'Light Gray', ASE::Color::Gray.new(0.75)
|
29
31
|
|
30
32
|
doc << palette
|
31
33
|
doc.to_file('path/to/file.ase')
|
@@ -36,13 +38,20 @@ doc.to_file('path/to/file.ase')
|
|
36
38
|
``` ruby
|
37
39
|
doc = ASE.from_file('path/to/file.ase')
|
38
40
|
|
39
|
-
puts doc['My Colors']['Red'].
|
41
|
+
puts doc['My Colors']['Red'].to_a
|
40
42
|
#=> [255, 0, 0]
|
41
43
|
|
42
44
|
puts doc['My Colors'].size
|
43
45
|
#=> 2
|
44
46
|
```
|
45
47
|
|
48
|
+
## Notes
|
49
|
+
|
50
|
+
* If the ASE file does not define a palette, and instead simply lists colors, ASE.rb will use `:default` as the palette name.
|
51
|
+
* ASE.rb does not support LAB colors yet.
|
52
|
+
* Because reading & writing CMYK/LAB colors is dependent on your color profile, the output might be different than what is shown in an Adobe application. Color profile support might be added in the future.
|
53
|
+
* Gray and Grey are interchangeable in ASE.rb
|
54
|
+
|
46
55
|
## Contributing
|
47
56
|
|
48
57
|
1. Fork it
|
data/examples/read.rb
ADDED
data/lib/ase.rb
CHANGED
@@ -1,13 +1,16 @@
|
|
1
1
|
dir_root = File.dirname(File.absolute_path(__FILE__))
|
2
2
|
|
3
3
|
require dir_root + "/ase/version"
|
4
|
-
|
4
|
+
|
5
|
+
require dir_root + "/ase/color_modes/cmyk"
|
6
|
+
require dir_root + "/ase/color_modes/gray"
|
7
|
+
require dir_root + "/ase/color_modes/rgb"
|
8
|
+
|
5
9
|
require dir_root + "/ase/file"
|
6
10
|
require dir_root + "/ase/palette"
|
7
11
|
require dir_root + "/ase/reader"
|
8
12
|
require dir_root + "/ase/writer"
|
9
13
|
|
10
|
-
|
11
14
|
class ASE
|
12
15
|
include Reader
|
13
16
|
include Writer
|
data/lib/ase/color.rb
CHANGED
@@ -2,60 +2,8 @@
|
|
2
2
|
# given color.
|
3
3
|
class ASE
|
4
4
|
class Color
|
5
|
-
|
6
|
-
|
7
|
-
args = args.first if args.length == 1
|
8
|
-
self.new *args
|
9
|
-
end
|
10
|
-
alias :from_rgb :from_rgba
|
11
|
-
|
12
|
-
def from_hex(hex)
|
13
|
-
self.new *hex.gsub('#', '').scan(/../).map { |c| c.to_i(16) }
|
14
|
-
end
|
5
|
+
def self.factory(mode, *args)
|
6
|
+
const_get(mode.strip).new(*args)
|
15
7
|
end
|
16
|
-
|
17
|
-
attr_accessor :r, :g, :b, :a
|
18
|
-
|
19
|
-
# We always internally store the color as RGBA.
|
20
|
-
def initialize(r, g, b, a = 255)
|
21
|
-
@r = r
|
22
|
-
@g = g
|
23
|
-
@b = b
|
24
|
-
@a = a
|
25
|
-
end
|
26
|
-
|
27
|
-
def to_rgba
|
28
|
-
[@r, @g, @b, @a]
|
29
|
-
end
|
30
|
-
|
31
|
-
def to_rgb
|
32
|
-
[@r, @g, @b]
|
33
|
-
end
|
34
|
-
|
35
|
-
def to_css
|
36
|
-
"rgba(#{r}, #{g}, #{b}, #{a})"
|
37
|
-
end
|
38
|
-
|
39
|
-
def [](i)
|
40
|
-
[@r, @g, @b, @a][i]
|
41
|
-
end
|
42
|
-
|
43
|
-
def to_hex(incl_hash=true, incl_alpha=false)
|
44
|
-
hex = incl_hash ? '#' : ''
|
45
|
-
colors = [@r, @g, @b]
|
46
|
-
colors << @a if incl_alpha
|
47
|
-
|
48
|
-
colors.each do |c|
|
49
|
-
color = c.to_s(16)
|
50
|
-
if c < 16
|
51
|
-
hex << "0#{color}"
|
52
|
-
else
|
53
|
-
hex << color
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
return hex
|
58
|
-
end
|
59
|
-
alias :to_s :to_hex
|
60
8
|
end
|
61
9
|
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require_relative '../color'
|
2
|
+
|
3
|
+
class ASE
|
4
|
+
class Color
|
5
|
+
class CMYK
|
6
|
+
attr_accessor :c, :m, :y, :k
|
7
|
+
|
8
|
+
def initialize(c=0, m=0, y=0, k=0)
|
9
|
+
@c = c
|
10
|
+
@m = m
|
11
|
+
@y = y
|
12
|
+
@k = k
|
13
|
+
end
|
14
|
+
|
15
|
+
def read!(file)
|
16
|
+
@c, @m, @y, @k = 4.times.map do
|
17
|
+
file.read(4).unpack('g')[0].round(4)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def write!(file)
|
22
|
+
file.write 'CMYK'
|
23
|
+
to_a.each { |c| file.write [c].pack('g') }
|
24
|
+
end
|
25
|
+
|
26
|
+
def to_rgb
|
27
|
+
r = (1 - (@c * (1 - @k) + @k)) * 255
|
28
|
+
g = (1 - (@m * (1 - @k) + @k)) * 255
|
29
|
+
b = (1 - (@y * (1 - @k) + @k)) * 255
|
30
|
+
|
31
|
+
# Clamp
|
32
|
+
r = [0, r, 255].sort[1].to_i
|
33
|
+
g = [0, g, 255].sort[1].to_i
|
34
|
+
b = [0, b, 255].sort[1].to_i
|
35
|
+
|
36
|
+
RGB.new(r, g, b)
|
37
|
+
end
|
38
|
+
|
39
|
+
def to_a
|
40
|
+
[@c, @m, @y, @k]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require_relative '../color'
|
2
|
+
|
3
|
+
class ASE
|
4
|
+
class Color
|
5
|
+
class Gray
|
6
|
+
attr_accessor :value
|
7
|
+
|
8
|
+
def initialize(value=0)
|
9
|
+
@value = value
|
10
|
+
end
|
11
|
+
|
12
|
+
def read!(file)
|
13
|
+
@value = file.read(4).unpack('g')[0].round(4)
|
14
|
+
end
|
15
|
+
|
16
|
+
def write!(file)
|
17
|
+
file.write('Gray')
|
18
|
+
to_a.each { |c| file.write [c].pack('g') }
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_rgb
|
22
|
+
RGB.new(*([rgb_value] * 3))
|
23
|
+
end
|
24
|
+
|
25
|
+
def to_a
|
26
|
+
[@value]
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def rgb_value
|
32
|
+
(@value * 255).to_i
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class Grey < Gray; end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require_relative '../color'
|
2
|
+
|
3
|
+
class ASE
|
4
|
+
class Color
|
5
|
+
class RGB
|
6
|
+
attr_accessor :r, :g, :b
|
7
|
+
|
8
|
+
class << self
|
9
|
+
def from_rgba(*args)
|
10
|
+
args = args.first if args.length == 1
|
11
|
+
self.new *args
|
12
|
+
end
|
13
|
+
alias :from_rgb :from_rgba
|
14
|
+
|
15
|
+
def from_hex(hex)
|
16
|
+
self.new *hex
|
17
|
+
.gsub('#', '')[0...6]
|
18
|
+
.scan(/../)
|
19
|
+
.map { |c| c.to_i(16) }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def initialize(r=0, g=0, b=0)
|
24
|
+
@r = r
|
25
|
+
@g = g
|
26
|
+
@b = b
|
27
|
+
end
|
28
|
+
|
29
|
+
def read!(file)
|
30
|
+
@r, @g, @b = 3.times.map do |c|
|
31
|
+
(file.read(4).unpack('g')[0] * 255).to_i
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def write!(file)
|
36
|
+
file.write 'RGB '
|
37
|
+
to_a.each { |c| file.write [c.to_f / 255].pack('g') }
|
38
|
+
end
|
39
|
+
|
40
|
+
def to_rgb
|
41
|
+
self
|
42
|
+
end
|
43
|
+
|
44
|
+
def to_a
|
45
|
+
[@r, @g, @b]
|
46
|
+
end
|
47
|
+
|
48
|
+
def to_css
|
49
|
+
"rgba(#{r}, #{g}, #{b}, #{255})"
|
50
|
+
end
|
51
|
+
|
52
|
+
def [](i)
|
53
|
+
[@r, @g, @b, 255][i]
|
54
|
+
end
|
55
|
+
|
56
|
+
def to_hex(incl_hash=true)
|
57
|
+
hex = incl_hash ? '#' : ''
|
58
|
+
colors = [@r, @g, @b]
|
59
|
+
|
60
|
+
colors.each do |c|
|
61
|
+
color = c.to_s(16)
|
62
|
+
if c < 16
|
63
|
+
hex << "0#{color}"
|
64
|
+
else
|
65
|
+
hex << color
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
return hex
|
70
|
+
end
|
71
|
+
alias :to_s :to_hex
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
data/lib/ase/palette.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
class ASE
|
2
2
|
class Palette
|
3
|
+
include Enumerable
|
4
|
+
|
3
5
|
attr_accessor :name, :colors
|
4
6
|
|
5
7
|
def initialize(name)
|
@@ -26,6 +28,10 @@ class ASE
|
|
26
28
|
end
|
27
29
|
alias :size :length
|
28
30
|
|
31
|
+
def each(&block)
|
32
|
+
@colors.each(&block)
|
33
|
+
end
|
34
|
+
|
29
35
|
def method_missing(method, *args, &block)
|
30
36
|
if @colors.has_key?(method.to_s)
|
31
37
|
return @colors[method.to_s]
|
data/lib/ase/reader.rb
CHANGED
@@ -30,45 +30,54 @@ class ASE
|
|
30
30
|
|
31
31
|
block_count = @file.read_ulong
|
32
32
|
|
33
|
-
|
33
|
+
@palette = Palette.new(:default)
|
34
|
+
read_section until @file.eof?
|
35
|
+
|
36
|
+
add_palette @palette if @palettes.length == 0
|
37
|
+
@palette = nil
|
34
38
|
|
35
39
|
@file.close
|
36
40
|
end
|
37
41
|
|
38
42
|
private
|
39
43
|
|
40
|
-
def
|
44
|
+
def read_section
|
41
45
|
block_start = @file.read_ushort
|
42
46
|
|
47
|
+
case block_start
|
48
|
+
when 0xC001 then start_palette
|
49
|
+
when 1 then read_color
|
50
|
+
when 0xC002 then end_palette
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def start_palette
|
43
55
|
title_block_size = @file.read_ulong
|
44
56
|
title = @file.read_string
|
45
57
|
|
46
|
-
palette = Palette.new(title)
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
58
|
+
@palette = Palette.new(title)
|
59
|
+
end
|
60
|
+
|
61
|
+
def end_palette
|
62
|
+
# Group end block
|
63
|
+
@file.seek 4, IO::SEEK_CUR
|
64
|
+
add_palette @palette
|
52
65
|
|
53
|
-
|
54
|
-
|
55
|
-
color_mode = @file.read(4)
|
66
|
+
@palette = Palette.new(:default)
|
67
|
+
end
|
56
68
|
|
57
|
-
|
58
|
-
|
59
|
-
|
69
|
+
def read_color
|
70
|
+
color_size = @file.read_ulong
|
71
|
+
color_name = @file.read_string
|
72
|
+
color_mode = @file.read(4)
|
60
73
|
|
61
|
-
|
74
|
+
color = Color.factory(color_mode)
|
75
|
+
color.read!(@file)
|
62
76
|
|
63
|
-
|
64
|
-
@file.seek 2, IO::SEEK_CUR
|
65
|
-
end
|
77
|
+
@palette.add color_name, color
|
66
78
|
|
67
|
-
#
|
68
|
-
@file.seek
|
69
|
-
|
70
|
-
add_palette palette
|
71
|
-
return true
|
79
|
+
# Null byte
|
80
|
+
@file.seek 2, IO::SEEK_CUR
|
72
81
|
end
|
73
82
|
end
|
74
83
|
end
|
data/lib/ase/version.rb
CHANGED
data/lib/ase/writer.rb
CHANGED
@@ -22,41 +22,47 @@ class ASE
|
|
22
22
|
@file.write_ulong(color_count + (palette_count * 2))
|
23
23
|
|
24
24
|
@palettes.each do |palette_name, palette|
|
25
|
-
|
26
|
-
|
25
|
+
write_palette(palette_name, palette)
|
26
|
+
end
|
27
27
|
|
28
|
-
|
29
|
-
|
28
|
+
@file.write_ulong 0 # Group end block
|
29
|
+
@file.close
|
30
|
+
end
|
30
31
|
|
31
|
-
|
32
|
-
@file.write_string palette_name
|
32
|
+
private
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
|
34
|
+
def write_palette(name, palette)
|
35
|
+
# Block start
|
36
|
+
@file.write_ushort 0xC001
|
37
37
|
|
38
|
-
|
39
|
-
|
38
|
+
# Block length (title is UTF-16 encoded)
|
39
|
+
@file.write_ulong 4 + (name.length * 2)
|
40
40
|
|
41
|
-
|
42
|
-
|
41
|
+
# Palette name
|
42
|
+
@file.write_string name.to_s
|
43
43
|
|
44
|
-
|
45
|
-
|
44
|
+
palette.colors.each do |name, color|
|
45
|
+
write_color(name, color)
|
46
|
+
end
|
46
47
|
|
47
|
-
|
48
|
-
|
49
|
-
rgb.each { |c| @file.write [c].pack('F').reverse }
|
50
|
-
|
51
|
-
# End of colors
|
52
|
-
@file.write_null_byte
|
53
|
-
end
|
48
|
+
@file.write_ushort 0xC002 # Group end
|
49
|
+
end
|
54
50
|
|
55
|
-
|
56
|
-
|
57
|
-
|
51
|
+
def write_color(name, color)
|
52
|
+
# Color start
|
53
|
+
@file.write_ushort 1
|
58
54
|
|
59
|
-
|
55
|
+
# Block length
|
56
|
+
@file.write_ulong 22 + (name.length * 2)
|
57
|
+
|
58
|
+
# Color name
|
59
|
+
@file.write_string name
|
60
|
+
|
61
|
+
# Color values
|
62
|
+
color.write!(@file)
|
63
|
+
|
64
|
+
# End of color
|
65
|
+
@file.write_null_byte
|
60
66
|
end
|
61
67
|
end
|
62
68
|
end
|
data/spec/ase_spec.rb
CHANGED
@@ -31,7 +31,7 @@ describe ASE do
|
|
31
31
|
|
32
32
|
it "can add and remove colors" do
|
33
33
|
palette = ASE::Palette.new('Test')
|
34
|
-
color = ASE::Color.new(255, 255, 255)
|
34
|
+
color = ASE::Color::RGB.new(255, 255, 255)
|
35
35
|
|
36
36
|
palette.add 'White', color
|
37
37
|
expect(palette.colors).to eq({
|
@@ -44,8 +44,8 @@ describe ASE do
|
|
44
44
|
|
45
45
|
it '#length returns the number of colors' do
|
46
46
|
palette = ASE::Palette.new('Test')
|
47
|
-
palette.add 'White', ASE::Color.new(255, 255, 255)
|
48
|
-
palette.add 'Black', ASE::Color.new(0, 0, 0)
|
47
|
+
palette.add 'White', ASE::Color::RGB.new(255, 255, 255)
|
48
|
+
palette.add 'Black', ASE::Color::RGB.new(0, 0, 0)
|
49
49
|
|
50
50
|
expect(palette.length).to be 2
|
51
51
|
expect(palette.size).to be 2
|
@@ -53,42 +53,10 @@ describe ASE do
|
|
53
53
|
|
54
54
|
it '#[] lets you access a specific color' do
|
55
55
|
palette = ASE::Palette.new('Test')
|
56
|
-
color = ASE::Color.new(255, 255, 255)
|
56
|
+
color = ASE::Color::RGB.new(255, 255, 255)
|
57
57
|
|
58
58
|
palette.add 'White', color
|
59
59
|
expect(palette['White']).to be color
|
60
60
|
end
|
61
61
|
end
|
62
|
-
|
63
|
-
describe ASE::Color do
|
64
|
-
it 'must be initialized with all RGB channels' do
|
65
|
-
expect {
|
66
|
-
ASE::Color.new
|
67
|
-
}.to raise_error
|
68
|
-
end
|
69
|
-
|
70
|
-
it 'sets a proper default for the alpha channel' do
|
71
|
-
color = ASE::Color.new(0, 0, 0)
|
72
|
-
expect(color.a).to be 255
|
73
|
-
end
|
74
|
-
|
75
|
-
it 'can be created with an RGB array' do
|
76
|
-
color1 = ASE::Color.from_rgba [0, 0, 0]
|
77
|
-
color2 = ASE::Color.from_rgb [0, 0, 0]
|
78
|
-
|
79
|
-
expect(color1.to_rgba).to eq([0, 0, 0, 255])
|
80
|
-
expect(color2.to_rgba).to eq([0, 0, 0, 255])
|
81
|
-
end
|
82
|
-
|
83
|
-
it 'can be created from a hex value' do
|
84
|
-
color1 = ASE::Color.from_hex('#000000')
|
85
|
-
color2 = ASE::Color.from_hex('000000')
|
86
|
-
color3 = ASE::Color.from_hex('#00000000')
|
87
|
-
|
88
|
-
rgba = [0, 0, 0, 255]
|
89
|
-
expect(color1.to_rgba).to eq(rgba)
|
90
|
-
expect(color2.to_rgba).to eq(rgba)
|
91
|
-
expect(color3.to_rgba).to eq([0, 0, 0, 0])
|
92
|
-
end
|
93
|
-
end
|
94
62
|
end
|
data/spec/color_spec.rb
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ASE::Color do
|
4
|
+
it "has a working factory method" do
|
5
|
+
expect(ASE::Color).to respond_to(:factory)
|
6
|
+
end
|
7
|
+
|
8
|
+
describe ASE::Color::RGB do
|
9
|
+
it "works with the color factory" do
|
10
|
+
expect(ASE::Color.factory('RGB')).to be_an_instance_of(ASE::Color::RGB)
|
11
|
+
expect(ASE::Color.factory('RGB ')).to be_an_instance_of(ASE::Color::RGB)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'can be created with an RGB array' do
|
15
|
+
color1 = ASE::Color::RGB.from_rgba [0, 0, 0]
|
16
|
+
color2 = ASE::Color::RGB.from_rgb [0, 0, 0]
|
17
|
+
|
18
|
+
expect(color1.to_a).to eq([0, 0, 0])
|
19
|
+
expect(color2.to_a).to eq([0, 0, 0])
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'can be created from a hex value' do
|
23
|
+
color1 = ASE::Color::RGB.from_hex('#000000')
|
24
|
+
color2 = ASE::Color::RGB.from_hex('000000')
|
25
|
+
color3 = ASE::Color::RGB.from_hex('#00000000')
|
26
|
+
|
27
|
+
rgb = [0, 0, 0]
|
28
|
+
expect(color1.to_a).to eq(rgb)
|
29
|
+
expect(color2.to_a).to eq(rgb)
|
30
|
+
expect(color3.to_a).to eq([0, 0, 0])
|
31
|
+
end
|
32
|
+
|
33
|
+
it "returns itself when calling to_rgb" do
|
34
|
+
color = ASE::Color::RGB.new(10, 10, 10)
|
35
|
+
expect(color.to_rgb).to be color
|
36
|
+
end
|
37
|
+
|
38
|
+
it "can be expressed as an array" do
|
39
|
+
color = ASE::Color::RGB.new(10, 10, 10)
|
40
|
+
expect(color.to_a).to eq([10, 10, 10])
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe ASE::Color::Gray do
|
45
|
+
it "works with the color factory" do
|
46
|
+
expect(ASE::Color.factory('Gray')).to be_an_instance_of(ASE::Color::Gray)
|
47
|
+
expect(ASE::Color.factory('Grey')).to be_an_instance_of(ASE::Color::Grey)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "has a readable value" do
|
51
|
+
color = ASE::Color::Gray.new(0.75)
|
52
|
+
expect(color.value).to eq(0.75)
|
53
|
+
end
|
54
|
+
|
55
|
+
it "can be expressed as an array" do
|
56
|
+
color = ASE::Color::Gray.new(0.75)
|
57
|
+
expect(color.to_a).to eq([0.75])
|
58
|
+
end
|
59
|
+
|
60
|
+
it "can be converted to RGB" do
|
61
|
+
color = ASE::Color::Gray.new(0.75)
|
62
|
+
rgb = color.to_rgb
|
63
|
+
|
64
|
+
rgb_value = (255 * 0.75).to_i
|
65
|
+
expect(rgb).to be_an_instance_of(ASE::Color::RGB)
|
66
|
+
expect(rgb.to_a).to eq([rgb_value] * 3)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe ASE::Color::CMYK do
|
71
|
+
it "works with the color factory" do
|
72
|
+
expect(ASE::Color.factory('CMYK')).to be_an_instance_of(ASE::Color::CMYK)
|
73
|
+
end
|
74
|
+
|
75
|
+
it "has readable values" do
|
76
|
+
color = ASE::Color::CMYK.new(0.1, 0.2, 0.3, 0.4)
|
77
|
+
expect(color.c).to eq(0.1)
|
78
|
+
expect(color.m).to eq(0.2)
|
79
|
+
expect(color.y).to eq(0.3)
|
80
|
+
expect(color.k).to eq(0.4)
|
81
|
+
end
|
82
|
+
|
83
|
+
it "can be expressed as an array" do
|
84
|
+
color = ASE::Color::CMYK.new(0.1, 0.2, 0.3, 0.4)
|
85
|
+
expect(color.to_a).to eq([0.1, 0.2, 0.3, 0.4])
|
86
|
+
end
|
87
|
+
|
88
|
+
it "can be converted to RGB" do
|
89
|
+
color = ASE::Color::CMYK.new(0.1, 0.2, 0.3, 0.4)
|
90
|
+
rgb = color.to_rgb
|
91
|
+
|
92
|
+
expect(rgb).to be_an_instance_of(ASE::Color::RGB)
|
93
|
+
expect(rgb.to_a).to eq([137, 122, 107])
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
data/spec/file_spec.rb
CHANGED
@@ -39,8 +39,8 @@ describe 'Files' do
|
|
39
39
|
|
40
40
|
it 'correctly reads the color values' do
|
41
41
|
doc = ASE.from_file('spec/files/control.ase')
|
42
|
-
expect(doc['Simple']['White'].
|
43
|
-
expect(doc['Simple']['Black'].
|
42
|
+
expect(doc['Simple']['White'].to_a).to eq([255, 255, 255])
|
43
|
+
expect(doc['Simple']['Black'].to_a).to eq([0, 0, 0])
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
@@ -49,8 +49,9 @@ describe 'Files' do
|
|
49
49
|
doc = ASE.new
|
50
50
|
|
51
51
|
palette = ASE::Palette.new('Test')
|
52
|
-
palette.add 'Red', ASE::Color.new(255, 0, 0)
|
53
|
-
palette.add 'Blue', ASE::Color.new(0, 0,
|
52
|
+
palette.add 'Red', ASE::Color::RGB.new(255, 0, 0)
|
53
|
+
palette.add 'Blue', ASE::Color::CMYK.new(0.91, 0.68, 0.2, 0)
|
54
|
+
palette.add 'Blah', ASE::Color::Gray.new(0.5)
|
54
55
|
|
55
56
|
doc << palette
|
56
57
|
|
@@ -73,7 +74,7 @@ describe 'Files' do
|
|
73
74
|
|
74
75
|
it 'writes the correct number of colors' do
|
75
76
|
d = ASE.from_file(@output.path)
|
76
|
-
expect(d['Test'].size).to be
|
77
|
+
expect(d['Test'].size).to be 3
|
77
78
|
end
|
78
79
|
|
79
80
|
it 'writes the correct color names' do
|
@@ -84,8 +85,16 @@ describe 'Files' do
|
|
84
85
|
|
85
86
|
it 'writes the correct color values' do
|
86
87
|
d = ASE.from_file(@output.path)
|
87
|
-
expect(d['Test']['Red'].
|
88
|
-
expect(d['Test']['Blue'].
|
88
|
+
expect(d['Test']['Red'].to_a).to eq([255, 0, 0])
|
89
|
+
expect(d['Test']['Blue'].to_a).to eq([0.91, 0.68, 0.2, 0])
|
90
|
+
expect(d['Test']['Blah'].to_a).to eq([0.5])
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'writes the correct color types' do
|
94
|
+
d = ASE.from_file(@output.path)
|
95
|
+
expect(d['Test']['Red']).to be_an_instance_of(ASE::Color::RGB)
|
96
|
+
expect(d['Test']['Blue']).to be_an_instance_of(ASE::Color::CMYK)
|
97
|
+
expect(d['Test']['Blah']).to be_an_instance_of(ASE::Color::Gray)
|
89
98
|
end
|
90
99
|
end
|
91
100
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ase
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan LeFevre
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-09-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -96,15 +96,20 @@ files:
|
|
96
96
|
- Rakefile
|
97
97
|
- ase.gemspec
|
98
98
|
- examples/control.php
|
99
|
+
- examples/read.rb
|
99
100
|
- examples/simple.rb
|
100
101
|
- lib/ase.rb
|
101
102
|
- lib/ase/color.rb
|
103
|
+
- lib/ase/color_modes/cmyk.rb
|
104
|
+
- lib/ase/color_modes/gray.rb
|
105
|
+
- lib/ase/color_modes/rgb.rb
|
102
106
|
- lib/ase/file.rb
|
103
107
|
- lib/ase/palette.rb
|
104
108
|
- lib/ase/reader.rb
|
105
109
|
- lib/ase/version.rb
|
106
110
|
- lib/ase/writer.rb
|
107
111
|
- spec/ase_spec.rb
|
112
|
+
- spec/color_spec.rb
|
108
113
|
- spec/file_spec.rb
|
109
114
|
- spec/files/control.ase
|
110
115
|
- spec/spec_helper.rb
|
@@ -135,6 +140,7 @@ summary: Reader/writer for Adobe Swatch Exchange files. Can be used across the e
|
|
135
140
|
Adobe Creative Suite.
|
136
141
|
test_files:
|
137
142
|
- spec/ase_spec.rb
|
143
|
+
- spec/color_spec.rb
|
138
144
|
- spec/file_spec.rb
|
139
145
|
- spec/files/control.ase
|
140
146
|
- spec/spec_helper.rb
|